Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code smells in metadata commands #980

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
/** The list of supported commands for the metadata tool */
public enum MetadataCommands {
/** Migrates items from a source and recreates them on the target cluster */
Migrate,
MIGRATE,

/** Inspects items from a source to determine which can be placed on a target cluster */
Evaluate;
EVALUATE;

public static MetadataCommands fromString(String s) {
for (var command : values()) {
if (command.name().toLowerCase().equals(s.toLowerCase())) {
if (command.name().equalsIgnoreCase(s)) {
return command;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@

var command = Optional.ofNullable(jCommander.getParsedCommand())
.map(MetadataCommands::fromString)
.orElse(MetadataCommands.Migrate);
.orElse(MetadataCommands.MIGRATE);

Check warning on line 57 in MetadataMigration/src/main/java/org/opensearch/migrations/MetadataMigration.java

View check run for this annotation

Codecov / codecov/patch

MetadataMigration/src/main/java/org/opensearch/migrations/MetadataMigration.java#L57

Added line #L57 was not covered by tests
Result result;
switch (command) {
default:
case Migrate:
case MIGRATE:
if (migrateArgs.help) {
printCommandUsage(jCommander);
return;
Expand All @@ -67,7 +67,7 @@
log.info("Starting Metadata Migration");
result = meta.migrate(migrateArgs).execute(context);
break;
case Evaluate:
case EVALUATE:
if (evaluateArgs.help) {
printCommandUsage(jCommander);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class EndToEndTest {

private static Stream<Arguments> scenarios() {
return Stream.of(
Arguments.of(TransferMedium.Http, MetadataCommands.Evaluate),
Arguments.of(TransferMedium.SnapshotImage, MetadataCommands.Migrate),
Arguments.of(TransferMedium.Http, MetadataCommands.Migrate)
Arguments.of(TransferMedium.Http, MetadataCommands.EVALUATE),
Arguments.of(TransferMedium.SnapshotImage, MetadataCommands.MIGRATE),
Arguments.of(TransferMedium.Http, MetadataCommands.MIGRATE)
);
}

Expand Down Expand Up @@ -183,7 +183,7 @@ private void migrateFrom_ES(
var metadata = new MetadataMigration();

MigrationItemResult result;
if (MetadataCommands.Migrate.equals(command)) {
if (MetadataCommands.MIGRATE.equals(command)) {
result = metadata.migrate(arguments).execute(metadataContext);
} else {
result = metadata.evaluate(arguments).execute(metadataContext);
Expand Down Expand Up @@ -223,7 +223,7 @@ private void verifyTargetCluster(
boolean sourceIsES6_8,
TestData testData
) {
var expectUpdatesOnTarget = MetadataCommands.Migrate.equals(command);
var expectUpdatesOnTarget = MetadataCommands.MIGRATE.equals(command);
// If the command was migrate, the target cluster should have the items, if not they
var verifyResponseCode = expectUpdatesOnTarget ? equalTo(200) : equalTo(404);

Expand Down