use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class Messages method bulkIndex.
public boolean bulkIndex(final List<Map.Entry<IndexSet, Message>> messageList) {
if (messageList.isEmpty()) {
return true;
}
final BulkRequestBuilder requestBuilder = c.prepareBulk().setConsistencyLevel(WriteConsistencyLevel.ONE);
for (Map.Entry<IndexSet, Message> entry : messageList) {
requestBuilder.add(buildIndexRequest(entry.getKey().getWriteIndexAlias(), entry.getValue().toElasticSearchObject(invalidTimestampMeter), entry.getValue().getId()));
}
final BulkResponse response = runBulkRequest(requestBuilder.request());
LOG.debug("Index: Bulk indexed {} messages, took {} ms, failures: {}", response.getItems().length, response.getTookInMillis(), response.hasFailures());
if (response.hasFailures()) {
propagateFailure(response.getItems(), messageList, response.buildFailureMessage());
}
return !response.hasFailures();
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class CountsTest method totalReturnsMinusOneIfIndexDoesNotExist.
@Test
public void totalReturnsMinusOneIfIndexDoesNotExist() throws Exception {
final IndexSet indexSet = mock(IndexSet.class);
when(indexSet.getManagedIndices()).thenReturn(new String[] { "does_not_exist" });
assertThat(counts.total(indexSet)).isEqualTo(-1L);
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class SizeBasedRotationStrategyTest method testDontRotate.
@Test
public void testDontRotate() throws Exception {
final CommonStats commonStats = new CommonStats();
commonStats.store = new StoreStats(1000, 0);
final IndexStatistics stats = IndexStatistics.create("name", commonStats, commonStats, Collections.<ShardRouting>emptyList());
when(indices.getIndexStats("name")).thenReturn(stats);
when(indexSet.getNewestIndex()).thenReturn("name");
when(indexSet.getConfig()).thenReturn(indexSetConfig);
when(indexSetConfig.rotationStrategy()).thenReturn(SizeBasedRotationStrategyConfig.create(100000L));
final SizeBasedRotationStrategy strategy = new SizeBasedRotationStrategy(indices, nodeId, auditEventSender);
strategy.rotate(indexSet);
verify(indexSet, never()).cycle();
reset(indexSet);
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class SizeBasedRotationStrategyTest method testRotate.
@Test
public void testRotate() throws Exception {
final CommonStats commonStats = new CommonStats();
commonStats.store = new StoreStats(1000, 0);
final IndexStatistics stats = IndexStatistics.create("name", commonStats, commonStats, Collections.<ShardRouting>emptyList());
when(indices.getIndexStats("name")).thenReturn(stats);
when(indexSet.getNewestIndex()).thenReturn("name");
when(indexSet.getConfig()).thenReturn(indexSetConfig);
when(indexSetConfig.rotationStrategy()).thenReturn(SizeBasedRotationStrategyConfig.create(100L));
final SizeBasedRotationStrategy strategy = new SizeBasedRotationStrategy(indices, nodeId, auditEventSender);
strategy.rotate(indexSet);
verify(indexSet, times(1)).cycle();
reset(indexSet);
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class IndexSetValidatorTest method validate.
@Test
public void validate() throws Exception {
final String prefix = "graylog_index";
final IndexSetConfig newConfig = mock(IndexSetConfig.class);
final IndexSet indexSet = mock(IndexSet.class);
when(indexSet.getIndexPrefix()).thenReturn("foo");
when(indexSetRegistry.iterator()).thenReturn(Collections.singleton(indexSet).iterator());
when(newConfig.indexPrefix()).thenReturn(prefix);
final Optional<IndexSetValidator.Violation> violation = validator.validate(newConfig);
assertThat(violation).isNotPresent();
}
Aggregations