Search in sources :

Example 1 with LookupDefaultSingleValue

use of org.graylog2.lookup.LookupDefaultSingleValue in project graylog2-server by Graylog2.

the class LookupTableService method createLookupTable.

private LookupTable createLookupTable(LookupTableDto dto) {
    final LookupCache cache = idToCache.get(dto.cacheId());
    if (cache == null) {
        LOG.warn("Lookup table {} is referencing a missing cache {}, check if it started properly.", dto.name(), dto.cacheId());
        return null;
    }
    final LookupDataAdapter adapter = idToAdapter.get(dto.dataAdapterId());
    if (adapter == null) {
        LOG.warn("Lookup table {} is referencing a missing data adapter {}, check if it started properly.", dto.name(), dto.dataAdapterId());
        return null;
    }
    final LookupDefaultSingleValue defaultSingleValue;
    try {
        defaultSingleValue = LookupDefaultSingleValue.create(dto.defaultSingleValue(), dto.defaultSingleValueType());
    } catch (Exception e) {
        LOG.error("Could not create default single value object for lookup table {}/{}: {}", dto.name(), dto.id(), e.getMessage());
        return null;
    }
    final LookupDefaultMultiValue defaultMultiValue;
    try {
        defaultMultiValue = LookupDefaultMultiValue.create(dto.defaultMultiValue(), dto.defaultMultiValueType());
    } catch (Exception e) {
        LOG.error("Could not create default multi value object for lookup table {}/{}: {}", dto.name(), dto.id(), e.getMessage());
        return null;
    }
    final LookupTable table = LookupTable.builder().id(dto.id()).name(dto.name()).description(dto.description()).title(dto.title()).cache(cache).dataAdapter(adapter).defaultSingleValue(defaultSingleValue).defaultMultiValue(defaultMultiValue).build();
    final LookupCache newCache = table.cache();
    final LookupDataAdapter newAdapter = table.dataAdapter();
    LOG.info("Starting lookup table {}/{} [@{}] using cache {}/{} [@{}], data adapter {}/{} [@{}]", table.name(), table.id(), objectId(table), newCache.name(), newCache.id(), objectId(newCache), newAdapter.name(), newAdapter.id(), objectId(newAdapter));
    final LookupTable previous = liveTables.put(dto.name(), table);
    if (previous != null) {
        LOG.info("Replaced previous lookup table {} [@{}]", previous.name(), objectId(previous));
    }
    return table;
}
Also used : LookupDataAdapter(org.graylog2.plugin.lookup.LookupDataAdapter) LookupCache(org.graylog2.plugin.lookup.LookupCache)

Aggregations

LookupCache (org.graylog2.plugin.lookup.LookupCache)1 LookupDataAdapter (org.graylog2.plugin.lookup.LookupDataAdapter)1