use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class ContentPackResource method installContentPack.
@POST
@Path("{contentPackId}/{revision}/installations")
@Timed
@ApiOperation(value = "Install a revision of a content pack")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Error loading content packs") })
@AuditEvent(type = AuditEventTypes.CONTENT_PACK_INSTALL)
@JsonView(ContentPackView.HttpView.class)
public ContentPackInstallation installContentPack(@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, @ApiParam(name = "installation request", value = "Content pack installation request", required = true) @Valid @NotNull ContentPackInstallationRequest contentPackInstallationRequest) {
checkPermission(RestPermissions.CONTENT_PACK_INSTALL, id.toString());
final ContentPack contentPack = contentPackPersistenceService.findByIdAndRevision(id, revision).orElseThrow(() -> new NotFoundException("Content pack " + id + " with revision " + revision + " not found!"));
final User currentUser = getCurrentUser();
final String userName = currentUser == null ? "unknown" : currentUser.getName();
final ContentPackInstallation installation = contentPackService.installContentPack(contentPack, contentPackInstallationRequest.parameters(), contentPackInstallationRequest.comment(), userName);
return installation;
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class ContentPackResource method uninstallDetails.
@GET
@Path("{contentPackId}/installations/{installationId}/uninstall_details")
@Timed
@ApiOperation(value = "Get details about which entities will actually be uninstalled")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Error loading content packs") })
@JsonView(ContentPackView.HttpView.class)
public ContentPackUninstallDetails uninstallDetails(@ApiParam(name = "contentPackId", value = "Content pack ID", required = true) @PathParam("contentPackId") ModelId id, @ApiParam(name = "installationId", value = "Installation ID", required = true) @PathParam("installationId") String installationId) {
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()));
return contentPackService.getUninstallDetails(contentPack, installation);
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class NotificationFacadeTest method exportEntity.
@Test
@MongoDBFixtures("NotificationFacadeTest.json")
public void exportEntity() {
final ModelId id = ModelId.of("5d4d33753d27460ad18e0c4d");
final EntityDescriptor descriptor = EntityDescriptor.create(id, ModelTypes.NOTIFICATION_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Optional<Entity> entity = facade.exportEntity(descriptor, entityDescriptorIds);
assertThat(entity).isPresent();
final EntityV1 entityV1 = (EntityV1) entity.get();
final NotificationEntity notificationEntity = objectMapper.convertValue(entityV1.data(), NotificationEntity.class);
assertThat(notificationEntity.title().asString()).isEqualTo("title");
assertThat(notificationEntity.description().asString()).isEqualTo("description");
assertThat(notificationEntity.config().type()).isEqualTo("email-notification-v1");
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class EventDefinitionFacadeTest method exportEntity.
@Test
@MongoDBFixtures("EventDefinitionFacadeTest.json")
public void exportEntity() {
final ModelId id = ModelId.of("5d4032513d2746703d1467f6");
when(jobDefinitionService.getByConfigField(eq("event_definition_id"), eq(id.id()))).thenReturn(Optional.of(mock(JobDefinitionDto.class)));
final EntityDescriptor descriptor = EntityDescriptor.create(id, ModelTypes.EVENT_DEFINITION_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Optional<Entity> entity = facade.exportEntity(descriptor, entityDescriptorIds);
assertThat(entity).isPresent();
final EntityV1 entityV1 = (EntityV1) entity.get();
final EventDefinitionEntity eventDefinitionEntity = objectMapper.convertValue(entityV1.data(), EventDefinitionEntity.class);
assertThat(eventDefinitionEntity.title().asString()).isEqualTo("title");
assertThat(eventDefinitionEntity.description().asString()).isEqualTo("description");
assertThat(eventDefinitionEntity.config().type()).isEqualTo(AggregationEventProcessorConfigEntity.TYPE_NAME);
assertThat(eventDefinitionEntity.isScheduled().asBoolean(ImmutableMap.of())).isTrue();
}
use of org.graylog2.contentpacks.model.ModelId in project graylog2-server by Graylog2.
the class EventDefinitionFacadeTest method exportEntityWithoutScheduling.
@Test
@MongoDBFixtures("EventDefinitionFacadeTest.json")
public void exportEntityWithoutScheduling() {
final ModelId id = ModelId.of("5d4032513d2746703d1467f6");
when(jobDefinitionService.getByConfigField(eq("event_definition_id"), eq(id.id()))).thenReturn(Optional.empty());
final EntityDescriptor descriptor = EntityDescriptor.create(id, ModelTypes.EVENT_DEFINITION_V1);
final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
final Optional<Entity> entity = facade.exportEntity(descriptor, entityDescriptorIds);
assertThat(entity).isPresent();
final EntityV1 entityV1 = (EntityV1) entity.get();
final EventDefinitionEntity eventDefinitionEntity = objectMapper.convertValue(entityV1.data(), EventDefinitionEntity.class);
assertThat(eventDefinitionEntity.title().asString()).isEqualTo("title");
assertThat(eventDefinitionEntity.description().asString()).isEqualTo("description");
assertThat(eventDefinitionEntity.config().type()).isEqualTo(AggregationEventProcessorConfigEntity.TYPE_NAME);
assertThat(eventDefinitionEntity.isScheduled().asBoolean(ImmutableMap.of())).isFalse();
}
Aggregations