use of javax.ws.rs.InternalServerErrorException 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 javax.ws.rs.InternalServerErrorException in project graylog2-server by Graylog2.
the class RetentionStrategyResource method config.
@PUT
@Path("config")
@Consumes(MediaType.APPLICATION_JSON)
@Timed
@ApiOperation(value = "Configuration of the current retention strategy", notes = "This resource stores the configuration of the currently used retention strategy.")
@AuditEvent(type = AuditEventTypes.ES_INDEX_RETENTION_STRATEGY_UPDATE)
public RetentionStrategySummary config(@ApiParam(value = "The description of the retention strategy and its configuration", required = true) @Valid @NotNull RetentionStrategySummary retentionStrategySummary) {
if (!retentionStrategies.containsKey(retentionStrategySummary.strategy())) {
throw new NotFoundException("Couldn't find retention strategy for given type " + retentionStrategySummary.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(oldConfig.rotationStrategy(), retentionStrategySummary.strategy());
clusterConfigService.write(retentionStrategySummary.config());
clusterConfigService.write(indexManagementConfig);
return retentionStrategySummary;
}
use of javax.ws.rs.InternalServerErrorException in project graylog2-server by Graylog2.
the class LdapResource method readGroups.
@GET
@ApiOperation(value = "Get the available LDAP groups", notes = "")
@RequiresPermissions(RestPermissions.LDAPGROUPS_READ)
@Path("/groups")
@Produces(MediaType.APPLICATION_JSON)
public Set<String> readGroups() {
final LdapSettings ldapSettings = firstNonNull(ldapSettingsService.load(), ldapSettingsFactory.createEmpty());
if (!ldapSettings.isEnabled()) {
throw new BadRequestException("LDAP is disabled.");
}
if (isNullOrEmpty(ldapSettings.getGroupSearchBase()) || isNullOrEmpty(ldapSettings.getGroupIdAttribute())) {
throw new BadRequestException("LDAP group configuration settings are not set.");
}
final LdapConnectionConfig config = new LdapConnectionConfig();
final URI ldapUri = ldapSettings.getUri();
config.setLdapHost(ldapUri.getHost());
config.setLdapPort(ldapUri.getPort());
config.setUseSsl(ldapUri.getScheme().startsWith("ldaps"));
config.setUseTls(ldapSettings.isUseStartTls());
if (ldapSettings.isTrustAllCertificates()) {
config.setTrustManagers(new TrustAllX509TrustManager());
}
if (!isNullOrEmpty(ldapSettings.getSystemUserName()) && !isNullOrEmpty(ldapSettings.getSystemPassword())) {
config.setName(ldapSettings.getSystemUserName());
config.setCredentials(ldapSettings.getSystemPassword());
}
try (LdapNetworkConnection connection = ldapConnector.connect(config)) {
return ldapConnector.listGroups(connection, ldapSettings.getGroupSearchBase(), ldapSettings.getGroupSearchPattern(), ldapSettings.getGroupIdAttribute());
} catch (IOException | LdapException e) {
LOG.error("Unable to retrieve available LDAP groups", e);
throw new InternalServerErrorException("Unable to retrieve available LDAP groups", e);
}
}
use of javax.ws.rs.InternalServerErrorException in project graylog2-server by Graylog2.
the class ClusterConfigResource method schema.
@GET
@Path("{configClass}")
@Produces(MoreMediaTypes.APPLICATION_SCHEMA_JSON)
@ApiOperation(value = "Get JSON schema of configuration class")
@Timed
@RequiresPermissions(RestPermissions.CLUSTER_CONFIG_ENTRY_READ)
public JsonSchema schema(@ApiParam(name = "configClass", value = "The name of the cluster configuration class", required = true) @PathParam("configClass") @NotBlank String configClass) {
final Class<?> cls = classFromName(configClass);
if (cls == null) {
throw new NotFoundException("Couldn't find configuration class \"" + configClass + "\"");
}
final SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
try {
objectMapper.acceptJsonFormatVisitor(objectMapper.constructType(cls), visitor);
} catch (JsonMappingException e) {
throw new InternalServerErrorException("Couldn't generate JSON schema for configuration class " + configClass, e);
}
return visitor.finalSchema();
}
use of javax.ws.rs.InternalServerErrorException 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();
}
Aggregations