Search in sources :

Example 26 with GlusterAsyncTask

use of org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask in project ovirt-engine by oVirt.

the class GlusterVolumeDaoImpl method fetchRelatedEntities.

/**
 * Fetches and populates related entities like bricks, options, access protocols for the given volume
 */
private void fetchRelatedEntities(GlusterVolumeEntity volume) {
    if (volume != null) {
        volume.setOptions(glusterOptionDao.getOptionsOfVolume(volume.getId()));
        volume.setAccessProtocols(new HashSet<>(getAccessProtocolsOfVolume(volume.getId())));
        volume.setTransportTypes(new HashSet<>(getTransportTypesOfVolume(volume.getId())));
        GlusterVolumeAdvancedDetails advancedDetails = fetchAdvancedDatails(volume.getId());
        if (advancedDetails != null) {
            volume.setAdvancedDetails(advancedDetails);
        }
        GlusterAsyncTask asyncTask = getAsyncTaskOfVolume(volume.getId());
        if (asyncTask != null) {
            volume.setAsyncTask(asyncTask);
        }
        List<GlusterBrickEntity> bricks = glusterBrickDao.getBricksOfVolume(volume.getId());
        if (volume.getAsyncTask() != null && volume.getAsyncTask().getTaskId() != null) {
            bricks.stream().filter(brick -> brick.getAsyncTask() != null && brick.getAsyncTask().getTaskId() != null && brick.getAsyncTask().getTaskId().equals(volume.getAsyncTask().getTaskId())).forEach(brick -> brick.setAsyncTask(volume.getAsyncTask()));
        }
        volume.setBricks(bricks);
        GlusterVolumeSnapshotConfig config = glusterVolumeSnapshotConfigDao.getConfigByVolumeIdAndName(volume.getClusterId(), volume.getId(), GlusterConstants.VOLUME_SNAPSHOT_MAX_HARD_LIMIT);
        if (config == null || StringUtils.isEmpty(config.getParamValue())) {
            config = glusterVolumeSnapshotConfigDao.getConfigByClusterIdAndName(volume.getClusterId(), GlusterConstants.VOLUME_SNAPSHOT_MAX_HARD_LIMIT);
        }
        volume.setSnapMaxLimit(config != null ? Integer.parseInt(config.getParamValue()) : 0);
    }
}
Also used : GlusterTaskType(org.ovirt.engine.core.common.asynctasks.gluster.GlusterTaskType) StringUtils(org.apache.commons.lang.StringUtils) StepEnum(org.ovirt.engine.core.common.job.StepEnum) MassOperationsGenericDao(org.ovirt.engine.core.dao.MassOperationsGenericDao) Guid(org.ovirt.engine.core.compat.Guid) GlusterVolumeType(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Singleton(javax.inject.Singleton) HashSet(java.util.HashSet) Inject(javax.inject.Inject) AccessProtocol(org.ovirt.engine.core.common.businessentities.gluster.AccessProtocol) GlusterConstants(org.ovirt.engine.core.common.constants.gluster.GlusterConstants) GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) GlusterVolumeSnapshotConfig(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotConfig) EnumUtils(org.ovirt.engine.core.common.utils.EnumUtils) GlusterVolumeSizeInfo(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSizeInfo) TransportType(org.ovirt.engine.core.common.businessentities.gluster.TransportType) Named(javax.inject.Named) GlusterVolumeOptionEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity) JobExecutionStatus(org.ovirt.engine.core.common.job.JobExecutionStatus) Collection(java.util.Collection) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterVolumeAdvancedDetails(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeAdvancedDetails) GlusterStatus(org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus) List(java.util.List) GlusterAsyncTask(org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask) RowMapper(org.springframework.jdbc.core.RowMapper) GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) GlusterVolumeSnapshotConfig(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotConfig) GlusterAsyncTask(org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask) GlusterVolumeAdvancedDetails(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeAdvancedDetails)

Example 27 with GlusterAsyncTask

use of org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask in project ovirt-engine by oVirt.

the class VolumeBrickListModel method retainBricks.

private void retainBricks() {
    if (getConfirmWindow() != null) {
        return;
    }
    ConfirmationModel model = new ConfirmationModel();
    setConfirmWindow(model);
    model.setTitle(ConstantsManager.getInstance().getConstants().retainBricksTitle());
    model.setMessage(ConstantsManager.getInstance().getConstants().retainBricksMessage());
    model.setHelpTag(HelpTag.volume_retain_brick);
    // $NON-NLS-1$
    model.setHashName("volume_retain_brick");
    GlusterVolumeEntity volumeEntity = getVolumeEntity();
    GlusterAsyncTask volumeTask = volumeEntity.getAsyncTask();
    ArrayList<String> list = new ArrayList<>();
    for (GlusterBrickEntity brick : volumeEntity.getBricks()) {
        if (brick.getAsyncTask() != null && volumeTask != null && brick.getAsyncTask().getTaskId() != null && brick.getAsyncTask().getTaskId().equals(volumeTask.getTaskId()) && volumeTask.getStatus() == JobExecutionStatus.FINISHED) {
            list.add(brick.getQualifiedName());
        }
    }
    model.setItems(list);
    // $NON-NLS-1$
    UICommand okCommand = UICommand.createDefaultOkUiCommand("OnRetainBricks", this);
    model.getCommands().add(okCommand);
    // $NON-NLS-1$
    UICommand cancelCommand = new UICommand("CancelConfirmation", this);
    cancelCommand.setTitle(ConstantsManager.getInstance().getConstants().close());
    cancelCommand.setIsCancel(true);
    model.getCommands().add(cancelCommand);
}
Also used : GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) GlusterVolumeEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity) GlusterAsyncTask(org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask) ArrayList(java.util.ArrayList) UICommand(org.ovirt.engine.ui.uicommonweb.UICommand) ConfirmationModel(org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)

