Skip to content

Commit

Permalink
fix ResourceAlreadyExistsException
Browse files Browse the repository at this point in the history
  • Loading branch information
tmanninger committed Sep 23, 2024
1 parent 401761c commit e8db512
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.opensearch.core.common.bytes.BytesArray;
import org.opensearch.core.xcontent.NamedXContentRegistry;
import org.opensearch.ResourceAlreadyExistsException;
import org.opensearch.transport.RemoteTransportException;

import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
Expand Down Expand Up @@ -132,16 +133,20 @@ private boolean initDataStream() {
}
this.dataStreamInitialized = true;
} catch (final Exception e) {
if ( e.getCause( ) instanceof ResourceAlreadyExistsException ) {
log.trace("Datastream {} already exists", dataStreamName);
this.dataStreamInitialized = true;
}
else {
log.error("Cannot create datastream {} due to", dataStreamName, e);
}
if (
e.getCause( ) instanceof ResourceAlreadyExistsException ||
e.getCause() instanceof RemoteTransportException && e.getCause().getCause() instanceof ResourceAlreadyExistsException
) {
log.trace("Datastream {} already exists", dataStreamName);
this.dataStreamInitialized = true;
}
else {
log.error("Cannot create datastream {} due to", dataStreamName, e);
return false;
}
}

return true;
return this.dataStreamInitialized;
}

@Override
Expand Down

0 comments on commit e8db512

Please sign in to comment.