Search in sources :

Example 16 with JobVariable

use of org.ow2.proactive.scheduler.common.job.JobVariable in project scheduling by ow2-proactive.

the class Job2XMLTransformerTest method checkJobVariables.

@Test
public void checkJobVariables() throws Exception {
    File xmlFile = tmpFolder.newFile();
    Map<String, JobVariable> variablesMap = new HashMap<>();
    JobVariable jobVar1 = new JobVariable("name1", "value1", "model1");
    JobVariable jobVar2 = new JobVariable("name2", "value2", "model2", "description2", "group2", true, true);
    variablesMap.put(jobVar1.getName(), jobVar1);
    variablesMap.put(jobVar2.getName(), jobVar2);
    TaskFlowJob job = new TaskFlowJob();
    JavaTask defaultTask = new JavaTask();
    defaultTask.setExecutableClassName("foo.Bar");
    job.addTask(defaultTask);
    job.setVariables(variablesMap);
    new Job2XMLTransformer().job2xmlFile(job, xmlFile);
    TaskFlowJob recreatedJob = (TaskFlowJob) (JobFactory.getFactory().createJob(xmlFile.getAbsolutePath()));
    Map<String, JobVariable> resVariables = recreatedJob.getVariables();
    assertEquals(2, resVariables.size());
    assertEquals(jobVar1, resVariables.get("name1"));
    assertEquals(jobVar2, resVariables.get("name2"));
}
Also used : HashMap(java.util.HashMap) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) File(java.io.File) Test(org.junit.Test)

Example 17 with JobVariable

use of org.ow2.proactive.scheduler.common.job.JobVariable in project scheduling by ow2-proactive.

the class DefaultModelJobValidatorServiceProviderTest method createJobWithSpelJobModelVariablesUnauthorizedType.

private TaskFlowJob createJobWithSpelJobModelVariablesUnauthorizedType() throws UserException {
    TaskFlowJob job = new TaskFlowJob();
    job.setVariables(ImmutableMap.of("var1", new JobVariable("var1", "value1", SPEL_LEFT + "T(java.lang.Runtime).getRuntime().exec('hostname').waitFor() instanceof T(Integer)" + SPEL_RIGHT)));
    return job;
}
Also used : TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable)

Example 18 with JobVariable

use of org.ow2.proactive.scheduler.common.job.JobVariable in project scheduling by ow2-proactive.

the class SchedulerClientTest method testJobSubmissionEventListener.

@Test(timeout = MAX_WAIT_TIME * 2)
public void testJobSubmissionEventListener() throws Exception {
    ISchedulerClient client = clientInstance();
    SchedulerEventListenerImpl listener = new SchedulerEventListenerImpl();
    client.addEventListener(listener, true, SchedulerEvent.JOB_SUBMITTED, SchedulerEvent.USERS_UPDATE);
    Job job = defaultJob();
    Map<String, JobVariable> jobVariables = new LinkedHashMap<>();
    jobVariables.put("MY_VAR", new JobVariable("MY_VAR", "MY_VALUE", "PA:NOT_EMPTY_STRING", "a test variable", "MY_GROUP", true, true));
    job.setVariables(jobVariables);
    JobId jobId = client.submit(job);
    JobState submittedJob = listener.getSubmittedJob();
    while (!submittedJob.getId().value().equals(jobId.value())) {
        submittedJob = listener.getSubmittedJob();
    }
    UserIdentification userIdentification = listener.getLastUserUpdate();
    assertTrue(userIdentification.getLastSubmitTime() != -1);
    JobInfo jobInfo = client.getJobInfo(jobId.toString());
    System.out.println("Variables = " + jobInfo.getVariables());
    Map<String, JobVariable> stateJobVariables = jobInfo.getDetailedVariables();
    assertEquals(jobVariables, stateJobVariables);
    client.removeEventListener();
    client.waitForJob(jobId, TimeUnit.SECONDS.toMillis(120));
}
Also used : JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) ISchedulerClient(org.ow2.proactive.scheduler.rest.ISchedulerClient) JobState(org.ow2.proactive.scheduler.common.job.JobState) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) SimpleJob(functionaltests.jobs.SimpleJob) Job(org.ow2.proactive.scheduler.common.job.Job) NonTerminatingJob(functionaltests.jobs.NonTerminatingJob) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) UserIdentification(org.ow2.proactive.scheduler.common.job.UserIdentification) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 19 with JobVariable

use of org.ow2.proactive.scheduler.common.job.JobVariable in project scheduling by ow2-proactive.

the class TestJobAttributes method testJobAttribute.

