Search in sources :

Example 66 with JavaTask

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

the class TestKillWhenInStoppedState method createPendingJob.

private TaskFlowJob createPendingJob() throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName("Test pending job");
    job.setOnTaskError(OnTaskError.CONTINUE_JOB_EXECUTION);
    JavaTask javaTask = new JavaTask();
    javaTask.setExecutableClassName(TestJavaTask.class.getName());
    javaTask.setName(TASK_NAME2);
    javaTask.setSelectionScript(new SelectionScript("selected = false;", "JavaScript", false));
    job.addTask(javaTask);
    return job;
}
Also used : SelectionScript(org.ow2.proactive.scripting.SelectionScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 67 with JavaTask

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

the class ByteCompressionUtilsTest method setup.

@Before
public void setup() throws UserException {
    job = new TaskFlowJob();
    job.setName(this.getClass().getName());
    job.addTask(new JavaTask());
    jobByte = SerializationUtils.serialize(job);
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) Before(org.junit.Before)

Example 68 with JavaTask

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

the class StaxJobFactory method createTask.

/**
 * Fill the given task by the information that are at the given cursorTask.
 * Leave the method with the cursor at the end of 'ELEMENT_TASK' tag.
 *
 * @param cursorTask the streamReader with the cursor on the 'ELEMENT_TASK' tag.
 * @return The newly created task that can be any type.
 */
private Task createTask(XMLStreamReader cursorTask, Job job, Map<String, ArrayList<String>> dependencies) throws JobCreationException {
    int i = 0;
    XMLTags currentTag = null;
    String current = null;
    String taskName = null;
    try {
        Task toReturn = null;
        Task tmpTask = new Task() {
        };
        // parse job attributes and fill the temporary one
        int attrLen = cursorTask.getAttributeCount();
        for (i = 0; i < attrLen; i++) {
            String attributeName = cursorTask.getAttributeLocalName(i);
            String attributeValue = cursorTask.getAttributeValue(i);
            if (XMLAttributes.COMMON_NAME.matches(attributeName)) {
                tmpTask.setName(attributeValue);
                taskName = attributeValue;
            } else if (XMLAttributes.TASK_NB_NODES.matches(attributeName)) {
                int numberOfNodesNeeded = Integer.parseInt(replace(attributeValue, tmpTask.getVariablesOverriden(job)));
                tmpTask.setParallelEnvironment(new ParallelEnvironment(numberOfNodesNeeded));
            } else if (XMLAttributes.COMMON_CANCEL_JOB_ON_ERROR.matches(attributeName)) {
                handleCancelJobOnErrorAttribute(tmpTask, attributeValue);
            } else if (XMLAttributes.COMMON_ON_TASK_ERROR.matches(attributeName)) {
                tmpTask.setOnTaskError(OnTaskError.getInstance(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.COMMON_RESTART_TASK_ON_ERROR.matches(attributeName)) {
                tmpTask.setRestartTaskOnError(RestartMode.getMode(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.COMMON_MAX_NUMBER_OF_EXECUTION.matches(attributeName)) {
                tmpTask.setMaxNumberOfExecution(Integer.parseInt(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.TASK_PRECIOUS_RESULT.matches(attributeName)) {
                tmpTask.setPreciousResult(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.TASK_PRECIOUS_LOGS.matches(attributeName)) {
                tmpTask.setPreciousLogs(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.TASK_WALLTIME.matches(attributeName)) {
                tmpTask.setWallTime(Tools.formatDate(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            } else if (XMLAttributes.TASK_RUN_AS_ME.matches(attributeName)) {
                tmpTask.setRunAsMe(Boolean.parseBoolean(replace(attributeValue, tmpTask.getVariablesOverriden(job))));
            }
        }
        int eventType;
        boolean shouldContinue = true;
        while (shouldContinue && cursorTask.hasNext()) {
            eventType = cursorTask.next();
            switch(eventType) {
                case XMLEvent.START_ELEMENT:
                    current = cursorTask.getLocalName();
                    currentTag = null;
                    if (XMLTags.COMMON_GENERIC_INFORMATION.matches(current)) {
                        tmpTask.setGenericInformation(getGenericInformation(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.VARIABLES.matches(current)) {
                        Map<String, TaskVariable> taskVariablesMap = createTaskVariables(cursorTask, tmpTask.getVariablesOverriden(job));
                        tmpTask.setVariables(taskVariablesMap);
                    } else if (XMLTags.COMMON_DESCRIPTION.matches(current)) {
                        tmpTask.setDescription(getDescription(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.DS_INPUT_FILES.matches(current)) {
                        setIOFIles(cursorTask, XMLTags.DS_INPUT_FILES.getXMLName(), tmpTask, tmpTask.getVariablesOverriden(job));
                    } else if (XMLTags.DS_OUTPUT_FILES.matches(current)) {
                        setIOFIles(cursorTask, XMLTags.DS_OUTPUT_FILES.getXMLName(), tmpTask, tmpTask.getVariablesOverriden(job));
                    } else if (XMLTags.PARALLEL_ENV.matches(current)) {
                        tmpTask.setParallelEnvironment(createParallelEnvironment(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.SCRIPT_SELECTION.matches(current)) {
                        tmpTask.setSelectionScripts(createSelectionScript(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.FORK_ENVIRONMENT.matches(current)) {
                        tmpTask.setForkEnvironment(createForkEnvironment(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.SCRIPT_PRE.matches(current)) {
                        tmpTask.setPreScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.SCRIPT_POST.matches(current)) {
                        tmpTask.setPostScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.SCRIPT_CLEANING.matches(current)) {
                        tmpTask.setCleaningScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.FLOW.matches(current)) {
                        tmpTask.setFlowScript(createControlFlowScript(cursorTask, tmpTask, tmpTask.getVariablesOverriden(job)));
                    } else if (XMLTags.TASK_DEPENDENCES.matches(current)) {
                        currentTag = XMLTags.TASK_DEPENDENCES;
                        dependencies.putAll(createDependences(cursorTask, tmpTask));
                    } else if (XMLTags.JAVA_EXECUTABLE.matches(current)) {
                        toReturn = new JavaTask();
                        setJavaExecutable((JavaTask) toReturn, cursorTask, tmpTask.getVariablesOverriden(job));
                    } else if (XMLTags.NATIVE_EXECUTABLE.matches(current)) {
                        toReturn = new NativeTask();
                        setNativeExecutable((NativeTask) toReturn, cursorTask);
                    } else if (XMLTags.SCRIPT_EXECUTABLE.matches(current)) {
                        toReturn = new ScriptTask();
                        ((ScriptTask) toReturn).setScript(new TaskScript(createScript(cursorTask, tmpTask.getVariablesOverriden(job))));
                    }
                    break;
                case XMLEvent.END_ELEMENT:
                    current = cursorTask.getLocalName();
                    if (XMLTags.TASK.matches(cursorTask.getLocalName())) {
                        shouldContinue = false;
                    }
                    break;
            }
        }
        // fill the real task with common attribute if it is a new one
        autoCopyfields(CommonAttribute.class, tmpTask, toReturn);
        autoCopyfields(Task.class, tmpTask, toReturn);
        if (toReturn != null) {
            if (toReturn.getRestartTaskOnErrorProperty().isSet()) {
                toReturn.setRestartTaskOnError(toReturn.getRestartTaskOnError());
            }
            if (toReturn.getMaxNumberOfExecutionProperty().isSet()) {
                toReturn.setMaxNumberOfExecution(toReturn.getMaxNumberOfExecution());
            }
        }
        return toReturn;
    } catch (JobCreationException jce) {
        jce.setTaskName(taskName);
        if (currentTag != null) {
            jce.pushTag(currentTag);
        } else {
            jce.pushTag(current);
        }
        throw jce;
    } catch (Exception e) {
        String attrtmp = null;
        if (cursorTask.isStartElement() && cursorTask.getAttributeCount() > i) {
            attrtmp = cursorTask.getAttributeLocalName(i);
        }
        if (currentTag != null) {
            throw new JobCreationException(currentTag, attrtmp, e);
        } else {
            throw new JobCreationException(current, attrtmp, e);
        }
    }
}
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) TaskScript(org.ow2.proactive.scripting.TaskScript) JobCreationException(org.ow2.proactive.scheduler.common.exception.JobCreationException) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask) 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) ParallelEnvironment(org.ow2.proactive.scheduler.common.task.ParallelEnvironment) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 69 with JavaTask

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

the class TestLoadJobsPagination method createJob.

private TaskFlowJob createJob(String name, JobPriority priority) throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(name);
    job.setPriority(priority);
    JavaTask task = new JavaTask();
    task.setExecutableClassName("className");
    job.addTask(task);
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 70 with JavaTask

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

the class Many2OneaskDependencySchedulingTest method createJob.

private TaskFlowJob createJob(int numberOfTasks) throws UserException {
    TaskFlowJob job = new TaskFlowJob();
    JavaTask poorGuyWaitsForAll = new JavaTask();
    poorGuyWaitsForAll.setName("poorGuyWaitsForAll");
    poorGuyWaitsForAll.setExecutableClassName(EmptyTask.class.getName());
    for (int i = 0; i < numberOfTasks; i++) {
        JavaTask task = new JavaTask();
        task.setName("JavaTask_" + i);
        task.setExecutableClassName(EmptyTask.class.getName());
        poorGuyWaitsForAll.addDependence(task);
        job.addTask(task);
    }
    job.addTask(poorGuyWaitsForAll);
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) EmptyTask(org.ow2.proactive.scheduler.examples.EmptyTask)

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