-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OutputCodecContext for output codecs.
Signed-off-by: Aiden Dai <[email protected]>
- Loading branch information
Showing
2 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
data-prepper-api/src/main/java/org/opensearch/dataprepper/model/sink/OutputCodecContext.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,52 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.model.sink; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Data Prepper Output Codec Context class. | ||
* The context contains information that are shared and may be used among {@link org.opensearch.dataprepper.model.codec.OutputCodec} | ||
*/ | ||
public class OutputCodecContext { | ||
|
||
private final String tagsTargetKey; | ||
|
||
private final List<String> includeKeys; | ||
private final List<String> excludeKeys; | ||
|
||
public OutputCodecContext() { | ||
this(null, Collections.emptyList(), Collections.emptyList()); | ||
} | ||
|
||
|
||
public OutputCodecContext(String tagsTargetKey, List<String> includeKeys, List<String> excludeKeys) { | ||
this.tagsTargetKey = tagsTargetKey; | ||
this.includeKeys = includeKeys; | ||
this.excludeKeys = excludeKeys; | ||
} | ||
|
||
|
||
public static OutputCodecContext fromSinkContext(SinkContext sinkContext) { | ||
if (sinkContext == null) { | ||
return new OutputCodecContext(); | ||
} | ||
return new OutputCodecContext(sinkContext.getTagsTargetKey(), sinkContext.getIncludeKeys(), sinkContext.getExcludeKeys()); | ||
} | ||
|
||
public String getTagsTargetKey() { | ||
return tagsTargetKey; | ||
} | ||
|
||
public List<String> getIncludeKeys() { | ||
return includeKeys; | ||
} | ||
|
||
public List<String> getExcludeKeys() { | ||
return excludeKeys; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...epper-api/src/test/java/org/opensearch/dataprepper/model/sink/OutputCodecContextTest.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,59 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.model.sink; | ||
|
||
import org.apache.commons.lang3.RandomStringUtils; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
public class OutputCodecContextTest { | ||
|
||
|
||
@Test | ||
public void testOutputCodecContextBasic() { | ||
final String testTagsTargetKey = RandomStringUtils.randomAlphabetic(6); | ||
final List<String> testIncludeKeys = Collections.emptyList(); | ||
final List<String> testExcludeKeys = Collections.emptyList(); | ||
OutputCodecContext codecContext = new OutputCodecContext(testTagsTargetKey, testIncludeKeys, testExcludeKeys); | ||
assertThat(codecContext.getTagsTargetKey(), equalTo(testTagsTargetKey)); | ||
assertThat(codecContext.getIncludeKeys(), equalTo(testIncludeKeys)); | ||
assertThat(codecContext.getExcludeKeys(), equalTo(testExcludeKeys)); | ||
|
||
OutputCodecContext emptyContext = new OutputCodecContext(); | ||
assertNull(emptyContext.getTagsTargetKey()); | ||
assertThat(emptyContext.getIncludeKeys(), equalTo(testIncludeKeys)); | ||
assertThat(emptyContext.getExcludeKeys(), equalTo(testExcludeKeys)); | ||
|
||
|
||
} | ||
|
||
@Test | ||
public void testOutputCodecContextAdapter() { | ||
final String testTagsTargetKey = RandomStringUtils.randomAlphabetic(6); | ||
final List<String> testIncludeKeys = Collections.emptyList(); | ||
final List<String> testExcludeKeys = Collections.emptyList(); | ||
|
||
SinkContext sinkContext = new SinkContext(testTagsTargetKey, null, testIncludeKeys, testExcludeKeys); | ||
|
||
OutputCodecContext codecContext = OutputCodecContext.fromSinkContext(sinkContext); | ||
assertThat(codecContext.getTagsTargetKey(), equalTo(testTagsTargetKey)); | ||
assertThat(codecContext.getIncludeKeys(), equalTo(testIncludeKeys)); | ||
assertThat(codecContext.getExcludeKeys(), equalTo(testExcludeKeys)); | ||
|
||
OutputCodecContext emptyContext = OutputCodecContext.fromSinkContext(null); | ||
assertNull(emptyContext.getTagsTargetKey()); | ||
assertThat(emptyContext.getIncludeKeys(), equalTo(testIncludeKeys)); | ||
assertThat(emptyContext.getExcludeKeys(), equalTo(testExcludeKeys)); | ||
|
||
|
||
} | ||
} |