Search in sources :

Example 11 with Step

use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.

the class CommonVmPoolCommand method createAddVmStepContext.

private CommandContext createAddVmStepContext(String currentVmName) {
    CommandContext commandCtx = null;
    try {
        Map<String, String> values = new HashMap<>();
        values.put(VdcObjectType.VM.name().toLowerCase(), currentVmName);
        Step addVmStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), StepEnum.ADD_VM_TO_POOL, ExecutionMessageDirector.resolveStepMessage(StepEnum.ADD_VM_TO_POOL, values));
        ExecutionContext ctx = new ExecutionContext();
        ctx.setStep(addVmStep);
        ctx.setMonitored(true);
        commandCtx = cloneContextAndDetachFromParent().withExecutionContext(ctx);
    } catch (RuntimeException e) {
        log.error("Failed to create command context of adding VM '{}' to Pool '{}': {}", currentVmName, getParameters().getVmPool().getName(), e.getMessage());
        log.debug("Exception", e);
    }
    return commandCtx;
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) CommandContext(org.ovirt.engine.core.bll.context.CommandContext) HashMap(java.util.HashMap) Step(org.ovirt.engine.core.common.job.Step)

Example 12 with Step

use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.

the class GlusterTasksSyncJob method updateTasksInCluster.

private void updateTasksInCluster(final Cluster cluster, final Map<Guid, GlusterAsyncTask> runningTasks) {
    for (Entry<Guid, GlusterAsyncTask> entry : runningTasks.entrySet()) {
        Guid taskId = entry.getKey();
        final GlusterAsyncTask task = entry.getValue();
        List<Step> steps = stepDao.getStepsByExternalId(taskId);
        if (steps.isEmpty()) {
            createJobForTaskFromCLI(cluster, task);
        }
        glusterTaskUtils.updateSteps(cluster, task, steps);
    }
}
Also used : GlusterAsyncTask(org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask) Guid(org.ovirt.engine.core.compat.Guid) Step(org.ovirt.engine.core.common.job.Step)

Example 13 with Step

use of org.ovirt.engine.core.common.job.Step 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 14 with Step

use of org.ovirt.engine.core.common.job.Step 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 15 with Step

use of org.ovirt.engine.core.common.job.Step in project ovirt-engine by oVirt.

the class CommandBase method handleCommandStepAndEntities.

private void handleCommandStepAndEntities() {
    if (getCommandStep() != null) {
        Step taskStep = executionHandler.addTaskStep(getExecutionContext(), getCommandStep(), ExecutionMessageDirector.resolveStepMessage(getCommandStep(), getJobMessageProperties()), getCommandStepSubjectEntities());
        if (taskStep != null) {
            if (shouldUpdateStepProgress()) {
                stepDao.updateStepProgress(taskStep.getId(), 0);
            }
            getExecutionContext().setStep(taskStep);
            persistCommandIfNeeded();
        }
    }
}
Also used : Step(org.ovirt.engine.core.common.job.Step)

Aggregations

Step (org.ovirt.engine.core.common.job.Step)52 ExecutionContext (org.ovirt.engine.core.bll.job.ExecutionContext)14 Guid (org.ovirt.engine.core.compat.Guid)12 HashMap (java.util.HashMap)8 Job (org.ovirt.engine.core.common.job.Job)8 Date (java.util.Date)7 Test (org.junit.Test)6 CommandContext (org.ovirt.engine.core.bll.context.CommandContext)6 ArrayList (java.util.ArrayList)5 JobExecutionStatus (org.ovirt.engine.core.common.job.JobExecutionStatus)5 List (java.util.List)4 VdcObjectType (org.ovirt.engine.core.common.VdcObjectType)4 GlusterAsyncTask (org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask)4 StepSubjectEntity (org.ovirt.engine.core.common.job.StepSubjectEntity)4 Map (java.util.Map)3 StepEnum (org.ovirt.engine.core.common.job.StepEnum)3 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Inject (javax.inject.Inject)2