Search in sources :

Example 1 with TestEventProcessorConfig

use of org.graylog.events.TestEventProcessorConfig in project graylog2-server by Graylog2.

the class EventDefinitionHandlerTest method updateWithSchedulingDisabled.

@Test
@MongoDBFixtures("event-processors.json")
public void updateWithSchedulingDisabled() {
    final String newTitle = "A NEW TITLE " + DateTime.now(DateTimeZone.UTC).toString();
    final String newDescription = "A NEW DESCRIPTION " + DateTime.now(DateTimeZone.UTC).toString();
    final EventDefinitionDto existingDto = eventDefinitionService.get("54e3deadbeefdeadbeef0000").orElse(null);
    final JobDefinitionDto existingJobDefinition = jobDefinitionService.get("54e3deadbeefdeadbeef0001").orElse(null);
    final JobTriggerDto existingTrigger = jobTriggerService.get("54e3deadbeefdeadbeef0002").orElse(null);
    final TestEventProcessorConfig existingConfig = (TestEventProcessorConfig) existingDto.config();
    final TestEventProcessorConfig newConfig = existingConfig.toBuilder().executeEveryMs(550000).searchWithinMs(800000).build();
    assertThat(existingDto).isNotNull();
    assertThat(existingJobDefinition).isNotNull();
    assertThat(existingTrigger).isNotNull();
    final EventDefinitionDto updatedDto = existingDto.toBuilder().title(newTitle).description(newDescription).config(newConfig).build();
    assertThat(handler.update(updatedDto, false)).isNotEqualTo(existingDto);
    assertThat(eventDefinitionService.get(existingDto.id())).isPresent().get().satisfies(dto -> {
        assertThat(dto.id()).isEqualTo(existingDto.id());
        assertThat(dto.title()).isEqualTo(newTitle);
        assertThat(dto.description()).isEqualTo(newDescription);
    });
    assertThat(jobDefinitionService.get("54e3deadbeefdeadbeef0001")).isNotPresent();
    assertThat(jobTriggerService.get("54e3deadbeefdeadbeef0002")).isNotPresent();
}
Also used : TestEventProcessorConfig(org.graylog.events.TestEventProcessorConfig) JobDefinitionDto(org.graylog.scheduler.JobDefinitionDto) JobTriggerDto(org.graylog.scheduler.JobTriggerDto) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 2 with TestEventProcessorConfig

use of org.graylog.events.TestEventProcessorConfig in project graylog2-server by Graylog2.

the class EventDefinitionHandlerTest method update.

@Test
@MongoDBFixtures("event-processors.json")
public void update() {
    final String newTitle = "A NEW TITLE " + DateTime.now(DateTimeZone.UTC).toString();
    final String newDescription = "A NEW DESCRIPTION " + DateTime.now(DateTimeZone.UTC).toString();
    final EventDefinitionDto existingDto = eventDefinitionService.get("54e3deadbeefdeadbeef0000").orElse(null);
    final JobDefinitionDto existingJobDefinition = jobDefinitionService.get("54e3deadbeefdeadbeef0001").orElse(null);
    final JobTriggerDto existingTrigger = jobTriggerService.get("54e3deadbeefdeadbeef0002").orElse(null);
    final TestEventProcessorConfig existingConfig = (TestEventProcessorConfig) existingDto.config();
    final TestEventProcessorConfig newConfig = existingConfig.toBuilder().executeEveryMs(550000).searchWithinMs(800000).build();
    final EventProcessorExecutionJob.Data existingTriggerData = (EventProcessorExecutionJob.Data) existingTrigger.data().orElseThrow(AssertionError::new);
    assertThat(existingDto).isNotNull();
    assertThat(existingJobDefinition).isNotNull();
    assertThat(existingTrigger).isNotNull();
    final EventDefinitionDto updatedDto = existingDto.toBuilder().title(newTitle).description(newDescription).config(newConfig).build();
    assertThat(handler.update(updatedDto, true)).isNotEqualTo(existingDto);
    assertThat(eventDefinitionService.get(existingDto.id())).isPresent().get().satisfies(dto -> {
        assertThat(dto.id()).isEqualTo(existingDto.id());
        assertThat(dto.title()).isEqualTo(newTitle);
        assertThat(dto.description()).isEqualTo(newDescription);
    });
    // Test that the schedule is updated to the new config
    final JobDefinitionDto newJobDefinition = jobDefinitionService.get("54e3deadbeefdeadbeef0001").orElseThrow(AssertionError::new);
    assertThat(newJobDefinition.title()).isEqualTo(newTitle);
    assertThat(newJobDefinition.description()).isEqualTo(newDescription);
    assertThat(((EventProcessorExecutionJob.Config) newJobDefinition.config()).processingHopSize()).isEqualTo(550000);
    assertThat(((EventProcessorExecutionJob.Config) newJobDefinition.config()).processingWindowSize()).isEqualTo(800000);
    // Test if the EventDefinition update removed the old trigger data
    // and reset the job definition timerange to the new parameters
    final EventProcessorExecutionJob.Config newJobConfig = (EventProcessorExecutionJob.Config) newJobDefinition.config();
    final TimeRange newTimeRange = newJobConfig.parameters().timerange();
    assertThat(newTimeRange.getFrom()).isEqualTo(clock.nowUTC().minus(newConfig.searchWithinMs()));
    assertThat(newTimeRange.getTo()).isEqualTo(clock.nowUTC());
    assertThat(jobTriggerService.get("54e3deadbeefdeadbeef0002")).isPresent().get().satisfies(trigger -> {
        assertThat(trigger.data()).isEmpty();
        assertThat(trigger.nextTime()).isEqualTo(clock.nowUTC());
    });
}
Also used : TestEventProcessorConfig(org.graylog.events.TestEventProcessorConfig) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) JobDefinitionDto(org.graylog.scheduler.JobDefinitionDto) TestEventProcessorConfig(org.graylog.events.TestEventProcessorConfig) JobTriggerDto(org.graylog.scheduler.JobTriggerDto) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 3 with TestEventProcessorConfig

