Search in sources :

Example 56 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class GrokResource method removePattern.

@DELETE
@Timed
@Path("/{patternId}")
@ApiOperation("Remove an existing pattern by id")
@AuditEvent(type = AuditEventTypes.GROK_PATTERN_DELETE)
public void removePattern(@ApiParam(name = "patternId", required = true) @PathParam("patternId") String patternId) throws NotFoundException {
    checkPermission(RestPermissions.INPUTS_EDIT);
    final GrokPattern pattern = grokPatternService.load(patternId);
    clusterBus.post(GrokPatternsChangedEvent.create(Sets.newHashSet(pattern.name()), Collections.emptySet()));
    if (grokPatternService.delete(patternId) == 0) {
        throw new javax.ws.rs.NotFoundException("Couldn't remove Grok pattern with ID " + patternId);
    }
}
Also used : GrokPattern(org.graylog2.grok.GrokPattern) NotFoundException(org.graylog2.database.NotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) AuditEvent(org.graylog2.audit.jersey.AuditEvent)

Example 57 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class BundleImporter method deleteCreatedInputs.

private void deleteCreatedInputs() throws NotFoundException {
    for (Map.Entry<String, MessageInput> entry : createdInputs.entrySet()) {
        final String inputId = entry.getKey();
        final MessageInput messageInput = entry.getValue();
        LOG.debug("Terminating message input {}", inputId);
        inputRegistry.remove(messageInput);
        final org.graylog2.inputs.Input input = inputService.find(messageInput.getId());
        inputService.destroy(input);
    }
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 58 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class BundleImporter method createInputs.

private void createInputs(final String bundleId, final Set<Input> inputs, final String userName) throws org.graylog2.plugin.inputs.Extractor.ReservedFieldException, org.graylog2.ConfigurationException, NoSuchInputTypeException, ValidationException, ExtractorFactory.NoSuchExtractorException, NotFoundException, ConfigurationException {
    for (final Input input : inputs) {
        final MessageInput messageInput = createMessageInput(bundleId, input, userName);
        createdInputs.put(messageInput.getId(), messageInput);
        // Launch input. (this will run async and clean up itself in case of an error.)
        inputLauncher.launch(messageInput);
    }
}
Also used : MessageInput(org.graylog2.plugin.inputs.MessageInput) MessageInput(org.graylog2.plugin.inputs.MessageInput)

Example 59 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class BundleImporter method createMessageInput.

private MessageInput createMessageInput(final String bundleId, final Input inputDescription, final String userName) throws NoSuchInputTypeException, ConfigurationException, ValidationException, NotFoundException, org.graylog2.ConfigurationException, ExtractorFactory.NoSuchExtractorException, org.graylog2.plugin.inputs.Extractor.ReservedFieldException {
    final Configuration inputConfig = new Configuration(inputDescription.getConfiguration());
    final DateTime createdAt = Tools.nowUTC();
    final MessageInput messageInput = messageInputFactory.create(inputDescription.getType(), inputConfig);
    messageInput.setTitle(inputDescription.getTitle());
    messageInput.setGlobal(inputDescription.isGlobal());
    messageInput.setCreatorUserId(userName);
    messageInput.setCreatedAt(createdAt);
    messageInput.setContentPack(bundleId);
    messageInput.checkConfiguration();
    // Don't run if exclusive and another instance is already running.
    if (messageInput.isExclusive() && inputRegistry.hasTypeRunning(messageInput.getClass())) {
        LOG.error("Input type <{}> of input <{}> is exclusive and already has input running.", messageInput.getClass(), messageInput.getTitle());
    }
    final String id = inputDescription.getId();
    final org.graylog2.inputs.Input mongoInput;
    if (id == null) {
        mongoInput = inputService.create(buildMongoDbInput(inputDescription, userName, createdAt, bundleId));
    } else {
        mongoInput = inputService.create(id, buildMongoDbInput(inputDescription, userName, createdAt, bundleId));
    }
    // Persist input.
    final String persistId = inputService.save(mongoInput);
    messageInput.setPersistId(persistId);
    messageInput.initialize();
    addStaticFields(messageInput, inputDescription.getStaticFields());
    addExtractors(messageInput, inputDescription.getExtractors(), userName);
    return messageInput;
}
Also used : Configuration(org.graylog2.plugin.configuration.Configuration) MessageInput(org.graylog2.plugin.inputs.MessageInput) DateTime(org.joda.time.DateTime)

Example 60 with NotFoundException

use of org.graylog2.database.NotFoundException in project graylog2-server by Graylog2.

the class RebuildIndexRangesJob method execute.

@Override
public void execute() {
    info("Recalculating index ranges.");
    // for each index set we know about
    final ListMultimap<IndexSet, String> indexSets = MultimapBuilder.hashKeys().arrayListValues().build();
    for (IndexSet indexSet : this.indexSets) {
        final String[] managedIndicesNames = indexSet.getManagedIndices();
        for (String name : managedIndicesNames) {
            indexSets.put(indexSet, name);
        }
    }
    if (indexSets.size() == 0) {
        info("No indices, nothing to calculate.");
        return;
    }
    indicesToCalculate = indexSets.values().size();
    Stopwatch sw = Stopwatch.createStarted();
    for (IndexSet indexSet : indexSets.keySet()) {
        LOG.info("Recalculating index ranges for index set {} ({}): {} indices affected.", indexSet.getConfig().title(), indexSet.getIndexWildcard(), indexSets.get(indexSet).size());
        for (String index : indexSets.get(indexSet)) {
            try {
                if (index.equals(indexSet.getActiveWriteIndex())) {
                    LOG.debug("{} is current write target, do not calculate index range for it", index);
                    final IndexRange emptyRange = indexRangeService.createUnknownRange(index);
                    try {
                        final IndexRange indexRange = indexRangeService.get(index);
                        if (indexRange.begin().getMillis() != 0 || indexRange.end().getMillis() != 0) {
                            LOG.info("Invalid date ranges for write index {}, resetting it.", index);
                            indexRangeService.save(emptyRange);
                        }
                    } catch (NotFoundException e) {
                        LOG.info("No index range found for write index {}, recreating it.", index);
                        indexRangeService.save(emptyRange);
                    }
                    indicesCalculated.incrementAndGet();
                    continue;
                }
            } catch (TooManyAliasesException e) {
                LOG.error("Multiple write alias targets found, this is a bug.");
                indicesCalculated.incrementAndGet();
                continue;
            }
            if (cancelRequested) {
                info("Stop requested. Not calculating next index range, not updating ranges.");
                sw.stop();
                return;
            }
            try {
                final IndexRange indexRange = indexRangeService.calculateRange(index);
                indexRangeService.save(indexRange);
                LOG.info("Created ranges for index {}: {}", index, indexRange);
            } catch (Exception e) {
                LOG.info("Could not calculate range of index [" + index + "]. Skipping.", e);
            } finally {
                indicesCalculated.incrementAndGet();
            }
        }
    }
    info("Done calculating index ranges for " + indicesToCalculate + " indices. Took " + sw.stop().elapsed(TimeUnit.MILLISECONDS) + "ms.");
}
Also used : Stopwatch(com.google.common.base.Stopwatch) NotFoundException(org.graylog2.database.NotFoundException) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) IndexSet(org.graylog2.indexer.IndexSet) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) NotFoundException(org.graylog2.database.NotFoundException)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)91 Timed (com.codahale.metrics.annotation.Timed)77 Path (javax.ws.rs.Path)75 ApiResponses (io.swagger.annotations.ApiResponses)66 AuditEvent (org.graylog2.audit.jersey.AuditEvent)60 Produces (javax.ws.rs.Produces)44 NotFoundException (org.graylog2.database.NotFoundException)32 GET (javax.ws.rs.GET)30 PUT (javax.ws.rs.PUT)28 BadRequestException (javax.ws.rs.BadRequestException)27 Stream (org.graylog2.plugin.streams.Stream)27 NotFoundException (javax.ws.rs.NotFoundException)26 Consumes (javax.ws.rs.Consumes)21 DELETE (javax.ws.rs.DELETE)21 POST (javax.ws.rs.POST)19 RequiresPermissions (org.apache.shiro.authz.annotation.RequiresPermissions)15 MessageInput (org.graylog2.plugin.inputs.MessageInput)15 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)11 Input (org.graylog2.inputs.Input)11 ValidationException (org.graylog2.plugin.database.ValidationException)11