use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity in project ovirt-engine by oVirt.
the class GlusterSyncJob method removeDeletedVolumes.
private void removeDeletedVolumes(Guid clusterId, Map<Guid, GlusterVolumeEntity> volumesMap) {
List<Guid> idsToRemove = new ArrayList<>();
for (GlusterVolumeEntity volume : volumeDao.getByClusterId(clusterId)) {
if (!volumesMap.containsKey(volume.getId())) {
idsToRemove.add(volume.getId());
log.debug("Volume '{}' has been removed directly using the gluster CLI. Removing it from engine as well.", volume.getName());
logUtil.logVolumeMessage(volume, AuditLogType.GLUSTER_VOLUME_DELETED_FROM_CLI);
// Set the gluster cli schedule enabled flag back to true
if (Config.<String>getValue(ConfigValues.GlusterMetaVolumeName).equalsIgnoreCase(volume.getName())) {
Cluster cluster = clusterDao.get(clusterId);
cluster.setGlusterCliBasedSchedulingOn(true);
clusterDao.update(cluster);
}
}
}
if (!idsToRemove.isEmpty()) {
try {
volumeDao.removeAll(idsToRemove);
} catch (Exception e) {
log.error("Error while removing volumes from database!", e);
}
}
}
use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity in project ovirt-engine by oVirt.
the class GlusterSyncJob method updateExistingAndNewVolumes.
private void updateExistingAndNewVolumes(Guid clusterId, Map<Guid, GlusterVolumeEntity> volumesMap) {
Cluster cluster = clusterDao.get(clusterId);
for (Entry<Guid, GlusterVolumeEntity> entry : volumesMap.entrySet()) {
GlusterVolumeEntity volume = entry.getValue();
log.debug("Analyzing volume '{}'", volume.getName());
GlusterVolumeEntity existingVolume = volumeDao.getById(entry.getKey());
if (existingVolume == null) {
try {
createVolume(volume);
} catch (Exception e) {
log.error("Could not save volume {} in database: {}", volume.getName(), e.getMessage());
log.debug("Exception", e);
}
// Set the CLI based snapshot scheduling flag accordingly
disableCliSnapshotSchedulingFlag(cluster, volume);
} else {
try {
log.debug("Volume '{}' exists in engine. Checking if it needs to be updated.", existingVolume.getName());
updateVolume(existingVolume, volume);
} catch (Exception e) {
log.error("Error while updating volume '{}': {}", volume.getName(), e.getMessage());
log.debug("Exception", e);
}
}
}
}
use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity in project ovirt-engine by oVirt.
the class GlusterTasksSyncJob method cleanUpOrphanTasks.
/**
* This method cleans the tasks in DB which the gluster CLI is no longer
* aware of.
* @param runningTasksInClusterMap - map of cluster id - task list in cluster
*/
private void cleanUpOrphanTasks(Map<Guid, Set<Guid>> runningTasksInClusterMap) {
// if map is empty, no tasks from clusters fetched. so return
if (runningTasksInClusterMap.isEmpty()) {
log.debug("Clean up of tasks has been skipped");
return;
}
// Populate the list of tasks that need to be monitored from database
List<Guid> taskListInDB = provider.getMonitoredTaskIDsInDB();
if (taskListInDB == null || taskListInDB.isEmpty()) {
return;
}
Set<Guid> allRunningTasksInCluster = new HashSet<>();
for (Set<Guid> taskSet : runningTasksInClusterMap.values()) {
if (taskSet != null) {
allRunningTasksInCluster.addAll(taskSet);
}
}
// if task is in DB but not in running task list
final Set<Guid> tasksNotRunning = new HashSet<>(taskListInDB);
tasksNotRunning.removeAll(allRunningTasksInCluster);
log.debug("Tasks to be cleaned up in db '{}'", tasksNotRunning);
for (Guid taskId : tasksNotRunning) {
GlusterVolumeEntity vol = volumeDao.getVolumeByGlusterTask(taskId);
if (vol != null && (vol.getStatus() != GlusterStatus.UP || !runningTasksInClusterMap.keySet().contains(vol.getClusterId()))) {
// contain the cluster id in such case
continue;
}
// Volume is up, but gluster does not know of task
// will mark job ended with status unknown.
List<Step> steps = stepDao.getStepsByExternalId(taskId);
Map<String, String> values = new HashMap<>();
values.put(GlusterConstants.CLUSTER, vol == null ? "" : vol.getClusterName());
values.put(GlusterConstants.VOLUME, vol == null ? "" : vol.getName());
values.put(GlusterConstants.JOB_STATUS, JobExecutionStatus.UNKNOWN.toString());
values.put(GlusterConstants.JOB_INFO, " ");
for (Step step : steps) {
if (TimeUnit.MILLISECONDS.toMinutes(System.currentTimeMillis() - step.getStartTime().getTime()) < getMininumWaitInMins()) {
// This task has been recently created. We will give it 10 mins before clearing it.
continue;
}
step.markStepEnded(JobExecutionStatus.UNKNOWN);
step.setStatus(JobExecutionStatus.UNKNOWN);
step.setDescription(ExecutionMessageDirector.resolveStepMessage(step.getStepType(), values));
glusterTaskUtils.endStepJob(step);
if (vol != null) {
logTaskStoppedFromCLI(step, vol);
}
}
glusterTaskUtils.releaseVolumeLock(taskId);
}
}
use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity in project ovirt-engine by oVirt.
the class GlusterTasksSyncJob method createJobToMonitor.
private void createJobToMonitor(Cluster cluster, GlusterAsyncTask task) {
if (!isTaskToBeMonitored(task)) {
// there's no need to monitor jobs that are failed or completed
return;
}
StepEnum step = task.getType().getStep();
ActionType actionType;
switch(step) {
case REBALANCING_VOLUME:
actionType = ActionType.StartRebalanceGlusterVolume;
break;
case REMOVING_BRICKS:
actionType = ActionType.StartRemoveGlusterVolumeBricks;
break;
default:
actionType = ActionType.Unknown;
}
String volumeName = task.getTaskParameters().getVolumeName();
GlusterVolumeEntity vol = volumeDao.getByName(cluster.getId(), volumeName);
if (vol == null) {
log.info("Volume '{}' does not exist yet for task detected from CLI '{}', not adding to engine", volumeName, task);
return;
}
Guid jobId = addJob(cluster, task, actionType, vol);
Guid execStepId = addExecutingStep(jobId);
Guid asyncStepId = addAsyncTaskStep(cluster, task, step, execStepId);
Step asyncStep = stepDao.get(asyncStepId);
executionHandler.updateStepExternalId(asyncStep, task.getTaskId(), ExternalSystemType.GLUSTER);
updateVolumeBricksAndLock(cluster, task, vol);
}
use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity 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;
}
Aggregations