use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class InputFacade method exportEntity.
@Override
public Optional<Entity> exportEntity(EntityDescriptor entityDescriptor, EntityDescriptorIds entityDescriptorIds) {
final ModelId modelId = entityDescriptor.id();
try {
final Input input = inputService.find(modelId.id());
final InputWithExtractors inputWithExtractors = InputWithExtractors.create(input, inputService.getExtractors(input));
return Optional.of(exportNativeEntity(inputWithExtractors, entityDescriptorIds));
} catch (NotFoundException e) {
return Optional.empty();
}
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class GrokPatternFacade method resolveNativeEntity.
@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entityDescriptor);
final ModelId modelId = entityDescriptor.id();
try {
final GrokPattern grokPattern = grokPatternService.load(modelId.id());
final String namedPattern = grokPattern.pattern();
final Set<String> patterns = GrokPatternService.extractPatternNames(namedPattern);
patterns.stream().forEach(patternName -> {
grokPatternService.loadByName(patternName).ifPresent(depPattern -> {
final EntityDescriptor depEntityDescriptor = EntityDescriptor.create(depPattern.id(), ModelTypes.GROK_PATTERN_V1);
mutableGraph.putEdge(entityDescriptor, depEntityDescriptor);
});
});
} catch (NotFoundException e) {
LOG.debug("Couldn't find grok pattern {}", entityDescriptor, e);
}
return mutableGraph;
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class ContentPackInstallationPersistenceService method findByContentPackIds.
public Set<ContentPackInstallation> findByContentPackIds(Set<ModelId> ids) {
final Set<String> stringIds = ids.stream().map(x -> x.toString()).collect(Collectors.toSet());
final DBObject query = BasicDBObjectBuilder.start().push(ContentPackInstallation.FIELD_CONTENT_PACK_ID).append("$in", stringIds).get();
final DBCursor<ContentPackInstallation> result = dbCollection.find(query);
return ImmutableSet.copyOf((Iterable<ContentPackInstallation>) result);
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class StreamFacade method resolveNativeEntity.
@Override
public Graph<EntityDescriptor> resolveNativeEntity(EntityDescriptor entityDescriptor) {
final MutableGraph<EntityDescriptor> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entityDescriptor);
final ModelId modelId = entityDescriptor.id();
try {
final Stream stream = streamService.load(modelId.id());
stream.getOutputs().stream().map(Output::getId).map(ModelId::of).map(id -> EntityDescriptor.create(id, ModelTypes.OUTPUT_V1)).forEach(output -> mutableGraph.putEdge(entityDescriptor, output));
} catch (NotFoundException e) {
LOG.debug("Couldn't find stream {}", entityDescriptor, e);
}
return ImmutableGraph.copyOf(mutableGraph);
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class ContentPackResource method downloadContentPackRevisions.
@GET
@Path("{contentPackId}/{revision}/download")
@Timed
@ApiOperation(value = "Download a revision of a content pack")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Error loading content packs") })
@JsonView(ContentPackView.HttpView.class)
public ContentPack downloadContentPackRevisions(@ApiParam(name = "contentPackId", value = "Content pack ID", required = true) @PathParam("contentPackId") ModelId id, @ApiParam(name = "revision", value = "Content pack revision", required = true) @PathParam("revision") int revision) {
checkPermission(RestPermissions.CONTENT_PACK_READ, id.toString());
ContentPack contentPack = contentPackPersistenceService.findByIdAndRevision(id, revision).orElseThrow(() -> new NotFoundException("Content pack " + id + " with revision " + revision + " not found!"));
return contentPack;
}
Aggregations