def run_pfioh_push(self): post_request = { "action": "pushPath", "meta": { "remote": { "key": self.JID }, "local": { "path": "/tmp/" + self.DIR }, "transport": { "mechanism": "compress", "compress": { "archive": "zip", "unpack": True, "cleanup": True } } } } dataComs = pfurl.Pfurl( msg = json.dumps(post_request), verb = 'POST', http = '%s/%s' % (str(self.PFIOH_URL), "api/v1/cmd"), b_quiet = False, b_raw = True, b_httpResponseBodyParse = True, jsonwrapper = '', authToken = self.password ) print(dataComs()) return (json.loads(dataComs()))
def pman_run(self): post_request = { "action": "run", "meta": { "cmd": "simpledsapp.py --prefix test- --sleepLength 0 /share/incoming /share/outgoing", "auid": "mochealthcheck", "jid": '"' + self.JID + '"', "threaded": True, "container": { "target": { "image" : "fnndsc/pl-simpledsapp" } } } } dataComs = pfurl.Pfurl( msg = json.dumps(post_request), verb = 'POST', http = '%s/%s' % (self.PMAN_URL, "api/v1/cmd"), b_quiet = False, b_raw = True, b_httpResponseBodyParse = True, jsonwrapper = '', authToken = self.password ) print(dataComs()) return (json.loads(dataComs()))
def call_app_service(self, d_msg): """ This method sends the JSON 'msg' argument to the remote service. """ remote_url = self.c_plugin_inst.compute_resource.compute_url serviceCall = pfurl.Pfurl( msg=json.dumps(d_msg), http=remote_url, verb='POST', # contentType = 'application/json', b_raw=True, b_quiet=True, b_httpResponseBodyParse=True, jsonwrapper='payload', ) logger.info('comms sent to pfcon service at -->%s<--', remote_url) logger.info('message sent: %s', json.dumps(d_msg, indent=4)) # speak to the service... d_response = json.loads(serviceCall()) if isinstance(d_response, dict): logger.info( 'looks like we got a successful response from pfcon service') logger.info('response from pfurl(): %s', json.dumps(d_response, indent=4)) else: logger.info( 'looks like we got an UNSUCCESSFUL response from pfcon service' ) logger.info('response from pfurl(): -->%s<--', d_response) if "Connection refused" in d_response: logging.error('fatal error in talking to pfcon service') return d_response
def call_app_service(self, d_msg): """ This method sends the JSON 'msg' argument to the remote service. """ remote_url = self.c_plugin_inst.compute_resource.compute_url serviceCall = pfurl.Pfurl( msg=json.dumps(d_msg), http=remote_url, verb='POST', # contentType = 'application/json', b_raw=True, b_quiet=True, b_httpResponseBodyParse=True, jsonwrapper='payload', ) logger.info('comms sent to pfcon service at -->%s<--', remote_url) logger.info('message sent: %s', json.dumps(d_msg, indent=4)) # Leave here for now... might be useful for later debugging. # with open('/tmp/%d-%s-%s.json' % \ # (time.time_ns() // 1000000, # d_msg['action'], # self.str_job_id), 'w') as l: # json.dump(d_msg, l, indent = 4) # logger.debug('comms sent to pfcon service at -->%s<--', remote_url) # logger.debug('message sent: %s', json.dumps(d_msg, indent=4)) # try: # rpudb.set_trace(addr='0.0.0.0', port=7901) # except: # pudb.set_trace() d_response = json.loads(serviceCall()) if isinstance(d_response, dict): logger.info( 'looks like we got a successful response from pfcon service') logger.info('response from pfurl(): %s', json.dumps(d_response, indent=4)) else: logger.info( 'looks like we got an UNSUCCESSFUL response from pfcon service' ) logger.info('response from pfurl(): -->%s<--', d_response) if "Connection refused" in d_response: logging.error('fatal error in talking to pfcon service') return d_response
def app_service_call(self, *args, **kwargs): """ This method sends the JSON 'msg' argument to the remote service. :param args: :param kwargs: :return: True | False """ d_msg = {} str_service = 'pfcon' b_httpResponseBodyParse = True for k, v in kwargs.items(): if k == 'msg': d_msg = v if k == 'service': str_service = v # pudb.set_trace() str_setting = 'settings.%s' % str_service.upper() str_http = '%s:%s' % (eval(str_setting)['host'], eval(str_setting)['port']) if str_service == 'pman': b_httpResponseBodyParse = False str_debugFile = '%s/tmp/debug-pfurl.log' % os.environ['HOME'] if self.str_debugFile == '/dev/null': str_debugFile = self.str_debugFile serviceCall = pfurl.Pfurl( msg=json.dumps(d_msg), http=str_http, verb='POST', # contentType = 'application/json', b_raw=True, b_quiet=self.b_quiet, b_httpResponseBodyParse=b_httpResponseBodyParse, jsonwrapper='payload', debugFile=str_debugFile, useDebug=self.b_useDebug) # speak to the service... d_response = json.loads(serviceCall()) if not b_httpResponseBodyParse: d_response = parse_qs(d_response) return d_response
def app_service_call(self, d_msg): """ This method sends the JSON 'msg' argument to the remote service. """ # pudb.set_trace() serviceCall = pfurl.Pfurl( msg=json.dumps(d_msg), http=self.str_http, verb='POST', # contentType = 'application/json', b_raw=True, b_quiet=True, b_httpResponseBodyParse=True, jsonwrapper='payload', ) # speak to the service... d_response = json.loads(serviceCall()) return d_response
def job_delete(self): post_request = { "action": "delete", "meta": { "key": "jid", "value": '"' + self.JID + '"' } } dataComs = pfurl.Pfurl( msg = json.dumps(post_request), verb = 'POST', http = '%s/%s' % (self.PMAN_URL, "api/v1/cmd"), b_quiet = False, b_raw = True, b_httpResponseBodyParse = True, jsonwrapper = '', authToken = self.password ) return (json.loads(dataComs()))
def service_call(self, *args, **kwargs): d_msg = {} for k, v in kwargs.items(): if k == 'msg': d_msg = v serviceCall = pfurl.Pfurl( msg = json.dumps(d_msg), http = self.str_pfdcm, verb = 'POST', b_raw = True, b_quiet = self.b_pfurlQuiet, b_httpResponseBodyParse = True, jsonwrapper = 'payload', debugFile = self.str_debugFile, useDebug = self.b_useDebug ) self.dp.qprint('Sending d_msg =\n %s' % self.df_print(d_msg)) d_response = json.loads(serviceCall()) return d_response