Search in sources :

Example 6 with EngineLock

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

Example 7 with EngineLock

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

Example 8 with EngineLock

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;
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) HashMap(java.util.HashMap) Step(org.ovirt.engine.core.common.job.Step) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 9 with EngineLock

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

Example 10 with EngineLock

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());
        }
    }
}
Also used : Snapshot(org.ovirt.engine.core.common.businessentities.Snapshot) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Date(java.util.Date)

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