use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class ContentPackService method rollback.
@SuppressWarnings("unchecked")
private void rollback(Map<EntityDescriptor, Object> entities) {
final ImmutableList<Map.Entry<EntityDescriptor, Object>> entries = ImmutableList.copyOf(entities.entrySet());
for (Map.Entry<EntityDescriptor, Object> entry : entries.reverse()) {
final EntityDescriptor entityDescriptor = entry.getKey();
final Object entity = entry.getValue();
final EntityWithExcerptFacade facade = entityFacades.getOrDefault(entityDescriptor.type(), UnsupportedEntityFacade.INSTANCE);
LOG.debug("Removing entity {}", entityDescriptor);
facade.delete(entity);
}
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class ViewFacade method createNativeEntity.
@Override
public NativeEntity<ViewDTO> createNativeEntity(Entity entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, String username) {
ensureV1(entity);
final User user = Optional.ofNullable(userService.load(username)).orElseThrow(() -> new IllegalStateException("Cannot load user <" + username + "> from db"));
return decode((EntityV1) entity, parameters, nativeEntities, user);
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class ViewFacade method resolveNativeEntity.
@SuppressWarnings("UnstableApiUsage")
@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entityDescriptor);
final ModelId modelId = entityDescriptor.id();
final ViewSummaryDTO viewSummaryDTO = viewSummaryService.get(modelId.id()).orElseThrow(() -> new NoSuchElementException("Could not find view with id " + modelId.id()));
final Search search = searchDbService.get(viewSummaryDTO.searchId()).orElseThrow(() -> new NoSuchElementException("Could not find search with id " + viewSummaryDTO.searchId()));
search.usedStreamIds().stream().map(s -> EntityDescriptor.create(s, ModelTypes.STREAM_V1)).forEach(streamDescriptor -> mutableGraph.putEdge(entityDescriptor, streamDescriptor));
return ImmutableGraph.copyOf(mutableGraph);
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class ViewFacade method exportEntity.
@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
final ModelId modelId = entityDescriptor.id();
final Optional<ViewDTO> optionalView = viewService.get(modelId.id());
if (optionalView.isPresent()) {
return Optional.of(exportNativeEntity(optionalView.get(), entityDescriptorIds));
}
LOG.debug("Couldn't find view {}", entityDescriptor);
return Optional.empty();
}
use of org.graylog2.contentpacks.model.entities.EntityDescriptor in project graylog2-server by Graylog2.
the class InputFacade method resolveNativeEntityGrokPattern.
private void resolveNativeEntityGrokPattern(EntityDescriptor entityDescriptor, InputWithExtractors inputWithExtractors, MutableGraph<EntityDescriptor> mutableGraph) {
inputWithExtractors.extractors().stream().filter(e -> e.getType().equals(Extractor.Type.GROK)).map(e -> (String) e.getExtractorConfig().get(GrokExtractor.CONFIG_GROK_PATTERN)).map(GrokPatternService::extractPatternNames).flatMap(Collection::stream).forEach(patternName -> {
grokPatternService.loadByName(patternName).ifPresent(depPattern -> {
final EntityDescriptor depEntityDescriptor = EntityDescriptor.create(depPattern.id(), ModelTypes.GROK_PATTERN_V1);
mutableGraph.putEdge(entityDescriptor, depEntityDescriptor);
});
});
}
Aggregations