use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class V20161116172200_CreateDefaultStreamMigrationTest method upgrade.
@Test
public void upgrade() throws Exception {
final ArgumentCaptor<Stream> streamArgumentCaptor = ArgumentCaptor.forClass(Stream.class);
when(streamService.load("000000000000000000000001")).thenThrow(NotFoundException.class);
when(indexSetRegistry.getDefault()).thenReturn(indexSet);
migration.upgrade();
verify(streamService).save(streamArgumentCaptor.capture());
final Stream stream = streamArgumentCaptor.getValue();
assertThat(stream.getTitle()).isEqualTo("All messages");
assertThat(stream.getDisabled()).isFalse();
assertThat(stream.getMatchingType()).isEqualTo(StreamImpl.MatchingType.DEFAULT);
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class MessageTest method testStreamMutatorsWithIndexSets.
@Test
public void testStreamMutatorsWithIndexSets() {
final Stream stream1 = mock(Stream.class);
final Stream stream2 = mock(Stream.class);
final Stream stream3 = mock(Stream.class);
final IndexSet indexSet1 = mock(IndexSet.class);
final IndexSet indexSet2 = mock(IndexSet.class);
assertThat(message.getIndexSets()).isEmpty();
when(stream1.getIndexSet()).thenReturn(indexSet1);
when(stream2.getIndexSet()).thenReturn(indexSet1);
when(stream3.getIndexSet()).thenReturn(indexSet2);
message.addStream(stream1);
message.addStreams(Sets.newHashSet(stream2, stream3));
assertThat(message.getIndexSets()).containsOnly(indexSet1, indexSet2);
message.removeStream(stream3);
assertThat(message.getIndexSets()).containsOnly(indexSet1);
final Set<IndexSet> indexSets = message.getIndexSets();
message.addStream(stream3);
// getIndexSets is a copy and doesn't change after mutations
assertThat(indexSets).containsOnly(indexSet1);
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class IndexRotationThreadTest method testPerformRotation.
@Test
public void testPerformRotation() throws NoTargetIndexException {
final Provider<RotationStrategy> provider = new RotationStrategyProvider() {
@Override
public void doRotate(IndexSet indexSet) {
indexSet.cycle();
}
};
final IndexRotationThread rotationThread = new IndexRotationThread(notificationService, indices, indexSetRegistry, cluster, new NullActivityWriter(), nodeId, ImmutableMap.<String, Provider<RotationStrategy>>builder().put("strategy", provider).build());
when(indexSetConfig.rotationStrategyClass()).thenReturn("strategy");
rotationThread.checkForRotation(indexSet);
verify(indexSet, times(1)).cycle();
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class IndexRotationThreadTest method testDoNotPerformRotationIfClusterIsDown.
@Test
public void testDoNotPerformRotationIfClusterIsDown() throws NoTargetIndexException {
final Provider<RotationStrategy> provider = spy(new RotationStrategyProvider());
when(cluster.isConnected()).thenReturn(false);
final IndexRotationThread rotationThread = new IndexRotationThread(notificationService, indices, indexSetRegistry, cluster, new NullActivityWriter(), nodeId, ImmutableMap.<String, Provider<RotationStrategy>>builder().put("strategy", provider).build());
rotationThread.doRun();
verify(indexSet, never()).cycle();
verify(provider, never()).get();
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class BundleImporter method createStream.
private org.graylog2.plugin.streams.Stream createStream(final String bundleId, final Stream streamDescription, final String userName) throws ValidationException {
// We cannot create streams without having a default index set.
final IndexSet indexSet = indexSetRegistry.getDefault();
final Map<String, Object> streamData = ImmutableMap.<String, Object>builder().put(StreamImpl.FIELD_TITLE, streamDescription.getTitle()).put(StreamImpl.FIELD_DESCRIPTION, streamDescription.getDescription()).put(StreamImpl.FIELD_DISABLED, streamDescription.isDisabled()).put(StreamImpl.FIELD_MATCHING_TYPE, streamDescription.getMatchingType().name()).put(StreamImpl.FIELD_CREATOR_USER_ID, userName).put(StreamImpl.FIELD_CREATED_AT, Tools.nowUTC()).put(StreamImpl.FIELD_CONTENT_PACK, bundleId).put(StreamImpl.FIELD_DEFAULT_STREAM, streamDescription.isDefaultStream()).put(StreamImpl.FIELD_INDEX_SET_ID, indexSet.getConfig().id()).build();
final String defaultStreamId = org.graylog2.plugin.streams.Stream.DEFAULT_STREAM_ID;
final ObjectId id = streamDescription.isDefaultStream() ? new ObjectId(defaultStreamId) : new ObjectId(streamDescription.getId());
final org.graylog2.plugin.streams.Stream stream = new StreamImpl(id, streamData, Collections.emptyList(), Collections.emptySet(), indexSet);
final String streamId = streamService.save(stream);
if (streamDescription.getStreamRules() != null) {
for (StreamRule streamRule : streamDescription.getStreamRules()) {
final Map<String, Object> streamRuleData = ImmutableMap.<String, Object>builder().put(StreamRuleImpl.FIELD_TYPE, streamRule.getType().toInteger()).put(StreamRuleImpl.FIELD_VALUE, streamRule.getValue()).put(StreamRuleImpl.FIELD_FIELD, streamRule.getField()).put(StreamRuleImpl.FIELD_INVERTED, streamRule.isInverted()).put(StreamRuleImpl.FIELD_STREAM_ID, new ObjectId(streamId)).put(StreamRuleImpl.FIELD_CONTENT_PACK, bundleId).put(StreamRuleImpl.FIELD_DESCRIPTION, streamRule.getDescription()).build();
streamRuleService.save(new StreamRuleImpl(streamRuleData));
}
}
for (final String outputId : streamDescription.getOutputs()) {
if (isNullOrEmpty(outputId)) {
LOG.warn("Couldn't find referenced output <{}> for stream <{}>", outputId, streamDescription.getTitle());
} else {
streamService.addOutput(stream, outputsByReferenceId.get(outputId));
}
}
return stream;
}
Aggregations