Search in sources :

Example 1 with CompensationTriggerStateImpl

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

the class ProcessCtrlStateMachineEngine method compensateInternal.

public StateMachineInstance compensateInternal(String stateMachineInstId, Map<String, Object> replaceParams, boolean async, AsyncCallback callback) throws EngineExecutionException {
    StateMachineInstance stateMachineInstance = reloadStateMachineInstance(stateMachineInstId);
    if (stateMachineInstance == null) {
        throw new EngineExecutionException("StateMachineInstance is not exits", FrameworkErrorCode.StateMachineInstanceNotExists);
    }
    if (ExecutionStatus.SU.equals(stateMachineInstance.getCompensationStatus())) {
        return stateMachineInstance;
    }
    if (stateMachineInstance.getCompensationStatus() != null) {
        ExecutionStatus[] denyStatus = new ExecutionStatus[] { ExecutionStatus.SU };
        checkStatus(stateMachineInstance, null, denyStatus, null, stateMachineInstance.getCompensationStatus(), "compensate");
    }
    if (replaceParams != null) {
        stateMachineInstance.getEndParams().putAll(replaceParams);
    }
    ProcessContextBuilder contextBuilder = ProcessContextBuilder.create().withProcessType(ProcessType.STATE_LANG).withOperationName(DomainConstants.OPERATION_NAME_COMPENSATE).withAsyncCallback(callback).withStateMachineInstance(stateMachineInstance).withStateMachineConfig(getStateMachineConfig()).withStateMachineEngine(this);
    contextBuilder.withIsAsyncExecution(async);
    ProcessContext context = contextBuilder.build();
    Map<String, Object> contextVariables = getStateMachineContextVariables(stateMachineInstance);
    if (replaceParams != null) {
        contextVariables.putAll(replaceParams);
    }
    putBusinesskeyToContextariables(stateMachineInstance, contextVariables);
    ConcurrentHashMap<String, Object> concurrentContextVariables = new ConcurrentHashMap<>(contextVariables.size());
    nullSafeCopy(contextVariables, concurrentContextVariables);
    context.setVariable(DomainConstants.VAR_NAME_STATEMACHINE_CONTEXT, concurrentContextVariables);
    stateMachineInstance.setContext(concurrentContextVariables);
    CompensationTriggerStateImpl tempCompensationTriggerState = new CompensationTriggerStateImpl();
    tempCompensationTriggerState.setStateMachine(stateMachineInstance.getStateMachine());
    stateMachineInstance.setRunning(true);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("Operation [compensate] start.  stateMachineInstance[id:" + stateMachineInstance.getId() + "]");
    }
    if (stateMachineInstance.getStateMachine().isPersist()) {
        stateMachineConfig.getStateLogStore().recordStateMachineRestarted(stateMachineInstance, context);
    }
    try {
        StateInstruction inst = new StateInstruction();
        inst.setTenantId(stateMachineInstance.getTenantId());
        inst.setStateMachineName(stateMachineInstance.getStateMachine().getName());
        inst.setTemporaryState(tempCompensationTriggerState);
        context.setInstruction(inst);
        if (async) {
            stateMachineConfig.getAsyncProcessCtrlEventPublisher().publish(context);
        } else {
            stateMachineConfig.getProcessCtrlEventPublisher().publish(context);
        }
    } catch (EngineExecutionException e) {
        LOGGER.error("Operation [compensate] failed", e);
        throw e;
    }
    return stateMachineInstance;
}
Also used : CompensationTriggerStateImpl(io.seata.saga.statelang.domain.impl.CompensationTriggerStateImpl) StateInstruction(io.seata.saga.engine.pcext.StateInstruction) EngineExecutionException(io.seata.saga.engine.exception.EngineExecutionException) ProcessContext(io.seata.saga.proctrl.ProcessContext) StateMachineInstance(io.seata.saga.statelang.domain.StateMachineInstance) ProcessContextBuilder(io.seata.saga.engine.utils.ProcessContextBuilder) ExecutionStatus(io.seata.saga.statelang.domain.ExecutionStatus) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with CompensationTriggerStateImpl

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

the class CompensationTriggerStateParser method parse.

@Override
public CompensationTriggerState parse(Object node) {
    CompensationTriggerStateImpl compensationTriggerState = new CompensationTriggerStateImpl();
    parseBaseAttributes(compensationTriggerState, node);
    return compensationTriggerState;
}
Also used : CompensationTriggerStateImpl(io.seata.saga.statelang.domain.impl.CompensationTriggerStateImpl)

Aggregations

CompensationTriggerStateImpl (io.seata.saga.statelang.domain.impl.CompensationTriggerStateImpl)2 EngineExecutionException (io.seata.saga.engine.exception.EngineExecutionException)1 StateInstruction (io.seata.saga.engine.pcext.StateInstruction)1 ProcessContextBuilder (io.seata.saga.engine.utils.ProcessContextBuilder)1 ProcessContext (io.seata.saga.proctrl.ProcessContext)1 ExecutionStatus (io.seata.saga.statelang.domain.ExecutionStatus)1 StateMachineInstance (io.seata.saga.statelang.domain.StateMachineInstance)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1