Search in sources :

Example 6 with IntervalJobSchedule

use of org.graylog.scheduler.schedule.IntervalJobSchedule in project graylog2-server by Graylog2.

the class EventDefinitionHandlerTest method create.

@Test
public void create() {
    final EventDefinitionDto newDto = EventDefinitionDto.builder().title("Test").description("A test event definition").config(TestEventProcessorConfig.builder().message("This is a test event processor").searchWithinMs(300000).executeEveryMs(60001).build()).priority(3).alert(false).notificationSettings(EventNotificationSettings.withGracePeriod(60000)).keySpec(ImmutableList.of("a", "b")).notifications(ImmutableList.of()).build();
    final EventDefinitionDto dto = handler.create(newDto, Optional.empty());
    // Handler should create the event definition
    assertThat(eventDefinitionService.get(dto.id())).isPresent();
    final Optional<JobDefinitionDto> jobDefinition = jobDefinitionService.getByConfigField("event_definition_id", dto.id());
    // Handler also should create the job definition for the event definition/processor
    assertThat(jobDefinition).isPresent().get().satisfies(definition -> {
        assertThat(definition.title()).isEqualTo("Test");
        assertThat(definition.description()).isEqualTo("A test event definition");
        assertThat(definition.config()).isInstanceOf(EventProcessorExecutionJob.Config.class);
        final EventProcessorExecutionJob.Config config = (EventProcessorExecutionJob.Config) definition.config();
        assertThat(config.processingWindowSize()).isEqualTo(300000);
        assertThat(config.processingHopSize()).isEqualTo(60001);
    });
    // And the handler should also create a job trigger for the created job definition
    final Optional<JobTriggerDto> jobTrigger = jobTriggerService.nextRunnableTrigger();
    assertThat(jobTrigger).isPresent().get().satisfies(trigger -> {
        assertThat(trigger.jobDefinitionId()).isEqualTo(jobDefinition.get().id());
        assertThat(trigger.schedule()).isInstanceOf(IntervalJobSchedule.class);
        final IntervalJobSchedule schedule = (IntervalJobSchedule) trigger.schedule();
        assertThat(schedule.interval()).isEqualTo(60001);
        assertThat(schedule.unit()).isEqualTo(TimeUnit.MILLISECONDS);
    });
}
Also used : JobDefinitionDto(org.graylog.scheduler.JobDefinitionDto) TestEventProcessorConfig(org.graylog.events.TestEventProcessorConfig) IntervalJobSchedule(org.graylog.scheduler.schedule.IntervalJobSchedule) JobTriggerDto(org.graylog.scheduler.JobTriggerDto) Test(org.junit.Test)

Example 7 with IntervalJobSchedule

use of org.graylog.scheduler.schedule.IntervalJobSchedule 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 8 with IntervalJobSchedule

use of org.graylog.scheduler.schedule.IntervalJobSchedule in project graylog2-server by Graylog2.

the class AggregationEventProcessorConfig method toJobSchedulerConfig.

@Override
public Optional<EventProcessorSchedulerConfig> toJobSchedulerConfig(EventDefinition eventDefinition, JobSchedulerClock clock) {
    final DateTime now = clock.nowUTC();
    // We need an initial timerange for the first execution of the event processor
    final AbsoluteRange timerange = AbsoluteRange.create(now.minus(searchWithinMs()), now);
    final EventProcessorExecutionJob.Config jobDefinitionConfig = EventProcessorExecutionJob.Config.builder().eventDefinitionId(eventDefinition.id()).processingWindowSize(searchWithinMs()).processingHopSize(executeEveryMs()).parameters(AggregationEventProcessorParameters.builder().timerange(timerange).build()).build();
    final IntervalJobSchedule schedule = IntervalJobSchedule.builder().interval(executeEveryMs()).unit(TimeUnit.MILLISECONDS).build();
    return Optional.of(EventProcessorSchedulerConfig.create(jobDefinitionConfig, schedule));
}
Also used : AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) IntervalJobSchedule(org.graylog.scheduler.schedule.IntervalJobSchedule) DateTime(org.joda.time.DateTime) EventProcessorExecutionJob(org.graylog.events.processor.EventProcessorExecutionJob)

Aggregations

IntervalJobSchedule (org.graylog.scheduler.schedule.IntervalJobSchedule)8 Test (org.junit.Test)6 TestEventProcessorConfig (org.graylog.events.TestEventProcessorConfig)3 EventProcessorExecutionJob (org.graylog.events.processor.EventProcessorExecutionJob)3 MongoDBFixtures (org.graylog.testing.mongodb.MongoDBFixtures)3 DateTime (org.joda.time.DateTime)3 JobDefinitionDto (org.graylog.scheduler.JobDefinitionDto)2 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)2 JobSchedulerTestClock (org.graylog.events.JobSchedulerTestClock)1 EventDefinitionDto (org.graylog.events.processor.EventDefinitionDto)1 JobTriggerData (org.graylog.scheduler.JobTriggerData)1 JobTriggerDto (org.graylog.scheduler.JobTriggerDto)1