Search in sources :

Example 6 with StreamImpl

use of org.graylog2.streams.StreamImpl in project graylog2-server by Graylog2.

the class DashboardV1FacadeTest method setUp.

@Before
public void setUp() throws IOException {
    objectMapper.registerSubtypes(new NamedType(AggregationConfigDTO.class, AggregationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(MessageListConfigDTO.class, MessageListConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(LineVisualizationConfigDTO.class, LineVisualizationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(BarVisualizationConfigDTO.class, BarVisualizationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(NumberVisualizationConfigDTO.class, NumberVisualizationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(TimeHistogramConfigDTO.class, TimeHistogramConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(ValueConfigDTO.class, ValueConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(PivotSortConfig.class, PivotSortConfig.Type));
    objectMapper.registerSubtypes(new NamedType(PivotEntity.class, PivotEntity.NAME));
    objectMapper.registerSubtypes(new NamedType(PivotSort.class, PivotSort.Type));
    objectMapper.registerSubtypes(new NamedType(OrFilter.class, OrFilter.NAME));
    objectMapper.registerSubtypes(new NamedType(StreamFilter.class, StreamFilter.NAME));
    objectMapper.registerSubtypes(new NamedType(QueryStringFilter.class, QueryStringFilter.NAME));
    objectMapper.registerSubtypes(new NamedType(AutoIntervalDTO.class, AutoIntervalDTO.type));
    final MongoConnection mongoConnection = mongodb.mongoConnection();
    final MongoJackObjectMapperProvider mapper = new MongoJackObjectMapperProvider(objectMapper);
    searchDbService = new ViewFacadeTest.TestSearchDBService(mongoConnection, mapper);
    viewService = new ViewFacadeTest.TestViewService(mongoConnection, mapper, null);
    viewSummaryService = new ViewFacadeTest.TestViewSummaryService(mongoConnection, mapper);
    userService = mock(UserService.class);
    final UserImpl fakeUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "testuser"));
    when(userService.load("testuser")).thenReturn(fakeUser);
    final DashboardWidgetConverter dashboardWidgetConverter = new DashboardWidgetConverter();
    final EntityConverter entityConverter = new EntityConverter(dashboardWidgetConverter);
    facade = new DashboardV1Facade(objectMapper, searchDbService, entityConverter, viewService, viewSummaryService, userService);
    final URL resourceUrl = Resources.getResource(DashboardV1Facade.class, "content-pack-dashboard-v1.json");
    final ContentPack contentPack = objectMapper.readValue(resourceUrl, ContentPack.class);
    assertThat(contentPack).isInstanceOf(ContentPackV1.class);
    final ContentPackV1 contentPackV1 = (ContentPackV1) contentPack;
    final Entity entity = contentPackV1.entities().iterator().next();
    final StreamImpl stream = new StreamImpl(Collections.emptyMap());
    final Map<EntityDescriptor, Object> nativeEntities = new HashMap<>(1);
    nativeEntities.put(EntityDescriptor.create("58b3d55a-51ad-4b3e-865c-85776016a151", ModelTypes.STREAM_V1), stream);
    final NativeEntity<ViewDTO> nativeEntity = facade.createNativeEntity(entity, ImmutableMap.of(), nativeEntities, "testuser");
    assertThat(nativeEntity).isNotNull();
    viewDTO = nativeEntity.entity();
}
Also used : NumberVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.NumberVisualizationConfigDTO) EntityConverter(org.graylog2.contentpacks.facades.dashboardV1.EntityConverter) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) PivotEntity(org.graylog2.contentpacks.model.entities.PivotEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) HashMap(java.util.HashMap) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) TimeHistogramConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.TimeHistogramConfigDTO) AutoIntervalDTO(org.graylog.plugins.views.search.views.widgets.aggregation.AutoIntervalDTO) PivotSortConfig(org.graylog.plugins.views.search.views.widgets.aggregation.sort.PivotSortConfig) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) QueryStringFilter(org.graylog.plugins.views.search.filter.QueryStringFilter) DashboardV1Facade(org.graylog2.contentpacks.facades.dashboardV1.DashboardV1Facade) URL(java.net.URL) AggregationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.AggregationConfigDTO) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) PasswordAlgorithmFactory(org.graylog2.security.PasswordAlgorithmFactory) MessageListConfigDTO(org.graylog.plugins.views.search.views.widgets.messagelist.MessageListConfigDTO) ContentPackV1(org.graylog2.contentpacks.model.ContentPackV1) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) DashboardWidgetConverter(org.graylog2.contentpacks.facades.dashboardV1.DashboardWidgetConverter) BarVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.BarVisualizationConfigDTO) UserService(org.graylog2.shared.users.UserService) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ContentPack(org.graylog2.contentpacks.model.ContentPack) OrFilter(org.graylog.plugins.views.search.filter.OrFilter) LineVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.LineVisualizationConfigDTO) PivotSort(org.graylog.plugins.views.search.searchtypes.pivot.PivotSort) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) StreamImpl(org.graylog2.streams.StreamImpl) ValueConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.ValueConfigDTO) MongoConnection(org.graylog2.database.MongoConnection) PivotEntity(org.graylog2.contentpacks.model.entities.PivotEntity) Before(org.junit.Before)

