def onJoin(self, details): s = ZmqPullConnection(ZF, ZFE) def go_pull(sr): chan, sr = sr[0].split(' ', 1) sr = pickle.loads(sr) print chan #self.publish(chan, sr) s.onPull = go_pull
def onJoin(self, details): s = ZmqPullConnection(ZF, ZFE) ss = ZmqPushConnection(ZF, ZFE_SSL ) def go_pull(sr): ss.push(sr) chan, sr = sr[0].split(' ', 1) sr = pickle.loads(sr) #print chan #print chan, sr['bdata_mode0']['updated'] self.publish(chan, sr) s.onPull = go_pull
def onJoin(self, details): s = ZmqPullConnection(ZF, ZFE) ss = ZmqPushConnection(ZF, ZFE_SSL) def go_pull(sr): ss.push(sr) chan, sr = sr[0].split(' ', 1) sr = pickle.loads(sr) #print chan #print chan, sr['bdata_mode0']['updated'] self.publish(chan, sr) s.onPull = go_pull
def __init__(self, worker): log.msg("Initializing auto server") # # Setup the zmq socket used for receiving images. # self.zmq_factory = ZmqFactory() # # Socket for pulling images and crops from the automatic client. # endpoint = ZmqEndpoint( 'connect', 'tcp://localhost:{zmq_port}'.format( zmq_port=gs.ZMQ_AUTO_WORKER_PUSH)) self.pull_socket = ZmqPullConnection(self.zmq_factory, endpoint) self.pull_socket.onPull = self.handleNewMessage # # Socket for pushing results to the automatic client. # endpoint = ZmqEndpoint( 'connect', 'tcp://localhost:{zmq_port}'.format( zmq_port=gs.ZMQ_AUTO_WORKER_PULL)) self.push_socket = ZmqPushConnection(self.zmq_factory, endpoint) self.worker = worker
def __init__(self, app): # # Setup the zmq socket used for receiving images. # self.zmq_factory = ZmqFactory() # # Socket for pushing images and crops to the automatic processing servers. # endpoint = ZmqEndpoint( 'bind', 'tcp://*:{zmq_port}'.format(zmq_port=gs.ZMQ_AUTO_WORKER_PUSH)) self.push_socket = ZmqPushConnection(self.zmq_factory, endpoint) # # Socket for pulling results from the automatic processing servers. # endpoint = ZmqEndpoint( 'bind', 'tcp://*:{zmq_port}'.format(zmq_port=gs.ZMQ_AUTO_WORKER_PULL)) self.pull_socket = ZmqPullConnection(self.zmq_factory, endpoint) self.pull_socket.onPull = self.handleNewMessage self.app = app
def __init__(self, taskd, **kwargs): TaseBasic.__init__(self, taskd, **kwargs) self.flow_stat = {} self.statdata = self.cache.get(radius_statcache_key) or statistics.MessageStat(quemax=180) self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('bind', self.config.mqproxy['task_bind'])) self.puller.onPull = self.update_stat logger.info('start stat mq %s' % self.puller)
def __init__(self, taskd, **kwargs): TaseBasic.__init__(self, taskd, **kwargs) self.statdata = statistics.MessageStat() self.puller = ZmqPullConnection( ZmqFactory(), ZmqEndpoint('bind', 'ipc:///tmp/radiusd-stat-task')) self.puller.onPull = self.update_stat logger.info("init Radius stat puller : %s " % (self.puller))
def __init__(self, config, dbengine, radcache=None): self.config = config self.dict = dictionary.Dictionary( os.path.join(os.path.dirname(toughradius.__file__), 'dictionarys/dictionary')) self.db_engine = dbengine or get_engine(config) self.mcache = radcache self.pusher = ZmqPushConnection( ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-acct-result')) self.stat_pusher = ZmqPushConnection( ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-stat-task')) self.puller = ZmqPullConnection( ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-acct-message')) self.puller.onPull = self.process logger.info("init acct worker pusher : %s " % (self.pusher)) logger.info("init acct worker puller : %s " % (self.puller)) logger.info("init auth stat pusher : %s " % (self.stat_pusher)) self.acct_class = { STATUS_TYPE_START: RadiusAcctStart, STATUS_TYPE_STOP: RadiusAcctStop, STATUS_TYPE_UPDATE: RadiusAcctUpdate, STATUS_TYPE_ACCT_ON: RadiusAcctOnoff, STATUS_TYPE_ACCT_OFF: RadiusAcctOnoff }
def __init__(self, config, logger=None): self.config = config self.logger = logger or Logger() self.debug = self.config.get('debug', True) self.vendor = self.config.get('vendor', 'cmccv2') self.secret = str(self.config.get('secret', 'secret')) self.rundata = {'challenges': {}} self.ac_handlers = { cmcc.REQ_CHALLENGE: chellenge_handler.ChellengeHandler(self.config, self.logger), cmcc.REQ_AUTH: auth_handler.AuthHandler(self.config, self.logger), cmcc.REQ_INFO: reqinfo_handler.ReqInfoHandler(self.config, self.logger), cmcc.AFF_ACK_AUTH: base_handler.EmptyHandler(self.config, self.logger), cmcc.ACK_NTF_LOGOUT: base_handler.EmptyHandler(self.config, self.logger), cmcc.NTF_HEARTBEAT: base_handler.EmptyHandler(self.config, self.logger), cmcc.REQ_LOGOUT: logout_handler.LogoutHandler(self.config, self.logger) } self.puller = ZmqPullConnection( ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/tpsim-message')) self.puller.onPull = self.process reactor.listenUDP(0, self) self.logger.info('init TpSimWorker puller : %s ' % self.puller)
def __init__(self, config, service='auth'): self.config = config self.service = service self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('bind', 'ipc:///tmp/radiusd-%s-message' % service)) self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('bind', 'ipc:///tmp/radiusd-%s-result' % service)) self.puller.onPull = self.reply logger.info("init %s master pusher : %s " % (self.service, self.pusher)) logger.info("init %s master puller : %s " % (self.service, self.puller))
def __init__(self, config, service = 'auth'): self.config = config self.service = service self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('bind', config.mqproxy[self.service + '_message'])) self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('bind', config.mqproxy[self.service + '_result'])) self.puller.onPull = self.radiusReply logger.info('%s master message bind @ %s' % (self.service, self.pusher)) logger.info('%s master result bind @ %s' % (self.service, self.puller))
def __init__(self, taskd, **kwargs): TaseBasic.__init__(self, taskd, **kwargs) self.flow_stat = {} self.statdata = self.cache.get( radius_statcache_key) or statistics.MessageStat() self.puller = ZmqPullConnection( ZmqFactory(), ZmqEndpoint('bind', 'ipc:///tmp/radiusd-stat-task')) self.puller.onPull = self.update_stat
def pull_share_async(obj, address): """ :param obj: :param address: :returns: AsyncPullExport """ socket = ZmqPullConnection(ZmqFactory(), ZmqEndpoint("bind", address)) return AsyncPullExport(obj, socket)
def __init__(self, endpoint, callBack=None): if endpoint: logger.debug("开始运行 PULL 服务器,连接地址为:{}...".format(endpoint)) self._pull = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('bind', endpoint)) if callBack: self._pull.onPull = callBack else: self._pull.onPull = self.doDataReceived else: self._pull = None
def add_pull(self, endpoint, callBack=onPrint): ''' :param endpoint: :param callBack: :return: ''' if endpoint: logger.debug("开始运行 PULL 服务器,连接地址为:{}...".format(endpoint)) self.pull_ = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('bind', endpoint)) self.pull_.onPull = callBack
def __init__(self, config, dbengine, radcache=None): self.config = config self.dict = dictionary.Dictionary( os.path.join(os.path.dirname(toughradius.__file__), 'dictionarys/dictionary')) self.db_engine = dbengine or get_engine(config) self.aes = utils.AESCipher(key=self.config.system.secret) self.mcache = radcache self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-auth-result')) self.stat_pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-stat-task')) self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('connect', 'ipc:///tmp/radiusd-auth-message')) self.puller.onPull = self.process reactor.listenUDP(0, self) logger.info("init auth worker pusher : %s " % (self.pusher)) logger.info("init auth worker puller : %s " % (self.puller)) logger.info("init auth stat pusher : %s " % (self.stat_pusher))
def __init__(self, zmq_notice_port, zmq_files_port, vn=None): self._loadSearchArea() # # Setup the zmq socket used for sending notice of images. # zmq_factory = ZmqFactory() endpoint = ZmqEndpoint('bind', 'tcp://*:{zmq_port}'.format(zmq_port=zmq_notice_port)) self.zmq_socket = ZmqPushConnection(zmq_factory, endpoint) # # Setup the zmq socket used for sending the images. # endpoint = ZmqEndpoint('bind', 'tcp://*:{zmq_port}'.format(zmq_port=zmq_files_port)) self.zmq_files_socket = ImageFileServerConnection(zmq_factory, endpoint, ) # # Setup the zmq socket used for receiving detection results from the # jetson. # endpoint_rx = ZmqEndpoint('connect', 'tcp://{ip}:{port}'.format(ip=JETSON_IP, port=ADLC_RX_PORT)) self.adlc_rx_socket = ZmqPullConnection(zmq_factory, endpoint_rx) self.adlc_rx_socket.onPull = self.handleADLCResults # # Flag that controls the sending the images # self._send_images = threading.Event() self.manual_crop_cnt = 0 self.auto_crop_cnt = 0 self._img_counter = 0 self._adlc_count = 0 self._received_image_count = 0 self._vn = vn # # Start the upload thread. # Note: # I am using a separate thread for uploading in order to use an # upload queue. We had a problem where slow upload caused many upload # processes to start together and cause jamming in communication. # self.upload_queue = tQueue.Queue(0) self.upload_thread = thread.start_new_thread(upload_thread, (self.upload_queue,))
def __init__(self, config, dbengine, radcache = None): self.config = config self.load_plugins(load_types=['radius_auth_req', 'radius_accept']) self.dict = dictionary.Dictionary(os.path.join(os.path.dirname(taurusxradius.__file__), 'dictionarys/dictionary')) self.db_engine = dbengine or get_engine(config) self.aes = utils.AESCipher(key=self.config.system.secret) self.mcache = radcache self.reject_debug = int(self.get_param_value('radius_reject_debug', 0)) == 1 self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', config.mqproxy['auth_result'])) self.stat_pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', config.mqproxy['task_connect'])) self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('connect', config.mqproxy['auth_message'])) self.puller.onPull = self.process logger.info('radius auth worker %s start' % os.getpid()) logger.info('init auth worker pusher : %s ' % self.pusher) logger.info('init auth worker puller : %s ' % self.puller) logger.info('init auth stat pusher : %s ' % self.stat_pusher) self.license_ulimit = 50000
def __init__(self, config, dbengine, radcache = None): self.config = config self.load_plugins(load_types=['radius_acct_req']) self.db_engine = dbengine or get_engine(config) self.mcache = radcache self.dict = dictionary.Dictionary(os.path.join(os.path.dirname(taurusxradius.__file__), 'dictionarys/dictionary')) self.stat_pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', config.mqproxy['task_connect'])) self.pusher = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', config.mqproxy['acct_result'])) self.puller = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('connect', config.mqproxy['acct_message'])) self.puller.onPull = self.process self.acct_class = {STATUS_TYPE_START: RadiusAcctStart, STATUS_TYPE_STOP: RadiusAcctStop, STATUS_TYPE_UPDATE: RadiusAcctUpdate, STATUS_TYPE_ACCT_ON: RadiusAcctOnoff, STATUS_TYPE_ACCT_OFF: RadiusAcctOnoff} logger.info('radius acct worker %s start' % os.getpid()) logger.info('init acct worker pusher : %s ' % self.pusher) logger.info('init acct worker puller : %s ' % self.puller) logger.info('init acct stat pusher : %s ' % self.stat_pusher)
def __init__(self, gdata): self.gdata = gdata self.config = gdata.config self.que = deque() self.cache = gdata.cache self.db_engine = gdata.db_engine self.metadata = models.get_metadata(self.db_engine) self.ops = { 'radstart':self.start_session, 'radstop':self.stop_session } self.radstart = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('connect', self.config.mqproxy.radstart_connect)) self.radstop = ZmqSubConnection(ZmqFactory(), ZmqEndpoint('connect',self.config.mqproxy.radstop_connect)) self.radresp = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', self.config.mqproxy.radresp_connect)) self.radstop.subscribe('radstop') self.radstop.gotMessage = self.subdataReceived self.radstart.onPull = self.dataReceived self.process_poll() logger.info("Start radstart %s" % self.radstart) logger.info("Start radstop %s" % self.radstop) logger.info("Start radresp %s" % self.radresp)
def __init__(self, server, port, secret, requests, concurrency, username, password, verb=False, timeout=30, forknum=1, interval=2, rate=1000): self.interval = interval tparams = [ ' - Client platform : %s, %s' % (platform.platform(), platform.machine()), ' - Python implement, version : %s, %s' % (platform.python_implementation(), platform.python_version()), ' - Radius server address : %s' % server, ' - Radius Server auth port : %s' % port, ' - Raduius share secret : %s' % secret, ' - Auth Request total : %s' % requests, ' - Concurrency level : %s' % concurrency, ' - Worker Process num : %s' % forknum, ' - All Requests timeout : %s sec' % timeout, ' - Stat data interval : %s sec' % interval, ' - Send request rate : %s/sec' % rate, ] self.stat_counter = AuthStatCounter(tparams) self.puller = ZmqPullConnection( ZmqFactory(), ZmqEndpoint('bind', 'ipc:///tmp/toughbt-message')) self.puller.onPull = self.do_stat # log.msg("init BenchmarkMaster puller : %s " % (self.puller)) reactor.callLater(interval, self.chk_task) reactor.callLater(timeout, reactor.stop)
from twisted.python.log import startLogging from twisted.internet import reactor from txrdq.rdq import ResizableDispatchQueue # startLogging(sys.stdout) parser = OptionParser("UptimeWorker") parser.add_option("-i", "--id", dest="id", help="Worker ID") parser.add_option("-p", "--ssh-port", dest="port", help="ssh port") parser.add_option("-u", "--ssh-user", dest="user", help="ssh user") parser.add_option("-s", "--source", dest="source", help="0MQ ssh hosts producer Endpoint") parser.add_option("-r", "--results", dest="results", help="0MQ ssh result sink Endpoint") parser.add_option("-c", "--concurrency", dest="concurrency", help="Max concurrent ssh sessions") (options, args) = parser.parse_args() ssh_options = {"worker_id": options.id, "port": int(options.port), "user": options.user} # limit concurrency otherwise things go pear shaped. rdq = ResizableDispatchQueue(do_ssh, int(options.concurrency)) # setup pull socket to ssh host producerr hosts_endpont = ZmqEndpoint("connect", options.source) reciever = ZmqPullConnection(zf, hosts_endpont) reciever.onPull = rdq.put # setup result sink socket sink_endpoint = ZmqEndpoint("connect", options.results) sink = ZmqPushConnection(zf, sink_endpoint) reactor.run()
parser.set_defaults(method="connect", endpoint="ipc:///tmp/txzmq-pc-demo") (options, args) = parser.parse_args() zf = ZmqFactory() e = ZmqEndpoint(options.method, options.endpoint) if options.mode == "push": s = ZmqPushConnection(zf, e) def produce(): data = [str(time.time()), socket.gethostname()] print "producing %r" % data try: s.push(data) except zmq.error.Again: print "Skipping, no pull consumers..." reactor.callLater(1, produce) reactor.callWhenRunning(reactor.callLater, 1, produce) else: s = ZmqPullConnection(zf, e) def doPrint(message): print "consuming %r" % (message,) s.onPull = doPrint reactor.run()
def init(gdata): appname = os.path.basename(gdata.app_dir) utils.update_tz(gdata.config.system.tz) syslog = logger.Logger(gdata.config, appname) dispatch.register(syslog) log.startLoggingWithObserver(syslog.emit, setStdout=0) gdata.db_engine = get_engine(gdata.config) gdata.db = scoped_session( sessionmaker(bind=gdata.db_engine, autocommit=False, autoflush=False)) # web 应用初始化 gdata.settings = dict( cookie_secret="12oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=", login_url="/admin/login", template_path=os.path.join(os.path.dirname(__file__), "views"), static_path=os.path.join(os.path.dirname(__file__), "static"), xsrf_cookies=True, xheaders=True, conf=gdata.config) # 模板初始化 gdata.tp_lookup = TemplateLookup( directories=[gdata.settings['template_path']], default_filters=['decode.utf8'], input_encoding='utf-8', output_encoding='utf-8', encoding_errors='ignore', module_directory="/tmp/toughcloud") gdata.redisconf = redis_conf(gdata.config) gdata.session_manager = session.SessionManager( gdata.redisconf, gdata.settings["cookie_secret"], 7200) gdata.cache = CacheManager(gdata.redisconf, cache_name='Cache-%s' % os.getpid()) gdata.aes = utils.AESCipher(key=gdata.config.system.secret) # 数据库备份器初始化 gdata.db_backup = DBBackup(models.get_metadata(gdata.db_engine), excludes=[]) #cache event init dispatch.register(gdata.cache) # app handles init handler_dir = os.path.join(gdata.app_dir, 'handlers') load_handlers(handler_path=handler_dir, pkg_prefix="%s.handlers" % appname, excludes=[]) gdata.all_handlers = permit.all_handlers # app event init event_dir = os.path.abspath(os.path.join(gdata.app_dir, 'events')) load_events(event_dir, "%s.events" % appname) # init zmq gdata.radque = deque([], 8192) gdata.radstart = ZmqPushConnection( ZmqFactory(), ZmqEndpoint('bind', gdata.config.mqproxy.radstart_bind)) gdata.radstop = ZmqPubConnection( ZmqFactory(), ZmqEndpoint('bind', gdata.config.mqproxy.radstop_bind)) gdata.radresp = ZmqPullConnection( ZmqFactory(), ZmqEndpoint('bind', gdata.config.mqproxy.radresp_bind)) gdata.radresp.onPull = lambda m: gdata.radque.appendleft( msgpack.unpackb(m[0])) gdata.statcache = StatCounter(gdata) gdata.statcache.init() gdata.statcache.poll_calc() logger.info(gdata.radstart) logger.info(gdata.radstop) logger.info(gdata.radresp)
def startService(self): zf = ZmqFactory() endpoint = ZmqEndpoint('bind', self._bindAddress) puller = ZmqPullConnection(zf, endpoint) puller.onPull = processor
def __init__(self, app, ip_camera, role, ip_controller): if role == gs.CONTROLLER: self.images_folder = gs.CTRL_IMAGES_FOLDER self.crops_folder = gs.CTRL_CROPS_FOLDER self.flightdata_folder = gs.CTRL_FLIGHTDATA_FOLDER self.thumbs_folder = None else: self.images_folder = gs.IMAGES_FOLDER self.crops_folder = gs.CROPS_FOLDER self.flightdata_folder = gs.FLIGHTDATA_FOLDER self.thumbs_folder = gs.THUMBNAILS_FOLDER if not os.path.exists(self.images_folder): os.makedirs(self.images_folder) if not os.path.exists(self.crops_folder): os.makedirs(self.crops_folder) if not os.path.exists(self.flightdata_folder): os.makedirs(self.flightdata_folder) if self.thumbs_folder is not None and not os.path.exists( self.thumbs_folder): os.makedirs(self.thumbs_folder) self.role = role # # Setup the zmq socket used for receiving images. # self.zmq_factory = ZmqFactory() if self.role == gs.CONTROLLER: # # Socket for pulling notices about images from the camera. # endpoint = ZmqEndpoint( 'connect', 'tcp://{server_ip}:{zmq_port}'.format( server_ip=ip_camera, zmq_port=gs.ZMQ_CAMERA_NOTICE_PORT)) self.pull_socket = ZmqPullConnection(self.zmq_factory, endpoint) self.pull_socket.onPull = self.handlePullMessage # # Socket for requesting images from the camera. # endpoint = ZmqEndpoint( 'connect', 'tcp://{server_ip}:{zmq_port}'.format( server_ip=ip_camera, zmq_port=gs.ZMQ_CAMERA_FILES_PORT)) self.req_socket = ZmqREQConnection(self.zmq_factory, endpoint) # # Socket for publishing images to subscribers. # endpoint = ZmqEndpoint( 'bind', 'tcp://0.0.0.0:{zmq_port}'.format( zmq_port=gs.ZMQ_PRIMARY_GS_PORT)) self.pub_socket = MyZmqPubConnection(self.zmq_factory, endpoint) # # Socket for responding with queued images or sync data. # endpoint = ZmqEndpoint( 'bind', 'tcp://*:{zmq_port}'.format( zmq_port=gs.ZMQ_PRIMARY_GS_CONTROLLER_PORT)) self.sync_rep_socket = ControllerSyncConnection( self.zmq_factory, endpoint, self) else: # # Socket for subscribing to images. # endpoint = ZmqEndpoint( 'connect', 'tcp://{server_ip}:{zmq_port}'.format( server_ip=ip_controller, zmq_port=gs.ZMQ_PRIMARY_GS_PORT)) self.sub_socket = MyZmqSubConnection(self.zmq_factory, endpoint) self.sub_socket.subscribe(gs.SUB_TAG) self.sub_socket.gotMessage = self.handleNewMessage # # Socket for requesting queued images or sync data from the controller. # endpoint = ZmqEndpoint( 'connect', 'tcp://{server_ip}:{zmq_port}'.format( server_ip=ip_controller, zmq_port=gs.ZMQ_PRIMARY_GS_CONTROLLER_PORT)) self.sync_req_socket = ZmqREQConnection(self.zmq_factory, endpoint) log.msg('Sending sync request') self.requestSyncImageList() self.requestSyncCropList() self.app = app