use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class InputFacade method resolveNativeEntity.
@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entityDescriptor);
final ModelId modelId = entityDescriptor.id();
try {
final Input input = inputService.find(modelId.toString());
final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input, inputService.getExtractors(input));
resolveNativeEntityLookupTable(entityDescriptor, inputWithExtractors, mutableGraph);
resolveNativeEntityGrokPattern(entityDescriptor, inputWithExtractors, mutableGraph);
return ImmutableGraph.copyOf(mutableGraph);
} catch (NotFoundException e) {
LOG.debug("Couldn't find input {}", entityDescriptor, e);
}
return ImmutableGraph.copyOf(mutableGraph);
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class InputFacade method resolveNativeEntityLookupTable.
private void resolveNativeEntityLookupTable(EntityDescriptor entityDescriptor, InputWithExtractors inputWithExtractors, MutableGraph<EntityDescriptor> mutableGraph) {
final Stream<String> extractorLookupNames = inputWithExtractors.extractors().stream().filter(e -> e.getType().equals(Extractor.Type.LOOKUP_TABLE)).map(e -> (String) e.getExtractorConfig().get(LookupTableExtractor.CONFIG_LUT_NAME));
final Stream<String> converterLookupNames = inputWithExtractors.extractors().stream().flatMap(e -> e.getConverters().stream()).filter(c -> c.getType().equals(Converter.Type.LOOKUP_TABLE)).map(c -> (String) c.getConfig().get("lookup_table_name"));
Stream.concat(extractorLookupNames, converterLookupNames).map(lookupTableService::get).filter(Optional::isPresent).map(Optional::get).forEach(lookupTableDto -> {
EntityDescriptor lookupTable = EntityDescriptor.create(ModelId.of(lookupTableDto.id()), ModelTypes.LOOKUP_TABLE_V1);
mutableGraph.putEdge(entityDescriptor, lookupTable);
});
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class LookupTableFacade method resolveNativeEntity.
@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entityDescriptor);
final ModelId modelId = entityDescriptor.id();
final Optional<LookupTableDto> lookupTableDto = lookupTableService.get(modelId.id());
lookupTableDto.map(LookupTableDto::dataAdapterId).map(this::adapterDescriptor).ifPresent(dataAdapter -> mutableGraph.putEdge(entityDescriptor, dataAdapter));
lookupTableDto.map(LookupTableDto::cacheId).map(this::cacheDescriptor).ifPresent(cache -> mutableGraph.putEdge(entityDescriptor, cache));
return ImmutableGraph.copyOf(mutableGraph);
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class LookupTableFacade method resolveForInstallation.
private Graph<Entity> resolveForInstallation(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entity);
final LookupTableEntity lookupTableEntity = objectMapper.convertValue(entity.data(), LookupTableEntity.class);
final String dataAdapterName = lookupTableEntity.dataAdapterName().asString(parameters);
final EntityDescriptor dataAdapterDescriptor = adapterDescriptor(dataAdapterName);
final Entity dataAdapterEntity = entities.get(dataAdapterDescriptor);
if (dataAdapterEntity == null) {
throw new ContentPackException("Missing data adapter \"" + dataAdapterName + "\" for lookup table " + entity.toEntityDescriptor());
} else {
mutableGraph.putEdge(entity, dataAdapterEntity);
}
final String cacheName = lookupTableEntity.cacheName().asString(parameters);
final EntityDescriptor cacheDescriptor = cacheDescriptor(cacheName);
final Entity cacheEntity = entities.get(cacheDescriptor);
if (cacheEntity == null) {
throw new ContentPackException("Missing cache \"" + cacheName + "\" for lookup table " + entity.toEntityDescriptor());
} else {
mutableGraph.putEdge(entity, cacheEntity);
}
return ImmutableGraph.copyOf(mutableGraph);
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class LookupTableFacade method decode.
private NativeEntity<LookupTableDto> decode(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities) {
final LookupTableEntity lookupTableEntity = objectMapper.convertValue(entity.data(), LookupTableEntity.class);
final String referencedDataAdapterName = lookupTableEntity.dataAdapterName().asString(parameters);
final EntityDescriptor dataAdapterDescriptor = adapterDescriptor(referencedDataAdapterName);
final Object dataAdapter = nativeEntities.get(dataAdapterDescriptor);
final String dataAdapterId;
if (dataAdapter instanceof DataAdapterDto) {
dataAdapterId = ((DataAdapterDto) dataAdapter).id();
} else {
throw new MissingNativeEntityException(dataAdapterDescriptor);
}
final String referencedCacheName = lookupTableEntity.cacheName().asString(parameters);
final EntityDescriptor cacheDescriptor = cacheDescriptor(referencedCacheName);
final Object cache = nativeEntities.get(cacheDescriptor);
final String cacheId;
if (cache instanceof CacheDto) {
cacheId = ((CacheDto) cache).id();
} else {
throw new MissingNativeEntityException(cacheDescriptor);
}
final LookupTableDto lookupTableDto = LookupTableDto.builder().name(lookupTableEntity.name().asString(parameters)).title(lookupTableEntity.title().asString(parameters)).description(lookupTableEntity.description().asString(parameters)).dataAdapterId(dataAdapterId).cacheId(cacheId).defaultSingleValue(lookupTableEntity.defaultSingleValue().asString(parameters)).defaultSingleValueType(lookupTableEntity.defaultSingleValueType().asEnum(parameters, LookupDefaultSingleValue.Type.class)).defaultMultiValue(lookupTableEntity.defaultMultiValue().asString(parameters)).defaultMultiValueType(lookupTableEntity.defaultMultiValueType().asEnum(parameters, LookupDefaultMultiValue.Type.class)).build();
final LookupTableDto savedLookupTableDto = lookupTableService.save(lookupTableDto);
return NativeEntity.create(entity.id(), savedLookupTableDto.id(), TYPE_V1, lookupTableDto.title(), savedLookupTableDto);
}
Aggregations