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));
}
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));
}
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)));
}
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);
}
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));
}
Aggregations