Search in sources :

Example 6 with PluginModel

use of com.amazon.dataprepper.model.configuration.PluginModel in project data-prepper by opensearch-project.

the class GrokLogstashPluginAttributesMapperTest method mapAttributes_sets_mapped_attributes_merging_multiple_match.

@Test
void mapAttributes_sets_mapped_attributes_merging_multiple_match() {
    final LogstashAttribute matchMultiKeysLogstashAttribute = prepareHashTypeMatchLogstashAttribute(Arrays.asList(Map.entry("message", "fake message regex 1"), Map.entry("other", "fake other regex")));
    final LogstashAttribute matchMessageLogstashAttribute2 = prepareArrayTypeMatchLogstashAttribute("message", "fake message regex 2");
    final List<LogstashAttribute> matchLogstashAttributes = Arrays.asList(matchMultiKeysLogstashAttribute, matchMessageLogstashAttribute2);
    final Map<String, Object> expectedMatchSettings = Map.of("message", Arrays.asList("fake message regex 1", "fake message regex 2"), "other", Collections.singletonList("fake other regex"));
    final String dataPrepperMatchAttribute = "match";
    final LogstashAttributesMappings mappings = mock(LogstashAttributesMappings.class);
    when(mappings.getMappedAttributeNames()).thenReturn(Collections.singletonMap(LOGSTASH_GROK_MATCH_ATTRIBUTE_NAME, dataPrepperMatchAttribute));
    final List<PluginModel> actualPluginModels = createObjectUnderTest().mapAttributes(matchLogstashAttributes, mappings);
    assertThat(actualPluginModels, notNullValue());
    assertThat(actualPluginModels.size(), equalTo(1));
    assertThat(actualPluginModels.get(0).getPluginSettings(), hasKey(dataPrepperMatchAttribute));
    assertThat(actualPluginModels.get(0).getPluginSettings().get(dataPrepperMatchAttribute), equalTo(expectedMatchSettings));
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) LogstashAttribute(org.opensearch.dataprepper.logstash.model.LogstashAttribute) Test(org.junit.jupiter.api.Test)

Example 7 with PluginModel

use of com.amazon.dataprepper.model.configuration.PluginModel in project data-prepper by opensearch-project.

the class OpenSearchPluginAttributesMapperTest method convert_logstashIndexPattern_joda_to_dataPrepperIndexPattern_java8.

@ParameterizedTest
@ArgumentsSource(JodaToJava8IndicesArgumentsProvider.class)
void convert_logstashIndexPattern_joda_to_dataPrepperIndexPattern_java8(final String logstashIndex, final String expectedIndex) {
    final LogstashAttribute logstashAttribute = createLogstashIndexAttribute(logstashIndex);
    final LogstashAttributesMappings logstashAttributesMappings = mock(LogstashAttributesMappings.class);
    when(logstashAttributesMappings.getMappedAttributeNames()).thenReturn(Collections.singletonMap(LOGSTASH_OPENSEARCH_INDEX_ATTRIBUTE_NAME, DATA_PREPPER_OPENSEARCH_INDEX_ATTRIBUTE));
    final List<PluginModel> actualPluginModel = createObjectUnderTest().mapAttributes(Collections.singletonList(logstashAttribute), logstashAttributesMappings);
    assertThat(actualPluginModel, Matchers.notNullValue());
    assertThat(actualPluginModel.size(), Matchers.equalTo(1));
    assertThat(actualPluginModel.get(0), Matchers.notNullValue());
    assertThat(actualPluginModel.get(0).getPluginSettings(), notNullValue());
    assertThat(actualPluginModel.get(0).getPluginSettings().size(), equalTo(1));
    assertThat(actualPluginModel.get(0).getPluginSettings(), hasKey(DATA_PREPPER_OPENSEARCH_INDEX_ATTRIBUTE));
    assertThat(actualPluginModel.get(0).getPluginSettings().get(DATA_PREPPER_OPENSEARCH_INDEX_ATTRIBUTE), equalTo(expectedIndex));
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) LogstashAttribute(org.opensearch.dataprepper.logstash.model.LogstashAttribute) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 8 with PluginModel

use of com.amazon.dataprepper.model.configuration.PluginModel in project data-prepper by opensearch-project.

the class OpenSearchPluginAttributesMapperTest method convert_emptyString_indexAttribute_to_return_pluginSettings_with_no_index_key.

