Search in sources :

Example 26 with PluginModel

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

the class DateLogstashPluginAttributesMapperTest method convert_match_attribute_with_single_pattern_from_list_to_date_match_list_test.

@Test
void convert_match_attribute_with_single_pattern_from_list_to_date_match_list_test() {
    final LogstashAttribute dateMatchAttribute = buildDateMatchLogstashAttribute(Arrays.asList("logdate", "yyyy-MM-dd"));
    final String dataPrepperMatchAttribute = "match";
    final LogstashAttributesMappings mappings = mock(LogstashAttributesMappings.class);
    when(mappings.getMappedAttributeNames()).thenReturn(Collections.singletonMap(LOGSTASH_DATE_MATCH_ATTRIBUTE_NAME, dataPrepperMatchAttribute));
    final List<PluginModel> actualPluginModel = dateLogstashPluginAttributesMapper.mapAttributes(Collections.singletonList(dateMatchAttribute), mappings);
    assertThat(actualPluginModel, notNullValue());
    assertThat(actualPluginModel.size(), equalTo(1));
    assertThat(actualPluginModel.get(0), notNullValue());
    final List<DateProcessorConfig.DateMatch> expectedMatchSettings = Collections.singletonList(new DateProcessorConfig.DateMatch("logdate", Collections.singletonList("yyyy-MM-dd")));
    final List<DateProcessorConfig.DateMatch> actualMatchSettings = (List<DateProcessorConfig.DateMatch>) actualPluginModel.get(0).getPluginSettings().get(dataPrepperMatchAttribute);
    assertThat(actualMatchSettings, notNullValue());
    assertThat(actualMatchSettings.size(), equalTo(1));
    assertThat(actualPluginModel.get(0).getPluginSettings(), hasKey(dataPrepperMatchAttribute));
    assertThat(actualMatchSettings.get(0).getPatterns().size(), equalTo(1));
    assertThat(actualMatchSettings.get(0).getKey(), equalTo(expectedMatchSettings.get(0).getKey()));
    assertThat(actualMatchSettings.get(0).getPatterns(), equalTo(expectedMatchSettings.get(0).getPatterns()));
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) LogstashAttribute(org.opensearch.dataprepper.logstash.model.LogstashAttribute) ArrayList(java.util.ArrayList) List(java.util.List) DateProcessorConfig(com.amazon.dataprepper.plugins.processor.date.DateProcessorConfig) Test(org.junit.jupiter.api.Test)

Example 27 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_besides_match.

@Test
void mapAttributes_sets_mapped_attributes_besides_match() {
    final String value = UUID.randomUUID().toString();
    final String logstashAttributeName = UUID.randomUUID().toString();
    final LogstashAttribute logstashAttribute = mock(LogstashAttribute.class);
    final LogstashAttributeValue logstashAttributeValue = mock(LogstashAttributeValue.class);
    when(logstashAttributeValue.getValue()).thenReturn(value);
    when(logstashAttribute.getAttributeName()).thenReturn(logstashAttributeName);
    when(logstashAttribute.getAttributeValue()).thenReturn(logstashAttributeValue);
    final String dataPrepperAttribute = UUID.randomUUID().toString();
    final LogstashAttributesMappings mappings = mock(LogstashAttributesMappings.class);
    when(mappings.getMappedAttributeNames()).thenReturn(Collections.singletonMap(logstashAttributeName, dataPrepperAttribute));
    final List<PluginModel> actualPluginModel = createObjectUnderTest().mapAttributes(Collections.singletonList(logstashAttribute), mappings);
    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(dataPrepperAttribute));
    assertThat(actualPluginModel.get(0).getPluginSettings().get(dataPrepperAttribute), equalTo(value));
}
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)

Example 28 with PluginModel

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

the class GrokLogstashPluginAttributesMapperTest method mapAttributes_converts_nested_syntax_in_overwrite_mapped_attributes.

@Test
void mapAttributes_converts_nested_syntax_in_overwrite_mapped_attributes() {
    final LogstashAttribute matchMultiKeysLogstashAttribute = prepareOverwriteLogstashAttribute(Arrays.asList("[outer][key1]", "[outer][key2]"));
    final List<LogstashAttribute> grokAttributes = Collections.singletonList(matchMultiKeysLogstashAttribute);
    final List<String> expectedOverwriteKeys = Arrays.asList("/outer/key1", "/outer/key2");
    final String dataPrepperOverwriteAttribute = "keys_to_overwrite";
    final LogstashAttributesMappings mappings = mock(LogstashAttributesMappings.class);
    when(mappings.getMappedAttributeNames()).thenReturn(Collections.singletonMap("overwrite", dataPrepperOverwriteAttribute));
    final List<PluginModel> actualPluginModels = createObjectUnderTest().mapAttributes(grokAttributes, mappings);
    assertThat(actualPluginModels, notNullValue());
    assertThat(actualPluginModels.size(), equalTo(1));
    assertThat(actualPluginModels.get(0).getPluginSettings(), hasKey(dataPrepperOverwriteAttribute));
    assertThat(actualPluginModels.get(0).getPluginSettings().get(dataPrepperOverwriteAttribute), equalTo(expectedOverwriteKeys));
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) LogstashAttribute(org.opensearch.dataprepper.logstash.model.LogstashAttribute) Test(org.junit.jupiter.api.Test)

Example 29 with PluginModel

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

the class LogstashPluginMapperTest method mapPlugin_with_custom_plugin_mapper_produces_plugins.

@Test
void mapPlugin_with_custom_plugin_mapper_produces_plugins() {
    final LogstashPlugin logstashPlugin = mock(LogstashPlugin.class);
    when(logstashPlugin.getPluginName()).thenReturn("mutate");
    when(pluginMapperProvider.getAttributesMapper(any(LogstashMappingModel.class))).thenReturn(new MutateMapper());
    final LogstashPluginMapper objectUnderTest = createObjectUnderTest();
    final List<PluginModel> pluginModels = objectUnderTest.mapPlugin(logstashPlugin);
    assertThat(pluginModels, notNullValue());
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) LogstashPlugin(org.opensearch.dataprepper.logstash.model.LogstashPlugin) MutateMapper(org.opensearch.dataprepper.logstash.mapping.mutate.MutateMapper) Test(org.junit.jupiter.api.Test)

Example 30 with PluginModel

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

the class LogstashPluginMapperTest method mapPlugin_should_return_PluginModel_with_mapped_attributes.

@Test
void mapPlugin_should_return_PluginModel_with_mapped_attributes() {
    final LogstashPlugin logstashPlugin = mock(LogstashPlugin.class);
    when(logstashPlugin.getPluginName()).thenReturn("amazon_es");
    final Map<String, Object> mappedPluginSettings = Collections.singletonMap(UUID.randomUUID().toString(), UUID.randomUUID().toString());
    when(logstashPluginAttributesMapper.mapAttributes(anyList(), any(LogstashAttributesMappings.class))).thenReturn(Collections.singletonList(new PluginModel("opensearch", mappedPluginSettings)));
    final List<PluginModel> pluginModels = createObjectUnderTest().mapPlugin(logstashPlugin);
    assertThat(pluginModels, notNullValue());
    assertThat(pluginModels.get(0).getPluginSettings(), notNullValue());
    assertThat(pluginModels.get(0).getPluginSettings(), equalTo(mappedPluginSettings));
}
Also used : PluginModel(com.amazon.dataprepper.model.configuration.PluginModel) LogstashPlugin(org.opensearch.dataprepper.logstash.model.LogstashPlugin) 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