00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00052
00053
00058 public CNLSFProcess() {
00059 super();
00060 }
00061
00067 public CNLSFProcess(ExternalProcess targetProcess) {
00068 super(targetProcess);
00069 }
00070
00071
00072
00073
00074 protected void internalStartProcess(String commandToExecute)
00075 throws java.io.IOException {
00076 ArrayList<String> al = new ArrayList<String>();
00077
00078
00079
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
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
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 }