Search in sources :

Example 46 with NativeEntity

use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.

the class PipelineFacade method delete.

@Override
public void delete(PipelineDao nativeEntity) {
    final Set<PipelineConnections> pipelineConnections = connectionsService.loadByPipelineId(nativeEntity.id());
    for (PipelineConnections connections : pipelineConnections) {
        final Set<String> pipelineIds = connections.pipelineIds().stream().filter(pipelineId -> !pipelineId.equals(nativeEntity.id())).collect(Collectors.toSet());
        if (pipelineIds.isEmpty()) {
            LOG.trace("Removing pipeline connections for stream {}", connections.streamId());
            connectionsService.delete(connections.streamId());
        } else {
            final PipelineConnections newConnections = connections.toBuilder().pipelineIds(pipelineIds).build();
            LOG.trace("Saving updated pipeline connections: {}", newConnections);
            connectionsService.save(newConnections);
        }
    }
    pipelineService.delete(nativeEntity.id());
}
Also used : PipelineConnections(org.graylog.plugins.pipelineprocessor.rest.PipelineConnections) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) RuleDao(org.graylog.plugins.pipelineprocessor.db.RuleDao) RuleService(org.graylog.plugins.pipelineprocessor.db.RuleService) ImmutableGraph(com.google.common.graph.ImmutableGraph) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) Entity(org.graylog2.contentpacks.model.entities.Entity) Stage(org.graylog.plugins.pipelineprocessor.ast.Stage) ModelType(org.graylog2.contentpacks.model.ModelType) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) Inject(javax.inject.Inject) PipelineService(org.graylog.plugins.pipelineprocessor.db.PipelineService) EntityExcerpt(org.graylog2.contentpacks.model.entities.EntityExcerpt) PipelineEntity(org.graylog2.contentpacks.model.entities.PipelineEntity) PipelineStreamConnectionsService(org.graylog.plugins.pipelineprocessor.db.PipelineStreamConnectionsService) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) JsonNode(com.fasterxml.jackson.databind.JsonNode) PipelineRuleParser(org.graylog.plugins.pipelineprocessor.parser.PipelineRuleParser) NotFoundException(org.graylog2.database.NotFoundException) Pipeline(org.graylog.plugins.pipelineprocessor.ast.Pipeline) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) ModelId(org.graylog2.contentpacks.model.ModelId) MutableGraph(com.google.common.graph.MutableGraph) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DateTime(org.joda.time.DateTime) MissingNativeEntityException(org.graylog2.contentpacks.exceptions.MissingNativeEntityException) Set(java.util.Set) PipelineDao(org.graylog.plugins.pipelineprocessor.db.PipelineDao) Collectors(java.util.stream.Collectors) GraphBuilder(com.google.common.graph.GraphBuilder) EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) Objects(java.util.Objects) Stream(org.graylog2.plugin.streams.Stream) StreamService(org.graylog2.streams.StreamService) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) Collections(java.util.Collections) Graph(com.google.common.graph.Graph) ModelTypes(org.graylog2.contentpacks.model.ModelTypes) PipelineConnections(org.graylog.plugins.pipelineprocessor.rest.PipelineConnections)

Example 47 with NativeEntity

use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.

the class SidecarCollectorConfigurationFacade method decode.

private NativeEntity<Configuration> decode(EntityV1 entity, Map<String, ValueReference> parameters) {
    final SidecarCollectorConfigurationEntity configurationEntity = objectMapper.convertValue(entity.data(), SidecarCollectorConfigurationEntity.class);
    final Configuration configuration = Configuration.create(configurationEntity.collectorId().asString(parameters), configurationEntity.title().asString(parameters), configurationEntity.color().asString(parameters), configurationEntity.template().asString(parameters));
    final Configuration savedConfiguration = configurationService.save(configuration);
    return NativeEntity.create(entity.id(), savedConfiguration.id(), TYPE_V1, configuration.name(), savedConfiguration);
}
Also used : Configuration(org.graylog.plugins.sidecar.rest.models.Configuration) SidecarCollectorConfigurationEntity(org.graylog2.contentpacks.model.entities.SidecarCollectorConfigurationEntity)

Example 48 with NativeEntity

use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.

the class UrlWhitelistFacade method createNativeEntity.

@Override
public NativeEntity<WhitelistEntry> createNativeEntity(Entity entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Object> nativeEntities, String username) {
    if (!(entity instanceof EntityV1)) {
        throw new IllegalArgumentException("Unsupported entity version: " + entity.getClass());
    }
    final WhitelistEntry whitelistEntry = objectMapper.convertValue(((EntityV1) entity).data(), WhitelistEntry.class);
    urlWhitelistService.addEntry(whitelistEntry);
    return NativeEntity.create(entity.id(), whitelistEntry.id(), TYPE_V1, createTitle(whitelistEntry), whitelistEntry);
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) WhitelistEntry(org.graylog2.system.urlwhitelist.WhitelistEntry)

Example 49 with NativeEntity

use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.

the class DashboardV1Facade 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 50 with NativeEntity

use of org.graylog2.contentpacks.model.entities.NativeEntity in project graylog2-server by Graylog2.

the class NotificationFacadeTest method createNativeEntity.

@Test
public void createNativeEntity() {
    final EntityV1 entityV1 = createTestEntity();
    final JobDefinitionDto jobDefinitionDto = mock(JobDefinitionDto.class);
    when(jobDefinitionService.save(any(JobDefinitionDto.class))).thenReturn(jobDefinitionDto);
    final UserImpl kmerzUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "kmerz"));
    when(userService.load("kmerz")).thenReturn(kmerzUser);
    final NativeEntity<NotificationDto> nativeEntity = facade.createNativeEntity(entityV1, ImmutableMap.of(), ImmutableMap.of(), "kmerz");
    assertThat(nativeEntity).isNotNull();
    final NotificationDto notificationDto = nativeEntity.entity();
    assertThat(notificationDto.title()).isEqualTo("title");
    assertThat(notificationDto.description()).isEqualTo("descriptions");
    assertThat(notificationDto.config().type()).isEqualTo("http-notification-v1");
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) PasswordAlgorithmFactory(org.graylog2.security.PasswordAlgorithmFactory) NotificationDto(org.graylog.events.notifications.NotificationDto) JobDefinitionDto(org.graylog.scheduler.JobDefinitionDto) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) Test(org.junit.Test)

Aggregations

NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)30 Entity (org.graylog2.contentpacks.model.entities.Entity)28 Test (org.junit.Test)26 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)14 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)12 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)7 LookupCacheEntity (org.graylog2.contentpacks.model.entities.LookupCacheEntity)7 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)7 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)7 HashMap (java.util.HashMap)6 LookupDataAdapterEntity (org.graylog2.contentpacks.model.entities.LookupDataAdapterEntity)6 CacheDto (org.graylog2.lookup.dto.CacheDto)6 Map (java.util.Map)5 RuleDao (org.graylog.plugins.pipelineprocessor.db.RuleDao)5 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)5 DataAdapterDto (org.graylog2.lookup.dto.DataAdapterDto)5 Graph (com.google.common.graph.Graph)4 GraphBuilder (com.google.common.graph.GraphBuilder)4 ImmutableGraph (com.google.common.graph.ImmutableGraph)4