use of org.graylog2.indexer.indices.Indices 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.indices.Indices 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.indices.Indices in project graylog2-server by Graylog2.
the class IndicesResource method indexSetOpen.
@GET
@Path("/{indexSetId}/open")
@Timed
@ApiOperation(value = "Get information of all open indices managed by Graylog and their shards.")
@RequiresPermissions(RestPermissions.INDICES_READ)
@Produces(MediaType.APPLICATION_JSON)
public OpenIndicesInfo indexSetOpen(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
final Set<IndexStatistics> indicesStats = indices.getIndicesStats(indexSet).stream().filter(indexStats -> indexSetRegistry.isManagedIndex(indexStats.indexName())).collect(Collectors.toSet());
return getOpenIndicesInfo(indicesStats);
}
use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.
the class IndexRangesResource method rebuildIndex.
@POST
@Timed
@Path("/{index: [a-z_0-9-]+}/rebuild")
@ApiOperation(value = "Rebuild/sync index range information.", notes = "This triggers a system job that scans an index and stores meta information " + "about what indices contain messages in what time ranges. It atomically overwrites " + "already existing meta information.")
@ApiResponses(value = { @ApiResponse(code = 202, message = "Rebuild/sync system job triggered.") })
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ES_INDEX_RANGE_UPDATE_JOB)
public Response rebuildIndex(@ApiParam(name = "index", value = "The name of the Graylog-managed Elasticsearch index", required = true) @PathParam("index") @NotEmpty String index) {
if (!indexSetRegistry.isManagedIndex(index)) {
throw new BadRequestException(index + " is not a Graylog-managed Elasticsearch index.");
}
checkPermission(RestPermissions.INDEXRANGES_REBUILD, index);
final SystemJob rebuildJob = singleIndexRangeJobFactory.create(indexSetRegistry.getAll(), index);
try {
this.systemJobManager.submit(rebuildJob);
} catch (SystemJobConcurrencyException e) {
final String msg = "Concurrency level of this job reached: " + e.getMessage();
LOG.error(msg);
throw new ForbiddenException(msg, e);
}
return Response.accepted().build();
}
use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.
the class IndicesTest method testCreateOverwritesIndexTemplate.
@Test
public void testCreateOverwritesIndexTemplate() throws Exception {
final ObjectMapper mapper = new ObjectMapperProvider().get();
final String templateName = indexSetConfig.indexTemplateName();
final IndicesAdminClient client = this.client.admin().indices();
final ImmutableMap<String, Object> beforeMapping = ImmutableMap.of("_source", ImmutableMap.of("enabled", false), "properties", ImmutableMap.of("message", ImmutableMap.of("type", "string", "index", "not_analyzed")));
assertThat(client.preparePutTemplate(templateName).setTemplate(indexSet.getIndexWildcard()).addMapping(IndexMapping.TYPE_MESSAGE, beforeMapping).get().isAcknowledged()).isTrue();
final GetIndexTemplatesResponse responseBefore = client.prepareGetTemplates(templateName).get();
final List<IndexTemplateMetaData> beforeIndexTemplates = responseBefore.getIndexTemplates();
assertThat(beforeIndexTemplates).hasSize(1);
final ImmutableOpenMap<String, CompressedXContent> beforeMappings = beforeIndexTemplates.get(0).getMappings();
final Map<String, Object> actualMapping = mapper.readValue(beforeMappings.get(IndexMapping.TYPE_MESSAGE).uncompressed(), new TypeReference<Map<String, Object>>() {
});
assertThat(actualMapping.get(IndexMapping.TYPE_MESSAGE)).isEqualTo(beforeMapping);
indices.create("index_template_test", indexSet);
final GetIndexTemplatesResponse responseAfter = client.prepareGetTemplates(templateName).get();
assertThat(responseAfter.getIndexTemplates()).hasSize(1);
final IndexTemplateMetaData templateMetaData = responseAfter.getIndexTemplates().get(0);
assertThat(templateMetaData.getName()).isEqualTo(templateName);
assertThat(templateMetaData.getMappings().keysIt()).containsExactly(IndexMapping.TYPE_MESSAGE);
final Map<String, Object> mapping = mapper.readValue(templateMetaData.getMappings().get(IndexMapping.TYPE_MESSAGE).uncompressed(), new TypeReference<Map<String, Object>>() {
});
final Map<String, Object> expectedTemplate = new IndexMapping().messageTemplate(indexSet.getIndexWildcard(), indexSetConfig.indexAnalyzer());
assertThat(mapping).isEqualTo(expectedTemplate.get("mappings"));
final DeleteIndexTemplateRequest deleteRequest = client.prepareDeleteTemplate(templateName).request();
final DeleteIndexTemplateResponse deleteResponse = client.deleteTemplate(deleteRequest).actionGet();
assertThat(deleteResponse.isAcknowledged()).isTrue();
indices.delete("index_template_test");
}
Aggregations