use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class IndexSetsResource method delete.
@DELETE
@Path("{id}")
@Timed
@ApiOperation(value = "Delete index set")
@AuditEvent(type = AuditEventTypes.INDEX_SET_DELETE)
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 404, message = "Index set not found") })
public void delete(@ApiParam(name = "id", required = true) @PathParam("id") String id, @ApiParam(name = "delete_indices") @QueryParam("delete_indices") @DefaultValue("true") boolean deleteIndices) {
checkPermission(RestPermissions.INDEXSETS_DELETE, id);
final IndexSet indexSet = getIndexSet(indexSetRegistry, id);
final IndexSet defaultIndexSet = indexSetRegistry.getDefault();
if (indexSet.equals(defaultIndexSet)) {
throw new BadRequestException("Default index set <" + indexSet.getConfig().id() + "> cannot be deleted!");
}
if (indexSetService.delete(id) == 0) {
throw new NotFoundException("Couldn't delete index set with ID <" + id + ">");
} else {
if (deleteIndices) {
try {
systemJobManager.submit(indexSetCleanupJobFactory.create(indexSet));
} catch (SystemJobConcurrencyException e) {
LOG.error("Error running system job", e);
}
}
}
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class IndicesResource method single.
@GET
@Timed
@Path("/{index}")
@ApiOperation(value = "Get information of an index and its shards.")
@Produces(MediaType.APPLICATION_JSON)
public IndexInfo single(@ApiParam(name = "index") @PathParam("index") String index) {
checkPermission(RestPermissions.INDICES_READ, index);
if (!indexSetRegistry.isManagedIndex(index)) {
final String msg = "Index [" + index + "] doesn't look like an index managed by Graylog.";
LOG.info(msg);
throw new NotFoundException(msg);
}
final IndexStatistics stats = indices.getIndexStats(index);
if (stats == null) {
final String msg = "Index [" + index + "] not found.";
LOG.error(msg);
throw new NotFoundException(msg);
}
final ImmutableList.Builder<ShardRouting> routing = ImmutableList.builder();
for (org.elasticsearch.cluster.routing.ShardRouting shardRouting : stats.shardRoutings()) {
routing.add(shardRouting(shardRouting));
}
return IndexInfo.create(indexStats(stats.primaries()), indexStats(stats.total()), routing.build(), indices.isReopened(index));
}
use of org.graylog2.database.NotFoundException 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 org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class ExtractorsResource method list.
@GET
@Timed
@ApiOperation(value = "List all extractors of an input")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node.") })
@Produces(MediaType.APPLICATION_JSON)
public ExtractorSummaryList list(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId) throws NotFoundException {
checkPermission(RestPermissions.INPUTS_READ, inputId);
final Input input = inputService.find(inputId);
final List<ExtractorSummary> extractors = Lists.newArrayList();
for (Extractor extractor : inputService.getExtractors(input)) {
extractors.add(toSummary(extractor));
}
return ExtractorSummaryList.create(extractors);
}
use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.
the class ExtractorsResource method update.
@PUT
@Timed
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update an extractor")
@Path("/{extractorId}")
@ApiResponses(value = { @ApiResponse(code = 404, message = "No such input on this node."), @ApiResponse(code = 404, message = "No such extractor on this input."), @ApiResponse(code = 400, message = "No such extractor type."), @ApiResponse(code = 400, message = "Field the extractor should write on is reserved."), @ApiResponse(code = 400, message = "Missing or invalid configuration.") })
@AuditEvent(type = AuditEventTypes.EXTRACTOR_UPDATE)
public ExtractorSummary update(@ApiParam(name = "inputId", required = true) @PathParam("inputId") String inputId, @ApiParam(name = "extractorId", required = true) @PathParam("extractorId") String extractorId, @ApiParam(name = "JSON body", required = true) @Valid @NotNull CreateExtractorRequest cer) throws NotFoundException {
checkPermission(RestPermissions.INPUTS_EDIT, inputId);
final Input mongoInput = inputService.find(inputId);
final Extractor originalExtractor = inputService.getExtractor(mongoInput, extractorId);
final Extractor extractor = buildExtractorFromRequest(cer, originalExtractor.getId());
inputService.removeExtractor(mongoInput, originalExtractor.getId());
try {
inputService.addExtractor(mongoInput, extractor);
} catch (ValidationException e) {
LOG.error("Extractor persist validation failed.", e);
throw new BadRequestException(e);
}
final String msg = "Updated extractor <" + originalExtractor.getId() + "> of type [" + cer.extractorType() + "] in input <" + inputId + ">.";
LOG.info(msg);
activityWriter.write(new Activity(msg, ExtractorsResource.class));
return toSummary(extractor);
}
Aggregations