com.fivefaces.cloud.workflow.awsonprem.impl.StateMachineRepoImpl Maven / Gradle / Ivy
package com.fivefaces.cloud.workflow.awsonprem.impl;
import com.amazonaws.services.stepfunctions.builder.StateMachine;
import com.fivefaces.cloud.Utils;
import com.fivefaces.cloud.workflow.awsonprem.StateMachineRepo;
import com.fivefaces.common.exception.ItemNotFoundException;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
@Service
@RequiredArgsConstructor
public class StateMachineRepoImpl implements StateMachineRepo {
private static final Map MACHINES = new HashMap<>();
private final Utils utils;
@Override
public StateMachine findByName(String functionName) {
if (functionName.contains("_")) {
functionName = functionName.substring(functionName.indexOf("_") + 1);
}
String machineDefinitions;
String machineDefinition;
if (MACHINES.containsKey(functionName)) {
machineDefinition = MACHINES.get(functionName);
} else {
machineDefinitions = utils.getOnPremiseFunctions();
machineDefinition = utils.parseOnPremiseFunction(machineDefinitions, functionName);
MACHINES.put(functionName, machineDefinition);
}
if (StringUtils.isNotBlank(machineDefinition)) {
return StateMachine.fromJson(machineDefinition).build();
}
throw new ItemNotFoundException(functionName + " is not defined");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy