Search in sources :

Example 56 with EntityDescriptor

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

the class ContentPackServiceTest method resolveEntitiesWithTransitiveDependencies.

@Test
public void resolveEntitiesWithTransitiveDependencies() throws NotFoundException {
    final StreamMock streamMock = new StreamMock(ImmutableMap.of("_id", "stream-1234", StreamImpl.FIELD_TITLE, "Stream Title")) {

        @Override
        public Set<Output> getOutputs() {
            return Collections.singleton(OutputImpl.create("output-1234", "Output Title", "org.example.outputs.SomeOutput", "admin", Collections.emptyMap(), new Date(0L), null));
        }
    };
    when(streamService.load("stream-1234")).thenReturn(streamMock);
    final ImmutableSet<EntityDescriptor> unresolvedEntities = ImmutableSet.of(EntityDescriptor.create("stream-1234", ModelTypes.STREAM_V1));
    final Set<EntityDescriptor> resolvedEntities = contentPackService.resolveEntities(unresolvedEntities);
    assertThat(resolvedEntities).containsOnly(EntityDescriptor.create("stream-1234", ModelTypes.STREAM_V1), EntityDescriptor.create("output-1234", ModelTypes.OUTPUT_V1));
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) StreamMock(org.graylog2.streams.StreamMock) MessageOutput(org.graylog2.plugin.outputs.MessageOutput) Output(org.graylog2.plugin.streams.Output) Date(java.util.Date) Test(org.junit.Test)

Example 57 with EntityDescriptor

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

the class ContentPackServiceTest method resolveEntitiesWithNoDependencies.

@Test
public void resolveEntitiesWithNoDependencies() throws NotFoundException {
    final StreamMock streamMock = new StreamMock(ImmutableMap.of("_id", "stream-1234", StreamImpl.FIELD_TITLE, "Stream Title"));
    when(streamService.load("stream-1234")).thenReturn(streamMock);
    final ImmutableSet<EntityDescriptor> unresolvedEntities = ImmutableSet.of(EntityDescriptor.create("stream-1234", ModelTypes.STREAM_V1));
    final Set<EntityDescriptor> resolvedEntities = contentPackService.resolveEntities(unresolvedEntities);
    assertThat(resolvedEntities).containsOnly(EntityDescriptor.create("stream-1234", ModelTypes.STREAM_V1));
}
Also used : EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntityDescriptor(org.graylog2.contentpacks.model.entities.NativeEntityDescriptor) StreamMock(org.graylog2.streams.StreamMock) Test(org.junit.Test)

Example 58 with EntityDescriptor

use of org.graylog2.contentpacks.model.entities.EntityDescriptor 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 59 with EntityDescriptor

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

the class DashboardV1FacadeTest method setUp.

