Search in sources :

Example 46 with IndexSet

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);
}
Also used : Stream(org.graylog2.plugin.streams.Stream) Test(org.junit.Test)

Example 47 with IndexSet

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);
}
Also used : Stream(org.graylog2.plugin.streams.Stream) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 48 with IndexSet

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();
}
Also used : NullActivityWriter(org.graylog2.shared.system.activities.NullActivityWriter) RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) IndexSet(org.graylog2.indexer.IndexSet) Test(org.junit.Test)

Example 49 with IndexSet

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();
}
Also used : NullActivityWriter(org.graylog2.shared.system.activities.NullActivityWriter) RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) Test(org.junit.Test)

Example 50 with IndexSet

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;
}
Also used : ObjectId(org.bson.types.ObjectId) StreamImpl(org.graylog2.streams.StreamImpl) StreamRuleImpl(org.graylog2.streams.StreamRuleImpl) IndexSet(org.graylog2.indexer.IndexSet)

Aggregations

IndexSet (org.graylog2.indexer.IndexSet)31 Test (org.junit.Test)26 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)22 Timed (com.codahale.metrics.annotation.Timed)13 ApiOperation (io.swagger.annotations.ApiOperation)13 Path (javax.ws.rs.Path)12 AuditEvent (org.graylog2.audit.jersey.AuditEvent)11 ApiResponses (io.swagger.annotations.ApiResponses)10 Map (java.util.Map)9 POST (javax.ws.rs.POST)9 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)9 BadRequestException (javax.ws.rs.BadRequestException)8 NotFoundException (javax.ws.rs.NotFoundException)8 Produces (javax.ws.rs.Produces)8 DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)8 Set (java.util.Set)7 Collectors (java.util.stream.Collectors)7 Inject (javax.inject.Inject)7 IndexSetRegistry (org.graylog2.indexer.IndexSetRegistry)7 Api (io.swagger.annotations.Api)6