Search in sources :

Example 26 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class RemoveVmPoolCommand method getExclusiveLocks.

@Override
protected Map<String, Pair<String, String>> getExclusiveLocks() {
    Map<String, Pair<String, String>> locks = new HashMap<>();
    locks.put(getVmPoolId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.VM_POOL, new LockMessage(EngineMessage.ACTION_TYPE_FAILED_VM_POOL_IS_BEING_REMOVED).withOptional("VmPoolName", getVmPool() != null ? getVmPool().getName() : null)));
    for (VM vm : getCachedVmsInPool()) {
        addVmLocks(vm, locks);
    }
    return locks;
}
Also used : HashMap(java.util.HashMap) VM(org.ovirt.engine.core.common.businessentities.VM) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 27 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class RemoveVmPoolCommand method createRemoveVmStepContext.

private CommandContext createRemoveVmStepContext(VM vm) {
    CommandContext commandCtx = null;
    try {
        Map<String, String> values = Collections.singletonMap(VdcObjectType.VM.name().toLowerCase(), vm.getName());
        Step removeVmStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), StepEnum.REMOVING_VM, ExecutionMessageDirector.resolveStepMessage(StepEnum.REMOVING_VM, values));
        ExecutionContext ctx = new ExecutionContext();
        ctx.setStep(removeVmStep);
        ctx.setMonitored(true);
        Map<String, Pair<String, String>> locks = new HashMap<>();
        addVmLocks(vm, locks);
        EngineLock engineLock = new EngineLock(locks, null);
        commandCtx = cloneContext().withoutCompensationContext().withExecutionContext(ctx).withLock(engineLock);
    } catch (RuntimeException e) {
        log.error("Failed to create command context of removing VM '{}' that was in Pool '{}': {}", vm.getName(), getVmPoolName(), e.getMessage());
        log.debug("Exception", e);
    }
    return commandCtx;
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) HashMap(java.util.HashMap) Step(org.ovirt.engine.core.common.job.Step) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 28 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class RemoveVmTemplateCommand method acquireBaseTemplateSuccessorLock.

/**
 * To prevent concurrent deletion.
 * @return first: true ~ successfully locked, false otherwise; second: fail reasons in form suitable for
 *         validationMessages
 */
private boolean acquireBaseTemplateSuccessorLock() {
    final Map<String, Pair<String, String>> lockSharedMap = Collections.singletonMap(baseTemplateSuccessor.getId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.TEMPLATE, createSubTemplateLockMessage(baseTemplateSuccessor)));
    baseTemplateSuccessorLock = new EngineLock(null, lockSharedMap);
    final Pair<Boolean, Set<String>> isLockedAndFailReason = lockManager.acquireLock(baseTemplateSuccessorLock);
    if (isLockedAndFailReason.getFirst()) {
        return true;
    }
    baseTemplateSuccessorLock = null;
    getReturnValue().getValidationMessages().addAll(extractVariableDeclarations(isLockedAndFailReason.getSecond()));
    return false;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 29 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class RefreshHostCapabilitiesCommand method getExclusiveLocks.

@Override
protected Map<String, Pair<String, String>> getExclusiveLocks() {
    Guid hostId = getParameters().getVdsId();
    Map<String, Pair<String, String>> exclusiveLocks = new HashMap<>();
    exclusiveLocks.put(hostId.toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.VDS, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
    exclusiveLocks.putAll(hostLocking.getSetupNetworksLock(hostId));
    return exclusiveLocks;
}
Also used : HashMap(java.util.HashMap) Guid(org.ovirt.engine.core.compat.Guid) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 30 with Pair

use of org.ovirt.engine.core.common.utils.Pair in project ovirt-engine by oVirt.

the class RemoveSnapshotSingleDiskLiveCommand method buildReduceImageCommand.

private Pair<ActionType, ReduceImageCommandParameters> buildReduceImageCommand() {
    ReduceImageCommandParameters parameters = new ReduceImageCommandParameters(getStoragePool().getSpmVdsId(), getVdsId(), getDiskImage().getStoragePoolId(), getDiskImage().getStorageIds().get(0), getActiveDiskImage().getId(), getDiskImage().getImageId(), getActiveDiskImage(), true);
    parameters.setParentCommand(ActionType.RemoveSnapshotSingleDiskLive);
    parameters.setParentParameters(getParameters());
    return new Pair<>(ActionType.ReduceImage, parameters);
}
Also used : ReduceImageCommandParameters(org.ovirt.engine.core.common.action.ReduceImageCommandParameters) Pair(org.ovirt.engine.core.common.utils.Pair)

Aggregations

Pair (org.ovirt.engine.core.common.utils.Pair)147 ArrayList (java.util.ArrayList)61 Guid (org.ovirt.engine.core.compat.Guid)61 HashMap (java.util.HashMap)30 VDS (org.ovirt.engine.core.common.businessentities.VDS)26 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)25 Test (org.junit.Test)24 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)19 List (java.util.List)16 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)16 Map (java.util.Map)13 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)13 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)12 VM (org.ovirt.engine.core.common.businessentities.VM)12 HashSet (java.util.HashSet)10 VmInit (org.ovirt.engine.core.common.businessentities.VmInit)10 VmInitNetwork (org.ovirt.engine.core.common.businessentities.VmInitNetwork)10 EngineException (org.ovirt.engine.core.common.errors.EngineException)9 Callable (java.util.concurrent.Callable)8 VmDevice (org.ovirt.engine.core.common.businessentities.VmDevice)8