@Before
public void setUp() throws IOException {
    objectMapper.registerSubtypes(new NamedType(AggregationConfigDTO.class, AggregationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(MessageListConfigDTO.class, MessageListConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(LineVisualizationConfigDTO.class, LineVisualizationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(BarVisualizationConfigDTO.class, BarVisualizationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(NumberVisualizationConfigDTO.class, NumberVisualizationConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(TimeHistogramConfigDTO.class, TimeHistogramConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(ValueConfigDTO.class, ValueConfigDTO.NAME));
    objectMapper.registerSubtypes(new NamedType(PivotSortConfig.class, PivotSortConfig.Type));
    objectMapper.registerSubtypes(new NamedType(PivotEntity.class, PivotEntity.NAME));
    objectMapper.registerSubtypes(new NamedType(PivotSort.class, PivotSort.Type));
    objectMapper.registerSubtypes(new NamedType(OrFilter.class, OrFilter.NAME));
    objectMapper.registerSubtypes(new NamedType(StreamFilter.class, StreamFilter.NAME));
    objectMapper.registerSubtypes(new NamedType(QueryStringFilter.class, QueryStringFilter.NAME));
    objectMapper.registerSubtypes(new NamedType(AutoIntervalDTO.class, AutoIntervalDTO.type));
    final MongoConnection mongoConnection = mongodb.mongoConnection();
    final MongoJackObjectMapperProvider mapper = new MongoJackObjectMapperProvider(objectMapper);
    searchDbService = new ViewFacadeTest.TestSearchDBService(mongoConnection, mapper);
    viewService = new ViewFacadeTest.TestViewService(mongoConnection, mapper, null);
    viewSummaryService = new ViewFacadeTest.TestViewSummaryService(mongoConnection, mapper);
    userService = mock(UserService.class);
    final UserImpl fakeUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "testuser"));
    when(userService.load("testuser")).thenReturn(fakeUser);
    final DashboardWidgetConverter dashboardWidgetConverter = new DashboardWidgetConverter();
    final EntityConverter entityConverter = new EntityConverter(dashboardWidgetConverter);
    facade = new DashboardV1Facade(objectMapper, searchDbService, entityConverter, viewService, viewSummaryService, userService);
    final URL resourceUrl = Resources.getResource(DashboardV1Facade.class, "content-pack-dashboard-v1.json");
    final ContentPack contentPack = objectMapper.readValue(resourceUrl, ContentPack.class);
    assertThat(contentPack).isInstanceOf(ContentPackV1.class);
    final ContentPackV1 contentPackV1 = (ContentPackV1) contentPack;
    final Entity entity = contentPackV1.entities().iterator().next();
    final StreamImpl stream = new StreamImpl(Collections.emptyMap());
    final Map<EntityDescriptor, Object> nativeEntities = new HashMap<>(1);
    nativeEntities.put(EntityDescriptor.create("58b3d55a-51ad-4b3e-865c-85776016a151", ModelTypes.STREAM_V1), stream);
    final NativeEntity<ViewDTO> nativeEntity = facade.createNativeEntity(entity, ImmutableMap.of(), nativeEntities, "testuser");
    assertThat(nativeEntity).isNotNull();
    viewDTO = nativeEntity.entity();
}
Also used : NumberVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.NumberVisualizationConfigDTO) EntityConverter(org.graylog2.contentpacks.facades.dashboardV1.EntityConverter) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) PivotEntity(org.graylog2.contentpacks.model.entities.PivotEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) HashMap(java.util.HashMap) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) TimeHistogramConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.TimeHistogramConfigDTO) AutoIntervalDTO(org.graylog.plugins.views.search.views.widgets.aggregation.AutoIntervalDTO) PivotSortConfig(org.graylog.plugins.views.search.views.widgets.aggregation.sort.PivotSortConfig) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) QueryStringFilter(org.graylog.plugins.views.search.filter.QueryStringFilter) DashboardV1Facade(org.graylog2.contentpacks.facades.dashboardV1.DashboardV1Facade) URL(java.net.URL) AggregationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.AggregationConfigDTO) ViewDTO(org.graylog.plugins.views.search.views.ViewDTO) PasswordAlgorithmFactory(org.graylog2.security.PasswordAlgorithmFactory) MessageListConfigDTO(org.graylog.plugins.views.search.views.widgets.messagelist.MessageListConfigDTO) ContentPackV1(org.graylog2.contentpacks.model.ContentPackV1) UserImpl(org.graylog2.users.UserImpl) Permissions(org.graylog2.shared.security.Permissions) DashboardWidgetConverter(org.graylog2.contentpacks.facades.dashboardV1.DashboardWidgetConverter) BarVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.BarVisualizationConfigDTO) UserService(org.graylog2.shared.users.UserService) MongoJackObjectMapperProvider(org.graylog2.bindings.providers.MongoJackObjectMapperProvider) ContentPack(org.graylog2.contentpacks.model.ContentPack) OrFilter(org.graylog.plugins.views.search.filter.OrFilter) LineVisualizationConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.LineVisualizationConfigDTO) PivotSort(org.graylog.plugins.views.search.searchtypes.pivot.PivotSort) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) StreamImpl(org.graylog2.streams.StreamImpl) ValueConfigDTO(org.graylog.plugins.views.search.views.widgets.aggregation.ValueConfigDTO) MongoConnection(org.graylog2.database.MongoConnection) PivotEntity(org.graylog2.contentpacks.model.entities.PivotEntity) Before(org.junit.Before)

