Search in sources :

Example 36 with EngineLock

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

the class RestoreGlusterVolumeSnapshotCommand method startGeoRepSessions.

private boolean startGeoRepSessions(List<GlusterGeoRepSession> geoRepSessions) {
    for (GlusterGeoRepSession session : geoRepSessions) {
        try (EngineLock lock = acquireGeoRepSessionLock(session.getId())) {
            ActionReturnValue retVal = runInternalAction(ActionType.StartGlusterVolumeGeoRep, new GlusterVolumeGeoRepSessionParameters(getGlusterVolumeId(), session.getId()));
            if (!retVal.getSucceeded()) {
                handleVdsError(AuditLogType.GLUSTER_VOLUME_GEO_REP_START_FAILED_EXCEPTION, retVal.getExecuteFailedMessages().toString());
                setSucceeded(false);
                return false;
            }
        }
    }
    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 37 with EngineLock

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

the class AutodefineExternalNetworkCommand method runAutodefineForOneProvider.

// Acquire lock for every provider and run auto-define inside this lock
private void runAutodefineForOneProvider(Guid providerId, int index) {
    try (EngineLock lock = acquireLockForProvider(providerId)) {
        Network externalNetwork = createExternalNetwork(calcExternalNetworkName(index), providerId);
        AddNetworkStoragePoolParameters storagePoolParameters = new AddNetworkStoragePoolParameters(getNetwork().getStoragePoolId(), externalNetwork);
        storagePoolParameters.setNetworkClusterList(networkHelper.createNetworkClusters(clustersByProvider.get(providerId)));
        storagePoolParameters.setVnicProfilePublicUse(false);
        runInternalAction(ActionType.AddNetworkOnProvider, storagePoolParameters);
    }
}
Also used : AddNetworkStoragePoolParameters(org.ovirt.engine.core.common.action.AddNetworkStoragePoolParameters) ProviderNetwork(org.ovirt.engine.core.common.businessentities.network.ProviderNetwork) Network(org.ovirt.engine.core.common.businessentities.network.Network) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

Example 38 with EngineLock

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

the class AutodefineExternalNetworkCommand method acquireLockForProvider.

protected EngineLock acquireLockForProvider(Guid providerId) {
    EngineLock lock = new EngineLock(networkLocking.getNetworkProviderLock(providerId));
    lockManager.acquireLockWait(lock);
    return lock;
}
Also used : EngineLock(org.ovirt.engine.core.utils.lock.EngineLock)

Example 39 with EngineLock

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

the class CreateGlusterVolumeSnapshotCommand method executeCommand.

@Override
protected void executeCommand() {
    GlusterVolumeEntity volume = getGlusterVolume();
    // Pause geo-rep sessions and create snapshot for slave volumes
    Boolean tranRetVal = TransactionSupport.executeInNewTransaction(() -> pauseAndCreateSnapshotForGeoRepSessions());
    if (!tranRetVal) {
        return;
    }
    // Create snapshot for the master volume
    VDSReturnValue retVal = runVdsCommand(VDSCommandType.CreateGlusterVolumeSnapshot, new CreateGlusterVolumeSnapshotVDSParameters(upServer.getId(), volume.getName(), snapshot.getSnapshotName(), snapshot.getDescription(), force));
    setSucceeded(retVal.getSucceeded());
    if (!retVal.getSucceeded()) {
        handleVdsError(AuditLogType.GLUSTER_VOLUME_SNAPSHOT_CREATE_FAILED, retVal.getVdsError().getMessage());
    } else {
        GlusterVolumeSnapshotEntity createdSnapshot = (GlusterVolumeSnapshotEntity) retVal.getReturnValue();
        createdSnapshot.setClusterId(snapshot.getClusterId());
        createdSnapshot.setVolumeId(snapshot.getVolumeId());
        createdSnapshot.setDescription(snapshot.getDescription());
        createdSnapshot.setStatus(GlusterSnapshotStatus.DEACTIVATED);
        glusterVolumeSnapshotDao.save(createdSnapshot);
        addCustomValue(GlusterConstants.VOLUME_SNAPSHOT_NAME, createdSnapshot.getSnapshotName());
        // check if the snapshot soft limit reached now for the volume and alert
        glusterUtil.alertVolumeSnapshotLimitsReached(getGlusterVolume());
    }
    // Resume the snapshot paused sessions by engine
    for (GlusterGeoRepSession session : enginePausedSessions) {
        if (session.getStatus() == GeoRepSessionStatus.PAUSED) {
            try (EngineLock lock = acquireGeoRepSessionLock(session.getId())) {
                ActionReturnValue sessionResumeRetVal = runInternalAction(ActionType.ResumeGeoRepSession, new GlusterVolumeGeoRepSessionParameters(volume.getId(), session.getId()));
                if (!sessionResumeRetVal.getSucceeded()) {
                    handleVdsErrors(AuditLogType.GLUSTER_VOLUME_GEO_REP_RESUME_FAILED, sessionResumeRetVal.getExecuteFailedMessages());
                    setSucceeded(false);
                    return;
                }
            }
        }
    }
}
Also used : CreateGlusterVolumeSnapshotVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.CreateGlusterVolumeSnapshotVDSParameters) ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) 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) VDSReturnValue(org.ovirt.engine.core.common.vdscommands.VDSReturnValue)

Example 40 with EngineLock

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

the class CreateGlusterVolumeSnapshotCommand method acquireGeoRepSessionLock.

protected EngineLock acquireGeoRepSessionLock(Guid id) {
    EngineLock lock = new EngineLock(Collections.singletonMap(id.toString(), LockMessagesMatchUtil.makeLockingPair(LockingGroup.GLUSTER_GEOREP, EngineMessage.ACTION_TYPE_FAILED_GEOREP_SESSION_LOCKED)), null);
    lockManager.acquireLockWait(lock);
    return lock;
}
Also used : 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