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