Skip to content

Commit

Permalink
Fix several minor issues in RFS codebase
Browse files Browse the repository at this point in the history
- Fix keyword ordering of DOC_CONFIG_PARAMETER_ARG_PREFIX
- Created exception for Unexpected status code to remove duplicated
  error strings
- Make check for hasCompatibilityModeEnabled null safe
- Use isEmpty instead of size() == 0
- Remove redundant static modifier on CreationFailureType

Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Nov 23, 2024
1 parent 7da05b7 commit b4a36ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -150,7 +149,7 @@ private Mono<Version> versionFromResponse(HttpResponse resp) {

Mono<Boolean> 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));
Expand All @@ -175,7 +174,7 @@ private boolean inCompatibilityMode(Optional<JsonNode> node) {

private Mono<Version> 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<Version>();
try {
Expand All @@ -188,7 +187,7 @@ private Mono<Version> 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));
}

Expand Down Expand Up @@ -556,4 +555,10 @@ public OperationFailed(String message, HttpResponse response) {
this.response = response;
}
}

public static class UnexpectedStatusCode extends OperationFailed {

Check failure on line 559 in RFS/src/main/java/org/opensearch/migrations/bulkload/common/OpenSearchClient.java

View workflow job for this annotation

GitHub Actions / Run SonarQube Analysis

java:S110

This class has 6 parents which is greater than 5 authorized.
public UnexpectedStatusCode(HttpResponse response) {
super("Unexpected status code " + response.statusCode, response);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit b4a36ba

Please sign in to comment.