public static void main(String[] args) throws Exception { // Load configuration Config config = Config.createConfig(); // FileProcessingWorkflowClientExternalFactory is auto-generated through flow framework FileProcessingWorkflowClientExternalFactory clientFactory = new FileProcessingWorkflowClientExternalFactoryImpl(config.createSWFClient(), config.getSwfDomain()); FileProcessingWorkflowClientExternal workflow = clientFactory.getClient(); // Start workflow execution workflow.processFile( config.getWorkflowInputBucketName(), config.getWorkflowInputFileName(), config.getWorkflowOutputBucketName(), config.getWorkflowOutputFileName()); WorkflowExecution workflowExecution = workflow.getWorkflowExecution(); LOG.info("Started periodic workflow with workflowId=\"" + workflowExecution.getWorkflowId() + "\" and runId=\"" + workflowExecution.getRunId() + "\""); System.exit(0); }
public static void main(String[] args) throws Exception { // Load configuration ConfigHelper configHelper = ConfigHelper.createConfig(); // Create the client for Simple Workflow Service swfService = configHelper.createSWFClient(); domain = configHelper.getDomain(); // Start Workflow execution String bucketName = configHelper.getValueFromConfig(SplitMergeConfigKeys.S3_BUCKET_NAME); String fileName = configHelper.getValueFromConfig(SplitMergeConfigKeys.S3_INPUT_FILENAME); String val = configHelper.getValueFromConfig(SplitMergeConfigKeys.NUMBER_OF_WORKERS); int numberOfWorkers = Integer.parseInt(val); AverageCalculatorWorkflowClientExternalFactory clientFactory = new AverageCalculatorWorkflowClientExternalFactoryImpl(swfService, domain); AverageCalculatorWorkflowClientExternal workflow = clientFactory.getClient(); workflow.average(bucketName, fileName, numberOfWorkers); // WorkflowExecution is available after workflow creation WorkflowExecution workflowExecution = workflow.getWorkflowExecution(); System.out.println("Started periodic workflow with workflowId=\"" + workflowExecution.getWorkflowId() + "\" and runId=\"" + workflowExecution.getRunId() + "\""); System.exit(0); }
public static void main(String[] args) throws Exception { ConfigHelper configHelper = ConfigHelper.createConfig(); AmazonSimpleWorkflow swfService = configHelper.createSWFClient(); String domain = configHelper.getDomain(); HelloWorldWorkflowClientExternalFactory clientFactory = new HelloWorldWorkflowClientExternalFactoryImpl(swfService, domain); HelloWorldWorkflowClientExternal workflow = clientFactory.getClient(); // Start Wrokflow Execution workflow.helloWorld("User"); // WorkflowExecution is available after workflow creation WorkflowExecution workflowExecution = workflow.getWorkflowExecution(); System.out.println("Started helloWorld workflow with workflowId=\"" + workflowExecution.getWorkflowId() + "\" and runId=\"" + workflowExecution.getRunId() + "\""); }
public static void main(String[] args) throws Exception { // Load configuration ConfigHelper configHelper = ConfigHelper.createConfig(); // Create the client for Simple Workflow Service swfService = configHelper.createSWFClient(); domain = configHelper.getDomain(); // Start Workflow instance String sourceBucketName = configHelper.getValueFromConfig(FileProcessingConfigKeys.WORKFLOW_INPUT_SOURCEBUCKETNAME_KEY); String sourceFilename = configHelper.getValueFromConfig(FileProcessingConfigKeys.WORKFLOW_INPUT_SOURCEFILENAME_KEY); String targetBucketName = configHelper.getValueFromConfig(FileProcessingConfigKeys.WORKFLOW_INPUT_TARGETBUCKETNAME_KEY); String targetFilename = configHelper.getValueFromConfig(FileProcessingConfigKeys.WORKFLOW_INPUT_TARGETFILENAME_KEY); FileProcessingWorkflowClientExternalFactory clientFactory = new FileProcessingWorkflowClientExternalFactoryImpl(swfService, domain); FileProcessingWorkflowClientExternal workflow = clientFactory.getClient(); workflow.processFile(sourceBucketName, sourceFilename, targetBucketName, targetFilename); // WorkflowExecution is available after workflow creation WorkflowExecution workflowExecution = workflow.getWorkflowExecution(); System.out.println("Started periodic workflow with workflowId=\"" + workflowExecution.getWorkflowId() + "\" and runId=\"" + workflowExecution.getRunId() + "\""); System.exit(0); }
public static void main(String[] args) throws Exception { if (args.length < 2) { System.err.println("Usage: java " + WorkflowExecutionGetState.class.getName() + " <workflowId> <runId>"); System.exit(1); } ConfigHelper configHelper = ConfigHelper.createConfig(); AmazonSimpleWorkflow swfService = configHelper.createSWFClient(); String domain = configHelper.getDomain(); WorkflowExecution workflowExecution = new WorkflowExecution(); String workflowId = args[1]; workflowExecution.setWorkflowId(workflowId); String runId = args[2]; workflowExecution.setRunId(runId); GenericWorkflowClientExternal client = new GenericWorkflowClientExternalImpl(swfService, domain); String state = client.getWorkflowState(workflowExecution); System.out.println("Current state of " + workflowExecution + ":"); System.out.println(state); }
public static void main(String[] args) throws Exception { if (args.length < 2) { System.err.println("Usage: java " + WorkflowExecutionHistoryPrinter.class.getName() + " <workflowId> <runId>"); System.exit(1); } ConfigHelper configHelper = ConfigHelper.createConfig(); AmazonSimpleWorkflow swfService = configHelper.createSWFClient(); String domain = configHelper.getDomain(); WorkflowExecution workflowExecution = new WorkflowExecution(); String workflowId = args[0]; workflowExecution.setWorkflowId(workflowId); String runId = args[1]; workflowExecution.setRunId(runId); System.out.println(WorkflowExecutionUtils.prettyPrintHistory(swfService, domain, workflowExecution, true)); }
/** * @inheritDoc */ @Override public WorkflowDetail getWorkflow( String workflowId, String runId ) { WorkflowExecution exec = new WorkflowExecution().withWorkflowId( workflowId ).withRunId( runId ); WorkflowExecutionDetail detail = swfService.describeWorkflowExecution( new DescribeWorkflowExecutionRequest().withDomain( swfDomain ).withExecution( exec ) ); Workflow workflow = createWorkflow( detail.getExecutionInfo(), detail.getExecutionInfo().getExecutionStatus().equalsIgnoreCase( "CLOSED" ) ); WorkflowDetail result = new WorkflowDetail(); result.setWorkflow( workflow ); Map<String, WorkflowActivity> activityMap = new HashMap<String, WorkflowActivity>(); traverseHistory( exec, activityMap ); List<WorkflowActivity> history = new ArrayList<WorkflowActivity>( activityMap.values() ); Collections.sort( history, Collections.reverseOrder( new ActivityComparator() ) ); result.setHistory( history ); return result; }
public WorkflowExecution submit(Workflow workflow, WorkflowId workflowId, Optional<Object> input) { log.info(format("submit workflow: %s", workflowId)); Optional<Input> inputOptional = input.map( i -> dataConverter().toData(i)).map(Input::of); StartWorkflowExecutionRequest request = WorkflowExecutionRequestBuilder.builder().domain(domain()) .workflow(workflow).input(inputOptional) .taskList(taskList()).workflowId(workflowId).build(); log.info(format("Start workflow execution: %s", workflowId)); Run run = swf().startWorkflowExecution(request); log.info(format("Started workflow %s", run)); return new WorkflowExecution().withWorkflowId(workflowId.value()).withRunId(run.getRunId()); }
public Map<String, Object> describeWorkflowInstance(String workflowId, String runId) { DescribeWorkflowExecutionRequest describeRequest = new DescribeWorkflowExecutionRequest(); describeRequest.setDomain(configuration.getDomainName()); describeRequest.setExecution(new WorkflowExecution().withWorkflowId(workflowId).withRunId(runId)); WorkflowExecutionDetail executionDetail = endpoint.getSWClient().describeWorkflowExecution(describeRequest); WorkflowExecutionInfo instanceMetadata = executionDetail.getExecutionInfo(); Map<String, Object> info = new HashMap<String, Object>(); info.put("closeStatus", instanceMetadata.getCloseStatus()); info.put("closeTimestamp", instanceMetadata.getCloseTimestamp()); info.put("executionStatus", instanceMetadata.getExecutionStatus()); info.put("tagList", instanceMetadata.getTagList()); info.put("executionDetail", executionDetail); return info; }
DynamicWorkflowClientExternal getDynamicWorkflowClient(String workflowId, String runId) { GenericWorkflowClientExternalImpl genericClient = new GenericWorkflowClientExternalImpl(endpoint.getSWClient(), configuration.getDomainName()); WorkflowExecution workflowExecution = new WorkflowExecution(); workflowExecution.setWorkflowId(workflowId != null ? workflowId : genericClient.generateUniqueId()); workflowExecution.setRunId(runId); return new DynamicWorkflowClientExternalImpl(workflowExecution, null, endpoint.getStartWorkflowOptions(), configuration.getDataConverter(), genericClient); }
@Test public void testDescribeWorkflowInstance() throws Exception { WorkflowExecutionInfo executionInfo = new WorkflowExecutionInfo(); executionInfo.setCloseStatus("COMPLETED"); Date closeTimestamp = new Date(); executionInfo.setCloseTimestamp(closeTimestamp); executionInfo.setExecutionStatus("CLOSED"); executionInfo.setTagList(Collections.EMPTY_LIST); WorkflowExecutionDetail workflowExecutionDetail = new WorkflowExecutionDetail(); workflowExecutionDetail.setExecutionInfo(executionInfo); when(swClient.describeWorkflowExecution(any(DescribeWorkflowExecutionRequest.class))).thenReturn(workflowExecutionDetail); Map<String, Object> description = camelSWFWorkflowClient.describeWorkflowInstance("123", "run1"); DescribeWorkflowExecutionRequest describeRequest = new DescribeWorkflowExecutionRequest(); describeRequest.setDomain(configuration.getDomainName()); describeRequest.setExecution(new WorkflowExecution().withWorkflowId("123").withRunId("run1")); verify(swClient).describeWorkflowExecution(describeRequest); assertThat((String) description.get("closeStatus"), is("COMPLETED")); assertThat((Date) description.get("closeTimestamp"), is(closeTimestamp)); assertThat((String) description.get("executionStatus"), is("CLOSED")); assertThat((List) description.get("tagList"), is(Collections.EMPTY_LIST)); assertThat((WorkflowExecutionDetail) description.get("executionDetail"), is(workflowExecutionDetail)); }
@Test public void testStartWorkflowExecution() throws Throwable { WorkflowExecution workflowExecution = new WorkflowExecution(); workflowExecution.setWorkflowId("123"); workflowExecution.setRunId("run1"); when(clientExternal.getWorkflowExecution()).thenReturn(workflowExecution); String[] ids = camelSWFWorkflowClient.startWorkflowExecution(null, null, "eventName", "version", null); verify(clientExternal).startWorkflowExecution(new Object[]{null}); assertThat("123", is(ids[0])); assertThat("run1", is(ids[1])); }
public static void main(String[] args) throws Exception { if (args.length < 3) { System.err.println("Usage: java " + WorkflowExecutionFlowThreadDumper.class.getName() + "<workflow implementation class> <workflowId> <runId>"); System.exit(1); } ConfigHelper configHelper = ConfigHelper.createConfig(); AmazonSimpleWorkflow swfService = configHelper.createSWFClient(); String domain = configHelper.getDomain(); WorkflowExecution workflowExecution = new WorkflowExecution(); String workflowId = args[1]; workflowExecution.setWorkflowId(workflowId); String runId = args[2]; workflowExecution.setRunId(runId); String implementationTypeName = args[0]; @SuppressWarnings("unchecked") Class<Object> workflowImplementationType = (Class<Object>) Class.forName(implementationTypeName); WorkflowReplayer<Object> replayer = new WorkflowReplayer<Object>(swfService, domain, workflowExecution, workflowImplementationType); System.out.println("Beginning workflow replay for " + workflowExecution); try { String flowThreadDump = replayer.getAsynchronousThreadDumpAsString(); System.out.println("Workflow asynchronous thread dump:"); System.out.println(flowThreadDump); } catch (WorkflowException e) { System.out.println("No asynchronous thread dump available as workflow has failed: " + e); } }
public static void main(String[] args) throws Exception { if (args.length < 3) { System.err.println("Usage: java " + WorkflowExecutionReplayer.class.getName() + "<workflow implementation class> <workflowId> <runId>"); System.exit(1); } ConfigHelper configHelper = ConfigHelper.createConfig(); AmazonSimpleWorkflow swfService = configHelper.createSWFClient(); String domain = configHelper.getDomain(); WorkflowExecution workflowExecution = new WorkflowExecution(); String workflowId = args[1]; workflowExecution.setWorkflowId(workflowId); String runId = args[2]; workflowExecution.setRunId(runId); String implementationTypeName = args[0]; @SuppressWarnings("unchecked") Class<Object> workflowImplementationType = (Class<Object>) Class.forName(implementationTypeName); WorkflowReplayer<Object> replayer = new WorkflowReplayer<Object>(swfService, domain, workflowExecution, workflowImplementationType); System.out.println("Beginning workflow replay for " + workflowExecution); Object workflow = replayer.loadWorkflow(); System.out.println("Workflow implementation object:"); System.out.println(workflow); System.out.println("Done workflow replay for " + workflowExecution); }
@Override public void doSomeWork(String parameter) { // Reset counter on the new run which changes when workflow continues as new ActivityExecutionContext activityExecutionContext = contextProvider.getActivityExecutionContext(); WorkflowExecution workflowExecution = activityExecutionContext.getWorkflowExecution(); String runId = workflowExecution.getRunId(); if (this.runId == null || !runId.equals(this.runId)) { runCount++; } this.runId = runId; workCount++; if (workCount % 2 != 0) { throw new RuntimeException("simulated failure to cause retry"); } }
@Override public void doSomeWork(String parameter) { // Reset counter on the new run which changes when workflow continues as new ActivityExecutionContext activityExecutionContext = contextProvider.getActivityExecutionContext(); WorkflowExecution workflowExecution = activityExecutionContext.getWorkflowExecution(); String runId = workflowExecution.getRunId(); if (this.runId == null || !runId.equals(this.runId)) { runCount++; } this.runId = runId; workCount++; }
@Override public void doSomeWork(String parameter) { // Reset counter on the new run which changes when workflow continues as new ActivityExecutionContext activityExecutionContext = contextProvider.getActivityExecutionContext(); WorkflowExecution workflowExecution = activityExecutionContext.getWorkflowExecution(); String runId = workflowExecution.getRunId(); if (this.runId != null && !runId.equals(this.runId)) { currentRunWorkCount = 0; } this.runId = runId; workCount++; currentRunWorkCount++; }
/** * @inheritDoc */ @Override public void notifyJobStarted() { WorkflowExecution exec = contextProvider.getActivityExecutionContext().getWorkflowExecution(); String ref = String.format( "swf:%s:%s:%s", contextProvider.getActivityExecutionContext().getDomain(), exec.getWorkflowId(), exec.getRunId() ); jobEventListener.onJobStarted( exec.getWorkflowId(), ref ); }
private static String getWorkflowExecutionResult(WorkflowExecution workflowExecution) { return WorkflowExecutionUtils.getWorkflowExecutionResult(config.swf(), config.domain().value(), workflowExecution).getResult(); }
public <I, O> WorkflowExecution submit(Workflow<I,O> workflow, I input) { WorkflowId workflowId = WorkflowId.randomUniqueWorkflowId(workflow); return submit(workflow, workflowId, Optional.ofNullable(input)); }
public List<HistoryEvent> getWorkflowExecutionHistory(String workflowId, String runId) { return WorkflowExecutionUtils.getHistory(endpoint.getSWClient(), configuration.getDomainName(), new WorkflowExecution().withWorkflowId(workflowId).withRunId(runId)); }
public static void main(String[] args) throws Exception { // Load configuration ConfigHelper configHelper = ConfigHelper.createConfig(); // Create the client for Simple Workflow Service swfService = configHelper.createSWFClient(); domain = configHelper.getDomain(); // Start Workflow execution PeriodicWorkflowClientExternalFactory clientFactory = new PeriodicWorkflowClientExternalFactoryImpl(swfService, domain); // Passing instance id to ensure that only one periodic workflow can be active at a time. // Use different id for each schedule. PeriodicWorkflowClientExternal workflow = clientFactory.getClient("periodic1"); // Execute activity every two 10 seconds, wait for it to complete before starting the new one, // create new run every 30 seconds and stop the workflow after two minutes. // Obviously these periods are so low to make example run fast enough to not be boring. // In production case there is no need to create new runs so frequently. PeriodicWorkflowOptions options = new PeriodicWorkflowOptions(); options.setExecutionPeriodSeconds(10); options.setContinueAsNewAfterSeconds(30); options.setCompleteAfterSeconds(120); options.setWaitForActivityCompletion(true); ActivityType activityType = new ActivityType(); activityType.setName("PeriodicWorkflowActivities.doSomeWork"); activityType.setVersion("1.0"); Object[] parameters = new Object[] { "parameter1" }; try { workflow.startPeriodicWorkflow(activityType, parameters, options); // WorkflowExecution is available after workflow creation WorkflowExecution workflowExecution = workflow.getWorkflowExecution(); System.out.println("Started periodic workflow with workflowId=\"" + workflowExecution.getWorkflowId() + "\" and runId=\"" + workflowExecution.getRunId() + "\""); } catch (WorkflowExecutionAlreadyStartedException e) { // It is expected to get this exception if start is called before workflow run is completed. System.out.println("Periodic workflow with workflowId=\"" + workflow.getWorkflowExecution().getWorkflowId() + " is already running"); } System.exit(0); }