Search in sources :

Example 11 with EntityDescriptor

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;
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)

Example 12 with EntityDescriptor

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();
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) ImmutableSet(com.google.common.collect.ImmutableSet)

Example 13 with EntityDescriptor

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));
}
Also used : Collector(org.graylog.plugins.sidecar.rest.models.Collector) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 14 with EntityDescriptor

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);
}
Also used : ViewStateEntity(org.graylog2.contentpacks.model.entities.ViewStateEntity) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) ViewStateDTO(org.graylog.plugins.views.search.views.ViewStateDTO) ViewEntity(org.graylog2.contentpacks.model.entities.ViewEntity) Search(org.graylog.plugins.views.search.Search) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with EntityDescriptor

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);
    });
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor)

Aggregations

EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)92 Test (org.junit.Test)63 Entity (org.graylog2.contentpacks.model.entities.Entity)62 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)59 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)48 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)44 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)44 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)42 ModelId (org.graylog2.contentpacks.model.ModelId)26 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)15 Map (java.util.Map)14 Graph (com.google.common.graph.Graph)13 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)13 Optional (java.util.Optional)12 Set (java.util.Set)12 Collectors (java.util.stream.Collectors)12 EntityExcerpt (org.graylog2.contentpacks.model.entities.EntityExcerpt)12 NotFoundException (org.graylog2.database.NotFoundException)12