1 /*****************************************************************************/ 2 /* Software Testing Automation Framework (STAF) */ 3 /* (C) Copyright IBM Corp. 2002, 2004 */ 4 /* */ 5 /* This software is licensed under the Eclipse Public License (EPL) V1.0. */ 6 /*****************************************************************************/ 7 8 package com.ibm.staf.service.stax; 9 import com.ibm.staf.*; 10 import com.ibm.staf.STAFUtil; 11 import org.python.core.Py; 12 import org.python.core.PyList; 13 import org.python.core.PyObject; 14 import java.util.*; 15 16 public class STAXProcessAction extends STAXActionDefaultImpl 17 implements STAXSTAFRequestCompleteListener, 18 STAXProcessCompleteListener, 19 STAXThreadCompleteListener, 20 STAXTimedEventListener 21 { 22 static final int INIT = 0; 23 static final int WAIT_REQUEST = 1; 24 static final int REQUEST_ERROR = 2; 25 static final int REQUEST_TIMEOUT = 3; 26 static final int RUNNING = 4; 27 static final int COMPLETE = 5; 28 29 static final String INIT_STRING = "INIT"; 30 static final String WAIT_REQUEST_STRING = "WAIT_REQUEST"; 31 static final String REQUEST_ERROR_STRING = "REQUEST_ERROR"; 32 static final String REQUEST_TIMEOUT_STRING = "REQUEST_TIMEOUT"; 33 static final String RUNNING_STRING = "RUNNING"; 34 static final String COMPLETE_STRING = "COMPLETE"; 35 static final String STATE_UNKNOWN_STRING = "UNKNOWN"; 36 STAXProcessAction()37 public STAXProcessAction() 38 { /* Do Nothing */ } 39 getActionFactory()40 public STAXProcessActionFactory getActionFactory() { return fFactory; } setActionFactory(STAXProcessActionFactory factory)41 public void setActionFactory(STAXProcessActionFactory factory) 42 { 43 fFactory = factory; 44 } 45 getLocation()46 public String getLocation() { return fLocation; } setLocation(String location)47 public void setLocation(String location) 48 { 49 fLocation = location; 50 fUnevalLocation = location; 51 } 52 getCommand()53 public String getCommand() { return fCommand; } setCommand(String command)54 public void setCommand(String command) 55 { 56 fCommand = command; 57 fUnevalCommand = command; 58 } 59 getName()60 public String getName() { return fName; } setName(String name)61 public void setName(String name) 62 { 63 fName = name; 64 fUnevalName = name; 65 } 66 getWorkload()67 public String getWorkload() { return fWorkload; } setWorkload(String workload, String workloadIf)68 public void setWorkload(String workload, String workloadIf) 69 { 70 fWorkload = workload; 71 fUnevalWorkload = workload; 72 fWorkloadIf = workloadIf; 73 } 74 getTitle()75 public String getTitle() { return fTitle; } setTitle(String title, String titleIf)76 public void setTitle(String title, String titleIf) 77 { 78 fTitle = title; 79 fUnevalTitle = title; 80 fTitleIf = titleIf; 81 } 82 getParms()83 public String getParms() { return fParms; } setParms(String parms, String parmsIf)84 public void setParms(String parms, String parmsIf) 85 { 86 fParms = parms; 87 fUnevalParms = parms; 88 fParmsIf = parmsIf; 89 } 90 getWorkdir()91 public String getWorkdir() { return fWorkdir; } setWorkdir(String workdir, String workdirIf)92 public void setWorkdir(String workdir, String workdirIf) 93 { 94 fWorkdir = workdir; 95 fUnevalWorkdir = workdir; 96 fWorkdirIf = workdirIf; 97 } 98 getVars()99 public Vector<String> getVars() { return fVars; } setVars(String vars, String varsIf)100 public void setVars(String vars, String varsIf) 101 { 102 fUnevalVars.add(vars); 103 fVarsIf.add(varsIf); 104 } 105 getEnvs()106 public Vector<String> getEnvs() { return fEnvs; } setEnvs(String envs, String envsIf)107 public void setEnvs(String envs, String envsIf) 108 { 109 fUnevalEnvs.add(envs); 110 fEnvsIf.add(envsIf); 111 } 112 getUseprocessvars()113 public String getUseprocessvars() { return fUseprocessvars; } setUseprocessvars(String useprocessvars, String useprocessvarsIf)114 public void setUseprocessvars(String useprocessvars, 115 String useprocessvarsIf) 116 { 117 fUseprocessvars = useprocessvars; 118 fUnevalUseprocessvars = useprocessvars; 119 fUseprocessvarsIf = useprocessvarsIf; 120 } 121 getStopusing()122 public String getStopusing() { return fStopusing; } setStopusing(String stopusing, String stopusingIf)123 public void setStopusing(String stopusing, String stopusingIf) 124 { 125 fStopusing = stopusing; 126 fUnevalStopusing = stopusing; 127 fStopusingIf = stopusingIf; 128 } 129 getConsole()130 public String getConsole() { return fConsole; } setConsole(String console, String consoleIf)131 public void setConsole(String console, String consoleIf) 132 { 133 fConsole = console; 134 fUnevalConsole = console; 135 fConsoleIf = consoleIf; 136 } 137 getFocus()138 public String getFocus() { return fFocus; } setFocus(String focus, String focusIf)139 public void setFocus(String focus, String focusIf) 140 { 141 fFocus = focus; 142 fUnevalFocus = focus; 143 fFocusIf = focusIf; 144 } 145 getUsername()146 public String getUsername() { return fUsername; } setUsername(String username, String usernameIf)147 public void setUsername(String username, String usernameIf) 148 { 149 fUsername = username; 150 fUnevalUsername = username; 151 fUsernameIf = usernameIf; 152 } 153 getPassword()154 public String getPassword() { return fPassword; } setPassword(String password, String passwordIf)155 public void setPassword(String password, String passwordIf) 156 { 157 fPassword = password; 158 fUnevalPassword = password; 159 fPasswordIf = passwordIf; 160 } 161 getDisabledauth()162 public String getDisabledauth() { return fDisabledauth; } setDisabledauth(String disabledauth, String disabledauthIf)163 public void setDisabledauth(String disabledauth, String disabledauthIf) 164 { 165 fDisabledauth = disabledauth; 166 fUnevalDisabledauth = disabledauth; 167 fDisabledauthIf = disabledauthIf; 168 } 169 getStatichandlename()170 public String getStatichandlename() { return fStatichandlename; } setStatichandlename(String statichandlename, String statichandlenameIf)171 public void setStatichandlename(String statichandlename, 172 String statichandlenameIf) 173 { 174 fStatichandlename = statichandlename; 175 fUnevalStatichandlename = statichandlename; 176 fStatichandlenameIf = statichandlenameIf; 177 } 178 getStdin()179 public String getStdin() { return fStdin; } setStdin(String stdin, String stdinIf)180 public void setStdin(String stdin, String stdinIf) 181 { 182 fStdin = stdin; 183 fUnevalStdin = stdin; 184 fStdinIf = stdinIf; 185 } 186 getStdout()187 public String getStdout() { return fStdout; } getStdoutMode()188 public String getStdoutMode() { return fStdoutMode; } setStdout(String stdout, String stdoutMode, String stdoutIf)189 public void setStdout(String stdout, String stdoutMode, String stdoutIf) 190 { 191 fStdout = stdout; 192 fUnevalStdout = stdout; 193 fStdoutIf = stdoutIf; 194 fStdoutMode = stdoutMode; 195 fUnevalStdoutMode = stdoutMode; 196 } 197 getStderr()198 public String getStderr() { return fStderr; } getStderrMode()199 public String getStderrMode() { return fStderrMode; } 200 setStderr(String stderr, String stderrMode, String stderrIf)201 public void setStderr(String stderr, String stderrMode, String stderrIf) 202 { 203 fStderr = stderr; 204 fUnevalStderr = stderr; 205 fStderrIf = stderrIf; 206 fStderrMode = stderrMode; 207 fUnevalStderrMode = stderrMode; 208 } 209 getReturnStdout()210 public String getReturnStdout() { return fReturnStdout; } setReturnStdout(String returnStdout, String returnStdoutIf)211 public void setReturnStdout(String returnStdout, String returnStdoutIf) 212 { 213 fReturnStdout = returnStdout; 214 fUnevalReturnStdout = returnStdout; 215 fReturnStdoutIf = returnStdoutIf; 216 } 217 getReturnStderr()218 public String getReturnStderr() { return fReturnStderr; } setReturnStderr(String returnStderr, String returnStderrIf)219 public void setReturnStderr(String returnStderr, String returnStderrIf) 220 { 221 fReturnStderr = returnStderr; 222 fUnevalReturnStderr = returnStderr; 223 fReturnStderrIf = returnStderrIf; 224 } 225 getReturnFiles()226 public Vector<String> getReturnFiles() { return fReturnFiles; } setReturnFiles(String returnFile, String returnFileIf)227 public void setReturnFiles(String returnFile, String returnFileIf) 228 { 229 fUnevalReturnFiles.add(returnFile); 230 fReturnFilesIf.add(returnFileIf); 231 } 232 getOther()233 public String getOther() { return fOther; } setOther(String other, String otherIf)234 public void setOther(String other, String otherIf) 235 { 236 fOther = other; 237 fUnevalOther = other; 238 fOtherIf = otherIf; 239 } 240 getProcessAction()241 public STAXAction getProcessAction() { return fProcessAction; } setProcessAction(STAXAction processAction, String processActionIf)242 public void setProcessAction(STAXAction processAction, 243 String processActionIf) 244 { 245 fProcessAction = processAction; 246 fProcessActionIf = processActionIf; 247 fUnevalProcessActionIf = processActionIf; 248 } 249 getCommandMode()250 public String getCommandMode() { return fCommandMode; } setCommandMode(String mode)251 public void setCommandMode(String mode) 252 { 253 fCommandMode = mode; 254 fUnevalCommandMode = mode; 255 } 256 getCommandShell()257 public String getCommandShell() { return fCommandShell; } setCommandShell(String shell)258 public void setCommandShell(String shell) 259 { 260 fCommandShell = shell; 261 fUnevalCommandShell = shell; 262 } 263 getThread()264 public STAXThread getThread() { return fThread; } 265 getCurrentBlockName()266 public String getCurrentBlockName() { return fCurrentBlockName; } 267 getStartTimestamp()268 public STAXTimestamp getStartTimestamp() { return fStartTimestamp; } 269 getProcessHandle()270 public int getProcessHandle() { return fProcessHandle; } 271 getStateAsString()272 public String getStateAsString() 273 { 274 switch (fState) 275 { 276 case INIT: 277 return INIT_STRING; 278 case WAIT_REQUEST: 279 return WAIT_REQUEST_STRING; 280 case REQUEST_ERROR: 281 return REQUEST_ERROR_STRING; 282 case REQUEST_TIMEOUT: 283 return REQUEST_TIMEOUT_STRING; 284 case RUNNING: 285 String stateString = RUNNING_STRING; 286 287 if (fIsProcessRunning && !fIsProcessActionRunning) 288 stateString += " (process)"; 289 else if (fIsProcessRunning && fIsProcessActionRunning) 290 stateString += " (process, process-action)"; 291 else if (!fIsProcessRunning && fIsProcessActionRunning) 292 stateString += " (process-action)"; 293 294 return stateString; 295 case COMPLETE: 296 return COMPLETE_STRING; 297 default: 298 return STATE_UNKNOWN_STRING; 299 } 300 } 301 getInfo()302 public String getInfo() 303 { 304 if (fName.length() > 40) 305 return fName.substring(0, 40) + "..."; 306 else 307 return fName; 308 } 309 getDetails()310 public String getDetails() 311 { 312 StringBuffer result = new StringBuffer(); 313 314 result.append("State:").append(getStateAsString()).append(";Name:"). 315 append(fName).append(";Location:").append(fLocation). 316 append(";Command:").append(fCommand); 317 if (!fCommandMode.equals("")) 318 result.append(";CommandMode:").append(fCommandMode); 319 if (!fCommandShell.equals("")) 320 result.append(";CommandShell:").append(fCommandShell); 321 if (!fWorkload.equals("")) 322 result.append(";Workload:").append(fWorkload); 323 if (!fTitle.equals("")) 324 result.append(";Title:").append(fTitle); 325 if (!fParms.equals("")) 326 result.append(";Parms:").append(fParms); 327 if (!fWorkdir.equals("")) 328 result.append(";Workdir:").append(fWorkdir); 329 330 for (int i = 0; i < fVars.size(); i++) 331 { 332 result.append(";Var").append(i + 1).append(":").append( 333 fVars.elementAt(i)); 334 } 335 336 for (int i = 0; i < fEnvs.size(); i++) 337 { 338 result.append(";Env").append(i + 1).append(":").append( 339 fEnvs.elementAt(i)); 340 } 341 342 if (!fUseprocessvars.equals("")) 343 result.append(";Useprocessvars:").append(fUseprocessvars); 344 if (!fStopusing.equals("")) 345 result.append(";Stopusing:").append(fStopusing); 346 if (!fConsole.equals("")) 347 result.append(";Console:").append(fConsole); 348 if (!fFocus.equals("")) 349 result.append(";Focus:").append(fFocus); 350 if (!fUsername.equals("")) 351 result.append(";Username:").append(fUsername); 352 if (!fPassword.equals("")) 353 result.append(";Password:*******"); 354 if (!fDisabledauth.equals("")) 355 result.append(";Disabledauth:").append(fDisabledauth); 356 if (!fStatichandlename.equals("")) 357 result.append(";Statichandlename:").append(fStatichandlename); 358 if (!fStdin.equals("")) 359 result.append(";Stdin:").append(fStdin); 360 if (!fStdout.equals("")) 361 result.append(";Stdout:").append(fStdout); 362 if (!fStdoutMode.equals("")) 363 result.append(";StdoutMode:").append(fStdoutMode); 364 if (!fStderr.equals("")) 365 result.append(";Stderr:").append(fStderr); 366 if (!fStderrMode.equals("")) 367 result.append(";StderrMode:").append(fStderrMode); 368 if (!fReturnStdout.equals("")) 369 result.append(";ReturnStdout:").append(fReturnStdout); 370 if (!fReturnStderr.equals("")) 371 result.append(";ReturnStderr:").append(fReturnStderr); 372 373 for (int i = 0; i < fReturnFiles.size(); i++) 374 { 375 result.append(";ReturnFile").append(i + 1).append(":"). 376 append(fReturnFiles.elementAt(i)); 377 } 378 379 if (!fOther.equals("")) 380 result.append(";Other:").append(fOther); 381 382 result.append(";RequestNumber:").append(fRequestNumber). 383 append(";RequestRC:").append(fRequestRC). 384 append(";Request:").append(fRequest). 385 append(";RequestResult:").append(fRequestResult). 386 append(";ProcessHandle:").append(fProcessHandle). 387 append(";ProcessRC:").append(fProcessRC). 388 append(";ProcessTimestamp:").append(fProcessTimestamp). 389 append(";StartTimestamp:").append(fStartTimestamp). 390 append(";BlockName:").append(fCurrentBlockName); 391 392 return result.toString(); 393 } 394 execute(STAXThread thread)395 public void execute(STAXThread thread) 396 { 397 synchronized (this) 398 { 399 if (fState == INIT) 400 { 401 fThread = thread; 402 403 if (fThread.getJob().getSTAX().getDebugProcess()) 404 { 405 STAX.logToJVMLog( 406 "Debug", fThread, 407 "key=" + fLocation + 408 " STAXProcessAction::execute(): fState=INIT"); 409 } 410 411 // Evaluate the process element and attribute values and 412 // generate a process start request and assign to fRequest. 413 414 if (generateProcessStartRequest() != 0) 415 { 416 if (fThread.getJob().getSTAX().getDebugProcess()) 417 { 418 STAX.logToJVMLog( 419 "Debug", fThread, 420 "key=" + fLocation + 421 " STAXProcessAction::execute(): " + 422 "generateProcessStartRequest() failed - return"); 423 } 424 425 return; 426 } 427 428 // Set current block name 429 try 430 { 431 fCurrentBlockName = fThread.pyStringEval( 432 "STAXCurrentBlock"); 433 } 434 catch (STAXPythonEvaluationException e) 435 { 436 fCurrentBlockName = ""; // Shouldn't happen 437 } 438 439 // Set to the current date and time. 440 fStartTimestamp = new STAXTimestamp(); 441 442 fState = WAIT_REQUEST; 443 444 fProcessKey = new Integer( 445 fThread.getJob().getNextProcessKey()).toString(); 446 447 if (fThread.getJob().getSTAX().getDebugProcess()) 448 { 449 STAX.logToJVMLog( 450 "Debug", fThread, 451 "key=" + fLocation + 452 " STAXProcessAction::execute(): " + 453 "Submitting PROCESS START NOTIFY ONEND KEY " + 454 fProcessKey + " " + fRequest); 455 } 456 457 // Submit PROCESS START STAF Command 458 459 STAFResult submitResult = fThread.getJob().submitAsync( 460 fLocation, "process", "START NOTIFY ONEND KEY " + 461 fProcessKey + " " + fRequest, this); 462 463 if (fThread.getJob().getSTAX().getDebugProcess()) 464 { 465 STAX.logToJVMLog( 466 "Debug", fThread, 467 "key=" + fLocation + 468 " STAXProcessAction::execute(): " + 469 "PROCESS START request submit RC=" + submitResult.rc + 470 ", Result=" + submitResult.result); 471 } 472 473 if (submitResult.rc == 0 ) 474 { 475 fRequestNumber = (new Integer(submitResult.result)). 476 intValue(); 477 } 478 479 if (fRequestNumber == 0) 480 { 481 // Request failed - Raise a STAXProcessStartError signal 482 fState = COMPLETE; 483 fThread.popAction(); 484 485 setPythonVariablesWhenFail( 486 "Process failed to start. Raised a " + 487 "STAXProcessStartError signal."); 488 489 setElementInfo(new STAXElementInfo( 490 getElement(), STAXElementInfo.NO_ATTRIBUTE_NAME, 491 "The process failed to start, Request#: 0, RC: " + 492 submitResult.rc + ", STAFResult: " + 493 submitResult.result)); 494 495 fThread.setSignalMsgVar( 496 "STAXProcessStartErrorMsg", 497 STAXUtil.formatErrorMessage(this)); 498 499 fThread.raiseSignal("STAXProcessStartError"); 500 501 return; 502 } 503 504 if (false && fThread.getJob().getSTAX().getDebugProcess()) 505 { 506 STAX.logToJVMLog( 507 "Debug", fThread, 508 "key=" + fLocation + 509 " STAXProcessAction::execute(): " + 510 "Add timed event - timeout=" + 511 fThread.getJob().getSTAX().getProcessTimeout()); 512 } 513 514 // Add a TimedEvent to the queue and return 515 516 fTimedEvent = new STAXTimedEvent(System.currentTimeMillis() + 517 fThread.getJob().getSTAX().getProcessTimeout(), this); 518 519 fThread.getJob().getTimedEventQueue().addTimedEvent( 520 fTimedEvent); 521 522 fThread.addCondition(fHoldCondition); 523 524 if (fThread.getJob().getSTAX().getDebugProcess()) 525 { 526 STAX.logToJVMLog( 527 "Debug", fThread, 528 "key=" + fLocation + 529 " STAXProcessAction::execute(): " + 530 "Added hold condition: State=" + getStateAsString()); 531 } 532 } 533 else if (fState == REQUEST_ERROR) 534 { 535 fState = COMPLETE; 536 fThread.popAction(); 537 538 fThread.pySetVar("RC", new Integer(fRequestRC)); 539 fThread.pySetVar("STAFResult", fRequestResult); 540 fThread.pySetVar("STAXResult", Py.None); 541 542 if (fThread.getJob().getSTAX().getDebugProcess()) 543 { 544 STAX.logToJVMLog( 545 "Debug", fThread, 546 "key=" + fLocation + ":" + fProcessHandle + 547 " STAXProcessAction::execute(): " + 548 "fState=REQUEST_ERROR - " + 549 "Raise STAXProcessStartError signal"); 550 } 551 552 setElementInfo(new STAXElementInfo( 553 getElement(), STAXElementInfo.NO_ATTRIBUTE_NAME, 554 "The process failed to start, RC: " + 555 fRequestRC + ", STAFResult: " + fRequestResult)); 556 557 fThread.setSignalMsgVar( 558 "STAXProcessStartErrorMsg", 559 STAXUtil.formatErrorMessage(this)); 560 561 fThread.raiseSignal("STAXProcessStartError"); 562 } 563 else if (fState == REQUEST_TIMEOUT) 564 { 565 // The process request did not start within the timeout, 566 // PROCESSTIMEOUT, (requestComplete was not called) so 567 // generate a STAXProcessStartTimeout signal 568 569 fState = COMPLETE; 570 fThread.popAction(); 571 572 if (fThread.getJob().getSTAX().getDebugProcess()) 573 { 574 STAX.logToJVMLog( 575 "Debug", fThread, 576 "key=" + fLocation + ":" + fProcessHandle + 577 " STAXProcessAction::execute(): " + 578 "fState=REQUEST_TIMEOUT - Raise " + 579 "STAXProcessStartTimeout signal"); 580 } 581 582 String timeoutMsg = "Process did not start within timeout " + 583 "value " + fThread.getJob().getSTAX().getProcessTimeout(); 584 585 // Set RC, STAFResult, STAXResult to indicate a timeout signal 586 587 fRequestRC = STAFResult.Timeout; 588 fThread.pySetVar("RC", new Integer(STAFResult.Timeout)); 589 fThread.pySetVar("STAFResult", timeoutMsg + 590 ". Raised a STAXProcessStartTimeout signal"); 591 fThread.pySetVar("STAXResult", Py.None); 592 593 setElementInfo(new STAXElementInfo( 594 getElement(), STAXElementInfo.NO_ATTRIBUTE_NAME, 595 timeoutMsg)); 596 597 fThread.setSignalMsgVar( 598 "STAXProcessStartTimeoutMsg", 599 STAXUtil.formatErrorMessage(this)); 600 601 fThread.raiseSignal("STAXProcessStartTimeout"); 602 } 603 else if ((fState == RUNNING) && 604 !fIsProcessRunning && !fIsProcessActionRunning) 605 { 606 if (fThread.getJob().getSTAX().getDebugProcess()) 607 { 608 STAX.logToJVMLog( 609 "Debug", fThread, 610 "key=" + fLocation + ":" + fProcessHandle + 611 " STAXProcessAction::execute(): fState=" + 612 getStateAsString()); 613 } 614 615 fState = COMPLETE; 616 fThread.popAction(); 617 618 // Set variables when process and process-action have completed 619 620 if (fThread.getJob().getSTAX().getDebugProcess()) 621 { 622 STAX.logToJVMLog( 623 "Debug", fThread, 624 "key=" + fLocation + ":" + fProcessHandle + 625 " STAXProcessAction::execute(): fState=COMPLETE, " + 626 "Set RC=" + fProcessRC + 627 ", STAFResult=" + fProcessSTAFResult); 628 // ", STAXResult=" + fProcessSTAXResult.length()); 629 } 630 631 fThread.pySetVar("RC", new Long(fProcessRC)); 632 fThread.pySetVar("STAFResult", fProcessSTAFResult); 633 634 try 635 { 636 fThread.pySetVar("STAXResult", fProcessSTAXResult); 637 } 638 catch (Exception ex) 639 { 640 // This should never happen 641 ex.printStackTrace(); 642 643 fThread.pySetVar("STAXResult", Py.None); 644 fProcessSTAXResult = Py.None; 645 646 setElementInfo(new STAXElementInfo( 647 getElement(), STAXElementInfo.NO_ATTRIBUTE_NAME, 648 "Error setting STAXResult to resultList.\n" + 649 "fileList: " + fProcessSTAXResult.toString() + 650 "\n\n" + ex.toString())); 651 652 fThread.setSignalMsgVar( 653 "STAXPythonEvalMsg", 654 STAXUtil.formatErrorMessage(this)); 655 656 fThread.raiseSignal("STAXPythonEvaluationError"); 657 } 658 } 659 else if (fState == COMPLETE) 660 { 661 // Note: We shouldn't be called in this state. 662 663 if (fThread.getJob().getSTAX().getDebugProcess()) 664 { 665 STAX.logToJVMLog( 666 "Debug", fThread, 667 "key=" + fLocation + ":" + fProcessHandle + 668 " STAXProcessAction::execute(): fState=COMPLETE " + 669 " when shouldn't be called in this state"); 670 } 671 672 fThread.popAction(); 673 } 674 else if (fThread.getJob().getSTAX().getDebugProcess()) 675 { 676 // Should not get here 677 678 STAX.logToJVMLog( 679 "Debug", fThread, 680 "key=" + fLocation + ":" + fProcessHandle + 681 " STAXProcessAction::execute(): fState=" + 682 getStateAsString() + " is an unexpected state"); 683 } 684 } // End synchronized (this) 685 } 686 687 688 // Note that this entire method is synchronized handleCondition(STAXThread thread, STAXCondition cond)689 public synchronized void handleCondition(STAXThread thread, 690 STAXCondition cond) 691 { 692 synchronized (this) 693 { 694 if (thread.getJob().getSTAX().getDebugProcess()) 695 { 696 STAX.logToJVMLog( 697 "Debug", thread, 698 "key=" + fLocation + ":" + fProcessHandle + 699 " STAXProcessAction::handleCondition():" + 700 " fState=" + getStateAsString()); 701 } 702 703 // Check if the process is running 704 705 if ((fState == RUNNING) && fIsProcessRunning) 706 { 707 fIsProcessRunning = false; 708 709 if (thread.getJob().getSTAX().getDebugProcess()) 710 { 711 STAX.logToJVMLog( 712 "Debug", thread, 713 "key=" + fLocation + ":" + fProcessHandle + 714 " STAXProcessAction::handleCondition():" + 715 " removeHoldCondition and stop handle"); 716 } 717 718 // Stop the process and free its termination info 719 // 1) Want to do this asynchronously in a single request for 720 // performance reasons since we're in synchronized code 721 // 2) Had to add a short delay (1 second) to allow time for 722 // the process to be completely stopped before submitting 723 // the FREE request 724 725 String stopFreeProcessCommand = 726 "STAF local PROCESS STOP HANDLE " + fProcessHandle + 727 " {STAF/Config/Sep/Command} " + 728 "STAF local DELAY DELAY 1000" + 729 " {STAF/Config/Sep/Command} " + 730 "STAF local PROCESS FREE HANDLE " + fProcessHandle; 731 732 thread.getJob().submitAsyncForget( 733 fLocation, "PROCESS", "START SHELL COMMAND " + 734 STAFUtil.wrapData(stopFreeProcessCommand) + " WAIT"); 735 736 // Generate a stop process event 737 738 generateProcessStopEvent(); 739 740 // Remove the process from the processRequestMap 741 742 String key = (fLocation + ":" + fProcessHandle).toLowerCase(); 743 TreeMap processes = (TreeMap)thread.getJob().getData( 744 "processRequestMap"); 745 746 if (processes != null) 747 { 748 synchronized (processes) 749 { 750 processes.remove(key); 751 } 752 } 753 } 754 755 // Terminate the process-action task if running 756 757 synchronized (fThreadMap) 758 { 759 if (!fThreadMap.isEmpty()) 760 { 761 if (thread.getJob().getSTAX().getDebugProcess()) 762 { 763 STAX.logToJVMLog( 764 "Debug", thread, 765 "key=" + fLocation + ":" + fProcessHandle + 766 " STAXProcessAction::handleCondition():" + 767 " Add HardHoldThread condition and terminate " + 768 "process-action thread"); 769 } 770 771 // Add a hard hold so we can wait until our children 772 // terminate. This is removed by threadComplete(). 773 774 thread.addCondition(fHardHoldCondition); 775 776 // Now, iterate of our children and tell them to terminate 777 778 for (STAXThread childThread : fThreadMap.values()) 779 { 780 childThread.terminate( 781 STAXThread.THREAD_END_STOPPED_BY_PARENT); 782 } 783 784 // Now, return so we can go to sleep 785 786 return; 787 } 788 } 789 790 fState = COMPLETE; 791 792 // Remove the HoldThread condition from the thread's condition 793 // stack (if it exists) 794 795 if (thread.getJob().getSTAX().getDebugProcess()) 796 { 797 STAX.logToJVMLog( 798 "Debug", thread, 799 "key=" + fLocation + ":" + fProcessHandle + 800 " STAXProcessAction::handleCondition(): Set fState=" + 801 "COMPLETE and remove HoldThread condition: " + 802 thread.getConditionStack()); 803 } 804 805 thread.removeCondition(fHoldCondition); 806 807 if (thread.getJob().getSTAX().getDebugProcess()) 808 { 809 STAX.logToJVMLog( 810 "Debug", thread, 811 "key=" + fLocation + ":" + fProcessHandle + 812 " STAXProcessAction::handleCondition(): " + 813 "Removed HoldThread condition"); 814 } 815 816 thread.popAction(); 817 } 818 } 819 cloneAction()820 public STAXAction cloneAction() 821 { 822 STAXProcessAction clone = new STAXProcessAction(); 823 824 clone.setElement(getElement()); 825 clone.setLineNumberMap(getLineNumberMap()); 826 clone.setXmlFile(getXmlFile()); 827 clone.setXmlMachine(getXmlMachine()); 828 829 clone.fUnevalLocation = fUnevalLocation; 830 clone.fUnevalCommand = fUnevalCommand; 831 clone.fUnevalName = fUnevalName; 832 clone.fUnevalWorkload = fUnevalWorkload; 833 clone.fUnevalWorkdir = fUnevalWorkdir; 834 clone.fUnevalTitle = fUnevalTitle; 835 clone.fUnevalParms = fUnevalParms; 836 clone.fUnevalWorkdir = fUnevalWorkdir; 837 clone.fUnevalVars = fUnevalVars; 838 clone.fUnevalEnvs = fUnevalEnvs; 839 clone.fUnevalUseprocessvars = fUnevalUseprocessvars; 840 clone.fUnevalStopusing = fUnevalStopusing; 841 clone.fUnevalConsole = fUnevalConsole; 842 clone.fUnevalFocus = fUnevalFocus; 843 clone.fUnevalUsername = fUnevalUsername; 844 clone.fUnevalPassword = fUnevalPassword; 845 clone.fUnevalDisabledauth = fUnevalDisabledauth; 846 clone.fUnevalStatichandlename = fUnevalStatichandlename; 847 clone.fUnevalStdin = fUnevalStdin; 848 clone.fUnevalStdout = fUnevalStdout; 849 clone.fUnevalStdoutMode = fUnevalStdoutMode; 850 clone.fUnevalStderr = fUnevalStderr; 851 clone.fUnevalStderrMode = fUnevalStderrMode; 852 clone.fUnevalReturnStdout = fUnevalReturnStdout; 853 clone.fUnevalReturnStderr = fUnevalReturnStderr; 854 clone.fUnevalReturnFiles = fUnevalReturnFiles; 855 clone.fUnevalOther = fUnevalOther; 856 clone.fUnevalCommandMode = fUnevalCommandMode; 857 clone.fUnevalCommandShell = fUnevalCommandShell; 858 859 clone.fCurrentBlockName = fCurrentBlockName; 860 clone.fFactory = fFactory; 861 clone.fLocation = fLocation; 862 clone.fCommand = fCommand; 863 clone.fName = fName; 864 clone.fWorkload = fWorkload; 865 clone.fWorkloadIf = fWorkloadIf; 866 clone.fWorkdir = fWorkdir; 867 clone.fWorkdirIf = fWorkdirIf; 868 clone.fTitle = fTitle; 869 clone.fTitleIf = fTitleIf; 870 clone.fParms = fParms; 871 clone.fParmsIf = fParmsIf; 872 clone.fVars = new Vector<String>(); 873 clone.fVarsIf = fVarsIf; 874 clone.fEnvs = new Vector<String>(); 875 clone.fEnvsIf = fEnvsIf; 876 clone.fUseprocessvars = fUseprocessvars; 877 clone.fUseprocessvarsIf = fUseprocessvarsIf; 878 clone.fStopusing = fStopusing; 879 clone.fStopusingIf = fStopusingIf; 880 clone.fConsole = fConsole; 881 clone.fConsoleIf = fConsoleIf; 882 clone.fFocus = fFocus; 883 clone.fFocusIf = fFocusIf; 884 clone.fUsername = fUsername; 885 clone.fUsernameIf = fUsernameIf; 886 clone.fPassword = fPassword; 887 clone.fPasswordIf = fPasswordIf; 888 clone.fDisabledauth = fDisabledauth; 889 clone.fDisabledauthIf = fDisabledauthIf; 890 clone.fStatichandlename = fStatichandlename; 891 clone.fStatichandlenameIf = fStatichandlenameIf; 892 clone.fStdin = fStdin; 893 clone.fStdinIf = fStdinIf; 894 clone.fStdout = fStdout; 895 clone.fStdoutIf = fStdoutIf; 896 clone.fStdoutMode = fStdoutMode; 897 clone.fStderr = fStderr; 898 clone.fStderrIf = fStderrIf; 899 clone.fStderrMode = fStderrMode; 900 clone.fReturnStdout = fReturnStdout; 901 clone.fReturnStdoutIf = fReturnStdoutIf; 902 clone.fReturnStderr = fReturnStderr; 903 clone.fReturnStderrIf = fReturnStderrIf; 904 clone.fReturnFiles = new Vector<String>(); 905 clone.fReturnFilesIf = fReturnFilesIf; 906 clone.fOther = fOther; 907 clone.fOtherIf = fOtherIf; 908 clone.fProcessAction = fProcessAction; 909 clone.fProcessActionIf = fProcessActionIf; 910 clone.fCommandMode = fCommandMode; 911 clone.fCommandShell = fCommandShell; 912 913 return clone; 914 } 915 916 // STAXTimedEventListener method 917 918 // Note that this entire method is synchronized timedEventOccurred(STAXTimedEvent timedEvent)919 public synchronized void timedEventOccurred(STAXTimedEvent timedEvent) 920 { 921 if (fThread.getJob().getSTAX().getDebugProcess()) 922 { 923 STAX.logToJVMLog( 924 "Debug", fThread, 925 "key=" + fLocation + ":" + fProcessHandle + 926 " STAXProcessAction::timedEventOccurred(): fState=" + 927 getStateAsString()); 928 } 929 930 if (fState == WAIT_REQUEST) 931 { 932 if (fThread.getJob().getSTAX().getDebugProcess()) 933 { 934 STAX.logToJVMLog( 935 "Debug", fThread, 936 "key=" + fLocation + ":" + fProcessHandle + 937 " STAXProcessAction::timedEventOccurred(): Set " + 938 "fState=REQUEST_TIMEOUT, remove holdCondition, " + 939 "and schedule thread"); 940 } 941 942 fState = REQUEST_TIMEOUT; 943 fThread.removeCondition(fHoldCondition); 944 fThread.schedule(); 945 } 946 } 947 948 // STAXSTAFRequestCompleteListener method 949 950 // Note that this entire method is synchronized requestComplete(int requestNumber, STAFResult result)951 public synchronized void requestComplete(int requestNumber, 952 STAFResult result) 953 { 954 if (fThread.getJob().getSTAX().getDebugProcess()) 955 { 956 STAX.logToJVMLog( 957 "Debug", fThread, 958 "key=" + fLocation + 959 " STAXProcessAction::requestComplete(): fState=" + 960 getStateAsString() + ", RC=" + result.rc + 961 ", Result=" + result.result); 962 } 963 964 // Already COMPLETE, so something like a STAXProcessRequestTimeout 965 // signal could have already been raised, so just return 966 967 if (fState == COMPLETE) return; 968 969 // Remove the timeout event from the STAXTimedEventQueue 970 971 fThread.getJob().getTimedEventQueue().removeTimedEvent(fTimedEvent); 972 973 if (result.rc == 0) 974 { 975 fState = RUNNING; 976 977 try 978 { 979 // XXX: Why do we store the handle in "int" form instead of 980 // just storing the handle in "string" form 981 982 fProcessHandle = Integer.parseInt(result.result); 983 984 // Register for Process Completion 985 986 String key = new String(); 987 String machine = fLocation; 988 989 if (fUsingProcessKeyOption) 990 { 991 key = fProcessKey; 992 } 993 else 994 { 995 key = (machine + "/" + fProcessHandle).toLowerCase(); 996 } 997 998 @SuppressWarnings("unchecked") 999 HashMap<String, Object> processMap = 1000 (HashMap<String, Object>)fThread.getJob().getData( 1001 "processMap"); 1002 1003 if (processMap != null) 1004 { 1005 synchronized (processMap) 1006 { 1007 // If we have a race condition, we may have already 1008 // received the "process end" message 1009 1010 if (processMap.containsKey(key)) 1011 { 1012 if (fThread.getJob().getSTAX().getDebugProcess()) 1013 { 1014 STAX.logToJVMLog( 1015 "Debug", fThread, 1016 "key=" + fLocation + ":" + fProcessHandle + 1017 " STAXProcessAction::requestComplete(): " + 1018 "RACE CONDITION - remove from processMap" + 1019 ", key=" + key); 1020 } 1021 1022 STAXSTAFMessage completionMessage = 1023 (STAXSTAFMessage)processMap.get(key); 1024 1025 processMap.remove(key); 1026 1027 // If a process-action is specified, start its action before 1028 // calling processComplete() 1029 1030 if ((fProcessAction != null) && fProcessActionFlag) 1031 { 1032 // Start action specified by <process-action> element 1033 1034 synchronized (fThreadMap) 1035 { 1036 fIsProcessActionRunning = true; 1037 1038 fThread.pySetVar("STAXProcessHandle", 1039 String.valueOf(fProcessHandle)); 1040 1041 STAXThread childThread = fThread.createChildThread(); 1042 1043 fThreadMap.put(childThread.getThreadNumber(), childThread); 1044 1045 STAXAction childThreadAction = fProcessAction; 1046 1047 childThread.addCompletionNotifiee(this); 1048 childThread.pushAction( 1049 childThreadAction.cloneAction()); 1050 childThread.schedule(); 1051 } 1052 } 1053 1054 processComplete(machine, fProcessHandle, 1055 completionMessage.getProcessRC(), 1056 completionMessage.getProcessResultAsList(), 1057 completionMessage.getProcessTimestamp()); 1058 1059 return; 1060 } 1061 else 1062 { 1063 fIsProcessRunning = true; 1064 1065 if (false && fThread.getJob().getSTAX().getDebugProcess()) 1066 { 1067 STAX.logToJVMLog( 1068 "Debug", fThread, 1069 "key=" + fLocation + ":" + fProcessHandle + 1070 " STAXProcessAction::requestComplete(): " + 1071 "Not race condition: add to processMap, " + 1072 "key=" + key); 1073 } 1074 1075 processMap.put(key, this); 1076 } 1077 } 1078 } 1079 } 1080 catch (NumberFormatException e) 1081 { 1082 // XXX: Do something. Maybe set fState = ERROR? 1083 } 1084 1085 if (fIsProcessRunning) 1086 { 1087 // Add the process to the processRequestMap 1088 1089 String key = (fLocation + ":" + fProcessHandle).toLowerCase(); 1090 1091 if (fThread.getJob().getSTAX().getDebugProcess()) 1092 { 1093 STAX.logToJVMLog( 1094 "Debug", fThread, 1095 "key=" + fLocation + ":" + fProcessHandle + 1096 " STAXProcessAction::requestComplete(): " + 1097 "Add to processRequestMap"); 1098 } 1099 1100 @SuppressWarnings("unchecked") 1101 TreeMap<String, STAXProcessAction> processes = 1102 (TreeMap<String, STAXProcessAction>)fThread.getJob(). 1103 getData("processRequestMap"); 1104 1105 if (processes != null) 1106 { 1107 synchronized (processes) 1108 { 1109 processes.put(key, this); 1110 } 1111 } 1112 1113 // Generate a process start event 1114 generateProcessStartEvent(); 1115 } 1116 1117 if ((fProcessAction != null) && fProcessActionFlag) 1118 { 1119 // Start action specified by <process-action> element 1120 1121 synchronized (fThreadMap) 1122 { 1123 fIsProcessActionRunning = true; 1124 1125 fThread.pySetVar("STAXProcessHandle", 1126 String.valueOf(fProcessHandle)); 1127 1128 STAXThread childThread = fThread.createChildThread(); 1129 1130 fThreadMap.put(childThread.getThreadNumber(), childThread); 1131 1132 STAXAction childThreadAction = fProcessAction; 1133 1134 childThread.addCompletionNotifiee(this); 1135 childThread.pushAction( 1136 childThreadAction.cloneAction()); 1137 childThread.schedule(); 1138 } 1139 } 1140 } 1141 else 1142 { 1143 if ((result.rc == STAFResult.InvalidRequestString) && 1144 fUsingProcessKeyOption) 1145 { 1146 // The target machine may not support the KEY option, 1147 // so re-submit the request without the KEY option. 1148 // If the second submit fails, then the InvalidRequestString 1149 // is not due to the KEY option not being supported. 1150 1151 fUsingProcessKeyOption = false; 1152 1153 // Submit PROCESS START STAF Command 1154 1155 STAFResult submitResult = fThread.getJob().submitAsync( 1156 fLocation, "PROCESS", "START NOTIFY ONEND " + 1157 fRequest, this); 1158 1159 if (submitResult.rc == 0 ) 1160 { 1161 fRequestNumber = (new Integer(submitResult.result)). 1162 intValue(); 1163 } 1164 1165 if (fRequestNumber == 0) 1166 { 1167 // Request failed - Raise a STAXProcessStartError signal 1168 fState = COMPLETE; 1169 fThread.popAction(); 1170 1171 fThread.pySetVar("RC", new Integer(submitResult.rc)); 1172 fThread.pySetVar("STAFResult", submitResult.result); 1173 fThread.pySetVar("STAXResult", Py.None); 1174 1175 setElementInfo(new STAXElementInfo( 1176 getElement(), STAXElementInfo.NO_ATTRIBUTE_NAME, 1177 "The process failed to start, Request#: 0, RC: " + 1178 submitResult.rc + ", STAFResult: " + 1179 submitResult.result)); 1180 1181 fThread.setSignalMsgVar( 1182 "STAXProcessStartErrorMsg", 1183 STAXUtil.formatErrorMessage(this)); 1184 1185 fThread.raiseSignal("STAXProcessStartError"); 1186 1187 fThread.schedule(); 1188 1189 return; 1190 } 1191 } 1192 else 1193 { 1194 fRequestRC = result.rc; 1195 fRequestResult = result.result; 1196 1197 if (fThread.getJob().getSTAX().getDebugProcess()) 1198 { 1199 STAX.logToJVMLog( 1200 "Debug", fThread, 1201 "key=" + fLocation + ":" + fProcessHandle + 1202 " STAXProcessAction::requestComplete(): " + 1203 "set fState=REQUEST_ERROR and remove holdCondition " + 1204 "and schedule thread"); 1205 } 1206 1207 fState = REQUEST_ERROR; 1208 fThread.removeCondition(fHoldCondition); 1209 fThread.schedule(); 1210 } 1211 } 1212 } 1213 processComplete(String machine, int handle, long rc, List fileList, String timestamp)1214 public synchronized void processComplete(String machine, int handle, 1215 long rc, List fileList, String timestamp) 1216 { 1217 if (fThread.getJob().getSTAX().getDebugProcess()) 1218 { 1219 STAX.logToJVMLog( 1220 "Debug", fThread, 1221 "key=" + fLocation + ":" + fProcessHandle + 1222 " STAXProcessAction::processComplete(): " + 1223 "RC=" + rc + " fState=" + getStateAsString()); 1224 } 1225 1226 fThread.getJob().submitAsyncForget( 1227 fLocation, "PROCESS", "FREE HANDLE " + fProcessHandle); 1228 1229 if (fState == COMPLETE) return; 1230 1231 if (fIsProcessRunning) 1232 { 1233 fIsProcessRunning = false; 1234 1235 // We only generate the stop event if we aren't COMPLETE. If we 1236 // were terminated before the process finished, then we generated 1237 // the stop event at that time. 1238 generateProcessStopEvent(); 1239 1240 // Remove the process from the processRequestMap 1241 1242 String key = (fLocation + ":" + fProcessHandle).toLowerCase(); 1243 1244 if (fThread.getJob().getSTAX().getDebugProcess()) 1245 { 1246 STAX.logToJVMLog( 1247 "Debug", fThread, 1248 "key=" + fLocation + ":" + fProcessHandle + 1249 " STAXProcessAction::processComplete():" + 1250 " Remove from processRequestMap"); 1251 } 1252 1253 TreeMap processes = (TreeMap)fThread.getJob().getData( 1254 "processRequestMap"); 1255 1256 if (processes != null) 1257 { 1258 synchronized (processes) 1259 { 1260 processes.remove(key); 1261 } 1262 } 1263 } 1264 1265 // Save process RC, STAFResult, and STAXResult values to set (in 1266 // the execute method) when both the process and process-action 1267 // have completed. 1268 1269 fProcessRC = rc; 1270 fProcessSTAFResult = Py.None; 1271 1272 PyList resultList = getResultList(fileList); 1273 1274 if (resultList != null) 1275 { 1276 fProcessSTAXResult = resultList; 1277 } 1278 1279 fProcessTimestamp = timestamp; 1280 1281 // If the process-action (if any) has completed, remove the HoldThread 1282 // condition and schedule the thread to run 1283 1284 if (fThreadMap.isEmpty()) 1285 { 1286 if (fThread.getJob().getSTAX().getDebugProcess()) 1287 { 1288 STAX.logToJVMLog( 1289 "Debug", fThread, 1290 "key=" + fLocation + ":" + fProcessHandle + 1291 " STAXProcessAction::processComplete():" + 1292 " Remove HoldThread condition: " + 1293 fThread.getConditionStack()); 1294 } 1295 1296 fThread.removeCondition(fHoldCondition); 1297 fThread.schedule(); 1298 } 1299 } 1300 threadComplete(STAXThread thread, int endCode)1301 public synchronized void threadComplete(STAXThread thread, int endCode) 1302 { 1303 synchronized(fThreadMap) 1304 { 1305 if (thread.getJob().getSTAX().getDebugProcess()) 1306 { 1307 STAX.logToJVMLog( 1308 "Debug", thread, 1309 "key=" + fLocation + ":" + fProcessHandle + 1310 " STAXProcessAction::threadComplete():" + 1311 " fState=" + getStateAsString()); 1312 } 1313 1314 fThreadMap.remove(thread.getThreadNumberAsInteger()); 1315 1316 if (fThreadMap.isEmpty()) 1317 { 1318 fIsProcessActionRunning = false; 1319 1320 // Note that thread.getParentThread() is the thread we are 1321 // running on 1322 1323 if (thread.getJob().getSTAX().getDebugProcess()) 1324 { 1325 STAX.logToJVMLog( 1326 "Debug", thread, 1327 "key=" + fLocation + ":" + fProcessHandle + 1328 " STAXProcessAction::threadComplete():" + 1329 " Remove HardHoldThread condition: " + 1330 thread.getParentThread().getConditionStack()); 1331 } 1332 1333 thread.getParentThread().removeCondition(fHardHoldCondition); 1334 1335 if ((fState == RUNNING) && !fIsProcessRunning) 1336 { 1337 if (thread.getJob().getSTAX().getDebugProcess()) 1338 { 1339 STAX.logToJVMLog( 1340 "Debug", thread, 1341 "key=" + fLocation + ":" + fProcessHandle + 1342 " STAXProcessAction::threadComplete():" + 1343 " Remove HoldThread condition: " + 1344 thread.getParentThread().getConditionStack()); 1345 } 1346 1347 thread.getParentThread().removeCondition(fHoldCondition); 1348 } 1349 1350 thread.getParentThread().schedule(); 1351 } 1352 } 1353 } 1354 getResultList(List fileList)1355 public PyList getResultList(List fileList) 1356 { 1357 if (fileList == null || fileList.size() == 0) return null; 1358 1359 // Create a Python List to contain a list of returned file info: 1360 // [ [ File1 RC, File1 Data ], [ File2 RC, File2 Data ], ... ] 1361 PyList resultList = new PyList(); 1362 1363 try 1364 { 1365 Iterator iter = fileList.iterator(); 1366 1367 while (iter.hasNext()) 1368 { 1369 Map fileInfoMap = (Map)iter.next(); 1370 1371 // Create a Python List to contain file information (RC & data) 1372 PyList fileInfoList = new PyList(); 1373 1374 // Assign file RC 1375 fileInfoList.append(Py.java2py( 1376 new Integer((String)fileInfoMap.get("rc")))); 1377 fileInfoList.append(Py.java2py( 1378 (String)fileInfoMap.get("data"))); 1379 1380 // Add file information List to result List 1381 resultList.append(fileInfoList); 1382 } 1383 } 1384 catch (Exception ex) 1385 { 1386 // This should never happen 1387 ex.printStackTrace(); 1388 1389 fThread.pySetVar("STAXResult", Py.None); 1390 1391 setElementInfo(new STAXElementInfo( 1392 getElement(), STAXElementInfo.NO_ATTRIBUTE_NAME, 1393 "Error assigning the content of the files returned by the " + 1394 "\"process\" to STAXResult. File List: " + 1395 fileList.toString() + "\n\n" + ex.toString())); 1396 1397 fThread.setSignalMsgVar( 1398 "STAXPythonEvalMsg", STAXUtil.formatErrorMessage(this)); 1399 1400 fThread.raiseSignal("STAXPythonEvaluationError"); 1401 } 1402 1403 return resultList; 1404 } 1405 setPythonVariablesWhenFail(String stafResult)1406 private void setPythonVariablesWhenFail(String stafResult) 1407 { 1408 fThread.pySetVar("RC", new Integer(-1)); 1409 fThread.pySetVar("STAFResult", stafResult); 1410 fThread.pySetVar("STAXResult", Py.None); 1411 } 1412 1413 // This method evaluates the process element/sub-elements and attribute 1414 // values and generates a process start request and assigns it to fRequest. 1415 // If an error occurs, it raises the appropriate signal and returns a 1416 //non-zero value. 1417 generateProcessStartRequest()1418 private int generateProcessStartRequest() 1419 { 1420 StringBuffer request = new StringBuffer(""); 1421 String evalElem = STAXElementInfo.NO_ELEMENT_NAME; 1422 String evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1423 int evalIndex = 0; 1424 1425 try 1426 { 1427 evalElem = "location"; 1428 fLocation = fThread.pyStringEval(fUnevalLocation); 1429 1430 if (!fName.equals("")) 1431 { 1432 evalElem = "process"; 1433 evalAttr = "name"; 1434 fName = fThread.pyStringEval(fUnevalName); 1435 } 1436 else 1437 { 1438 fName = "Process" + 1439 String.valueOf(fThread.getJob().getNextProcNumber()); 1440 fUnevalName = fName; 1441 } 1442 1443 evalElem = "command"; 1444 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1445 fCommand = fThread.pyStringEval(fUnevalCommand); 1446 1447 if (!fCommandMode.equals("")) 1448 { 1449 evalAttr = "mode"; 1450 fCommandMode= fThread.pyStringEval(fCommandMode); 1451 1452 if (!(fCommandMode.equalsIgnoreCase("shell")) && 1453 !(fCommandMode.equalsIgnoreCase("default"))) 1454 { 1455 // Raise a StartProcessError signal 1456 fState = COMPLETE; 1457 fThread.popAction(); 1458 1459 setPythonVariablesWhenFail( 1460 "Process failed to start. Raised a " + 1461 "STAXProcessStartError signal."); 1462 1463 setElementInfo(new STAXElementInfo( 1464 evalElem, evalAttr, evalIndex, 1465 "Invalid value: " + fCommandMode + 1466 "\n\nValid values for attribute \"mode\" are: " + 1467 "'default' or 'shell'.")); 1468 1469 fThread.setSignalMsgVar( 1470 "STAXProcessStartErrorMsg", 1471 STAXUtil.formatErrorMessage(this)); 1472 1473 fThread.raiseSignal("STAXProcessStartError"); 1474 1475 return 1; 1476 } 1477 1478 if (fCommandMode.equalsIgnoreCase("shell")) 1479 { 1480 request.append("SHELL "); 1481 1482 if (!fCommandShell.equals("")) 1483 { 1484 evalAttr = "shell"; 1485 fCommandShell= fThread.pyStringEval(fCommandShell); 1486 request.append(STAFUtil.wrapData(fCommandShell)); 1487 request.append(" "); 1488 } 1489 } 1490 else 1491 fCommandShell = ""; 1492 } 1493 1494 request.append("COMMAND "); 1495 request.append(STAFUtil.wrapData(fCommand)); 1496 1497 if (!fWorkload.equals("")) 1498 { 1499 evalElem = "workload"; 1500 evalAttr = "if"; 1501 1502 if (fThread.pyBoolEval(fWorkloadIf)) 1503 { 1504 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1505 fWorkload = fThread.pyStringEval(fUnevalWorkload); 1506 request.append(" WORKLOAD "); 1507 request.append(STAFUtil.wrapData(fWorkload)); 1508 } 1509 else 1510 fWorkload = ""; 1511 } 1512 1513 if (!fTitle.equals("")) 1514 { 1515 evalElem = "title"; 1516 evalAttr = "if"; 1517 1518 if (fThread.pyBoolEval(fTitleIf)) 1519 { 1520 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1521 fTitle = fThread.pyStringEval(fUnevalTitle); 1522 request.append(" TITLE "); 1523 request.append(STAFUtil.wrapData(fTitle)); 1524 } 1525 else 1526 fTitle = ""; 1527 } 1528 1529 if (!fParms.equals("")) 1530 { 1531 evalElem = "parms"; 1532 evalAttr = "if"; 1533 1534 if (fThread.pyBoolEval(fParmsIf)) 1535 { 1536 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1537 fParms = fThread.pyStringEval(fUnevalParms); 1538 request.append(" PARMS "); 1539 request.append(STAFUtil.wrapData(fParms)); 1540 } 1541 else 1542 fParms = ""; 1543 } 1544 1545 if (!fWorkdir.equals("")) 1546 { 1547 evalElem = "workdir"; 1548 evalAttr = "if"; 1549 1550 if (fThread.pyBoolEval(fWorkdirIf)) 1551 { 1552 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1553 fWorkdir = fThread.pyStringEval(fUnevalWorkdir); 1554 request.append(" WORKDIR "); 1555 request.append(STAFUtil.wrapData(fWorkdir)); 1556 } 1557 else 1558 fWorkdir = ""; 1559 } 1560 1561 evalElem = "var"; 1562 1563 for (int i = 0; i < fUnevalVars.size(); i++) 1564 { 1565 evalIndex = i; 1566 evalAttr = "if"; 1567 String varsIf = fThread.pyStringEval(fVarsIf.elementAt(i)); 1568 1569 if (fThread.pyBoolEval(varsIf)) 1570 { 1571 // Evaluate as a list; each item in list is a single var 1572 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1573 List varList = fThread.pyListEval( 1574 fUnevalVars.elementAt(i)); 1575 for (int j = 0; j < varList.size(); j++) 1576 { 1577 String var = ((Object)varList.get(j)).toString(); 1578 fVars.add(var); 1579 request.append(" VAR "); 1580 request.append(STAFUtil.wrapData(var)); 1581 } 1582 } 1583 } 1584 1585 evalElem = "env"; 1586 1587 for (int i = 0; i < fUnevalEnvs.size(); i++) 1588 { 1589 evalIndex = i; 1590 evalAttr = "if"; 1591 String envsIf = fThread.pyStringEval(fEnvsIf.elementAt(i)); 1592 1593 if (fThread.pyBoolEval(envsIf)) 1594 { 1595 // Evaluate as a list; each item in list is a single var 1596 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1597 List envList = fThread.pyListEval( 1598 fUnevalEnvs.elementAt(i)); 1599 for (int j = 0; j < envList.size(); j++) 1600 { 1601 String env = ((Object)envList.get(j)).toString(); 1602 fEnvs.add(env); 1603 request.append(" ENV "); 1604 request.append(STAFUtil.wrapData(env)); 1605 } 1606 } 1607 } 1608 1609 evalIndex = 0; 1610 1611 if (!fUseprocessvars.equals("")) 1612 { 1613 evalElem = "useprocessvars"; 1614 evalAttr = "if"; 1615 1616 if (fThread.pyBoolEval(fUseprocessvarsIf)) 1617 request.append(" USEPROCESSVARS"); 1618 else 1619 fUseprocessvars = ""; 1620 } 1621 1622 if (!fStopusing.equals("")) 1623 { 1624 evalElem = "stopusing"; 1625 evalAttr = "if"; 1626 1627 if (fThread.pyBoolEval(fStopusingIf)) 1628 { 1629 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1630 fStopusing = fThread.pyStringEval(fUnevalStopusing); 1631 request.append(" STOPUSING "); 1632 request.append(STAFUtil.wrapData(fStopusing)); 1633 } 1634 else 1635 fStopusing = ""; 1636 } 1637 1638 if (!fConsole.equals("")) 1639 { 1640 evalElem = "console"; 1641 evalAttr = "if"; 1642 1643 if (fThread.pyBoolEval(fConsoleIf)) 1644 { 1645 evalAttr = "use"; 1646 fConsole = fThread.pyStringEval(fUnevalConsole); 1647 1648 if (fConsole.equalsIgnoreCase("new")) 1649 request.append(" NEWCONSOLE"); 1650 else if (fConsole.equalsIgnoreCase("same")) 1651 request.append(" SAMECONSOLE"); 1652 else 1653 { 1654 // Raise a StartProcessError signal 1655 fState = COMPLETE; 1656 fThread.popAction(); 1657 1658 setPythonVariablesWhenFail( 1659 "Process failed to start. Raised a " + 1660 "STAXProcessStartError signal."); 1661 1662 setElementInfo(new STAXElementInfo( 1663 evalElem, evalAttr, evalIndex, 1664 "Invalid value: " + fConsole + 1665 "\n\nValid values for attribute \"use\" are: " + 1666 "'new' or 'same'.")); 1667 1668 fThread.setSignalMsgVar( 1669 "STAXProcessStartErrorMsg", 1670 STAXUtil.formatErrorMessage(this)); 1671 1672 fThread.raiseSignal("STAXProcessStartError"); 1673 1674 return 1; 1675 } 1676 } 1677 else 1678 fConsole = ""; 1679 } 1680 1681 if (!fFocus.equals("")) 1682 { 1683 evalElem = "focus"; 1684 evalAttr = "if"; 1685 1686 if (fThread.pyBoolEval(fFocusIf)) 1687 { 1688 evalAttr = "mode"; 1689 fFocus = fThread.pyStringEval(fUnevalFocus); 1690 1691 if (fFocus.equalsIgnoreCase("minimized")) 1692 { 1693 fFocus = "Minimized"; 1694 request.append(" FOCUS Minimized"); 1695 } 1696 else if (fFocus.equalsIgnoreCase("foreground")) 1697 { 1698 fFocus = "Foreground"; 1699 request.append(" FOCUS Foreground"); 1700 } 1701 else if (fFocus.equalsIgnoreCase("background")) 1702 { 1703 fFocus = "Background"; 1704 request.append(" FOCUS Background"); 1705 } 1706 else 1707 { 1708 // Raise a StartProcessError signal 1709 fState = COMPLETE; 1710 fThread.popAction(); 1711 1712 setPythonVariablesWhenFail( 1713 "Process failed to start. Raised a " + 1714 "STAXProcessStartError signal."); 1715 1716 setElementInfo(new STAXElementInfo( 1717 evalElem, evalAttr, evalIndex, 1718 "Invalid valid: " + fFocus + 1719 "\n\nValid values for attribute \"mode\" are: " + 1720 "'minimized', 'foreground', or 'background'.")); 1721 1722 fThread.setSignalMsgVar( 1723 "STAXProcessStartErrorMsg", 1724 STAXUtil.formatErrorMessage(this)); 1725 1726 fThread.raiseSignal("STAXProcessStartError"); 1727 1728 return 1; 1729 } 1730 } 1731 else 1732 fFocus = ""; 1733 } 1734 1735 if (!fUsername.equals("")) 1736 { 1737 evalElem = "username"; 1738 evalAttr = "if"; 1739 1740 if (fThread.pyBoolEval(fUsernameIf)) 1741 { 1742 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1743 fUsername = fThread.pyStringEval(fUnevalUsername); 1744 request.append(" USERNAME "); 1745 request.append(STAFUtil.wrapData(fUsername)); 1746 } 1747 else 1748 fUsername = ""; 1749 } 1750 1751 if (!fPassword.equals("")) 1752 { 1753 evalElem = "password"; 1754 evalAttr = "if"; 1755 1756 if (fThread.pyBoolEval(fPasswordIf)) 1757 { 1758 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1759 fPassword = fThread.pyStringEval(fUnevalPassword); 1760 request.append(" PASSWORD "); 1761 request.append(STAFUtil.wrapData(fPassword)); 1762 } 1763 else 1764 fPassword = ""; 1765 } 1766 1767 if (!fDisabledauth.equals("")) 1768 { 1769 evalElem = "disabledauth"; 1770 evalAttr = "if"; 1771 1772 if (fThread.pyBoolEval(fDisabledauthIf)) 1773 { 1774 evalAttr = "action"; 1775 1776 fDisabledauth = fThread.pyStringEval(fUnevalDisabledauth); 1777 1778 if (fDisabledauth.equalsIgnoreCase("error")) 1779 request.append(" DISABLEDAUTHISERROR"); 1780 else if (fDisabledauth.equalsIgnoreCase("ignore")) 1781 request.append(" IGNOREDISABLEDAUTH"); 1782 else 1783 { 1784 // Raise a StartProcessError signal 1785 fState = COMPLETE; 1786 fThread.popAction(); 1787 1788 setPythonVariablesWhenFail( 1789 "Process failed to start. Raised a " + 1790 "STAXProcessStartError signal."); 1791 1792 setElementInfo(new STAXElementInfo( 1793 evalElem, evalAttr, evalIndex, 1794 "Invalid value: " + fDisabledauth + 1795 "\n\nValid values for attribute \"action\" are: " + 1796 "'error' or 'ignore'.")); 1797 1798 fThread.setSignalMsgVar( 1799 "STAXProcessStartErrorMsg", 1800 STAXUtil.formatErrorMessage(this)); 1801 1802 fThread.raiseSignal("STAXProcessStartError"); 1803 1804 return 1; 1805 } 1806 } 1807 else 1808 fDisabledauth = ""; 1809 } 1810 1811 if (!fStatichandlename.equals("")) 1812 { 1813 evalElem = "statichandlename"; 1814 evalAttr = "if"; 1815 1816 if (fThread.pyBoolEval(fStatichandlenameIf)) 1817 { 1818 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1819 fStatichandlename = fThread.pyStringEval( 1820 fUnevalStatichandlename); 1821 request.append(" STATICHANDLENAME "); 1822 request.append(STAFUtil.wrapData(fStatichandlename)); 1823 } 1824 else 1825 fStatichandlename = ""; 1826 } 1827 1828 if (!fStdin.equals("")) 1829 { 1830 evalElem = "stdin"; 1831 evalAttr = "if"; 1832 1833 if (fThread.pyBoolEval(fStdinIf)) 1834 { 1835 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1836 fStdin = fThread.pyStringEval(fUnevalStdin); 1837 request.append(" STDIN "); 1838 request.append(STAFUtil.wrapData(fStdin)); 1839 } 1840 else 1841 fStdin = ""; 1842 } 1843 1844 if (!fStdout.equals("")) 1845 { 1846 evalElem = "stdout"; 1847 evalAttr = "if"; 1848 1849 if (fThread.pyBoolEval(fStdoutIf)) 1850 { 1851 evalAttr = "mode"; 1852 fStdoutMode = fThread.pyStringEval(fUnevalStdoutMode); 1853 1854 if (fStdoutMode.equalsIgnoreCase("replace")) 1855 { 1856 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1857 fStdout = fThread.pyStringEval(fUnevalStdout); 1858 request.append(" STDOUT "); 1859 request.append(STAFUtil.wrapData(fStdout)); 1860 } 1861 else if (fStdoutMode.equalsIgnoreCase("append")) 1862 { 1863 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1864 fStdout = fThread.pyStringEval(fUnevalStdout); 1865 request.append(" STDOUTAPPEND "); 1866 request.append(STAFUtil.wrapData(fStdout)); 1867 } 1868 else 1869 { 1870 // Raise a StartProcessError signal 1871 fState = COMPLETE; 1872 fThread.popAction(); 1873 1874 setPythonVariablesWhenFail( 1875 "Process failed to start. Raised a " + 1876 "STAXProcessStartError signal."); 1877 1878 setElementInfo(new STAXElementInfo( 1879 evalElem, evalAttr, evalIndex, 1880 "Invalid value: " + fStdoutMode + 1881 "\n\nValid values for attribute \"mode\" are: " + 1882 "'replace' or 'append'.")); 1883 1884 fThread.setSignalMsgVar( 1885 "STAXProcessStartErrorMsg", 1886 STAXUtil.formatErrorMessage(this)); 1887 1888 fThread.raiseSignal("STAXProcessStartError"); 1889 return 1; 1890 1891 } 1892 } 1893 else 1894 { 1895 fStdout = ""; 1896 fStdoutMode = ""; 1897 } 1898 } 1899 1900 if (!fStderr.equals("") || !fUnevalStderrMode.equals("")) 1901 { 1902 evalElem = "stderr"; 1903 evalAttr = "if"; 1904 1905 if (fThread.pyBoolEval(fStderrIf)) 1906 { 1907 evalAttr = "mode"; 1908 fStderrMode = fThread.pyStringEval(fUnevalStderrMode); 1909 1910 if (! fStderrMode.equalsIgnoreCase("stdout")) 1911 { 1912 // Check if EXACT same file name was specified 1913 // for stdout and stderr and if so, set mode=stdout 1914 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 1915 fStderr = fThread.pyStringEval(fUnevalStderr); 1916 if (fStderr.equals(fStdout)) 1917 fStderrMode = "stdout"; 1918 } 1919 1920 evalAttr = "mode"; 1921 1922 if (fStderrMode.equalsIgnoreCase("replace")) 1923 { 1924 request.append(" STDERR "); 1925 request.append(STAFUtil.wrapData(fStderr)); 1926 } 1927 else if (fStderrMode.equalsIgnoreCase("append")) 1928 { 1929 request.append(" STDERRAPPEND "); 1930 request.append(STAFUtil.wrapData(fStderr)); 1931 } 1932 else if (fStderrMode.equalsIgnoreCase("stdout")) 1933 { 1934 fStderr = ""; 1935 request.append(" STDERRTOSTDOUT"); 1936 } 1937 else 1938 { 1939 // Raise a StartProcessError signal 1940 fState = COMPLETE; 1941 fThread.popAction(); 1942 1943 setPythonVariablesWhenFail( 1944 "Process failed to start. Raised a " + 1945 "STAXProcessStartError signal."); 1946 1947 setElementInfo(new STAXElementInfo( 1948 evalElem, evalAttr, evalIndex, 1949 "Invalid value: " + fStderrMode + 1950 "\n\nValid values for attribute \"mode\" are: " + 1951 "'replace', 'append', or 'stdout'.")); 1952 1953 fThread.setSignalMsgVar( 1954 "STAXProcessStartErrorMsg", 1955 STAXUtil.formatErrorMessage(this)); 1956 1957 fThread.raiseSignal("STAXProcessStartError"); 1958 1959 return 1; 1960 } 1961 } 1962 else 1963 { 1964 fStderr = ""; 1965 fStderrMode = ""; 1966 } 1967 } 1968 1969 if (!fReturnStdout.equals("")) 1970 { 1971 evalElem = "returnstdout"; 1972 evalAttr = "if"; 1973 1974 if (fThread.pyBoolEval(fReturnStdoutIf)) 1975 request.append(" RETURNSTDOUT"); 1976 else 1977 fReturnStdout = ""; 1978 } 1979 1980 if (!fReturnStderr.equals("")) 1981 { 1982 evalElem = "returnstderr"; 1983 evalAttr = "if"; 1984 1985 if (fThread.pyBoolEval(fReturnStderrIf)) 1986 request.append(" RETURNSTDERR"); 1987 else 1988 fReturnStderr = ""; 1989 } 1990 1991 evalElem = "returnfile"; 1992 1993 for (int i = 0; i < fUnevalReturnFiles.size(); i++) 1994 { 1995 evalIndex = i; 1996 evalAttr = "if"; 1997 String returnFilesIf = fThread.pyStringEval( 1998 fReturnFilesIf.elementAt(i)); 1999 2000 if (fThread.pyBoolEval(returnFilesIf)) 2001 { 2002 // Evaluate as a list; each list item is a single file 2003 2004 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 2005 List fileList = fThread.pyListEval( 2006 fUnevalReturnFiles.elementAt(i)); 2007 2008 for (int j = 0; j < fileList.size(); j++) 2009 { 2010 String file = ((Object)fileList.get(j)).toString(); 2011 fReturnFiles.add(file); 2012 request.append(" RETURNFILE "); 2013 request.append(STAFUtil.wrapData(file)); 2014 } 2015 } 2016 } 2017 2018 evalIndex = 0; 2019 2020 if (fProcessAction != null) 2021 { 2022 evalElem = "process-action"; 2023 evalAttr = "if"; 2024 fProcessActionFlag = fThread.pyBoolEval(fProcessActionIf); 2025 } 2026 2027 if (!fOther.equals("")) 2028 { 2029 evalElem = "other"; 2030 evalAttr = "if"; 2031 2032 if (fThread.pyBoolEval(fOtherIf)) 2033 { 2034 evalAttr = STAXElementInfo.NO_ATTRIBUTE_NAME; 2035 fOther = fThread.pyStringEval(fUnevalOther); 2036 request.append(" "); 2037 request.append(fOther); 2038 } 2039 else 2040 fOther = ""; 2041 } 2042 } 2043 catch (STAXPythonEvaluationException e) 2044 { 2045 fState = COMPLETE; 2046 fThread.popAction(); 2047 2048 setPythonVariablesWhenFail( 2049 "Process failed to start. Raised a " + 2050 "STAXPythonEvaluationError signal."); 2051 2052 setElementInfo(new STAXElementInfo( 2053 evalElem, evalAttr, evalIndex)); 2054 2055 fThread.setSignalMsgVar( 2056 "STAXPythonEvalMsg", STAXUtil.formatErrorMessage(this), e); 2057 2058 fThread.raiseSignal("STAXPythonEvaluationError"); 2059 2060 return 1; 2061 } 2062 2063 fRequest = request.toString(); 2064 2065 return 0; 2066 } 2067 2068 generateProcessStartEvent()2069 private void generateProcessStartEvent() 2070 { 2071 // Generate a start process event 2072 2073 HashMap<String, String> processMap = new HashMap<String, String>(); 2074 processMap.put("type", "process"); 2075 processMap.put("block", fCurrentBlockName); 2076 processMap.put("status", "start"); 2077 processMap.put("location", fLocation); 2078 processMap.put("command", STAFUtil.maskPrivateData(fCommand)); 2079 processMap.put("handle", String.valueOf(fProcessHandle)); 2080 processMap.put("parms", STAFUtil.maskPrivateData(fParms)); 2081 processMap.put("name", fName); 2082 processMap.put("mode", fCommandMode); 2083 processMap.put("workload", fWorkload); 2084 processMap.put("title", fTitle); 2085 processMap.put("workdir", fWorkdir); 2086 2087 if (!fCommandShell.equals("")) 2088 { 2089 processMap.put("shell", fCommandShell); 2090 } 2091 2092 // Convert the fVars vector to a list 2093 2094 List<String> varList = new ArrayList<String>(); 2095 2096 for (int i = 0; i < fVars.size(); i++) 2097 { 2098 varList.add(fVars.elementAt(i)); 2099 } 2100 2101 processMap.put("varList", STAFMarshallingContext.marshall( 2102 varList, new STAFMarshallingContext())); 2103 2104 // Convert the fEnvs vector to a list 2105 2106 List<String> envList = new ArrayList<String>(); 2107 2108 for (int i = 0; i < fEnvs.size(); i++) 2109 { 2110 envList.add(fEnvs.elementAt(i)); 2111 } 2112 2113 processMap.put("envList", STAFMarshallingContext.marshall( 2114 envList, new STAFMarshallingContext())); 2115 2116 if (!fUseprocessvars.equals("")) 2117 { 2118 processMap.put("useprocessvars", ""); 2119 } 2120 2121 processMap.put("stopusing", fStopusing); 2122 2123 if (fConsole.equalsIgnoreCase("new")) 2124 { 2125 processMap.put("newconsole", ""); 2126 } 2127 else if (fConsole.equalsIgnoreCase("same")) 2128 { 2129 processMap.put("sameconsole", ""); 2130 } 2131 2132 if (!fFocus.equals("")) 2133 { 2134 processMap.put("focus", fFocus); 2135 } 2136 2137 processMap.put("username", fUsername); 2138 2139 if (!fPassword.equals("")) 2140 { 2141 processMap.put("password", "*******"); 2142 } 2143 2144 if (fDisabledauth.equalsIgnoreCase("error")) 2145 { 2146 processMap.put("disabledauthiserror", ""); 2147 } 2148 else if (fDisabledauth.equalsIgnoreCase("ignore")) 2149 { 2150 processMap.put("ignoredisabledauth", ""); 2151 } 2152 2153 processMap.put("stdin", fStdin); 2154 2155 if (fStdoutMode.equalsIgnoreCase("replace")) 2156 { 2157 processMap.put("stdout", fStdout); 2158 } 2159 else if (fStdoutMode.equalsIgnoreCase("append")) 2160 { 2161 processMap.put("stdoutappend", fStdout); 2162 } 2163 2164 if (fStderrMode.equalsIgnoreCase("replace")) 2165 { 2166 processMap.put("stderr", fStderr); 2167 } 2168 else if (fStderrMode.equalsIgnoreCase("append")) 2169 { 2170 processMap.put("stderrappend", fStderr); 2171 } 2172 else if (fStderrMode.equalsIgnoreCase("stdout")) 2173 { 2174 processMap.put("stderrtostdout", ""); 2175 } 2176 2177 if (!fReturnStdout.equals("")) 2178 { 2179 processMap.put("returnstdout", ""); 2180 } 2181 2182 if (!fReturnStderr.equals("")) 2183 { 2184 processMap.put("returnstderr", ""); 2185 } 2186 2187 // Convert the fReturnFiles vector to a string containing a marshalled 2188 // list of strings 2189 2190 List<String> returnFileList = new ArrayList<String>(); 2191 2192 for (int i = 0; i < fReturnFiles.size(); i++) 2193 { 2194 returnFileList.add(fReturnFiles.elementAt(i)); 2195 } 2196 2197 processMap.put("returnFileList", STAFMarshallingContext.marshall( 2198 returnFileList, new STAFMarshallingContext())); 2199 2200 processMap.put("statichandlename", fStatichandlename); 2201 2202 processMap.put("other", fOther); 2203 2204 fThread.getJob().generateEvent( 2205 STAXProcessActionFactory.STAX_PROCESS_EVENT, processMap); 2206 } 2207 2208 generateProcessStopEvent()2209 private void generateProcessStopEvent() 2210 { 2211 // Generate a stop process event 2212 2213 HashMap<String, String> processMap = new HashMap<String, String>(); 2214 processMap.put("type", "process"); 2215 processMap.put("block", fCurrentBlockName); 2216 processMap.put("status", "stop"); 2217 processMap.put("location", fLocation); 2218 processMap.put("command", STAFUtil.maskPrivateData(fCommand)); 2219 processMap.put("handle", String.valueOf(fProcessHandle)); 2220 processMap.put("parms", STAFUtil.maskPrivateData(fParms)); 2221 processMap.put("name", fName); 2222 2223 fThread.getJob().generateEvent( 2224 STAXProcessActionFactory.STAX_PROCESS_EVENT, processMap); 2225 } 2226 2227 replace(String source, String find, String replace)2228 private String replace(String source, String find, String replace) 2229 { 2230 StringBuffer result = new StringBuffer(source); 2231 int position = source.indexOf(find); 2232 2233 while (position > -1) 2234 { 2235 result.replace(position, position + find.length(), replace); 2236 position = result.toString().indexOf(find, position + 2237 replace.length()); 2238 } 2239 2240 return result.toString(); 2241 } 2242 2243 STAXThread fThread = null; 2244 int fState = INIT; 2245 boolean fIsProcessRunning = false; 2246 boolean fIsProcessActionRunning = false; 2247 2248 private String fLocation = new String(); 2249 private String fCommand = new String(); 2250 private String fName = new String(); 2251 private String fWorkload = new String(""); 2252 private String fWorkloadIf = new String(""); 2253 private String fTitle = new String(""); 2254 private String fTitleIf = new String(""); 2255 private String fParms = new String(""); 2256 private String fParmsIf = new String(""); 2257 private String fWorkdir = new String(""); 2258 private String fWorkdirIf = new String(""); 2259 private Vector<String> fVars = new Vector<String>(); 2260 private Vector<String> fVarsIf = new Vector<String>(); 2261 private Vector<String> fEnvs = new Vector<String>(); 2262 private Vector<String> fEnvsIf = new Vector<String>(); 2263 private String fUseprocessvars = new String(""); 2264 private String fUseprocessvarsIf = new String(""); 2265 private String fStopusing = new String(""); 2266 private String fStopusingIf = new String(""); 2267 private String fConsole = new String(""); 2268 private String fConsoleIf = new String(""); 2269 private String fFocus = new String(""); 2270 private String fFocusIf = new String(""); 2271 private String fUsername = new String(""); 2272 private String fUsernameIf = new String(""); 2273 private String fPassword = new String(""); 2274 private String fPasswordIf = new String(""); 2275 private String fDisabledauth = new String(""); 2276 private String fDisabledauthIf = new String(""); 2277 private String fStatichandlename = new String(""); 2278 private String fStatichandlenameIf = new String(""); 2279 private String fStdin = new String(""); 2280 private String fStdinIf = new String(""); 2281 private String fStdout = new String(""); 2282 private String fStdoutIf = new String(""); 2283 private String fStdoutMode = new String(""); 2284 private String fStderr = new String(""); 2285 private String fStderrIf = new String(""); 2286 private String fStderrMode = new String(""); 2287 private String fReturnStdout = new String(""); 2288 private String fReturnStdoutIf = new String(""); 2289 private String fReturnStderr = new String(""); 2290 private String fReturnStderrIf = new String(""); 2291 private Vector<String> fReturnFiles = new Vector<String>(); 2292 private Vector<String> fReturnFilesIf = new Vector<String>(); 2293 private String fOther = new String(""); 2294 private String fOtherIf = new String(""); 2295 private String fCommandMode = new String(""); 2296 private String fCommandShell = new String(""); 2297 private STAXAction fProcessAction = null; 2298 private String fProcessActionIf = new String(""); 2299 2300 private String fUnevalLocation = new String(); 2301 private String fUnevalCommand = new String(); 2302 private String fUnevalName = new String(); 2303 private String fUnevalWorkload = new String(""); 2304 private String fUnevalTitle = new String(""); 2305 private String fUnevalParms = new String(""); 2306 private String fUnevalWorkdir = new String(""); 2307 private Vector<String> fUnevalVars = new Vector<String>(); 2308 private Vector<String> fUnevalEnvs = new Vector<String>(); 2309 private String fUnevalUseprocessvars = new String(""); 2310 private String fUnevalStopusing = new String(""); 2311 private String fUnevalConsole = new String(""); 2312 private String fUnevalFocus = new String(""); 2313 private String fUnevalUsername = new String(""); 2314 private String fUnevalPassword = new String(""); 2315 private String fUnevalDisabledauth = new String(""); 2316 private String fUnevalStatichandlename = new String(""); 2317 private String fUnevalStdin = new String(""); 2318 private String fUnevalStdout = new String(""); 2319 private String fUnevalStdoutMode = new String(""); 2320 private String fUnevalStderr = new String(""); 2321 private String fUnevalStderrMode = new String(""); 2322 private String fUnevalReturnStdout = new String(""); 2323 private String fUnevalReturnStderr = new String(""); 2324 private Vector<String> fUnevalReturnFiles = new Vector<String>(); 2325 private String fUnevalOther = new String(""); 2326 private String fUnevalProcessActionIf = new String(""); 2327 private String fUnevalCommandMode = new String(""); 2328 private String fUnevalCommandShell = new String(""); 2329 2330 private STAXHoldThreadCondition fHoldCondition = 2331 new STAXHoldThreadCondition("Process"); 2332 private STAXHardHoldThreadCondition fHardHoldCondition = 2333 new STAXHardHoldThreadCondition("Process"); 2334 private int fRequestNumber = 0; 2335 private int fRequestRC = 0; 2336 private String fRequest = new String(); 2337 private String fRequestResult = new String(); 2338 private int fProcessHandle = 0; 2339 private long fProcessRC = -1; 2340 private PyObject fProcessSTAFResult = Py.None; 2341 private PyObject fProcessSTAXResult = Py.None; 2342 private String fProcessTimestamp = new String(); 2343 private STAXTimestamp fStartTimestamp; 2344 private STAXProcessActionFactory fFactory; 2345 private String fCurrentBlockName = new String(); 2346 private HashMap<Integer, STAXThread> fThreadMap = 2347 new HashMap<Integer, STAXThread>(); 2348 private boolean fProcessActionFlag = true; 2349 private STAXTimedEvent fTimedEvent = null; 2350 private String fProcessKey = ""; 2351 private boolean fUsingProcessKeyOption = true; 2352 }