use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class TestLoadJobsPagination method testPagingAndFilteting.
@Test
public void testPagingAndFilteting() throws Exception {
InternalJob job;
InternalTask task;
// pending job - 1
defaultSubmitJob(createJob());
// job for user1 - 2
defaultSubmitJob(createJob(), "user1");
// running job - 3
job = defaultSubmitJob(createJob());
job.start();
task = startTask(job, job.getITasks().get(0));
dbManager.jobTaskStarted(job, task, true);
// killed job - 4
job = defaultSubmitJob(createJob());
job.failed(null, JobStatus.KILLED);
dbManager.updateAfterJobKilled(job, Collections.<TaskId>emptySet());
// job for user2 - 5
defaultSubmitJob(createJob(), "user2");
// finished job - 6
job = defaultSubmitJob(createJob());
job.start();
task = startTask(job, job.getITasks().get(0));
dbManager.jobTaskStarted(job, task, true);
TaskResultImpl result = new TaskResultImpl(null, new TestResult(0, "result"), null, 0);
job.terminateTask(false, task.getId(), null, null, result);
job.terminate();
dbManager.updateAfterTaskFinished(job, task, new TaskResultImpl(null, new TestResult(0, "result"), null, 0));
// canceled job - 7
job = defaultSubmitJob(createJob());
job.failed(job.getITasks().get(0).getId(), JobStatus.CANCELED);
dbManager.updateAfterJobKilled(job, Collections.<TaskId>emptySet());
// job marked as removed, method 'getJobs' shouldn't return it
job = defaultSubmitJob(createJob());
dbManager.removeJob(job.getId(), System.currentTimeMillis(), false);
List<JobInfo> jobs;
List<SortParameter<JobSortParameter>> sortParameters = new ArrayList<>();
sortParameters.add(new SortParameter<>(JobSortParameter.ID, SortOrder.ASC));
jobs = dbManager.getJobs(5, 1, null, true, true, true, sortParameters).getList();
JobInfo jobInfo = jobs.get(0);
Assert.assertEquals("6", jobInfo.getJobId().value());
Assert.assertEquals(JobStatus.FINISHED, jobInfo.getStatus());
Assert.assertEquals("TestLoadJobsPagination", jobInfo.getJobId().getReadableName());
Assert.assertEquals(1, jobInfo.getTotalNumberOfTasks());
Assert.assertEquals(1, jobInfo.getNumberOfFinishedTasks());
Assert.assertEquals(0, jobInfo.getNumberOfRunningTasks());
Assert.assertEquals(0, jobInfo.getNumberOfPendingTasks());
Assert.assertEquals(JobPriority.NORMAL, jobInfo.getPriority());
Assert.assertEquals(DEFAULT_USER_NAME, jobInfo.getJobOwner());
jobs = dbManager.getJobs(0, 10, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
jobs = dbManager.getJobs(-1, -1, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
jobs = dbManager.getJobs(-1, 5, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 1, 2, 3, 4, 5);
jobs = dbManager.getJobs(2, -1, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 3, 4, 5, 6, 7);
jobs = dbManager.getJobs(0, 0, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 1, 2, 3, 4, 5, 6, 7);
jobs = dbManager.getJobs(0, 1, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 1);
jobs = dbManager.getJobs(0, 3, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 1, 2, 3);
jobs = dbManager.getJobs(1, 10, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 2, 3, 4, 5, 6, 7);
jobs = dbManager.getJobs(5, 10, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 6, 7);
jobs = dbManager.getJobs(6, 10, null, true, true, true, sortParameters).getList();
checkJobs(jobs, 7);
jobs = dbManager.getJobs(7, 10, null, true, true, true, sortParameters).getList();
checkJobs(jobs);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, true, true, sortParameters).getList();
checkJobs(jobs, 1, 3, 4, 6, 7);
jobs = dbManager.getJobs(0, 10, "user1", true, true, true, sortParameters).getList();
checkJobs(jobs, 2);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, false, false, sortParameters).getList();
checkJobs(jobs, 1);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, true, false, sortParameters).getList();
checkJobs(jobs, 3);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, false, true, sortParameters).getList();
checkJobs(jobs, 4, 6, 7);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, true, true, sortParameters).getList();
checkJobs(jobs, 3, 4, 6, 7);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, false, true, sortParameters).getList();
checkJobs(jobs, 1, 4, 6, 7);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, true, true, false, sortParameters).getList();
checkJobs(jobs, 1, 3);
jobs = dbManager.getJobs(0, 10, DEFAULT_USER_NAME, false, false, false, sortParameters).getList();
checkJobs(jobs);
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class InProcessTaskExecutor method execute.
/**
* Executes a task inside a task context.
*
* @param taskContext Task context to execute.
* @param output Standard output sink.
* @param error Error sink.
* @return Returns the task result.
*/
@Override
public TaskResultImpl execute(TaskContext taskContext, PrintStream output, PrintStream error) {
ScriptHandler scriptHandler = ScriptLoader.createLocalHandler();
String nodesFile = null;
SchedulerNodeClient schedulerNodeClient = null;
RMNodeClient rmNodeClient = null;
RemoteSpace userSpaceClient = null;
RemoteSpace globalSpaceClient = null;
try {
nodesFile = writeNodesFile(taskContext);
VariablesMap variables = new VariablesMap();
variables.setInheritedMap(taskContextVariableExtractor.getAllNonTaskVariablesInjectNodesFile(taskContext, nodesFile));
variables.setScopeMap(taskContextVariableExtractor.getScopeVariables(taskContext));
Map<String, String> resultMetadata = new HashMap<>();
Map<String, Serializable> resultMap = new HashMap<>();
Map<String, String> thirdPartyCredentials = forkedTaskVariablesManager.extractThirdPartyCredentials(taskContext);
schedulerNodeClient = forkedTaskVariablesManager.createSchedulerNodeClient(taskContext);
rmNodeClient = forkedTaskVariablesManager.createRMNodeClient(taskContext);
userSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(taskContext, schedulerNodeClient, IDataSpaceClient.Dataspace.USER);
globalSpaceClient = forkedTaskVariablesManager.createDataSpaceNodeClient(taskContext, schedulerNodeClient, IDataSpaceClient.Dataspace.GLOBAL);
forkedTaskVariablesManager.addBindingsToScriptHandler(scriptHandler, taskContext, variables, resultMap, thirdPartyCredentials, schedulerNodeClient, rmNodeClient, userSpaceClient, globalSpaceClient, resultMetadata, output, error);
Stopwatch stopwatch = Stopwatch.createUnstarted();
TaskResultImpl taskResult;
try {
stopwatch.start();
Serializable result = execute(taskContext, output, error, scriptHandler, thirdPartyCredentials, variables);
stopwatch.stop();
taskResult = new TaskResultImpl(taskContext.getTaskId(), result, null, stopwatch.elapsed(TimeUnit.MILLISECONDS));
} catch (Throwable e) {
stopwatch.stop();
e.printStackTrace(error);
taskResult = new TaskResultImpl(taskContext.getTaskId(), e, null, stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
executeFlowScript(taskContext.getControlFlowScript(), scriptHandler, output, error, taskResult);
taskResult.setPropagatedVariables(SerializationUtil.serializeVariableMap(variables.getPropagatedVariables()));
taskResult.setResultMap(resultMap);
taskResult.setMetadata(resultMetadata);
return taskResult;
} catch (Throwable e) {
e.printStackTrace(error);
TaskResultImpl result = new TaskResultImpl(taskContext.getTaskId(), e);
result.setPropagatedVariables(taskContextVariableExtractor.extractPropagatedVariables(taskContext));
return result;
} finally {
if (nodesFile != null && !nodesFile.isEmpty()) {
FileUtils.deleteQuietly(new File(nodesFile));
}
if (schedulerNodeClient != null && schedulerNodeClient.isConnected()) {
try {
schedulerNodeClient.disconnect();
} catch (Exception ignored) {
}
}
if (rmNodeClient != null && rmNodeClient.getSession() != null) {
try {
rmNodeClient.disconnect();
} catch (Exception ignored) {
}
}
}
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class ForkedTaskExecutorRunAsMeTest method runAsMe_PasswordMethod.
@Test
public void runAsMe_PasswordMethod() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
Decrypter decrypter = createCredentials(USERNAME, PASSWORD);
ForkedTaskExecutor taskExecutor = new ForkedTaskExecutor(tmpFolder.newFolder());
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setTaskId((TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L)));
ScriptExecutableContainer container = new ScriptExecutableContainer(new TaskScript(new SimpleScript("whoami", "native")));
container.setRunAsUser(true);
TaskContext taskContext = new TaskContext(container, initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", ""), decrypter);
TaskResultImpl result = taskExecutor.execute(taskContext, taskOutput.outputStream, taskOutput.error);
assertTaskResultOk(result);
assertEquals("admin\n", taskOutput.output());
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method storePreScriptAbsolute.
@Test
public void storePreScriptAbsolute() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setPreScript(new SimpleScript("println('pre')", "groovy"));
initializer.setPostScript(new SimpleScript("println('post')", "groovy"));
Map<String, String> genericInfo = new HashMap<>();
File file = File.createTempFile("test", ".py");
genericInfo.put("PRE_SCRIPT_AS_FILE", file.getAbsolutePath());
file.delete();
initializer.setGenericInformation(genericInfo);
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("println('hello'); java.lang.Thread.sleep(5); result='hello'", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
// Make sure that the execution of the pre-script is skipped
assertEquals(String.format("hello%npost%n"), taskOutput.output());
assertEquals("hello", result.value());
// Make sure that the pre-script is stored in a file
assertTrue(file.exists());
String content = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())));
assertEquals("println('pre')", content);
file.delete();
}
use of org.ow2.proactive.scheduler.task.TaskResultImpl in project scheduling by ow2-proactive.
the class InProcessTaskExecutorTest method storePreScriptWithoutExtension.
@Test
public void storePreScriptWithoutExtension() throws Throwable {
TestTaskOutput taskOutput = new TestTaskOutput();
TaskLauncherInitializer initializer = new TaskLauncherInitializer();
initializer.setPreScript(new SimpleScript("println('pre')", "groovy"));
initializer.setPostScript(new SimpleScript("println('post')", "groovy"));
Map<String, String> genericInfo = new HashMap<>();
File file = File.createTempFile("test", "");
genericInfo.put("PRE_SCRIPT_AS_FILE", file.getAbsolutePath());
file.delete();
initializer.setGenericInformation(genericInfo);
initializer.setTaskId(TaskIdImpl.createTaskId(JobIdImpl.makeJobId("1000"), "job", 1000L));
TaskResultImpl result = new InProcessTaskExecutor().execute(new TaskContext(new ScriptExecutableContainer(new TaskScript(new SimpleScript("println('hello'); java.lang.Thread.sleep(5); result='hello'", "groovy"))), initializer, null, new NodeDataSpacesURIs("", "", "", "", "", ""), "", new NodeInfo("", "", "", "")), taskOutput.outputStream, taskOutput.error);
// Make sure that the execution of the pre-script is skipped
assertEquals(String.format("hello%npost%n"), taskOutput.output());
assertEquals("hello", result.value());
// Make sure that the pre-script is stored in a file
file = new File(file.getAbsolutePath() + ".groovy");
assertTrue(file.exists());
String content = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())));
assertEquals("println('pre')", content);
file.delete();
}
Aggregations