use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class StreamFacade method resolveForInstallation.
private Graph<Entity> resolveForInstallation(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
final MutableGraph<Entity> mutableGraph = GraphBuilder.directed().build();
mutableGraph.addNode(entity);
final StreamEntity streamEntity = objectMapper.convertValue(entity.data(), StreamEntity.class);
streamEntity.outputs().stream().map(valueReference -> valueReference.asString(parameters)).map(ModelId::of).map(modelId -> EntityDescriptor.create(modelId, ModelTypes.OUTPUT_V1)).map(entities::get).filter(Objects::nonNull).forEach(outputEntity -> mutableGraph.putEdge(entity, outputEntity));
return ImmutableGraph.copyOf(mutableGraph);
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class DashboardV1Facade method resolveEntityV1.
@SuppressWarnings("UnstableApiUsage")
private Graph<Entity> resolveEntityV1(EntityV1 entity, Map<String, ValueReference> parameters, Map<EntityDescriptor, Entity> entities) {
final DashboardEntity dashboardEntity = objectMapper.convertValue(entity.data(), DashboardEntity.class);
final ViewEntity viewEntity = entityConverter.convert(dashboardEntity, parameters);
return resolveViewEntity(entity, viewEntity, entities);
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class EventDefinitionFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() {
final EntityV1 entityV1 = createTestEntity();
final NotificationDto notificationDto = NotificationDto.builder().config(HTTPEventNotificationConfig.builder().url("https://hulud.net").build()).title("Notify me Senpai").description("A notification for senpai").id("dead-beef").build();
final EntityDescriptor entityDescriptor = EntityDescriptor.create("123123", ModelTypes.NOTIFICATION_V1);
final ImmutableMap<EntityDescriptor, Object> nativeEntities = ImmutableMap.of(entityDescriptor, notificationDto);
final JobDefinitionDto jobDefinitionDto = mock(JobDefinitionDto.class);
final JobTriggerDto jobTriggerDto = mock(JobTriggerDto.class);
when(jobDefinitionDto.id()).thenReturn("job-123123");
when(jobSchedulerClock.nowUTC()).thenReturn(DateTime.now(DateTimeZone.UTC));
when(jobDefinitionService.save(any(JobDefinitionDto.class))).thenReturn(jobDefinitionDto);
when(jobTriggerService.create(any(JobTriggerDto.class))).thenReturn(jobTriggerDto);
final UserImpl kmerzUser = new UserImpl(mock(PasswordAlgorithmFactory.class), new Permissions(ImmutableSet.of()), ImmutableMap.of("username", "kmerz"));
when(userService.load("kmerz")).thenReturn(kmerzUser);
final NativeEntity<EventDefinitionDto> nativeEntity = facade.createNativeEntity(entityV1, ImmutableMap.of(), nativeEntities, "kmerz");
assertThat(nativeEntity).isNotNull();
final EventDefinitionDto eventDefinitionDto = nativeEntity.entity();
assertThat(eventDefinitionDto.title()).isEqualTo("title");
assertThat(eventDefinitionDto.description()).isEqualTo("description");
assertThat(eventDefinitionDto.config().type()).isEqualTo("aggregation-v1");
// verify that ownership was registered for this entity
verify(entityOwnershipService, times(1)).registerNewEventDefinition(nativeEntity.entity().id(), kmerzUser);
}
use of org.graylog2.contentpacks.model.entities.EntityV1 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);
}
use of org.graylog2.contentpacks.model.entities.EntityV1 in project graylog2-server by Graylog2.
the class GrokPatternFacadeTest method createNativeEntity.
@Test
public void createNativeEntity() throws NotFoundException {
final Entity grokPatternEntity = EntityV1.builder().id(ModelId.of("1")).type(ModelTypes.GROK_PATTERN_V1).data(objectMapper.convertValue(GrokPatternEntity.create("Test", "[a-z]+"), JsonNode.class)).build();
final NativeEntity<GrokPattern> nativeEntity = facade.createNativeEntity(grokPatternEntity, Collections.emptyMap(), Collections.emptyMap(), "admin");
final GrokPattern expectedGrokPattern = GrokPattern.create("1", "Test", "[a-z]+", null);
final NativeEntityDescriptor expectedDescriptor = NativeEntityDescriptor.create("1", "1", ModelTypes.GROK_PATTERN_V1, "Test");
assertThat(nativeEntity.descriptor().title()).isEqualTo(expectedDescriptor.title());
assertThat(nativeEntity.descriptor().type()).isEqualTo(expectedDescriptor.type());
assertThat(nativeEntity.entity()).isEqualTo(expectedGrokPattern);
assertThat(grokPatternService.load("1")).isEqualTo(expectedGrokPattern);
}
Aggregations