Search in sources :

Example 71 with JavaTask

use of org.ow2.proactive.scheduler.common.task.JavaTask 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("TaskRetryDelay: " + job.getTaskRetryDelay());
        logger.debug("maxNumberOfExecution: " + job.getMaxNumberOfExecution());
        logger.debug("inputSpace: " + job.getInputSpace());
        logger.debug("outputSpace: " + job.getOutputSpace());
        logger.debug("genericInformation: " + job.getGenericInformation());
        logger.debug("visualization: " + job.getVisualization());
        logger.debug("TASKS ------------------------------------------------");
        ArrayList<Task> tasks = job.getType().equals(JobType.TASKSFLOW) ? ((TaskFlowJob) job).getTasks() : new ArrayList<>();
        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("taskRetryDelay: " + t.getTaskRetryDelay());
            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());
                logger.debug("outputFileList: length=" + t.getOutputFilesList().size());
            } catch (NullPointerException ignored) {
            // Ignore this exception
            }
            if (t.getDependencesList() != null) {
                StringBuilder dep = new StringBuilder("dependence: ");
                t.getDependencesList().forEach(tdep -> dep.append(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: " + t.isFork());
                logger.debug("runAsMe: " + t.isRunAsMe());
            } 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) 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) IOException(java.io.IOException)

Example 72 with JavaTask

use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.

the class JobComparator method isTaskEqual.

private boolean isTaskEqual(Task t1, Task t2) throws IOException, ClassNotFoundException {
    if ((t1 == null) && (t2 == null))
        return true;
    if ((t1 == null) ^ (t2 == null)) {
        stack.push("One of 2 tasks is null");
        return false;
    }
    if (!isEqualCommonAttribute(t1, t2))
        return false;
    if (!t1.getName().equals(t2.getName())) {
        stack.push("name");
        return false;
    }
    if (!isEqualString(t1.getDescription(), t2.getDescription())) {
        stack.push("description");
        return false;
    }
    if (t1.getWallTime() != t2.getWallTime()) {
        stack.push("walltime");
        return false;
    }
    // ****** task dependencies ****
    stack.push("task dependenices");
    List<Task> dep1 = t1.getDependencesList();
    List<Task> dep2 = t2.getDependencesList();
    if (dep1 == null ^ dep2 == null) {
        stack.push("one dependency list is empty");
        return false;
    }
    if (dep1 != null) {
        if (dep1.size() != dep2.size()) {
            stack.push("sizes don't match");
            return false;
        }
        // we only compare the names in the 2 dependencies lists
        int dep1Size = dep1.size();
        Set<String> names1 = new HashSet<String>(dep1Size);
        Set<String> names2 = new HashSet<String>(dep1Size);
        for (int k = 0; k < dep1Size; k++) {
            names1.add(dep1.get(k).getName());
            names2.add(dep2.get(k).getName());
        }
        if (!CollectionUtils.isEqualCollection(names1, names2)) {
            return false;
        }
    }
    // task dependencies
    stack.pop();
    // **** parallel environment ****
    stack.push("parallel environment");
    if (!isEqualParallelEnvironment(t1.getParallelEnvironment(), t2.getParallelEnvironment()))
        return false;
    // parallel env
    stack.pop();
    // input files
    stack.push("input files");
    if (!isEqualInputFiles(t1.getInputFilesList(), t2.getInputFilesList()))
        return false;
    stack.pop();
    stack.push("output files");
    if (!isEqualOutputFiles(t1.getOutputFilesList(), t2.getOutputFilesList()))
        return false;
    stack.pop();
    // scripts
    stack.push("pre script");
    if (!isEqualScript(t1.getPreScript(), t2.getPreScript()))
        return false;
    stack.pop();
    stack.push("post script");
    if (!isEqualScript(t1.getPostScript(), t2.getPostScript()))
        return false;
    stack.pop();
    stack.push("cleaning script");
    if (!isEqualScript(t1.getCleaningScript(), t2.getCleaningScript()))
        return false;
    stack.pop();
    stack.push("selection scripts");
    List<SelectionScript> ss1 = t1.getSelectionScripts();
    List<SelectionScript> ss2 = t2.getSelectionScripts();
    if ((ss1 == null) ^ (ss2 == null)) {
        stack.push("One of two lists of selection scripts is null");
        return false;
    }
    if (ss1 != null) {
        if (t1.getSelectionScripts().size() != t2.getSelectionScripts().size()) {
            stack.push("lists size don't match");
            return false;
        }
        for (int k = 0; k < t1.getSelectionScripts().size(); k++) {
            if (!isEqualScript(t1.getSelectionScripts().get(k), t2.getSelectionScripts().get(k))) {
                return false;
            }
        }
    }
    // select scripts
    stack.pop();
    // flow control
    if (t1.getFlowBlock() != t2.getFlowBlock()) {
        stack.push("flow block");
        return false;
    }
    stack.push("flow control");
    if (!isEqualFlowControl(t1.getFlowScript(), t2.getFlowScript()))
        return false;
    stack.pop();
    // ***** task executable *****
    if (!isEqualClass(t1.getClass(), t2.getClass())) {
        stack.push("Executable types don't match");
        return false;
    }
    if (t1 instanceof JavaTask) {
        JavaTask jt1 = (JavaTask) t1;
        JavaTask jt2 = (JavaTask) t2;
        stack.push("arguments");
        if (!isEqualMap(jt1.getArguments(), jt2.getArguments()))
            return false;
        stack.pop();
        stack.push("executable class");
        if (!isEqualString(jt1.getExecutableClassName(), jt2.getExecutableClassName()))
            return false;
        stack.pop();
        stack.push("forked environemnt");
        if (!isEqualForkedEnvironment(jt1.getForkEnvironment(), jt2.getForkEnvironment()))
            return false;
        stack.pop();
    }
    if (t1 instanceof NativeTask) {
        NativeTask nt1 = (NativeTask) t1;
        NativeTask nt2 = (NativeTask) t2;
        String[] cl1 = nt1.getCommandLine();
        String[] cl2 = nt2.getCommandLine();
        if (cl1 == null ^ cl2 == null) {
            return false;
        } else if (cl1 != null) {
            if (!CollectionUtils.isEqualCollection(Arrays.asList(cl1), Arrays.asList(cl2))) {
                return false;
            }
        }
    }
    if (t1 instanceof ScriptTask) {
        ScriptTask st1 = (ScriptTask) t1;
        ScriptTask st2 = (ScriptTask) t2;
        if (!isEqualScript(st1.getScript(), st2.getScript()))
            return false;
    }
    return true;
}
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) SelectionScript(org.ow2.proactive.scripting.SelectionScript) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) HashSet(java.util.HashSet)

