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.
Lots of improvements for jinjava and type mappings transformations an…
…d other findings along the way * JsonAccumulator (replayer) no longer throws when numeric values are > 32 bit ranges - now we use longs and doubles to parse the string sequences into, so some tuple transformation exceptions cease. * regex replace filters now can be configured via the jinjava config to specify what format the replacement strings should be in. The format is controlled by a series of regex replacements on the replacement string itself - e.g. to convert \\# to $# so that python-style regexes can be used. Notice that this was done the way that it was so that it's a easier to override and let users tweak for their own specific needs. Things get really sticky on malformed input and I don't have an interest in fully supporting that we behave the same on malformed escape sequences. Letting users have the option to specify the exact escaping seems like it's a hedge. * template files (resources) are still loaded from the jarfile, but users can add more templates and override existing ones. New templates can be passed through the json config to the provider in a simple key->template dictionary. * VARIANTs of top-level templates are gone. Now there's a top-level transformByType.j2 that does some tests on the incoming document and routes switches for the replayer template or the document backfill one (implementation and tests are still pending). That simplifies contextual awareness where this transformer no longer needs to have it. To round that change out, replayer.j2 was renamed httpRequests.j2 since that's a more accurate name now. * log_value and log_value_and_return are bound for jinjava templates to log through Slf4j. * There's still more work to be done in rewriteCreateIndexRequest to work w/ various versions of ES so that we can figure out when type mappings should/shouldn't be present and do the right thing. Now that we have source properties, that's just a matter of pulling a field and writing some more template code. * Converted all of the test indices and types to NOT include upper-case characters to avoid confusion and exercising transforms in ways that they'll never need to be tested. Signed-off-by: Greg Schohn <greg.schohn@gmail.com>
- Loading branch information
1 parent
5be3ddc
commit 73c8e13
Showing
37 changed files
with
519 additions
and
144 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
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
20 changes: 20 additions & 0 deletions
20
...aTransformer/src/main/java/org/opensearch/migrations/transform/jinjava/JinjavaConfig.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,20 @@ | ||
package org.opensearch.migrations.transform.jinjava; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class JinjavaConfig { | ||
@JsonProperty("regexReplacementConversionPatterns") | ||
private List<Map.Entry<String, String>> regexReplacementConversionPatterns; | ||
|
||
@JsonProperty("regexReplacementConversionPatterns") | ||
Map<String, String> namedScripts; | ||
} |
28 changes: 28 additions & 0 deletions
28
...avaTransformer/src/main/java/org/opensearch/migrations/transform/jinjava/LogFunction.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,28 @@ | ||
package org.opensearch.migrations.transform.jinjava; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.slf4j.event.Level; | ||
|
||
@Slf4j | ||
public class LogFunction { | ||
|
||
/** | ||
* Called from templates through the registration in the JinjavaTransformer class | ||
*/ | ||
public static Object logValueAndReturn(String levelStr, Object valueToLog, Object valueToReturn) { | ||
Level level; | ||
try { | ||
level = Level.valueOf(levelStr); | ||
} catch (IllegalArgumentException e) { | ||
log.atError().setMessage("Could not parse the level as it was passed in, so using ERROR. Level={}") | ||
.addArgument(levelStr).log(); | ||
level = Level.ERROR; | ||
} | ||
log.atLevel(level).setMessage("{}").addArgument(valueToLog).log(); | ||
return valueToReturn; | ||
} | ||
|
||
public static void logValue(String level, Object valueToLog) { | ||
logValueAndReturn(level, valueToLog, null); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
...rmer/src/main/java/org/opensearch/migrations/transform/jinjava/RegexReplaceException.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,31 @@ | ||
package org.opensearch.migrations.transform.jinjava; | ||
|
||
import java.util.StringJoiner; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class RegexReplaceException extends RuntimeException { | ||
final String input; | ||
final String pattern; | ||
final String replacement; | ||
final String rewrittenReplacement; | ||
|
||
public RegexReplaceException(Throwable cause, String input, String pattern, String replacement, String rewrittenReplacement) { | ||
super(cause); | ||
this.input = input; | ||
this.pattern = pattern; | ||
this.replacement = replacement; | ||
this.rewrittenReplacement = rewrittenReplacement; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return super.getMessage() + | ||
new StringJoiner(", ", "{", "}") | ||
.add("input='" + input + "'") | ||
.add("pattern='" + pattern + "'") | ||
.add("replacement='" + replacement + "'") | ||
.add("rewrittenReplacement='" + rewrittenReplacement + "'"); | ||
} | ||
} |
Oops, something went wrong.