use of org.ow2.proactive.scheduler.common.task.ForkEnvironment 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.task.ForkEnvironment in project scheduling by ow2-proactive.
the class StaxJobFactory method displayJobInfo.
private void displayJobInfo(Job job) {
if (logger.isDebugEnabled()) {
logger.debug("type: " + job.getType());
logger.debug("name: " + job.getName());
logger.debug("description: " + job.getDescription());
logger.debug("projectName: " + job.getProjectName());
logger.debug("variables: " + job.getVariables());
logger.debug("priority: " + job.getPriority());
logger.debug("onTaskError: " + job.getOnTaskErrorProperty().getValue().toString());
logger.debug("restartTaskOnError: " + job.getRestartTaskOnError());
logger.debug("maxNumberOfExecution: " + job.getMaxNumberOfExecution());
logger.debug("inputSpace: " + job.getInputSpace());
logger.debug("outputSpace: " + job.getOutputSpace());
logger.debug("genericInformation: " + job.getGenericInformation());
logger.debug("TASKS ------------------------------------------------");
ArrayList<Task> tasks = new ArrayList<>();
switch(job.getType()) {
case TASKSFLOW:
tasks.addAll(((TaskFlowJob) job).getTasks());
break;
default:
break;
}
for (Task t : tasks) {
logger.debug("name: " + t.getName());
logger.debug("description: " + t.getDescription());
logger.debug("parallel: " + t.isParallel());
logger.debug("nbNodes: " + (t.getParallelEnvironment() == null ? "1" : t.getParallelEnvironment().getNodesNumber()));
logger.debug("onTaskError: " + t.getOnTaskErrorProperty().getValue().toString());
logger.debug("preciousResult: " + t.isPreciousResult());
logger.debug("preciousLogs: " + t.isPreciousLogs());
logger.debug("restartTaskOnError: " + t.getRestartTaskOnError());
logger.debug("maxNumberOfExecution: " + t.getMaxNumberOfExecution());
logger.debug("walltime: " + t.getWallTime());
logger.debug("selectionScripts: " + t.getSelectionScripts());
logger.debug("preScript: " + t.getPreScript());
logger.debug("postScript: " + t.getPostScript());
logger.debug("cleaningScript: " + t.getCleaningScript());
try {
logger.debug("inputFileList: length=" + t.getInputFilesList().size());
} catch (NullPointerException ignored) {
}
try {
logger.debug("outputFileList: length=" + t.getOutputFilesList().size());
} catch (NullPointerException ignored) {
}
if (t.getDependencesList() != null) {
String dep = "dependence: ";
for (Task tdep : t.getDependencesList()) {
dep += tdep.getName() + " ";
}
logger.debug(dep);
} else {
logger.debug("dependence: null");
}
logger.debug("genericInformation: " + t.getGenericInformation());
logger.debug("variables: " + t.getVariables());
if (t instanceof JavaTask) {
logger.debug("class: " + ((JavaTask) t).getExecutableClassName());
try {
logger.debug("args: " + ((JavaTask) t).getArguments());
} catch (Exception e) {
logger.debug("Cannot get args: " + e.getMessage(), e);
}
logger.debug("fork: " + ((JavaTask) t).isFork());
} else if (t instanceof NativeTask) {
logger.debug("commandLine: " + Arrays.toString(((NativeTask) t).getCommandLine()));
} else if (t instanceof ScriptTask) {
logger.debug("script: " + ((ScriptTask) t).getScript());
}
ForkEnvironment forkEnvironment = t.getForkEnvironment();
if (forkEnvironment != null) {
logger.debug("javaHome: " + forkEnvironment.getJavaHome());
logger.debug("systemEnvironment: " + forkEnvironment.getSystemEnvironment());
logger.debug("jvmArguments: " + forkEnvironment.getJVMArguments());
logger.debug("classpath: " + forkEnvironment.getAdditionalClasspath());
logger.debug("envScript: " + forkEnvironment.getEnvScript());
}
logger.debug("--------------------------------------------------");
}
}
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class ForkedJvmTaskExecutionCommandCreatorTest method javaCommandContains.
private void javaCommandContains(List<String> stringsContained, ForkEnvironment forkEnvironment) throws Exception {
ForkedJvmTaskExecutionCommandCreator forkedJvmTaskExecutionCommandCreator = new ForkedJvmTaskExecutionCommandCreator();
replaceJavaPrefixCommandCreatorWithMock(forkedJvmTaskExecutionCommandCreator);
TaskContext taskContext = createTaskContext();
taskContext.getInitializer().setForkEnvironment(forkEnvironment);
List<String> containsJavaHome = forkedJvmTaskExecutionCommandCreator.createForkedJvmTaskExecutionCommand(taskContext, null, serializedContextAbsolutePath);
for (String insideJavaCommand : stringsContained) {
assertThatListHasAtLeastOneStringWhichContains(containsJavaHome, insideJavaCommand);
}
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class ForkedTaskVariablesManagerTest method testAddBindingsToScriptHandlerContainsScratchURI.
@Test
public void testAddBindingsToScriptHandlerContainsScratchURI() throws InvalidScriptException, NodeException, NoSuchFieldException, IllegalAccessException {
ScriptExecutableContainer scriptContainer = createScriptContainer();
TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
taskLauncherInitializer.setForkEnvironment(new ForkEnvironment());
TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(testSetString, null, null, null, null, null), null, null);
// Expect taskResultArray to be inside the map
validateThatScriptHandlerBindingsContain(new ScriptHandler(), taskContext, new VariablesMap(), new HashMap<String, String>(), new HashMap<String, String>(), SchedulerConstants.DS_SCRATCH_BINDING_NAME, testSetString);
}
use of org.ow2.proactive.scheduler.common.task.ForkEnvironment in project scheduling by ow2-proactive.
the class ForkedTaskVariablesManagerTest method testAddBindingsToScriptHandlerContainsInputURI.
@Test
public void testAddBindingsToScriptHandlerContainsInputURI() throws InvalidScriptException, NodeException, NoSuchFieldException, IllegalAccessException {
ScriptExecutableContainer scriptContainer = createScriptContainer();
TaskLauncherInitializer taskLauncherInitializer = new TaskLauncherInitializer();
taskLauncherInitializer.setForkEnvironment(new ForkEnvironment());
TaskContext taskContext = new TaskContext(scriptContainer, taskLauncherInitializer, null, new NodeDataSpacesURIs(null, null, testSetString, null, null, null), null, null);
// Expect taskResultArray to be inside the map
validateThatScriptHandlerBindingsContain(new ScriptHandler(), taskContext, new VariablesMap(), new HashMap<String, String>(), new HashMap<String, String>(), SchedulerConstants.DS_INPUT_BINDING_NAME, testSetString);
}
Aggregations