use of org.graylog.scheduler.schedule.IntervalJobSchedule in project graylog2-server by Graylog2.
the class EventDefinitionHandlerTest method schedule.
@Test
@MongoDBFixtures("event-processors-without-schedule.json")
public void schedule() {
assertThat(eventDefinitionService.get("54e3deadbeefdeadbeef0000")).isPresent();
assertThat(jobDefinitionService.streamAll().count()).isEqualTo(0);
assertThat(jobTriggerService.all()).isEmpty();
handler.schedule("54e3deadbeefdeadbeef0000");
assertThat(eventDefinitionService.get("54e3deadbeefdeadbeef0000")).isPresent();
assertThat(jobDefinitionService.getByConfigField("event_definition_id", "54e3deadbeefdeadbeef0000")).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(60000);
assertThat(jobTriggerService.nextRunnableTrigger()).get().satisfies(trigger -> {
assertThat(trigger.jobDefinitionId()).isEqualTo(definition.id());
assertThat(trigger.schedule()).isInstanceOf(IntervalJobSchedule.class);
final IntervalJobSchedule schedule = (IntervalJobSchedule) trigger.schedule();
assertThat(schedule.interval()).isEqualTo(60000);
assertThat(schedule.unit()).isEqualTo(TimeUnit.MILLISECONDS);
});
});
assertThat(jobDefinitionService.get("54e3deadbeefdeadbeef0001")).isNotPresent();
assertThat(jobTriggerService.get("54e3deadbeefdeadbeef0002")).isNotPresent();
}
use of org.graylog.scheduler.schedule.IntervalJobSchedule in project graylog2-server by Graylog2.
the class TestEventProcessorConfig 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(TestEventProcessorParameters.builder().timerange(timerange).build()).build();
final IntervalJobSchedule schedule = IntervalJobSchedule.builder().interval(executeEveryMs()).unit(TimeUnit.MILLISECONDS).build();
return Optional.of(EventProcessorSchedulerConfig.create(jobDefinitionConfig, schedule));
}
use of org.graylog.scheduler.schedule.IntervalJobSchedule in project graylog2-server by Graylog2.
the class AggregationEventProcessorConfigTest method toJobSchedulerConfig.
@Test
@MongoDBFixtures("aggregation-processors.json")
public void toJobSchedulerConfig() {
final EventDefinitionDto dto = dbService.get("54e3deadbeefdeadbeefaffe").orElse(null);
assertThat(dto).isNotNull();
assertThat(dto.config().toJobSchedulerConfig(dto, clock)).isPresent().get().satisfies(schedulerConfig -> {
assertThat(schedulerConfig.jobDefinitionConfig()).satisfies(jobDefinitionConfig -> {
assertThat(jobDefinitionConfig).isInstanceOf(EventProcessorExecutionJob.Config.class);
final EventProcessorExecutionJob.Config config = (EventProcessorExecutionJob.Config) jobDefinitionConfig;
assertThat(config.eventDefinitionId()).isEqualTo(dto.id());
assertThat(config.processingWindowSize()).isEqualTo(300000);
assertThat(config.processingHopSize()).isEqualTo(300000);
assertThat(config.parameters()).isEqualTo(AggregationEventProcessorParameters.builder().timerange(AbsoluteRange.create(clock.nowUTC().minus(300000), clock.nowUTC())).build());
});
assertThat(schedulerConfig.schedule()).satisfies(schedule -> {
assertThat(schedule).isInstanceOf(IntervalJobSchedule.class);
final IntervalJobSchedule config = (IntervalJobSchedule) schedule;
assertThat(config.interval()).isEqualTo(300000);
assertThat(config.unit()).isEqualTo(TimeUnit.MILLISECONDS);
});
});
}
use of org.graylog.scheduler.schedule.IntervalJobSchedule in project graylog2-server by Graylog2.
the class DBJobTriggerServiceTest method nextRunnableTriggerWithPausedCompletedAndErrorStatus.
@Test
public void nextRunnableTriggerWithPausedCompletedAndErrorStatus() {
// No triggers yet
assertThat(dbJobTriggerService.nextRunnableTrigger()).isEmpty();
final IntervalJobSchedule schedule = IntervalJobSchedule.builder().interval(1).unit(TimeUnit.SECONDS).build();
final JobTriggerDto trigger1 = dbJobTriggerService.create(JobTriggerDto.Builder.create(clock).jobDefinitionId("abc-123").nextTime(clock.nowUTC().plusSeconds(11)).schedule(schedule).build());
// This trigger should never be fired because its status is COMPLETE
dbJobTriggerService.create(JobTriggerDto.Builder.create(clock).jobDefinitionId("abc-123").status(JobTriggerStatus.COMPLETE).nextTime(clock.nowUTC().plusSeconds(10)).schedule(schedule).build());
// This trigger should never be fired because its status is PAUSED
dbJobTriggerService.create(JobTriggerDto.Builder.create(clock).jobDefinitionId("abc-123").status(JobTriggerStatus.PAUSED).nextTime(clock.nowUTC().plusSeconds(10)).schedule(schedule).build());
// This trigger should never be fired because its status is ERROR
dbJobTriggerService.create(JobTriggerDto.Builder.create(clock).jobDefinitionId("abc-123").status(JobTriggerStatus.ERROR).nextTime(clock.nowUTC().plusSeconds(10)).schedule(schedule).build());
// First try is empty because the next time of the trigger is in the future
assertThat(dbJobTriggerService.nextRunnableTrigger()).isEmpty();
clock.plus(20, TimeUnit.SECONDS);
// The second call should return trigger1 because the other ones are in status COMPLETE, PAUSED and ERROR
assertThat(dbJobTriggerService.nextRunnableTrigger()).isNotEmpty().get().satisfies(trigger -> assertThat(trigger.id()).isEqualTo(trigger1.id()));
clock.plus(20, TimeUnit.SECONDS);
// No trigger left
assertThat(dbJobTriggerService.nextRunnableTrigger()).isEmpty();
}
use of org.graylog.scheduler.schedule.IntervalJobSchedule in project graylog2-server by Graylog2.
the class CreateJobTriggerRequestTest method toDto.
@Test
public void toDto() {
final DateTime now = DateTime.now(UTC);
final JobSchedulerTestClock clock = new JobSchedulerTestClock(now);
final IntervalJobSchedule schedule = IntervalJobSchedule.builder().interval(1).unit(TimeUnit.SECONDS).build();
final CreateJobTriggerRequest request = CreateJobTriggerRequest.builder().jobDefinitionId("abc-123").startTime(now).nextTime(now).schedule(schedule).build();
final JobTriggerData.FallbackData data = new JobTriggerData.FallbackData();
final CreateJobTriggerRequest requestWithDataAndEndTime = CreateJobTriggerRequest.builder().jobDefinitionId("abc-123").startTime(now).endTime(now.plusDays(1)).nextTime(now).schedule(schedule).data(data).build();
assertThat(request.toDto(clock)).satisfies(dto -> {
assertThat(dto.jobDefinitionId()).isEqualTo("abc-123");
assertThat(dto.startTime()).isEqualTo(now);
assertThat(dto.endTime()).isNotPresent();
assertThat(dto.nextTime()).isEqualTo(now);
assertThat(dto.createdAt()).isEqualTo(now);
assertThat(dto.updatedAt()).isEqualTo(now);
assertThat(dto.triggeredAt()).isNotPresent();
assertThat(dto.status()).isEqualTo(JobTriggerStatus.RUNNABLE);
assertThat(dto.lock()).isEqualTo(JobTriggerLock.empty());
assertThat(dto.schedule()).isEqualTo(schedule);
assertThat(dto.data()).isNotPresent();
});
assertThat(requestWithDataAndEndTime.toDto(clock)).satisfies(dto -> {
assertThat(dto.jobDefinitionId()).isEqualTo("abc-123");
assertThat(dto.startTime()).isEqualTo(now);
assertThat(dto.endTime()).isPresent().get().isEqualTo(now.plusDays(1));
assertThat(dto.nextTime()).isEqualTo(now);
assertThat(dto.createdAt()).isEqualTo(now);
assertThat(dto.updatedAt()).isEqualTo(now);
assertThat(dto.triggeredAt()).isNotPresent();
assertThat(dto.status()).isEqualTo(JobTriggerStatus.RUNNABLE);
assertThat(dto.lock()).isEqualTo(JobTriggerLock.empty());
assertThat(dto.schedule()).isEqualTo(schedule);
assertThat(dto.data()).isPresent().get().isEqualTo(data);
});
}
Aggregations