Search in sources :

Example 1 with ConfigClass

use of org.graylog2.plugin.inputs.annotations.ConfigClass in project graylog2-server by Graylog2.

the class RotationStrategyResource method config.

@GET
@Path("config")
@Timed
@ApiOperation(value = "Configuration of the current rotation strategy", notes = "This resource returns the configuration of the currently used rotation strategy.")
public RotationStrategySummary config() {
    final IndexManagementConfig indexManagementConfig = clusterConfigService.get(IndexManagementConfig.class);
    if (indexManagementConfig == null) {
        throw new InternalServerErrorException("Couldn't retrieve index management configuration");
    }
    final String strategyName = indexManagementConfig.rotationStrategy();
    final Provider<RotationStrategy> provider = rotationStrategies.get(strategyName);
    if (provider == null) {
        throw new InternalServerErrorException("Couldn't retrieve rotation strategy provider");
    }
    final RotationStrategy rotationStrategy = provider.get();
    @SuppressWarnings("unchecked") final Class<RotationStrategyConfig> configClass = (Class<RotationStrategyConfig>) rotationStrategy.configurationClass();
    final RotationStrategyConfig config = clusterConfigService.get(configClass);
    return RotationStrategySummary.create(strategyName, config);
}
Also used : RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) RotationStrategyConfig(org.graylog2.plugin.indexer.rotation.RotationStrategyConfig) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) IndexManagementConfig(org.graylog2.indexer.management.IndexManagementConfig) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with ConfigClass

use of org.graylog2.plugin.inputs.annotations.ConfigClass in project graylog2-server by Graylog2.

the class V20161116172100_DefaultIndexSetMigration method getRotationStrategyConfig.

private RotationStrategyConfig getRotationStrategyConfig(IndexManagementConfig indexManagementConfig) {
    final String strategyName = indexManagementConfig.rotationStrategy();
    final Provider<RotationStrategy> provider = rotationStrategies.get(strategyName);
    checkState(provider != null, "Couldn't retrieve rotation strategy provider for <" + strategyName + ">");
    final RotationStrategy rotationStrategy = provider.get();
    @SuppressWarnings("unchecked") final Class<RotationStrategyConfig> configClass = (Class<RotationStrategyConfig>) rotationStrategy.configurationClass();
    final RotationStrategyConfig rotationStrategyConfig = clusterConfigService.get(configClass);
    checkState(rotationStrategyConfig != null, "Couldn't retrieve rotation strategy config for <" + strategyName + ">");
    return rotationStrategyConfig;
}
Also used : RotationStrategy(org.graylog2.plugin.indexer.rotation.RotationStrategy) RotationStrategyConfig(org.graylog2.plugin.indexer.rotation.RotationStrategyConfig)

Example 3 with ConfigClass

use of org.graylog2.plugin.inputs.annotations.ConfigClass in project graylog2-server by Graylog2.

the class RetentionStrategyResource method config.

@GET
@Path("config")
@Timed
@ApiOperation(value = "Configuration of the current retention strategy", notes = "This resource returns the configuration of the currently used retention strategy.")
public RetentionStrategySummary config() {
    final IndexManagementConfig indexManagementConfig = clusterConfigService.get(IndexManagementConfig.class);
    if (indexManagementConfig == null) {
        throw new InternalServerErrorException("Couldn't retrieve index management configuration");
    }
    final String strategyName = indexManagementConfig.retentionStrategy();
    final Provider<RetentionStrategy> provider = retentionStrategies.get(strategyName);
    if (provider == null) {
        LOG.error("Couldn't retrieve retention strategy provider for {}. Returning no-op strategy config.", strategyName);
        return RetentionStrategySummary.create(NoopRetentionStrategy.class.getCanonicalName(), NoopRetentionStrategyConfig.createDefault());
    }
    final RetentionStrategy retentionStrategy = provider.get();
    @SuppressWarnings("unchecked") final Class<RetentionStrategyConfig> configClass = (Class<RetentionStrategyConfig>) retentionStrategy.configurationClass();
    final RetentionStrategyConfig config = clusterConfigService.get(configClass);
    return RetentionStrategySummary.create(strategyName, config);
}
Also used : NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) NoopRetentionStrategyConfig(org.graylog2.indexer.retention.strategies.NoopRetentionStrategyConfig) RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) RetentionStrategy(org.graylog2.plugin.indexer.retention.RetentionStrategy) NoopRetentionStrategy(org.graylog2.indexer.retention.strategies.NoopRetentionStrategy) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) IndexManagementConfig(org.graylog2.indexer.management.IndexManagementConfig) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with ConfigClass

