use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class TestStaxJobFactory method testJobCreationAttributeOrderDefinitionParameterXmlElement.
@Test
public void testJobCreationAttributeOrderDefinitionParameterXmlElement() throws URISyntaxException, JobCreationException, IOException, ClassNotFoundException {
TaskFlowJob job = (TaskFlowJob) factory.createJob(getResource("job_attr_def_parameter_xml_element.xml"));
Map<String, Serializable> arguments = ((JavaTask) job.getTask("task")).getArguments();
assertExpectedKeyValueEntriesMatch(arguments);
}
use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class DefaultModelJobValidatorServiceProviderTest method createJobWithTaskModelVariable.
private TaskFlowJob createJobWithTaskModelVariable(String value, String model) throws UserException {
TaskFlowJob job = new TaskFlowJob();
TaskVariable variable = new TaskVariable("VAR", value, model, false);
Task task = new ScriptTask();
task.setName("ModelTask");
task.setVariables(Collections.singletonMap(variable.getName(), variable));
job.addTask(task);
return job;
}
use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class TaskContextVariableExtractor method extractSystemVariables.
/**
* Extract default scheduller context variables, for a complete list see the documentation.
* https://doc.activeeon.com/latest/user/ProActiveUserGuide.html#_proactive_system_variables
*
* @param taskContext object that contains job information to extract the desired variables.
* @return map containing variables with values set.
*/
private Map<String, Serializable> extractSystemVariables(TaskContext taskContext, String nodesFile) {
TaskLauncherInitializer initializer = taskContext.getInitializer();
Map<String, Serializable> variables = new HashMap<>();
variables.put(SchedulerVars.PA_JOB_ID.toString(), initializer.getTaskId().getJobId().value());
variables.put(SchedulerVars.PA_JOB_NAME.toString(), initializer.getTaskId().getJobId().getReadableName());
variables.put(SchedulerVars.PA_TASK_ID.toString(), initializer.getTaskId().value());
variables.put(SchedulerVars.PA_TASK_NAME.toString(), initializer.getTaskId().getReadableName());
variables.put(SchedulerVars.PA_TASK_ITERATION.toString(), initializer.getIterationIndex());
variables.put(SchedulerVars.PA_TASK_REPLICATION.toString(), initializer.getReplicationIndex());
variables.put(SchedulerVars.PA_TASK_PROGRESS_FILE.toString(), taskContext.getProgressFilePath());
variables.put(SchedulerVars.PA_SCHEDULER_HOME.toString(), taskContext.getSchedulerHome());
variables.put(SchedulerVars.PA_USER.toString(), initializer.getJobOwner());
variables.put(SchedulerVars.PA_NODESFILE.toString(), nodesFile);
variables.put(SchedulerVars.PA_NODESNUMBER.toString(), taskContext.getOtherNodesURLs().size() + 1);
variables.put(SchedulerVars.PA_SCHEDULER_REST_URL.toString(), initializer.getSchedulerRestUrl());
variables.put(SchedulerVars.PA_CATALOG_REST_URL.toString(), initializer.getCatalogRestUrl());
return variables;
}
use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class ForkedTaskExecutor method execute.
@Override
public TaskResultImpl execute(TaskContext context, PrintStream outputSink, PrintStream errorSink) {
CookieBasedProcessTreeKiller taskProcessTreeKiller = null;
Process process = null;
ProcessStreamsReader processStreamsReader = null;
File serializedContext = null;
try {
if (!workingDir.exists()) {
FileUtils.forceMkdir(workingDir);
}
serializedContext = taskContextSerializer.serializeContext(context, workingDir);
OSProcessBuilder processBuilder = forkedJvmProcessBuilderCreator.createForkedProcessBuilder(context, serializedContext, outputSink, errorSink, workingDir);
TaskId taskId = context.getTaskId();
String cookieNameSuffix = "Job" + taskId.getJobId().value() + "Task" + taskId.value();
taskProcessTreeKiller = CookieBasedProcessTreeKiller.createProcessChildrenKiller(cookieNameSuffix, processBuilder.environment());
process = processBuilder.start();
processStreamsReader = new ProcessStreamsReader(taskId.toString(), process, outputSink, errorSink);
int exitCode = process.waitFor();
if (exitCode != 0) {
try {
Object error = deserializeTaskResult(serializedContext);
if (error instanceof TaskContext) {
return createTaskResult(context, new IOException("Forked JVM process returned with exit code " + exitCode + ", see task logs for more information"));
} else {
Throwable exception = (Throwable) error;
return createTaskResult(context, exception);
}
} catch (Throwable cannotDeserializeResult) {
return createTaskResult(context, cannotDeserializeResult);
}
}
return (TaskResultImpl) deserializeTaskResult(serializedContext);
} catch (Throwable throwable) {
return createTaskResult(context, throwable);
} finally {
FileUtils.deleteQuietly(serializedContext);
if (process != null) {
process.destroy();
}
if (taskProcessTreeKiller != null) {
taskProcessTreeKiller.kill();
}
if (processStreamsReader != null) {
processStreamsReader.close();
}
}
}
use of org.ow2.proactive.scheduler.common.job.Job in project scheduling by ow2-proactive.
the class TestTaskIdImpl method testGetIterationIndex.
@Test
public void testGetIterationIndex() throws Exception {
TaskId taskNoIterationIndex = TaskIdImpl.createTaskId(new JobIdImpl(1L, "job"), "task", 1);
TaskId taskIterationIndexSmallerThan9 = TaskIdImpl.createTaskId(new JobIdImpl(1L, "job"), "task#1", 1);
TaskId taskIterationIndexGreaterThan9 = TaskIdImpl.createTaskId(new JobIdImpl(1L, "job"), "task#10", 1);
TaskId taskReplicatedAndIterated = TaskIdImpl.createTaskId(new JobIdImpl(1L, "job"), "task#10*10", 1);
assertEquals(0, taskNoIterationIndex.getIterationIndex());
assertEquals(1, taskIterationIndexSmallerThan9.getIterationIndex());
assertEquals(10, taskIterationIndexGreaterThan9.getIterationIndex());
assertEquals(10, taskReplicatedAndIterated.getIterationIndex());
}
Aggregations