Search in sources :

Example 1 with CommandStatus

use of org.ovirt.engine.core.compat.CommandStatus in project ovirt-engine by oVirt.

the class CommandBase method handleCommandExecutionEnded.

private boolean handleCommandExecutionEnded() {
    boolean shouldEndAction = parentHasCallback() ? isEndProcedureApplicableToEndAction() : true;
    CommandStatus newStatus = isEndSuccessfully() ? CommandStatus.SUCCEEDED : CommandStatus.FAILED;
    if (getCallback() == null) {
        setCommandStatus(newStatus);
        if (!shouldEndAction) {
            logEndWillBeExecutedByParent(newStatus);
        }
    }
    return shouldEndAction;
}
Also used : CommandStatus(org.ovirt.engine.core.compat.CommandStatus)

Example 2 with CommandStatus

use of org.ovirt.engine.core.compat.CommandStatus in project ovirt-engine by oVirt.

the class ChildCommandsCallbackBase method setCommandEndStatus.

protected void setCommandEndStatus(CommandBase<?> command, boolean childCommandFailed, CommandExecutionStatus status, List<Guid> childCmdIds) {
    command.getParameters().setTaskGroupSuccess(!childCommandFailed && status == CommandExecutionStatus.EXECUTED);
    CommandStatus newStatus = command.getParameters().getTaskGroupSuccess() ? CommandStatus.SUCCEEDED : CommandStatus.FAILED;
    log.info("Command '{}' id: '{}' child commands '{}' executions were completed, status '{}'", command.getActionType(), command.getCommandId(), childCmdIds, newStatus);
    if (!shouldExecuteEndMethod(command)) {
        logEndWillBeExecutedByParent(command, newStatus);
    }
    command.setCommandStatus(newStatus, false);
    command.persistCommand(command.getParameters().getParentCommand(), command.getCallback() != null);
}
Also used : CommandStatus(org.ovirt.engine.core.compat.CommandStatus)

Example 3 with CommandStatus

use of org.ovirt.engine.core.compat.CommandStatus in project ovirt-engine by oVirt.

the class CommandCallbacksPoller method invokeCallbackMethodsImpl.

private void invokeCallbackMethodsImpl() {
    Iterator<Entry<Guid, CallbackTiming>> iterator = commandsRepository.getCallbacksTiming().entrySet().iterator();
    while (iterator.hasNext()) {
        Entry<Guid, CallbackTiming> entry = iterator.next();
        Guid cmdId = entry.getKey();
        CallbackTiming callbackTiming = entry.getValue();
        CommandEntity commandEntity = commandsRepository.getCommandEntity(cmdId);
        CorrelationIdTracker.setCorrelationId(commandEntity != null ? commandEntity.getCommandParameters().getCorrelationId() : null);
        if (commandEntity != null && updateCommandWaitingForEvent(commandEntity, callbackTiming)) {
            continue;
        }
        // Decrement counter; execute if it reaches 0
        callbackTiming.setRemainingDelay(callbackTiming.getRemainingDelay() - pollingRate);
        if (callbackTiming.getRemainingDelay() > 0) {
            continue;
        }
        CommandCallback callback = callbackTiming.getCallback();
        CommandStatus status = commandsRepository.getCommandStatus(cmdId);
        boolean runCallbackAgain = false;
        boolean errorInCallback = false;
        try {
            switch(status) {
                case FAILED:
                case SUCCEEDED:
                    runCallbackAgain = endCallback(cmdId, callback, status);
                    break;
                case ACTIVE:
                    if (commandEntity != null && commandEntity.isExecuted()) {
                        callback.doPolling(cmdId, getChildCommandIds(cmdId));
                    }
                    break;
                case EXECUTION_FAILED:
                    if (callback.pollOnExecutionFailed()) {
                        callback.doPolling(cmdId, getChildCommandIds(cmdId));
                    }
                    break;
                default:
                    break;
            }
        } catch (Exception ex) {
            errorInCallback = true;
            handleError(ex, status, cmdId);
        } finally {
            if ((CommandStatus.FAILED == status || (CommandStatus.SUCCEEDED == status && !errorInCallback)) && !runCallbackAgain) {
                commandsRepository.updateCallbackNotified(cmdId);
                iterator.remove();
                CommandEntity cmdEntity = commandsRepository.getCommandEntity(entry.getKey());
                if (cmdEntity != null) {
                    // When a child finishes, its parent's callback should execute shortly thereafter
                    CallbackTiming rootCmdContainer = commandsRepository.getCallbackTiming(cmdEntity.getRootCommandId());
                    if (rootCmdContainer != null) {
                        rootCmdContainer.setInitialDelay(pollingRate);
                        rootCmdContainer.setRemainingDelay(pollingRate);
                    }
                }
            } else if (status != commandsRepository.getCommandStatus(cmdId)) {
                callbackTiming.setInitialDelay(pollingRate);
                callbackTiming.setRemainingDelay(pollingRate);
            } else {
                long maxDelay = Config.<Long>getValue(ConfigValues.AsyncCommandPollingRateInSeconds);
                callbackTiming.setInitialDelay(Math.min(maxDelay, callbackTiming.getInitialDelay() * 2));
                callbackTiming.setRemainingDelay(callbackTiming.getInitialDelay());
            }
        }
    }
    CorrelationIdTracker.setCorrelationId(null);
    commandsRepository.markExpiredCommandsAsFailure();
}
Also used : Entry(java.util.Map.Entry) CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity) CommandStatus(org.ovirt.engine.core.compat.CommandStatus) Guid(org.ovirt.engine.core.compat.Guid) CommandCallback(org.ovirt.engine.core.bll.tasks.interfaces.CommandCallback)

Aggregations

CommandStatus (org.ovirt.engine.core.compat.CommandStatus)3 Entry (java.util.Map.Entry)1 CommandCallback (org.ovirt.engine.core.bll.tasks.interfaces.CommandCallback)1 CommandEntity (org.ovirt.engine.core.common.businessentities.CommandEntity)1 Guid (org.ovirt.engine.core.compat.Guid)1