use of co.cask.cdap.api.schedule.Trigger in project cdap by caskdata.
the class ProgramScheduleService method update.
/**
* Update the given schedule
*
* @param scheduleId the schedule to update
* @param scheduleDetail the schedule to update it to
* @throws NotFoundException if the schedule could not be found
* @throws BadRequestException if the update is invalid
* @throws UnauthorizedException if the principal is not authorized as an admin operations on the schedule program
* @throws Exception if any other errors occurred while performing the authorization enforcement check
*/
public void update(ScheduleId scheduleId, ScheduleDetail scheduleDetail) throws Exception {
authorizationEnforcer.enforce(scheduleId.getParent(), authenticationContext.getPrincipal(), Action.ADMIN);
ProgramSchedule existing = scheduler.getSchedule(scheduleId);
String description = Objects.firstNonNull(scheduleDetail.getDescription(), existing.getDescription());
ProgramId programId = scheduleDetail.getProgram() == null ? existing.getProgramId() : existing.getProgramId().getParent().program(scheduleDetail.getProgram().getProgramType() == null ? existing.getProgramId().getType() : ProgramType.valueOfSchedulableType(scheduleDetail.getProgram().getProgramType()), Objects.firstNonNull(scheduleDetail.getProgram().getProgramName(), existing.getProgramId().getProgram()));
if (!programId.equals(existing.getProgramId())) {
throw new BadRequestException(String.format("Must update the schedule '%s' with the same program as '%s'. " + "To change the program in a schedule, please delete the schedule and create a new one.", existing.getName(), existing.getProgramId().toString()));
}
Map<String, String> properties = Objects.firstNonNull(scheduleDetail.getProperties(), existing.getProperties());
Trigger trigger = Objects.firstNonNull(scheduleDetail.getTrigger(), existing.getTrigger());
List<? extends Constraint> constraints = Objects.firstNonNull(scheduleDetail.getConstraints(), existing.getConstraints());
Long timeoutMillis = Objects.firstNonNull(scheduleDetail.getTimeoutMillis(), existing.getTimeoutMillis());
ProgramSchedule updatedSchedule = new ProgramSchedule(existing.getName(), description, programId, properties, trigger, constraints, timeoutMillis);
scheduler.updateSchedule(updatedSchedule);
}
use of co.cask.cdap.api.schedule.Trigger in project cdap by caskdata.
the class AppWithFrequentScheduledWorkflows method configure.
@Override
public void configure() {
setName(NAME);
setDescription("Sample application with multiple Workflows");
addWorkflow(new DummyWorkflow(SOME_WORKFLOW));
addWorkflow(new DummyWorkflow(ANOTHER_WORKFLOW));
addWorkflow(new DummyWorkflow(SCHEDULED_WORKFLOW_1));
addWorkflow(new DummyWorkflow(SCHEDULED_WORKFLOW_2));
addWorkflow(new DummyWorkflow(COMPOSITE_WORKFLOW));
schedule(buildSchedule(DATASET_PARTITION_SCHEDULE_1, ProgramType.WORKFLOW, SOME_WORKFLOW).triggerOnPartitions(DATASET_NAME1, 1));
schedule(buildSchedule(DATASET_PARTITION_SCHEDULE_2, ProgramType.WORKFLOW, ANOTHER_WORKFLOW).triggerOnPartitions(DATASET_NAME2, 2));
// Schedule the workflow to run in every ten seconds
schedule(buildSchedule(TEN_SECOND_SCHEDULE_1, ProgramType.WORKFLOW, SCHEDULED_WORKFLOW_1).triggerByTime("*/10 * * * * ?"));
// Schedule the workflow to run in every ten seconds
schedule(buildSchedule(TEN_SECOND_SCHEDULE_2, ProgramType.WORKFLOW, SCHEDULED_WORKFLOW_2).triggerByTime("*/10 * * * * ?"));
// OrTrigger with only PartitionTrigger to be triggered
Trigger orTrigger1 = getTriggerFactory().or(getTriggerFactory().onPartitions(DATASET_NAME2, 3), getTriggerFactory().onProgramStatus(ProgramType.WORKFLOW, SCHEDULED_WORKFLOW_1, ProgramStatus.KILLED));
// OrTrigger with only TimeTrigger to be triggered
Trigger orTrigger2 = getTriggerFactory().or(getTriggerFactory().byTime("*/5 * * * * ?"), getTriggerFactory().onProgramStatus(ProgramType.WORKFLOW, SCHEDULED_WORKFLOW_1, ProgramStatus.KILLED));
schedule(buildSchedule(COMPOSITE_SCHEDULE, ProgramType.WORKFLOW, COMPOSITE_WORKFLOW).triggerOn(getTriggerFactory().and(orTrigger1, orTrigger2)));
}
use of co.cask.cdap.api.schedule.Trigger in project cdap by caskdata.
the class AbstractCompositeTriggerBuilder method getBuiltTriggers.
protected SatisfiableTrigger[] getBuiltTriggers(String namespace, String applicationName, String applicationVersion) {
int numTriggers = triggers.length;
SatisfiableTrigger[] builtTriggers = new SatisfiableTrigger[numTriggers];
for (int i = 0; i < numTriggers; i++) {
Trigger trigger = triggers[i];
builtTriggers[i] = trigger instanceof TriggerBuilder ? ((TriggerBuilder) trigger).build(namespace, applicationName, applicationVersion) : (SatisfiableTrigger) trigger;
}
return builtTriggers;
}
use of co.cask.cdap.api.schedule.Trigger in project cdap by caskdata.
the class TriggerCodecTest method testSerDeserYieldsTrigger.
private void testSerDeserYieldsTrigger(ProtoTrigger proto, Trigger trigger) {
String jsonOfTrigger = GSON.toJson(trigger);
String jsonOfTriggerAsTrigger = GSON.toJson(trigger, Trigger.class);
String jsonOfProto = GSON.toJson(proto);
String jsonOfProtoAsTrigger = GSON.toJson(proto, Trigger.class);
String jsonOfTriggerByProto = GSON_PROTO.toJson(trigger);
String jsonOfTriggerAsTriggerByProto = GSON_PROTO.toJson(trigger, Trigger.class);
String jsonOfProtoByProto = GSON_PROTO.toJson(proto);
String jsonOfProtoAsTriggerByProto = GSON_PROTO.toJson(proto, Trigger.class);
Assert.assertEquals(jsonOfTrigger, jsonOfTriggerAsTrigger);
Assert.assertEquals(jsonOfTrigger, jsonOfProto);
Assert.assertEquals(jsonOfTrigger, jsonOfProtoAsTrigger);
Assert.assertEquals(jsonOfTrigger, jsonOfTriggerByProto);
Assert.assertEquals(jsonOfTrigger, jsonOfTriggerAsTriggerByProto);
Assert.assertEquals(jsonOfTrigger, jsonOfProtoByProto);
Assert.assertEquals(jsonOfTrigger, jsonOfProtoAsTriggerByProto);
Trigger deserialized = GSON.fromJson(jsonOfTrigger, Trigger.class);
Trigger deserializedAsProto = GSON_PROTO.fromJson(jsonOfTrigger, Trigger.class);
Assert.assertEquals(trigger, deserialized);
Assert.assertEquals(proto, deserializedAsProto);
}
Aggregations