Search in sources :

Example 1 with ConcurrencyConstraint

use of co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint in project cdap by caskdata.

the class ProgramLifecycleHttpHandlerTest method testUpdateSchedule.

private void testUpdateSchedule(ApplicationId appV2Id) throws Exception {
    ScheduleDetail updateDetail = new ScheduleDetail(AppWithSchedule.SCHEDULE, "updatedDescription", null, ImmutableMap.of("twoKey", "twoValue", "someKey", "newValue"), new TimeTrigger("0 4 * * *"), ImmutableList.of(new ConcurrencyConstraint(5)), null);
    // trying to update schedule for a non-existing app should fail
    HttpResponse response = updateSchedule(TEST_NAMESPACE1, "nonExistingApp", null, AppWithSchedule.SCHEDULE, updateDetail);
    Assert.assertEquals(HttpResponseStatus.NOT_FOUND.code(), response.getStatusLine().getStatusCode());
    // trying to update a non-existing schedule should fail
    ScheduleDetail nonExistingSchedule = new ScheduleDetail("NonExistingSchedule", "updatedDescription", null, ImmutableMap.of("twoKey", "twoValue"), new TimeTrigger("0 4 * * *"), ImmutableList.of(new ConcurrencyConstraint(5)), null);
    response = updateSchedule(TEST_NAMESPACE1, AppWithSchedule.NAME, null, "NonExistingSchedule", nonExistingSchedule);
    Assert.assertEquals(HttpResponseStatus.NOT_FOUND.code(), response.getStatusLine().getStatusCode());
    // should be able to update an existing schedule with a valid new time schedule
    response = updateSchedule(TEST_NAMESPACE1, AppWithSchedule.NAME, null, AppWithSchedule.SCHEDULE, updateDetail);
    Assert.assertEquals(HttpResponseStatus.OK.code(), response.getStatusLine().getStatusCode());
    // verify that the schedule information for updated
    ScheduleDetail schedule = getSchedule(TEST_NAMESPACE1, AppWithSchedule.NAME, null, AppWithSchedule.SCHEDULE);
    Assert.assertEquals("updatedDescription", schedule.getDescription());
    Assert.assertEquals("0 4 * * *", ((TimeTrigger) schedule.getTrigger()).getCronExpression());
    Assert.assertEquals(new ProtoConstraint.ConcurrencyConstraint(5), schedule.getConstraints().get(0));
    // the properties should have been replaced
    Assert.assertEquals(2, schedule.getProperties().size());
    Assert.assertEquals("newValue", schedule.getProperties().get("someKey"));
    Assert.assertEquals("twoValue", schedule.getProperties().get("twoKey"));
    // the old property should not exist
    Assert.assertNull(schedule.getProperties().get("oneKey"));
    // the above update should not have affected the schedule for the other version of the app
    schedule = getSchedule(TEST_NAMESPACE1, AppWithSchedule.NAME, appV2Id.getVersion(), AppWithSchedule.SCHEDULE);
    Assert.assertNotEquals("updatedDescription", schedule.getDescription());
    Assert.assertEquals("0/15 * * * * ?", ((TimeTrigger) schedule.getTrigger()).getCronExpression());
    // try to update the schedule again but this time with property as null. It should retain the old properties
    ScheduleDetail scheduleDetail = new ScheduleDetail(AppWithSchedule.SCHEDULE, "updatedDescription", null, null, new ProtoTrigger.TimeTrigger("0 4 * * *"), null, null);
    response = updateSchedule(TEST_NAMESPACE1, AppWithSchedule.NAME, null, AppWithSchedule.SCHEDULE, scheduleDetail);
    Assert.assertEquals(HttpResponseStatus.OK.code(), response.getStatusLine().getStatusCode());
    schedule = getSchedule(TEST_NAMESPACE1, AppWithSchedule.NAME, null, AppWithSchedule.SCHEDULE);
    Assert.assertEquals(2, schedule.getProperties().size());
    Assert.assertEquals("newValue", schedule.getProperties().get("someKey"));
    Assert.assertEquals("twoValue", schedule.getProperties().get("twoKey"));
    Assert.assertEquals(new ProtoConstraint.ConcurrencyConstraint(5), schedule.getConstraints().get(0));
}
Also used : ConcurrencyConstraint(co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint) ProtoConstraint(co.cask.cdap.proto.ProtoConstraint) TimeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger) ProtoTrigger(co.cask.cdap.proto.ProtoTrigger) HttpResponse(org.apache.http.HttpResponse) ScheduleDetail(co.cask.cdap.proto.ScheduleDetail)

Example 2 with ConcurrencyConstraint

use of co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint in project cdap by caskdata.

the class Schedulers method toScheduleCreationSpec.