Example 73 with JavaTask

use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.

the class TestGetUsage method createJob.

private TaskFlowJob createJob() throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(this.getClass().getSimpleName());
    JavaTask javaTask = new JavaTask();
    javaTask.setExecutableClassName(TestJavaTask.class.getName());
    javaTask.setName("Test task");
    job.addTask(javaTask);
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 74 with JavaTask

use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.

the class TestMultipleUsersMakingMassivGetResultRequest method testMultipleUsersMakingMassivGetResultRequest.

@Test
public void testMultipleUsersMakingMassivGetResultRequest() throws Throwable {
    final SchedulerAuthenticationInterface auth = schedulerHelper.getSchedulerAuth();
    // create a job
    final TaskFlowJob job = new TaskFlowJob();
    for (int i = 0; i < taskPerJob; i++) {
        JavaTask task = new JavaTask();
        task.setName("jt" + i);
        task.setExecutableClassName(EmptyTask.class.getName());
        job.addTask(task);
    }
    // start threads
    for (int i = 0; i < ThreadNumber; i++) {
        new Thread() {

            @Override
            public void run() {
                try {
                    // connect the scheduler
                    log(Thread.currentThread().getName() + " -> Connecting the scheduler");
                    Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey());
                    Scheduler user = auth.login(cred);
                    log(Thread.currentThread().getName() + " -> Connected");
                    long start = System.currentTimeMillis();
                    int submitted = 1;
                    while (true) {
                        log(Thread.currentThread().getName() + " -> Submit (" + submitted + ")");
                        JobId id = user.submit(job);
                        JobResult jr = null;
                        while (jr == null) {
                            Thread.sleep(getResultDelay);
                            jr = user.getJobResult(id);
                        }
                        if (System.currentTimeMillis() - start > jobSubmissionDuration) {
                            log(Thread.currentThread().getName() + " -> Terminate");
                            nbFinished++;
                            break;
                        }
                        submitted++;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }
    while (nbFinished < ThreadNumber) {
        Thread.sleep(100);
    }
    log("All threads terminated.");
}
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) CredData(org.ow2.proactive.authentication.crypto.CredData) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) EmptyTask(org.ow2.proactive.scheduler.examples.EmptyTask) Credentials(org.ow2.proactive.authentication.crypto.Credentials) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 75 with JavaTask

use of org.ow2.proactive.scheduler.common.task.JavaTask in project scheduling by ow2-proactive.

the class TestKilledJobResult method test.

@Test
public void test() throws Throwable {
    TaskFlowJob job = new TaskFlowJob();
    JavaTask task1 = new JavaTask();
    task1.setName("task1");
    task1.setExecutableClassName(TestJavaTask1.class.getName());
    job.addTask(task1);
    JavaTask task2 = new JavaTask();
    task2.setName("task2");
    task2.setExecutableClassName(TestJavaTask2.class.getName());
    job.addTask(task2);
    task2.addDependence(task1);
    log("Submit job");
    JobId jobId = schedulerHelper.submitJob(job);
    log("Submitted job " + jobId);
    log("Waiting for task1 to finish");
    schedulerHelper.waitForEventTaskFinished(jobId, "task1");
    schedulerHelper.waitForEventTaskRunning(jobId, "task2");
    Scheduler scheduler = schedulerHelper.getSchedulerInterface();
    log("Killing job");
    scheduler.killJob(jobId);
    log("Wait when job finishes");
    schedulerHelper.waitForEventJobFinished(jobId);
    JobResult jobResult = scheduler.getJobResult(jobId);
    printResult(jobResult);
    assertEquals(1, jobResult.getAllResults().size());
    assertEquals("OK", jobResult.getAllResults().get("task1").value().toString());
    JobInfo jobInfo = jobResult.getJobInfo();
    assertEquals(JobStatus.KILLED, jobInfo.getStatus());
    assertEquals(1, jobInfo.getNumberOfFinishedTasks());
    assertEquals(2, jobInfo.getTotalNumberOfTasks());
    assertEquals(0, jobInfo.getNumberOfPendingTasks());
    assertEquals(0, jobInfo.getNumberOfRunningTasks());
    JobState state = scheduler.getJobState(jobId);
    assertEquals(JobStatus.KILLED, state.getStatus());
    assertEquals(1, state.getNumberOfFinishedTasks());
    assertEquals(2, state.getTotalNumberOfTasks());
    assertEquals(0, state.getNumberOfPendingTasks());
    assertEquals(0, state.getNumberOfRunningTasks());
    assertEquals(2, state.getTasks().size());
    assertEquals(TaskStatus.FINISHED, findTask(state, "task1").getStatus());
    assertEquals(TaskStatus.ABORTED, findTask(state, "task2").getStatus());
    TaskState taskState0 = state.getTasks().get(0);
    TaskState taskState1 = state.getTasks().get(1);
    assertTrue(taskState0.getStartTime() > 0);
    assertTrue(taskState0.getFinishedTime() > 0);
    assertTrue(taskState0.getExecutionDuration() >= 0);
    assertTrue(taskState0.getExecutionDuration() <= taskState0.getFinishedTime() - taskState0.getStartTime());
    assertTrue(taskState1.getStartTime() > 0);
    assertTrue(taskState1.getFinishedTime() > 0);
    assertTrue(taskState1.getExecutionDuration() >= 0);
    assertTrue(taskState1.getExecutionDuration() <= taskState1.getFinishedTime() - taskState1.getStartTime());
}
Also used : Scheduler(org.ow2.proactive.scheduler.common.Scheduler) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) TaskState(org.ow2.proactive.scheduler.common.task.TaskState) Test(org.junit.Test)

Aggregations

TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)104 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)104 Test (org.junit.Test)44 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)24 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)20 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)18 JobId (org.ow2.proactive.scheduler.common.job.JobId)14 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)14 EmptyTask (org.ow2.proactive.scheduler.examples.EmptyTask)13 SelectionScript (org.ow2.proactive.scripting.SelectionScript)12 SimpleScript (org.ow2.proactive.scripting.SimpleScript)12 File (java.io.File)11 TaskResultImpl (org.ow2.proactive.scheduler.task.TaskResultImpl)11 HashMap (java.util.HashMap)10 Task (org.ow2.proactive.scheduler.common.task.Task)9 JobResult (org.ow2.proactive.scheduler.common.job.JobResult)7 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)6 EmptyExecutable (functionaltests.executables.EmptyExecutable)5 JobDescriptor (org.ow2.proactive.scheduler.common.JobDescriptor)5 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)5