1 31 package org.objectweb.proactive.core.process.prun; 32 33 import org.objectweb.proactive.core.config.ProActiveConfiguration; 34 import org.objectweb.proactive.core.process.AbstractExternalProcessDecorator; 35 import org.objectweb.proactive.core.process.ExternalProcess; 36 import org.objectweb.proactive.core.process.MessageSink; 37 import org.objectweb.proactive.core.process.SimpleExternalProcess; 38 import org.objectweb.proactive.core.util.MessageLogger; 39 40 import java.util.StringTokenizer ; 41 42 43 64 public class PrunSubProcess extends AbstractExternalProcessDecorator { 65 private static final String FILE_SEPARATOR = System.getProperty( 66 "file.separator"); 67 68 public final static String DEFAULT_PRUNPATH = "/usr/local/bin/prun"; 78 79 protected static final String DEFAULT_HOSTS_NUMBER = "1"; 83 protected static final String DEFAULT_PROCESSOR_NUMBER = "1"; 84 protected static final String DEFAULT_BOOKING_DURATION = "00:01:00"; 85 protected int jobID; 86 protected String queueName; 87 protected String hostList; 88 89 protected String hosts = DEFAULT_HOSTS_NUMBER; 91 protected String processorPerNode = DEFAULT_PROCESSOR_NUMBER; 92 protected String bookingDuration = DEFAULT_BOOKING_DURATION; 93 protected String interactive = "false"; 94 protected String outputFile; 95 96 100 104 public PrunSubProcess() { 105 super(); 106 setCompositionType(GIVE_COMMAND_AS_PARAMETER); 107 this.hostname = null; 108 } 109 110 115 public PrunSubProcess(ExternalProcess targetProcess) { 116 super(targetProcess); 117 this.hostname = null; 118 } 119 120 public void setErrorMessageLogger(MessageLogger errorMessageLogger) { 128 super.setErrorMessageLogger(new CompositeMessageLogger( 129 new ParserMessageLogger(), errorMessageLogger)); 130 } 131 132 public void setOutputMessageSink(MessageSink outputMessageSink) { 133 if (outputMessageSink == null) { 134 super.setOutputMessageSink(new SimpleMessageSink()); 135 } else { 136 super.setOutputMessageSink(outputMessageSink); 137 } 138 } 139 140 145 public static ExternalProcess buildBKillProcess(int jobID) { 146 return new SimpleExternalProcess("qdel " + jobID); 147 } 148 149 public static void main(String [] args) { 150 ProActiveConfiguration.load(); 151 try { 152 PrunSubProcess p = new PrunSubProcess(new SimpleExternalProcess( 153 "/bin/ls ")); 154 p.setHostsNumber("2"); 155 p.startProcess(); 156 } catch (Exception e) { 157 e.printStackTrace(); 158 } 159 } 160 161 164 public String getOutputFile() { 165 return outputFile; 166 } 167 168 172 public void setOutputFile(String string) { 173 outputFile = string; 174 } 175 176 180 public int getJobID() { 181 return jobID; 182 } 183 184 188 public String getQueueName() { 189 return queueName; 190 } 191 192 196 public void setQueueName(String queueName) { 197 checkStarted(); 198 if (queueName == null) { 199 throw new NullPointerException (); 200 } 201 this.queueName = queueName; 202 } 203 204 208 public void setHostList(String hostList) { 209 checkStarted(); 210 this.hostList = hostList; 211 } 212 213 217 public String getHostList() { 218 return hostList; 219 } 220 221 229 233 public void setBookingDuration(String d) { 234 this.bookingDuration = d; 235 } 236 237 241 public String getBookingDuration() { 242 return this.bookingDuration; 243 } 244 245 251 protected String parseHostname(String message) { 252 String result = new String (); 253 if (logger.isDebugEnabled()) { 254 logger.info("parseHostname() analyzing " + message); 255 } 256 java.util.StringTokenizer st = new java.util.StringTokenizer (message); 257 if (st.countTokens() < 2) { 258 return null; } 260 if (!":".equals(st.nextToken())) { 261 return null; } 263 264 while (st.hasMoreTokens()) { 265 result += (st.nextToken()); 266 result += " "; 267 } 268 return result; 269 } 270 271 275 public void setInteractive(String interactive) { 276 this.interactive = interactive; 277 } 278 279 283 public void setHostsNumber(String hosts) { 284 checkStarted(); 285 if (hosts != null) { 286 this.hosts = hosts; 287 } 288 289 } 291 292 296 public void setProcessorPerNodeNumber(String processorPerNode) { 297 checkStarted(); 298 if (processorPerNode != null) { 299 this.processorPerNode = processorPerNode; 300 } 301 } 302 303 307 public String getHostsNumber() { 308 return this.hosts; 309 } 310 311 public String getProcessorPerNodeNumber() { 312 return this.processorPerNode; 313 } 314 315 protected String internalBuildCommand() { 329 return buildEnvironmentCommand(); } 331 332 protected void sendJobDetailsCommand() { 333 } 335 336 protected void internalStartProcess(String command) 337 throws java.io.IOException { 338 super.internalStartProcess(command); 342 } 343 344 protected String buildCommand() { 345 StringBuffer prunCommand = new StringBuffer (); 346 prunCommand.append(DEFAULT_PRUNPATH); 347 if (interactive.equals("true")) { 348 prunCommand.append(" -I"); 349 } 350 351 String [] commandAndOptions = separateCommandFromOptions(targetProcess.getCommand()); 352 prunCommand.append(" -no-panda -v -" + processorPerNode + " -t " + 353 bookingDuration + " "); 354 355 if (hostList != null) { 356 prunCommand.append("-m " + hostList + " "); 357 } 358 359 if (outputFile != null) { 360 prunCommand.append("-o " + outputFile + " "); 361 } 362 363 if (queueName != null) { 364 365 prunCommand.append("-q " + queueName + " ") ; 366 } 367 368 prunCommand.append(commandAndOptions[0] + " " + hosts + " " + 369 commandAndOptions[1]); 371 if (logger.isDebugEnabled()) { 372 logger.debug("prun command is " + prunCommand.toString()); 373 } 374 return prunCommand.toString(); 375 } 376 377 protected String [] separateCommandFromOptions(String s) { 378 String [] result = { "", "" }; 379 380 StringTokenizer st = new StringTokenizer (s); 384 if (st.countTokens() > 1) { 385 result[0] = st.nextToken(); 386 while (st.hasMoreTokens()) { 387 result[1] += st.nextToken(); 388 result[1] += " "; 389 } 390 } 391 return result; 392 } 393 394 401 404 public class ParserMessageLogger implements MessageLogger, 405 java.io.Serializable { 406 private boolean foundJobID; 407 private boolean foundHostname; 408 409 public ParserMessageLogger() { 410 } 411 412 public void log(String message) { 413 int nbProcessor = (new Integer (hosts)).intValue(); 415 String h = parseHostname(message); 416 417 } 421 422 public void log(Throwable t) { 423 } 424 425 public void log(String message, Throwable t) { 426 } 427 } 428 429 } 431 | Popular Tags |