use of org.graylog.events.TestEventProcessorConfig in project graylog2-server by Graylog2.

the class EventDefinitionHandlerTest method updateWithSchedulingReEnabled.

@Test
@MongoDBFixtures("event-processors-without-schedule.json")
public void updateWithSchedulingReEnabled() {
    final String newTitle = "A NEW TITLE " + DateTime.now(DateTimeZone.UTC).toString();
    final String newDescription = "A NEW DESCRIPTION " + DateTime.now(DateTimeZone.UTC).toString();
    final EventDefinitionDto existingDto = eventDefinitionService.get("54e3deadbeefdeadbeef0000").orElse(null);
    final TestEventProcessorConfig existingConfig = (TestEventProcessorConfig) existingDto.config();
    final TestEventProcessorConfig newConfig = existingConfig.toBuilder().executeEveryMs(550000).searchWithinMs(800000).build();
    assertThat(existingDto).isNotNull();
    final EventDefinitionDto updatedDto = existingDto.toBuilder().title(newTitle).description(newDescription).config(newConfig).build();
    assertThat(handler.update(updatedDto, true)).isNotEqualTo(existingDto);
    assertThat(eventDefinitionService.get(existingDto.id())).isPresent().get().satisfies(dto -> {
        assertThat(dto.id()).isEqualTo(existingDto.id());
        assertThat(dto.title()).isEqualTo(newTitle);
        assertThat(dto.description()).isEqualTo(newDescription);
    });
    final JobDefinitionDto newJobDefinition = jobDefinitionService.getByConfigField("event_definition_id", existingDto.id()).orElseThrow(AssertionError::new);
    assertThat(newJobDefinition.title()).isEqualTo(newTitle);
    assertThat(newJobDefinition.description()).isEqualTo(newDescription);
    assertThat(((EventProcessorExecutionJob.Config) newJobDefinition.config()).processingHopSize()).isEqualTo(550000);
    assertThat(jobTriggerService.getForJob(newJobDefinition.id()).get(0)).satisfies(trigger -> {
        final IntervalJobSchedule schedule = (IntervalJobSchedule) trigger.schedule();
        assertThat(schedule.interval()).isEqualTo(550000);
    });
}
Also used : TestEventProcessorConfig(org.graylog.events.TestEventProcessorConfig) JobDefinitionDto(org.graylog.scheduler.JobDefinitionDto) TestEventProcessorConfig(org.graylog.events.TestEventProcessorConfig) IntervalJobSchedule(org.graylog.scheduler.schedule.IntervalJobSchedule) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Example 4 with TestEventProcessorConfig

use of org.graylog.events.TestEventProcessorConfig in project graylog2-server by Graylog2.

the class DBEventProcessorServiceTest method loadPersisted.

@Test
@MongoDBFixtures("event-processors.json")
public void loadPersisted() {
    final List<EventDefinitionDto> dtos = dbService.streamAll().collect(Collectors.toList());
    assertThat(dtos).hasSize(1);
    assertThat(dtos.get(0)).satisfies(dto -> {
        assertThat(dto.id()).isNotBlank();
        assertThat(dto.title()).isEqualTo("Test");
        assertThat(dto.description()).isEqualTo("A test event definition");
        assertThat(dto.priority()).isEqualTo(2);
        assertThat(dto.keySpec()).isEqualTo(ImmutableList.of("username"));
        assertThat(dto.fieldSpec()).isEmpty();
        assertThat(dto.notifications()).isEmpty();
        assertThat(dto.storage()).hasSize(1);
        assertThat(dto.config()).isInstanceOf(TestEventProcessorConfig.class);
        assertThat(dto.config()).satisfies(abstractConfig -> {
            final TestEventProcessorConfig config = (TestEventProcessorConfig) abstractConfig;
            assertThat(config.type()).isEqualTo("__test_event_processor_config__");
            assertThat(config.message()).isEqualTo("This is a test event processor");
        });
    });
}
Also used : TestEventProcessorConfig(org.graylog.events.TestEventProcessorConfig) MongoDBFixtures(org.graylog.testing.mongodb.MongoDBFixtures) Test(org.junit.Test)

Aggregations

TestEventProcessorConfig (org.graylog.events.TestEventProcessorConfig)4 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)4 Test (org.junit.Test)4 JobDefinitionDto (org.graylog.scheduler.JobDefinitionDto)3 JobTriggerDto (org.graylog.scheduler.JobTriggerDto)2 IntervalJobSchedule (org.graylog.scheduler.schedule.IntervalJobSchedule)1 TimeRange (org.graylog2.plugin.indexer.searches.timeranges.TimeRange)1