@Test
public void testJobAttribute() throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    job.setMaxNumberOfExecution(10);
    job.setOnTaskError(OnTaskError.CANCEL_JOB);
    job.setDescription("desc");
    job.setProjectName("project");
    job.setName("name");
    job.setInputSpace("input");
    job.setOutputSpace("output");
    job.setGenericInformation(null);
    job.setPriority(JobPriority.HIGHEST);
    InternalJob jobData = defaultSubmitJob(job, DEFAULT_USER_NAME);
    Assert.assertNotNull(jobData.getId());
    Assert.assertEquals("name", jobData.getId().getReadableName());
    jobData = loadInternalJob(true, jobData.getId());
    Assert.assertNotNull(jobData.getId());
    Assert.assertEquals("name", jobData.getId().getReadableName());
    Assert.assertEquals(10, jobData.getMaxNumberOfExecution());
    Assert.assertEquals(OnTaskError.CANCEL_JOB, jobData.getOnTaskErrorProperty().getValue());
    Assert.assertEquals("name", jobData.getName());
    Assert.assertEquals("desc", jobData.getDescription());
    Assert.assertEquals("project", jobData.getProjectName());
    Assert.assertEquals("input", jobData.getInputSpace());
    Assert.assertEquals("output", jobData.getOutputSpace());
    Assert.assertEquals(JobPriority.HIGHEST, jobData.getPriority());
    Assert.assertNotNull(jobData.getGenericInformation());
    Assert.assertTrue(jobData.getGenericInformation().isEmpty());
    Map<String, JobVariable> jobDataVariables = jobData.getVariables();
    Assert.assertNotNull(jobDataVariables);
    Assert.assertTrue(jobDataVariables.isEmpty());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) Test(org.junit.Test)

Example 20 with JobVariable

use of org.ow2.proactive.scheduler.common.job.JobVariable in project scheduling by ow2-proactive.

the class TestJobAttributes method testJobVariables.

@Test
public void testJobVariables() throws Exception {
    TaskFlowJob job = new TaskFlowJob();
    InternalJob jobData;
    HashMap<String, JobVariable> jobVariables = new HashMap<>();
    job.setVariables(jobVariables);
    jobData = defaultSubmitJobAndLoadInternal(false, job);
    Assert.assertNotNull(jobData.getVariables());
    Assert.assertTrue(jobData.getVariables().isEmpty());
    jobVariables.put("var1", new JobVariable("var1", "value1", null));
    jobVariables.put("var2", new JobVariable("var2", "value2", null));
    job.setVariables(jobVariables);
    jobVariables = new HashMap<>();
    jobVariables.put("var1", new JobVariable("var1", "value1", null));
    jobVariables.put("var2", new JobVariable("var2", "value2", null));
    job.setVariables(jobVariables);
    jobData = defaultSubmitJobAndLoadInternal(false, job);
    Assert.assertEquals(2, jobData.getVariables().size());
    Assert.assertEquals("value1", jobData.getVariables().get("var1").getValue());
    Assert.assertEquals("value2", jobData.getVariables().get("var2").getValue());
    StringBuilder longString = new StringBuilder();
    for (int i = 0; i < 100; i++) {
        longString.append("0123456789abcdefghijklmnopqrstuvwxyz");
    }
    jobVariables = new HashMap<>();
    jobVariables.put("longProperty", new JobVariable("longProperty", longString.toString()));
    job.setVariables(jobVariables);
    jobData = defaultSubmitJobAndLoadInternal(false, job);
    Assert.assertEquals(1, jobData.getVariables().size());
    Assert.assertEquals(longString.toString(), jobData.getVariables().get("longProperty").getValue());
}
Also used : InternalJob(org.ow2.proactive.scheduler.job.InternalJob) HashMap(java.util.HashMap) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) Test(org.junit.Test)

Aggregations

JobVariable (org.ow2.proactive.scheduler.common.job.JobVariable)51 Test (org.junit.Test)19 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)17 HashMap (java.util.HashMap)15 LinkedHashMap (java.util.LinkedHashMap)9 Job (org.ow2.proactive.scheduler.common.job.Job)8 JobId (org.ow2.proactive.scheduler.common.job.JobId)8 InternalJob (org.ow2.proactive.scheduler.job.InternalJob)7 JobValidationException (org.ow2.proactive.scheduler.common.exception.JobValidationException)6 Task (org.ow2.proactive.scheduler.common.task.Task)6 TaskVariable (org.ow2.proactive.scheduler.common.task.TaskVariable)6 IOException (java.io.IOException)5 JobCreationException (org.ow2.proactive.scheduler.common.exception.JobCreationException)5 SimpleScript (org.ow2.proactive.scripting.SimpleScript)5 TaskScript (org.ow2.proactive.scripting.TaskScript)5 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)4 SimpleJob (functionaltests.jobs.SimpleJob)4 FileNotFoundException (java.io.FileNotFoundException)4 XMLStreamException (javax.xml.stream.XMLStreamException)4 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)4