Search in sources :

Example 21 with CommandEntity

use of org.ovirt.engine.core.common.businessentities.CommandEntity in project ovirt-engine by oVirt.

the class ChildCommandsCallbackBase method shouldWaitForEndMethodsCompletion.

private boolean shouldWaitForEndMethodsCompletion(CommandBase<?> childCommand, CommandBase<?> parentCommand) {
    CommandEntity cmdEntity = commandCoordinatorUtil.getCommandEntity(childCommand.getCommandId());
    boolean hasNotifiedCallback = cmdEntity.isCallbackEnabled() && cmdEntity.isCallbackNotified();
    if (shouldCommandEndOnAsyncOpEnd(childCommand) && !hasNotifiedCallback) {
        logWaitingForChildCommand(childCommand, parentCommand);
        return true;
    }
    return false;
}
Also used : CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity)

Example 22 with CommandEntity

use of org.ovirt.engine.core.common.businessentities.CommandEntity 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)

Example 23 with CommandEntity

use of org.ovirt.engine.core.common.businessentities.CommandEntity in project ovirt-engine by oVirt.

the class CommandsCacheImpl method updateCommandExecuted.

@Override
public void updateCommandExecuted(final Guid commandId) {
    CommandEntity cmdEntity = get(commandId);
    if (cmdEntity != null) {
        cmdEntity.setExecuted(true);
        commandEntityDao.updateExecuted(commandId);
    }
}
Also used : CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity)

Example 24 with CommandEntity

use of org.ovirt.engine.core.common.businessentities.CommandEntity in project ovirt-engine by oVirt.

the class CommandsRepository method persistCommand.

public void persistCommand(CommandEntity cmdEntity) {
    if (Guid.isNullOrEmpty(cmdEntity.getId())) {
        return;
    }
    CommandEntity existingCmdEntity = commandsCache.get(cmdEntity.getId());
    if (existingCmdEntity != null) {
        cmdEntity.setExecuted(existingCmdEntity.isExecuted());
        cmdEntity.setCallbackNotified(existingCmdEntity.isCallbackNotified());
    }
    commandsCache.put(cmdEntity);
    // check if callback is enabled or if parent command has callback enabled
    if (cmdEntity.isCallbackEnabled() || (!Guid.isNullOrEmpty(cmdEntity.getParentCommandId()) && commandsCache.get(cmdEntity.getParentCommandId()) != null && commandsCache.get(cmdEntity.getParentCommandId()).isCallbackEnabled())) {
        buildCmdHierarchy(cmdEntity);
        if (!cmdEntity.isCallbackNotified()) {
            addToCallbackMap(cmdEntity);
        }
    }
}
Also used : CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity)

Example 25 with CommandEntity

use of org.ovirt.engine.core.common.businessentities.CommandEntity in project ovirt-engine by oVirt.

the class CommandsRepository method getCommands.

/**
 * @param onlyWithCallbackEnabled Specifies if the returned commands' callbacks are enabled or not.
 * @return Returns commands with callback enabled or disabled, based on given parameter
 */
public List<CommandEntity> getCommands(boolean onlyWithCallbackEnabled) {
    List<CommandEntity> cmdEntities = new ArrayList<>();
    CommandEntity cmdEntity;
    for (Guid cmdId : commandsCache.keySet()) {
        cmdEntity = commandsCache.get(cmdId);
        if (!onlyWithCallbackEnabled || commandsCache.get(cmdId).isCallbackEnabled()) {
            cmdEntities.add(cmdEntity);
        }
    }
    return cmdEntities;
}
Also used : ArrayList(java.util.ArrayList) CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

CommandEntity (org.ovirt.engine.core.common.businessentities.CommandEntity)25 Guid (org.ovirt.engine.core.compat.Guid)7 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Transaction (javax.transaction.Transaction)2 ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)2 CommandAssociatedEntity (org.ovirt.engine.core.common.businessentities.CommandAssociatedEntity)2 Serializable (java.io.Serializable)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 CommandCallback (org.ovirt.engine.core.bll.tasks.interfaces.CommandCallback)1 HostJobCommandParameters (org.ovirt.engine.core.common.action.HostJobCommandParameters)1 AsyncTask (org.ovirt.engine.core.common.businessentities.AsyncTask)1 HostJobInfo (org.ovirt.engine.core.common.businessentities.HostJobInfo)1 HostJobStatus (org.ovirt.engine.core.common.businessentities.HostJobInfo.HostJobStatus)1 VDS (org.ovirt.engine.core.common.businessentities.VDS)1 CommandStatus (org.ovirt.engine.core.compat.CommandStatus)1