Search in sources :

Example 41 with JobVariable

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

the class GlobalVariablesParserTest method testParseConfigTwoVars.

@Test
public void testParseConfigTwoVars() throws IOException {
    GlobalVariablesParser.setConfigurationPath(GlobalVariablesParserTest.class.getResource("global_variables_two_vars.xml").toExternalForm());
    GlobalVariablesParser.getInstance().reloadFilters();
    List<Filter> filters = GlobalVariablesParser.getInstance().getLoadedFilters();
    Assert.assertEquals(1, filters.size());
    Assert.assertEquals(1, filters.get(0).getXpath().size());
    Assert.assertEquals(".", filters.get(0).getXpath().get(0));
    Assert.assertEquals(2, filters.get(0).getVariables().size());
    Assert.assertEquals(new JobVariable("var1", "value1", "model1"), filters.get(0).getVariables().get(0));
    Assert.assertEquals(new JobVariable("var2", "value2", "model2"), filters.get(0).getVariables().get(1));
    GlobalVariablesData globalData = GlobalVariablesParser.getInstance().getVariablesFor(IOUtils.toString(GlobalVariablesParserTest.class.getResource("/org/ow2/proactive/scheduler/common/job/factories/job_no_variables.xml"), PASchedulerProperties.FILE_ENCODING.getValueAsString()));
    ;
    Map<String, JobVariable> globalVariables = globalData.getVariables();
    Assert.assertEquals(2, globalVariables.size());
    Assert.assertEquals(new JobVariable("var1", "value1", "model1"), globalVariables.get("var1"));
    Assert.assertEquals(new JobVariable("var2", "value2", "model2"), globalVariables.get("var2"));
    Map<String, String> globalGI = globalData.getGenericInformation();
    Assert.assertEquals(2, globalGI.size());
    Assert.assertEquals("gi_value1", globalGI.get("gi1"));
    Assert.assertEquals("gi_value2", globalGI.get("gi2"));
}
Also used : JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) Test(org.junit.Test)

Example 42 with JobVariable

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

the class GlobalVariablesParserTest method testParseConfigOneFilterOK.

@Test
public void testParseConfigOneFilterOK() throws IOException {
    GlobalVariablesParser.setConfigurationPath(GlobalVariablesParserTest.class.getResource("global_variables_one_filter.xml").toExternalForm());
    GlobalVariablesParser.getInstance().reloadFilters();
    List<Filter> filters = GlobalVariablesParser.getInstance().getLoadedFilters();
    Assert.assertEquals(1, filters.size());
    Assert.assertEquals(2, filters.get(0).getXpath().size());
    Assert.assertEquals(2, filters.get(0).getVariables().size());
    GlobalVariablesData globalData = GlobalVariablesParser.getInstance().getVariablesFor(IOUtils.toString(GlobalVariablesParserTest.class.getResource("/org/ow2/proactive/scheduler/common/job/factories/job_with_global_variables_and_gi.xml"), PASchedulerProperties.FILE_ENCODING.getValueAsString()));
    Map<String, JobVariable> globalVariables = globalData.getVariables();
    // As this job matches the xpath filters, it will return the configured variables
    Assert.assertEquals(2, globalVariables.size());
    Assert.assertEquals(new JobVariable("var1", "value1", "model1"), globalVariables.get("var1"));
    Assert.assertEquals(new JobVariable("var2", "value2", "model2"), globalVariables.get("var2"));
    Map<String, String> globalGI = globalData.getGenericInformation();
    Assert.assertEquals(2, globalGI.size());
    Assert.assertEquals("gi_value1", globalGI.get("gi1"));
    Assert.assertEquals("gi_value2", globalGI.get("gi2"));
}
Also used : JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) Test(org.junit.Test)

Example 43 with JobVariable

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

the class GetJobContentGeneratorTest method testReplaceVars.

