use of org.graylog2.contentpacks.model.ContentPackInstallation in project graylog2-server by Graylog2.
the class ContentPackService method getUninstallDetails.
private ContentPackUninstallDetails getUninstallDetails(ContentPackV1 contentPack, ContentPackInstallation installation) {
final Entity rootEntity = EntityV1.createRoot(contentPack);
final ImmutableMap<String, ValueReference> parameters = installation.parameters();
final ImmutableGraph<Entity> dependencyGraph = buildEntityGraph(rootEntity, contentPack.entities(), parameters);
final Traverser<Entity> entityTraverser = Traverser.forGraph(dependencyGraph);
final Iterable<Entity> entitiesInOrder = entityTraverser.breadthFirst(rootEntity);
final Set<NativeEntityDescriptor> nativeEntityDescriptors = new HashSet<>();
entitiesInOrder.forEach((entity -> {
if (entity.equals(rootEntity)) {
return;
}
final Optional<NativeEntityDescriptor> nativeEntityDescriptorOptional = installation.entities().stream().filter(descriptor -> entity.id().equals(descriptor.contentPackEntityId())).findFirst();
if (nativeEntityDescriptorOptional.isPresent()) {
NativeEntityDescriptor nativeEntityDescriptor = nativeEntityDescriptorOptional.get();
if (contentPackInstallationPersistenceService.countInstallationOfEntityById(nativeEntityDescriptor.id()) <= 1) {
nativeEntityDescriptors.add(nativeEntityDescriptor);
}
}
}));
return ContentPackUninstallDetails.create(nativeEntityDescriptors);
}
use of org.graylog2.contentpacks.model.ContentPackInstallation 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.ContentPackInstallation 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.ContentPackInstallation in project graylog2-server by Graylog2.
the class V20191219090834_AddSourcesPageTest method upgradeFailsBecauseSourcePageContentPackExists.
@Test
public void upgradeFailsBecauseSourcePageContentPackExists() throws IOException {
final URL contentPackURL = V20191219090834_AddSourcesPage.class.getResource("V20191219090834_AddSourcesPage_Content_Pack.json");
final ContentPack contentPack = ContentPackV1.builder().id(ModelId.of("04fcf179-49e0-4e8f-9c02-0ff13062efbe")).summary("summary").revision(1).name("Sources Page").description("description").vendor("").url(URI.create("http://graylog.com")).entities(ImmutableSet.of()).build();
final ContentPackInstallation contentPackInstallation = ContentPackInstallation.builder().contentPackId(contentPack.id()).contentPackRevision(1).parameters(ImmutableMap.of()).entities(ImmutableSet.of()).comment("Comment").createdAt(Instant.now()).createdBy("admin").build();
when(configService.get(V20191219090834_AddSourcesPage.MigrationCompleted.class)).thenReturn(null);
when(objectMapper.readValue(contentPackURL, ContentPack.class)).thenReturn(contentPack);
when(contentPackPersistenceService.insert(contentPack)).thenReturn(Optional.empty());
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> migration.upgrade()).withMessage("Could not install Source Page Content Pack.");
verify(configService).write(V20191219090834_AddSourcesPage.MigrationCompleted.create("04fcf179-49e0-4e8f-9c02-0ff13062efbe"));
verifyZeroInteractions(contentPackService);
}
use of org.graylog2.contentpacks.model.ContentPackInstallation in project graylog2-server by Graylog2.
the class ContentPackInstallationPersistenceServiceTest method findByIdWithInvalidId.
@Test
@MongoDBFixtures("ContentPackInstallationPersistenceServiceTest.json")
public void findByIdWithInvalidId() {
final Optional<ContentPackInstallation> contentPacks = persistenceService.findById(new ObjectId("0000000000000000deadbeef"));
assertThat(contentPacks).isEmpty();
}
Aggregations