org/objectweb/proactive/core/process/lsf/CNLSFProcess.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.lsf;
00032 
00033 import java.util.ArrayList;
00034 import java.util.regex.Matcher;
00035 import java.util.regex.Pattern;
00036 
00037 import org.objectweb.proactive.core.process.ExternalProcess;
00038 
00039 
00046 public class CNLSFProcess extends LSFBSubProcess {
00047     protected String queueName;
00048     protected String jobname = "grid";
00049 
00050     //
00051     // -- CONSTRUCTORS -----------------------------------------------
00052     //
00053 
00058     public CNLSFProcess() {
00059         super();
00060     }
00061 
00067     public CNLSFProcess(ExternalProcess targetProcess) {
00068         super(targetProcess);
00069     }
00070 
00071     //
00072     // -- PROTECTED METHODS -----------------------------------------------
00073     //
00074     protected void internalStartProcess(String commandToExecute)
00075         throws java.io.IOException {
00076         ArrayList<String> al = new ArrayList<String>();
00077 
00078         //we divide the command into tokens
00079         //it's basically 3 blocks, the script path, the option and the rest
00080         Pattern p = Pattern.compile("(.*) .*(-c).*'(.*)'");
00081         Matcher m = p.matcher(commandToExecute);
00082         if (!m.matches()) {
00083             System.err.println("Could not match command ");
00084             System.err.println(commandToExecute);
00085         }
00086         for (int i = 1; i <= m.groupCount(); i++) {
00087             //            System.out.println(m.group(i));
00088             al.add(m.group(i));
00089         }
00090         String[] command = al.toArray(new String[] {  });
00091 
00092         try {
00093             externalProcess = Runtime.getRuntime().exec(command);
00094             java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(
00095                         externalProcess.getInputStream()));
00096             java.io.BufferedReader err = new java.io.BufferedReader(new java.io.InputStreamReader(
00097                         externalProcess.getErrorStream()));
00098             java.io.BufferedWriter out = new java.io.BufferedWriter(new java.io.OutputStreamWriter(
00099                         externalProcess.getOutputStream()));
00100             handleProcess(in, out, err);
00101         } catch (java.io.IOException e) {
00102             isFinished = true;
00103             //throw e;
00104             e.printStackTrace();
00105         }
00106     }
00107 
00108     protected String internalBuildCommand() {
00109         return buildCNBSubCommand();
00110     }
00111 
00112     protected String buildCNBSubCommand() {
00113         String executable = scriptLocation.substring(0,
00114                 scriptLocation.lastIndexOf("/") + 1) + "startExecutable.sh";
00115         StringBuilder bSubCommand = new StringBuilder();
00116         bSubCommand.append("/bin/sh -c  'echo ");
00117         bSubCommand.append(targetProcess.getCommand());
00118         bSubCommand.append(" > ");
00119         bSubCommand.append(executable);
00120         bSubCommand.append(" ; chmod 744 " + executable + " ; ");
00121         bSubCommand.append(command_path);
00122         bSubCommand.append(" -n " + processor + " ");
00123         if (getCompositionType() == GIVE_COMMAND_AS_PARAMETER) {
00124             bSubCommand.append(scriptLocation + " '");
00125         }
00126         return bSubCommand.toString();
00127     }
00128 }

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