-
Notifications
You must be signed in to change notification settings - Fork 326
Add TransformFunctionProvider to DynamicConfigTransformer #6881
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
Open
kkondaka
wants to merge
5
commits into
opensearch-project:main
Choose a base branch
from
kkondaka:dyn-config-xfmr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2947aee
Add TransformFunctionProvider to DynamicConfigTransformer
kkondaka 83d632c
Fixed checkstyle errors
kkondaka a1df854
Fixed License headers
kkondaka cbbf7cf
Fixed failing coverage tests in aws-plugin
kkondaka 0e0b838
Addressed review comments
kkondaka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
...pi/src/main/java/org/opensearch/dataprepper/model/annotations/TransformationFunction.java
This file contains hidden or 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,34 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.dataprepper.model.annotations; | ||
|
|
||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * Marks a method as a pipeline transformation function that can be invoked | ||
| * dynamically from template YAML files via the {@code FUNCTION_NAME} placeholder. | ||
| * <p> | ||
| * Annotated methods must be {@code public static} and accept a single {@code String} | ||
| * parameter, returning a {@code String} result. | ||
| * <p> | ||
| * The enclosing class must implement | ||
| * {@link org.opensearch.dataprepper.model.plugin.PipelineTransformFunctionProvider}. | ||
| * | ||
| * @since 2.12 | ||
| */ | ||
| @Documented | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target({ElementType.METHOD}) | ||
| public @interface TransformationFunction { | ||
| } |
24 changes: 24 additions & 0 deletions
24
.../main/java/org/opensearch/dataprepper/model/plugin/PipelineTransformFunctionProvider.java
This file contains hidden or 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,24 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.dataprepper.model.plugin; | ||
|
|
||
| /** | ||
| * Marker interface for classes that provide pipeline transformation functions. | ||
| * Classes implementing this interface can be referenced in rule YAML files via | ||
| * the {@code function_providers} field and have their methods invoked dynamically | ||
| * during pipeline template transformation. | ||
| * <p> | ||
| * Methods intended to be callable from templates must also be annotated with | ||
| * {@link org.opensearch.dataprepper.model.annotations.TransformationFunction}. | ||
| * | ||
| * @since 2.12 | ||
| */ | ||
| public interface PipelineTransformFunctionProvider { | ||
| } |
70 changes: 70 additions & 0 deletions
70
...rc/test/java/org/opensearch/dataprepper/model/annotations/TransformationFunctionTest.java
This file contains hidden or 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,70 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.dataprepper.model.annotations; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.lang.annotation.Documented; | ||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| class TransformationFunctionTest { | ||
|
|
||
| @Test | ||
| void annotation_is_retained_at_runtime() { | ||
| Retention retention = TransformationFunction.class.getAnnotation(Retention.class); | ||
| assertNotNull(retention); | ||
| assertThat(retention.value(), equalTo(RetentionPolicy.RUNTIME)); | ||
| } | ||
|
|
||
| @Test | ||
| void annotation_targets_methods() { | ||
| Target target = TransformationFunction.class.getAnnotation(Target.class); | ||
| assertNotNull(target); | ||
| assertThat(target.value().length, equalTo(1)); | ||
| assertThat(target.value()[0], equalTo(ElementType.METHOD)); | ||
| } | ||
|
|
||
| @Test | ||
| void annotation_is_documented() { | ||
| Documented documented = TransformationFunction.class.getAnnotation(Documented.class); | ||
| assertNotNull(documented); | ||
| } | ||
|
|
||
| @Test | ||
| void annotation_is_present_on_annotated_method() throws NoSuchMethodException { | ||
| assertTrue(AnnotatedClass.class.getMethod("annotatedMethod", String.class) | ||
| .isAnnotationPresent(TransformationFunction.class)); | ||
| } | ||
|
|
||
| @Test | ||
| void annotation_is_not_present_on_unannotated_method() throws NoSuchMethodException { | ||
| assertTrue(!AnnotatedClass.class.getMethod("unannotatedMethod", String.class) | ||
| .isAnnotationPresent(TransformationFunction.class)); | ||
| } | ||
|
|
||
| static class AnnotatedClass { | ||
| @TransformationFunction | ||
| public static String annotatedMethod(String input) { | ||
| return input; | ||
| } | ||
|
|
||
| public static String unannotatedMethod(String input) { | ||
| return input; | ||
| } | ||
| } | ||
| } |
66 changes: 66 additions & 0 deletions
66
...t/java/org/opensearch/dataprepper/model/plugin/PipelineTransformFunctionProviderTest.java
This file contains hidden or 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,66 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.dataprepper.model.plugin; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| class PipelineTransformFunctionProviderTest { | ||
|
|
||
| @Test | ||
| void implementing_class_is_assignable_from_interface() { | ||
| PipelineTransformFunctionProvider provider = new TestFunctionProvider(); | ||
| assertNotNull(provider); | ||
| assertTrue(provider instanceof PipelineTransformFunctionProvider); | ||
| } | ||
|
|
||
| @Test | ||
| void interface_is_assignable_from_implementing_class() { | ||
| assertThat(PipelineTransformFunctionProvider.class.isAssignableFrom(TestFunctionProvider.class), | ||
| equalTo(true)); | ||
| } | ||
|
|
||
| @Test | ||
| void interface_is_not_assignable_from_non_implementing_class() { | ||
| assertThat(PipelineTransformFunctionProvider.class.isAssignableFrom(NonProvider.class), | ||
| equalTo(false)); | ||
| } | ||
|
|
||
| @Test | ||
| void interface_has_no_declared_methods() { | ||
| assertThat(PipelineTransformFunctionProvider.class.getDeclaredMethods().length, equalTo(0)); | ||
| } | ||
|
|
||
| @Test | ||
| void interface_is_public() { | ||
| assertTrue(java.lang.reflect.Modifier.isPublic(PipelineTransformFunctionProvider.class.getModifiers())); | ||
| } | ||
|
|
||
| @Test | ||
| void interface_is_an_interface() { | ||
| assertTrue(PipelineTransformFunctionProvider.class.isInterface()); | ||
| } | ||
|
|
||
| static class TestFunctionProvider implements PipelineTransformFunctionProvider { | ||
| public static String sampleFunction(String input) { | ||
| return input; | ||
| } | ||
| } | ||
|
|
||
| static class NonProvider { | ||
| public static String someMethod(String input) { | ||
| return input; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should have a special requirement on the package name as additional protection. For example, the package name must contain
dataprepper_transformer. This would place a requirement for packages like:org.opensearch.dataprepper.documentdb.dataprepper_transformer.MyTransformercom.mycompany.myplugin.dataprepper_transformer.MyTransformer