forked from opensearch-project/data-prepper
-
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.
Rename s3 sink object metadata config options (opensearch-project#5041)
* Addressed review comments. Introduced a new config, will deprecate the old config Signed-off-by: Kondaka <[email protected]> * Addressed review comments. Introduced a new config for metadata Signed-off-by: Kondaka <[email protected]> * Addressed review comments. Created a separate class for object metadata Signed-off-by: Kondaka <[email protected]> * Addressed review comments. Signed-off-by: Kondaka <[email protected]> * Fixed indentation Signed-off-by: Kondaka <[email protected]> --------- Signed-off-by: Kondaka <[email protected]>
- Loading branch information
Showing
7 changed files
with
173 additions
and
8 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...gins/s3-sink/src/main/java/org/opensearch/dataprepper/plugins/sink/s3/ObjectMetadata.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,43 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class ObjectMetadata { | ||
private Map<String, String> metadata; | ||
private ObjectMetadataConfig objectMetadataConfig; | ||
private PredefinedObjectMetadata predefinedObjectMetadata; | ||
|
||
public ObjectMetadata(final Object objectMetadataConfig) { | ||
if (objectMetadataConfig instanceof ObjectMetadataConfig) { | ||
this.objectMetadataConfig = (ObjectMetadataConfig)objectMetadataConfig; | ||
} else { // instanceof PredefinedObjectMetadata | ||
this.predefinedObjectMetadata = (PredefinedObjectMetadata)objectMetadataConfig; | ||
} | ||
this.metadata = new HashMap<String, String>(); | ||
} | ||
|
||
public void setEventCount(final int eventCount) { | ||
String numberOfEventsKey = null; | ||
if (objectMetadataConfig != null) { | ||
numberOfEventsKey = objectMetadataConfig.getNumberOfEventsKey(); | ||
} else if (predefinedObjectMetadata != null) { | ||
numberOfEventsKey = predefinedObjectMetadata.getNumberOfObjects(); | ||
} | ||
if (numberOfEventsKey != null) { | ||
metadata.put(numberOfEventsKey, Integer.toString(eventCount)); | ||
} | ||
} | ||
|
||
public Map<String, String> get() { | ||
return metadata; | ||
} | ||
|
||
} | ||
|
||
|
18 changes: 18 additions & 0 deletions
18
...3-sink/src/main/java/org/opensearch/dataprepper/plugins/sink/s3/ObjectMetadataConfig.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,18 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public class ObjectMetadataConfig { | ||
@JsonProperty("number_of_events_key") | ||
private String numberOfEventsKey; | ||
|
||
public String getNumberOfEventsKey() { | ||
return numberOfEventsKey; | ||
} | ||
|
||
} |
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
30 changes: 30 additions & 0 deletions
30
...nk/src/test/java/org/opensearch/dataprepper/plugins/sink/s3/ObjectMetadataConfigTest.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,30 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import org.opensearch.dataprepper.test.helper.ReflectivelySetField; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import java.util.UUID; | ||
|
||
public class ObjectMetadataConfigTest { | ||
@Test | ||
void test_default() { | ||
assertThat(new ObjectMetadataConfig().getNumberOfEventsKey(), equalTo(null)); | ||
} | ||
|
||
@Test | ||
void test_number_of_events_key() throws Exception { | ||
final String numberOfEventsKey = UUID.randomUUID().toString(); | ||
final ObjectMetadataConfig objectUnderTest = new ObjectMetadataConfig(); | ||
ReflectivelySetField.setField(ObjectMetadataConfig.class, objectUnderTest, "numberOfEventsKey", numberOfEventsKey); | ||
assertThat(objectUnderTest.getNumberOfEventsKey(), equalTo(numberOfEventsKey)); | ||
} | ||
} | ||
|
58 changes: 58 additions & 0 deletions
58
.../s3-sink/src/test/java/org/opensearch/dataprepper/plugins/sink/s3/ObjectMetadataTest.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 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.sink.s3; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import org.mockito.Mock; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.Random; | ||
import java.util.UUID; | ||
|
||
public class ObjectMetadataTest { | ||
private ObjectMetadata objectMetadata; | ||
@Mock | ||
private ObjectMetadataConfig objectMetadataConfig; | ||
@Mock | ||
private PredefinedObjectMetadata predefinedObjectMetadata; | ||
private String numberOfEventsKey; | ||
|
||
private ObjectMetadata createObjectUnderTest(Object metadataConfig) { | ||
return new ObjectMetadata(metadataConfig); | ||
} | ||
|
||
@BeforeEach | ||
public void setup() { | ||
objectMetadataConfig = mock(ObjectMetadataConfig.class); | ||
predefinedObjectMetadata = mock(PredefinedObjectMetadata.class); | ||
numberOfEventsKey = UUID.randomUUID().toString(); | ||
when(objectMetadataConfig.getNumberOfEventsKey()).thenReturn(numberOfEventsKey); | ||
when(predefinedObjectMetadata.getNumberOfObjects()).thenReturn(numberOfEventsKey); | ||
} | ||
|
||
@Test | ||
public void test_setEventCount_with_PredefinedObjectMetadata() { | ||
objectMetadata = createObjectUnderTest(predefinedObjectMetadata); | ||
Random random = new Random(); | ||
Integer numEvents = Math.abs(random.nextInt()); | ||
objectMetadata.setEventCount(numEvents); | ||
assertThat(objectMetadata.get().get(numberOfEventsKey), equalTo(Integer.toString(numEvents))); | ||
} | ||
|
||
@Test | ||
void test_setEventCount_with_ObjectMetadata() { | ||
objectMetadata = createObjectUnderTest(objectMetadataConfig); | ||
Random random = new Random(); | ||
Integer numEvents = Math.abs(random.nextInt()); | ||
objectMetadata.setEventCount(numEvents); | ||
assertThat(objectMetadata.get().get(numberOfEventsKey), equalTo(Integer.toString(numEvents))); | ||
} | ||
|
||
} |