Search in sources :

Example 31 with EngineLock

use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.

the class TryBackToAllSnapshotsOfVmCommand method updateVm.

private boolean updateVm(VmStatic vm, Version oldClusterVersion, boolean disableLock) {
    VmManagementParametersBase updateParams = new VmManagementParametersBase(vm);
    updateParams.setClusterLevelChangeFromVersion(oldClusterVersion);
    CommandContext context;
    if (disableLock) {
        updateParams.setLockProperties(LockProperties.create(LockProperties.Scope.None));
        context = cloneContextAndDetachFromParent();
    } else {
        // Wait for VM lock
        EngineLock updateVmLock = createUpdateVmLock();
        // will be released by UpdateVmCommand
        lockManager.acquireLockWait(updateVmLock);
        context = ExecutionHandler.createInternalJobContext(updateVmLock);
    }
    ActionReturnValue result = runInternalAction(ActionType.UpdateVm, updateParams, context);
    if (!result.getSucceeded()) {
        getReturnValue().setFault(result.getFault());
        return false;
    }
    return true;
}
Also used : CommandContext(org.ovirt.engine.core.bll.context.CommandContext) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) VmManagementParametersBase(org.ovirt.engine.core.common.action.VmManagementParametersBase) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

Example 32 with EngineLock

use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.

the class InMemoryLockManagerTest method setup.

@Before
public void setup() {
    updateGuid = Guid.newGuid().toString();
    lockGuid = Guid.newGuid().toString();
    Map<String, Pair<String, String>> updateRegionsMap = new HashMap<>();
    updateRegionsMap.put(updateGuid, new Pair<>("1", ERROR1));
    updateLock1 = new EngineLock();
    updateLock1.setSharedLocks(updateRegionsMap);
    lockLock1 = new EngineLock();
    lockLock1.setExclusiveLocks(updateRegionsMap);
    Map<String, Pair<String, String>> lockedRegionsMap = new HashMap<>();
    lockedRegionsMap.put(lockGuid, new Pair<>("2", ERROR2));
    lockLock2 = new EngineLock();
    lockLock2.setExclusiveLocks(lockedRegionsMap);
    updateLock2 = new EngineLock();
    updateLock2.setSharedLocks(lockedRegionsMap);
    updateAndLockLock = new EngineLock();
    updateAndLockLock.setSharedLocks(updateRegionsMap);
    updateAndLockLock.setExclusiveLocks(lockedRegionsMap);
    failLockLock = new EngineLock();
    failLockLock.setExclusiveLocks(updateRegionsMap);
    Map<String, Pair<String, String>> updateRegionsMap2 = new HashMap<>();
    updateRegionsMap2.put(updateGuid, new Pair<>("1", ERROR3));
    updateLock3 = new EngineLock();
    updateLock3.setSharedLocks(updateRegionsMap2);
}
Also used : HashMap(java.util.HashMap) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Pair(org.ovirt.engine.core.common.utils.Pair) Before(org.junit.Before)

Example 33 with EngineLock

use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.

the class VdsManager method init.

@PostConstruct
private void init() {
    monitoringStrategy = monitoringStrategyFactory.getMonitoringStrategyForVds(cachedVds);
    monitoringLock = new EngineLock(Collections.singletonMap(vdsId.toString(), new Pair<>(LockingGroup.VDS_INIT.name(), "")), null);
    registeredJobs = new ArrayList<>();
    handlePreviousStatus();
    handleSecureSetup();
    initVdsBroker();
}
Also used : EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) PostConstruct(javax.annotation.PostConstruct)

Example 34 with EngineLock

use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.

the class ImageTransferUpdater method updateEntity.

public ImageTransfer updateEntity(ImageTransfer updates, Guid commandId, boolean clearResourceId) {
    // TODO this lock might not be enough; analyze possible concurrent calls
    EngineLock lock = getEntityUpdateLock(commandId);
    try {
        lockManager.acquireLockWait(lock);
        ImageTransfer entity = imageTransferDao.get(commandId);
        if (entity == null) {
            log.error("Attempt to update non-existent ImageTransfer entity");
            return null;
        }
        entity.setLastUpdated(new Date());
        if (updates != null) {
            if (updates.getId() != null) {
                entity.setId(updates.getId());
            }
            if (updates.getPhase() != null) {
                String disk = entity.getDiskId() != null ? String.format(" (image %s)", entity.getDiskId().toString()) : "";
                String message = entity.getMessage() != null ? String.format(" (message: '%s')", entity.getMessage()) : "";
                log.info("Updating image transfer {}{} phase to {}{}", commandId, disk, updates.getPhase(), message);
                entity.setPhase(updates.getPhase());
            }
            if (updates.getType() != null) {
                entity.setType(updates.getType());
            }
            if (updates.getActive() != null) {
                entity.setActive(updates.getActive());
            }
            if (updates.getMessage() != null) {
                entity.setMessage(updates.getMessage());
            }
            if (updates.getVdsId() != null) {
                entity.setVdsId(updates.getVdsId());
            }
            if (updates.getDiskId() != null) {
                entity.setDiskId(updates.getDiskId());
            }
            if (updates.getImagedTicketId() != null || clearResourceId) {
                entity.setImagedTicketId(updates.getImagedTicketId());
            }
            if (updates.getProxyUri() != null) {
                entity.setProxyUri(updates.getProxyUri());
            }
            if (updates.getDaemonUri() != null) {
                entity.setDaemonUri(updates.getDaemonUri());
            }
            if (updates.getSignedTicket() != null) {
                entity.setSignedTicket(updates.getSignedTicket());
            }
            if (updates.getBytesSent() != null) {
                entity.setBytesSent(updates.getBytesSent());
            }
            if (updates.getBytesTotal() != null) {
                entity.setBytesTotal(updates.getBytesTotal());
            }
        }
        imageTransferDao.update(entity);
        return entity;
    } finally {
        lockManager.releaseLock(lock);
    }
}
Also used : ImageTransfer(org.ovirt.engine.core.common.businessentities.storage.ImageTransfer) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Date(java.util.Date)

Example 35 with EngineLock

use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.

the class LiveMigrateDiskCommand method lockVm.

protected boolean lockVm(Guid vmId) {
    liveStorageMigrationEngineLock = new EngineLock();
    liveStorageMigrationEngineLock.setExclusiveLocks(Collections.singletonMap(vmId.toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.LIVE_STORAGE_MIGRATION, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED)));
    Pair<Boolean, Set<String>> pair = lockManager.acquireLock(liveStorageMigrationEngineLock);
    return pair.getFirst();
}
Also used : Set(java.util.Set) 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