public static void main(String[] args) throws Exception { AmazonSimpleWorkflow service = new AmazonSimpleWorkflowClient(); service.setEndpoint("https://swf.us-east-1.amazonaws.com"); String domain = "helloWorldWalkthrough"; String taskListToPoll = "HelloWorldAsyncList"; WorkflowWorker wfw = new WorkflowWorker(service, domain, taskListToPoll); wfw.setRegisterDomain(true); wfw.setDomainRetentionPeriodInDays(1); wfw.addWorkflowImplementationType(GreeterWorkflowImpl.class); wfw.start(); ActivityWorker aw = new ActivityWorker(service, domain, taskListToPoll); aw.addActivitiesImplementation(new GreeterActivitiesImpl()); aw.start(); GreeterWorkflowClientExternalFactory clientFactory = new GreeterWorkflowClientExternalFactoryImpl(service, domain); GreeterWorkflowClientExternal client = clientFactory.getClient(); client.greet(); }
@Test public void multiplePages(@Mocked AmazonSimpleWorkflow swf) { PollForDecisionTaskRequest initialRequest = new PollForDecisionTaskRequest(); List<HistoryEvent> events = loadHistoryEvents("fixtures/simple_workflow.json"); int numberOfPages = 4; int sizePerPage = (int) Math.ceil( (double) events.size() / numberOfPages); List<List<HistoryEvent>> pages = Lists.partition(events, sizePerPage); assertThat("partitioned incorrectly", pages, hasSize(numberOfPages)); DecisionTask initialDecisionTask = new DecisionTask().withTaskToken("xyz") .withNextPageToken("1").withEvents(pages.get(0)); DecisionTaskIterator decisionTaskIterator = new DecisionTaskIterator(swf, initialRequest, initialDecisionTask); new Expectations() {{ swf.pollForDecisionTask(initialRequest);times=(numberOfPages-1); returns(new DecisionTask().withTaskToken("abc").withNextPageToken("2").withEvents(pages.get(1)), new DecisionTask().withTaskToken("def").withNextPageToken("3").withEvents(pages.get(2)), new DecisionTask().withTaskToken("ghi").withEvents(pages.get(3))); }}; assertThat(Lists.newArrayList(decisionTaskIterator), is(events)); }
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 { 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)); }
@Autowired public DataMungServiceImpl( AmazonSimpleWorkflow swfService, ServiceConfig config ) { instanceWorkflowFactory = new ExportInstanceWorkflowClientExternalFactoryImpl( swfService, config.getSwfDomainName() ); snapshotWorkflowFactory = new ExportSnapshotWorkflowClientExternalFactoryImpl( swfService, config.getSwfDomainName() ); this.swfService = swfService; this.swfDomain = config.getSwfDomainName(); }
public DecisionTaskIterator(AmazonSimpleWorkflow swf, PollForDecisionTaskRequest request, DecisionTask startingResponse) { this.swf = swf; this.request = request; this.nextPageToken = startingResponse.getNextPageToken(); this.currentPage = Optional.ofNullable(startingResponse.getEvents()) .map(List::iterator).orElse( Collections.emptyIterator()); this.isLastPage = this.nextPageToken == null; }
@Value.Default public AmazonSimpleWorkflow swf() { //SWF holds the connection for 60 seconds to see if a decision is available final Duration DEFAULT_CONNECTION_TIMEOUT = Duration.ofSeconds(60); final Duration DEFAULT_SOCKET_TIMEOUT = DEFAULT_CONNECTION_TIMEOUT.plusSeconds(10); return new AmazonSimpleWorkflowClient(new DefaultAWSCredentialsProviderChain(), new ClientConfiguration().withConnectionTimeout((int) DEFAULT_CONNECTION_TIMEOUT.toMillis()) .withSocketTimeout((int) DEFAULT_SOCKET_TIMEOUT.toMillis())); }
/** * Create a new SWF client given the current configuration. * * @return an AmazonSimpleWorkflow client */ AmazonSimpleWorkflow createSWFClient() { AWSCredentials credentials = new DefaultAWSCredentialsProviderChain().getCredentials(); AmazonSimpleWorkflow service = new AmazonSimpleWorkflowClient(credentials, new ClientConfiguration().withSocketTimeout(SOCKET_TIMEOUT)); service.setEndpoint(swfServiceUrl); return service; }
/** * @throws IOException */ public static void main(String[] args) throws IOException { //get task token and result from user String taskToken = getTaskToken(); String result = getResult(); //complete the activity task AmazonSimpleWorkflow swfService = createSWFClient(); ManualActivityCompletionClientFactory manualCompletionClientFactory = new ManualActivityCompletionClientFactoryImpl( swfService); ManualActivityCompletionClient manualCompletionClient = manualCompletionClientFactory.getClient(taskToken); manualCompletionClient.complete(result); }
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); }
static AmazonSimpleWorkflow createSWFClient() { AWSCredentials awsCredentials = new BasicAWSCredentials("{swfAccessId}", "{swfSecretKey}"); AmazonSimpleWorkflow client = new AmazonSimpleWorkflowClient(awsCredentials); client.setEndpoint("{swfServiceUrl}"); return client; }
public AmazonSimpleWorkflow createSWFClient() { AWSCredentials awsCredentials = new BasicAWSCredentials(this.swfAccessId, this.swfSecretKey); AmazonSimpleWorkflow client = new AmazonSimpleWorkflowClient(awsCredentials); client.setEndpoint(this.swfServiceUrl); return client; }
public abstract AmazonSimpleWorkflow service();
public abstract AmazonSimpleWorkflow swf();