use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class RefreshHostCapabilitiesCommand method executeCommand.
@Override
protected void executeCommand() {
try (EngineLock monitoringLock = acquireMonitorLock("Refresh host capabilities")) {
resourceManager.getVdsManager(getVdsId()).refreshHostSync(getVds());
setSucceeded(true);
}
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class AttachUserToVmFromPoolAndRunCommand method freeLock.
@Override
protected void freeLock() {
super.freeLock();
if (getCommandStatus() == CommandStatus.ENDED_WITH_FAILURE && !Guid.Empty.equals(getVmId()) && getParameters().isNonPrestartedVmLocked()) {
EngineLock runLock = vmPoolHandler.createLock(getVmId());
lockManager.releaseLock(runLock);
getParameters().setNonPrestartedVmLocked(false);
log.info("VM lock freed: {}", runLock);
}
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class AttachUserToVmFromPoolAndRunCommand method getExclusiveLocks.
@Override
protected Map<String, Pair<String, String>> getExclusiveLocks() {
Map<String, Pair<String, String>> locks = new HashMap<>();
locks.put(getAdUserId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.USER_VM_POOL, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
if (!Guid.Empty.equals(getVmId()) && isVmPrestarted()) {
EngineLock runLock = vmPoolHandler.createLock(getVmId());
if (runLock.getExclusiveLocks() != null) {
locks.putAll(runLock.getExclusiveLocks());
}
}
return locks;
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class GlusterSnapshotCommandBase method acquireEngineLock.
protected EngineLock acquireEngineLock(Guid id, LockingGroup group) {
EngineLock lock = new EngineLock(Collections.singletonMap(id.toString(), LockMessagesMatchUtil.makeLockingPair(group, EngineMessage.ACTION_TYPE_FAILED_VOLUME_OPERATION_IN_PROGRESS)), null);
lockManager.acquireLockWait(lock);
return lock;
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class GlusterSnapshotSyncJob method addOrUpdateSnapshots.
private void addOrUpdateSnapshots(Guid clusterId, List<GlusterVolumeSnapshotEntity> fetchedSnapshots) {
Map<Guid, GlusterVolumeSnapshotEntity> fetchedSnapshotsMap = new HashMap<>();
for (GlusterVolumeSnapshotEntity fetchedSnapshot : fetchedSnapshots) {
fetchedSnapshotsMap.put(fetchedSnapshot.getId(), fetchedSnapshot);
}
Cluster cluster = clusterDao.get(clusterId);
List<GlusterVolumeSnapshotEntity> existingSnapshots = volumeSnapshotDao.getAllByClusterId(clusterId);
Map<Guid, GlusterVolumeSnapshotEntity> existingSnapshotsMap = new HashMap<>();
for (GlusterVolumeSnapshotEntity existingSnapshot : existingSnapshots) {
existingSnapshotsMap.put(existingSnapshot.getId(), existingSnapshot);
}
List<GlusterVolumeSnapshotEntity> updatedSnapshots = new ArrayList<>();
List<GlusterVolumeSnapshotEntity> newlyAddedSnapshots = new ArrayList<>();
List<GlusterVolumeSnapshotEntity> deletedSnapshots = new ArrayList<>();
for (final GlusterVolumeSnapshotEntity fetchedSnapshot : fetchedSnapshots) {
GlusterVolumeSnapshotEntity correspondingExistingSnapshot = existingSnapshotsMap.get(fetchedSnapshot.getId());
if (correspondingExistingSnapshot == null) {
final GlusterVolumeEntity volume = volumeDao.getById(fetchedSnapshot.getVolumeId());
newlyAddedSnapshots.add(fetchedSnapshot);
log.debug("Detected new gluster volume snapshot '{}' for volume '{}' on cluster: '{}'", fetchedSnapshot.getSnapshotName(), volume.getName(), cluster.getName());
Map<String, String> customValues = new HashMap<>();
customValues.put("snapName", fetchedSnapshot.getSnapshotName());
customValues.put(GlusterConstants.VOLUME_NAME, volume.getName());
logUtil.logAuditMessage(clusterId, volume.getClusterName(), volume, null, AuditLogType.GLUSTER_VOLUME_SNAPSHOT_DETECTED_NEW, customValues);
} else if (correspondingExistingSnapshot.getStatus() != fetchedSnapshot.getStatus()) {
correspondingExistingSnapshot.setStatus(fetchedSnapshot.getStatus());
updatedSnapshots.add(correspondingExistingSnapshot);
}
}
for (final GlusterVolumeSnapshotEntity existingSnapshot : existingSnapshots) {
GlusterVolumeSnapshotEntity correspondingFetchedSnapshot = fetchedSnapshotsMap.get(existingSnapshot.getId());
if (correspondingFetchedSnapshot == null) {
final GlusterVolumeEntity volume = volumeDao.getById(existingSnapshot.getVolumeId());
deletedSnapshots.add(existingSnapshot);
log.debug("Gluster volume snapshot '{}' detected removed for volume '{}' on cluster: '{}'", existingSnapshot.getSnapshotName(), volume.getName(), cluster.getName());
Map<String, String> customValues = new HashMap<>();
customValues.put("snapName", existingSnapshot.getSnapshotName());
customValues.put(GlusterConstants.VOLUME_NAME, volume.getName());
logUtil.logAuditMessage(clusterId, volume.getClusterName(), volume, null, AuditLogType.GLUSTER_VOLUME_SNAPSHOT_DELETED_FROM_CLI, customValues);
}
}
// update snapshot details
try (EngineLock lock = acquireVolumeSnapshotLock(clusterId)) {
saveNewSnapshots(newlyAddedSnapshots);
updateSnapshots(updatedSnapshots);
deleteSnapshots(deletedSnapshots);
} catch (Exception e) {
log.error("Exception ocuured while adding/updating snapshots from CLI - '{}'", e.getMessage());
log.debug("Exception", e);
throw new EngineException(EngineError.GlusterSnapshotInfoFailedException, e.getLocalizedMessage());
}
}
Aggregations