1 31 package org.objectweb.proactive.core.descriptor.xml; 32 33 import org.objectweb.proactive.core.ProActiveException; 34 import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor; 35 import org.objectweb.proactive.core.process.ExternalProcess; 36 import org.objectweb.proactive.core.process.ExternalProcessDecorator; 37 import org.objectweb.proactive.core.process.JVMProcess; 38 import org.objectweb.proactive.core.process.globus.GlobusProcess; 39 import org.objectweb.proactive.core.process.lsf.LSFBSubProcess; 40 import org.objectweb.proactive.core.process.prun.PrunSubProcess; 41 import org.objectweb.proactive.core.process.rsh.maprsh.MapRshProcess; 42 import org.objectweb.proactive.core.xml.handler.AbstractUnmarshallerDecorator; 43 import org.objectweb.proactive.core.xml.handler.BasicUnmarshaller; 44 import org.objectweb.proactive.core.xml.handler.BasicUnmarshallerDecorator; 45 import org.objectweb.proactive.core.xml.handler.CollectionUnmarshaller; 46 import org.objectweb.proactive.core.xml.handler.PassiveCompositeUnmarshaller; 47 import org.objectweb.proactive.core.xml.handler.UnmarshallerHandler; 48 import org.objectweb.proactive.core.xml.io.Attributes; 49 50 import org.xml.sax.SAXException ; 51 52 53 public class ProcessDefinitionHandler extends AbstractUnmarshallerDecorator 54 implements ProActiveDescriptorConstants { 55 protected String id; 56 protected ProActiveDescriptor proActiveDescriptor; 57 protected ExternalProcess targetProcess; 58 59 public ProcessDefinitionHandler(ProActiveDescriptor proActiveDescriptor) { 60 super(false); 61 this.proActiveDescriptor = proActiveDescriptor; 62 this.addHandler(JVM_PROCESS_TAG, 63 new JVMProcessHandler(proActiveDescriptor)); 64 this.addHandler(RSH_PROCESS_TAG, 65 new RSHProcessHandler(proActiveDescriptor)); 66 this.addHandler(MAPRSH_PROCESS_TAG, 67 new MapRshProcessHandler(proActiveDescriptor)); 68 this.addHandler(SSH_PROCESS_TAG, 69 new SSHProcessHandler(proActiveDescriptor)); 70 this.addHandler(RLOGIN_PROCESS_TAG, 71 new RLoginProcessHandler(proActiveDescriptor)); 72 this.addHandler(BSUB_PROCESS_TAG, 73 new BSubProcessHandler(proActiveDescriptor)); 74 this.addHandler(GLOBUS_PROCESS_TAG, 75 new GlobusProcessHandler(proActiveDescriptor)); 76 this.addHandler(PRUN_PROCESS_TAG, 77 new PrunProcessHandler(proActiveDescriptor)); 78 } 79 80 83 protected void notifyEndActiveHandler(String name, 84 UnmarshallerHandler activeHandler) throws SAXException { 85 } 86 87 90 public Object getResultObject() throws SAXException { 91 ExternalProcess result = targetProcess; 92 targetProcess = null; 93 return result; 94 } 95 96 99 public void startContextElement(String name, Attributes attributes) 100 throws SAXException { 101 id = attributes.getValue("id"); 102 } 103 104 public class ProcessHandler extends AbstractUnmarshallerDecorator 105 implements ProActiveDescriptorConstants { 106 protected ProActiveDescriptor proActiveDescriptor; 107 protected boolean isRef; 108 109 public ProcessHandler(ProActiveDescriptor proActiveDescriptor) { 110 super(); 111 this.proActiveDescriptor = proActiveDescriptor; 112 addHandler(ENVIRONMENT_TAG, new EnvironmentHandler()); 113 addHandler(PROCESS_REFERENCE_TAG, new ProcessReferenceHandler()); 114 } 115 116 public void startContextElement(String name, Attributes attributes) 117 throws org.xml.sax.SAXException { 118 String className = attributes.getValue("class"); 119 if (!checkNonEmpty(className)) { 120 throw new org.xml.sax.SAXException ( 121 "Process defined without specifying the class"); 122 } 123 try { 124 targetProcess = proActiveDescriptor.createProcess(id, className); 125 } catch (ProActiveException e) { 126 throw new org.xml.sax.SAXException (e.getMessage()); 128 } 129 String hostname = attributes.getValue("hostname"); 130 if (checkNonEmpty(hostname)) { 131 targetProcess.setHostname(hostname); 132 } 133 String username = attributes.getValue("username"); 134 if (checkNonEmpty(username)) { 135 targetProcess.setUsername("username"); 136 } 137 } 138 139 public Object getResultObject() throws org.xml.sax.SAXException { 143 return null; 144 } 145 146 protected void notifyEndActiveHandler(String name, 150 UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException { 151 if (name.equals(ENVIRONMENT_TAG)) { 152 targetProcess.setEnvironment((String []) activeHandler.getResultObject()); 153 } else if (name.equals(PROCESS_REFERENCE_TAG)) { 154 if (!(targetProcess instanceof ExternalProcessDecorator)) { 155 throw new org.xml.sax.SAXException ( 156 "found a Process defined inside a non composite process"); 157 } 158 ExternalProcessDecorator cep = (ExternalProcessDecorator) targetProcess; 159 Object result = activeHandler.getResultObject(); 160 proActiveDescriptor.registerProcess(cep, (String ) result); 161 } 162 } 163 164 168 171 protected class EnvironmentHandler extends BasicUnmarshaller { 172 private java.util.ArrayList variables; 173 174 public EnvironmentHandler() { 175 } 176 177 public void startContextElement(String name, Attributes attributes) 178 throws org.xml.sax.SAXException { 179 variables = new java.util.ArrayList (); 180 } 181 182 public Object getResultObject() throws org.xml.sax.SAXException { 183 if (variables == null) { 184 isResultValid = false; 185 } else { 186 int n = variables.size(); 187 String [] result = new String [n]; 188 if (n > 0) { 189 variables.toArray(result); 190 } 191 setResultObject(result); 192 variables.clear(); 193 variables = null; 194 } 195 return super.getResultObject(); 196 } 197 198 public void startElement(String name, Attributes attributes) 199 throws org.xml.sax.SAXException { 200 if (name.equals(VARIABLE_TAG)) { 201 String vName = attributes.getValue("name"); 202 String vValue = attributes.getValue("value"); 203 if (checkNonEmpty(vName) && (vValue != null)) { 204 logger.info("Found environment variable name=" + vName + 205 " value=" + vValue); 206 variables.add(vName + "=" + vValue); 207 } 208 } 209 } 210 } 211 212 } 214 215 protected class PrunProcessHandler extends ProcessHandler { 217 public PrunProcessHandler(ProActiveDescriptor proActiveDescriptor) { 218 super(proActiveDescriptor); 219 this.addHandler(PRUN_OPTIONS_TAG, new PrunOptionHandler()); 220 } 222 223 protected class PrunOptionHandler extends PassiveCompositeUnmarshaller { 224 public PrunOptionHandler() { 228 UnmarshallerHandler pathHandler = new PathHandler(); 231 this.addHandler(HOST_LIST_TAG, new SingleValueUnmarshaller()); 232 this.addHandler(HOSTS_NUMBER_TAG, new SingleValueUnmarshaller()); 233 this.addHandler(PROCESSOR_TAG, new SingleValueUnmarshaller()); 234 this.addHandler(BOOKING_DURATION_TAG, 235 new SingleValueUnmarshaller()); 236 this.addHandler(PRUN_OUTPUT_FILE, new SingleValueUnmarshaller()); 237 BasicUnmarshallerDecorator bch = new BasicUnmarshallerDecorator(); 238 bch.addHandler(ABS_PATH_TAG, pathHandler); 239 bch.addHandler(REL_PATH_TAG, pathHandler); 240 } 242 243 public void startContextElement(String name, Attributes attributes) 244 throws org.xml.sax.SAXException { 245 } 246 247 protected void notifyEndActiveHandler(String name, 248 UnmarshallerHandler activeHandler) 249 throws org.xml.sax.SAXException { 250 PrunSubProcess prunSubProcess = (PrunSubProcess) targetProcess; 253 254 if (name.equals(HOST_LIST_TAG)) { 256 prunSubProcess.setHostList((String ) activeHandler.getResultObject()); 257 } else if (name.equals(HOSTS_NUMBER_TAG)) { 258 prunSubProcess.setHostsNumber((String ) activeHandler.getResultObject()); 259 } else if (name.equals(PROCESSOR_PER_NODE_TAG)) { 260 prunSubProcess.setProcessorPerNodeNumber((String ) activeHandler.getResultObject()); 261 } else if (name.equals(BOOKING_DURATION_TAG)) { 265 prunSubProcess.setBookingDuration((String ) activeHandler.getResultObject()); 266 } else if (name.equals(PRUN_OUTPUT_FILE)) { 267 prunSubProcess.setOutputFile((String ) activeHandler.getResultObject()); 268 } else { 269 super.notifyEndActiveHandler(name, activeHandler); 270 } 271 } 272 } 273 } 274 275 protected class JVMProcessHandler extends ProcessHandler { 277 public JVMProcessHandler(ProActiveDescriptor proActiveDescriptor) { 278 super(proActiveDescriptor); 279 UnmarshallerHandler pathHandler = new PathHandler(); 280 { 281 CollectionUnmarshaller cu = new CollectionUnmarshaller(String .class); 282 cu.addHandler(ABS_PATH_TAG, pathHandler); 283 cu.addHandler(REL_PATH_TAG, pathHandler); 284 cu.addHandler(JVMPARAMETER_TAG, new SimpleValueHandler()); 285 this.addHandler(CLASSPATH_TAG, cu); 286 this.addHandler(BOOT_CLASSPATH_TAG, cu); 287 this.addHandler(JVMPARAMETERS_TAG, cu); 288 } 289 BasicUnmarshallerDecorator bch = new BasicUnmarshallerDecorator(); 290 bch.addHandler(ABS_PATH_TAG, pathHandler); 291 bch.addHandler(REL_PATH_TAG, pathHandler); 292 bch.addHandler(JVMPARAMETER_TAG, new BasicUnmarshaller()); 293 this.addHandler(JAVA_PATH_TAG, bch); 295 this.addHandler(POLICY_FILE_TAG, bch); 296 this.addHandler(LOG4J_FILE_TAG, bch); 297 this.addHandler(PROACTIVE_PROPS_FILE_TAG, bch); 298 this.addHandler(CLASSNAME_TAG, new SingleValueUnmarshaller()); 299 this.addHandler(PARAMETERS_TAG, new SingleValueUnmarshaller()); 300 } 302 303 protected void notifyEndActiveHandler(String name, 310 UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException { 311 JVMProcess jvmProcess = (JVMProcess) targetProcess; 314 315 if (name.equals(CLASSPATH_TAG)) { 316 String [] paths = (String []) activeHandler.getResultObject(); 317 if (paths.length > 0) { 318 StringBuffer sb = new StringBuffer (); 319 String pathSeparator = System.getProperty("path.separator"); 320 sb.append(paths[0]); 321 for (int i = 1; i < paths.length; i++) { 322 sb.append(pathSeparator); 323 sb.append(paths[i]); 324 } 325 jvmProcess.setClasspath(sb.toString()); 326 } 327 } else if (name.equals(BOOT_CLASSPATH_TAG)) { 328 String [] paths = (String []) activeHandler.getResultObject(); 329 if (paths.length > 0) { 330 StringBuffer sb = new StringBuffer (); 331 String pathSeparator = System.getProperty("path.separator"); 332 sb.append(paths[0]); 333 for (int i = 1; i < paths.length; i++) { 334 sb.append(pathSeparator); 335 sb.append(paths[i]); 336 } 337 jvmProcess.setBootClasspath(sb.toString()); 338 } 339 } else if (name.equals(JVMPARAMETERS_TAG)) { 340 String [] paths = (String []) activeHandler.getResultObject(); 341 342 if (paths.length > 0) { 343 StringBuffer sb = new StringBuffer (); 344 for (int i = 0; i < paths.length; i++) { 345 sb.append(paths[i]); 347 sb.append(" "); 348 } 349 jvmProcess.setJvmOptions(sb.toString()); 350 } 351 } else if (name.equals(JAVA_PATH_TAG)) { 352 String jp = (String ) activeHandler.getResultObject(); 353 jvmProcess.setJavaPath(jp); 354 } else if (name.equals(POLICY_FILE_TAG)) { 355 jvmProcess.setPolicyFile((String ) activeHandler.getResultObject()); 356 } else if (name.equals(LOG4J_FILE_TAG)) { 357 jvmProcess.setLog4jFile((String ) activeHandler.getResultObject()); 358 } else if (name.equals(PROACTIVE_PROPS_FILE_TAG)) { 359 jvmProcess.setJvmOptions("-Dproactive.configuration=" + 360 (String ) activeHandler.getResultObject()); 361 } else if (name.equals(CLASSNAME_TAG)) { 362 jvmProcess.setClassname((String ) activeHandler.getResultObject()); 363 } else if (name.equals(PARAMETERS_TAG)) { 364 jvmProcess.setParameters((String ) activeHandler.getResultObject()); 365 } 367 else { 368 super.notifyEndActiveHandler(name, activeHandler); 369 } 370 } 371 } 372 373 protected class RSHProcessHandler extends ProcessHandler { 375 public RSHProcessHandler(ProActiveDescriptor proActiveDescriptor) { 376 super(proActiveDescriptor); 377 } 378 } 379 380 protected class MapRshProcessHandler extends ProcessHandler { 382 public MapRshProcessHandler(ProActiveDescriptor proActiveDescriptor) { 383 super(proActiveDescriptor); 384 UnmarshallerHandler pathHandler = new PathHandler(); 385 BasicUnmarshallerDecorator bch = new BasicUnmarshallerDecorator(); 386 bch.addHandler(ABS_PATH_TAG, pathHandler); 387 bch.addHandler(REL_PATH_TAG, pathHandler); 388 this.addHandler(SCRIPT_PATH_TAG, bch); 389 } 390 391 public void startContextElement(String name, Attributes attributes) 392 throws org.xml.sax.SAXException { 393 super.startContextElement(name, attributes); 397 String parallelize = attributes.getValue("parallelize"); 398 if (checkNonEmpty(parallelize)) { 399 ((MapRshProcess) targetProcess).setParallelization( 400 "parallelize"); 401 } 402 } 403 404 protected void notifyEndActiveHandler(String name, 405 UnmarshallerHandler activeHandler) throws org.xml.sax.SAXException { 406 if (name.equals(SCRIPT_PATH_TAG)) { 408 ((MapRshProcess) targetProcess).setScriptLocation((String ) activeHandler.getResultObject()); 409 } else { 410 super.notifyEndActiveHandler(name, activeHandler); 411 } 412 } 413 } 414 415 protected class SSHProcessHandler extends ProcessHandler { 417 public SSHProcessHandler(ProActiveDescriptor proActiveDescriptor) { 418 super(proActiveDescriptor); 419 } 420 } 421 422 protected class RLoginProcessHandler extends ProcessHandler { 424 public RLoginProcessHandler(ProActiveDescriptor proActiveDescriptor) { 425 super(proActiveDescriptor); 426 } 427 } 428 429 protected class BSubProcessHandler extends ProcessHandler { 431 public BSubProcessHandler(ProActiveDescriptor proActiveDescriptor) { 432 super(proActiveDescriptor); 433 this.addHandler(BSUB_OPTIONS_TAG, new BsubOptionHandler()); 434 } 435 436 public void startContextElement(String name, Attributes attributes) 437 throws org.xml.sax.SAXException { 438 super.startContextElement(name, attributes); 442 String interactive = (attributes.getValue("interactive")); 443 if (checkNonEmpty(interactive)) { 444 ((LSFBSubProcess) targetProcess).setInteractive(interactive); 445 } 446 String queueName = (attributes.getValue("queue")); 447 if (checkNonEmpty(queueName)) { 448 ((LSFBSubProcess) targetProcess).setQueueName(queueName); 449 } 450 } 451 452 protected class BsubOptionHandler extends PassiveCompositeUnmarshaller { 453 public BsubOptionHandler() { 457 UnmarshallerHandler pathHandler = new PathHandler(); 459 this.addHandler(HOST_LIST_TAG, new SingleValueUnmarshaller()); 460 this.addHandler(PROCESSOR_TAG, new SingleValueUnmarshaller()); 461 this.addHandler(RES_REQ_TAG, new SimpleValueHandler()); 462 BasicUnmarshallerDecorator bch = new BasicUnmarshallerDecorator(); 463 bch.addHandler(ABS_PATH_TAG, pathHandler); 464 bch.addHandler(REL_PATH_TAG, pathHandler); 465 this.addHandler(SCRIPT_PATH_TAG, bch); 466 } 467 468 public void startContextElement(String name, Attributes attributes) 469 throws org.xml.sax.SAXException { 470 } 471 472 protected void notifyEndActiveHandler(String name, 473 UnmarshallerHandler activeHandler) 474 throws org.xml.sax.SAXException { 475 LSFBSubProcess bSubProcess = (LSFBSubProcess) targetProcess; 478 if (name.equals(HOST_LIST_TAG)) { 479 bSubProcess.setHostList((String ) activeHandler.getResultObject()); 480 } else if (name.equals(PROCESSOR_TAG)) { 481 bSubProcess.setProcessorNumber((String ) activeHandler.getResultObject()); 482 } else if (name.equals(RES_REQ_TAG)) { 483 bSubProcess.setRes_requirement((String ) activeHandler.getResultObject()); 484 } else if (name.equals(SCRIPT_PATH_TAG)) { 485 bSubProcess.setScriptLocation((String ) activeHandler.getResultObject()); 486 } else { 487 super.notifyEndActiveHandler(name, activeHandler); 488 } 489 } 490 } 491 492 } 494 495 protected class GlobusProcessHandler extends ProcessHandler { 497 public GlobusProcessHandler(ProActiveDescriptor proActiveDescriptor) { 498 super(proActiveDescriptor); 499 this.addHandler(GLOBUS_OPTIONS_TAG, new GlobusOptionHandler()); 500 } 501 502 protected class GlobusOptionHandler extends PassiveCompositeUnmarshaller { 503 public GlobusOptionHandler() { 504 this.addHandler(GLOBUS_COUNT_TAG, new SingleValueUnmarshaller()); 505 } 506 507 public void startContextElement(String name, Attributes attributes) 508 throws org.xml.sax.SAXException { 509 } 510 511 protected void notifyEndActiveHandler(String name, 512 UnmarshallerHandler activeHandler) 513 throws org.xml.sax.SAXException { 514 GlobusProcess globusProcess = (GlobusProcess) targetProcess; 517 if (name.equals(GLOBUS_COUNT_TAG)) { 518 globusProcess.setCount((String ) activeHandler.getResultObject()); 519 } else { 520 super.notifyEndActiveHandler(name, activeHandler); 521 } 522 } 523 } 524 525 } 527 528 private class SingleValueUnmarshaller extends BasicUnmarshaller { 530 public void readValue(String value) throws org.xml.sax.SAXException { 531 setResultObject(value); 533 } 534 } 535 536 private class SimpleValueHandler extends BasicUnmarshaller { 537 public void startContextElement(String name, Attributes attributes) 538 throws org.xml.sax.SAXException { 539 String value = attributes.getValue("value"); 541 542 setResultObject(value); 543 } 544 } 545 546 } 548 | Popular Tags |