def __init__(self, port, timeout=60000): self.conn = make_client(timeline.TemporalEngineService, '127.0.0.1', port, timeout=timeout) self.configConn = make_client(timeline.LifecycleConfigurationService, '127.0.0.1', port, timeout=timeout) self.getServerRequestID()
def main(): print("Fetching status of local gdcv server...") gdcv_thrift = thriftpy.load('gdcv/if/gdcv.thrift', module_name='gdcv_thrift') client = make_client(gdcv_thrift.FrcRealtimeScoringService, '127.0.0.1', 6000) print("{} v{} is {}, since {}".format(client.getName(), client.getVersion(), client.getStatus(), client.aliveSince())) metadataKey = "testKey" print("Testing metadata server... {}={}".format( metadataKey, client.getMetadataValue(metadataKey))) print("Testing Pub/Sub...") testMessage = "Hello World!" result = client.sendPubSubMessage(testMessage) print("Result from pubsub send: {}".format(result)) result = client.getPubSubMessage() print("Got message {} through local Pub/Sub".format(result)) print("Testing db...") testMessage = "Hello World!" client.clearAllTestMessages() result = client.insertTestRow(testMessage) print("All rows: {}".format(client.getAllTestMessages())) print("Testing frc-livescore...") print("Test image: {}".format(client.processTestImage()))
def cn_job(cn_id, cluster_spec, times): signal.signal(signal.SIGINT, soft_exit) ping_thrift = thriftpy.load("ping.thrift", module_name="ping_thrift") conn = make_client(ping_thrift.PingService, '127.0.0.1', 6000) for i in range(times): compute_pi(100000) conn.ping(cn_id)
def function_wrapper(*args, **kwargs): function_name = func.__name__ service_class_ins = func.im_self service_name = service_class_ins.__class__.__name__ thrift_module = service_class_ins.thrift_module thrift_service_ins = getattr(thrift_module, service_name) function_args_dict = getattr(thrift_service_ins, function_name + '_args') user_params_dict = get_params(func, *args, **kwargs) thrift_kwargs = assemble_kwargs(function_args_dict, user_params_dict) client = make_client(thrift_service_ins, host=service_class_ins.host, port=int(service_class_ins.port)) try: response = getattr(client, function_name)(**thrift_kwargs) finally: client.close() print( LOG_FORMAT.format(thrift_module_name=thrift_module.__name__, service_name=service_name, function_name=function_name, thrift_kwargs=thrift_kwargs, response=response)) return response
def get_nimbus_client(env_config=None, host=None, port=None, timeout=7000): """Get a Thrift RPC client for Nimbus given project's config file. :param env_config: The project's parsed config. :type env_config: `dict` :param host: The host to use for Nimbus. If specified, `env_config` will not be consulted. :type host: `str` :param port: The port to use for Nimbus. If specified, `env_config` will not be consulted. :type port: `int` :param timeout: The time to wait (in milliseconds) for a response from Nimbus. :param timeout: `int` :returns: a ThriftPy RPC client to use to communicate with Nimbus """ if host is None: host, port = get_nimbus_host_port(env_config) nimbus_client = make_client( Nimbus, host=host, port=port, proto_factory=TBinaryProtocolFactory(), trans_factory=TFramedTransportFactory(), timeout=timeout, ) return nimbus_client
def heart_push(args): while True: try: send_msg = {'rate': '', 'serviceType': 'T', 'serviceid': cid} if not (r.exists("xid_count")): xid_count = '0' send_msg['rate'] = xid_count else: xid_count = r.get('xid_count') send_msg['rate'] = xid_count.decode('utf-8') # send_msg['rate'] = bytes.decode(xid_count) print(xid_count) in_json = json.dumps(send_msg) gui_service = get_gui_agent_services() if gui_service['address'] == '' or gui_service['port'] == '': # if True:#gui_service['address'] == '' or gui_service['port'] == '': gui_service['address'] = '127.0.0.1' gui_service['port'] = '9090' client = make_client(gui_client.ToWeb, gui_service['address'], int(gui_service['port'])) ret = client.pushData(str(in_json)) print(ret) service_register() except Exception as e: print('---heart push error --', e) # except : # print("it's still wrong") finally: time.sleep(5)
def main(): client = make_client(sleep_thrift.Sleep, '127.0.0.1', 6000) # sleep multiple times, but the client won't wait any more client.sleep(1) client.sleep(2) client.sleep(3) client.sleep(4)
def capture(all_servers, server_id='all'): """ Sends the capture commands to the server given in `server_id` from the list of given servers (`all_servers`), else sends the capture command to all of the servers in `all_servers`. :param all_servers: a list of dictionaries of servers, with each being {id: id, ip: ip} :param server_id: the server_id to send to, or `all` for all servers :return: None """ if server_id != 'all': servers = [find_server_by(all_servers, id_=server_id)] if not servers: logging.warn("Couldn't find server with id: {}".format(server_id)) return else: # Capturing from all servers = map(lambda x: (x['id'], make_client(pepi_thrift.CameraServer, x['ip'], 6000)), all_servers) for _, server in servers: server.start_capture(str(app.capture_no)) for id_, server in servers: app.server_data[id_].append(str(app.capture_no)) server.close() app.capture_no += 1
def client(self): client = make_client( accessstats_thrift.AccessStats, self._address, self._port ) return client
def client(self): client = make_client( publicationstats_thrift.PublicationStats, self._address, self._port ) return client
def client(self): client = make_client( citedby_thrift.Citedby, self._address, self._port ) return client
def client(self): client = make_client( articlemeta_thrift.ArticleMeta, self._address, self._port ) return client
def client(self): client = make_client( ratchet_thrift.RatchetStats, self._address, self._port ) return client
def __init__(self, api_key, host, port): self.api_key = api_key trade_thrift = thriftpy.load("traderpc.thrift", module_name="trade_thrift") self.client = make_client(trade_thrift.TradeRpcService, host, port, timeout=5000)
def client(self): client = make_client( publication_stats_thrift.PublicationStats, self._address, self._port ) return client
def test(thrift_server, thriftpy_test_module, request_xtruct): client = make_client(thriftpy_test_module.ThriftTest, host='127.0.0.1', port=6000, proto_factory=TBinaryProtocolFactory(), trans_factory=TFramedTransportFactory()) response = client.testStruct(request_xtruct) assert response == utils.build_xtruct(thriftpy_test_module, "string_thingy2", 1, 17, 33, 65)
def client(self): client = make_client( self.CITEDBY_THRIFT.Citedby, self._address, self._port ) return client
def init_sender(ip, port): if not os.path.exists("weightsync.thrift"): f = _get_thrift_file() weightsync_thrift = thriftpy.load(f.name, module_name="weightsync_thrift") f.close() else: weightsync_thrift = thriftpy.load("weightsync.thrift", module_name="weightsync_thrift") sender = make_client(weightsync_thrift.WeightForward, ip, port) return sender
def init_conn(ip, port): if not os.path.exists("weightsync.thrift"): f = _get_thrift_file() weightsync_thrift = thriftpy.load(f.name, module_name="weightsync_thrift") f.close() else: weightsync_thrift = thriftpy.load("weightsync.thrift", module_name="weightsync_thrift") client = make_client(weightsync_thrift.WeightSync, ip, port) return client
def connect(self, ip_addr, port, thrift_file_path): self.ui_thrift = thriftpy.load(thrift_file_path) self.THRIFT_SMS_FMAN_DATA = self.ui_thrift.THRIFT_SMS_FMAN_DATA self.THRIFT_MAP_IMAGE = self.ui_thrift.THRIFT_MAP_IMAGE self.THRIFT_SENSOR_DATA = self.ui_thrift.THRIFT_SENSOR_DATA self.THRIFT_IPLIMAGE = self.ui_thrift.THRIFT_IPLIMAGE self.THRIFT_QIMAGE = self.ui_thrift.THRIFT_QIMAGE self.client = make_client(self.ui_thrift.Control, ip_addr, port)
def put(self, *args, **kwargs): self.project = make_client( thriftpy.load(pjoin(protocols, "project.thrift"), module_name="project_thrift").ProjectHandle, port=6000) # program = kwargs.get("program") body = json.loads(self.request.body) self.write(self.project.update_project(json.dumps(body))) self.project.close()
def re_init(): try: global client client = make_client(broker_thrift.TradeService, config.BROKER_HOST, config.BROKER_PORT, proto_factory=TBinaryProtocolFactory(), trans_factory=TFramedTransportFactory(), timeout=60000) except Exception as e: logging.warn("make_client exception") traceback.print_exc()
def init_broker(): try: global client client = make_client(broker_thrift.TradeService, config.BROKER_HOST, config.BROKER_PORT, proto_factory=TBinaryProtocolFactory(), trans_factory=TFramedTransportFactory(), timeout=60000) except Exception as e: logging.warn("make_client exception") traceback.print_exc()
def blocking_call(): client = make_client( service=addressbook.AddressBookService, host=self.host, port=self.port, trans_factory=TFramedTransportFactory(), proto_factory=TBinaryProtocolFactory(), ) with closing_client(client): return getattr(client, method)(*args, **kwargs)
def main(): host = '127.0.0.1' if len(sys.argv) < 2 else sys.argv[1] port = 9090 if len(sys.argv) < 3 else int(sys.argv[2]) uniqueid_thrift = thriftpy.load('../protocol/uniqueid.thrift', module_name='uniqueid_thrift') client = make_client(uniqueid_thrift.Uniqueid, host, port) request = uniqueid_thrift.UniqueidRequest() request.logid = random.randint(-2147483648, 2147483647) request.serial = random.randint(0, 9) request.length = random.randint(1, 10) response = client.uniqueid(request) print(response)
def post(self, *args, **kwargs): self.project = make_client( thriftpy.load(pjoin(protocols, "project.thrift"), module_name="project_thrift").ProjectHandle, port=6000) self.write( self.project.do_actions( json.dumps( dict(programs=self.get_argument("programs", []), actions=self.get_argument("actions", []))))) self.project.close()
def __init__(self, ip="10.15.208.61", port=6800): self.ip = ip self.port = port try: self.client = make_client(CNN_i2i_thrift.CNNPredictService, ip, port,trans_factory=TFramedTransportFactory(), timeout=12000) ## timeout ms except Exception as err: print err traceback.print_exc() return
def ensure_auth(self): if not self.inited: if not self.username or self.username == "": raise RuntimeError("not inited") self.client = make_client(thrift.JqDataService, self.host, self.port) self.inited = True response = self.client.auth(self.username, self.password) if not response.status: raise self.get_error(response) else: print("auth success")
def checker(runner_ip, script_path, host, port): try: checker_runner = make_client(checker_thrift.xoj, runner_ip, RPC_PORT) ret = checker_runner.checker(script_path, host, port) return json.loads(ret) except TException as e: logger.error("Thrift Exception | checker error runner[%s] host[%s] port[%d] msg[%s]", runner_ip, host, port, str(e)) return {'status': 'up', 'msg': 'thrift TTransportException'} except Exception as e: logger.error("checker error runner[%s] host[%s] port[%d] msg[%s]", runner_ip, host, port, str(e)) return {'status': 'up', 'msg': 'run script error'}
def delete(self, *args, **kwargs): self.project = make_client( thriftpy.load(pjoin(protocols, "project.thrift"), module_name="project_thrift").ProjectHandle, port=6000) if __debug__: print self.request.body body = json.loads(self.request.body) self.write( self.project.remove_projects(json.dumps(body.get("programs", [])))) self.project.close()
def write_multiple(self, spans): entries = [self.__span_to_entry(span) for span in spans] # TODO(will): The old implementation used to open and close transport here, with the new # client based API this seems like the only way to get parity. Not sure if we would rather # try persistent connections + reconnecting in the long run. client = make_client(scribe_thrift.scribe, host=self.host, port=self.port, timeout=self.timeout, proto_factory=self.protocol_factory, trans_factory=self.transport_factory) client.Log(entries) client.close()
def post(self, *args, **kwargs): self.project = make_client( thriftpy.load(pjoin(protocols, "project.thrift"), module_name="project_thrift").ProjectHandle, port=6000) if __debug__: print self.request.body body = json.loads(self.request.body) if not isinstance(body, list): return self.write(json.dumps(dict(status="fail", msg=u"参数不正确"))) self.write(self.project.add_projects(self.request.body)) self.project.close()
def __init__(self): # We need to run a FrontendService server, even though it does nothing in # practice fes = make_server(sparrow_service_thrift.FrontendService, FLAGS.sparrow_frontend_host, FLAGS.sparrow_frontend_port, trans_factory=tf) self.scheduler_client = make_client(sparrow_service_thrift.SchedulerService, FLAGS.sparrow_scheduler_host, FLAGS.sparrow_scheduler_port, trans_factory=tf) self.scheduler_client.registerFrontend("clusterMixApp", FLAGS.sparrow_frontend_host + ":" + str(FLAGS.sparrow_frontend_port))
def ensure_auth(self): if not self.inited: if not self.username: raise RuntimeError("not inited") self.client = make_client(thrift.JqDataService, self.host, self.port) self.inited = True response = self.client.auth(self.username, self.password, self.compress) if not response.status: self._threading_local._instance = None raise self.get_error(response) else: if self.not_auth: print("auth success %s" % response.msg) self.not_auth = False
def handleClient(num, actual): # Open independent client connection client = make_client(service=echo_thrift.Echo, host='127.0.0.1', port=9999, trans_factory=TFramedTransportFactory()) # UUID uid = str(uuid4()) for i in range(num): # Make thrift call and increment atomic count txt = uid + str(i) ret = client.echo(echo_thrift.Message(text=txt)) if (txt == ret): with actual.get_lock(): actual.value += 1
def start_client(): while True: while True: try: client = make_client(thrift_service.Ping, 'localhost', 9000) break except: continue while True: try: pong = client.ping() except: break print(pong) time.sleep(1) continue
def getClient(): wwfAPIpathname = os.path.join('thrift', 'wwf_api.thrift') wwfAPI_thrift = thriftpy.load(path=wwfAPIpathname, module_name='wwfAPI_thrift', include_dirs=['thrift']) tTransport = TFramedTransportFactory() client = make_client(wwfAPI_thrift.WwfApi, port=9090, trans_factory=tTransport) return client
def mk_client(self): return make_client(addressbook.AddressBookService, '127.0.0.1', self.port, proto_factory=self.PROTOCOL_FACTORY, trans_factory=self.TRANSPORT_FACTORY)
import thriftpy pingpong_thrift = thriftpy.load("pingpong.thrift", module_name="pingpong_thrift") from thriftpy.rpc import make_client client = make_client(pingpong_thrift.PingPong, '127.0.0.1', 6000) client.ping()
#!/usr/bin/env python # -*- coding: utf-8 -*- import thriftpy from thriftpy.rpc import make_client pingpong_thrift = thriftpy.load("pingpong.thrift", module_name="pingpong_thrift") client = make_client(pingpong_thrift.PingPong, '0.0.0.0', 6000) print client.ping()
def rpc_call(call, server, *args): client = make_client(lang_thrift.CodeExecutor, *server) return getattr(client, call)(*args)
import os import thriftpy import json from thriftpy.rpc import make_client publication_stats_thrift = thriftpy.load( os.path.dirname(__file__)+'/publication_stats.thrift', module_name='publication_stats_thrift' ) if __name__ == '__main__': client = make_client( publication_stats_thrift.PublicationStats, 'publication.scielo.org', 11620 ) body = { "query": { "match": { "collection": "scl" } }, "aggs": { "languages": { "terms": { "field": "languages" } }
def __init__(self, address, port=9196): thrift = load(resource_filename(__name__, "static/yaoguang.thrift"), module_name="yaoguang_thrift") self._client = make_client(thrift.ThriftInterface, address, port)
import thriftpy broker_thrift = thriftpy.load("arbitrage/lib/broker.thrift", module_name="broker_thrift") from thriftpy.rpc import make_client from thriftpy.protocol.binary import TBinaryProtocolFactory from thriftpy.transport.framed import TFramedTransportFactory import config import logging import traceback client = make_client(broker_thrift.TradeService, config.BROKER_HOST, config.BROKER_PORT, proto_factory=TBinaryProtocolFactory(), trans_factory=TFramedTransportFactory(), timeout=60000) def re_init(): try: global client client = make_client(broker_thrift.TradeService, config.BROKER_HOST, config.BROKER_PORT, proto_factory=TBinaryProtocolFactory(), trans_factory=TFramedTransportFactory(), timeout=60000) except Exception as e: logging.warn("make_client exception") traceback.print_exc() def exchange_ping(): client.ping() return
# coding: utf-8 import os import thriftpy articlemeta_thrift = thriftpy.load( os.path.dirname(__file__)+'/articlemeta.thrift', module_name='articlemeta_thrift' ) from thriftpy.rpc import make_client if __name__ == '__main__': client = make_client( articlemeta_thrift.ArticleMeta, '127.0.0.1', 11720 ) #article = client.get_article('S0034-71672014000600891', collection='scl', replace_journal_metadata=True) identifiers = client.get_journal_identifiers(collection='scl', limit=10, offset=0) for i in identifiers: print i.collection, i.code
# coding: utf-8 import os import thriftpy import json from thriftpy.rpc import make_client ratchet_thrift = thriftpy.load( os.path.dirname(__file__)+'/ratchet.thrift', module_name='ratchet_thrift' ) if __name__ == "__main__": client = make_client( ratchet_thrift.RatchetStats, '127.0.0.1', 11630 ) print json.loads(client.general('scl'))
# coding: utf-8 import os import thriftpy articlemeta_thrift = thriftpy.load( os.path.dirname(__file__)+'/articlemeta.thrift', module_name='articlemeta_thrift' ) from thriftpy.rpc import make_client if __name__ == '__main__': client = make_client( articlemeta_thrift.ArticleMeta, 'articlemeta.scielo.org', 11720 ) #article = client.get_article('S0034-71672014000600891', collection='scl', replace_journal_metadata=True) identifiers = client.get_journal_identifiers(collection='scl', limit=10, offset=0) for i in identifiers: print i.collection, i.code
def mk_client(self): return make_client( addressbook.AddressBookService, "127.0.0.1", self.port, trans_factory=TFramedTransportFactory() )
# coding: utf-8 import os import thriftpy import json access_stats_thrift = thriftpy.load( os.path.dirname(__file__)+'/access_stats.thrift', module_name='access_stats_thrift' ) from thriftpy.rpc import make_client if __name__ == '__main__': client = make_client( access_stats_thrift.AccessStats, 'ratchet.scielo.org', 11640 ) print json.loads(client.document('S1807-86212013000200003', 'scl'))
#!/usr/bin/env python # -*- coding: utf-8 -*- import thriftpy from thriftpy.rpc import make_client import os if __name__ == "__main__": file_path = os.path.abspath("../conf/simple.thrift") # 加载注册文件 simple_thrift = thriftpy.load(file_path, module_name="simple_thrift") client = make_client(simple_thrift.RPCTest, '192.168.1.105', 6000) print client.print_fun("wxmimperio")
def send_to_taskqueue(task, task_id, ip, port): client = make_client(enqueue_thrift.RPC, ip, port) client.task_service(task, task_id)
import thriftpy import json publication_stats_thrift = thriftpy.load( os.path.dirname(__file__)+'/publication_stats.thrift', module_name='publication_stats_thrift' ) from thriftpy.rpc import make_client if __name__ == '__main__': client = make_client( publication_stats_thrift.PublicationStats, '127.0.0.1', 11620 ) body = { "query": { "match": { "collection": "scl" } }, "aggs": { "languages": { "terms": { "field": "languages" }
#!/usr/bin/env python # coding: utf-8 import os import thriftpy from thriftpy.rpc import make_client # Examples using thrift if __name__ == '__main__': citedby_thrift = thriftpy.load(os.path.join(os.path.dirname( os.path.abspath(__file__)), 'citedby.thrift')) client = make_client(citedby_thrift.Citedby, 'localhost', 11610) print client.citedby_pid('S1516-89132010000300001', False) print client.citedby_doi('10.1590/S1516-89132010000300001') print client.citedby_meta(title='Biochemical and morphological changes during the growth kinetics of Araucaria angustifolia suspension cultures')
def send_to_worker(task, ip, port): client = make_client(dequeue_thrift.RPC, ip, port) client.task_service(task)