##################################################################### # printenv.py (Jython) control script # # Constructs shell command which executes the shell script # controlling the application and passes it to the ProcessManager's # exec method, which monitors and reports on the process streams # as well as the exit value of the process when it returns. # # Both logs the output and publishes to an event channel. # Assumes that a PGEC (persistent generic event channel) has already # been registered. # # Example code by Albert L. Rossi, IU Extreme! Computing # December 2001 ##################################################################### import sys from java.lang import * from jarray import zeros from soaprmi.events import * from soaprmi.events.util import Util from xcat.framework.util import ProcessManager ## initialize mappings try: EventMappings.init() except Exception, e: System.err.println("printenv.py, EventMappings.init: " + e) ## retrieve the event channel evtchname = "myPEGC" evtchctx = "ldap://palomar.extreme.indiana.edu/" evtchctx = evtchctx + "ou=events,o=soaprmi,dc=cs,dc=indiana,dc=edu" try: channel = Util.getPEGCRef(evtchname, evtchctx) except Exception, e: channel = None ## method for publishing events to the channel ###################### def publish (msg): if channel == None: return event = Event(msg) event.setEventType("demo") event.setSource("printenv.py") try: channel.handleEvent(event) except Exception, e: System.err.println ("printenv.py, channel.handleEvent: " + e) ##################################################################### ## construct the shell command arguments ## shell script assumed to be in current directory command = zeros(3, String) command[0] = String("/bin/sh") command[1] = String("-c") command[2] = String("./printenv.csh") ## construct ProcessManager ## (a) with event channel publication pm = ProcessManager("printenv_py","demo",channel,0) ## (b) without event channel publication # pm = ProcessManager("printenv_py","demo") ## execute and monitor pm.exec(command) ## make the application manager exit System.exit(0)