use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class ContentPackService method resolveDependencyGraph.
private MutableGraph<EntityDescriptor> resolveDependencyGraph(Graph<EntityDescriptor> dependencyGraph, Set<EntityDescriptor> resolvedEntities) {
final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.from(dependencyGraph).build();
Graphs.merge(mutableGraph, dependencyGraph);
for (EntityDescriptor entityDescriptor : dependencyGraph.nodes()) {
LOG.debug("Resolving entity {}", entityDescriptor);
if (resolvedEntities.contains(entityDescriptor)) {
LOG.debug("Entity {} already resolved, skipping.", entityDescriptor);
continue;
}
final EntityWithExcerptFacade<?, ?> facade = entityFacades.getOrDefault(entityDescriptor.type(), UnsupportedEntityFacade.INSTANCE);
final Graph<EntityDescriptor> graph = facade.resolveNativeEntity(entityDescriptor);
LOG.trace("Dependencies of entity {}: {}", entityDescriptor, graph);
Graphs.merge(mutableGraph, graph);
LOG.trace("New dependency graph: {}", mutableGraph);
resolvedEntities.add(entityDescriptor);
final Graph<EntityDescriptor> result = resolveDependencyGraph(mutableGraph, resolvedEntities);
Graphs.merge(mutableGraph, result);
}
return mutableGraph;
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class ContentPackService method collectEntities.
public ImmutableSet<Entity> collectEntities(Collection<EntityDescriptor> resolvedEntities) {
// It's important to only compute the EntityDescriptor IDs once per #collectEntities call! Otherwise we
// will get broken references between the entities.
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(resolvedEntities);
final ImmutableSet.Builder<Entity> entities = ImmutableSet.builder();
for (EntityDescriptor entityDescriptor : resolvedEntities) {
if (EntityDescriptorIds.isSystemStreamDescriptor(entityDescriptor)) {
continue;
}
final EntityWithExcerptFacade<?, ?> facade = entityFacades.getOrDefault(entityDescriptor.type(), UnsupportedEntityFacade.INSTANCE);
facade.exportEntity(entityDescriptor, entityDescriptorIds).ifPresent(entities::add);
}
return entities.build();
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class SidecarCollectorFacade method exportEntity.
@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
final ModelId modelId = entityDescriptor.id();
final Collector collector = collectorService.find(modelId.id());
if (isNull(collector)) {
LOG.debug("Couldn't find collector {}", entityDescriptor);
return Optional.empty();
}
return Optional.of(exportNativeEntity(collector, entityDescriptorIds));
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class ViewFacade method decode.
protected NativeEntity<ViewDTO> decode(EntityV1 entityV1, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, User user) {
final ViewEntity viewEntity = objectMapper.convertValue(entityV1.data(), ViewEntity.class);
final Map<String, ViewStateDTO> viewStateMap = new LinkedHashMap<>(viewEntity.state().size());
for (Map.Entry<String, ViewStateEntity> entry : viewEntity.state().entrySet()) {
final ViewStateEntity entity = entry.getValue();
viewStateMap.put(entry.getKey(), entity.toNativeEntity(parameters, nativeEntities));
}
final ViewDTO.Builder viewBuilder = viewEntity.toNativeEntity(parameters, nativeEntities);
viewBuilder.state(viewStateMap);
final Search search = viewEntity.search().toNativeEntity(parameters, nativeEntities);
final Search persistedSearch = searchDbService.save(search);
final ViewDTO persistedView = viewService.saveWithOwner(viewBuilder.searchId(persistedSearch.id()).build(), user);
return NativeEntity.create(entityV1.id(), persistedView.id(), getModelType(), persistedView.title(), persistedView);
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class AggregationEventProcessorConfig method resolveNativeEntity.
@Override
public void resolveNativeEntity(EntityDescriptor entityDescriptor, MutableGraph<EntityDescriptor> mutableGraph) {
streams().forEach(streamId -> {
final EntityDescriptor depStream = EntityDescriptor.builder().id(ModelId.of(streamId)).type(ModelTypes.STREAM_V1).build();
mutableGraph.putEdge(entityDescriptor, depStream);
});
}
Aggregations