Search in sources :

Example 11 with UserException

use of org.ow2.proactive.scheduler.common.exception.UserException in project scheduling by ow2-proactive.

the class TestPropagatedVariables method createTaskFlowJob.

private TaskFlowJob createTaskFlowJob() throws UserException {
    TaskFlowJob flowJob = new TaskFlowJob();
    JavaTask taskA = new JavaTask();
    taskA.setName("Task_A");
    HashMap<String, String> setA = new HashMap<>();
    setA.put("Task_A_Var", "Task_A_Val");
    taskA.addArgument("set", setA);
    taskA.setExecutableClassName(PropagateVariablesExec.class.getName());
    flowJob.addTask(taskA);
    JavaTask taskB = new JavaTask();
    taskB.setName("Task_B");
    HashMap<String, String> setB = new HashMap<>();
    setB.put("Task_B_Var", "Task_B_Val");
    taskB.addArgument("set", setB);
    taskB.setExecutableClassName(PropagateVariablesExec.class.getName());
    flowJob.addTask(taskB);
    JavaTask taskC = new JavaTask();
    taskC.setName("Task_C");
    taskC.addDependence(taskA);
    taskC.addDependence(taskB);
    HashMap<String, String> checkC = new HashMap<>();
    checkC.put("Task_A_Var", "Task_A_Val");
    checkC.put("Task_B_Var", "Task_B_Val");
    taskC.addArgument("check", checkC);
    taskC.setExecutableClassName(PropagateVariablesExec.class.getName());
    flowJob.addTask(taskC);
    if (OperatingSystem.unix == OperatingSystem.getOperatingSystem()) {
        NativeTask taskD = new NativeTask();
        taskD.setName("TaskD");
        taskD.setCommandLine("/bin/bash", "-c", "echo $variables_Task_A_Var; test \"$variables_Task_A_Var\" == \"Task_A_Val\"");
        taskD.addDependence(taskC);
        flowJob.addTask(taskD);
    }
    return flowJob;
}
Also used : PropagateVariablesExec(functionaltests.executables.PropagateVariablesExec) HashMap(java.util.HashMap) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask) NativeTask(org.ow2.proactive.scheduler.common.task.NativeTask)

Example 12 with UserException

use of org.ow2.proactive.scheduler.common.exception.UserException in project scheduling by ow2-proactive.

the class Job2XMLTransformerTest method checkIfOnTaskErrorIsInJobAndTaskInXML.

private void checkIfOnTaskErrorIsInJobAndTaskInXML(OnTaskError jobOnTaskErrorSetting, OnTaskError taskOnTaskErrorSetting) throws UserException, TransformerException, ParserConfigurationException, IOException {
    String taskName = "taskName";
    TaskFlowJob jobWithCancelJobOnErrorTrue = new TaskFlowJob();
    jobWithCancelJobOnErrorTrue.setOnTaskError(jobOnTaskErrorSetting);
    JavaTask task = new JavaTask();
    task.setName(taskName);
    task.setExecutableClassName("oo.Bar");
    task.setOnTaskError(taskOnTaskErrorSetting);
    jobWithCancelJobOnErrorTrue.addTask(task);
    // Check that onTaskError is inside the <job [here] > xml tag
    assertThat("XML must contain onTaskError=\\\"" + jobOnTaskErrorSetting.toString() + "\\\"", new Job2XMLTransformer().jobToxmlString(jobWithCancelJobOnErrorTrue), org.hamcrest.Matchers.matchesPattern(matchEvery + matchJobTagOpening + notMatchSmallerSign + matchOnTaskErrorEquals(jobOnTaskErrorSetting) + matchEvery + matchSmallerSign + matchEvery));
    // Check that onTaskError is inside the <task [here] > xml tag
    assertThat("XML must contain onTaskError=\\\"" + taskOnTaskErrorSetting.toString() + "\\\"", new Job2XMLTransformer().jobToxmlString(jobWithCancelJobOnErrorTrue), org.hamcrest.Matchers.matchesPattern(matchEvery + matchTaskTagOpening + notMatchSmallerSign + matchOnTaskErrorEquals(taskOnTaskErrorSetting) + matchEvery + matchSmallerSign + matchEvery));
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JavaTask(org.ow2.proactive.scheduler.common.task.JavaTask)

Example 13 with UserException

use of org.ow2.proactive.scheduler.common.exception.UserException in project scheduling by ow2-proactive.

the class DefaultModelJobValidatorServiceProviderTest method createJobWithJobModelVariable.

private TaskFlowJob createJobWithJobModelVariable(String value, String model) throws UserException {
    TaskFlowJob job = new TaskFlowJob();
    JobVariable jobVariable = new JobVariable("VAR", value, model);
    job.setVariables(Collections.singletonMap(jobVariable.getName(), jobVariable));
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Example 14 with UserException

use of org.ow2.proactive.scheduler.common.exception.UserException in project scheduling by ow2-proactive.

the class DefaultModelJobValidatorServiceProviderTest method createJobWithSpelJobModelVariablesKO.

private TaskFlowJob createJobWithSpelJobModelVariablesKO() throws UserException {
    TaskFlowJob job = new TaskFlowJob();
    job.setVariables(ImmutableMap.of("var1", new JobVariable("var1", "value1", SPEL_LEFT + "#value == 'value1' ? (variables['var2'] == '' ? (variables['var2'] = 'toto1') instanceof T(String) : true) : false" + SPEL_RIGHT), "var2", new JobVariable("var2", "", SPEL_LEFT + "#value == 'toto2'" + SPEL_RIGHT)));
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Example 15 with UserException

use of org.ow2.proactive.scheduler.common.exception.UserException in project scheduling by ow2-proactive.

the class DefaultModelJobValidatorServiceProviderTest method createJobWithSpelJobModelVariablesOK.

private TaskFlowJob createJobWithSpelJobModelVariablesOK() throws UserException {
    TaskFlowJob job = new TaskFlowJob();
    job.setVariables(ImmutableMap.of("var1", new JobVariable("var1", "value1", SPEL_LEFT + "#value == 'value1' ? (variables['var2'] == '' ? (variables['var2'] = 'toto1') instanceof T(String) : true) : false" + SPEL_RIGHT), "var2", new JobVariable("var2", "", SPEL_LEFT + "#value == 'toto1'" + SPEL_RIGHT)));
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Aggregations

TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)16 JavaTask (org.ow2.proactive.scheduler.common.task.JavaTask)7 Test (org.junit.Test)6 ModelValidatorContext (org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext)6 ScriptTask (org.ow2.proactive.scheduler.common.task.ScriptTask)6 SimpleScript (org.ow2.proactive.scripting.SimpleScript)6 TaskScript (org.ow2.proactive.scripting.TaskScript)5 JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)4 ForkEnvironment (org.ow2.proactive.scheduler.common.task.ForkEnvironment)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 UserException (org.ow2.proactive.scheduler.common.exception.UserException)2 ValidationException (org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException)2 Task (org.ow2.proactive.scheduler.common.task.Task)2 TaskVariable (org.ow2.proactive.scheduler.common.task.TaskVariable)2 SelectionScript (org.ow2.proactive.scripting.SelectionScript)2 PropagateVariablesExec (functionaltests.executables.PropagateVariablesExec)1 HashMap (java.util.HashMap)1 Before (org.junit.Before)1 NativeTask (org.ow2.proactive.scheduler.common.task.NativeTask)1 EmptyTask (org.ow2.proactive.scheduler.examples.EmptyTask)1