def local_services(): """ Return list of local services """ #cnfame = os.path.join( settings['LOCAL_WORKERS_DIR'], SERVICE_GLOBAL_CONFIG_NAME ) #if os.path.exists(cnfame): # config = KasayaConfigParser(cnfame) #else: # config = None result = {} # # internal services # if settings.USE_ASYNC_SERVICE: # s = Service("asyncd", config) # result[s.name] = s # # if settings.USE_TRANSACTION_SERVICE: # s = Service("transactiond", config) # result[s.name] = s # # if settings.USE_AUTH_SERVICE: # s = Service("authd", config) # result[s.name] = s # # if settings.USE_LOG_SERVICE: # s = Service("logd", config) # result[s.name] = s # user services dname = os.path.abspath(settings.LOCAL_WORKERS_DIR) if not os.path.exists(dname): return result for sdir in os.listdir(dname): # service config fp = os.path.join(dname, sdir) cnf = os.path.join(fp, SERVICE_CONFIG_NAME) if not os.path.exists(cnf): continue # directory contains service try: s = Service(fp) except UnknownServiceMode as e: LOG.error( "Service [%s] requires mode [%s] which is unimplemented. Ignoring." % (e.service, e.mode)) continue if s.name in result: LOG.error("Found more than one service with name [%s]. Ignoring." % s.name) continue result[s.name] = s return result
def loop(self): while self.is_running: # receive data msgdata, addr = self.SOCK.recvfrom(4096) # skip own broadcast messages if addr[0] == self.own_ip: continue # deserialize try: msgdata, repreq = self.serializer.deserialize(msgdata) except NotOurMessage: continue except Exception: LOG.warning("Message from broadcast deserialisation error") LOG.debug( "Broken message body dump in hex (only first 1024 bytes):\n%s" % msgdata[:1024].encode("hex")) continue # own broadcast from another interface try: if msgdata['__sid__'] == self.ID: continue except KeyError: continue # message type try: msg = msgdata['message'] except KeyError: LOG.debug("Decoded message is incomplete. Message dump: %s" % repr(msgdata)) continue # find handler try: handler = self._msgdb[msg] except KeyError: # unknown messages are ignored silently LOG.warning("Unknown message received [%s]" % msg) LOG.debug("Message body dump:\n%s" % repr(msgdata)) continue # run handler try: handler(msgdata) except Exception as e: # log exception details excname = e.__class__.__name__ # traceback tback = traceback.format_exc() try: tback = unicode(tback, "utf-8") except: tback = repr(tback) # error message errmsg = e.message try: errmsg = unicode(errmsg, "utf-8") except: errmsg = repr(errmsg) # log & clean LOG.error( "Exception [%s] when processing message [%s]. Message: %s." % (excname, msg, errmsg)) LOG.debug("Message dump: %s" % repr(msgdata)) LOG.debug(tback) del excname, tback, errmsg