Search in sources :

Example 6 with CommandEntity

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

the class CoCoAsyncTaskHelper method shouldRemoveCommand.

private boolean shouldRemoveCommand(AsyncTask asyncTask) {
    if (asyncTask == null || Guid.isNullOrEmpty(asyncTask.getCommandId())) {
        return false;
    }
    CommandEntity cmdEntity = coco.get().getCommandEntity(asyncTask.getCommandId());
    CommandEntity parentEntity = null;
    if (cmdEntity != null) {
        parentEntity = coco.get().getCommandEntity(cmdEntity.getParentCommandId());
    }
    return cmdEntity != null && !cmdEntity.isCallbackEnabled() && (parentEntity == null || !parentEntity.isCallbackEnabled());
}
Also used : CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity)

Example 7 with CommandEntity

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

the class CoCoEventSubscriber method processEvent.

/**
 * Processes the event of the current subscription by invoking the {@code CommandCallback.onEvent} of the associated
 * command. After the event is processed, the callback can be terminated from the {@code CommandCallback.onEvent} or
 * continue to the rest of command's callback execution.
 *
 * @param eventData
 *            the requested data for the event processing
 */
private void processEvent(Map<String, Object> eventData) {
    Guid cmdId = commandEntity.getId();
    CallbackTiming callbackTiming = commandsRepository.getCallbackTiming(cmdId);
    if (callbackTiming == null) {
        return;
    }
    try {
        // TODO there is a race condition between processing the callback here and by the polling, in case of an
        // event which has arrived during its timeout treatment by CommandCallbacksPoller.
        // Once Bug 1334926 is implemented, this code will be changed to mark the callback to be processed, and
        // the actual processing will be done by the CommandCallbacksPoller which will be the responsible to invoke
        // the CommandCallback.onEvent() on thread from a dedicated thread pool
        callbackTiming.getCallback().onEvent(cmdId, commandsRepository.getChildCommandIds(cmdId), eventData);
    } finally {
        subscription.cancel();
        commandsRepository.removeEventSubscription(cmdId);
        CommandEntity commandEntityFromCache = commandsRepository.getCommandEntity(cmdId);
        if (commandEntityFromCache != null) {
            commandEntityFromCache.setWaitingForEvent(false);
        }
    }
}
Also used : CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity) Guid(org.ovirt.engine.core.compat.Guid)

Example 8 with CommandEntity

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

the class CommandExecutor method updateCommandResult.

private void updateCommandResult(final Guid commandId, final ActionReturnValue result) {
    CommandEntity cmdEntity = commandsRepository.getCommandEntity(commandId);
    cmdEntity.setReturnValue(result);
    if (!result.isValid()) {
        cmdEntity.setCommandStatus(CommandStatus.FAILED);
    }
    commandsRepository.persistCommand(cmdEntity);
}
Also used : CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity)

Example 9 with CommandEntity

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

the class CommandsCacheImpl method updateCommandStatus.

@Override
public void updateCommandStatus(Guid commandId, CommandStatus status) {
    final CommandEntity cmdEntity = get(commandId);
    if (cmdEntity != null) {
        cmdEntity.setCommandStatus(status);
        saveOrUpdateWithoutTransaction(cmdEntity);
    }
}
Also used : CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity)

Example 10 with CommandEntity

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

the class CommandsCacheImpl method updateCommandData.

@Override
public void updateCommandData(Guid commandId, Map<String, Serializable> data) {
    final CommandEntity cmdEntity = get(commandId);
    if (cmdEntity != null) {
        cmdEntity.setData(data);
        saveOrUpdateWithoutTransaction(cmdEntity);
    }
}
Also used : CommandEntity(org.ovirt.engine.core.common.businessentities.CommandEntity)

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