Example 60 with EntityDescriptor

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

the class InputFacadeTest method collectEntity.

@Test
@MongoDBFixtures("InputFacadeTest.json")
public void collectEntity() {
    final EntityDescriptor descriptor = EntityDescriptor.create("5adf25294b900a0fdb4e5365", ModelTypes.INPUT_V1);
    final EntityDescriptorIds entityDescriptorIds = EntityDescriptorIds.of(descriptor);
    final Optional<Entity> collectedEntity = facade.exportEntity(descriptor, entityDescriptorIds);
    assertThat(collectedEntity).isPresent().containsInstanceOf(EntityV1.class);
    final EntityV1 entity = (EntityV1) collectedEntity.get();
    assertThat(entity.id()).isEqualTo(ModelId.of(entityDescriptorIds.get(descriptor).orElse(null)));
    assertThat(entity.type()).isEqualTo(ModelTypes.INPUT_V1);
    final InputEntity inputEntity = objectMapper.convertValue(entity.data(), InputEntity.class);
    assertThat(inputEntity.title()).isEqualTo(ValueReference.of("Global Random HTTP"));
    assertThat(inputEntity.type()).isEqualTo(ValueReference.of("org.graylog2.inputs.random.FakeHttpMessageInput"));
    assertThat(inputEntity.global()).isEqualTo(ValueReference.of(true));
    assertThat(inputEntity.staticFields()).containsEntry("custom_field", ValueReference.of("foobar"));
    assertThat(inputEntity.configuration()).isNotEmpty();
    assertThat(inputEntity.extractors()).hasSize(5);
}
Also used : EntityV1(org.graylog2.contentpacks.model.entities.EntityV1) EntityDescriptor(org.graylog2.contentpacks.model.entities.EntityDescriptor) NativeEntity(org.graylog2.contentpacks.model.entities.NativeEntity) ConverterEntity(org.graylog2.contentpacks.model.entities.ConverterEntity) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) Entity(org.graylog2.contentpacks.model.entities.Entity) ExtractorEntity(org.graylog2.contentpacks.model.entities.ExtractorEntity) LookupTableEntity(org.graylog2.contentpacks.model.entities.LookupTableEntity) GrokPatternEntity(org.graylog2.contentpacks.model.entities.GrokPatternEntity) EntityDescriptorIds(org.graylog2.contentpacks.EntityDescriptorIds) InputEntity(org.graylog2.contentpacks.model.entities.InputEntity) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

EntityDescriptor (org.graylog2.contentpacks.model.entities.EntityDescriptor)92 Test (org.junit.Test)63 Entity (org.graylog2.contentpacks.model.entities.Entity)62 NativeEntity (org.graylog2.contentpacks.model.entities.NativeEntity)59 EntityV1 (org.graylog2.contentpacks.model.entities.EntityV1)48 EntityDescriptorIds (org.graylog2.contentpacks.EntityDescriptorIds)44 NativeEntityDescriptor (org.graylog2.contentpacks.model.entities.NativeEntityDescriptor)44 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)42 ModelId (org.graylog2.contentpacks.model.ModelId)26 ValueReference (org.graylog2.contentpacks.model.entities.references.ValueReference)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 LookupTableEntity (org.graylog2.contentpacks.model.entities.LookupTableEntity)15 Map (java.util.Map)14 Graph (com.google.common.graph.Graph)13 GrokPatternEntity (org.graylog2.contentpacks.model.entities.GrokPatternEntity)13 Optional (java.util.Optional)12 Set (java.util.Set)12 Collectors (java.util.stream.Collectors)12 EntityExcerpt (org.graylog2.contentpacks.model.entities.EntityExcerpt)12 NotFoundException (org.graylog2.database.NotFoundException)12