Search in sources :

Example 1 with StateMachineInstanceImpl

use of io.seata.saga.statelang.domain.impl.StateMachineInstanceImpl in project seata by seata.

the class ProcessCtrlStateMachineEngine method createMachineInstance.

private StateMachineInstance createMachineInstance(String stateMachineName, String tenantId, String businessKey, Map<String, Object> startParams) {
    StateMachine stateMachine = stateMachineConfig.getStateMachineRepository().getStateMachine(stateMachineName, tenantId);
    if (stateMachine == null) {
        throw new EngineExecutionException("StateMachine[" + stateMachineName + "] is not exists", FrameworkErrorCode.ObjectNotExists);
    }
    StateMachineInstanceImpl inst = new StateMachineInstanceImpl();
    inst.setStateMachine(stateMachine);
    inst.setMachineId(stateMachine.getId());
    inst.setTenantId(tenantId);
    inst.setBusinessKey(businessKey);
    inst.setStartParams(startParams);
    if (startParams != null) {
        if (StringUtils.hasText(businessKey)) {
            startParams.put(DomainConstants.VAR_NAME_BUSINESSKEY, businessKey);
        }
        String parentId = (String) startParams.get(DomainConstants.VAR_NAME_PARENT_ID);
        if (StringUtils.hasText(parentId)) {
            inst.setParentId(parentId);
            startParams.remove(DomainConstants.VAR_NAME_PARENT_ID);
        }
    }
    inst.setStatus(ExecutionStatus.RU);
    inst.setRunning(true);
    inst.setGmtStarted(new Date());
    inst.setGmtUpdated(inst.getGmtStarted());
    return inst;
}
Also used : StateMachine(io.seata.saga.statelang.domain.StateMachine) StateMachineInstanceImpl(io.seata.saga.statelang.domain.impl.StateMachineInstanceImpl) EngineExecutionException(io.seata.saga.engine.exception.EngineExecutionException) Date(java.util.Date)

Aggregations

EngineExecutionException (io.seata.saga.engine.exception.EngineExecutionException)1 StateMachine (io.seata.saga.statelang.domain.StateMachine)1 StateMachineInstanceImpl (io.seata.saga.statelang.domain.impl.StateMachineInstanceImpl)1 Date (java.util.Date)1