Search in sources :

Example 1 with GlusterGeoRepSession

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession in project ovirt-engine by oVirt.

the class GlusterGeoRepSyncJob method updateDiscoveredSessions.

private void updateDiscoveredSessions(Cluster cluster, Map<String, GlusterGeoRepSession> sessionsMap, GlusterVolumeEntity volume) {
    removeDeletedSessions(cluster, sessionsMap, volume);
    // for each geo-rep session, find session in database and update details.
    for (GlusterGeoRepSession session : sessionsMap.values()) {
        GlusterVolumeEntity masterVolume = getVolume(cluster, session.getMasterVolumeName());
        if (masterVolume == null) {
            log.info("Could not find corresponding volume for geo-rep session '{}' and volume '{}' - status will not be updated.", session.getSessionKey(), session.getMasterVolumeName());
        } else {
            session.setMasterVolumeId(masterVolume.getId());
            // update consolidated status
            updateGeoRepStatus(masterVolume, session);
        }
        // check if session exists in database
        GlusterGeoRepSession sessionInDb = geoRepDao.getGeoRepSession(session.getSessionKey());
        if (sessionInDb == null) {
            // save the session in database first.
            log.debug("detected new geo-rep session '{}' for volume '{}'", session.getSessionKey(), session.getMasterVolumeName());
            if (Guid.isNullOrEmpty(session.getId())) {
                session.setId(Guid.newGuid());
            }
            if (session.getSlaveNodeUuid() == null && session.getSlaveVolumeId() == null) {
                updateSlaveNodeAndVolumeId(session);
            }
            geoRepDao.save(session);
            logGeoRepMessage(AuditLogType.GLUSTER_GEOREP_SESSION_DETECTED_FROM_CLI, cluster, session);
        } else {
            // if retrieved session does not have the slave uuid's set
            if (session.getSlaveNodeUuid() == null && session.getSlaveVolumeId() == null) {
                // set it from the one in db
                session.setSlaveNodeUuid(sessionInDb.getSlaveNodeUuid());
                session.setSlaveVolumeId(sessionInDb.getSlaveVolumeId());
            }
            // if even the updated session has no slave ids, try setting it by querying db
            if (session.getSlaveNodeUuid() == null && session.getSlaveVolumeId() == null) {
                updateSlaveNodeAndVolumeId(session);
            }
            session.setId(sessionInDb.getId());
            geoRepDao.updateSession(session);
        }
        updateSessionDetailsInDB(session);
        updateDiscoveredSessionConfig(cluster, session);
    }
}
Also used : GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterGeoRepSession(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)

Example 2 with GlusterGeoRepSession

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession in project ovirt-engine by oVirt.

the class GlusterGeoRepSyncJob method refreshGeoRepDataForVolume.

/**
 * Exposing this to be called via BLL command in case of force sync of geo-replication session data for volume
 */
public void refreshGeoRepDataForVolume(final GlusterVolumeEntity volume) {
    if (volume == null) {
        throw new EngineException(EngineError.GlusterVolumeGeoRepSyncFailed, "No volume information");
    }
    Cluster cluster = clusterDao.get(volume.getClusterId());
    discoverGeoRepDataInCluster(cluster, volume);
    List<GlusterGeoRepSession> geoRepSessions = geoRepDao.getGeoRepSessions(volume.getId());
    refreshGeoRepSessionStatusForSessions(cluster, geoRepSessions);
}
Also used : EngineException(org.ovirt.engine.core.common.errors.EngineException) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) GlusterGeoRepSession(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)

Example 3 with GlusterGeoRepSession

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession in project ovirt-engine by oVirt.

the class GlusterGeoRepSyncJob method removeDeletedSessions.