Example 7 with StreamImpl

use of org.graylog2.streams.StreamImpl in project graylog2-server by Graylog2.

the class V20190705071400_AddEventIndexSetsMigration method createEventsStream.

private void createEventsStream(String streamId, String streamTitle, String streamDescription, IndexSet indexSet) {
    final ObjectId id = new ObjectId(streamId);
    final Map<String, Object> fields = ImmutableMap.<String, Object>builder().put(StreamImpl.FIELD_TITLE, streamTitle).put(StreamImpl.FIELD_DESCRIPTION, streamDescription).put(StreamImpl.FIELD_DISABLED, false).put(StreamImpl.FIELD_CREATED_AT, DateTime.now(DateTimeZone.UTC)).put(StreamImpl.FIELD_CREATOR_USER_ID, "admin").put(StreamImpl.FIELD_MATCHING_TYPE, StreamImpl.MatchingType.DEFAULT.name()).put(StreamImpl.FIELD_REMOVE_MATCHES_FROM_DEFAULT_STREAM, true).put(StreamImpl.FIELD_INDEX_SET_ID, requireNonNull(indexSet.getConfig().id(), "index set ID cannot be null")).put(StreamImpl.FIELD_DEFAULT_STREAM, false).build();
    final Stream stream = new StreamImpl(id, fields, Collections.emptyList(), Collections.emptySet(), indexSet);
    try {
        streamService.save(stream);
        LOG.info("Successfully created events stream <{}/{}>", stream.getId(), stream.getTitle());
    } catch (ValidationException e) {
        LOG.error("Couldn't create events stream <{}/{}>! This is a bug!", streamId, streamTitle, e);
    }
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) ObjectId(org.bson.types.ObjectId) StreamImpl(org.graylog2.streams.StreamImpl) Stream(org.graylog2.plugin.streams.Stream)

Example 8 with StreamImpl

use of org.graylog2.streams.StreamImpl in project graylog2-server by Graylog2.

the class V20161116172200_CreateDefaultStreamMigration method createDefaultStream.

private void createDefaultStream() {
    final IndexSet indexSet = indexSetRegistry.getDefault();
    final ObjectId id = new ObjectId(Stream.DEFAULT_STREAM_ID);
    final Map<String, Object> fields = ImmutableMap.<String, Object>builder().put(StreamImpl.FIELD_TITLE, "All messages").put(StreamImpl.FIELD_DESCRIPTION, "Stream containing all messages").put(StreamImpl.FIELD_DISABLED, false).put(StreamImpl.FIELD_CREATED_AT, DateTime.now(DateTimeZone.UTC)).put(StreamImpl.FIELD_CREATOR_USER_ID, "local:admin").put(StreamImpl.FIELD_MATCHING_TYPE, StreamImpl.MatchingType.DEFAULT.name()).put(StreamImpl.FIELD_REMOVE_MATCHES_FROM_DEFAULT_STREAM, false).put(StreamImpl.FIELD_DEFAULT_STREAM, true).put(StreamImpl.FIELD_INDEX_SET_ID, indexSet.getConfig().id()).build();
    final Stream stream = new StreamImpl(id, fields, Collections.emptyList(), Collections.emptySet(), indexSet);
    try {
        streamService.save(stream);
        LOG.info("Successfully created default stream: {}", stream.getTitle());
    } catch (ValidationException e) {
        LOG.error("Couldn't create default stream! This is a bug!");
    }
}
Also used : ValidationException(org.graylog2.plugin.database.ValidationException) ObjectId(org.bson.types.ObjectId) StreamImpl(org.graylog2.streams.StreamImpl) Stream(org.graylog2.plugin.streams.Stream) IndexSet(org.graylog2.indexer.IndexSet)

Example 9 with StreamImpl

use of org.graylog2.streams.StreamImpl in project graylog2-server by Graylog2.

the class StreamServiceImpl method loadAll.

