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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations