Commit fca2a335 authored by cdelbe's avatar cdelbe
Browse files

PICKED FROM TRUNK 15157

SCHEDULING-529 : rename Exporter into PropertyUtils, add doc

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/proactive/scheduling/branches/Scheduling_2.0.x@15162 28e8926c-6b08-0410-baaa-805c5e19b8d6
parent 6fd0b74d
......@@ -15,7 +15,7 @@
<copy toDir="${cl.scheduler.tests.dir}">
<fileset dir="${src.scheduler.tests.dir}" excludes="**/*.java"/>
</copy>
<chmod file="${cl.scheduler.tests.dir}/functionaltests/executables/exportedVars.sh" perm="ugo+x"/>
<javac
srcdir="${src.scheduler.dir}"
destdir="${cl.scheduler.dir}"
......
......@@ -1006,6 +1006,16 @@ task2.setGenerationScript(gscript);
for file transfer purposes to manage file copies.
Some script samples are available in 'samples/scripts/filetransfer' directory.
</para>
<para>
Another helper is provided for transmitting Java properties to either forked environment (native
or forked Java task) or to all dependent tasks, namely the org.ow2.proactive.scripting.helper.PropertyUtils
class. The exportProperty(String name) method makes the property available in the native environment as a
system variable (renamed like my.java.property becomes MY_JAVA_PROPERTY). The propagateProperty(String name)
makes the property available in the java environment as a Java property (not renamed) of all the dependent tasks.
Note that if several value for a single property a propagated to a single task (i.e. a task with several parents),
the resulting value is not specified and can be any of the propagated value.
</para>
</listitem>
<listitem>
<para>
......@@ -1014,7 +1024,9 @@ task2.setGenerationScript(gscript);
A boolean variable named "success" is available in this script in order to
inform user about the success of the task execution. if success is true, the execution
has finished successfully, if not, execution has generated an exception.
The same helper than for pre-script can be used in the post-script.
The same helpers than for pre-script can be used in the post-script, except the
org.ow2.proactive.scripting.helper.PropertyUtils.exportProperty(String name) which has no effect
since no process can be forked after the post-script.
</para>
</listitem>
<listitem>
......
......@@ -35,10 +35,13 @@
package org.ow2.proactive.scripting;
/**
* This class is used for exporting java property, i.e. make this property available for all dependent tasks.
* This class defines utils for java property, e.g propagating java property, i.e. make this
* property available for all dependent tasks.
*
* @since Scheduling 2.0
*/
public class Exporter {
public class PropertyUtils {
/** Name of the java property that contains the names of currently exported properties */
public final static String PROPAGATED_PROPERTIES_VAR_NAME = "pa.scheduler.propagated.properties.names";
......
......@@ -108,7 +108,7 @@ public interface TaskResult extends Serializable {
/**
* Returns a map containing all the java properties that has been propagated by this task
* (by the executable or by scripts).
* @see org.ow2.proactive.scripting.Exporter
* @see org.ow2.proactive.scripting.PropertyUtils
* @return a map containing all the java properties that has been propagated by this task,
* null if no property has been propagated
*/
......
......@@ -60,7 +60,7 @@ import org.ow2.proactive.scheduler.task.launcher.TaskLauncher.SchedulerVars;
import org.ow2.proactive.scheduler.util.SchedulerDevLoggers;
import org.ow2.proactive.scheduler.util.process.ProcessTreeKiller;
import org.ow2.proactive.scheduler.util.process.ThreadReader;
import org.ow2.proactive.scripting.Exporter;
import org.ow2.proactive.scripting.PropertyUtils;
import org.ow2.proactive.scripting.GenerationScript;
import org.ow2.proactive.scripting.ScriptHandler;
import org.ow2.proactive.scripting.ScriptLoader;
......@@ -221,10 +221,10 @@ public class NativeExecutable extends Executable {
.getProperty(SchedulerVars.JAVAENV_TASK_NAME_VARNAME.toString()));
// exported properties
String allVars = System.getProperty(Exporter.EXPORTED_PROPERTIES_VAR_NAME);
String allVars = System.getProperty(PropertyUtils.EXPORTED_PROPERTIES_VAR_NAME);
Map<String, String> taskExportedProperties = null;
if (allVars != null) {
StringTokenizer parser = new StringTokenizer(allVars, Exporter.VARS_VAR_SEPARATOR);
StringTokenizer parser = new StringTokenizer(allVars, PropertyUtils.VARS_VAR_SEPARATOR);
taskExportedProperties = new Hashtable<String, String>(parser.countTokens());
while (parser.hasMoreTokens()) {
String key = parser.nextToken();
......@@ -236,7 +236,7 @@ public class NativeExecutable extends Executable {
logger_dev.warn("Exported property " + key + " is not set !");
}
}
System.clearProperty(Exporter.EXPORTED_PROPERTIES_VAR_NAME);
System.clearProperty(PropertyUtils.EXPORTED_PROPERTIES_VAR_NAME);
}
// current env
......
......@@ -85,7 +85,7 @@ import org.ow2.proactive.scheduler.task.ExecutableContainer;
import org.ow2.proactive.scheduler.task.KillTask;
import org.ow2.proactive.scheduler.task.launcher.dataspace.AntFileSelector;
import org.ow2.proactive.scheduler.util.SchedulerDevLoggers;
import org.ow2.proactive.scripting.Exporter;
import org.ow2.proactive.scripting.PropertyUtils;
import org.ow2.proactive.scripting.Script;
import org.ow2.proactive.scripting.ScriptHandler;
import org.ow2.proactive.scripting.ScriptLoader;
......@@ -317,8 +317,8 @@ public abstract class TaskLauncher implements InitActive {
System.setProperty(SchedulerVars.JAVAENV_TASK_ID_VARNAME.toString(), this.taskId.value());
System.setProperty(SchedulerVars.JAVAENV_TASK_NAME_VARNAME.toString(), this.taskId.getReadableName());
// previously exported and propagated vars must be deleted
System.clearProperty(Exporter.EXPORTED_PROPERTIES_VAR_NAME);
System.clearProperty(Exporter.PROPAGATED_PROPERTIES_VAR_NAME);
System.clearProperty(PropertyUtils.EXPORTED_PROPERTIES_VAR_NAME);
System.clearProperty(PropertyUtils.PROPAGATED_PROPERTIES_VAR_NAME);
}
/**
......@@ -334,7 +334,7 @@ public abstract class TaskLauncher implements InitActive {
/**
* Set as Java Property all the properties that comes with incoming results, i.e.
* properties that have been propagated in parent tasks.
* @see org.ow2.proactive.scripting.Exporter
* @see org.ow2.proactive.scripting.PropertyUtils
*/
protected void setPropagatedProperties(TaskResult[] incomingResults) {
for (int i = 0; i < incomingResults.length; i++) {
......@@ -354,15 +354,15 @@ public abstract class TaskLauncher implements InitActive {
/**
* Extract name and value of all the properties that have been propagated during the execution
* of this task launcher (on scripts and executable).
* @see org.ow2.proactive.scripting.Exporter
* @see org.ow2.proactive.scripting.PropertyUtils
* @return a map that contains [name->value] of all propagated properties.
*/
protected Map<String, BigString> retreivePropagatedProperties() {
// get all names of propagated vars
String allVars = System.getProperty(Exporter.PROPAGATED_PROPERTIES_VAR_NAME);
String allVars = System.getProperty(PropertyUtils.PROPAGATED_PROPERTIES_VAR_NAME);
if (allVars != null) {
logger_dev.info("Propagated properties for task " + this.taskId + " are : " + allVars);
StringTokenizer parser = new StringTokenizer(allVars, Exporter.VARS_VAR_SEPARATOR);
StringTokenizer parser = new StringTokenizer(allVars, PropertyUtils.VARS_VAR_SEPARATOR);
Map<String, BigString> exportedVars = new Hashtable<String, BigString>();
while (parser.hasMoreTokens()) {
String key = parser.nextToken();
......@@ -375,7 +375,7 @@ public abstract class TaskLauncher implements InitActive {
logger_dev.warn("Propagated property " + key + " is not set !");
}
}
System.clearProperty(Exporter.PROPAGATED_PROPERTIES_VAR_NAME);
System.clearProperty(PropertyUtils.PROPAGATED_PROPERTIES_VAR_NAME);
return exportedVars;
} else {
logger_dev.info("No Propagated properties for task " + this.taskId);
......
......@@ -60,19 +60,10 @@ public class TestExportVars extends FunctionalTest {
SchedulerTHelper.waitForEventJobFinished(id);
JobResult res = SchedulerTHelper.getJobResult(id);
for (String i : res.getAllResults().keySet()) {
System.out.println("====> Output " + i + " : " + res.getResult(i).getOutput().getAllLogs(true));
}
String taskid = "task1";
TaskResult r = res.getResult(taskid);
Map<String, String> exVal = r.getPropagatedProperties();
System.out.println("+++++++++++++");
for (String k : r.getPropagatedProperties().keySet()) {
System.out.println("+++++++++++++" + k);
}
Assert.assertTrue(exVal != null);
Assert.assertTrue(exVal.get("key1").equals("value1"));
Assert.assertTrue(exVal.get("key2").equals("value2"));
......@@ -92,7 +83,6 @@ public class TestExportVars extends FunctionalTest {
taskid = "task5";
r = res.getResult(taskid);
// exception in post script evaluation
System.out.println("***************************************" + r.value());
Assert.assertEquals(0, (Integer) r.value());
}
......
......@@ -12,12 +12,12 @@
<pre>
<script>
<code language="javascript">
importClass(org.ow2.proactive.scripting.Exporter);
importClass(org.ow2.proactive.scripting.PropertyUtils);
java.lang.System.setProperty("key1", "value1");
print("Setting system property key1 = " + java.lang.System.getProperty("key1") + "\n");
java.lang.System.setProperty("key2", "value2");
print("Setting system property key2 = " + java.lang.System.getProperty("key2") + "\n");
Exporter.propagateProperty("key1");
PropertyUtils.propagateProperty("key1");
</code>
</script>
</pre>
......@@ -25,8 +25,8 @@
<post>
<script>
<code language="javascript">
importClass(org.ow2.proactive.scripting.Exporter);
Exporter.propagateProperty("key2");
importClass(org.ow2.proactive.scripting.PropertyUtils);
PropertyUtils.propagateProperty("key2");
</code>
</script>
</post>
......@@ -59,8 +59,8 @@
<pre>
<script>
<code language="javascript">
importClass(org.ow2.proactive.scripting.Exporter);
Exporter.propagateProperty("prohibited%name");
importClass(org.ow2.proactive.scripting.PropertyUtils);
PropertyUtils.propagateProperty("prohibited%name");
</code>
</script>
</pre>
......@@ -72,9 +72,9 @@
<pre>
<script>
<code language="javascript">
importClass(org.ow2.proactive.scripting.Exporter);
importClass(org.ow2.proactive.scripting.PropertyUtils);
java.lang.System.setProperty("user.var.1", ".User Value 1.");
Exporter.propagateProperty("user.var.1");
PropertyUtils.propagateProperty("user.var.1");
</code>
</script>
</pre>
......@@ -89,10 +89,10 @@
<pre>
<script>
<code language="javascript">
importClass(org.ow2.proactive.scripting.Exporter);
importClass(org.ow2.proactive.scripting.PropertyUtils);
java.lang.System.setProperty("user.var.2", ".User Value 2.");
Exporter.exportProperty("user.var.2");
Exporter.exportProperty("user.var.1");
PropertyUtils.exportProperty("user.var.2");
PropertyUtils.exportProperty("user.var.1");
</code>
</script>
</pre>
......
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