use of org.quartz.CronExpression in project kylo by Teradata.
the class UtilityRestController method validateCronExpression.
@GET
@Path("/cron-expression/validate")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Validates the specified cron expression.")
@ApiResponses(@ApiResponse(code = 200, message = "Returns the result.", response = Map.class))
public Response validateCronExpression(@QueryParam("cronExpression") String cronExpression) {
boolean valid = CronExpression.isValidExpression(cronExpression);
if (valid) {
try {
CronExpression e = new CronExpression(cronExpression);
valid = CronExpressionUtil.getNextFireTime(e) != null;
} catch (Exception e) {
valid = false;
}
}
return Response.ok("{\"valid\":" + valid + "}").build();
}
use of org.quartz.CronExpression in project kylo by Teradata.
the class FeedOnTimeArrivalMetricAssessorTest method testFailure.
@Test
public void testFailure() throws ParseException {
PowerMockito.mockStatic(DateTime.class);
PowerMockito.mockStatic(CronExpressionUtil.class);
DateTime now = new DateTime().minusHours(2);
// Some Cron Expression .. Mockito will overwrite
CronExpression cron = new CronExpression("0 0 0/2 1/1 * ? *");
// set the current time to a known time
BDDMockito.given(DateTime.now()).willReturn(now);
// set the previous fire date to a known time in the past
DateTime previousFireTime = new DateTime(now).minusHours(4);
BDDMockito.given(CronExpressionUtil.getPreviousFireTime(cron)).willReturn(previousFireTime.toDate());
// window is = (now - 4) - (now -4) + lateTimeGracePeriod)
// Some Feed End Time to a time outside the window
DateTime lastFeedTime = new DateTime(previousFireTime).minusHours(lateTimeGracePeriod + 1);
when(this.feedProvider.getLastActiveTimeStamp("feed")).thenReturn(lastFeedTime);
this.metric = new FeedOnTimeArrivalMetric("feed", cron, Period.hours(lateTimeGracePeriod));
this.assessor.assess(metric, this.builder);
// assert values
verify(this.builder.result(AssessmentResult.FAILURE));
}
use of org.quartz.CronExpression in project kylo by Teradata.
the class FeedOnTimeArrivalMetricAssessorTest method testSuccess.
@Test
public void testSuccess() throws ParseException {
PowerMockito.mockStatic(DateTime.class);
PowerMockito.mockStatic(CronExpressionUtil.class);
DateTime now = new DateTime().minusHours(2);
// set the current time to a known time
BDDMockito.given(DateTime.now()).willReturn(now);
// set the previous fire date to a known time in the past,but within the window
DateTime previousFireTime = new DateTime(now).minusHours(3);
// Some Cron Expression .. Mockito will overwrite
CronExpression cron = new CronExpression("0 0 0/2 1/1 * ? *");
BDDMockito.given(CronExpressionUtil.getPreviousFireTime(cron)).willReturn(previousFireTime.toDate());
// window is = (now - 3) - (now -3) + lateTime)
// Some Feed End Time to a time within this window
DateTime lastFeedTime = new DateTime(previousFireTime).plus(lateTimeGracePeriod - 1);
when(this.feedProvider.getLastActiveTimeStamp("feed")).thenReturn(lastFeedTime);
this.metric = new FeedOnTimeArrivalMetric("feed", cron, Period.hours(lateTimeGracePeriod));
this.assessor.assess(metric, this.builder);
// assert values
DateTime lateTime = previousFireTime.plusHours(lateTimeGracePeriod);
Assert.assertTrue((lastFeedTime.isAfter(previousFireTime) && lastFeedTime.isBefore(lateTime)));
verify(this.builder.result(AssessmentResult.SUCCESS));
}
use of org.quartz.CronExpression in project pentaho-platform by pentaho.
the class QuartzSchedulerTest method testSetTimezone.
@Test
public void testSetTimezone() throws Exception {
CronTrigger cronTrigger = new CronTrigger();
cronTrigger.setCronExpression(new CronExpression("0 15 10 ? * 6L 2002-2018"));
String currentTimezoneId = TimeZone.getDefault().getID();
new QuartzScheduler().setTimezone(cronTrigger, currentTimezoneId);
assertNotNull(cronTrigger.getTimeZone());
assertEquals(currentTimezoneId, cronTrigger.getTimeZone().getID());
}
use of org.quartz.CronExpression in project alfresco-repository by Alfresco.
the class RenditionDefinitionRegistry2Impl method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
PropertyCheck.mandatory(this, "transformServiceRegistry", transformServiceRegistry);
PropertyCheck.mandatory(this, "timeoutDefault", timeoutDefault);
PropertyCheck.mandatory(this, "jsonObjectMapper", jsonObjectMapper);
// If we have a cronExpression it indicates that we will schedule reading.
if (cronExpression != null) {
PropertyCheck.mandatory(this, "initialAndOnErrorCronExpression", initialAndOnErrorCronExpression);
}
configFileFinder = new ConfigFileFinder(jsonObjectMapper) {
@Override
protected void readJson(JsonNode jsonNode, String readFromMessage, String baseUrl) throws IOException {
try {
JsonNode renditions = jsonNode.get("renditions");
if (renditions != null && renditions.isArray()) {
for (JsonNode rendition : renditions) {
RenditionDef def = jsonObjectMapper.convertValue(rendition, RenditionDef.class);
Map<String, String> map = new HashMap<>();
if (def.options != null) {
def.options.forEach(o -> map.put(o.name, o.value));
}
if (!map.containsKey(RenditionDefinition2.TIMEOUT)) {
map.put(RenditionDefinition2.TIMEOUT, timeoutDefault);
}
RenditionDefinition2 original = getRenditionDefinition(def.renditionName);
new RenditionDefinition2Impl(def.renditionName, def.targetMediaType, map, true, RenditionDefinitionRegistry2Impl.this);
if (original != null) {
log.debug(readFromMessage + " replaced the rendition " + def.renditionName);
}
}
}
} catch (IllegalArgumentException e) {
log.error("Error reading " + readFromMessage + " " + e.getMessage());
}
}
};
configScheduler.run(true, log, cronExpression, initialAndOnErrorCronExpression);
}
Aggregations