private List<Stream> loadAll(DBObject query) {
    final List<DBObject> results = query(StreamImpl.class, query);
    final List<String> streamIds = results.stream().map(o -> o.get("_id").toString()).collect(Collectors.toList());
    final Map<String, List<StreamRule>> allStreamRules = streamRuleService.loadForStreamIds(streamIds);
    final ImmutableList.Builder<Stream> streams = ImmutableList.builder();
    final Map<String, IndexSet> indexSets = indexSetsForStreams(results);
    final Set<String> outputIds = results.stream().map(this::outputIdsForRawStream).flatMap(outputs -> outputs.stream().map(ObjectId::toHexString)).collect(Collectors.toSet());
    final Map<String, Output> outputsById = outputService.loadByIds(outputIds).stream().collect(Collectors.toMap(Output::getId, Function.identity()));
    for (DBObject o : results) {
        final ObjectId objectId = (ObjectId) o.get("_id");
        final String id = objectId.toHexString();
        final List<StreamRule> streamRules = allStreamRules.getOrDefault(id, Collections.emptyList());
        LOG.debug("Found {} rules for stream <{}>", streamRules.size(), id);
        final Set<Output> outputs = outputIdsForRawStream(o).stream().map(ObjectId::toHexString).map(outputId -> {
            final Output output = outputsById.get(outputId);
            if (output == null) {
                final String streamTitle = Strings.nullToEmpty((String) o.get(StreamImpl.FIELD_TITLE));
                LOG.warn("Stream \"" + streamTitle + "\" <" + id + "> references missing output <" + outputId + "> - ignoring output.");
            }
            return output;
        }).filter(Objects::nonNull).collect(Collectors.toSet());
        @SuppressWarnings("unchecked") final Map<String, Object> fields = o.toMap();
        final String indexSetId = (String) fields.get(StreamImpl.FIELD_INDEX_SET_ID);
        streams.add(new StreamImpl(objectId, fields, streamRules, outputs, indexSets.get(indexSetId)));
    }
    return streams.build();
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Tools(org.graylog2.plugin.Tools) LoggerFactory(org.slf4j.LoggerFactory) AlarmCallbackConfiguration(org.graylog2.alarmcallbacks.AlarmCallbackConfiguration) AlertService(org.graylog2.alerts.AlertService) StreamRule(org.graylog2.plugin.streams.StreamRule) BasicDBList(com.mongodb.BasicDBList) DBObject(com.mongodb.DBObject) Map(java.util.Map) EmbeddedPersistable(org.graylog2.plugin.database.EmbeddedPersistable) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) StreamsChangedEvent(org.graylog2.streams.events.StreamsChangedEvent) PersistedServiceImpl(org.graylog2.database.PersistedServiceImpl) ImmutableSet(com.google.common.collect.ImmutableSet) NotificationService(org.graylog2.notifications.NotificationService) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) CreateStreamRequest(org.graylog2.rest.resources.streams.requests.CreateStreamRequest) List(java.util.List) ClusterEventBus(org.graylog2.events.ClusterEventBus) IndexSetService(org.graylog2.indexer.indexset.IndexSetService) Stream(org.graylog2.plugin.streams.Stream) AlertCondition(org.graylog2.plugin.alarms.AlertCondition) Optional(java.util.Optional) MongoConnection(org.graylog2.database.MongoConnection) EntityOwnershipService(org.graylog.security.entities.EntityOwnershipService) QueryBuilder(com.mongodb.QueryBuilder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) EmailAlarmCallback(org.graylog2.alarmcallbacks.EmailAlarmCallback) HashMap(java.util.HashMap) Function(java.util.function.Function) DBProjection(org.mongojack.DBProjection) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) MongoIndexSet(org.graylog2.indexer.MongoIndexSet) StreamSupport(java.util.stream.StreamSupport) Alert(org.graylog2.alerts.Alert) NotFoundException(org.graylog2.database.NotFoundException) Nullable(javax.annotation.Nullable) Notification(org.graylog2.notifications.Notification) Logger(org.slf4j.Logger) BasicDBObject(com.mongodb.BasicDBObject) StreamDeletedEvent(org.graylog2.streams.events.StreamDeletedEvent) Maps(com.google.common.collect.Maps) AlarmCallbackConfigurationImpl(org.graylog2.alarmcallbacks.AlarmCallbackConfigurationImpl) AlarmCallbackConfigurationService(org.graylog2.alarmcallbacks.AlarmCallbackConfigurationService) DBCursor(com.mongodb.DBCursor) Output(org.graylog2.plugin.streams.Output) ValidationException(org.graylog2.plugin.database.ValidationException) ObjectId(org.bson.types.ObjectId) User(org.graylog2.plugin.database.users.User) Collections(java.util.Collections) ObjectId(org.bson.types.ObjectId) ImmutableList(com.google.common.collect.ImmutableList) StreamRule(org.graylog2.plugin.streams.StreamRule) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) Output(org.graylog2.plugin.streams.Output) BasicDBList(com.mongodb.BasicDBList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Stream(org.graylog2.plugin.streams.Stream) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) IndexSet(org.graylog2.indexer.IndexSet) MongoIndexSet(org.graylog2.indexer.MongoIndexSet)

Aggregations

StreamImpl (org.graylog2.streams.StreamImpl)7 ObjectId (org.bson.types.ObjectId)5 HashMap (java.util.HashMap)3 IndexSet (org.graylog2.indexer.IndexSet)3 ValidationException (org.graylog2.plugin.database.ValidationException)3 Stream (org.graylog2.plugin.streams.Stream)3 Test (org.junit.Test)3 BasicDBObject (com.mongodb.BasicDBObject)2 DBObject (com.mongodb.DBObject)2 StreamFilter (org.graylog.plugins.views.search.filter.StreamFilter)2 ViewDTO (org.graylog.plugins.views.search.views.ViewDTO)2 Entity (org.graylog2.contentpacks.model.entities.Entity)2 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)2 StreamEntity (org.graylog2.contentpacks.model.entities.StreamEntity)2 MongoConnection (org.graylog2.database.MongoConnection)2 Output (org.graylog2.plugin.streams.Output)2 StreamRule (org.graylog2.plugin.streams.StreamRule)2 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)1 Strings (com.google.common.base.Strings)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1