Search in sources :

Example 16 with EngineLock

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

the class RestoreGlusterVolumeSnapshotCommand method restoreSlaveVolumesToSnapshot.

private boolean restoreSlaveVolumesToSnapshot(List<GlusterGeoRepSession> geoRepSessions) {
    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_RESTORE_FAILED, EngineError.NoUpServerFoundInRemoteCluster.name());
            setSucceeded(false);
            return false;
        }
        try (EngineLock lock = acquireEngineLock(slaveVolume.getClusterId(), LockingGroup.GLUSTER_SNAPSHOT)) {
            if (!restoreVolumeToSnapshot(slaveUpServer.getId(), slaveVolume, getSnapshot().getSnapshotName())) {
                return false;
            }
        }
    }
    return true;
}
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 17 with EngineLock

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

the class RestoreGlusterVolumeSnapshotCommand method resumeGeoRepSessions.

private boolean resumeGeoRepSessions(List<GlusterGeoRepSession> geoRepSessions) {
    for (GlusterGeoRepSession session : geoRepSessions) {
        GlusterVolumeEntity slaveVolume = glusterVolumeDao.getById(session.getSlaveVolumeId());
        if (slaveVolume == null) {
            // continue with other sessions and try to pause
            continue;
        }
        try (EngineLock lock = acquireGeoRepSessionLock(session.getId())) {
            ActionReturnValue retVal = runInternalAction(ActionType.ResumeGeoRepSession, new GlusterVolumeGeoRepSessionParameters(getGlusterVolumeId(), session.getId()));
            if (!retVal.getSucceeded()) {
                handleVdsError(AuditLogType.GLUSTER_VOLUME_GEO_REP_RESUME_FAILED, retVal.getExecuteFailedMessages().toString());
                setSucceeded(false);
                return false;
            }
        }
    }
    return true;
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterVolumeGeoRepSessionParameters(org.ovirt.engine.core.common.action.gluster.GlusterVolumeGeoRepSessionParameters) GlusterGeoRepSession(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

Example 18 with EngineLock

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

the class RestoreGlusterVolumeSnapshotCommand method stopGeoReplicationSessions.

private boolean stopGeoReplicationSessions(List<GlusterGeoRepSession> geoRepSessions) {
    for (GlusterGeoRepSession session : geoRepSessions) {
        if (!(session.getStatus() == GeoRepSessionStatus.STOPPED || session.getStatus() == GeoRepSessionStatus.CREATED)) {
            try (EngineLock lock = acquireGeoRepSessionLock(session.getId())) {
                ActionReturnValue retVal = runInternalAction(ActionType.StopGeoRepSession, new GlusterVolumeGeoRepSessionParameters(getGlusterVolumeId(), session.getId()));
                if (!retVal.getSucceeded()) {
                    handleVdsError(AuditLogType.GEOREP_SESSION_STOP_FAILED, retVal.getExecuteFailedMessages().toString());
                    setSucceeded(false);
                    return false;
                }
                session.setStatus(GeoRepSessionStatus.STOPPED);
                engineStoppedSessions.add(session);
            }
        }
    }
    return true;
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) GlusterVolumeGeoRepSessionParameters(org.ovirt.engine.core.common.action.gluster.GlusterVolumeGeoRepSessionParameters) GlusterGeoRepSession(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

Example 19 with EngineLock

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

the class RestoreGlusterVolumeSnapshotCommand method executeCommand.

@Override
public void executeCommand() {
    Boolean tranRetVal = TransactionSupport.executeInNewTransaction(() -> {
        if (georepSessions != null) {
            // Stop the geo-replication session
            if (!stopGeoReplicationSessions(georepSessions)) {
                return false;
            }
            // Stop the slave volumes
            if (!stopSlaveVolumes(georepSessions)) {
                return false;
            }
            // Restore the slave volumes to said the snapshot
            if (!restoreSlaveVolumesToSnapshot(georepSessions)) {
                return false;
            }
        }
        return true;
    });
    if (!tranRetVal) {
        return;
    }
    // Stop the master volume
    if (!stopVolume(getGlusterVolume())) {
        if (!georepSessions.isEmpty()) {
            handleVdsError(AuditLogType.GLUSTER_MASTER_VOLUME_STOP_FAILED_DURING_SNAPSHOT_RESTORE, EngineError.FailedToStopMasterVolumeDuringVolumeSnapshotRestore.name());
        }
        return;
    }
    // Restore the master volume to the said snapshot
    try (EngineLock lock = acquireEngineLock(getGlusterVolume().getClusterId(), LockingGroup.GLUSTER_SNAPSHOT)) {
        if (!restoreVolumeToSnapshot(upServer.getId(), getGlusterVolume(), getParameters().getSnapshotName())) {
            if (!georepSessions.isEmpty()) {
                handleVdsError(AuditLogType.GLUSTER_MASTER_VOLUME_SNAPSHOT_RESTORE_FAILED, EngineError.FailedToRestoreMasterVolumeDuringVolumeSnapshotRestore.name());
            }
            return;
        }
    }
    // Start the slave volumes
    if (engineStoppedSessions != null && !startSlaveVolumes(engineStoppedSessions)) {
        return;
    }
    // Start the master volume
    if (!startVolume(getGlusterVolumeId())) {
        return;
    }
    if (engineStoppedSessions != null) {
        // Start the geo-replication sessions
        if (!startGeoRepSessions(engineStoppedSessions)) {
            return;
        }
        // Resume the geo-replication sessions
        if (!resumeGeoRepSessions(engineStoppedSessions)) {
            return;
        }
    }
    setSucceeded(true);
}
Also used : EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

Example 20 with EngineLock

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

the class CommandBase method acquireLockInternal.

protected boolean acquireLockInternal() {
    // if commandLock is null then we acquire new lock, otherwise probably we got lock from caller command.
    if (context.getLock() == null) {
        EngineLock lock = buildLock();
        if (lock != null) {
            Pair<Boolean, Set<String>> lockAcquireResult = lockManager.acquireLock(lock);
            if (lockAcquireResult.getFirst()) {
                log.info("Lock Acquired to object '{}'", lock);
                context.withLock(lock);
            } else {
                log.info("Failed to Acquire Lock to object '{}'", lock);
                getReturnValue().getValidationMessages().addAll(extractVariableDeclarations(lockAcquireResult.getSecond()));
                return false;
            }
        }
    }
    return true;
}
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