use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class CommandBase method buildLock.
private EngineLock buildLock() {
EngineLock lock = null;
Map<String, Pair<String, String>> exclusiveLocks = getExclusiveLocks();
Map<String, Pair<String, String>> sharedLocks = getSharedLocks();
if (exclusiveLocks != null || sharedLocks != null) {
lock = new EngineLock(exclusiveLocks, sharedLocks);
}
return lock;
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class VdsEventListener method processStorageOnVdsInactive.
private void processStorageOnVdsInactive(final VDS vds) {
// anymore.
if (!Guid.Empty.equals(vds.getStoragePoolId())) {
// when vds is being moved to maintenance, this is the part in which we disconnect it from the pool
// and the storage server. it should be synced with the host autorecovery mechanism to try to avoid
// leaving the host with storage/pool connection when it's on maintenance.
EngineLock lock = new EngineLock(Collections.singletonMap(vds.getId().toString(), new Pair<>(LockingGroup.VDS_POOL_AND_STORAGE_CONNECTIONS.toString(), EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED.toString())), null);
try {
lockManager.acquireLockWait(lock);
clearDomainCache(vds);
StoragePool storage_pool = storagePoolDao.get(vds.getStoragePoolId());
if (StoragePoolStatus.Uninitialized != storage_pool.getStatus()) {
vdsBroker.runVdsCommand(VDSCommandType.DisconnectStoragePool, new DisconnectStoragePoolVDSCommandParameters(vds.getId(), vds.getStoragePoolId(), vds.getVdsSpmId()));
HostStoragePoolParametersBase params = new HostStoragePoolParametersBase(storage_pool, vds);
backend.runInternalAction(ActionType.DisconnectHostFromStoragePoolServers, params);
}
} finally {
lockManager.releaseLock(lock);
}
}
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class HostSetupNetworksCommand method executeCommand.
@Override
protected void executeCommand() {
if (noChangesDetected()) {
log.info("No changes were detected in setup networks for host '{}' (ID: '{}')", getVdsName(), getVdsId());
setSucceeded(true);
return;
}
try (EngineLock monitoringLock = acquireMonitorLock("Host setup networks")) {
int timeout = getSetupNetworksTimeout();
FutureVDSCall<VDSReturnValue> setupNetworksTask = invokeSetupNetworksCommand(timeout);
try {
VDSReturnValue retVal = setupNetworksTask.get(timeout, TimeUnit.SECONDS);
if (retVal != null) {
if (!retVal.getSucceeded() && retVal.getVdsError() == null && getParameters().rollbackOnFailure()) {
throw new EngineException(EngineError.SETUP_NETWORKS_ROLLBACK, retVal.getExceptionString());
}
VdsHandler.handleVdsResult(retVal);
if (retVal.getSucceeded()) {
VDSReturnValue returnValue = runVdsCommand(VDSCommandType.GetCapabilities, new VdsIdAndVdsVDSCommandParametersBase(getVds()));
VDS updatedHost = (VDS) returnValue.getReturnValue();
persistNetworkChanges(updatedHost);
}
setSucceeded(true);
}
} catch (TimeoutException e) {
log.debug("Host Setup networks command timed out for {} seconds", timeout);
}
}
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class AbstractDiskVmCommand method getDiskAddressMap.
/**
* Returns disk's address map by specified VmDevice and DiskInterface
* (note: for VirtIO_SCSI/SPAPR_VSCSI interfaces, the method updates the VM device's address accordingly).
* @return disk's address map
*/
public Map<String, String> getDiskAddressMap(VmDevice vmDevice, DiskInterface diskInterface) {
String address = vmDevice.getAddress();
if (diskInterface != DiskInterface.VirtIO_SCSI && diskInterface != DiskInterface.SPAPR_VSCSI) {
if (StringUtils.isNotBlank(address)) {
return StringMapUtils.string2Map(address);
}
} else {
EngineLock vmDiskHotPlugEngineLock = null;
try {
vmDiskHotPlugEngineLock = lockVmDiskHotPlugWithWait();
VM vm = vmDao.get(getParameters().getVmId());
Map<DiskInterface, Integer> controllerIndexMap = ArchStrategyFactory.getStrategy(vm.getClusterArch()).run(new GetControllerIndices()).returnValue();
int virtioScsiIndex = controllerIndexMap.get(DiskInterface.VirtIO_SCSI);
int sPaprVscsiIndex = controllerIndexMap.get(DiskInterface.SPAPR_VSCSI);
if (diskInterface == DiskInterface.VirtIO_SCSI) {
Map<Integer, Map<VmDevice, Integer>> vmDeviceUnitMap = vmInfoBuildUtils.getVmDeviceUnitMapForVirtioScsiDisks(getVm());
return getAddressMapForScsiDisk(address, vmDeviceUnitMapForController(vmDevice, vmDeviceUnitMap), vmDevice, virtioScsiIndex, false, false);
} else if (diskInterface == DiskInterface.SPAPR_VSCSI) {
Map<Integer, Map<VmDevice, Integer>> vmDeviceUnitMap = vmInfoBuildUtils.getVmDeviceUnitMapForSpaprScsiDisks(getVm());
return getAddressMapForScsiDisk(address, vmDeviceUnitMapForController(vmDevice, vmDeviceUnitMap), vmDevice, sPaprVscsiIndex, true, true);
}
} finally {
lockManager.releaseLock(vmDiskHotPlugEngineLock);
}
}
return null;
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class GlusterVolumeSnapshotCommandBase method acquireGeoRepSessionLock.
protected EngineLock acquireGeoRepSessionLock(Guid id) {
EngineLock lock = new EngineLock(Collections.singletonMap(id.toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.GLUSTER_GEOREP, EngineMessage.ACTION_TYPE_FAILED_GEOREP_SESSION_LOCKED)), null);
lockManager.acquireLockWait(lock);
return lock;
}
Aggregations