-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Logstash attributes mapper to use template pattern
Signed-off-by: Asif Sohail Mohammed <[email protected]>
- Loading branch information
1 parent
54f8ce7
commit 8126cc3
Showing
3 changed files
with
76 additions
and
45 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
...a/org/opensearch/dataprepper/logstash/mapping/AbstractLogstashPluginAttributesMapper.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,54 @@ | ||
package org.opensearch.dataprepper.logstash.mapping; | ||
|
||
import org.opensearch.dataprepper.logstash.model.LogstashAttribute; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Collection; | ||
import java.util.Objects; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.LinkedHashMap; | ||
|
||
public abstract class AbstractLogstashPluginAttributesMapper implements LogstashPluginAttributesMapper { | ||
private static final Logger LOG = LoggerFactory.getLogger(AbstractLogstashPluginAttributesMapper.class); | ||
|
||
@Override | ||
public Map<String, Object> mapAttributes(final List<LogstashAttribute> logstashAttributes, final LogstashAttributesMappings logstashAttributesMappings) { | ||
|
||
Objects.requireNonNull(logstashAttributes); | ||
Objects.requireNonNull(logstashAttributesMappings); | ||
Objects.requireNonNull(logstashAttributesMappings.getMappedAttributeNames()); | ||
Objects.requireNonNull(logstashAttributesMappings.getAdditionalAttributes()); | ||
|
||
final Map<String, Object> pluginSettings = new LinkedHashMap<>(logstashAttributesMappings.getAdditionalAttributes()); | ||
final Map<String, String> mappedAttributeNames = logstashAttributesMappings.getMappedAttributeNames(); | ||
|
||
Collection<String> customMappedAttributeNames = getCustomMappedAttributeNames(); | ||
|
||
logstashAttributes | ||
.stream() | ||
.filter(logstashAttribute -> !customMappedAttributeNames.contains(logstashAttribute.getAttributeName())) | ||
.forEach(logstashAttribute -> { | ||
if (mappedAttributeNames.containsKey(logstashAttribute.getAttributeName())) { | ||
pluginSettings.put( | ||
mappedAttributeNames.get(logstashAttribute.getAttributeName()), | ||
logstashAttribute.getAttributeValue().getValue() | ||
); | ||
} | ||
else { | ||
LOG.warn("Attribute name {} is not found in mapping file.", logstashAttribute.getAttributeName()); | ||
} | ||
}); | ||
|
||
if (!customMappedAttributeNames.isEmpty()) { | ||
mapCustomAttributes(logstashAttributes, logstashAttributesMappings, pluginSettings); | ||
} | ||
|
||
return pluginSettings; | ||
} | ||
|
||
abstract void mapCustomAttributes(List<LogstashAttribute> logstashAttributes, LogstashAttributesMappings logstashAttributesMappings, Map<String, Object> pluginSettings); | ||
|
||
abstract Collection<String> getCustomMappedAttributeNames(); | ||
} |
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