Example 28 with GlusterAsyncTask

use of org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask in project ovirt-engine by oVirt.

the class GlusterTasksSyncJob method updateVolumeBricksAndLock.

private void updateVolumeBricksAndLock(Cluster cluster, GlusterAsyncTask task, final GlusterVolumeEntity vol) {
    try {
        // acquire lock on volume
        acquireLock(vol.getId());
        // update volume with task id
        volumeDao.updateVolumeTask(vol.getId(), task.getTaskId());
        if (GlusterTaskType.REMOVE_BRICK == task.getType()) {
            // update bricks associated with task id
            String[] bricks = task.getTaskParameters().getBricks();
            if (bricks != null) {
                List<GlusterBrickEntity> brickEntities = new ArrayList<>();
                for (String brick : bricks) {
                    String[] brickParts = brick.split(":", -1);
                    String hostnameOrIp = brickParts[0];
                    String brickDir = brickParts[1];
                    GlusterBrickEntity brickEntity = new GlusterBrickEntity();
                    VdsStatic server = glusterDBUtils.getServer(cluster.getId(), hostnameOrIp);
                    if (server == null) {
                        log.warn("Could not find server '{}' in cluster '{}'", hostnameOrIp, cluster.getId());
                    } else {
                        brickEntity.setServerId(server.getId());
                        brickEntity.setBrickDirectory(brickDir);
                        brickEntity.setAsyncTask(new GlusterAsyncTask());
                        brickEntity.getAsyncTask().setTaskId(task.getTaskId());
                        brickEntities.add(brickEntity);
                    }
                }
                brickDao.updateAllBrickTasksByHostIdBrickDirInBatch(brickEntities);
            }
        }
        logTaskStartedFromCLI(cluster, task, vol);
    } catch (Exception e) {
        log.error("Exception", e);
        // Release the lock only if there is any exception,
        // otherwise the lock will be released once the task is completed
        releaseLock(vol.getId());
        throw new EngineException(EngineError.GeneralException, e.getMessage());
    }
}
Also used : VdsStatic(org.ovirt.engine.core.common.businessentities.VdsStatic) GlusterBrickEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity) GlusterAsyncTask(org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask) ArrayList(java.util.ArrayList) EngineException(org.ovirt.engine.core.common.errors.EngineException) EngineException(org.ovirt.engine.core.common.errors.EngineException)

Example 29 with GlusterAsyncTask

use of org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask in project ovirt-engine by oVirt.

the class GlusterAsyncTaskStatusQueryBase method setStartAndStopTime.

private GlusterVolumeTaskStatusEntity setStartAndStopTime(GlusterVolumeTaskStatusEntity status) {
    if (status == null) {
        return null;
    }
    GlusterAsyncTask asyncTask = volume.getAsyncTask();
    if (asyncTask != null && asyncTask.getTaskId() != null) {
        List<Step> stepsList = stepDao.getStepsByExternalId(asyncTask.getTaskId());
        if (stepsList != null && !stepsList.isEmpty()) {
            status.setStartTime(stepsList.get(0).getStartTime());
            status.setStopTime(stepsList.get(0).getEndTime());
        }
    }
    return status;
}
Also used : GlusterAsyncTask(org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask) Step(org.ovirt.engine.core.common.job.Step)

Example 30 with GlusterAsyncTask

use of org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask in project ovirt-engine by oVirt.

the class GlusterAsyncTaskStatusQueryBase method updateLatestStatus.

private void updateLatestStatus(GlusterVolumeTaskStatusEntity status) {
    GlusterAsyncTask asyncTask = volume.getAsyncTask();
    if (asyncTask != null && asyncTask.getTaskId() != null) {
        GlusterTaskParameters taskParameters = new GlusterTaskParameters();
        taskParameters.setVolumeName(volume.getName());
        asyncTask.setTaskParameters(taskParameters);
        List<Step> stepsList = stepDao.getStepsByExternalId(asyncTask.getTaskId());
        // if step has already ended, do not update status.
        if (stepsList != null && !stepsList.isEmpty() && stepsList.get(0).getEndTime() != null) {
            asyncTask.setStatus(status.getStatusSummary().getStatus());
            asyncTask.setMessage(glusterTaskUtils.getSummaryMessage(status.getStatusSummary()));
            glusterTaskUtils.updateSteps(clusterDao.get(clusterId), asyncTask, stepsList);
            // release the volume lock if the task is completed
            if (glusterTaskUtils.hasTaskCompleted(asyncTask)) {
                glusterTaskUtils.releaseLock(volume.getId());
            }
        }
    }
}
Also used : GlusterTaskParameters(org.ovirt.engine.core.common.asynctasks.gluster.GlusterTaskParameters) GlusterAsyncTask(org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask) Step(org.ovirt.engine.core.common.job.Step)

Aggregations

GlusterAsyncTask (org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask)30 GlusterBrickEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity)11 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)10 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)5 GlusterTaskParameters (org.ovirt.engine.core.common.asynctasks.gluster.GlusterTaskParameters)4 Step (org.ovirt.engine.core.common.job.Step)4 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)4 Guid (org.ovirt.engine.core.compat.Guid)4 EngineException (org.ovirt.engine.core.common.errors.EngineException)3 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)3 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 JobExecutionStatus (org.ovirt.engine.core.common.job.JobExecutionStatus)2 GlusterVolumeRemoveBricksVDSParameters (org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeRemoveBricksVDSParameters)2 Collection (java.util.Collection)1 Date (java.util.Date)1 Map (java.util.Map)1