in metron-platform/metron-common/src/main/java/org/apache/metron/common/configuration/enrichment/SensorEnrichmentUpdateConfig.java [131:220]
public static void updateSensorConfigs( SourceConfigHandler scHandler
, Map<String, FieldList> sensorToFieldList
) throws Exception
{
Map<String, SensorEnrichmentConfig> sourceConfigsChanged = new HashMap<>();
for (Map.Entry<String, FieldList> kv : sensorToFieldList.entrySet()) {
SensorEnrichmentConfig config = findConfigBySensorType(scHandler, sourceConfigsChanged, kv.getKey());
Map<String, Object > fieldMap = null;
Map<String, List<String>> fieldToTypeMap = null;
List<String> fieldList = null;
if(kv.getValue().type == Type.THREAT_INTEL) {
fieldMap = config.getThreatIntel().getFieldMap();
if(fieldMap!= null) {
fieldList = (List<String>)fieldMap.get(Constants.SIMPLE_HBASE_THREAT_INTEL);
} else {
fieldMap = new HashMap<>();
}
if(fieldList == null) {
fieldList = new ArrayList<>();
fieldMap.put(Constants.SIMPLE_HBASE_THREAT_INTEL, fieldList);
}
fieldToTypeMap = config.getThreatIntel().getFieldToTypeMap();
if(fieldToTypeMap == null) {
fieldToTypeMap = new HashMap<>();
config.getThreatIntel().setFieldToTypeMap(fieldToTypeMap);
}
}
else if(kv.getValue().type == Type.ENRICHMENT) {
fieldMap = config.getEnrichment().getFieldMap();
if(fieldMap!= null) {
fieldList = (List<String>)fieldMap.get(Constants.SIMPLE_HBASE_ENRICHMENT);
} else {
fieldMap = new HashMap<>();
}
if(fieldList == null) {
fieldList = new ArrayList<>();
fieldMap.put(Constants.SIMPLE_HBASE_ENRICHMENT, fieldList);
}
fieldToTypeMap = config.getEnrichment().getFieldToTypeMap();
if(fieldToTypeMap == null) {
fieldToTypeMap = new HashMap<>();
config.getEnrichment().setFieldToTypeMap(fieldToTypeMap);
}
}
if(fieldToTypeMap == null || fieldMap == null) {
LOG.debug("fieldToTypeMap is null or fieldMap is null, so skipping");
continue;
}
//Add the additional fields to the field list associated with the hbase adapter
{
HashSet<String> fieldSet = new HashSet<>(fieldList);
List<String> additionalFields = new ArrayList<>();
for (String field : kv.getValue().getFieldToEnrichmentTypes().keySet()) {
if (!fieldSet.contains(field)) {
additionalFields.add(field);
}
}
//adding only the ones that we don't already have to the field list
if (additionalFields.size() > 0) {
LOG.debug("Adding additional fields: {}", () -> Joiner.on(',').join(additionalFields));
fieldList.addAll(additionalFields);
sourceConfigsChanged.put(kv.getKey(), config);
}
}
//Add the additional enrichment types to the mapping between the fields
{
for(Map.Entry<String, List<String>> fieldToType : kv.getValue().getFieldToEnrichmentTypes().entrySet()) {
String field = fieldToType.getKey();
final HashSet<String> types = new HashSet<>(fieldToType.getValue());
int sizeBefore = 0;
if(fieldToTypeMap.containsKey(field)) {
List<String> typeList = (List<String>)fieldToTypeMap.get(field);
sizeBefore = new HashSet<>(typeList).size();
types.addAll(typeList);
}
int sizeAfter = types.size();
boolean changed = sizeBefore != sizeAfter;
if(changed) {
fieldToTypeMap.put(field, new ArrayList<String>() {{
addAll(types);
}});
sourceConfigsChanged.put(kv.getKey(), config);
}
}
}
}
for(Map.Entry<String, SensorEnrichmentConfig> kv : sourceConfigsChanged.entrySet()) {
scHandler.persistConfig(kv.getKey(), kv.getValue());
}
}