use of org.ovirt.engine.core.common.job.Job in project ovirt-engine by oVirt.
the class AddExternalStepCommandTest method makeExternalTestJob.
private Job makeExternalTestJob(Guid jobId) {
Job job = new Job();
job.setId(jobId);
job.setDescription("Sample Job");
job.setExternal(true);
return job;
}
use of org.ovirt.engine.core.common.job.Job in project ovirt-engine by oVirt.
the class AddJobCommand method createJob.
protected void createJob(ActionType actionType, boolean isExternal) {
Job job = ExecutionHandler.createJob(actionType, this);
job.setDescription(getParameters().getDescription());
job.setAutoCleared(getParameters().isAutoCleared());
Guid id = job.getId();
job.setExternal(isExternal);
jobRepository.saveJob(job);
if (jobDao.get(id) != null) {
setActionReturnValue(id);
setSucceeded(true);
} else {
setSucceeded(false);
}
}
use of org.ovirt.engine.core.common.job.Job in project ovirt-engine by oVirt.
the class JobRepositoryTest method getJobWithSteps.
@Test
public void getJobWithSteps() {
Job jobWithSteps = jobRepository.getJobWithSteps(job.getId());
assertNotNull(jobWithSteps);
assertNotNull(jobWithSteps.getSteps());
assertTrue(!jobWithSteps.getSteps().isEmpty());
assertEquals(JOB_SUBJECT_ENTITIES_MAP, jobWithSteps.getJobSubjectEntities());
}
use of org.ovirt.engine.core.common.job.Job in project ovirt-engine by oVirt.
the class ExecutionHandler method prepareCommandForMonitoring.
/**
* Prepares the monitoring objects for the command by the default behavior:
* <ul>
* <li> {@link ExecutionContext} determines how the command should be monitored. By default, non-internal commands
* will be associated with {@code Job} to represent the command execution. Internal commands will not be monitored
* by default, therefore the {@code ExecutionContext} is created as non-monitored context.
* <li> {@link Job} is created for monitored actions
* </ul>
*
* @param command
* The created instance of the command (can't be <code>null</code>).
* @param actionType
* The action type of the command
* @param runAsInternal
* Indicates if the command should be run as internal action or not
*/
public void prepareCommandForMonitoring(CommandBase<?> command, ActionType actionType, boolean runAsInternal) {
ExecutionContext context = command.getExecutionContext();
if (context == null) {
context = new ExecutionContext();
}
try {
boolean isMonitored = shouldMonitorCommand(actionType, runAsInternal);
// A monitored job is created for monitored external flows
if (isMonitored || context.isJobRequired()) {
Job job = getJob(command, actionType);
context.setExecutionMethod(ExecutionMethod.AsJob);
context.setJob(job);
command.setExecutionContext(context);
command.setJobId(job.getId());
context.setMonitored(true);
}
} catch (Exception e) {
log.error("Failed to prepare command of type '{}' for monitoring due to error '{}'", actionType.name(), e.getMessage());
log.debug("Exception", e);
}
}
use of org.ovirt.engine.core.common.job.Job in project ovirt-engine by oVirt.
the class ExecutionHandler method createJob.
/**
* Creates and returns an instance of {@link Job} entity.
*
* @param actionType
* The action type the job entity represents.
* @param command
* The {@code CommandBase} instance which the job entity describes.
* @return An initialized {@code Job} instance.
*/
public static Job createJob(ActionType actionType, CommandBase<?> command) {
Job job = new Job();
job.setId(Guid.newGuid());
job.setActionType(actionType);
job.setDescription(ExecutionMessageDirector.resolveJobMessage(actionType, command.getJobMessageProperties()));
job.setJobSubjectEntities(getSubjectEntities(command.getPermissionCheckSubjects()));
job.setOwnerId(command.getUserId());
job.setEngineSessionSeqId(command.getSessionSeqId());
job.setStatus(JobExecutionStatus.STARTED);
job.setStartTime(new Date());
job.setCorrelationId(command.getCorrelationId());
return job;
}
Aggregations