@Test
void convert_emptyString_indexAttribute_to_return_pluginSettings_with_no_index_key() {
    final LogstashAttribute logstashAttribute = mock(LogstashAttribute.class);
    final LogstashAttributeValue logstashAttributeValue = mock(LogstashAttributeValue.class);
    when(logstashAttribute.getAttributeName()).thenReturn(UUID.randomUUID().toString());
    when(logstashAttribute.getAttributeValue()).thenReturn(logstashAttributeValue);
    when(logstashAttributeValue.getAttributeValueType()).thenReturn(LogstashValueType.STRING);
    when(logstashAttributeValue.getValue()).thenReturn(UUID.randomUUID().toString());
    final LogstashAttributesMappings logstashAttributesMappings = mock(LogstashAttributesMappings.class);
    when(logstashAttributesMappings.getMappedAttributeNames()).thenReturn(Collections.emptyMap());
    final List<PluginModel> actualPluginModel = createObjectUnderTest().mapAttributes(Collections.singletonList(logstashAttribute), logstashAttributesMappings);
    assertThat(actualPluginModel, Matchers.notNullValue());
    assertThat(actualPluginModel.size(), Matchers.equalTo(1));
    assertThat(actualPluginModel.get(0), Matchers.notNullValue());
    assertThat(actualPluginModel.get(0).getPluginSettings().size(), equalTo(0));
    assertThat(actualPluginModel.get(0).getPluginSettings(), not(hasKey(DATA_PREPPER_OPENSEARCH_INDEX_ATTRIBUTE)));
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) LogstashAttributeValue(org.opensearch.dataprepper.logstash.model.LogstashAttributeValue) LogstashAttribute(org.opensearch.dataprepper.logstash.model.LogstashAttribute) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with PluginModel

use of com.amazon.dataprepper.model.configuration.PluginModel in project data-prepper by opensearch-project.

the class AggregateProcessor method loadAggregateAction.

private AggregateAction loadAggregateAction(final PluginFactory pluginFactory) {
    final PluginModel actionConfiguration = aggregateProcessorConfig.getAggregateAction();
    final PluginSetting actionPluginSetting = new PluginSetting(actionConfiguration.getPluginName(), actionConfiguration.getPluginSettings());
    return pluginFactory.loadPlugin(AggregateAction.class, actionPluginSetting);
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) PluginSetting(com.amazon.dataprepper.model.configuration.PluginSetting)

Example 10 with PluginModel

use of com.amazon.dataprepper.model.configuration.PluginModel in project data-prepper by opensearch-project.

the class AbstractLogstashPluginAttributesMapperTest method mapAttributes_with_defaults_should_set_the_default_attribute_name_when_different_from_logstash_attribute_name.

@Test
void mapAttributes_with_defaults_should_set_the_default_attribute_name_when_different_from_logstash_attribute_name() {
    final String defaultSettingName = UUID.randomUUID().toString();
    final String defaultSettingValue = UUID.randomUUID().toString();
    final String attributeName = UUID.randomUUID().toString();
    final String attributeValue = UUID.randomUUID().toString();
    when(mappings.getDefaultSettings()).thenReturn(Collections.singletonMap(defaultSettingName, defaultSettingValue));
    when(mappings.getMappedAttributeNames()).thenReturn(Collections.singletonMap(attributeName, defaultSettingName));
    final LogstashAttribute logstashAttribute = mock(LogstashAttribute.class);
    when(logstashAttribute.getAttributeName()).thenReturn(attributeName);
    final LogstashAttributeValue logstashAttributeValue = mock(LogstashAttributeValue.class);
    when(logstashAttribute.getAttributeValue()).thenReturn(logstashAttributeValue);
    when(logstashAttributeValue.getValue()).thenReturn(attributeValue);
    final List<LogstashAttribute> logstashAttributes = Collections.singletonList(logstashAttribute);
    final List<PluginModel> pluginModels = createObjectUnderTest().mapAttributes(logstashAttributes, mappings);
    assertThat(pluginModels, notNullValue());
    assertThat(pluginModels.size(), equalTo(1));
    final PluginModel actualPluginModel = pluginModels.get(0);
    assertThat(actualPluginModel, notNullValue());
    assertThat(actualPluginModel.getPluginSettings(), notNullValue());
    assertThat(actualPluginModel.getPluginSettings(), hasKey(defaultSettingName));
    assertThat(actualPluginModel.getPluginSettings(), not(hasKey(attributeName)));
    assertThat(actualPluginModel.getPluginSettings().get(defaultSettingName), equalTo(attributeValue));
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) LogstashAttributeValue(org.opensearch.dataprepper.logstash.model.LogstashAttributeValue) LogstashAttribute(org.opensearch.dataprepper.logstash.model.LogstashAttribute) Test(org.junit.jupiter.api.Test)

Aggregations

PluginModel (com.amazon.dataprepper.model.configuration.PluginModel)31 Test (org.junit.jupiter.api.Test)21 LogstashAttribute (org.opensearch.dataprepper.logstash.model.LogstashAttribute)17 List (java.util.List)8 ArrayList (java.util.ArrayList)6 PluginSetting (com.amazon.dataprepper.model.configuration.PluginSetting)5 DateProcessorConfig (com.amazon.dataprepper.plugins.processor.date.DateProcessorConfig)5 HashMap (java.util.HashMap)5 LogstashAttributeValue (org.opensearch.dataprepper.logstash.model.LogstashAttributeValue)5 LinkedList (java.util.LinkedList)3 Map (java.util.Map)3 LogstashPlugin (org.opensearch.dataprepper.logstash.model.LogstashPlugin)3 DataPrepperConfiguration (com.amazon.dataprepper.parser.model.DataPrepperConfiguration)2 Objects (java.util.Objects)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 LogstashMappingException (org.opensearch.dataprepper.logstash.exception.LogstashMappingException)2 PipelineModel (com.amazon.dataprepper.model.configuration.PipelineModel)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1