Search in sources :

Example 31 with ModelId

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;
}
Also used : User(org.graylog2.plugin.database.users.User) ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) ContentPack(org.graylog2.contentpacks.model.ContentPack) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) JsonView(com.fasterxml.jackson.annotation.JsonView) AuditEvent(org.graylog2.audit.jersey.AuditEvent) ApiResponses(io.swagger.annotations.ApiResponses)

Example 32 with ModelId

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);
}
Also used : ContentPackInstallation(org.graylog2.contentpacks.model.ContentPackInstallation) ObjectId(org.bson.types.ObjectId) ContentPack(org.graylog2.contentpacks.model.ContentPack) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) JsonView(com.fasterxml.jackson.annotation.JsonView) ApiResponses(io.swagger.annotations.ApiResponses)

Example 33 with ModelId

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");
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) HttpEventNotificationConfigEntity(org.graylog.events.contentpack.entities.HttpEventNotificationConfigEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) EmailEventNotificationConfigEntity(org.graylog.events.contentpack.entities.EmailEventNotificationConfigEntity) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) ModelId(org.graylog2.contentpacks.model.ModelId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 34 with ModelId

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();
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) EventNotificationHandlerConfigEntity(org.graylog.events.contentpack.entities.EventNotificationHandlerConfigEntity) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) HttpEventNotificationConfigEntity(org.graylog.events.contentpack.entities.HttpEventNotificationConfigEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) AggregationEventProcessorConfigEntity(org.graylog.events.contentpack.entities.AggregationEventProcessorConfigEntity) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity) ModelId(org.graylog2.contentpacks.model.ModelId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 35 with ModelId

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();
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) EventNotificationHandlerConfigEntity(org.graylog.events.contentpack.entities.EventNotificationHandlerConfigEntity) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) HttpEventNotificationConfigEntity(org.graylog.events.contentpack.entities.HttpEventNotificationConfigEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) AggregationEventProcessorConfigEntity(org.graylog.events.contentpack.entities.AggregationEventProcessorConfigEntity) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) EventDefinitionEntity(org.graylog.events.contentpack.entities.EventDefinitionEntity) ModelId(org.graylog2.contentpacks.model.ModelId) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

ModelId (org.graylog2.contentpacks.model.ModelId)31 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)16 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)16 Entity (org.graylog2.contentpacks.model.entities.Entity)11 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)11 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)11 Map (java.util.Map)10 Set (java.util.Set)10 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)10 Test (org.junit.Test)10 Optional (java.util.Optional)9 ContentPack (org.graylog2.contentpacks.model.ContentPack)9 Collectors (java.util.stream.Collectors)8 Inject (javax.inject.Inject)8 ContentPackInstallation (org.graylog2.contentpacks.model.ContentPackInstallation)8 NotFoundException (org.graylog2.database.NotFoundException)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 Graph (com.google.common.graph.Graph)7 GraphBuilder (com.google.common.graph.GraphBuilder)7