Search in sources :

Example 6 with IndexSetSummary

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());
    }
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) BadRequestException(javax.ws.rs.BadRequestException) DuplicateKeyException(com.mongodb.DuplicateKeyException) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 7 with IndexSetSummary

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);
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) Test(org.junit.Test)

Example 8 with IndexSetSummary

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);
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) MessageCountRotationStrategy(org.graylog2.indexer.rotation.strategies.MessageCountRotationStrategy) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) Test(org.junit.Test)

Aggregations

DefaultIndexSetConfig (org.graylog2.indexer.indexset.DefaultIndexSetConfig)8 IndexSetConfig (org.graylog2.indexer.indexset.IndexSetConfig)8 Timed (com.codahale.metrics.annotation.Timed)5 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 AuditEvent (org.graylog2.audit.jersey.AuditEvent)5 IndexSetSummary (org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary)5 ClientErrorException (javax.ws.rs.ClientErrorException)4 NotFoundException (javax.ws.rs.NotFoundException)4 PUT (javax.ws.rs.PUT)4 Path (javax.ws.rs.Path)4 DuplicateKeyException (com.mongodb.DuplicateKeyException)3 BadRequestException (javax.ws.rs.BadRequestException)3 Consumes (javax.ws.rs.Consumes)3 POST (javax.ws.rs.POST)3 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)3 Api (io.swagger.annotations.Api)2 ApiParam (io.swagger.annotations.ApiParam)2 ApiResponse (io.swagger.annotations.ApiResponse)2 Collections (java.util.Collections)2