gpt4 book ai didi

co.cask.cdap.api.workflow.WorkflowToken.put()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-26 17:09:05 32 4
gpt4 key购买 nike

本文整理了Java中co.cask.cdap.api.workflow.WorkflowToken.put()方法的一些代码示例,展示了WorkflowToken.put()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WorkflowToken.put()方法的具体详情如下:
包路径:co.cask.cdap.api.workflow.WorkflowToken
类名称:WorkflowToken
方法名:put

WorkflowToken.put介绍

[英]Put the specified key and Value into the WorkflowToken. The token may store additional information about the context in which this key is being set. For example, the context information stored by the token may be the workflow node that is performing the operation, or the name of the workflow if the operation is performed in AbstractWorkflow#initializeor AbstractWorkflow#destroy method.
[中]将指定的键和值放入WorkflowToken。令牌可以存储关于设置该密钥的上下文的附加信息。例如,令牌存储的上下文信息可能是正在执行操作的工作流节点,或者如果在AbstractWorkflow#initializeor AbstractWorkflow#destroy method中执行操作,则可能是工作流的名称。

代码示例

代码示例来源:origin: co.cask.cdap/hydrator-spark-core2

private void updateWorkflowToken(WorkflowToken token, Map<String, StageStatisticsCollector> collectors) {
  for (Map.Entry<String, StageStatisticsCollector> entry : collectors.entrySet()) {
   SparkStageStatisticsCollector collector = (SparkStageStatisticsCollector) entry.getValue();
   String keyPrefix = Constants.StageStatistics.PREFIX + "." + entry.getKey() + ".";

   String inputRecordKey = keyPrefix + Constants.StageStatistics.INPUT_RECORDS;
   token.put(inputRecordKey, String.valueOf(collector.getInputRecordCount()));

   String outputRecordKey = keyPrefix + Constants.StageStatistics.OUTPUT_RECORDS;
   token.put(outputRecordKey, String.valueOf(collector.getOutputRecordCount()));

   String errorRecordKey = keyPrefix + Constants.StageStatistics.ERROR_RECORDS;
   token.put(errorRecordKey, String.valueOf(collector.getErrorRecordCount()));
  }
 }
}

代码示例来源:origin: cdapio/cdap

@Override
@SuppressWarnings("ConstantConditions")
public void initialize() throws Exception {
 WorkflowToken token = getContext().getWorkflowToken();
 Preconditions.checkArgument(token != null, "Workflow actions should always have a workflow token available");
 token.put(TOKEN_KEY, TOKEN_VALUE);
}

代码示例来源:origin: cdapio/cdap

@Override
 public boolean apply(@Nullable WorkflowContext input) {
  input.getToken().put("simple.condition.initialize", "true");
  if (input.getRuntimeArguments().containsKey("simple.condition")) {
   return true;
  }
  return false;
 }
}

代码示例来源:origin: cdapio/cdap

@Override
 public boolean apply(@Nullable WorkflowContext input) {
  input.getToken().put("configurable.condition.apply", "true");
  if (input.getRuntimeArguments().containsKey("configurable.condition")) {
   return true;
  }
  return false;
 }
}

代码示例来源:origin: cdapio/cdap

@Override
 public void initialize(WorkflowContext context) throws Exception {
  super.initialize(context);
  context.getToken().put(ANOTHER_TOKEN_KEY, ANOTHER_TOKEN_VALUE);
 }
}

代码示例来源:origin: cdapio/cdap

@Override
public void initialize() throws Exception {
 WorkflowToken token = getContext().getWorkflowToken();
 token.put("running", Value.of(true));
 token.put("finished", Value.of(false));
}

代码示例来源:origin: cdapio/cdap

@Override
 public void destroy() {
  WorkflowToken token = getContext().getWorkflowToken();
  token.put("running", Value.of(false));
  token.put("finished", Value.of(true));
 }
}

代码示例来源:origin: cdapio/cdap

@Override
public void initialize() throws Exception {
 WorkflowToken workflowToken = getContext().getWorkflowToken();
 workflowToken.put(TOKEN_KEY, TOKEN_VALUE);
}

代码示例来源:origin: cdapio/cdap

