use of co.cask.cdap.api.schedule.TriggerInfo in project cdap by caskdata.
the class TriggeringScheduleInfoAdapterTest method testSerDeserScheduleInfo.
@Test
public void testSerDeserScheduleInfo() {
BasicWorkflowToken token = new BasicWorkflowToken(1);
token.setCurrentNode("node");
token.put("tokenKey", "tokenVal");
List<TriggerInfo> triggerInfos = ImmutableList.<TriggerInfo>of(new DefaultProgramStatusTriggerInfo("ns", Specifications.from(new WebCrawlApp()), ProgramType.WORKFLOW, "workflow", RunIds.generate(), ProgramStatus.COMPLETED, token, Collections.<String, String>emptyMap()), new DefaultPartitionTriggerInfo("ns", "ds", 10, 11), new DefaultTimeTriggerInfo("1 * * * *", 0L));
TriggeringScheduleInfo scheduleInfo = new DefaultTriggeringScheduleInfo("schedule", "description", triggerInfos, ImmutableMap.of("key", "value"));
String scheduleInfoJson = GSON.toJson(scheduleInfo);
TriggeringScheduleInfo deserializedScheduleInfo = GSON.fromJson(scheduleInfoJson, TriggeringScheduleInfo.class);
Assert.assertEquals(scheduleInfoJson, GSON.toJson(deserializedScheduleInfo));
DefaultProgramStatusTriggerInfo expectedProgramStatusTriggerInfo = (DefaultProgramStatusTriggerInfo) triggerInfos.get(0);
DefaultProgramStatusTriggerInfo deserializedProgramStatusTriggerInfo = (DefaultProgramStatusTriggerInfo) deserializedScheduleInfo.getTriggerInfos().get(0);
Assert.assertEquals(expectedProgramStatusTriggerInfo.getApplicationSpecification().getName(), deserializedProgramStatusTriggerInfo.getApplicationSpecification().getName());
Assert.assertEquals(expectedProgramStatusTriggerInfo.getWorkflowToken().getAll(), deserializedProgramStatusTriggerInfo.getWorkflowToken().getAll());
}
use of co.cask.cdap.api.schedule.TriggerInfo in project cdap by caskdata.
the class ProgramStatusTrigger method getTriggerInfos.
@Override
public List<TriggerInfo> getTriggerInfos(final TriggerInfoContext context) {
Function<ProgramRunInfo, List<TriggerInfo>> function = new Function<ProgramRunInfo, List<TriggerInfo>>() {
@Override
public List<TriggerInfo> apply(ProgramRunInfo runInfo) {
Map<String, String> runtimeArgs = context.getProgramRuntimeArguments(runInfo.getProgramRunId());
TriggerInfo triggerInfo = new DefaultProgramStatusTriggerInfo(programId.getNamespace(), context.getApplicationSpecification(programId.getParent()), ProgramType.valueOf(programId.getType().name()), programId.getProgram(), RunIds.fromString(runInfo.getProgramRunId().getRun()), runInfo.getProgramStatus(), context.getWorkflowToken(runInfo.getProgramRunId()), runtimeArgs);
return Collections.singletonList(triggerInfo);
}
};
return getTriggerSatisfiedResult(context.getNotifications(), ImmutableList.<TriggerInfo>of(), function);
}
use of co.cask.cdap.api.schedule.TriggerInfo in project cdap by caskdata.
the class TimeTrigger method getTriggerInfos.
@Override
public List<TriggerInfo> getTriggerInfos(TriggerInfoContext context) {
for (Notification notification : context.getNotifications()) {
if (!isSatisfied(context.getSchedule(), notification)) {
continue;
}
Long logicalStartTime = getLogicalStartTime(notification);
if (logicalStartTime == null) {
LOG.warn("The notification '{}' in the job of schedule '{}' does not contain logical start time", notification, context.getSchedule());
continue;
}
TriggerInfo triggerInfo = new DefaultTimeTriggerInfo(getCronExpression(), logicalStartTime);
return Collections.singletonList(triggerInfo);
}
return Collections.emptyList();
}
use of co.cask.cdap.api.schedule.TriggerInfo in project cdap by caskdata.
the class AppWithMultipleSchedules method getNewTokensFromScheduleInfo.
private static Map<String, String> getNewTokensFromScheduleInfo(TriggeringScheduleInfo scheduleInfo, Map<String, String> propertiesMap) {
List<TriggerInfo> triggerInfoList = scheduleInfo.getTriggerInfos();
List<ProgramStatusTriggerInfo> programStatusTriggerInfos = new ArrayList<>();
for (TriggerInfo info : triggerInfoList) {
if (info instanceof ProgramStatusTriggerInfo) {
programStatusTriggerInfos.add((ProgramStatusTriggerInfo) info);
}
}
Map<String, String> newRuntimeArgs = new HashMap<>();
// If no ProgramStatusTriggerInfo, no need of override the existing runtimeArgs
if (programStatusTriggerInfos.size() == 0) {
return newRuntimeArgs;
}
// token#<user-token-key>:<node-name>
for (Map.Entry<String, String> entry : propertiesMap.entrySet()) {
String triggeringPropertyName = entry.getKey();
String[] propertyParts = triggeringPropertyName.split("#");
if ("runtime-arg".equals(propertyParts[0])) {
addRuntimeArgs(programStatusTriggerInfos, newRuntimeArgs, propertyParts[1], entry.getValue());
} else if ("token".equals(propertyParts[0])) {
addTokens(programStatusTriggerInfos, newRuntimeArgs, propertyParts[1], entry.getValue());
}
}
return newRuntimeArgs;
}
use of co.cask.cdap.api.schedule.TriggerInfo in project cdap by caskdata.
the class ScheduleTaskRunner method getTriggeringScheduleInfo.
private TriggeringScheduleInfo getTriggeringScheduleInfo(Job job) {
TriggerInfoContext triggerInfoContext = new TriggerInfoContext(job, store);
SatisfiableTrigger trigger = ((SatisfiableTrigger) job.getSchedule().getTrigger());
List<TriggerInfo> triggerInfo = trigger.getTriggerInfos(triggerInfoContext);
ProgramSchedule schedule = job.getSchedule();
return new DefaultTriggeringScheduleInfo(schedule.getName(), schedule.getDescription(), triggerInfo, schedule.getProperties());
}
Aggregations