use of org.graylog2.indexer.indexset.IndexSetConfig in project graylog2-server by Graylog2.
the class IndexSetsResource method save.
@POST
@Timed
@ApiOperation(value = "Create index set")
@RequiresPermissions(RestPermissions.INDEXSETS_CREATE)
@Consumes(MediaType.APPLICATION_JSON)
@AuditEvent(type = AuditEventTypes.INDEX_SET_CREATE)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized") })
public IndexSetSummary save(@ApiParam(name = "Index set configuration", required = true) @Valid @NotNull IndexSetSummary indexSet) {
try {
final IndexSetConfig indexSetConfig = indexSet.toIndexSetConfig();
final Optional<IndexSetValidator.Violation> violation = indexSetValidator.validate(indexSetConfig);
if (violation.isPresent()) {
throw new BadRequestException(violation.get().message());
}
final IndexSetConfig savedObject = indexSetService.save(indexSetConfig);
final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
return IndexSetSummary.fromIndexSetConfig(savedObject, savedObject.equals(defaultIndexSet));
} catch (DuplicateKeyException e) {
throw new BadRequestException(e.getMessage());
}
}
use of org.graylog2.indexer.indexset.IndexSetConfig in project graylog2-server by Graylog2.
the class IndexSetValidatorTest method validateWithConflict2.
@Test
public void validateWithConflict2() throws Exception {
final IndexSetConfig newConfig = mock(IndexSetConfig.class);
final IndexSet indexSet = mock(IndexSet.class);
when(indexSetRegistry.iterator()).thenReturn(Collections.singleton(indexSet).iterator());
// Existing index prefix starts with new index prefix
when(indexSet.getIndexPrefix()).thenReturn("graylog");
when(newConfig.indexPrefix()).thenReturn("gray");
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 indexSetsCacheShouldReturnCachedList.
@Test
public void indexSetsCacheShouldReturnCachedList() {
final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
when(indexSetService.findAll()).thenReturn(indexSetConfigs);
final List<IndexSetConfig> result = this.indexSetsCache.get();
assertThat(result).isNotNull().hasSize(1).containsExactly(indexSetConfig);
final List<IndexSetConfig> cachedResult = this.indexSetsCache.get();
assertThat(cachedResult).isNotNull().hasSize(1).containsExactly(indexSetConfig);
verify(indexSetService, times(1)).findAll();
}
use of org.graylog2.indexer.indexset.IndexSetConfig in project graylog2-server by Graylog2.
the class MongoIndexSetRegistryTest method indexSetsCacheShouldBeInvalidatedForIndexSetDeletion.
@Test
public void indexSetsCacheShouldBeInvalidatedForIndexSetDeletion() {
final IndexSetConfig indexSetConfig = mock(IndexSetConfig.class);
final List<IndexSetConfig> indexSetConfigs = Collections.singletonList(indexSetConfig);
when(indexSetService.findAll()).thenReturn(indexSetConfigs);
final List<IndexSetConfig> result = this.indexSetsCache.get();
assertThat(result).isNotNull().hasSize(1).containsExactly(indexSetConfig);
this.indexSetsCache.handleIndexSetDeletion(mock(IndexSetDeletedEvent.class));
final IndexSetConfig newIndexSetConfig = mock(IndexSetConfig.class);
final List<IndexSetConfig> newIndexSetConfigs = Collections.singletonList(newIndexSetConfig);
when(indexSetService.findAll()).thenReturn(newIndexSetConfigs);
final List<IndexSetConfig> newResult = this.indexSetsCache.get();
assertThat(newResult).isNotNull().hasSize(1).containsExactly(newIndexSetConfig);
verify(indexSetService, times(2)).findAll();
}
use of org.graylog2.indexer.indexset.IndexSetConfig in project graylog2-server by Graylog2.
the class MongoIndexSetRegistryTest method getAllShouldNotBeCachedForCallAfterInvalidate.
@Test
public void getAllShouldNotBeCachedForCallAfterInvalidate() {
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);
this.indexSetsCache.invalidate();
assertThat(this.indexSetRegistry.getAll()).isNotNull().isNotEmpty().hasSize(1).containsExactly(indexSet);
verify(indexSetService, times(2)).findAll();
}
Aggregations