Search in sources :

Example 1 with UserException

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

the class DefaultModelJobValidatorServiceProviderTest method createJobWithTaskModelVariable.

private TaskFlowJob createJobWithTaskModelVariable(String value, String model) throws UserException {
    TaskFlowJob job = new TaskFlowJob();
    TaskVariable variable = new TaskVariable("VAR", value, model, false);
    Task task = new ScriptTask();
    task.setName("ModelTask");
    task.setVariables(Collections.singletonMap(variable.getName(), variable));
    job.addTask(task);
    return job;
}
Also used : Task(org.ow2.proactive.scheduler.common.task.Task) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) TaskVariable(org.ow2.proactive.scheduler.common.task.TaskVariable)

Example 2 with UserException

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

the class SpelValidatorTest method testSpelOKUpdateTaskVariable.

@Test
public void testSpelOKUpdateTaskVariable() throws ValidationException, UserException {
    SpelValidator validator = new SpelValidator("#value == 'MyString'?(variables['var1'] = 'toto1') instanceof T(String) : false");
    String value = "MyString";
    ModelValidatorContext context = new ModelValidatorContext(createTask());
    Assert.assertEquals(value, validator.validate(value, context));
    Assert.assertEquals("toto1", context.getSpELVariables().getVariables().get("var1"));
}
Also used : ModelValidatorContext(org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext) Test(org.junit.Test)

Example 3 with UserException

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

the class SpelValidatorTest method testSpelOKUpdateJobVariableWhenEmptyOK.

@Test
public void testSpelOKUpdateJobVariableWhenEmptyOK() throws ValidationException, UserException {
    SpelValidator validator = new SpelValidator("#value == 'MyString' ? (variables['var4'] == null ? (variables['var4'] = 'toto1') instanceof T(String) : true) : false");
    String value = "MyString";
    ModelValidatorContext context = new ModelValidatorContext(createJob());
    Assert.assertEquals(value, validator.validate(value, context));
    Assert.assertEquals("toto1", context.getSpELVariables().getVariables().get("var4"));
}
Also used : ModelValidatorContext(org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext) Test(org.junit.Test)

Example 4 with UserException

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

the class SpelValidatorTest method testSpelOKUpdateJobVariableWhenEmptyKO.

@Test
public void testSpelOKUpdateJobVariableWhenEmptyKO() throws ValidationException, UserException {
    SpelValidator validator = new SpelValidator("#value == 'MyString' ? (variables['var2'] == null ? (variables['var2'] = 'toto1') instanceof T(String) : true) : false");
    String value = "MyString";
    ModelValidatorContext context = new ModelValidatorContext(createJob());
    Assert.assertEquals(value, validator.validate(value, context));
    Assert.assertEquals("value2", context.getSpELVariables().getVariables().get("var2"));
}
Also used : ModelValidatorContext(org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidatorContext) Test(org.junit.Test)

Example 5 with UserException

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

the class TestDataspaceConcurrentTransfer method createJobWithFileTransfers.

public Job createJobWithFileTransfers() throws UserException, InvalidScriptException {
    TaskFlowJob job = new TaskFlowJob();
    job.setName(JOB_NAME);
    job.setOnTaskError(OnTaskError.CONTINUE_JOB_EXECUTION);
    for (int i = 0; i < NB_TASKS; i++) {
        ScriptTask st1 = new ScriptTask();
        st1.setName(TASK_NAME_CREATE + i);
        st1.setScript(new TaskScript(new SimpleScript("org.apache.commons.io.FileUtils.touch(new File(localspace, \"" + FOLDER_IN_NAME + i + "/" + FILE_NAME + i + FILE_EXT_IN + "\"));", "groovy")));
        st1.addOutputFiles("**/*" + FILE_EXT_IN, OutputAccessMode.TransferToGlobalSpace);
        job.addTask(st1);
        ScriptTask st2 = new ScriptTask();
        st2.setName(TASK_NAME_PROCESS + i);
        st2.setScript(new TaskScript(new SimpleScript("org.apache.commons.io.FileUtils.copyFile(new File(localspace, \"" + FOLDER_IN_NAME + i + "/" + FILE_NAME + i + FILE_EXT_IN + "\"), new File(localspace, \"" + FOLDER_OUT_NAME + i + "/" + FILE_NAME + i + FILE_EXT_OUT + "\"));", "groovy")));
        st2.addInputFiles(FOLDER_IN_NAME + i + "/" + FILE_NAME + i + FILE_EXT_IN, InputAccessMode.TransferFromGlobalSpace);
        st2.addOutputFiles("**/*" + FILE_EXT_OUT, OutputAccessMode.TransferToGlobalSpace);
        st2.addDependence(st1);
        job.addTask(st2);
    }
    return job;
}
Also used : ScriptTask(org.ow2.proactive.scheduler.common.task.ScriptTask) TaskScript(org.ow2.proactive.scripting.TaskScript) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleScript(org.ow2.proactive.scripting.SimpleScript)

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