use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.
the class TestNativeTaskPaths method testNativeTaskPaths.
@Test
public void testNativeTaskPaths() throws Throwable {
File in = File.createTempFile("input", "space");
in.delete();
in.mkdir();
String inPath = in.getAbsolutePath();
File out = File.createTempFile("output", "space");
out.delete();
out.mkdir();
File outc = new File(out, OutVarsFileC);
File outd = new File(out, OutVarsFileD);
if (outc.exists()) {
outc.delete();
}
if (outd.exists()) {
outd.delete();
}
File scriptTestEnv = null;
if (OperatingSystem.getOperatingSystem() == OperatingSystem.unix) {
scriptTestEnv = new File(inPath + File.separator + scriptCLinux);
scriptTestEnv.createNewFile();
PrintWriter out3 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(scriptTestEnv))));
out3.print(scriptCLinuxContent);
out3.close();
} else {
scriptTestEnv = new File(inPath + File.separator + scriptCWindows);
scriptTestEnv.createNewFile();
PrintWriter out3 = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(scriptTestEnv))));
out3.print(scriptCWindowsContent);
out3.close();
}
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName());
job.setInputSpace(in.toURI().toURL().toString());
job.setOutputSpace(out.toURI().toURL().toString());
// // testing paths pattern
// NativeTask C = new NativeTask();
// C.setName("C");
// C.addOutputFiles(OutVarsFileC, OutputAccessMode.TransferToOutputSpace);
// switch (OperatingSystem.getOperatingSystem()) {
// case windows:
// C.setCommandLine(new String[] { "cmd", "/C",
// "echo \"$JAVA\" \"$PROACTIVE_HOME\" > $LOCALSPACE\\" + OutVarsFileC });
// break;
// case unix:
// C.setCommandLine(new String[] { "/bin/bash", "-c",
// "echo \\\"$JAVA\\\" \\\"$PROACTIVE_HOME\\\" > $LOCALSPACE/" + OutVarsFileC });
// break;
// default:
// throw new IllegalStateException("Unsupported operating system");
// }
// job.addTask(C);
// testing $USERSPACE environment variable
NativeTask D = new NativeTask();
D.setName("D");
if (OperatingSystem.getOperatingSystem() == OperatingSystem.unix) {
D.addInputFiles(scriptCLinux, InputAccessMode.TransferFromInputSpace);
} else {
D.addInputFiles(scriptCWindows, InputAccessMode.TransferFromInputSpace);
}
D.addOutputFiles(OutVarsFileD, OutputAccessMode.TransferToOutputSpace);
switch(OperatingSystem.getOperatingSystem()) {
case windows:
D.setCommandLine(new String[] { "cmd", "/C", scriptCWindows });
break;
case unix:
D.setCommandLine(new String[] { "/bin/bash", "-c", "chmod u+x $localspace/" + scriptCLinux + "; $localspace/" + scriptCLinux });
break;
default:
throw new IllegalStateException("Unsupported operating system");
}
D.setForkEnvironment(new ForkEnvironment("$LOCALSPACE"));
job.addTask(D);
Scheduler sched = schedulerHelper.getSchedulerInterface();
JobId id = sched.submit(job);
schedulerHelper.waitForEventJobFinished(id);
String contentExpected = "foo";
JobResult jr = schedulerHelper.getJobResult(id);
Assert.assertFalse(jr.hadException());
logger.info("Expected : '" + contentExpected + "'");
// logger.info(jr.getAllResults().get("C").getOutput().getAllLogs(true));
// String receivedc = IOUtils.toString(outc.toURI()).trim();
// logger.info("Received C : '" + receivedc + "'");
// Assert.assertEquals(contentExpected.toLowerCase(), receivedc.toLowerCase());
logger.info(jr.getAllResults().get("D").getOutput().getAllLogs(true));
String receivedd = IOUtils.toString(outd.toURI()).trim();
logger.info("Received D : '" + receivedd + "'");
Assert.assertEquals(contentExpected.toLowerCase(), receivedd.toLowerCase());
}
use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.
the class TestTaskRestartOnNodeFailure method checkJobResult.
private void checkJobResult(Scheduler scheduler, JobId jobId) throws Exception {
JobResult jobResult = scheduler.getJobResult(jobId);
assertEquals("Unexpected number of task results", 1, jobResult.getAllResults().size());
for (TaskResult taskResult : jobResult.getAllResults().values()) {
log("Task " + taskResult.getTaskId());
assertNull("Unexpected task result exception", taskResult.getException());
String output = taskResult.getOutput().getAllLogs(false);
log("Task output:");
log(output);
assertTrue("Unxepected output", output.contains("OK"));
}
}
use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.
the class TestPreciousLogs method testPreciousLogs.
private void testPreciousLogs(boolean createJavaTask, boolean forkEnv) throws Exception {
TaskFlowJob job = new TaskFlowJob();
job.setName(this.getClass().getSimpleName());
Map<String, List<String>> expectedOutput = new LinkedHashMap<>();
for (int i = 0; i < 3; i++) {
String forkOutput = "forkOutput-" + i;
String preOutput = "preOutput-" + i;
String postOutput = "postOutput-" + i;
List<String> expectedTaskOutput = new ArrayList<>();
expectedTaskOutput.add(TASK_OUTPUT);
expectedTaskOutput.add(preOutput);
expectedTaskOutput.add(postOutput);
Task task;
if (createJavaTask) {
JavaTask javaTask = new JavaTask();
javaTask.setExecutableClassName(TestJavaTask.class.getName());
if (forkEnv) {
ForkEnvironment env = new ForkEnvironment();
env.setEnvScript(createScript(forkOutput));
javaTask.setForkEnvironment(env);
expectedTaskOutput.add(forkOutput);
}
task = javaTask;
} else {
NativeTask nativeTask = new NativeTask();
File script = new File(getClass().getResource("/functionaltests/executables/test_echo_task.sh").getFile());
if (!script.exists()) {
Assert.fail("Can't find script " + script.getAbsolutePath());
}
nativeTask.setCommandLine(script.getAbsolutePath());
task = nativeTask;
}
task.setMaxNumberOfExecution(1);
task.setOnTaskError(OnTaskError.CANCEL_JOB);
task.setPreciousLogs(true);
task.setName("Task-" + i);
task.setPreScript(createScript(preOutput));
task.setPostScript(createScript(postOutput));
expectedOutput.put(task.getName(), expectedTaskOutput);
job.addTask(task);
}
JobId jobId = schedulerHelper.testJobSubmission(job);
Scheduler scheduler = schedulerHelper.getSchedulerInterface();
String userURI = scheduler.getUserSpaceURIs().get(0);
String userPath = new File(new URI(userURI)).getAbsolutePath();
JobResult jobResult = scheduler.getJobResult(jobId);
Map<String, TaskResult> results = jobResult.getAllResults();
for (String taskName : expectedOutput.keySet()) {
File taskLog = new File(userPath + "/" + jobId.value(), String.format("TaskLogs-%s-%s.log", jobId.value(), results.get(taskName).getTaskId().value()));
if (!taskLog.exists()) {
Assert.fail("Task log file " + taskLog.getAbsolutePath() + " doesn't exist");
}
String output = new String(FileToBytesConverter.convertFileToByteArray(taskLog));
System.out.println("Log file for " + taskName + ":");
System.out.println(output);
for (String expectedLine : expectedOutput.get(taskName)) {
Assert.assertTrue("Output doesn't contain line " + expectedLine, output.contains(expectedLine));
}
}
}
use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.
the class TestMultipleHostsRequest method testMultipleHostsRequest.
@Test
public void testMultipleHostsRequest() throws Throwable {
String task1Name = "task1";
switch(OperatingSystem.getOperatingSystem()) {
case windows:
// set system Property for executable path
System.setProperty(executablePathPropertyName, new File(executablePathWindows.toURI()).getAbsolutePath());
break;
case unix:
SchedulerTHelper.setExecutable(new File(executablePath.toURI()).getAbsolutePath());
// set system Property for executable path
System.setProperty(executablePathPropertyName, new File(executablePath.toURI()).getAbsolutePath());
break;
default:
throw new IllegalStateException("Unsupported operating system");
}
// test submission and event reception
TaskFlowJob job = (TaskFlowJob) StaxJobFactory.getFactory().createJob(new File(jobDescriptor.toURI()).getAbsolutePath());
JobId id = schedulerHelper.submitJob(job);
schedulerHelper.addExtraNodes(3);
log("Job submitted, id " + id.toString());
log("Waiting for jobSubmitted Event");
JobState receivedState = schedulerHelper.waitForEventJobSubmitted(id);
assertEquals(receivedState.getId(), id);
log("Waiting for job running");
JobInfo jInfo = schedulerHelper.waitForEventJobRunning(id);
assertEquals(jInfo.getJobId(), id);
assertEquals(JobStatus.RUNNING, jInfo.getStatus());
schedulerHelper.waitForEventTaskRunning(id, task1Name);
TaskInfo tInfo = schedulerHelper.waitForEventTaskFinished(id, task1Name);
log(schedulerHelper.getSchedulerInterface().getTaskResult(id, "task1").getOutput().getAllLogs(false));
assertEquals(TaskStatus.FINISHED, tInfo.getStatus());
schedulerHelper.waitForEventJobFinished(id);
JobResult res = schedulerHelper.getJobResult(id);
// check that there is one exception in results
assertTrue(res.getExceptionResults().isEmpty());
// remove job
schedulerHelper.removeJob(id);
schedulerHelper.waitForEventJobRemoved(id);
}
use of org.ow2.proactive.scheduler.common.job.JobResult in project scheduling by ow2-proactive.
the class EnabledListenJobLogsSupport method listenJobLogs.
@Override
public synchronized void listenJobLogs(JobId jobId, AppenderProvider appenderProvider) throws UnknownJobException {
jlogger.info(jobId, "listening logs");
// create the appender to the remote listener
Appender clientAppender = null;
try {
clientAppender = appenderProvider.getAppender();
} catch (LogForwardingException e) {
jlogger.error(jobId, "cannot create an appender", e);
throw new InternalException("Cannot create an appender for job " + jobId, e);
}
boolean logIsAlreadyInitialized = jobsToBeLogged.contains(jobId);
initJobLogging(jobId, clientAppender);
JobResult result = dbManager.loadJobResult(jobId);
if (result == null) {
throw new UnknownJobException(jobId);
}
// for finished tasks, add logs events "manually"
Collection<TaskResult> allRes = result.getAllResults().values();
for (TaskResult tr : allRes) {
this.flushTaskLogs(tr, clientAppender, jobId);
}
for (RunningTaskData taskData : liveJobs.getRunningTasks(jobId)) {
jlogger.debug(jobId, "Handling log initialization for task " + taskData.getTask().getName());
try {
TaskLauncher taskLauncher = taskData.getLauncher();
if (logIsAlreadyInitialized) {
jlogger.debug(jobId, "Call getStoredLogs");
taskLauncher.getStoredLogs(appenderProvider);
} else {
jlogger.debug(jobId, "Call activateLogs");
taskLauncher.activateLogs(lfs.getAppenderProvider());
}
} catch (Exception e) {
tlogger.error(taskData.getTask().getId(), "cannot create an appender provider", e);
}
}
if (!result.getJobInfo().getStatus().isJobAlive()) {
jlogger.info(jobId, "cleaning loggers for already finished job");
cleanLoggers(jobId);
}
}
Aggregations