Search in sources :

Example 26 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class EntityConverter method convert.

public ViewEntity convert(DashboardEntity dashboardEntity, Map<String, ValueReference> parameters) {
    this.parameters = parameters;
    this.dashboardEntity = dashboardEntity;
    final String queryId = UUID.randomUUID().toString();
    final Map<DashboardWidgetEntity, List<WidgetEntity>> widgets = convertWidgets();
    final Map<String, WidgetPositionDTO> widgetPositionMap = DashboardEntity.positionMap(parameters, widgets);
    final Titles titles = DashboardEntity.widgetTitles(widgets, parameters);
    final Map<String, Set<String>> widgetMapping = new HashMap<>();
    final Set<SearchTypeEntity> searchTypes = new HashSet<>();
    createSearchTypes(widgets, widgetMapping, searchTypes);
    SearchEntity searchEntity;
    try {
        searchEntity = createSearchEntity(queryId, searchTypes);
    } catch (InvalidRangeParametersException e) {
        throw new IllegalArgumentException("The provided entity does not have a valid TimeRange", e);
    }
    final ViewStateEntity viewStateEntity = ViewStateEntity.builder().widgets(widgets.values().stream().flatMap(Collection::stream).collect(Collectors.toSet())).titles(titles).widgetMapping(widgetMapping).widgetPositions(widgetPositionMap).build();
    final Map<String, ViewStateEntity> viewStateEntityMap = ImmutableMap.of(queryId, viewStateEntity);
    return ViewEntity.builder().search(searchEntity).state(viewStateEntityMap).title(dashboardEntity.title()).properties(Collections.emptySet()).description(dashboardEntity.description()).requires(Collections.emptyMap()).summary(ValueReference.of("Converted Dashboard")).createdAt(DateTime.now(DateTimeZone.UTC)).type(ViewEntity.Type.DASHBOARD).build();
}
Also used : ViewStateEntity(org.graylog2.contentpacks.model.entities.ViewStateEntity) SearchTypeEntity(org.graylog2.contentpacks.model.entities.SearchTypeEntity) HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) HashMap(java.util.HashMap) ElasticsearchQueryString(org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString) Titles(org.graylog.plugins.views.search.views.Titles) SearchEntity(org.graylog2.contentpacks.model.entities.SearchEntity) DashboardWidgetEntity(org.graylog2.contentpacks.model.entities.DashboardWidgetEntity) Collection(java.util.Collection) List(java.util.List) WidgetPositionDTO(org.graylog.plugins.views.search.views.WidgetPositionDTO) HashSet(java.util.HashSet)

Example 27 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class EventDefinitionFacadeTest method resolveForInstallation.

@Test
@MongoDBFixtures("EventDefinitionFacadeTest.json")
public void resolveForInstallation() {
    EntityV1 eventEntityV1 = createTestEntity();
    final NotificationEntity notificationEntity = NotificationEntity.builder().title(ValueReference.of("title")).description(ValueReference.of("description")).config(HttpEventNotificationConfigEntity.builder().url(ValueReference.of("http://url")).build()).build();
    final JsonNode data = objectMapper.convertValue(notificationEntity, JsonNode.class);
    final EntityV1 notificationV1 = EntityV1.builder().data(data).id(ModelId.of("123123")).type(ModelTypes.EVENT_DEFINITION_V1).build();
    final EntityDescriptor entityDescriptor = EntityDescriptor.create("123123", ModelTypes.NOTIFICATION_V1);
    Map<String, ValueReference> parameters = ImmutableMap.of();
    Map<EntityDescriptor, Entity> entities = ImmutableMap.of(entityDescriptor, notificationV1);
    Graph<Entity> graph = facade.resolveForInstallation(eventEntityV1, parameters, entities);
    assertThat(graph).isNotNull();
    Set<Entity> expectedNodes = ImmutableSet.of(eventEntityV1, notificationV1);
    assertThat(graph.nodes()).isEqualTo(expectedNodes);
}
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) JsonNode(com.fasterxml.jackson.databind.JsonNode) NotificationEntity(org.graylog.events.contentpack.entities.NotificationEntity) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 28 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class GrokPatternFacadeTest method resolveMatchingDependecyForInstallation.

