def execute(self,script=None,scriptFile=None): """This runs a uEngine script. Supply the script with the script=<script text> argument or use scriptFile=<filename> to read the script text from a file. Returns xml string. The status of the uEngine script must be checked with class attribute status. 0 for success. Any other value there were problems. """ # The script to run is either passed in or can be read from a file xml="" if script == None and scriptFile != None: script = self.readscript(scriptFile) if script != None: # submit the input to the server and obtain result ch = CH.CommHandler(self._connection, self._service) ch.process(script) # expect message 200, if not print error message and return error code if not ch.isGoodStatus(): print "######### ERROR reportHTTPResponse" util.reportHTTPResponse(ch.formatResponse()) self.status = 1 else: # Pull the responses element out of the xml xml=ch.getContents() self.status = 0 return xml
def __processRequest(self): msg = self.__createMessage() service = config.endpoint.get('subscribe') connection=str(os.getenv("DEFAULT_HOST", "localhost") + ":" + os.getenv("DEFAULT_PORT", "9581")) ch = CH.CommHandler(connection, service) ch.process(msg) if not ch.isGoodStatus(): util.reportHTTPResponse(ch.formatResponse()) retVal = self.__processResponse(ch.getContents()) return retVal
def __submitRequestMessage(self,msg): try: runner = self.commands.get('runner') service = config.endpoint.get(runner) # send the request to the server connection=str(os.getenv("DEFAULT_HOST", "localhost") + ":" + os.getenv("DEFAULT_PORT", "9581")) ch = CH.CommHandler(connection,service) ch.process(msg) if not ch.isGoodStatus(): util.reportHTTPResponse(ch.formatResponse()) return None return ch.getContents() except Exception,e: raise CH.CommError("Unable to submit request to server",e)
def __runScript(self): io = IO.InputOutput() # pass the script to EDEX runner = self.commands.get('runner') service = config.endpoint.get(runner) # submit the input to the server and obtain result connection = str( os.getenv("DEFAULT_HOST", "localhost") + ":" + os.getenv("DEFAULT_PORT", "9581")) ch = CH.CommHandler(connection, service) ch.process(self.script) # expect message 200, if not print error message and return error code if not ch.isGoodStatus(): util.reportHTTPResponse(ch.formatResponse()) return 1 if 'fullMessage' in self.commands: # Return the full XML message to the appropriate stream io.setStream(sys.stdout) io.writeln(data=ch.getContents()) retVal = 0 else: # Pull the responses element out of the xml msg = MSG.Message() msg.parse(ch.getContents()) # process the response and send results to the appropriate stream error, hdr, resp = self.__getResponse(msg) if error: io.setStream(sys.stderr) retVal = 1 else: io.setStream(sys.stdout) retVal = 0 io.writeln(data=hdr) io.writeln(data=resp) return retVal