use of javax.ws.rs.InternalServerErrorException in project graylog2-server by Graylog2.
the class RetentionStrategyResource method getRetentionStrategyDescription.
private RetentionStrategyDescription getRetentionStrategyDescription(@ApiParam(name = "strategy", value = "The name of the retention strategy", required = true) @PathParam("strategy") @NotEmpty String strategyName) {
final Provider<RetentionStrategy> provider = retentionStrategies.get(strategyName);
if (provider == null) {
throw new NotFoundException("Couldn't find retention strategy for given type " + strategyName);
}
final RetentionStrategy retentionStrategy = provider.get();
final RetentionStrategyConfig defaultConfig = retentionStrategy.defaultConfiguration();
final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
try {
objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(retentionStrategy.configurationClass()), visitor);
} catch (JsonMappingException e) {
throw new InternalServerErrorException("Couldn't generate JSON schema for retention strategy " + strategyName, e);
}
return RetentionStrategyDescription.create(strategyName, defaultConfig, visitor.finalSchema());
}
use of javax.ws.rs.InternalServerErrorException in project graylog2-server by Graylog2.
the class RotationStrategyResource method config.
@PUT
@Path("config")
@Consumes(MediaType.APPLICATION_JSON)
@Timed
@ApiOperation(value = "Configuration of the current rotation strategy", notes = "This resource stores the configuration of the currently used rotation strategy.")
@AuditEvent(type = AuditEventTypes.ES_INDEX_ROTATION_STRATEGY_UPDATE)
public RotationStrategySummary config(@ApiParam(value = "The description of the rotation strategy and its configuration", required = true) @Valid @NotNull RotationStrategySummary rotationStrategySummary) {
if (!rotationStrategies.containsKey(rotationStrategySummary.strategy())) {
throw new NotFoundException("Couldn't find rotation strategy for given type " + rotationStrategySummary.strategy());
}
final IndexManagementConfig oldConfig = clusterConfigService.get(IndexManagementConfig.class);
if (oldConfig == null) {
throw new InternalServerErrorException("Couldn't retrieve index management configuration");
}
final IndexManagementConfig indexManagementConfig = IndexManagementConfig.create(rotationStrategySummary.strategy(), oldConfig.retentionStrategy());
clusterConfigService.write(rotationStrategySummary.config());
clusterConfigService.write(indexManagementConfig);
return rotationStrategySummary;
}
use of javax.ws.rs.InternalServerErrorException 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 javax.ws.rs.InternalServerErrorException in project graylog2-server by Graylog2.
the class RotationStrategyResource method getRotationStrategyDescription.
private RotationStrategyDescription getRotationStrategyDescription(String strategyName) {
final Provider<RotationStrategy> provider = rotationStrategies.get(strategyName);
if (provider == null) {
throw new NotFoundException("Couldn't find rotation strategy for given type " + strategyName);
}
final RotationStrategy rotationStrategy = provider.get();
final RotationStrategyConfig defaultConfig = rotationStrategy.defaultConfiguration();
final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
try {
objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(rotationStrategy.configurationClass()), visitor);
} catch (JsonMappingException e) {
throw new InternalServerErrorException("Couldn't generate JSON schema for rotation strategy " + strategyName, e);
}
return RotationStrategyDescription.create(strategyName, defaultConfig, visitor.finalSchema());
}
use of javax.ws.rs.InternalServerErrorException in project graylog2-server by Graylog2.
the class UsersResource method setUserRoles.
private void setUserRoles(@Nullable List<String> roles, User user) {
if (roles != null) {
try {
final Map<String, Role> nameMap = roleService.loadAllLowercaseNameMap();
final Iterable<String> roleIds = Iterables.transform(roles, Roles.roleNameToIdFunction(nameMap));
user.setRoleIds(Sets.newHashSet(roleIds));
} catch (org.graylog2.database.NotFoundException e) {
throw new InternalServerErrorException(e);
}
}
}
Aggregations