Search in sources :

Example 31 with ForkEnvironment

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));
        }
    }
}
Also used : JobResult(org.ow2.proactive.scheduler.common.job.JobResult) Scheduler(org.ow2.proactive.scheduler.common.Scheduler) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) ArrayList(java.util.ArrayList) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) JobId(org.ow2.proactive.scheduler.common.job.JobId)

Example 32 with ForkEnvironment

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("--------------------------------------------------");
        }
    }
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) ArrayList(java.util.ArrayList) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) XMLStreamException(javax.xml.stream.XMLStreamException) JobValidationException(org.ow2.proactive.scheduler.common.exception.JobValidationException) FileNotFoundException(java.io.FileNotFoundException) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) VerifierConfigurationException(org.iso_relax.verifier.VerifierConfigurationException)

Example 33 with ForkEnvironment

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);
    }
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext)

Example 34 with ForkEnvironment

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);
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler) Test(org.junit.Test)

Example 35 with ForkEnvironment

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);
}
Also used : TaskContext(org.ow2.proactive.scheduler.task.context.TaskContext) ScriptExecutableContainer(org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer) VariablesMap(org.ow2.proactive.scheduler.task.utils.VariablesMap) ForkEnvironment(org.ow2.proactive.scheduler.common.task.ForkEnvironment) NodeDataSpacesURIs(org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs) TaskLauncherInitializer(org.ow2.proactive.scheduler.task.TaskLauncherInitializer) ScriptHandler(org.ow2.proactive.scripting.ScriptHandler) Test(org.junit.Test)

Aggregations

ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)54 Test (org.junit.Test)27 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)25 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)22 ScriptExecutableContainer (org.ow2.proactive.scheduler.task.containers.ScriptExecutableContainer)17 TaskContext (org.ow2.proactive.scheduler.task.context.TaskContext)15 TaskLauncherInitializer (org.ow2.proactive.scheduler.task.TaskLauncherInitializer)14 SimpleScript (org.ow2.proactive.scripting.SimpleScript)14 NodeDataSpacesURIs (org.ow2.proactive.scheduler.task.context.NodeDataSpacesURIs)13 VariablesMap (org.ow2.proactive.scheduler.task.utils.VariablesMap)9 ScriptHandler (org.ow2.proactive.scripting.ScriptHandler)9 File (java.io.File)8 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)8 TaskScript (org.ow2.proactive.scripting.TaskScript)8 JobId (org.ow2.proactive.scheduler.common.job.JobId)7 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)5 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)5 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)5 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)5 FileNotFoundException (java.io.FileNotFoundException)4