use of org.graylog2.indexer.indexset.IndexSetConfig 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();
}
use of org.graylog2.indexer.indexset.IndexSetConfig 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.IndexSetConfig 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.IndexSetConfig 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.IndexSetConfig in project graylog2-server by Graylog2.
the class IndexSetsResource method get.
@GET
@Path("{id}")
@Timed
@ApiOperation(value = "Get index set")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 404, message = "Index set not found") })
public IndexSetSummary get(@ApiParam(name = "id", required = true) @PathParam("id") String id) {
checkPermission(RestPermissions.INDEXSETS_READ, id);
final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
return indexSetService.get(id).map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).orElseThrow(() -> new NotFoundException("Couldn't load index set with ID <" + id + ">"));
}
Aggregations