Search in sources :

Example 21 with EngineLock

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;
}
Also used : EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 22 with EngineLock

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);
        }
    }
}
Also used : HostStoragePoolParametersBase(org.ovirt.engine.core.common.action.HostStoragePoolParametersBase) StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) DisconnectStoragePoolVDSCommandParameters(org.ovirt.engine.core.common.vdscommands.DisconnectStoragePoolVDSCommandParameters) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 23 with EngineLock

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);
        }
    }
}
Also used : VDS(org.ovirt.engine.core.common.businessentities.VDS) VdsIdAndVdsVDSCommandParametersBase(org.ovirt.engine.core.common.vdscommands.VdsIdAndVdsVDSCommandParametersBase) EngineException(org.ovirt.engine.core.common.errors.EngineException) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue) TimeoutException(java.util.concurrent.TimeoutException)

Example 24 with EngineLock

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;
}
Also used : VmDevice(org.ovirt.engine.core.common.businessentities.VmDevice) VM(org.ovirt.engine.core.common.businessentities.VM) DiskInterface(org.ovirt.engine.core.common.businessentities.storage.DiskInterface) Map(java.util.Map) HashMap(java.util.HashMap) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) GetControllerIndices(org.ovirt.engine.core.vdsbroker.architecture.GetControllerIndices)

Example 25 with EngineLock

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;
}
Also used : EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

Aggregations

EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)54 Pair (org.ovirt.engine.core.common.utils.Pair)13 VDS (org.ovirt.engine.core.common.businessentities.VDS)11 HashMap (java.util.HashMap)9 GlusterGeoRepSession (org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)9 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)9 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)8 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)7 Guid (org.ovirt.engine.core.compat.Guid)6 GlusterVolumeGeoRepSessionParameters (org.ovirt.engine.core.common.action.gluster.GlusterVolumeGeoRepSessionParameters)5 EngineException (org.ovirt.engine.core.common.errors.EngineException)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Date (java.util.Date)3 Set (java.util.Set)3 GlusterServerInfo (org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo)3 GlusterVolumeSnapshotEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity)3 Network (org.ovirt.engine.core.common.businessentities.network.Network)3 Callable (java.util.concurrent.Callable)2 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)2