diff --git a/DocumentsFromSnapshotMigration/src/main/java/org/opensearch/migrations/RfsMigrateDocuments.java b/DocumentsFromSnapshotMigration/src/main/java/org/opensearch/migrations/RfsMigrateDocuments.java index 569e8b4a6..203d10d1d 100644 --- a/DocumentsFromSnapshotMigration/src/main/java/org/opensearch/migrations/RfsMigrateDocuments.java +++ b/DocumentsFromSnapshotMigration/src/main/java/org/opensearch/migrations/RfsMigrateDocuments.java @@ -176,7 +176,7 @@ public static class DocParams implements TransformerParams { public String getTransformerConfigParameterArgPrefix() { return DOC_CONFIG_PARAMETER_ARG_PREFIX; } - final static String DOC_CONFIG_PARAMETER_ARG_PREFIX = "doc-"; + private static final String DOC_CONFIG_PARAMETER_ARG_PREFIX = "doc-"; @Parameter( required = false, diff --git a/RFS/src/main/java/org/opensearch/migrations/bulkload/common/OpenSearchClient.java b/RFS/src/main/java/org/opensearch/migrations/bulkload/common/OpenSearchClient.java index 9b7dbeda9..e1d68950d 100644 --- a/RFS/src/main/java/org/opensearch/migrations/bulkload/common/OpenSearchClient.java +++ b/RFS/src/main/java/org/opensearch/migrations/bulkload/common/OpenSearchClient.java @@ -15,7 +15,6 @@ import org.opensearch.migrations.Flavor; import org.opensearch.migrations.Version; import org.opensearch.migrations.VersionMatchers; -import org.opensearch.migrations.bulkload.common.OpenSearchClient.OperationFailed; import org.opensearch.migrations.bulkload.common.http.ConnectionContext; import org.opensearch.migrations.bulkload.common.http.HttpResponse; import org.opensearch.migrations.bulkload.tracing.IRfsContexts; @@ -37,7 +36,7 @@ public class OpenSearchClient { /** Amazon OpenSearch Serverless cluster don't have a version number, but * its closely aligned with the latest open-source OpenSearch 2.X */ - private static Version AMAZON_SERVERLESS_VERSION = Version.builder() + private static final Version AMAZON_SERVERLESS_VERSION = Version.builder() .flavor(Flavor.AMAZON_SERVERLESS_OPENSEARCH) .major(2) .build(); @@ -89,7 +88,7 @@ public Version getClusterVersion() { if (resp.statusCode == 404) { return Mono.just(AMAZON_SERVERLESS_VERSION); } - return Mono.error(new OperationFailed("Unexpected status code " + resp.statusCode, resp)); + return Mono.error(new UnexpectedStatusCode(resp)); }) .doOnError(e -> log.error(e.getMessage())) .retryWhen(CHECK_IF_ITEM_EXISTS_RETRY_STRATEGY) @@ -105,7 +104,7 @@ public Version getClusterVersion() { .retryWhen(CHECK_IF_ITEM_EXISTS_RETRY_STRATEGY) .flatMap(hasCompatibilityModeEnabled -> { log.atInfo().setMessage("Checking CompatibilityMode, was enabled? {}").addArgument(hasCompatibilityModeEnabled).log(); - if (!hasCompatibilityModeEnabled) { + if (Boolean.FALSE.equals(hasCompatibilityModeEnabled)) { return Mono.just(versionFromRootApi); } return client.getAsync("_nodes/_all/nodes,version?format=json", null) @@ -150,7 +149,7 @@ private Mono versionFromResponse(HttpResponse resp) { Mono checkCompatibilityModeFromResponse(HttpResponse resp) { if (resp.statusCode != 200) { - return Mono.error(new OperationFailed("Unexpected status code " + resp.statusCode, resp)); + return Mono.error(new UnexpectedStatusCode(resp)); } try { var body = Optional.of(objectMapper.readTree(resp.body)); @@ -175,7 +174,7 @@ private boolean inCompatibilityMode(Optional node) { private Mono getVersionFromNodes(HttpResponse resp) { if (resp.statusCode != 200) { - return Mono.error(new OperationFailed("Unexpected status code " + resp.statusCode, resp)); + return Mono.error(new UnexpectedStatusCode(resp)); } var foundVersions = new HashSet(); try { @@ -188,7 +187,7 @@ private Mono getVersionFromNodes(HttpResponse resp) { foundVersions.add(nodeVersion); }); - if (foundVersions.size() == 0) { + if (foundVersions.isEmpty()) { return Mono.error(new OperationFailed("Unable to find any version numbers", resp)); } @@ -547,7 +546,7 @@ public String getFailureMessage() { } } - public static class OperationFailed extends RfsException { + public static class OperationFailed extends RuntimeException { public final transient HttpResponse response; public OperationFailed(String message, HttpResponse response) { @@ -556,4 +555,10 @@ public OperationFailed(String message, HttpResponse response) { this.response = response; } } + + public static class UnexpectedStatusCode extends OperationFailed { + public UnexpectedStatusCode(HttpResponse response) { + super("Unexpected status code " + response.statusCode, response); + } + } } diff --git a/RFS/src/main/java/org/opensearch/migrations/metadata/CreationResult.java b/RFS/src/main/java/org/opensearch/migrations/metadata/CreationResult.java index 243347d42..69597053a 100644 --- a/RFS/src/main/java/org/opensearch/migrations/metadata/CreationResult.java +++ b/RFS/src/main/java/org/opensearch/migrations/metadata/CreationResult.java @@ -26,7 +26,7 @@ public boolean wasFatal() { @AllArgsConstructor @Getter - public static enum CreationFailureType { + public enum CreationFailureType { ALREADY_EXISTS(false, "already exists"), UNABLE_TO_TRANSFORM_FAILURE(true, "failed to transform to the target version"), TARGET_CLUSTER_FAILURE(true, "failed on target cluster"),