@Test
public void testReplaceVars() throws IOException {
    URL url = Resources.getResource("org/ow2/proactive/scheduler/common/job/factories/job_with_vars_and_info.xml");
    String jobContent = Resources.toString(url, Charsets.UTF_8);
    Map<String, JobVariable> vars = new HashMap<>();
    vars.put("var", new JobVariable("var", "myvalue"));
    final String newJobContent = generator.replaceVarsAndGenericInfo(jobContent, vars, Collections.emptyMap());
    assertTrue(newJobContent.contains("<variables>"));
    assertTrue(newJobContent.contains("myvalue"));
    assertFalse(newJobContent.contains("<genericInformation>"));
    assertNotEquals(jobContent, newJobContent);
}
Also used : HashMap(java.util.HashMap) JobVariable(org.ow2.proactive.scheduler.common.job.JobVariable) URL(java.net.URL) Test(org.junit.Test)

Example 44 with JobVariable

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

the class SchedulerClientTest method testReSubmitJobReplaceVarValue.

@Test
public void testReSubmitJobReplaceVarValue() throws Exception {
    ISchedulerClient client = clientInstance();
    Job job = nodeClientJob("/functionaltests/descriptors/dataspace_client_node_push_delete.groovy", "/functionaltests/descriptors/dataspace_client_node_fork.groovy", null);
    job.getVariables().put("originalVar", new JobVariable("originalVar", "originalValue"));
    JobId jobId = submitJob(job, client);
    Map<String, String> vars = new HashMap<>();
    vars.put("originalVar", "newValue");
    JobId jobId1 = client.reSubmit(jobId, vars, Collections.emptyMap(), null);
    String jobContent1 = client.getJobContent(jobId1);
    assertTrue(jobContent1.contains("<variables>"));
    assertTrue(jobContent1.contains("originalVar"));
    assertTrue(jobContent1.contains("newValue"));
    assertFalse(jobContent1.contains("originalValue"));
    assertFalse(jobContent1.contains("<genericInformation>"));
}
Also used : ISchedulerClient(org.ow2.proactive.scheduler.rest.ISchedulerClient) 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) JobId(org.ow2.proactive.scheduler.common.job.JobId) Test(org.junit.Test)

Example 45 with JobVariable

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

the class SchedulerClientTest method testSignals.

@Test(timeout = MAX_WAIT_TIME)
public void testSignals() throws Throwable {
    ISchedulerClient client = clientInstance();
    Job job = nodeClientJob("/functionaltests/descriptors/register_service_with_signals.groovy", null, null);
    // submit job with 'ready signal' and add variables
    JobId jobId = submitJob(job, client);
    JobInfo jobInfo;
    // wait until 'ready_my_signal' signal is sent
    do {
        jobInfo = client.getJobInfo(jobId.toString());
        Assert.assertNotNull(jobInfo);
        Thread.sleep(1000);
    } while (!jobInfo.getSignals().contains("ready_my_signal"));
    Map<String, String> outpuVariables = new HashMap<>();
    outpuVariables.put("name", "15");
    // validate the job variables
    List<JobVariable> jobVariables = client.validateJobSignal(jobId.value(), "my_signal", outpuVariables);
    // add 'my_signal' signal
    Set<String> signals = client.addJobSignal(jobId.value(), "my_signal", outpuVariables);
    // wait until the job is finished
    client.waitForJob(jobId.toString(), TimeUnit.MINUTES.toMillis(5));
    Assert.assertFalse(signals.contains("ready_my_signal"));
    Assert.assertTrue(signals.contains("my_signal"));
    JobVariable nameJobVariable = jobVariables.stream().filter(jobVariable -> jobVariable.getName().equals("name")).findFirst().get();
    Assert.assertNotNull(nameJobVariable);
    Assert.assertEquals("15", nameJobVariable.getValue());
    Assert.assertEquals("PA:Integer", nameJobVariable.getModel());
    JobVariable secondJobVariable = jobVariables.stream().filter(jobVariable -> jobVariable.getName().equals("second")).findFirst().get();
    Assert.assertNotNull(secondJobVariable);
    Assert.assertEquals("15", secondJobVariable.getValue());
    Assert.assertEquals("PA:Integer", secondJobVariable.getModel());
}
Also used : JobInfo(org.ow2.proactive.scheduler.common.job.JobInfo) ISchedulerClient(org.ow2.proactive.scheduler.rest.ISchedulerClient) 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) JobId(org.ow2.proactive.scheduler.common.job.JobId) 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