use of org.graylog2.contentpacks.facades.EntityWithExcerptFacade 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.facades.EntityWithExcerptFacade 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.facades.EntityWithExcerptFacade in project graylog2-server by Graylog2.
the class ContentPackServiceTest method setUp.
@Before
public void setUp() throws Exception {
final ContentPackInstallationPersistenceService contentPackInstallationPersistenceService = contentPackInstallService;
final Set<ConstraintChecker> constraintCheckers = Collections.emptySet();
pluginMetaData = new HashSet<>();
outputFactories = new HashMap<>();
outputFactories2 = new HashMap<>();
final Map<ModelType, EntityWithExcerptFacade<?, ?>> entityFacades = ImmutableMap.of(ModelTypes.GROK_PATTERN_V1, new GrokPatternFacade(objectMapper, patternService), ModelTypes.STREAM_V1, new StreamFacade(objectMapper, streamService, streamRuleService, alertService, alarmCallbackConfigurationService, legacyAlertConditionMigration, indexSetService, userService), ModelTypes.OUTPUT_V1, new OutputFacade(objectMapper, outputService, pluginMetaData, outputFactories, outputFactories2));
contentPackService = new ContentPackService(contentPackInstallationPersistenceService, constraintCheckers, entityFacades);
Map<String, String> entityData = new HashMap<>(2);
entityData.put("name", "NAME");
entityData.put("pattern", "\\w");
grokPattern = GrokPattern.builder().pattern("\\w").name("NAME").build();
JsonNode jsonData = objectMapper.convertValue(entityData, JsonNode.class);
EntityV1 entityV1 = EntityV1.builder().id(ModelId.of("12345")).type(ModelTypes.GROK_PATTERN_V1).data(jsonData).build();
ImmutableSet<Entity> entities = ImmutableSet.of(entityV1);
NativeEntityDescriptor nativeEntityDescriptor = NativeEntityDescriptor.create(ModelId.of("12345"), "dead-beef1", ModelTypes.GROK_PATTERN_V1, "NAME");
nativeEntityDescriptors = ImmutableSet.of(nativeEntityDescriptor);
contentPack = ContentPackV1.builder().description("test").entities(entities).name("test").revision(1).summary("").vendor("").url(URI.create("http://graylog.com")).id(ModelId.of("dead-beef")).build();
contentPackInstallation = ContentPackInstallation.builder().contentPackId(ModelId.of("dead-beef")).contentPackRevision(1).entities(nativeEntityDescriptors).comment("Installed").parameters(ImmutableMap.copyOf(Collections.emptyMap())).createdAt(Instant.now()).createdBy("me").build();
}
use of org.graylog2.contentpacks.facades.EntityWithExcerptFacade in project graylog2-server by Graylog2.
the class CatalogResourceTest method setUp.
@Before
public void setUp() {
final ContentPackInstallationPersistenceService contentPackInstallationPersistenceService = mock(ContentPackInstallationPersistenceService.class);
final Set<ConstraintChecker> constraintCheckers = Collections.emptySet();
final Map<ModelType, EntityWithExcerptFacade<?, ?>> entityFacades = Collections.singletonMap(ModelType.of("test", "1"), mockEntityFacade);
contentPackService = new ContentPackService(contentPackInstallationPersistenceService, constraintCheckers, entityFacades);
catalogResource = new CatalogResource(contentPackService);
}
use of org.graylog2.contentpacks.facades.EntityWithExcerptFacade in project graylog2-server by Graylog2.
the class ContentPackService method buildEntityGraph.
private ImmutableGraph<Entity> buildEntityGraph(Entity rootEntity, Set<Entity> entities, Map<String, ValueReference> parameters) {
final Map<EntityDescriptor, Entity> entityDescriptorMap = entities.stream().collect(Collectors.toMap(Entity::toEntityDescriptor, Function.identity()));
final MutableGraph<Entity> dependencyGraph = GraphBuilder.directed().allowsSelfLoops(false).expectedNodeCount(entities.size()).build();
for (Map.Entry<EntityDescriptor, Entity> entry : entityDescriptorMap.entrySet()) {
final EntityDescriptor entityDescriptor = entry.getKey();
final Entity entity = entry.getValue();
final EntityWithExcerptFacade<?, ?> facade = entityFacades.getOrDefault(entity.type(), UnsupportedEntityFacade.INSTANCE);
final Graph<Entity> entityGraph = facade.resolveForInstallation(entity, parameters, entityDescriptorMap);
LOG.trace("Dependencies of entity {}: {}", entityDescriptor, entityGraph);
dependencyGraph.putEdge(rootEntity, entity);
Graphs.merge(dependencyGraph, entityGraph);
LOG.trace("New dependency graph: {}", dependencyGraph);
}
final Set<Entity> unexpectedEntities = dependencyGraph.nodes().stream().filter(entity -> !rootEntity.equals(entity)).filter(entity -> !entities.contains(entity)).collect(Collectors.toSet());
if (!unexpectedEntities.isEmpty()) {
throw new UnexpectedEntitiesException(unexpectedEntities);
}
return ImmutableGraph.copyOf(dependencyGraph);
}
Aggregations