use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class DeleteGlusterVolumeSnapshotCommand method executeCommand.
@Override
public void executeCommand() {
if (georepSessions != null) {
for (GlusterGeoRepSession session : georepSessions) {
GlusterVolumeEntity slaveVolume = glusterVolumeDao.getById(session.getSlaveVolumeId());
if (slaveVolume == null) {
// continue with other sessions and try to pause
continue;
}
VDS slaveUpServer = glusterUtil.getRandomUpServer(slaveVolume.getClusterId());
if (slaveUpServer == null) {
handleVdsError(AuditLogType.GLUSTER_VOLUME_SNAPSHOT_DELETE_FAILED, EngineError.NoUpServerFoundInRemoteCluster.name());
setSucceeded(false);
return;
}
try (EngineLock lock = acquireEngineLock(session.getSlaveVolumeId(), LockingGroup.GLUSTER_SNAPSHOT)) {
if (!deleteGlusterVolumeSnapshot(slaveUpServer.getId(), slaveVolume.getName(), getSnapshot().getSnapshotName())) {
return;
}
// Check and remove soft limit alert for the volume
glusterUtil.checkAndRemoveVolumeSnapshotLimitsAlert(slaveVolume);
}
}
}
deleteGlusterVolumeSnapshot(getUpServer().getId(), getGlusterVolumeName(), getSnapshot().getSnapshotName());
// Check and remove soft limit alert for the volume
glusterUtil.checkAndRemoveVolumeSnapshotLimitsAlert(getGlusterVolume());
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class SpmStopVDSCommand method retrieveVdsExecutionLock.
private EngineLock retrieveVdsExecutionLock() {
if (lock == null) {
Map<String, Pair<String, String>> exsluciveLock = Collections.singletonMap(getParameters().getVdsId().toString(), new Pair<>(LockingGroup.VDS_EXECUTION.toString(), EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED.toString()));
lock = new EngineLock(exsluciveLock, null);
}
return lock;
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class RemoveVmPoolCommand method createRemoveVmStepContext.
private CommandContext createRemoveVmStepContext(VM vm) {
CommandContext commandCtx = null;
try {
Map<String, String> values = Collections.singletonMap(VdcObjectType.VM.name().toLowerCase(), vm.getName());
Step removeVmStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), StepEnum.REMOVING_VM, ExecutionMessageDirector.resolveStepMessage(StepEnum.REMOVING_VM, values));
ExecutionContext ctx = new ExecutionContext();
ctx.setStep(removeVmStep);
ctx.setMonitored(true);
Map<String, Pair<String, String>> locks = new HashMap<>();
addVmLocks(vm, locks);
EngineLock engineLock = new EngineLock(locks, null);
commandCtx = cloneContext().withoutCompensationContext().withExecutionContext(ctx).withLock(engineLock);
} catch (RuntimeException e) {
log.error("Failed to create command context of removing VM '{}' that was in Pool '{}': {}", vm.getName(), getVmPoolName(), e.getMessage());
log.debug("Exception", e);
}
return commandCtx;
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class RemoveVmTemplateCommand method acquireBaseTemplateSuccessorLock.
/**
* To prevent concurrent deletion.
* @return first: true ~ successfully locked, false otherwise; second: fail reasons in form suitable for
* validationMessages
*/
private boolean acquireBaseTemplateSuccessorLock() {
final Map<String, Pair<String, String>> lockSharedMap = Collections.singletonMap(baseTemplateSuccessor.getId().toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.TEMPLATE, createSubTemplateLockMessage(baseTemplateSuccessor)));
baseTemplateSuccessorLock = new EngineLock(null, lockSharedMap);
final Pair<Boolean, Set<String>> isLockedAndFailReason = lockManager.acquireLock(baseTemplateSuccessorLock);
if (isLockedAndFailReason.getFirst()) {
return true;
}
baseTemplateSuccessorLock = null;
getReturnValue().getValidationMessages().addAll(extractVariableDeclarations(isLockedAndFailReason.getSecond()));
return false;
}
use of org.ovirt.engine.core.utils.lock.EngineLock in project ovirt-engine by oVirt.
the class ProcessDownVmCommand method applyNextRunConfiguration.
/**
* Update VM configuration with NEXT_RUN configuration, if exists.
*/
private void applyNextRunConfiguration() {
// Remove snpashot first, in case other update is in progress, it will block this one with exclusive lock
// and any newer update should be preffered to this one.
Snapshot runSnap = snapshotDao.get(getVmId(), SnapshotType.NEXT_RUN);
if (runSnap != null && getVm().getStatus() != VMStatus.Suspended) {
log.debug("Attempt to apply NEXT_RUN snapshot for VM '{}'", getVmId());
EngineLock updateVmLock = createUpdateVmLock();
if (lockManager.acquireLock(updateVmLock).getFirst()) {
snapshotDao.remove(runSnap.getId());
Date originalCreationDate = getVm().getVmCreationDate();
snapshotsManager.updateVmFromConfiguration(getVm(), runSnap.getVmConfiguration());
// override creation date because the value in the config is the creation date of the config, not the vm
getVm().setVmCreationDate(originalCreationDate);
ActionReturnValue result = runInternalAction(ActionType.UpdateVm, createUpdateVmParameters(), ExecutionHandler.createInternalJobContext(updateVmLock));
if (result.getActionReturnValue() != null && result.getActionReturnValue().equals(ActionType.UpdateVmVersion)) {
// Template-version changed
templateVersionChanged = true;
}
} else {
log.warn("Could not acquire lock for UpdateVmCommand to apply Next Run Config of VM '{}'", getVmId());
}
}
}
Aggregations