com.fivefaces.cloud.workflow.AWSWorkflowService Maven / Gradle / Ivy
package com.fivefaces.cloud.workflow;
import com.amazonaws.services.stepfunctions.AWSStepFunctions;
import com.amazonaws.services.stepfunctions.model.*;
import com.fivefaces.cloud.Utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;
@Profile("WORKFLOW_AWS")
@Slf4j
@Service
public class AWSWorkflowService implements WorkflowService {
private final Utils utils;
private AWSStepFunctions stepFunctionsClient;
public AWSWorkflowService(Utils utils, ProcessFactory processFactory) {
this.utils = utils;
}
@Override
public WorkflowExecutionResult instantiateWorkflow(final String functionName, final String jsonInput) {
final String stateMachineArn = utils.getWorkflowArn(functionName);
StartExecutionRequest request = new StartExecutionRequest()
.withStateMachineArn(stateMachineArn)
.withInput(jsonInput);
StartExecutionResult result = getStepFunctionsClient().startExecution(request);
return new WorkflowExecutionResult(result.getExecutionArn(), "PENDING", null, null);
}
@Override
public WorkflowExecutionResult instantiateSyncWorkflow(final String functionName, final String jsonInput) {
final String stateMachineArn = utils.getWorkflowArn(functionName);
StartSyncExecutionRequest request = new StartSyncExecutionRequest()
.withStateMachineArn(stateMachineArn)
.withInput(jsonInput);
StartSyncExecutionResult result = getStepFunctionsClient().startSyncExecution(request);
return new WorkflowExecutionResult(result.getExecutionArn(), result.getStatus(), result.getOutput(), null);
}
@Override
public DescribeExecutionResult getExecutionResult(final String executionArn) {
DescribeExecutionRequest request = new DescribeExecutionRequest()
.withExecutionArn(executionArn);
return getStepFunctionsClient().describeExecution(request);
}
private AWSStepFunctions getStepFunctionsClient() {
if (stepFunctionsClient == null) {
stepFunctionsClient = utils.generateStepFunctionClient();
}
return stepFunctionsClient;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy