Search in sources :

Example 6 with Step

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

the class TaskListModel method updateSingleTask.

public boolean updateSingleTask(final String guidOrCorrelationId) {
    if (!detailedTaskMap.containsKey(guidOrCorrelationId)) {
        detailedTaskMap.put(guidOrCorrelationId, null);
        if (guidOrCorrelationId.startsWith(WEBADMIN)) {
            GetJobsByCorrelationIdQueryParameters parameters = new GetJobsByCorrelationIdQueryParameters();
            parameters.setCorrelationId(guidOrCorrelationId);
            Frontend.getInstance().runQuery(QueryType.GetJobsByCorrelationId, parameters, new AsyncQuery<QueryReturnValue>(returnValue -> {
                ArrayList<Job> retTasks = returnValue.getReturnValue();
                ArrayList<Job> taskList = (ArrayList<Job>) getItems();
                ArrayList<Job> newTaskList = new ArrayList<>();
                for (Job task : taskList) {
                    if (task.getCorrelationId().equals(guidOrCorrelationId)) {
                        detailedTaskMap.put(guidOrCorrelationId, task);
                        task.setStatus(JobExecutionStatus.FINISHED);
                        for (Job job : retTasks) {
                            Step step = new Step();
                            step.setId(job.getId());
                            step.setDescription(job.getDescription());
                            step.setCorrelationId(job.getCorrelationId());
                            step.setStartTime(job.getStartTime());
                            step.setEndTime(job.getEndTime());
                            step.setStatus(job.getStatus());
                            step.setSteps(job.getSteps());
                            if (!task.getStatus().equals(JobExecutionStatus.FINISHED) && !job.getStatus().equals(JobExecutionStatus.FINISHED)) {
                                task.setStatus(job.getStatus());
                            }
                            if (task.getLastUpdateTime() == null || (task.getLastUpdateTime().before(job.getLastUpdateTime()) && !task.getLastUpdateTime().equals(job.getLastUpdateTime()))) {
                                task.setLastUpdateTime(job.getEndTime());
                            }
                            Date tempDate = task.getLastUpdateTime();
                            if (task.getStartTime() == null || task.getStartTime().after(job.getStartTime())) {
                                task.setStartTime(job.getStartTime());
                            }
                            if (task.getEndTime() != null && (task.getEndTime() == null || task.getEndTime().before(job.getEndTime()))) {
                                task.setEndTime(job.getEndTime());
                            }
                            task.addStep(step);
                            task.setLastUpdateTime(tempDate);
                        }
                    }
                    newTaskList.add(task);
                }
                setItems(newTaskList);
            }));
        } else {
            IdQueryParameters parameters = new IdQueryParameters(new Guid(guidOrCorrelationId));
            Frontend.getInstance().runQuery(QueryType.GetJobByJobId, parameters, new AsyncQuery<QueryReturnValue>(returnValue -> {
                Job retTask = returnValue.getReturnValue();
                if (retTask == null) {
                    return;
                }
                detailedTaskMap.put(retTask.getId().toString(), retTask);
                ArrayList<Job> taskList = (ArrayList<Job>) getItems();
                ArrayList<Job> newTaskList = new ArrayList<>();
                for (Job task : taskList) {
                    if (task.getId().equals(retTask.getId())) {
                        newTaskList.add(retTask);
                    } else {
                        newTaskList.add(task);
                    }
                }
                setItems(newTaskList);
            }));
        }
        return false;
    }
    return true;
}
Also used : GetJobsByOffsetQueryParameters(org.ovirt.engine.core.common.queries.GetJobsByOffsetQueryParameters) JobExecutionStatus(org.ovirt.engine.core.common.job.JobExecutionStatus) QueryType(org.ovirt.engine.core.common.queries.QueryType) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) Date(java.util.Date) Job(org.ovirt.engine.core.common.job.Job) Guid(org.ovirt.engine.core.compat.Guid) HashMap(java.util.HashMap) Random(java.util.Random) SearchableListModel(org.ovirt.engine.ui.uicommonweb.models.SearchableListModel) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) ArrayList(java.util.ArrayList) GetJobsByCorrelationIdQueryParameters(org.ovirt.engine.core.common.queries.GetJobsByCorrelationIdQueryParameters) Frontend(org.ovirt.engine.ui.frontend.Frontend) List(java.util.List) Map(java.util.Map) Step(org.ovirt.engine.core.common.job.Step) QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) IdQueryParameters(org.ovirt.engine.core.common.queries.IdQueryParameters) GetJobsByCorrelationIdQueryParameters(org.ovirt.engine.core.common.queries.GetJobsByCorrelationIdQueryParameters) GetJobsByCorrelationIdQueryParameters(org.ovirt.engine.core.common.queries.GetJobsByCorrelationIdQueryParameters) ArrayList(java.util.ArrayList) Step(org.ovirt.engine.core.common.job.Step) Guid(org.ovirt.engine.core.compat.Guid) Job(org.ovirt.engine.core.common.job.Job) Date(java.util.Date)

