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