@Test
public void resolveMatchingDependecyForInstallation() {
    final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "%{PORTAL}"), JsonNode.class)).build();
    final Entity grokPatternEntityDependency = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("PORTAL", "\\d\\d"), JsonNode.class)).build();
    final EntityDescriptor dependencyDescriptor = grokPatternEntityDependency.toEntityDescriptor();
    final Map<EntityDescriptor, Entity> entityDescriptorEntityMap = new HashMap(1);
    entityDescriptorEntityMap.put(dependencyDescriptor, grokPatternEntityDependency);
    final Map<String, ValueReference> parameters = Collections.emptyMap();
    Graph<Entity> graph = facade.resolveForInstallation(grokPatternEntity, parameters, entityDescriptorEntityMap);
    assertThat(graph.nodes().toArray()).contains(grokPatternEntityDependency);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) HashMap(java.util.HashMap) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) Test(org.junit.Test)

Example 29 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class ContentPackInstallationRequestTest method testSerialisation.

@Test
public void testSerialisation() {
    final ImmutableMap<String, ValueReference> parameters = ImmutableMap.of("param1", ValueReference.of("string"), "param2", ValueReference.of(42), "param3", ValueReference.of(3.14d), "param4", ValueReference.of(true));
    final ContentPackInstallationRequest request = ContentPackInstallationRequest.create(parameters, "comment");
    final JsonNode node = objectMapper.valueToTree(request);
    assertThat(node.path("comment").asText()).isEqualTo("comment");
    assertThat(node.path("parameters").path("param1").path("@type").asText()).isEqualTo("string");
    assertThat(node.path("parameters").path("param1").path("@value").asText()).isEqualTo("string");
    assertThat(node.path("parameters").path("param2").path("@type").asText()).isEqualTo("integer");
    assertThat(node.path("parameters").path("param2").path("@value").asInt()).isEqualTo(42);
    assertThat(node.path("parameters").path("param3").path("@type").asText()).isEqualTo("double");
    assertThat(node.path("parameters").path("param3").path("@value").asDouble()).isEqualTo(3.14d);
    assertThat(node.path("parameters").path("param4").path("@type").asText()).isEqualTo("boolean");
    assertThat(node.path("parameters").path("param4").path("@value").asBoolean()).isEqualTo(true);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) Test(org.junit.Test)

Example 30 with ValueReference

use of org.graylog2.contentpacks.model.entities.references.ValueReference in project graylog2-server by Graylog2.

the class GrokPatternFacadeTest method notResolveNotMatchingDependecyForInstallation.

@Test
public void notResolveNotMatchingDependecyForInstallation() {
    final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "%{DOOM}"), JsonNode.class)).build();
    final Entity grokPatternEntityDependency = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("PORTAL", "\\d\\d"), JsonNode.class)).build();
    final EntityDescriptor dependencyDescriptor = grokPatternEntityDependency.toEntityDescriptor();
    final Map<EntityDescriptor, Entity> entityDescriptorEntityMap = new HashMap(1);
    entityDescriptorEntityMap.put(dependencyDescriptor, grokPatternEntityDependency);
    final Map<String, ValueReference> parameters = Collections.emptyMap();
    Graph<Entity> graph = facade.resolveForInstallation(grokPatternEntity, parameters, entityDescriptorEntityMap);
    assertThat(graph.nodes().toArray()).doesNotContain(grokPatternEntityDependency);
}
Also used : NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) HashMap(java.util.HashMap) ValueReference(org.graylog2.contentpacks.model.entities.references.ValueReference) Test(org.junit.Test)

Aggregations

ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)18 Entity (org.graylog2.contentpacks.model.entities.Entity)16 EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)16 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)16 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 Map (java.util.Map)10 ContentPackException (org.graylog2.contentpacks.exceptions.ContentPackException)10 ModelType (org.graylog2.contentpacks.model.ModelType)10 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)10 Set (java.util.Set)9 ImmutableSet (com.google.common.collect.ImmutableSet)8 Graph (com.google.common.graph.Graph)8 GraphBuilder (com.google.common.graph.GraphBuilder)8 ImmutableGraph (com.google.common.graph.ImmutableGraph)8 MutableGraph (com.google.common.graph.MutableGraph)8 HashMap (java.util.HashMap)8 Optional (java.util.Optional)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)7 Collection (java.util.Collection)7