private void removeDeletedSessions(Cluster cluster, final Map<String, GlusterGeoRepSession> sessionsMap, GlusterVolumeEntity volume) {
    List<GlusterGeoRepSession> sessionsInDb;
    if (volume != null) {
        // syncing for a specific volume, so retrieve only that volume's sessions
        sessionsInDb = geoRepDao.getGeoRepSessions(volume.getId());
    } else {
        sessionsInDb = geoRepDao.getGeoRepSessionsInCluster(cluster.getId());
    }
    if (CollectionUtils.isEmpty(sessionsInDb)) {
        return;
    }
    List<GlusterGeoRepSession> sessionsToDelete = new ArrayList<>();
    for (GlusterGeoRepSession grepSession : sessionsInDb) {
        if (sessionsMap.get(grepSession.getSessionKey()) == null) {
            sessionsToDelete.add(grepSession);
        }
    }
    for (final GlusterGeoRepSession session : sessionsToDelete) {
        log.info("geo-rep session '{}' detected removed for volume '{}'", session.getSessionKey(), session.getMasterVolumeName());
        // check if geo-rep session is reference by a DR schedule
        List<StorageDomainDR> storageDRs = storageDomainDRDao.getWithGeoRepSession(session.getId());
        for (StorageDomainDR storageDR : storageDRs) {
            // delete and log deletion of storage DR - the schedule needs to be deleted as well
            log.info("Geo-rep session '{}'- for volume '{}' that has been deleted from CLI " + "has associated DR sync schedules which will be removed", session.getSessionKey(), session.getMasterVolumeName());
            if (storageDR.getJobId() != null) {
                schedulerUtil.deleteJob(storageDR.getJobId());
            }
            storageDomainDRDao.remove(storageDR.getStorageDomainId(), storageDR.getGeoRepSessionId());
            StorageDomainStatic storageDomain = storageDomainStaticDao.get(storageDR.getStorageDomainId());
            Map<String, String> customValues = new HashMap<>();
            customValues.put("storageDomainName", storageDomain.getName());
            customValues.put("geoRepSessionKey", session.getSessionKey());
            logGeoRepMessage(AuditLogType.STORAGE_DOMAIN_DR_DELETED, cluster, customValues);
        }
        geoRepDao.remove(session.getId());
        logGeoRepMessage(AuditLogType.GLUSTER_GEOREP_SESSION_DELETED_FROM_CLI, cluster, session);
    }
}
Also used : StorageDomainStatic(org.ovirt.engine.core.common.businessentities.StorageDomainStatic) StorageDomainDR(org.ovirt.engine.core.common.businessentities.StorageDomainDR) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GlusterGeoRepSession(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)

Example 4 with GlusterGeoRepSession

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession in project ovirt-engine by oVirt.

the class CreateGlusterVolumeGeoRepSessionCommand method validate.

@Override
protected boolean validate() {
    slaveHost = getSlaveHost();
    if (slaveHost == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_HOST_NOT_EXIST);
    }
    if (slaveHost.getStatus() != VDSStatus.Up) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_SERVER_STATUS_NOT_UP, String.format("$%1$s %2$s", "VdsName", slaveHost.getName()));
    }
    slaveVolume = getSlaveVolume();
    if (slaveVolume == null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_GLUSTER_VOLUME_INVALID);
    }
    if (slaveVolume.getStatus() != GlusterStatus.UP) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_GLUSTER_VOLUME_SHOULD_BE_STARTED);
    }
    if (!areAllRemoteServersUp()) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_ONE_OR_MORE_REMOTE_HOSTS_ARE_NOT_ACCESSIBLE);
    }
    GlusterGeoRepSession geoRepSession = glusterGeoRepDao.getGeoRepSession(getGlusterVolumeId(), slaveHost.getId(), getParameters().getSlaveVolumeName());
    if (geoRepSession != null) {
        return failValidation(EngineMessage.ACTION_TYPE_FAILED_GLUSTER_GEOREP_SESSION_ALREADY_CREATED);
    }
    return super.validate();
}
Also used : GlusterGeoRepSession(org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)

Example 5 with GlusterGeoRepSession

use of org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession in project ovirt-engine by oVirt.

the class CreateGlusterVolumeSnapshotCommand method pauseAndCreateSnapshotForGeoRepSessions.

private boolean pauseAndCreateSnapshotForGeoRepSessions() {
    if (georepSessions != null && georepSessions.size() > 0) {
        for (GlusterGeoRepSession session : georepSessions) {
            final GlusterVolumeEntity slaveVolume = glusterVolumeDao.getById(session.getSlaveVolumeId());
            if (slaveVolume == null) {
                // Continue to other geo-rep sessions and pause them for snapshot purpose
                continue;
            }
            VDS slaveUpServer = glusterUtil.getRandomUpServer(slaveVolume.getClusterId());
            if (slaveUpServer == null) {
                handleVdsError(AuditLogType.GLUSTER_VOLUME_SNAPSHOT_CREATE_FAILED, "No up server found in slave cluster of geo-rep session");
                setSucceeded(false);
                return false;
            }
            // Pause the geo-rep session if required
            if (!(session.getStatus() == GeoRepSessionStatus.CREATED || session.getStatus() == GeoRepSessionStatus.PAUSED || session.getStatus() == GeoRepSessionStatus.STOPPED)) {
                ActionReturnValue sessionPauseRetVal = null;
                try (EngineLock lock = acquireEngineLock(slaveVolume.getId(), LockingGroup.GLUSTER_SNAPSHOT)) {
                    sessionPauseRetVal = runInternalAction(ActionType.PauseGlusterVolumeGeoRepSession, new GlusterVolumeGeoRepSessionParameters(getGlusterVolumeId(), session.getId()));
                }
                if (sessionPauseRetVal != null && !sessionPauseRetVal.getSucceeded()) {
                    handleVdsErrors(AuditLogType.GLUSTER_VOLUME_GEO_REP_PAUSE_FAILED, sessionPauseRetVal.getExecuteFailedMessages());
                    setSucceeded(false);
                    return false;
                }
                session.setStatus(GeoRepSessionStatus.PAUSED);
                enginePausedSessions.add(session);
            }
            // Create snapshot for slave volume
            VDSReturnValue snapCreationRetVal = runVdsCommand(VDSCommandType.CreateGlusterVolumeSnapshot, new CreateGlusterVolumeSnapshotVDSParameters(slaveUpServer.getId(), session.getSlaveVolumeName(), snapshot.getSnapshotName(), snapshot.getDescription(), force));
            if (!snapCreationRetVal.getSucceeded()) {
                handleVdsError(AuditLogType.GLUSTER_VOLUME_SNAPSHOT_CREATE_FAILED, snapCreationRetVal.getVdsError().getMessage());
                setSucceeded(false);
                return false;
            } else {
                // Persist the snapshot details
                GlusterVolumeSnapshotEntity slaveVolumeSnapshot = (GlusterVolumeSnapshotEntity) snapCreationRetVal.getReturnValue();
                slaveVolumeSnapshot.setClusterId(slaveVolume.getClusterId());
                slaveVolumeSnapshot.setVolumeId(slaveVolume.getId());
                slaveVolumeSnapshot.setDescription(snapshot.getDescription());
                slaveVolumeSnapshot.setStatus(GlusterSnapshotStatus.DEACTIVATED);
                glusterVolumeSnapshotDao.save(slaveVolumeSnapshot);
                // check if the snapshot soft limit reached now for the volume and alert
                glusterUtil.alertVolumeSnapshotLimitsReached(slaveVolume);
            }
        }
    }
    return true;
}
Also used : CreateGlusterVolumeSnapshotVDSParameters(org.ovirt.engine.core.common.vdscommands.gluster.CreateGlusterVolumeSnapshotVDSParameters) VDS(org.ovirt.engine.core.common.businessentities.VDS) 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) GlusterVolumeSnapshotEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity) 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)

Aggregations

GlusterGeoRepSession (org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)49 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)12 EngineLock (org.ovirt.engine.core.utils.lock.EngineLock)9 GlusterVolumeGeoRepSessionParameters (org.ovirt.engine.core.common.action.gluster.GlusterVolumeGeoRepSessionParameters)8 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 VDS (org.ovirt.engine.core.common.businessentities.VDS)6 Guid (org.ovirt.engine.core.compat.Guid)6 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)5 GlusterVolumeGeoRepSessionVDSParameters (org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeGeoRepSessionVDSParameters)5 GlusterGeoRepSessionDetails (org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSessionDetails)3 GlusterVolumeSnapshotEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity)3 HashMap (java.util.HashMap)2 Callable (java.util.concurrent.Callable)2 StorageDomainDR (org.ovirt.engine.core.common.businessentities.StorageDomainDR)2 StorageDomainStatic (org.ovirt.engine.core.common.businessentities.StorageDomainStatic)2 GlusterBrickEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity)2 EngineException (org.ovirt.engine.core.common.errors.EngineException)2 CreateGlusterVolumeSnapshotVDSParameters (org.ovirt.engine.core.common.vdscommands.gluster.CreateGlusterVolumeSnapshotVDSParameters)2