Search in sources :

Example 11 with CronExpression

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();
}
Also used : CronExpression(org.quartz.CronExpression) BadRequestException(javax.ws.rs.BadRequestException) ParseException(java.text.ParseException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 12 with CronExpression

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));
}
Also used : CronExpression(org.quartz.CronExpression) FeedOnTimeArrivalMetric(com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric) DateTime(org.joda.time.DateTime) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with CronExpression

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));
}
Also used : CronExpression(org.quartz.CronExpression) FeedOnTimeArrivalMetric(com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric) DateTime(org.joda.time.DateTime) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with CronExpression

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());
}
Also used : CronTrigger(org.quartz.CronTrigger) CronExpression(org.quartz.CronExpression) Test(org.junit.Test)

Example 15 with CronExpression

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);
}
Also used : ConfigFileFinder(org.alfresco.util.ConfigFileFinder) ShutdownIndicator(org.alfresco.util.ShutdownIndicator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CronExpression(org.quartz.CronExpression) Pair(org.alfresco.util.Pair) Set(java.util.Set) ConfigScheduler(org.alfresco.util.ConfigScheduler) IOException(java.io.IOException) HashMap(java.util.HashMap) InitializingBean(org.springframework.beans.factory.InitializingBean) TransformServiceRegistry(org.alfresco.transform.client.registry.TransformServiceRegistry) HashSet(java.util.HashSet) Map(java.util.Map) PropertyCheck(org.alfresco.util.PropertyCheck) JsonNode(com.fasterxml.jackson.databind.JsonNode) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) Collections(java.util.Collections) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) ConfigFileFinder(org.alfresco.util.ConfigFileFinder)

Aggregations

CronExpression (org.quartz.CronExpression)30 Date (java.util.Date)13 ParseException (java.text.ParseException)12 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)6 Calendar (java.util.Calendar)5 DateTime (org.joda.time.DateTime)5 FeedOnTimeArrivalMetric (com.thinkbiganalytics.metadata.sla.api.core.FeedOnTimeArrivalMetric)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 RFC5545Schedule (com.hubspot.singularity.helpers.RFC5545Schedule)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Matcher (java.util.regex.Matcher)2 ProcessException (org.apache.nifi.processor.exception.ProcessException)2 InvalidRecurrenceRuleException (org.dmfs.rfc5545.recur.InvalidRecurrenceRuleException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SingularityDeployStatistics (com.hubspot.singularity.SingularityDeployStatistics)1 PendingType (com.hubspot.singularity.SingularityPendingRequest.PendingType)1 AbstractJob (com.jeesuite.scheduler.AbstractJob)1