public static ScheduleCreationSpec toScheduleCreationSpec(NamespaceId deployNamespace, Schedule schedule, String programName, Map<String, String> properties) {
    Trigger trigger;
    if (schedule instanceof TimeSchedule) {
        trigger = new TimeTrigger(((TimeSchedule) schedule).getCronEntry());
    } else {
        StreamSizeSchedule streamSizeSchedule = ((StreamSizeSchedule) schedule);
        trigger = new StreamSizeTrigger(deployNamespace.stream(streamSizeSchedule.getStreamName()), streamSizeSchedule.getDataTriggerMB());
    }
    Integer maxConcurrentRuns = schedule.getRunConstraints().getMaxConcurrentRuns();
    List<Constraint> constraints = maxConcurrentRuns == null ? ImmutableList.<Constraint>of() : ImmutableList.<Constraint>of(new ConcurrencyConstraint(maxConcurrentRuns));
    return new ScheduleCreationSpec(schedule.getName(), schedule.getDescription(), programName, properties, trigger, constraints, Schedulers.JOB_QUEUE_TIMEOUT_MILLIS);
}
Also used : ConcurrencyConstraint(co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint) StreamSizeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger) TimeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger) Trigger(co.cask.cdap.internal.schedule.trigger.Trigger) TimeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger) Constraint(co.cask.cdap.internal.schedule.constraint.Constraint) ConcurrencyConstraint(co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint) StreamSizeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule) ScheduleCreationSpec(co.cask.cdap.internal.schedule.ScheduleCreationSpec)

Example 3 with ConcurrencyConstraint

use of co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint in project cdap by caskdata.

the class Schedulers method toProgramSchedule.

public static ProgramSchedule toProgramSchedule(ApplicationId appId, ScheduleSpecification spec) {
    Schedule schedule = spec.getSchedule();
    ProgramType programType = ProgramType.valueOfSchedulableType(spec.getProgram().getProgramType());
    ProgramId programId = appId.program(programType, spec.getProgram().getProgramName());
    Trigger trigger;
    if (schedule instanceof TimeSchedule) {
        TimeSchedule timeSchedule = (TimeSchedule) schedule;
        trigger = new TimeTrigger(timeSchedule.getCronEntry());
    } else {
        StreamSizeSchedule streamSchedule = (StreamSizeSchedule) schedule;
        StreamId streamId = programId.getNamespaceId().stream(streamSchedule.getStreamName());
        trigger = new StreamSizeTrigger(streamId, streamSchedule.getDataTriggerMB());
    }
    Integer maxConcurrentRuns = schedule.getRunConstraints().getMaxConcurrentRuns();
    List<Constraint> constraints = maxConcurrentRuns == null ? ImmutableList.<Constraint>of() : ImmutableList.<Constraint>of(new ConcurrencyConstraint(maxConcurrentRuns));
    return new ProgramSchedule(schedule.getName(), schedule.getDescription(), programId, spec.getProperties(), trigger, constraints);
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) ConcurrencyConstraint(co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint) TimeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger) Constraint(co.cask.cdap.internal.schedule.constraint.Constraint) ConcurrencyConstraint(co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint) ProgramId(co.cask.cdap.proto.id.ProgramId) StreamSizeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger) TimeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger) Trigger(co.cask.cdap.internal.schedule.trigger.Trigger) ProgramSchedule(co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule) Schedule(co.cask.cdap.api.schedule.Schedule) ProgramSchedule(co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) StreamSizeTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger) TimeSchedule(co.cask.cdap.internal.schedule.TimeSchedule) ProgramType(co.cask.cdap.proto.ProgramType) StreamSizeSchedule(co.cask.cdap.internal.schedule.StreamSizeSchedule)

Aggregations

ConcurrencyConstraint (co.cask.cdap.internal.app.runtime.schedule.constraint.ConcurrencyConstraint)3 TimeTrigger (co.cask.cdap.internal.app.runtime.schedule.trigger.TimeTrigger)3 StreamSizeTrigger (co.cask.cdap.internal.app.runtime.schedule.trigger.StreamSizeTrigger)2 StreamSizeSchedule (co.cask.cdap.internal.schedule.StreamSizeSchedule)2 TimeSchedule (co.cask.cdap.internal.schedule.TimeSchedule)2 Constraint (co.cask.cdap.internal.schedule.constraint.Constraint)2 Trigger (co.cask.cdap.internal.schedule.trigger.Trigger)2 Schedule (co.cask.cdap.api.schedule.Schedule)1 ProgramSchedule (co.cask.cdap.internal.app.runtime.schedule.ProgramSchedule)1 ScheduleCreationSpec (co.cask.cdap.internal.schedule.ScheduleCreationSpec)1 ProgramType (co.cask.cdap.proto.ProgramType)1 ProtoConstraint (co.cask.cdap.proto.ProtoConstraint)1 ProtoTrigger (co.cask.cdap.proto.ProtoTrigger)1 ScheduleDetail (co.cask.cdap.proto.ScheduleDetail)1 ProgramId (co.cask.cdap.proto.id.ProgramId)1 StreamId (co.cask.cdap.proto.id.StreamId)1 HttpResponse (org.apache.http.HttpResponse)1