forked from opensearch-project/opensearch-migrations
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Peter Nied <[email protected]>
- Loading branch information
Showing
10 changed files
with
216 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...es/src/main/java/org/opensearch/migrations/transformation/rules/IndexMappingNotArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.opensearch.migrations.transformation.rules; | ||
|
||
import java.util.Map.Entry; | ||
|
||
import org.opensearch.migrations.transformation.CanApplyResult; | ||
import org.opensearch.migrations.transformation.TransformationRule; | ||
import org.opensearch.migrations.transformation.Version.Product; | ||
import org.opensearch.migrations.transformation.Version; | ||
import org.opensearch.migrations.transformation.VersionRange; | ||
import org.opensearch.migrations.transformation.entity.Index; | ||
|
||
|
||
public class IndexMappingNotArray implements TransformationRule<Index> { | ||
|
||
@Override | ||
public VersionRange supportedSourceVersionRange() { | ||
return new VersionRange( | ||
new Version(Product.ELASTICSEARCH, 0, 0, 0), | ||
new Version(Product.ELASTICSEARCH, 7, 0, 0) | ||
); | ||
} | ||
|
||
@Override | ||
public VersionRange supportedTargetVersionRange() { | ||
return new VersionRange( | ||
new Version(Product.OPENSEARCH, 0, 0, 0), | ||
new Version(Product.OPENSEARCH, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE) | ||
); | ||
} | ||
|
||
@Override | ||
public CanApplyResult canApply(final Index index) { | ||
final var mappingNode = index.raw().get("mappings"); | ||
if (mappingNode.isNull() || mappingNode.size() > 1) { | ||
return CanApplyResult.UNSUPPORTED; | ||
} | ||
|
||
if (mappingNode.isObject()) { | ||
return CanApplyResult.NO; | ||
} | ||
|
||
return CanApplyResult.YES; | ||
} | ||
|
||
@Override | ||
public boolean applyTransformation(final Index index) { | ||
if (CanApplyResult.YES != canApply(index)) { | ||
return false; | ||
} | ||
|
||
final var mappingsNode = index.raw().get("mappings"); | ||
final var inner = mappingsNode.get(0); | ||
|
||
index.raw().set("mappings", inner); | ||
|
||
return true; | ||
} | ||
} |
Oops, something went wrong.