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