@Override
public void initialize(WorkflowContext context) throws Exception {
 super.initialize(context);
 context.getToken().put(SampleWorkflow.INITIALIZE_TOKEN_KEY, SampleWorkflow.INITIALIZE_TOKEN_VALUE);
}

代码示例来源:origin: cdapio/cdap

@Override
public void destroy() {
 WorkflowToken token = getContext().getToken();
 @SuppressWarnings("ConstantConditions")
 String initializeValue = token.get(SampleWorkflow.INITIALIZE_TOKEN_KEY, SampleWorkflow.NAME).toString();
 if (!initializeValue.equals(SampleWorkflow.INITIALIZE_TOKEN_VALUE)) {
  // Should not happen, since we are always putting token in the Workflow.initialize method.
  // We can not throw exception here since any exception thrown will be caught in the Workflow driver.
  // So in order to test this put some token value which is check in the test case.
  token.put(SampleWorkflow.DESTROY_TOKEN_KEY, SampleWorkflow.DESTROY_TOKEN_FAIL_VALUE);
 } else {
  token.put(SampleWorkflow.DESTROY_TOKEN_KEY, SampleWorkflow.DESTROY_TOKEN_SUCCESS_VALUE);
 }
}

代码示例来源:origin: cdapio/cdap

@Override
 public void initialize() throws Exception {
  MapReduceContext context = getContext();
  Map<String, String> args = context.getRuntimeArguments();
  String inputPath = args.get("inputPath");
  String outputPath = args.get("outputPath");
  WordCount.configureJob((Job) context.getHadoopJob(), inputPath, outputPath);
  WorkflowToken workflowToken = context.getWorkflowToken();
  if (workflowToken == null) {
   return;
  }
  // Put something in the token
  workflowToken.put("action_type", "MapReduce");
  workflowToken.put("start_time", Value.of(System.currentTimeMillis()));
 }
}

代码示例来源:origin: cdapio/cdap

@Override
 public void initialize() throws Exception {
  MapReduceContext context = getContext();
  Job job = context.getHadoopJob();
  job.setMapperClass(MyVerifier.class);
  String inputPath = context.getRuntimeArguments().get("inputPath");
  String outputPath = context.getRuntimeArguments().get("outputPath");
  FileInputFormat.addInputPath(job, new Path(inputPath));
  FileOutputFormat.setOutputPath(job, new Path(outputPath));
  // Put something in the token
  WorkflowToken workflowToken = context.getWorkflowToken();
  if (workflowToken == null) {
   return;
  }
  workflowToken.put("action.type", "MapReduce");
  workflowToken.put("start.time", Value.of(System.currentTimeMillis()));
 }
}

代码示例来源:origin: cdapio/cdap

@Override
 public void initialize(WorkflowContext context) throws Exception {
  super.initialize(context);
  TriggeringScheduleInfo scheduleInfo = context.getTriggeringScheduleInfo();
  if (scheduleInfo != null) {
   // Get values of the runtime args and workflow token from the triggering program
   // whose keys are defined as keys in TRIGGERING_PROPERTIES_MAPPING with a special syntax and use their values
   // for the corresponding workflow tokens as defined in TRIGGERING_PROPERTIES_MAPPING values
   String propertiesMappingString =
    scheduleInfo.getProperties().get(TRIGGERING_PROPERTIES_MAPPING);
   if (propertiesMappingString != null) {
    Map<String, String> propertiesMap = GSON.fromJson(propertiesMappingString, STRING_STRING_MAP);
    Map<String, String> newTokenMap =
     getNewTokensFromScheduleInfo(scheduleInfo, propertiesMap);
    for (Map.Entry<String, String> entry : newTokenMap.entrySet()) {
     // Write the workflow token into context
     context.getToken().put(entry.getKey(), entry.getValue());
    }
   }
  }
 }
}

代码示例来源:origin: cdapio/cdap

