Commit 0a144df2 authored by cdelbe's avatar cdelbe
Browse files

PICKED FROM TRUNK 15154

SCHEDULING-529 : fix test and clean

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/proactive/scheduling/branches/Scheduling_2.0.x@15159 28e8926c-6b08-0410-baaa-805c5e19b8d6
parent 22c0cf8f
......@@ -278,6 +278,7 @@
<include name="org/ow2/proactive/scheduler/common/util/ObjectArrayFormatter.java" />
<include name="org/ow2/proactive/scheduler/common/TaskTerminateNotification.java" />
<include name="org/ow2/proactive/scheduler/examples/PropertyTask.java" />
<include name="org/ow2/proactive/scheduler/examples/EmptyTask.java" />
<include name="org/ow2/proactive/scheduler/examples/NativeTestWithRandomDefault.java" />
<include name="org/ow2/proactive/scheduler/examples/MonteCarlo.java" />
<include name="org/ow2/proactive/scheduler/examples/JoinPreview.java" />
......
......@@ -52,7 +52,12 @@ public class Exporter {
public static void exportProperty(String key) {
if (System.getProperty(key) == null) {
throw new IllegalArgumentException(key + " is not set as Java Property");
// CHECK SIZE < 255
} else if (key.length() > 255) {
throw new IllegalArgumentException(key +
" name is too long (exported property name length must be less than 256).");
} else if (key.contains(EXPORTED_VARS_VAR_SEPARATOR)) {
throw new IllegalArgumentException(key + " cannot contain character " +
EXPORTED_VARS_VAR_SEPARATOR);
} else {
String allExportedVars = System.getProperty(EXPORTED_PROPERTIES_VAR_NAME);
if (allExportedVars == null) {
......
......@@ -109,7 +109,8 @@ public interface TaskResult extends Serializable {
* Returns a map containing all the java properties that has been exported by this task
* (by the executable or by scripts).
* @see org.ow2.proactive.scripting.Exporter
* @return a map containing all the java properties that has been exported by this task.
* @return a map containing all the java properties that has been exported by this task,
* null if no property has been exported
*/
public Map<String, String> getExportedProperties();
}
......@@ -49,6 +49,7 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
......@@ -60,6 +61,8 @@ import org.hibernate.annotations.Any;
import org.hibernate.annotations.AnyMetaDef;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.MetaValue;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.Type;
......@@ -74,6 +77,7 @@ import org.ow2.proactive.scheduler.common.task.SimpleTaskLogs;
import org.ow2.proactive.scheduler.common.task.TaskId;
import org.ow2.proactive.scheduler.common.task.TaskLogs;
import org.ow2.proactive.scheduler.common.task.TaskResult;
import org.ow2.proactive.scheduler.common.task.util.BigString;
import org.ow2.proactive.scheduler.common.task.util.ResultPreviewTool.SimpleTextPanel;
import org.ow2.proactive.scheduler.util.SchedulerDevLoggers;
import org.ow2.proactive.scheduler.util.classloading.TaskClassLoader;
......@@ -155,11 +159,14 @@ public class TaskResultImpl implements TaskResult {
//Managed by taskInfo, this field is here only to bring taskDuration to core AO
@Transient
private long taskDuration = -1; // TODO : jlscheef transient ?
private long taskDuration = -1;
@Transient
// TODO jlscheef ?
private Map<String, String> exportedProperties;
/** All the properties export through Exporter.exportProperty() */
@Unloadable
@OneToMany(cascade = javax.persistence.CascadeType.ALL)
@Cascade(CascadeType.ALL)
@LazyCollection(value = LazyCollectionOption.FALSE)
private Map<String, BigString> exportedProperties;
/** ProActive empty constructor. */
public TaskResultImpl() {
......@@ -503,7 +510,21 @@ public class TaskResultImpl implements TaskResult {
}
}
/**
* {@inheritDoc}
*/
public Map<String, String> getExportedProperties() {
return this.exportedProperties;
// null if no prop has been exported
if (this.exportedProperties == null) {
return null;
} else {
// do not return to user internal type BigString
Map<String, String> convertedProperties = new Hashtable<String, String>(this.exportedProperties
.size());
for (String k : this.exportedProperties.keySet()) {
convertedProperties.put(k, this.exportedProperties.get(k).getValue());
}
return convertedProperties;
}
}
}
......@@ -74,6 +74,7 @@ import org.ow2.proactive.scheduler.common.task.TaskResult;
import org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector;
import org.ow2.proactive.scheduler.common.task.dataspaces.OutputSelector;
import org.ow2.proactive.scheduler.common.task.executable.Executable;
import org.ow2.proactive.scheduler.common.task.util.BigString;
import org.ow2.proactive.scheduler.common.util.logforwarder.AppenderProvider;
import org.ow2.proactive.scheduler.common.util.logforwarder.LogForwardingException;
import org.ow2.proactive.scheduler.common.util.logforwarder.appenders.AsyncAppenderWithStorage;
......@@ -313,8 +314,6 @@ public abstract class TaskLauncher implements InitActive {
.getReadableName());
System.setProperty(SchedulerVars.JAVAENV_TASK_ID_VARNAME.toString(), this.taskId.value());
System.setProperty(SchedulerVars.JAVAENV_TASK_NAME_VARNAME.toString(), this.taskId.getReadableName());
// set exported vars
}
/**
......@@ -353,19 +352,19 @@ public abstract class TaskLauncher implements InitActive {
* @see org.ow2.proactive.scripting.Exporter
* @return a map that contains [name->value] of all exported properties.
*/
protected Map<String, String> retreiveExportedProperties() {
protected Map<String, BigString> retreiveExportedProperties() {
// get all names of exported vars
String allVars = System.getProperty(Exporter.EXPORTED_PROPERTIES_VAR_NAME);
if (allVars != null) {
logger_dev.info("Exported properties for task " + this.taskId + " are : " + allVars);
StringTokenizer parser = new StringTokenizer(allVars, Exporter.EXPORTED_VARS_VAR_SEPARATOR);
Map<String, String> exportedVars = new Hashtable<String, String>();
Map<String, BigString> exportedVars = new Hashtable<String, BigString>();
while (parser.hasMoreTokens()) {
String key = parser.nextToken();
String value = System.getProperty(key);
if (value != null) {
logger_dev.debug("Value of exported property " + key + " is " + value);
exportedVars.put(key, value);
exportedVars.put(key, new BigString(value));
System.clearProperty(key);
} else {
logger_dev.warn("Exported property " + key + " is not set !");
......
......@@ -34,7 +34,7 @@
*/
package functionaltests;
import java.util.Map.Entry;
import java.util.Map;
import org.junit.Assert;
import org.ow2.proactive.scheduler.common.job.JobId;
......@@ -57,25 +57,29 @@ public class TestExportVars extends FunctionalTest {
@org.junit.Test
public void run() throws Throwable {
JobId id = SchedulerTHelper.submitJob(jobDescriptor);
// Assert.assertFalse(SchedulerTHelper.getJobResult(id).hadException());
SchedulerTHelper.waitForEventJobFinished(id);
// check result are not null
JobResult res = SchedulerTHelper.getJobResult(id);
// Assert.assertFalse(SchedulerTHelper.getJobResult(id).hadException());
//
// for (Entry<String, TaskResult> entry : res.getAllResults().entrySet()) {
// Assert.assertNotNull(entry.getValue().value());
// }
// //remove job
// SchedulerTHelper.removeJob(id);
// SchedulerTHelper.waitForEventJobRemoved(id);
for (String n : res.getAllResults().keySet()) {
TaskResult r = res.getResult(n);
System.out.println(n + " result : [" + r + "]");
System.out.println(n + " logs : [" + r.getOutput().getAllLogs(false) + "]");
for (String i : res.getAllResults().keySet()) {
System.out.println("==>" + i);
}
String taskid = "task1";
TaskResult r = res.getResult(taskid);
Map<String, String> exVal = r.getExportedProperties();
Assert.assertTrue(exVal != null);
Assert.assertTrue(exVal.get("key1").equals("value1"));
Assert.assertTrue(exVal.get("key2").equals("value2"));
taskid = "task2";
r = res.getResult(taskid);
// no exception in post script evaluation
Assert.assertTrue(!r.hadException());
taskid = "task3ex";
r = res.getResult(taskid);
// exception in post script evaluation
Assert.assertTrue(r.hadException());
}
}
<?xml version="1.0" encoding="UTF-8"?>
<job xmlns="urn:proactive:jobdescriptor:dev" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:proactive:jobdescriptor:dev ../../../src/org/ow2/proactive/scheduler/common/xml/schemas/jobdescriptor/dev/schedulerjob.xsd"
name="job_pre_post" cancelJobOnError="true" priority="normal">
<variables>
<!-- pa.scheduler.home is known as java property - ie : start with -Dpa.scheduler.home=value -->
<variable name="WORK_DIR" value="${pa.scheduler.home}/samples/scripts/misc"/>
</variables>
name="job_export_var" cancelJobOnError="false" priority="normal">
<description>Export variables</description>
<taskFlow>
<task name="task1.1" preciousResult="true">
<task name="task1" preciousResult="true">
<pre>
<script>
......@@ -19,33 +15,33 @@
java.lang.System.setProperty("key2", "value2");
print("Setting system property key2 = " + java.lang.System.getProperty("key2") + "\n");
Exporter.exportProperty("key1");
Exporter.exportProperty("key2");
</code>
</script>
</pre>
<javaExecutable class="org.ow2.proactive.scheduler.examples.PropertyTask"/>
<javaExecutable class="org.ow2.proactive.scheduler.examples.EmptyTask"/>
<post>
<script>
<code language="javascript">
//importClass(org.ow2.proactive.scripting.Exporter);
//Exporter.exportProperty("user.property1");
</code>
<code language="javascript">
importClass(org.ow2.proactive.scripting.Exporter);
Exporter.exportProperty("key2");
</code>
</script>
</post>
</task>
<task name="task2" preciousResult="true">
<depends>
<task ref="task1.1"/>
<task ref="task1"/>
</depends>
<pre>
<script>
<code language="javascript">
print("exported.vars = " + java.lang.System.getProperty("exported.vars"));
print("Get system property key1 = " + java.lang.System.getProperty("key1") + "\n");
print("Get system property key2 = " + java.lang.System.getProperty("key2") + "\n");
print("Get system property user.property1 = " + java.lang.System.getProperty("user.property1") + "\n");
var v1 = java.lang.System.getProperty("key1");
var v2 = java.lang.System.getProperty("key2");
if (v1!="value1"){thrrrrow.me.An.exception();}
if (v2!="value2"){thrrrrow.me.An.exception();}
</code>
</script>
</pre>
......@@ -55,5 +51,19 @@
</staticCommand>
</nativeExecutable>
</task>
<task name="task3ex" preciousResult="true">
<pre>
<script>
<code language="javascript">
importClass(org.ow2.proactive.scripting.Exporter);
Exporter.exportProperty("prohibited%name");
</code>
</script>
</pre>
<javaExecutable class="org.ow2.proactive.scheduler.examples.EmptyTask"/>
</task>
</taskFlow>
</job>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment