Search in sources :

Example 66 with GlusterVolumeEntity

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);
        }
    }
}
Also used : GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) ArrayList(java.util.ArrayList) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Guid(org.ovirt.engine.core.compat.Guid)

Example 67 with GlusterVolumeEntity

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);
            }
        }
    }
}
Also used : GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) Cluster(org.ovirt.engine.core.common.businessentities.Cluster) Guid(org.ovirt.engine.core.compat.Guid)

Example 68 with GlusterVolumeEntity

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);
    }
}
Also used : HashMap(java.util.HashMap) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) Guid(org.ovirt.engine.core.compat.Guid) Step(org.ovirt.engine.core.common.job.Step) HashSet(java.util.HashSet)

Example 69 with GlusterVolumeEntity

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);
}
Also used : ActionType(org.ovirt.engine.core.common.action.ActionType) StepEnum(org.ovirt.engine.core.common.job.StepEnum) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) Guid(org.ovirt.engine.core.compat.Guid) Step(org.ovirt.engine.core.common.job.Step)

Example 70 with GlusterVolumeEntity

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

Aggregations

GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)220 ArrayList (java.util.ArrayList)57 GlusterBrickEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity)49 Test (org.junit.Test)47 Guid (org.ovirt.engine.core.compat.Guid)30 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)30 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)26 GlusterAsyncTask (org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask)20 VDS (org.ovirt.engine.core.common.businessentities.VDS)19 HashMap (java.util.HashMap)16 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)16 List (java.util.List)15 Map (java.util.Map)15 ValidationResult (org.ovirt.engine.core.bll.ValidationResult)15 ActionType (org.ovirt.engine.core.common.action.ActionType)13 GlusterGeoRepSession (org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)13 GlusterVolumeSnapshotEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity)13 GlusterVolumeType (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType)13 GlusterVolumeRemoveBricksParameters (org.ovirt.engine.core.common.action.gluster.GlusterVolumeRemoveBricksParameters)12 GlusterTaskType (org.ovirt.engine.core.common.asynctasks.gluster.GlusterTaskType)12