use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class ContentPackPersistenceService method loadAllLatest.
public Set<ContentPack> loadAllLatest() {
final Set<ContentPack> allContentPacks = loadAll();
final ImmutableMultimap.Builder<ModelId, ContentPack> byIdBuilder = ImmutableMultimap.builder();
for (ContentPack contentPack : allContentPacks) {
byIdBuilder.put(contentPack.id(), contentPack);
}
final ImmutableMultimap<ModelId, ContentPack> contentPacksById = byIdBuilder.build();
final ImmutableSet.Builder<ContentPack> latestContentPacks = ImmutableSet.builderWithExpectedSize(contentPacksById.keySet().size());
for (ModelId id : contentPacksById.keySet()) {
final ImmutableCollection<ContentPack> contentPacks = contentPacksById.get(id);
final ContentPack latestContentPackRevision = Collections.max(contentPacks, Comparator.comparingInt(Revisioned::revision));
latestContentPacks.add(latestContentPackRevision);
}
return latestContentPacks.build();
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class ContentPackInstallationPersistenceService method getInstallationMetadata.
public Map<ModelId, Map<Integer, ContentPackMetadata>> getInstallationMetadata(Set<ModelId> ids) {
final Set<ContentPackInstallation> contentPackInstallations = findByContentPackIds(ids);
Map<ModelId, Map<Integer, ContentPackMetadata>> installationMetaData = new HashMap<>();
for (ContentPackInstallation installation : contentPackInstallations) {
Map<Integer, ContentPackMetadata> metadataMap = installationMetaData.get(installation.contentPackId());
if (metadataMap == null) {
metadataMap = new HashMap<>();
}
ContentPackMetadata metadata = metadataMap.get(installation.contentPackRevision());
int count = 1;
if (metadata != null) {
count = metadata.installationCount() + 1;
}
ContentPackMetadata newMetadata = ContentPackMetadata.create(count);
metadataMap.put(installation.contentPackRevision(), newMetadata);
installationMetaData.put(installation.contentPackId(), metadataMap);
}
return installationMetaData;
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class ContentPackResource method deleteContentPackInstallationById.
@DELETE
@Path("{contentPackId}/installations/{installationId}")
@Timed
@ApiOperation(value = "Uninstall a content pack installation")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Error loading content packs") })
@AuditEvent(type = AuditEventTypes.CONTENT_PACK_UNINSTALL)
@JsonView(ContentPackView.HttpView.class)
public Response deleteContentPackInstallationById(@ApiParam(name = "contentPackId", value = "Content pack ID", required = true) @PathParam("contentPackId") ModelId contentPackId, @ApiParam(name = "installationId", value = "Installation ID", required = true) @PathParam("installationId") String installationId) {
checkPermission(RestPermissions.CONTENT_PACK_UNINSTALL, contentPackId.toString());
final ContentPackInstallation installation = contentPackInstallationPersistenceService.findById(new ObjectId(installationId)).orElseThrow(() -> new NotFoundException("Couldn't find installation " + installationId));
final ContentPack contentPack = contentPackPersistenceService.findByIdAndRevision(installation.contentPackId(), installation.contentPackRevision()).orElseThrow(() -> new NotFoundException("Couldn't find content pack " + installation.contentPackId() + " rev " + installation.contentPackRevision()));
final ContentPackUninstallation removedInstallation = contentPackService.uninstallContentPack(contentPack, installation);
return Response.ok(ImmutableMap.of("content_pack", contentPack, "uninstalled", removedInstallation)).build();
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class ContentPackResource method getContentPackRevisions.
@GET
@Path("{contentPackId}/{revision}")
@Timed
@ApiOperation(value = "Get a revision of a content pack")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Error loading content packs") })
@JsonView(ContentPackView.HttpView.class)
public ContentPackResponse getContentPackRevisions(@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);
ContentPack contentPack = contentPackPersistenceService.findByIdAndRevision(id, revision).orElseThrow(() -> new NotFoundException("Content pack " + id + " with revision " + revision + " not found!"));
Set<ConstraintCheckResult> constraints = contentPackService.checkConstraints(contentPack);
return ContentPackResponse.create(contentPack, constraints);
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class PipelineFacade method resolveForInstallation.
private Graph<Entity> resolveForInstallation(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entity);
final PipelineEntity pipelineEntity = objectMapper.convertValue(entity.data(), PipelineEntity.class);
final String source = pipelineEntity.source().asString(parameters);
final Collection<String> referencedRules = referencedRules(source);
referencedRules.stream().map(ModelId::of).map(modelId -> EntityDescriptor.create(modelId, ModelTypes.PIPELINE_RULE_V1)).map(entities::get).filter(Objects::nonNull).forEach(ruleEntity -> mutableGraph.putEdge(entity, ruleEntity));
pipelineEntity.connectedStreams().stream().map(valueReference -> valueReference.asString(parameters)).map(ModelId::of).map(modelId -> EntityDescriptor.create(modelId, ModelTypes.STREAM_V1)).map(entities::get).filter(Objects::nonNull).forEach(streamEntity -> mutableGraph.putEdge(entity, streamEntity));
return ImmutableGraph.copyOf(mutableGraph);
}
Aggregations