use of org.graylog2.plugin.inputs.annotations.ConfigClass in project graylog2-server by Graylog2.

the class ClusterConfigResource method update.

@PUT
@Timed
@Path("{configClass}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update configuration in database")
@RequiresPermissions({ RestPermissions.CLUSTER_CONFIG_ENTRY_CREATE, RestPermissions.CLUSTER_CONFIG_ENTRY_EDIT })
@AuditEvent(type = AuditEventTypes.CLUSTER_CONFIGURATION_UPDATE)
public Response update(@ApiParam(name = "configClass", value = "The name of the cluster configuration class", required = true) @PathParam("configClass") @NotBlank String configClass, @ApiParam(name = "body", value = "The payload of the cluster configuration", required = true) @NotNull InputStream body) throws IOException {
    final Class<?> cls = classFromName(configClass);
    if (cls == null) {
        throw new NotFoundException("Couldn't find configuration class \"" + configClass + "\"");
    }
    final Object o;
    try {
        o = objectMapper.readValue(body, cls);
    } catch (Exception e) {
        final String msg = "Couldn't parse cluster configuration \"" + configClass + "\".";
        LOG.error(msg, e);
        throw new BadRequestException(msg);
    }
    try {
        clusterConfigService.write(o);
    } catch (Exception e) {
        final String msg = "Couldn't write cluster config \"" + configClass + "\".";
        LOG.error(msg, e);
        throw new InternalServerErrorException(msg, e);
    }
    return Response.accepted(o).build();
}
Also used : NotFoundException(javax.ws.rs.NotFoundException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) BadRequestException(javax.ws.rs.BadRequestException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) IOException(java.io.IOException) NotFoundException(javax.ws.rs.NotFoundException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) Path(javax.ws.rs.Path) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent) PUT(javax.ws.rs.PUT)

Example 5 with ConfigClass

use of org.graylog2.plugin.inputs.annotations.ConfigClass in project graylog2-server by Graylog2.

the class V20161116172100_DefaultIndexSetMigration method getRetentionStrategyConfig.

private RetentionStrategyConfig getRetentionStrategyConfig(IndexManagementConfig indexManagementConfig) {
    final String strategyName = indexManagementConfig.retentionStrategy();
    final Provider<RetentionStrategy> provider = retentionStrategies.get(strategyName);
    checkState(provider != null, "Couldn't retrieve retention strategy provider for <" + strategyName + ">");
    final RetentionStrategy retentionStrategy = provider.get();
    @SuppressWarnings("unchecked") final Class<RetentionStrategyConfig> configClass = (Class<RetentionStrategyConfig>) retentionStrategy.configurationClass();
    final RetentionStrategyConfig retentionStrategyConfig = clusterConfigService.get(configClass);
    checkState(retentionStrategyConfig != null, "Couldn't retrieve retention strategy config for <" + strategyName + ">");
    return retentionStrategyConfig;
}
Also used : RetentionStrategyConfig(org.graylog2.plugin.indexer.retention.RetentionStrategyConfig) RetentionStrategy(org.graylog2.plugin.indexer.retention.RetentionStrategy)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)3 ApiOperation (io.swagger.annotations.ApiOperation)3 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)3 Path (javax.ws.rs.Path)3 GET (javax.ws.rs.GET)2 IndexManagementConfig (org.graylog2.indexer.management.IndexManagementConfig)2 RetentionStrategy (org.graylog2.plugin.indexer.retention.RetentionStrategy)2 RetentionStrategyConfig (org.graylog2.plugin.indexer.retention.RetentionStrategyConfig)2 RotationStrategy (org.graylog2.plugin.indexer.rotation.RotationStrategy)2 RotationStrategyConfig (org.graylog2.plugin.indexer.rotation.RotationStrategyConfig)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 IOException (java.io.IOException)1 BadRequestException (javax.ws.rs.BadRequestException)1 Consumes (javax.ws.rs.Consumes)1 NotFoundException (javax.ws.rs.NotFoundException)1 PUT (javax.ws.rs.PUT)1 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)1 AuditEvent (org.graylog2.audit.jersey.AuditEvent)1 NoopRetentionStrategy (org.graylog2.indexer.retention.strategies.NoopRetentionStrategy)1 NoopRetentionStrategyConfig (org.graylog2.indexer.retention.strategies.NoopRetentionStrategyConfig)1