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();
}
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);
}
}
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!");
}
}
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();
}
Aggregations