Search in sources :

Example 1 with TriggerInfo

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());
}
Also used : DefaultPartitionTriggerInfo(co.cask.cdap.internal.app.runtime.schedule.trigger.DefaultPartitionTriggerInfo) WebCrawlApp(co.cask.cdap.WebCrawlApp) DefaultTimeTriggerInfo(co.cask.cdap.internal.app.runtime.schedule.trigger.DefaultTimeTriggerInfo) DefaultPartitionTriggerInfo(co.cask.cdap.internal.app.runtime.schedule.trigger.DefaultPartitionTriggerInfo) DefaultProgramStatusTriggerInfo(co.cask.cdap.internal.app.runtime.schedule.trigger.DefaultProgramStatusTriggerInfo) TriggerInfo(co.cask.cdap.api.schedule.TriggerInfo) DefaultTimeTriggerInfo(co.cask.cdap.internal.app.runtime.schedule.trigger.DefaultTimeTriggerInfo) TriggeringScheduleInfo(co.cask.cdap.api.schedule.TriggeringScheduleInfo) BasicWorkflowToken(co.cask.cdap.internal.app.runtime.workflow.BasicWorkflowToken) DefaultProgramStatusTriggerInfo(co.cask.cdap.internal.app.runtime.schedule.trigger.DefaultProgramStatusTriggerInfo) Test(org.junit.Test)

Example 2 with TriggerInfo

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);
}
Also used : Function(com.google.common.base.Function) TriggerInfo(co.cask.cdap.api.schedule.TriggerInfo) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 3 with TriggerInfo

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();
}
Also used : TriggerInfo(co.cask.cdap.api.schedule.TriggerInfo) Notification(co.cask.cdap.proto.Notification)

Example 4 with TriggerInfo

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;
}
Also used : ProgramStatusTriggerInfo(co.cask.cdap.api.schedule.ProgramStatusTriggerInfo) HashMap(java.util.HashMap) TriggerInfo(co.cask.cdap.api.schedule.TriggerInfo) ProgramStatusTriggerInfo(co.cask.cdap.api.schedule.ProgramStatusTriggerInfo) ArrayList(java.util.ArrayList) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with TriggerInfo

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());
}
Also used : SatisfiableTrigger(co.cask.cdap.internal.app.runtime.schedule.trigger.SatisfiableTrigger) TriggerInfo(co.cask.cdap.api.schedule.TriggerInfo) TriggerInfoContext(co.cask.cdap.internal.app.runtime.schedule.trigger.TriggerInfoContext)

Aggregations

TriggerInfo (co.cask.cdap.api.schedule.TriggerInfo)7 ProgramStatusTriggerInfo (co.cask.cdap.api.schedule.ProgramStatusTriggerInfo)2 TriggeringScheduleInfo (co.cask.cdap.api.schedule.TriggeringScheduleInfo)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 WebCrawlApp (co.cask.cdap.WebCrawlApp)1 ArtifactSummary (co.cask.cdap.api.artifact.ArtifactSummary)1 AlreadyExistsException (co.cask.cdap.common.AlreadyExistsException)1 ConflictException (co.cask.cdap.common.ConflictException)1 NotFoundException (co.cask.cdap.common.NotFoundException)1 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1 Id (co.cask.cdap.common.id.Id)1 BasicArguments (co.cask.cdap.etl.common.BasicArguments)1 ArgumentMapping (co.cask.cdap.etl.proto.v2.ArgumentMapping)1 PluginPropertyMapping (co.cask.cdap.etl.proto.v2.PluginPropertyMapping)1 Job (co.cask.cdap.internal.app.runtime.schedule.queue.Job)1 DefaultPartitionTriggerInfo (co.cask.cdap.internal.app.runtime.schedule.trigger.DefaultPartitionTriggerInfo)1 DefaultProgramStatusTriggerInfo (co.cask.cdap.internal.app.runtime.schedule.trigger.DefaultProgramStatusTriggerInfo)1