Example 7 with Step

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

the class RunVmCommand method createContextForRunStatelessVm.

private CommandContext createContextForRunStatelessVm() {
    Step step = getExecutionContext().getStep();
    if (step == null) {
        return cloneContextAndDetachFromParent();
    }
    // Retrieve the job object and its steps as this the endSuccessfully stage of command execution -
    // at this is a new instance of the command is used
    // (comparing with the execution state) so all information on the job and steps should be retrieved.
    Job job = jobRepository.getJobWithSteps(step.getJobId());
    Step executingStep = job.getDirectStep(StepEnum.EXECUTING);
    // We would like to to set the run stateless step as substep of executing step
    setInternalExecution(true);
    ExecutionContext runStatelessVmCtx = new ExecutionContext();
    // The internal command should be monitored for tasks
    runStatelessVmCtx.setMonitored(true);
    Step runStatelessStep = executionHandler.addSubStep(getExecutionContext(), executingStep, StepEnum.RUN_STATELESS_VM, ExecutionMessageDirector.resolveStepMessage(StepEnum.RUN_STATELESS_VM, getVmValuesForMsgResolving()));
    // This is needed in order to end the job upon execution of the steps of the child command
    runStatelessVmCtx.setShouldEndJob(true);
    runStatelessVmCtx.setJob(job);
    // Since run stateless step involves invocation of command, we should set the run stateless vm step as
    // the "beginning step" of the child command.
    runStatelessVmCtx.setStep(runStatelessStep);
    return cloneContextAndDetachFromParent().withExecutionContext(runStatelessVmCtx);
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) Step(org.ovirt.engine.core.common.job.Step) Job(org.ovirt.engine.core.common.job.Job)

Example 8 with Step

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

the class RemoveVmPoolCommand method createRemoveVmStepContext.

private CommandContext createRemoveVmStepContext(VM vm) {
    CommandContext commandCtx = null;
    try {
        Map<String, String> values = Collections.singletonMap(VdcObjectType.VM.name().toLowerCase(), vm.getName());
        Step removeVmStep = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), StepEnum.REMOVING_VM, ExecutionMessageDirector.resolveStepMessage(StepEnum.REMOVING_VM, values));
        ExecutionContext ctx = new ExecutionContext();
        ctx.setStep(removeVmStep);
        ctx.setMonitored(true);
        Map<String, Pair<String, String>> locks = new HashMap<>();
        addVmLocks(vm, locks);
        EngineLock engineLock = new EngineLock(locks, null);
        commandCtx = cloneContext().withoutCompensationContext().withExecutionContext(ctx).withLock(engineLock);
    } catch (RuntimeException e) {
        log.error("Failed to create command context of removing VM '{}' that was in Pool '{}': {}", vm.getName(), getVmPoolName(), 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) EngineLock(org.ovirt.engine.core.utils.lock.EngineLock) Pair(org.ovirt.engine.core.common.utils.Pair)

Example 9 with Step

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

the class AddStepCommand method executeCommand.

@Override
protected void executeCommand() {
    ExecutionContext context = new ExecutionContext();
    context.setMonitored(true);
    if (parentStep == null) {
        // A step that is directly under a job
        context.setJob(job);
        context.setExecutionMethod(ExecutionMethod.AsJob);
        jobRepository.loadJobSteps(job);
        Step step = executionHandler.addStep(context, getParameters().getStepType(), getParameters().getDescription(), true);
        setActionReturnValue(step.getId());
        setSucceeded(true);
    } else {
        // this is a sub-step
        context.setStep(parentStep);
        context.setExecutionMethod(ExecutionMethod.AsStep);
        jobRepository.loadParentStepSteps(parentStep);
        Step step = executionHandler.addSubStep(context, parentStep, getParameters().getStepType(), getParameters().getDescription(), true);
        setActionReturnValue(step.getId());
        setSucceeded(true);
    }
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) Step(org.ovirt.engine.core.common.job.Step)

Example 10 with Step

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

the class AttachUserToVmFromPoolAndRunCommand method createRunVmContext.

private ExecutionContext createRunVmContext() {
    ExecutionContext ctx = new ExecutionContext();
    try {
        Step step = executionHandler.addSubStep(getExecutionContext(), getExecutionContext().getJob().getStep(StepEnum.EXECUTING), StepEnum.TAKING_VM_FROM_POOL, ExecutionMessageDirector.resolveStepMessage(StepEnum.TAKING_VM_FROM_POOL, Collections.singletonMap(VdcObjectType.VM.name().toLowerCase(), getVmName())));
        ctx.setStep(step);
        ctx.setMonitored(true);
        ctx.setShouldEndJob(true);
    } catch (RuntimeException e) {
        log.error("Error when creating executing context for running stateless VM", e);
    }
    return ctx;
}
Also used : ExecutionContext(org.ovirt.engine.core.bll.job.ExecutionContext) 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