Search in sources :

Example 91 with EntityDescriptor

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);
    }
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) EntityWithExcerptFacade(org.graylog2.contentpacks.facades.EntityWithExcerptFacade) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 92 with EntityDescriptor

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);
}
Also used : User(org.graylog2.plugin.database.users.User)

Example 93 with EntityDescriptor

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);
}
Also used : EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) ImmutableGraph(com.google.common.graph.ImmutableGraph) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) LoggerFactory(org.slf4j.LoggerFactory) Entity(org.graylog2.contentpacks.model.entities.Entity) ModelType(org.graylog2.contentpacks.model.ModelType) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) Inject(javax.inject.Inject) LinkedHashMap(java.util.LinkedHashMap) SearchEntity(org.graylog2.contentpacks.model.entities.SearchEntity) ViewStateEntity(org.graylog2.contentpacks.model.entities.ViewStateEntity) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) Search(org.graylog.plugins.views.search.Search) ViewSummaryService(org.graylog.plugins.views.search.views.ViewSummaryService) NoSuchElementException(java.util.NoSuchElementException) Logger(org.slf4j.Logger) ModelId(org.graylog2.contentpacks.model.ModelId) MutableGraph(com.google.common.graph.MutableGraph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) ViewSummaryDTO(org.graylog.plugins.views.search.views.ViewSummaryDTO) Collectors(java.util.stream.Collectors) GraphBuilder(com.google.common.graph.GraphBuilder) ViewEntity(org.graylog2.contentpacks.model.entities.ViewEntity) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) Objects(java.util.Objects) Stream(java.util.stream.Stream) UserService(org.graylog2.shared.users.UserService) ViewStateDTO(org.graylog.plugins.views.search.views.ViewStateDTO) Optional(java.util.Optional) ViewService(org.graylog.plugins.views.search.views.ViewService) SearchDbService(org.graylog.plugins.views.search.db.SearchDbService) User(org.graylog2.plugin.database.users.User) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Graph(com.google.common.graph.Graph) ModelTypes(org.graylog2.contentpacks.model.ModelTypes) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Search(org.graylog.plugins.views.search.Search) ViewSummaryDTO(org.graylog.plugins.views.search.views.ViewSummaryDTO) ModelId(org.graylog2.contentpacks.model.ModelId) NoSuchElementException(java.util.NoSuchElementException)

Example 94 with EntityDescriptor

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();
}
Also used : ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 95 with EntityDescriptor

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);
        });
    });
}
Also used : Extractor(org.graylog2.plugin.inputs.Extractor) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) ImmutableGraph(com.google.common.graph.ImmutableGraph) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Tools(org.graylog2.plugin.Tools) InputService(org.graylog2.inputs.InputService) NoSuchInputTypeException(org.graylog2.shared.inputs.NoSuchInputTypeException) LoggerFactory(org.slf4j.LoggerFactory) ModelType(org.graylog2.contentpacks.model.ModelType) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) InputRegistry(org.graylog2.shared.inputs.InputRegistry) MessageInputFactory(org.graylog2.shared.inputs.MessageInputFactory) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConverterFactory(org.graylog2.inputs.converters.ConverterFactory) ImmutableSet(com.google.common.collect.ImmutableSet) ModelId(org.graylog2.contentpacks.model.ModelId) GrokPatternService(org.graylog2.grok.GrokPatternService) ImmutableMap(com.google.common.collect.ImmutableMap) MutableGraph(com.google.common.graph.MutableGraph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) Collection(java.util.Collection) Set(java.util.Set) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) ServerStatus(org.graylog2.plugin.ServerStatus) ReferenceMapUtils.toReferenceMap(org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toReferenceMap) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) GraphBuilder(com.google.common.graph.GraphBuilder) List(java.util.List) Stream(java.util.stream.Stream) GrokExtractor(org.graylog2.inputs.extractors.GrokExtractor) PluginMetaData(org.graylog2.plugin.PluginMetaData) Optional(java.util.Optional) ModelTypes(org.graylog2.contentpacks.model.ModelTypes) Configuration(org.graylog2.plugin.configuration.Configuration) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) Converter(org.graylog2.plugin.inputs.Converter) Entity(org.graylog2.contentpacks.model.entities.Entity) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ContentPackException(org.graylog2.contentpacks.exceptions.ContentPackException) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) DBLookupTableService(org.graylog2.lookup.db.DBLookupTableService) Inject(javax.inject.Inject) ImmutableList(com.google.common.collect.ImmutableList) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) ConfigurationException(org.graylog2.plugin.configuration.ConfigurationException) Input(org.graylog2.inputs.Input) ExtractorFactory(org.graylog2.inputs.extractors.ExtractorFactory) NotFoundException(org.graylog2.database.NotFoundException) ReferenceMap(org.graylog2.contentpacks.model.entities.references.ReferenceMap) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) Ints(com.google.common.primitives.Ints) LookupTableExtractor(org.graylog2.inputs.extractors.LookupTableExtractor) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) MessageInput(org.graylog2.plugin.inputs.MessageInput) ValidationException(org.graylog2.plugin.database.ValidationException) VisibleForTesting(com.google.common.annotations.VisibleForTesting) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Message(org.graylog2.plugin.Message) ReferenceMapUtils.toValueMap(org.graylog2.contentpacks.model.entities.references.ReferenceMapUtils.toValueMap) Graph(com.google.common.graph.Graph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) GrokPatternService(org.graylog2.grok.GrokPatternService)

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