@Override
 public void initialize() throws Exception {
  MapReduceContext context = getContext();
  Map<String, String> args = context.getRuntimeArguments();
  String inputPath = args.get("inputPath");
  String outputPath = args.get("outputPath");
  WordCount.configureJob((Job) context.getHadoopJob(), inputPath, outputPath);
  WorkflowToken workflowToken = context.getWorkflowToken();
  if (workflowToken == null) {
   return;
  }
  // Put something in the token
  workflowToken.put("action.type", "MapReduce");
  workflowToken.put("start.time", Value.of(System.currentTimeMillis()));
  Preconditions.checkNotNull(workflowToken.get("start.time", "RecordVerifier"));
 }
}

代码示例来源:origin: cdapio/cdap

@Override
public void destroy() {
 super.destroy();
 getContext().getToken().put("configurable.condition.destroy", "true");
}

代码示例来源:origin: cdapio/cdap

@Override
public void initialize(WorkflowContext context) throws Exception {
 super.initialize(context);
 getContext().getToken().put("configurable.condition.initialize", "true");
}

代码示例来源:origin: cdapio/cdap

@Override
 public boolean apply(@Nullable WorkflowContext input) {
  if (input != null) {
   input.getToken().put("action.type", "Condition");
   List<NodeValue> goodRecords = input.getToken().getAll("MyCustomCounter.GoodRecord", WorkflowToken.Scope.SYSTEM);
   List<NodeValue> badRecords = input.getToken().getAll("MyCustomCounter.BadRecord", WorkflowToken.Scope.SYSTEM);
   // If number of good records are greater than the number of bad records then only
   // return true to execute the true branch associated with this Condition node
   if (goodRecords.get(0).getValue().getAsLong() > badRecords.get(0).getValue().getAsLong()) {
    input.getToken().put("conditionResult", "true");
    return true;
   }
   input.getToken().put("conditionResult", "false");
  }
  return false;
 }
}

代码示例来源:origin: cdapio/cdap

@Override
 public void run() {
  String actionName = getContext().getSpecification().getName();
  LOG.info("Running SimpleAction: {}", actionName);
  WorkflowToken token = getContext().getWorkflowToken();
  // Put something in the token
  token.put("action.type", "CustomAction");
  try {
   File file = new File(getContext().getRuntimeArguments().get(actionName + ".simple.action.file"));
   Preconditions.checkState(file.createNewFile());
   File doneFile = new File(getContext().getRuntimeArguments().get(actionName + ".simple.action.donefile"));
   while (!doneFile.exists()) {
    TimeUnit.MILLISECONDS.sleep(50);
   }
  } catch (Exception e) {
   // no-op
  }
 }
}

代码示例来源:origin: co.cask.cdap/cdap-etl-batch

@Override
 public void run() throws Exception {
  CustomActionContext context = getContext();
  Map<String, String> properties = context.getSpecification().getProperties();
  BatchPhaseSpec phaseSpec = GSON.fromJson(properties.get(Constants.PIPELINEID), BatchPhaseSpec.class);
  PipelinePhase phase = phaseSpec.getPhase();
  StageSpec stageSpec = phase.iterator().next();
  PluginContext pluginContext = new PipelinePluginContext(context, metrics,
                              phaseSpec.isStageLoggingEnabled(),
                              phaseSpec.isProcessTimingEnabled());
  PipelineRuntime pipelineRuntime = new PipelineRuntime(context, metrics);
  Action action =
   pluginContext.newPluginInstance(stageSpec.getName(),
                   new DefaultMacroEvaluator(pipelineRuntime.getArguments(),
                                context.getLogicalStartTime(),
                                context,
                                context.getNamespace()));
  ActionContext actionContext = new BasicActionContext(context, pipelineRuntime, stageSpec);
  if (!context.getDataTracer(stageSpec.getName()).isEnabled()) {
   action.run(actionContext);
  }
  WorkflowToken token = context.getWorkflowToken();
  if (token == null) {
   throw new IllegalStateException("WorkflowToken cannot be null when action is executed through Workflow.");
  }
  for (Map.Entry<String, String> entry : pipelineRuntime.getArguments().getAddedArguments().entrySet()) {
   token.put(entry.getKey(), entry.getValue());
  }
 }
}

代码示例来源:origin: cdapio/cdap

@Override
 public void run() throws Exception {
  WorkflowToken token = getContext().getWorkflowToken();
  token.put("action.name", getContext().getSpecification().getName());
 }
}

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com