org/objectweb/proactive/core/process/globus/GlobusProcess.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.core.process.globus;
00032 
00033 import org.objectweb.proactive.core.process.AbstractExternalProcessDecorator;
00034 import org.objectweb.proactive.core.process.JVMProcess;
00035 import org.objectweb.proactive.core.process.JVMProcessImpl;
00036 import org.objectweb.proactive.core.process.UniversalProcess;
00037 
00038 
00046 public class GlobusProcess extends AbstractExternalProcessDecorator {
00047     protected JVMProcessImpl jvmProcess;
00048     protected String count = "1";
00049     protected String stderr = null;
00050     protected String stdout = null;
00051     protected String queue = null;
00052     protected String maxTime = null;
00053 
00054     //===========================================================
00055     // Constructor
00056     //===========================================================
00057 
00061     public GlobusProcess() {
00062         super();
00063         setCompositionType(GIVE_COMMAND_AS_PARAMETER);
00064         this.hostname = null;
00065     }
00066 
00070     public GlobusProcess(JVMProcess process) {
00071         super(process, GIVE_COMMAND_AS_PARAMETER);
00072         this.jvmProcess = (JVMProcessImpl) targetProcess;
00073         this.hostname = null;
00074     }
00075 
00076     /* (non-Javadoc)
00077      * @see org.objectweb.proactive.core.process.AbstractExternalProcessDecorator#internalBuildCommand()
00078      */
00079     protected String internalBuildCommand() {
00080         return buildRSLCommand();
00081     }
00082 
00083     public static void main(String[] args) {
00084         String RSL = "& (executable = /nfs/software/java/j2sdk1.4.2_07/bin/java )(count=5)";
00085 
00086         // String RSL = "& (executable = /user/rquilici/home/ProActive/scripts/unix/cluster/startRuntime.sh )(arguments='/user/rquilici/home/j2sdk1.4.2_05/bin/java -Dproactive.jobid=JOB-986939693  -cp /user/rquilici/home/ProActive/classes:/user/rquilici/home/ProActive/lib/asm.jar:/user/rquilici/home/ProActive/lib/log4j.jar:/user/rquilici/home/ProActive/lib/components/fractal.jar:/user/rquilici/home/ProActive/lib/xercesImpl.jar:/user/rquilici/home/ProActive/lib/bouncycastle.jar -Djava.security.policy=/user/rquilici/home/ProActive/scripts/proactive.java.policy -Dlog4j.configuration=file:/user/rquilici/home/ProActive/scripts/proactive-log4j org.objectweb.proactive.core.runtime.StartRuntime Renderer //sea.inria.fr/PA_JVM986939693_sea.inria.fr 1 globus_jvm Jvm4')(jobType=multiple)(count=5)";
00087         GridJob Job1 = new GridJob("viz-login.isi.edu/jobmanager-pbs", false);
00088 
00089         //GridJob Job1 = new GridJob("cluster.inria.fr", false);
00090         Job1.GlobusRun(RSL);
00091         //String jobOut = 
00092         //System.out.println(jobOut);
00093     }
00094 
00095     protected void internalStartProcess(String rslCommand)
00096         throws java.io.IOException {
00097         GridJob Job1 = new GridJob(hostname, false);
00098         String jobOut = Job1.GlobusRun(getCommand());
00099         logger.info(jobOut);
00100     }
00101 
00106     private String buildRSLCommand() {
00107         //here we guess that the process behind globus is a java process. Indeed it makes no sense to
00108         //run a globus process foloowed by something else, since we target direclty the globus frontend
00109         String java_command = ((JVMProcess) getTargetProcess()).getJavaPath();
00110         String initial_args = ((JVMProcess) getTargetProcess()).getCommand()
00111                                .substring(java_command.length() + 1);
00112 
00113         //This is because the GT2 provider doesn't support the = in the RSL command,
00114         //we surround the whole arg with \. This has to be removed for GT4 if one day 
00115         // we include the notion of provider, since GT4 supports =.
00116         String args = checkSyntax(initial_args);
00117 
00118         String RSLCommand = "& (executable = " + java_command + ")(arguments=" +
00119             args + ")(count=" + count + ")";
00120 
00121         if (stdout != null) {
00122             RSLCommand = RSLCommand + "(stdout=" + stdout + ")";
00123         }
00124 
00125         if (stderr != null) {
00126             RSLCommand = RSLCommand + "(stderr=" + stderr + ")";
00127         }
00128 
00129         if (queue != null) {
00130             RSLCommand = RSLCommand + "(queue=" + queue + ")";
00131         }
00132 
00133         if (environment != null) {
00134             RSLCommand = RSLCommand + "(environment=" +
00135                 buildEnvironmentCommand() + ")";
00136         }
00137         if (maxTime != null) {
00138             RSLCommand = RSLCommand + "(maxTime=" + maxTime + ")";
00139         }
00140         return RSLCommand;
00141     }
00142 
00143     protected String buildEnvironmentCommand() {
00144         if (environment == null) {
00145             return "";
00146         }
00147         StringBuilder sb = new StringBuilder();
00148         String[] globusEnvironment = new String[environment.length];
00149         for (int i = 0; i < environment.length; i++) {
00150             globusEnvironment[i] = environment[i].replace('=', ' ');
00151             sb.append("(");
00152             sb.append(globusEnvironment[i]);
00153             sb.append(")");
00154         }
00155         return sb.toString();
00156     }
00157 
00162     public String getCount() {
00163         return count;
00164     }
00165 
00170     public void setCount(String count) {
00171         this.count = count;
00172     }
00173 
00177     public String getProcessId() {
00178         return "globus_" + targetProcess.getProcessId();
00179     }
00180 
00184     public int getNodeNumber() {
00185         return (new Integer(getCount()).intValue());
00186     }
00187 
00191     public UniversalProcess getFinalProcess() {
00192         checkStarted();
00193         return targetProcess.getFinalProcess();
00194     }
00195 
00199     private String checkSyntax(String args) {
00200         String formatted_args = "";
00201         String[] splitted_args = args.split("\\s");
00202         for (int i = 0; i < splitted_args.length; i++) {
00203             if (!(splitted_args[i].indexOf("=") < 0)) {
00204                 splitted_args[i] = "\"" + splitted_args[i] + "\"";
00205             }
00206             formatted_args = formatted_args + " " + splitted_args[i];
00207         }
00208         return formatted_args;
00209     }
00210 
00214     public String getStderr() {
00215         return stderr;
00216     }
00217 
00221     public void setStderr(String stderr) {
00222         this.stderr = stderr;
00223     }
00224 
00228     public String getStdout() {
00229         return stdout;
00230     }
00231 
00235     public void setStdout(String stdout) {
00236         this.stdout = stdout;
00237     }
00238 
00242     public String getQueue() {
00243         return queue;
00244     }
00245 
00249     public void setQueue(String queue) {
00250         this.queue = queue;
00251     }
00252 
00253     public String getMaxTime() {
00254         return maxTime;
00255     }
00256 
00257     public void setMaxTime(String maxTime) {
00258         this.maxTime = maxTime;
00259     }
00260 }

Generated on Mon Jan 22 15:16:08 2007 for ProActive by  doxygen 1.5.1