From ee3fcc548644cd9dd26599068b46a53794e86dfd Mon Sep 17 00:00:00 2001 From: Andre Kurait Date: Thu, 9 Jan 2025 12:06:26 -0600 Subject: [PATCH] Metadata add 1:many custom transformations (#1225) * Metadata add 1:many custom transformations Signed-off-by: Andre Kurait * Fix FanOutCompositeTransformer Signed-off-by: Andre Kurait --------- Signed-off-by: Andre Kurait --- .../commands/MigratorEvaluatorBase.java | 4 +- .../MultiTypeMappingTransformationTest.java | 1 + ...r.java => FanOutCompositeTransformer.java} | 15 ++++-- .../bulkload/transformers/Transformer.java | 4 +- .../TransformerToIJsonTransformerAdapter.java | 49 ++++++++++++------- .../Transformer_ES_6_8_to_OS_2_11.java | 4 +- .../Transformer_ES_7_10_OS_2_11.java | 6 ++- .../bulkload/worker/IndexRunner.java | 35 ++++++++----- ...va => FanOutCompositeTransformerTest.java} | 2 +- .../Transformer_ES_7_10_OS_2_11Test.java | 8 +-- .../rules/IndexMappingTypeRemoval.java | 5 +- .../rules/IndexMappingTypeRemovalTest.java | 20 +++----- 12 files changed, 91 insertions(+), 62 deletions(-) rename RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/{CompositeTransformer.java => FanOutCompositeTransformer.java} (54%) rename RFS/src/test/java/org/opensearch/migrations/bulkload/common/http/{CompositeTransformerTest.java => FanOutCompositeTransformerTest.java} (97%) diff --git a/MetadataMigration/src/main/java/org/opensearch/migrations/commands/MigratorEvaluatorBase.java b/MetadataMigration/src/main/java/org/opensearch/migrations/commands/MigratorEvaluatorBase.java index 55cc8febd..0ea3ed668 100644 --- a/MetadataMigration/src/main/java/org/opensearch/migrations/commands/MigratorEvaluatorBase.java +++ b/MetadataMigration/src/main/java/org/opensearch/migrations/commands/MigratorEvaluatorBase.java @@ -5,7 +5,7 @@ import org.opensearch.migrations.MigrateOrEvaluateArgs; import org.opensearch.migrations.MigrationMode; -import org.opensearch.migrations.bulkload.transformers.CompositeTransformer; +import org.opensearch.migrations.bulkload.transformers.FanOutCompositeTransformer; import org.opensearch.migrations.bulkload.transformers.TransformFunctions; import org.opensearch.migrations.bulkload.transformers.Transformer; import org.opensearch.migrations.bulkload.transformers.TransformerToIJsonTransformerAdapter; @@ -76,7 +76,7 @@ protected Transformer selectTransformer(Clusters clusters) { arguments.metadataTransformationParams ); var customTransformer = getCustomTransformer(); - var compositeTransformer = new CompositeTransformer(customTransformer, versionTransformer); + var compositeTransformer = new FanOutCompositeTransformer(customTransformer, versionTransformer); log.atInfo().setMessage("Selected transformer: {}").addArgument(compositeTransformer).log(); return compositeTransformer; } diff --git a/MetadataMigration/src/test/java/org/opensearch/migrations/MultiTypeMappingTransformationTest.java b/MetadataMigration/src/test/java/org/opensearch/migrations/MultiTypeMappingTransformationTest.java index 6473be7fc..a1a50cdbe 100644 --- a/MetadataMigration/src/test/java/org/opensearch/migrations/MultiTypeMappingTransformationTest.java +++ b/MetadataMigration/src/test/java/org/opensearch/migrations/MultiTypeMappingTransformationTest.java @@ -81,6 +81,7 @@ public void multiTypeTransformationTest_union() { var dataFilterArgs = new DataFilterArgs(); dataFilterArgs.indexAllowlist = List.of(originalIndexName); arguments.dataFilterArgs = dataFilterArgs; + arguments.sourceVersion = upgradedSourceCluster.getContainerVersion().getVersion(); // Use union method for multi-type mappings arguments.metadataTransformationParams.multiTypeResolutionBehavior = IndexMappingTypeRemoval.MultiTypeResolutionBehavior.UNION; diff --git a/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/CompositeTransformer.java b/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/FanOutCompositeTransformer.java similarity index 54% rename from RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/CompositeTransformer.java rename to RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/FanOutCompositeTransformer.java index 075c5204b..2ebdcd565 100644 --- a/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/CompositeTransformer.java +++ b/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/FanOutCompositeTransformer.java @@ -1,12 +1,16 @@ package org.opensearch.migrations.bulkload.transformers; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + import org.opensearch.migrations.bulkload.models.GlobalMetadata; import org.opensearch.migrations.bulkload.models.IndexMetadata; -public class CompositeTransformer implements Transformer { +public class FanOutCompositeTransformer implements Transformer { private final Transformer[] transformers; - public CompositeTransformer(Transformer... transformers) { + public FanOutCompositeTransformer(Transformer... transformers) { this.transformers = transformers; } @@ -19,10 +23,11 @@ public GlobalMetadata transformGlobalMetadata(GlobalMetadata globalData) { } @Override - public IndexMetadata transformIndexMetadata(IndexMetadata indexData) { + public List transformIndexMetadata(IndexMetadata indexData) { + var indexDataStream = Stream.of(indexData); for (Transformer transformer : transformers) { - indexData = transformer.transformIndexMetadata(indexData); + indexDataStream = indexDataStream.flatMap(data -> transformer.transformIndexMetadata(data).stream()); } - return indexData; + return indexDataStream.collect(Collectors.toList()); } } diff --git a/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer.java b/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer.java index bf00d9f6c..363da33b5 100644 --- a/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer.java +++ b/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer.java @@ -1,5 +1,7 @@ package org.opensearch.migrations.bulkload.transformers; +import java.util.List; + import org.opensearch.migrations.bulkload.models.GlobalMetadata; import org.opensearch.migrations.bulkload.models.IndexMetadata; @@ -16,5 +18,5 @@ public interface Transformer { /** * Takes the raw JSON representing the Index Metadata of one version and returns a new, transformed copy of the JSON */ - public IndexMetadata transformIndexMetadata(IndexMetadata indexData); + public List transformIndexMetadata(IndexMetadata indexData); } diff --git a/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/TransformerToIJsonTransformerAdapter.java b/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/TransformerToIJsonTransformerAdapter.java index 23ba722df..1afdbb36e 100644 --- a/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/TransformerToIJsonTransformerAdapter.java +++ b/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/TransformerToIJsonTransformerAdapter.java @@ -24,7 +24,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +/** + * Adapts an {@link IJsonTransformer} to a {@link Transformer}. + */ @Slf4j public class TransformerToIJsonTransformerAdapter implements Transformer { public static final String OUTPUT_TRANSFORMATION_JSON_LOGGER = "OutputTransformationJsonLogger"; @@ -74,12 +76,21 @@ private static String printMap(Object map) { } @SuppressWarnings("unchecked") - private MigrationItem transformMigrationItem(MigrationItem migrationItem) { + private List transformMigrationItem(MigrationItem migrationItem) { // Keep untouched original for logging final Map originalMap = MAPPER.convertValue(migrationItem, Map.class); - Object transformedMigrationItem = transformer.transformJson(MAPPER.convertValue(migrationItem, Map.class)); - logTransformation(originalMap, transformedMigrationItem); - return MAPPER.convertValue(transformedMigrationItem, MigrationItem.class); + Object transformedResult = transformer.transformJson(MAPPER.convertValue(migrationItem, Map.class)); + logTransformation(originalMap, transformedResult); + + List transformedItems = new ArrayList<>(); + if (transformedResult instanceof List) { + for (Object item : (List) transformedResult) { + transformedItems.add(MAPPER.convertValue(item, MigrationItem.class)); + } + } else { + transformedItems.add(MAPPER.convertValue(transformedResult, MigrationItem.class)); + } + return transformedItems; } void updateTemplates(Collection transformedItems, ObjectNode itemsRoot) { @@ -98,11 +109,8 @@ void updateTemplates(Collection transformedItems, Objec @Override public GlobalMetadata transformGlobalMetadata(GlobalMetadata globalData) { - var inputJson = objectNodeToMap(globalData.toObjectNode()); - log.atInfo().setMessage("BeforeJsonGlobal: {}").addArgument(() -> printMap(inputJson)).log(); - Object afterJson = transformer.transformJson(inputJson); - log.atInfo().setMessage("AfterJsonGlobal: {}").addArgument(() -> printMap(afterJson)).log(); - + log.atInfo().setMessage("BeforeJsonGlobal: {}") + .addArgument(() -> printMap(objectNodeToMap(globalData.toObjectNode()))).log(); final List legacyTemplates = new ArrayList<>(); globalData.getTemplates().fields().forEachRemaining( @@ -122,7 +130,8 @@ public GlobalMetadata transformGlobalMetadata(GlobalMetadata globalData) { indexTemplates.stream()), componentTemplates.stream() ) - .map(this::transformMigrationItem).collect(Collectors.toList()); + .flatMap(item -> transformMigrationItem(item).stream()) + .collect(Collectors.toList()); var transformedLegacy = transformedTemplates.stream() .filter(LegacyTemplate.class::isInstance) @@ -139,24 +148,30 @@ public GlobalMetadata transformGlobalMetadata(GlobalMetadata globalData) { .map(ComponentTemplate.class::cast) .collect(Collectors.toList()); - assert transformedLegacy.size() + transformedIndex.size() + transformedComponent.size() == transformedTemplates.size(); - updateTemplates(transformedLegacy, globalData.getTemplates()); updateTemplates(transformedIndex, globalData.getIndexTemplates()); updateTemplates(transformedComponent, globalData.getComponentTemplates()); - log.atInfo().setMessage("GlobalOutput: {}").addArgument(() -> printMap(objectNodeToMap(globalData.toObjectNode()))).log(); + log.atInfo().setMessage("AfterJsonGlobal: {}") + .addArgument(() -> printMap(objectNodeToMap(globalData.toObjectNode()))).log(); return globalData; } @SuppressWarnings("unchecked") @Override - public IndexMetadata transformIndexMetadata(IndexMetadata indexData) { + public List transformIndexMetadata(IndexMetadata indexData) { final Map originalInput = MAPPER.convertValue(indexData, Map.class); final Map inputJson = MAPPER.convertValue(indexData, Map.class); Object afterJson = transformer.transformJson(inputJson); logTransformation(originalInput, afterJson); - return MAPPER.convertValue(inputJson, IndexMetadata.class); + if (afterJson instanceof List) { + return ((List>) afterJson).stream() + .map(json -> MAPPER.convertValue(json, IndexMetadata.class)) + .collect(Collectors.toList()); + } else if (afterJson instanceof Map) { + return List.of(MAPPER.convertValue(afterJson, IndexMetadata.class)); + } else { + throw new IllegalArgumentException("Unexpected transformation result type: " + afterJson.getClass()); + } } - } diff --git a/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_6_8_to_OS_2_11.java b/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_6_8_to_OS_2_11.java index 014172cc6..70e635820 100644 --- a/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_6_8_to_OS_2_11.java +++ b/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_6_8_to_OS_2_11.java @@ -85,10 +85,10 @@ public ObjectNode getRawJson() { } @Override - public IndexMetadata transformIndexMetadata(IndexMetadata index) { + public List transformIndexMetadata(IndexMetadata index) { var copy = index.deepCopy(); transformIndex(copy, IndexType.CONCRETE); - return new IndexMetadataData_OS_2_11(copy.getRawJson(), copy.getId(), copy.getName()); + return List.of(new IndexMetadataData_OS_2_11(copy.getRawJson(), copy.getId(), copy.getName())); } private void transformIndex(Index index, IndexType type) { diff --git a/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_7_10_OS_2_11.java b/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_7_10_OS_2_11.java index e841da5b1..ae99903a9 100644 --- a/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_7_10_OS_2_11.java +++ b/RFS/src/main/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_7_10_OS_2_11.java @@ -1,5 +1,7 @@ package org.opensearch.migrations.bulkload.transformers; +import java.util.List; + import org.opensearch.migrations.bulkload.models.GlobalMetadata; import org.opensearch.migrations.bulkload.models.IndexMetadata; import org.opensearch.migrations.bulkload.version_os_2_11.GlobalMetadataData_OS_2_11; @@ -84,7 +86,7 @@ public GlobalMetadata transformGlobalMetadata(GlobalMetadata metaData) { } @Override - public IndexMetadata transformIndexMetadata(IndexMetadata indexData) { + public List transformIndexMetadata(IndexMetadata indexData) { log.atDebug().setMessage("Original Object: {}").addArgument(indexData::getRawJson).log(); var copy = indexData.deepCopy(); var newRoot = copy.getRawJson(); @@ -96,6 +98,6 @@ public IndexMetadata transformIndexMetadata(IndexMetadata indexData) { TransformFunctions.fixReplicasForDimensionality(newRoot, awarenessAttributeDimensionality); log.atDebug().setMessage("Transformed Object: {}").addArgument(newRoot).log(); - return copy; + return List.of(copy); } } diff --git a/RFS/src/main/java/org/opensearch/migrations/bulkload/worker/IndexRunner.java b/RFS/src/main/java/org/opensearch/migrations/bulkload/worker/IndexRunner.java index 8dd42d968..e9fb5f97c 100644 --- a/RFS/src/main/java/org/opensearch/migrations/bulkload/worker/IndexRunner.java +++ b/RFS/src/main/java/org/opensearch/migrations/bulkload/worker/IndexRunner.java @@ -1,5 +1,6 @@ package org.opensearch.migrations.bulkload.worker; +import java.util.ArrayList; import java.util.List; import org.opensearch.migrations.MigrationMode; @@ -33,44 +34,56 @@ public IndexMetadataResults migrateIndices(MigrationMode mode, ICreateIndexConte repoDataProvider.getIndicesInSnapshot(snapshotName) .stream() .forEach(index -> { - CreationResult creationResult; + List creationResults; if (skipCreation.test(index.getName())) { log.atInfo() .setMessage("Index {} was not part of the allowlist and will not be migrated.") .addArgument(index.getName()) .log(); - creationResult = CreationResult.builder() + creationResults = List.of(CreationResult.builder() .name(index.getName()) .failureType(CreationFailureType.SKIPPED_DUE_TO_FILTER) - .build(); + .build()); } else { - creationResult = createIndex(index.getName(), mode, context); + creationResults = createIndex(index.getName(), mode, context); } - results.index(creationResult); + creationResults.forEach(results::index); var indexMetadata = metadataFactory.fromRepo(snapshotName, index.getName()); indexMetadata.getAliases().fieldNames().forEachRemaining(alias -> { var aliasResult = CreationResult.builder().name(alias); - aliasResult.failureType(creationResult.getFailureType()); + aliasResult.failureType(creationResults.get(0).getFailureType()); results.alias(aliasResult.build()); }); }); return results.build(); } - private CreationResult createIndex(String indexName, MigrationMode mode, ICreateIndexContext context) { + private List createIndex(String indexName, MigrationMode mode, ICreateIndexContext context) { var originalIndexMetadata = metadataFactory.fromRepo(snapshotName, indexName); var indexMetadata = originalIndexMetadata.deepCopy(); + List creationResults = new ArrayList<>(); try { - indexMetadata = transformer.transformIndexMetadata(indexMetadata); - return indexCreator.create(indexMetadata, mode, context); + List transformedMetadataList = transformer.transformIndexMetadata(indexMetadata); + for (IndexMetadata transformedMetadata : transformedMetadataList) { + try { + creationResults.add(indexCreator.create(transformedMetadata, mode, context)); + } catch (Exception e) { + creationResults.add(CreationResult.builder() + .name(indexName) + .exception(new IndexTransformationException(indexName, e)) + .failureType(CreationFailureType.UNABLE_TO_TRANSFORM_FAILURE) + .build()); + } + } } catch (Exception e) { - return CreationResult.builder() + creationResults.add(CreationResult.builder() .name(indexName) .exception(new IndexTransformationException(indexName, e)) .failureType(CreationFailureType.UNABLE_TO_TRANSFORM_FAILURE) - .build(); + .build()); } + return creationResults; } } diff --git a/RFS/src/test/java/org/opensearch/migrations/bulkload/common/http/CompositeTransformerTest.java b/RFS/src/test/java/org/opensearch/migrations/bulkload/common/http/FanOutCompositeTransformerTest.java similarity index 97% rename from RFS/src/test/java/org/opensearch/migrations/bulkload/common/http/CompositeTransformerTest.java rename to RFS/src/test/java/org/opensearch/migrations/bulkload/common/http/FanOutCompositeTransformerTest.java index 5bc3872e2..b28c4ade7 100644 --- a/RFS/src/test/java/org/opensearch/migrations/bulkload/common/http/CompositeTransformerTest.java +++ b/RFS/src/test/java/org/opensearch/migrations/bulkload/common/http/FanOutCompositeTransformerTest.java @@ -11,7 +11,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -public class CompositeTransformerTest { +public class FanOutCompositeTransformerTest { @Test public void testCompositeTransformer() { diff --git a/RFS/src/test/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_7_10_OS_2_11Test.java b/RFS/src/test/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_7_10_OS_2_11Test.java index 926a6368b..a75d10ddf 100644 --- a/RFS/src/test/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_7_10_OS_2_11Test.java +++ b/RFS/src/test/java/org/opensearch/migrations/bulkload/transformers/Transformer_ES_7_10_OS_2_11Test.java @@ -51,19 +51,19 @@ public void transformIndexMetadata_AsExpected() throws Exception { Transformer_ES_7_10_OS_2_11 transformer = new Transformer_ES_7_10_OS_2_11(2); IndexMetadata indexMetadataBwc = sourceResourceProvider.getIndexMetadata().fromRepo(snapshot.name, "bwc_index_1"); - IndexMetadata transformedIndexBwc = transformer.transformIndexMetadata(indexMetadataBwc); + IndexMetadata transformedIndexBwc = transformer.transformIndexMetadata(indexMetadataBwc).get(0); IndexMetadataData_OS_2_11 finalIndexBwc =new IndexMetadataData_OS_2_11(transformedIndexBwc.getRawJson(), transformedIndexBwc.getId(), transformedIndexBwc.getName()); IndexMetadata indexMetadataFwc = sourceResourceProvider.getIndexMetadata().fromRepo(snapshot.name, "fwc_index_1"); - IndexMetadata transformedIndexFwc = transformer.transformIndexMetadata(indexMetadataFwc); + IndexMetadata transformedIndexFwc = transformer.transformIndexMetadata(indexMetadataFwc).get(0); IndexMetadataData_OS_2_11 finalIndexFwc =new IndexMetadataData_OS_2_11(transformedIndexFwc.getRawJson(), transformedIndexFwc.getId(), transformedIndexFwc.getName()); IndexMetadata indexMetadataNoMappingNoDocs = sourceResourceProvider.getIndexMetadata().fromRepo(snapshot.name, "no_mappings_no_docs"); - IndexMetadata transformedIndexNoMappingNoDocs = transformer.transformIndexMetadata(indexMetadataNoMappingNoDocs); + IndexMetadata transformedIndexNoMappingNoDocs = transformer.transformIndexMetadata(indexMetadataNoMappingNoDocs).get(0); IndexMetadataData_OS_2_11 finalIndexNoMappingNoDocs = new IndexMetadataData_OS_2_11(transformedIndexNoMappingNoDocs.getRawJson(), transformedIndexNoMappingNoDocs.getId(), transformedIndexNoMappingNoDocs.getName()); IndexMetadata indexMetadataEmptyMappingNoDocs = sourceResourceProvider.getIndexMetadata().fromRepo(snapshot.name, "empty_mappings_no_docs"); - IndexMetadata transformedIndexEmptyMappingNoDocs = transformer.transformIndexMetadata(indexMetadataEmptyMappingNoDocs); + IndexMetadata transformedIndexEmptyMappingNoDocs = transformer.transformIndexMetadata(indexMetadataEmptyMappingNoDocs).get(0); IndexMetadataData_OS_2_11 finalIndexEmptyMappingNoDocs = new IndexMetadataData_OS_2_11(transformedIndexEmptyMappingNoDocs.getRawJson(), transformedIndexEmptyMappingNoDocs.getId(), transformedIndexEmptyMappingNoDocs.getName()); String expectedIndexBwc = "{\"version\":3,\"mapping_version\":1,\"settings_version\":1,\"aliases_version\":1,\"routing_num_shards\":1024,\"state\":\"open\",\"settings\":{\"creation_date\":\"1727459371883\",\"number_of_replicas\":1,\"number_of_shards\":\"1\",\"provided_name\":\"bwc_index_1\",\"uuid\":\"tBmFXxGhTeiDlznQiKfNCA\",\"version\":{\"created\":\"7100299\"}},\"mappings\":{\"properties\":{\"content\":{\"type\":\"text\"},\"title\":{\"type\":\"text\"}}},\"aliases\":{\"bwc_alias\":{}},\"primary_terms\":[1],\"in_sync_allocations\":{\"0\":[\"jSYEePXYTka3EJ0vvdPGJA\"]},\"rollover_info\":{},\"system\":false}"; diff --git a/transformation/src/main/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemoval.java b/transformation/src/main/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemoval.java index 9610e0ab1..56b346500 100644 --- a/transformation/src/main/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemoval.java +++ b/transformation/src/main/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemoval.java @@ -1,7 +1,6 @@ package org.opensearch.migrations.transformation.rules; import org.opensearch.migrations.transformation.CanApplyResult; -import org.opensearch.migrations.transformation.CanApplyResult.Unsupported; import org.opensearch.migrations.transformation.TransformationRule; import org.opensearch.migrations.transformation.entity.Index; @@ -77,10 +76,10 @@ public CanApplyResult canApply(final Index index) { // 2.
{"mappings": [{ "foo": {...}, "bar": {...}  }]}
if (mappingNode.isArray() && (mappingNode.size() > 1 || mappingNode.get(0).size() > 1)) { if (MultiTypeResolutionBehavior.NONE.equals(multiTypeResolutionBehavior)) { - return new Unsupported("No multi type resolution behavior declared, specify --multi-type-behavior to process"); + throw new IllegalArgumentException("No multi type resolution behavior declared, specify --multi-type-behavior to process"); } if (MultiTypeResolutionBehavior.SPLIT.equals(multiTypeResolutionBehavior)) { - return new Unsupported("Split on multiple mapping types is not supported"); + throw new IllegalArgumentException("Split on multiple mapping types is not supported"); } // Support UNION } diff --git a/transformation/src/test/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemovalTest.java b/transformation/src/test/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemovalTest.java index 5bbfa33b3..9e3e2c0d3 100644 --- a/transformation/src/test/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemovalTest.java +++ b/transformation/src/test/java/org/opensearch/migrations/transformation/rules/IndexMappingTypeRemovalTest.java @@ -4,7 +4,6 @@ import java.util.function.Function; import org.opensearch.migrations.transformation.CanApplyResult; -import org.opensearch.migrations.transformation.CanApplyResult.Unsupported; import org.opensearch.migrations.transformation.entity.Index; import com.fasterxml.jackson.databind.ObjectMapper; @@ -15,7 +14,6 @@ import org.junit.jupiter.params.provider.CsvSource; import org.mockito.Mockito; -import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; @@ -240,14 +238,11 @@ void testApplyTransformation_twoCustomTypes(String resolutionBehavior, String ex var behavior = IndexMappingTypeRemoval.MultiTypeResolutionBehavior.valueOf(resolutionBehavior); - // Action - var wasChanged = applyTransformation(behavior, indexJson); - var canApply = canApply(behavior, originalJson); - assertThat(canApply, instanceOf(Unsupported.class)); - assertThat(((Unsupported) canApply).getReason(), equalTo(expectedReason)); + // Action & Assertion + var exception = assertThrows(IllegalArgumentException.class, () -> canApply(behavior, originalJson)); + assertThat(exception.getMessage(), equalTo(expectedReason)); // Verification - assertThat(wasChanged, equalTo(false)); assertThat(originalJson.toPrettyString(), equalTo(indexJson.toPrettyString())); } @@ -263,14 +258,11 @@ void testApplyTransformation_twoMappingEntries(String resolutionBehavior, String var indexJson = originalJson.deepCopy(); var behavior = IndexMappingTypeRemoval.MultiTypeResolutionBehavior.valueOf(resolutionBehavior); - // Action - var wasChanged = applyTransformation(behavior, indexJson); - var canApply = canApply(behavior, originalJson); - assertThat(canApply, instanceOf(Unsupported.class)); - assertThat(((Unsupported) canApply).getReason(), equalTo(expectedReason)); + // Action & Assertion + var exception = assertThrows(IllegalArgumentException.class, () -> canApply(behavior, originalJson)); + assertThat(exception.getMessage(), equalTo(expectedReason)); // Verification - assertThat(wasChanged, equalTo(false)); assertThat(originalJson.toPrettyString(), equalTo(indexJson.toPrettyString())); }