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);
}
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;
}
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);
}
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();
}
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;
}
Aggregations