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);
}
}
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);
}
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);
}
}
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();
}
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;
}
Aggregations