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
- Make AMAZON_SERVERLESS_VERSION final so it follows naming conventions
- Have OperationFailed extend RuntimeException so it can be inheirited
  from, otherwise it would trigger 'java:S110 This class has 6 parents which is
greater than 5 authorized.'

Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Nov 23, 2024
1 parent 7da05b7 commit eeffc58
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 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 All @@ -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();
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 @@ -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) {
Expand All @@ -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);
}
}
}
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 eeffc58

Please sign in to comment.