use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class IndexSetValidatorTest method validateWithConflict.
@Test
public void validateWithConflict() throws Exception {
final IndexSetConfig newConfig = mock(IndexSetConfig.class);
final IndexSet indexSet = mock(IndexSet.class);
when(indexSetRegistry.iterator()).thenReturn(Collections.singleton(indexSet).iterator());
// New index prefix starts with existing index prefix
when(indexSet.getIndexPrefix()).thenReturn("graylog");
when(newConfig.indexPrefix()).thenReturn("graylog_index");
final Optional<IndexSetValidator.Violation> violation = validator.validate(newConfig);
assertThat(violation).isPresent();
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class IndexSetValidatorTest method validateWhenAlreadyManaged.
@Test
public void validateWhenAlreadyManaged() 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.isManagedIndex("graylog_index_0")).thenReturn(true);
when(indexSetRegistry.iterator()).thenReturn(Collections.singleton(indexSet).iterator());
when(newConfig.indexPrefix()).thenReturn(prefix);
final Optional<IndexSetValidator.Violation> violation = validator.validate(newConfig);
assertThat(violation).isPresent();
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class MongoIndexSetRegistryTest method getAllShouldBeCachedForNonEmptyList.
@Test
public void getAllShouldBeCachedForNonEmptyList() {
final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
final MongoIndexSet indexSet = mock(MongoIndexSet.class);
when(mongoIndexSetFactory.create(indexSetConfig)).thenReturn(indexSet);
when(indexSetService.findAll()).thenReturn(indexSetConfigs);
assertThat(this.indexSetRegistry.getAll()).isNotNull().isNotEmpty().hasSize(1).containsExactly(indexSet);
assertThat(this.indexSetRegistry.getAll()).isNotNull().isNotEmpty().hasSize(1).containsExactly(indexSet);
verify(indexSetService, times(1)).findAll();
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class IndexRangesResource method rebuildIndexSet.
@POST
@Timed
@Path("/index_set/{indexSetId}/rebuild")
@RequiresPermissions(RestPermissions.INDEXRANGES_REBUILD)
@ApiOperation(value = "Rebuild/sync index range information for the given index set.", notes = "This triggers a systemjob that scans every index in the given index set and stores meta information " + "about what indices contain messages in what timeranges. It atomically overwrites " + "already existing meta information.")
@ApiResponses(value = { @ApiResponse(code = 202, message = "Rebuild/sync systemjob triggered.") })
@Produces(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.ES_INDEX_RANGE_UPDATE_JOB)
public Response rebuildIndexSet(@ApiParam(name = "indexSetId") @PathParam("indexSetId") @NotBlank final String indexSetId) {
final IndexSet indexSet = indexSetRegistry.get(indexSetId).orElseThrow(() -> new javax.ws.rs.NotFoundException("Index set <" + indexSetId + "> not found!"));
submitIndexRangesJob(Collections.singleton(indexSet));
return Response.accepted().build();
}
use of org.graylog2.indexer.IndexSet in project graylog2-server by Graylog2.
the class IndexSetsResource method list.
@GET
@Timed
@ApiOperation(value = "Get a list of all index sets")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized") })
public IndexSetResponse list(@ApiParam(name = "skip", value = "The number of elements to skip (offset).", required = true) @QueryParam("skip") @DefaultValue("0") int skip, @ApiParam(name = "limit", value = "The maximum number of elements to return.", required = true) @QueryParam("limit") @DefaultValue("0") int limit, @ApiParam(name = "stats", value = "Include index set stats.") @QueryParam("stats") @DefaultValue("false") boolean computeStats) {
final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
List<IndexSetSummary> indexSets;
int count;
if (limit > 0) {
// First collect all index set ids the user is allowed to see.
final Set<String> allowedIds = indexSetService.findAll().stream().filter(indexSet -> isPermitted(RestPermissions.INDEXSETS_READ, indexSet.id())).map(IndexSetConfig::id).collect(Collectors.toSet());
indexSets = indexSetService.findPaginated(allowedIds, limit, skip).stream().map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
count = allowedIds.size();
} else {
indexSets = indexSetService.findAll().stream().filter(indexSetConfig -> isPermitted(RestPermissions.INDEXSETS_READ, indexSetConfig.id())).map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
count = indexSets.size();
}
final Map<String, IndexSetStats> stats;
if (computeStats) {
stats = indexSetRegistry.getAll().stream().collect(Collectors.toMap(indexSet -> indexSet.getConfig().id(), indexSetStatsCreator::getForIndexSet));
} else {
stats = Collections.emptyMap();
}
return IndexSetResponse.create(count, indexSets, stats);
}
Aggregations