use of org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary 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.rest.resources.system.indexer.responses.IndexSetSummary in project graylog2-server by Graylog2.
the class IndexSetsResourceTest method save.
@Test
public void save() {
final IndexSetConfig indexSetConfig = IndexSetConfig.create("title", "description", true, "prefix", 1, 0, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(1), ZonedDateTime.of(2016, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC), "standard", "prefix-template", 1, false);
final IndexSetConfig savedIndexSetConfig = indexSetConfig.toBuilder().id("id").build();
when(indexSetService.save(indexSetConfig)).thenReturn(savedIndexSetConfig);
final IndexSetSummary summary = indexSetsResource.save(IndexSetSummary.fromIndexSetConfig(indexSetConfig, false));
verify(indexSetService, times(1)).save(indexSetConfig);
verify(indexSetService, times(1)).getDefault();
verifyNoMoreInteractions(indexSetService);
assertThat(summary.toIndexSetConfig()).isEqualTo(savedIndexSetConfig);
}
use of org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary in project graylog2-server by Graylog2.
the class IndexSetsResourceTest method update.
@Test
public void update() {
final IndexSetConfig indexSetConfig = IndexSetConfig.create("id", "new title", "description", true, "prefix", 1, 0, MessageCountRotationStrategy.class.getCanonicalName(), MessageCountRotationStrategyConfig.create(1000), NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.create(1), ZonedDateTime.of(2016, 10, 10, 12, 0, 0, 0, ZoneOffset.UTC), "standard", "index-template", 1, false);
final IndexSetConfig updatedIndexSetConfig = indexSetConfig.toBuilder().title("new title").build();
when(indexSetService.get("id")).thenReturn(Optional.of(indexSetConfig));
when(indexSetService.save(indexSetConfig)).thenReturn(updatedIndexSetConfig);
final IndexSetSummary summary = indexSetsResource.update("id", IndexSetUpdateRequest.fromIndexSetConfig(indexSetConfig));
verify(indexSetService, times(1)).get("id");
verify(indexSetService, times(1)).save(indexSetConfig);
verify(indexSetService, times(1)).getDefault();
verifyNoMoreInteractions(indexSetService);
// The real update wouldn't replace the index template nameā¦
final IndexSetConfig actual = summary.toIndexSetConfig().toBuilder().indexTemplateName("index-template").build();
assertThat(actual).isEqualTo(updatedIndexSetConfig);
}
Aggregations