use of co.cask.cdap.api.schedule.ProgramStatusTriggerInfo 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.ProgramStatusTriggerInfo in project cdap by caskdata.
the class AppWithMultipleSchedules method addTokens.
private static void addTokens(List<ProgramStatusTriggerInfo> programStatusTriggerInfos, Map<String, String> runtimeArgs, String triggeringKeyNodePair, String key) {
for (ProgramStatusTriggerInfo triggerInfo : programStatusTriggerInfos) {
WorkflowToken token = triggerInfo.getWorkflowToken();
if (token == null) {
continue;
}
String[] keyNode = triggeringKeyNodePair.split(":");
Value value = token.get(keyNode[0], keyNode[1]);
if (value == null) {
continue;
}
runtimeArgs.put(key, value.toString());
}
}
use of co.cask.cdap.api.schedule.ProgramStatusTriggerInfo in project cdap by caskdata.
the class SmartWorkflow method updateTokenWithTriggeringProperties.
private void updateTokenWithTriggeringProperties(TriggeringScheduleInfo scheduleInfo, TriggeringPropertyMapping propertiesMapping, WorkflowToken token) {
List<ProgramStatusTriggerInfo> programStatusTriggerInfos = new ArrayList<>();
for (TriggerInfo info : scheduleInfo.getTriggerInfos()) {
if (info instanceof ProgramStatusTriggerInfo) {
programStatusTriggerInfos.add((ProgramStatusTriggerInfo) info);
}
}
// If no ProgramStatusTriggerInfo, no need of override the existing runtimeArgs
if (programStatusTriggerInfos.isEmpty()) {
return;
}
// Currently only expecting one trigger in a schedule
ProgramStatusTriggerInfo triggerInfo = programStatusTriggerInfos.get(0);
BasicArguments triggeringArguments = new BasicArguments(triggerInfo.getWorkflowToken(), triggerInfo.getRuntimeArguments());
// Get the value of every triggering pipeline arguments specified in the propertiesMapping and update newRuntimeArgs
List<ArgumentMapping> argumentMappings = propertiesMapping.getArguments();
for (ArgumentMapping mapping : argumentMappings) {
String sourceKey = mapping.getSource();
if (sourceKey == null) {
LOG.warn("The name of argument from the triggering pipeline cannot be null, " + "skip this argument mapping: '{}'.", mapping);
continue;
}
String value = triggeringArguments.get(sourceKey);
if (value == null) {
LOG.warn("Runtime argument '{}' is not found in run '{}' of the triggering pipeline '{}' " + "in namespace '{}' ", sourceKey, triggerInfo.getRunId(), triggerInfo.getApplicationSpecification().getName(), triggerInfo.getNamespace());
continue;
}
// Use the argument name in the triggering pipeline if target is not specified
String targetKey = mapping.getTarget() == null ? sourceKey : mapping.getTarget();
token.put(targetKey, value);
}
// Get the resolved plugin properties map from triggering pipeline's workflow token in triggeringArguments
Map<String, Map<String, String>> resolvedProperties = GSON.fromJson(triggeringArguments.get(RESOLVED_PLUGIN_PROPERTIES_MAP), STAGE_PROPERTIES_MAP);
for (PluginPropertyMapping mapping : propertiesMapping.getPluginProperties()) {
String stageName = mapping.getStageName();
if (stageName == null) {
LOG.warn("The name of the stage cannot be null in plugin property mapping, skip this mapping: '{}'.", mapping);
continue;
}
Map<String, String> pluginProperties = resolvedProperties.get(stageName);
if (pluginProperties == null) {
LOG.warn("No plugin properties can be found with stage name '{}' in triggering pipeline '{}' " + "in namespace '{}' ", mapping.getStageName(), triggerInfo.getApplicationSpecification().getName(), triggerInfo.getNamespace());
continue;
}
String sourceKey = mapping.getSource();
if (sourceKey == null) {
LOG.warn("The name of argument from the triggering pipeline cannot be null, " + "skip this argument mapping: '{}'.", mapping);
continue;
}
String value = pluginProperties.get(sourceKey);
if (value == null) {
LOG.warn("No property with name '{}' can be found in plugin '{}' of the triggering pipeline '{}' " + "in namespace '{}' ", sourceKey, stageName, triggerInfo.getApplicationSpecification().getName(), triggerInfo.getNamespace());
continue;
}
// Use the argument name in the triggering pipeline if target is not specified
String targetKey = mapping.getTarget() == null ? sourceKey : mapping.getTarget();
token.put(targetKey, value);
}
return;
}
Aggregations