Commit 22c0cf8f authored by cdelbe's avatar cdelbe
Browse files

PICKED FROM TRUNK 15153

SCHEDULING-529 : able for now to export Java prop only

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/proactive/scheduling/branches/Scheduling_2.0.x@15158 28e8926c-6b08-0410-baaa-805c5e19b8d6
parent b3785e7d
/*
* ################################################################
*
* ProActive: The Java(TM) library for Parallel, Distributed,
* Concurrent computing with Security and Mobility
*
* Copyright (C) 1997-2009 INRIA/University of
* Nice-Sophia Antipolis/ActiveEon
* Contact: proactive@ow2.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 3 of
* the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* If needed, contact us to obtain a release under GPL Version 2.
*
* Initial developer(s): The ProActive Team
* http://proactive.inria.fr/team_members.htm
* Contributor(s):
*
* ################################################################
* $ACTIVEEON_INITIAL_DEV$
*/
package org.ow2.proactive.scripting;
/**
* This class is used for exporting java property, i.e. make this property available for all dependent tasks.
*/
public class Exporter {
/** Name of the java property that contains the names of currently exported properties */
public final static String EXPORTED_PROPERTIES_VAR_NAME = "pa.scheduler.exported.properties.names";
public final static String EXPORTED_VARS_VAR_SEPARATOR = "%";
/**
* This method allows to export a java property, i.e. make this property available for all dependent tasks.
* @param key the name of the exported property.
* @throws IllegalArgumentException if the property key is not set.
*/
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 {
String allExportedVars = System.getProperty(EXPORTED_PROPERTIES_VAR_NAME);
if (allExportedVars == null) {
System.setProperty(EXPORTED_PROPERTIES_VAR_NAME, "");
allExportedVars = "";
}
System.setProperty(EXPORTED_PROPERTIES_VAR_NAME, allExportedVars + EXPORTED_VARS_VAR_SEPARATOR +
key);
}
}
}
......@@ -35,6 +35,7 @@
package org.ow2.proactive.scheduler.common.task;
import java.io.Serializable;
import java.util.Map;
import javax.swing.JPanel;
......@@ -104,4 +105,11 @@ public interface TaskResult extends Serializable {
*/
public String getTextualDescription();
/**
* 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.
*/
public Map<String, String> getExportedProperties();
}
......@@ -39,6 +39,8 @@ import java.io.IOException;
import java.io.Serializable;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Hashtable;
import java.util.Map;
import javax.persistence.Column;
import javax.persistence.Entity;
......@@ -153,7 +155,11 @@ public class TaskResultImpl implements TaskResult {
//Managed by taskInfo, this field is here only to bring taskDuration to core AO
@Transient
private long taskDuration = -1;
private long taskDuration = -1; // TODO : jlscheef transient ?
@Transient
// TODO jlscheef ?
private Map<String, String> exportedProperties;
/** ProActive empty constructor. */
public TaskResultImpl() {
......@@ -497,4 +503,7 @@ public class TaskResultImpl implements TaskResult {
}
}
}
\ No newline at end of file
public Map<String, String> getExportedProperties() {
return this.exportedProperties;
}
}
......@@ -111,5 +111,4 @@ public class InternalNativeTask extends InternalTask {
return launcher;
}
}
......@@ -117,7 +117,7 @@ public class ForkedJavaTaskLauncher extends JavaTaskLauncher {
} catch (Throwable ex) {
logger_dev.info("", ex);
return new TaskResultImpl(taskId, ex, this.getLogs(), duration);
return new TaskResultImpl(taskId, ex, this.getLogs(), duration, null);
} finally {
cancelTimer();
finalizeTask(core);
......
......@@ -91,6 +91,9 @@ public class JavaTaskLauncher extends TaskLauncher {
//copy datas from OUTPUT or INPUT to local scratch
copyInputDataToScratch();
// set exported vars
this.setExportedProperties(results);
sample = System.currentTimeMillis();
//launch pre script
if (pre != null) {
......@@ -132,11 +135,12 @@ public class JavaTaskLauncher extends TaskLauncher {
}
//return result
return new TaskResultImpl(taskId, userResult, this.getLogs(), duration);
return new TaskResultImpl(taskId, userResult, this.getLogs(), duration,
retreiveExportedProperties());
} catch (Throwable ex) {
logger_dev.info("", ex);
// exceptions are always handled at scheduler core level
return new TaskResultImpl(taskId, ex, this.getLogs(), duration);
return new TaskResultImpl(taskId, ex, this.getLogs(), duration, retreiveExportedProperties());
} finally {
terminateDataSpace();
if (core != null) {
......
......@@ -104,6 +104,9 @@ public class NativeTaskLauncher extends TaskLauncher {
//copy datas from OUTPUT or INPUT to local scratch
copyInputDataToScratch();
// set exported vars
this.setExportedProperties(results);
//get Executable before schedule timer
currentExecutable = executableContainer.getExecutable();
//start walltime if needed
......@@ -154,15 +157,13 @@ public class NativeTaskLauncher extends TaskLauncher {
throw exception;
}
//logBuffer is filled up
TaskResult result = new TaskResultImpl(taskId, userResult, this.getLogs(), duration);
//return result
return result;
return new TaskResultImpl(taskId, userResult, this.getLogs(), duration,
retreiveExportedProperties());
} catch (Throwable ex) {
logger_dev.info("", ex);
// exceptions are always handled at scheduler core level
return new TaskResultImpl(taskId, ex, this.getLogs(), duration);
return new TaskResultImpl(taskId, ex, this.getLogs(), duration, retreiveExportedProperties());
} finally {
terminateDataSpace();
if (isWallTime()) {
......
......@@ -38,8 +38,11 @@ import java.io.PrintStream;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.log4j.Appender;
......@@ -79,6 +82,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.Script;
import org.ow2.proactive.scripting.ScriptHandler;
import org.ow2.proactive.scripting.ScriptLoader;
......@@ -303,11 +307,14 @@ public abstract class TaskLauncher implements InitActive {
* Set scheduler related variables for the current task.
*/
protected void initEnv() {
// set task vars
System.setProperty(SchedulerVars.JAVAENV_JOB_ID_VARNAME.toString(), this.taskId.getJobId().value());
System.setProperty(SchedulerVars.JAVAENV_JOB_NAME_VARNAME.toString(), this.taskId.getJobId()
.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
}
/**
......@@ -320,6 +327,58 @@ public abstract class TaskLauncher implements InitActive {
System.clearProperty(SchedulerVars.JAVAENV_TASK_NAME_VARNAME.toString());
}
/**
* Set as Java Property all the properties that comes with incoming results, i.e.
* properties that have been exported in parent tasks.
* @see org.ow2.proactive.scripting.Exporter
*/
protected void setExportedProperties(TaskResult[] incomingResults) {
for (int i = 0; i < incomingResults.length; i++) {
Map<String, String> properties = incomingResults[i].getExportedProperties();
if (properties != null) {
logger_dev.info("Imported properties for task " + this.taskId + " are " + properties);
for (String key : properties.keySet()) {
logger_dev.debug("Value of imported property " + key + " is " + properties.get(key));
System.setProperty(key, properties.get(key));
}
} else {
logger_dev.info(" No imported properties for task " + this.taskId);
}
}
}
/**
* Extract name and value of all the properties that have been exported during the execution
* of this task launcher (on scripts and executable).
* @see org.ow2.proactive.scripting.Exporter
* @return a map that contains [name->value] of all exported properties.
*/
protected Map<String, String> 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>();
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);
System.clearProperty(key);
} else {
logger_dev.warn("Exported property " + key + " is not set !");
}
}
System.clearProperty(Exporter.EXPORTED_PROPERTIES_VAR_NAME);
return exportedVars;
} else {
logger_dev.info("No exported properties for task " + this.taskId);
return null;
}
}
/**
* Activate the logs on this host and port.
* @param logSink the provider for the appender to write in.
......
......@@ -36,6 +36,7 @@ package org.ow2.proactive.scheduler.task.launcher;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.ow2.proactive.scheduler.common.task.TaskId;
import org.ow2.proactive.scheduler.common.task.dataspaces.InputSelector;
......
/*
* ################################################################
*
* ProActive: The Java(TM) library for Parallel, Distributed,
* Concurrent computing with Security and Mobility
*
* Copyright (C) 1997-2009 INRIA/University of
* Nice-Sophia Antipolis/ActiveEon
* Contact: proactive@ow2.org
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 3 of
* the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* If needed, contact us to obtain a release under GPL Version 2.
*
* Initial developer(s): The ProActive Team
* http://proactive.inria.fr/team_members.htm
* Contributor(s): ActiveEon Team - http://www.activeeon.com
*
* ################################################################
* $$ACTIVEEON_CONTRIBUTOR$$
*/
package functionaltests;
import java.util.Map.Entry;
import org.junit.Assert;
import org.ow2.proactive.scheduler.common.job.JobId;
import org.ow2.proactive.scheduler.common.job.JobResult;
import org.ow2.proactive.scheduler.common.task.TaskResult;
import functionalTests.FunctionalTest;
public class TestExportVars extends FunctionalTest {
private static String jobDescriptor = TestJobPrePostSubmission.class.getResource(
"/functionaltests/descriptors/Job_exportVars.xml").getPath();
/**
* Tests start here.
*
* @throws Throwable any exception that can be thrown during the test.
*/
@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) + "]");
}
}
}
<?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>
<description>Export variables</description>
<taskFlow>
<task name="task1.1" preciousResult="true">
<pre>
<script>
<code language="javascript">
importClass(org.ow2.proactive.scripting.Exporter);
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.exportProperty("key1");
Exporter.exportProperty("key2");
</code>
</script>
</pre>
<javaExecutable class="org.ow2.proactive.scheduler.examples.PropertyTask"/>
<post>
<script>
<code language="javascript">
//importClass(org.ow2.proactive.scripting.Exporter);
//Exporter.exportProperty("user.property1");
</code>
</script>
</post>
</task>
<task name="task2" preciousResult="true">
<depends>
<task ref="task1.1"/>
</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");
</code>
</script>
</pre>
<nativeExecutable>
<staticCommand
value="date">
</staticCommand>
</nativeExecutable>
</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