def __init__(self, configuration, shouldConnectToZooKeeper=True): if configuration is None or not isinstance(configuration, EZConfiguration): raise Exception("Invalid configuration.") self.__ezConfiguration = configuration self.__applicationName = ApplicationConfiguration.fromConfiguration(configuration).getApplicationName() self.__securityConfiguration = SecurityConfiguration.fromConfiguration(configuration) self.__thriftConfiguration = ThriftConfiguration.fromConfiguration(configuration) # TODO: Add logging stuff here logging.basicConfig(filename="/tmp/py.log", level=logging.DEBUG, format='%(asctime)s \t%(levelname)s: \t%(message)s\t') self.__log = logging.getLogger(__name__) self.__serviceMapLock = threading.RLock() self.__serviceMap = {} self.__connectionPool = {} self.__reverseLookup = {} print "Application name: " + self.__applicationName if self.__applicationName is None: self.__log.warn("No application name was found. Only common services will be discoverable.") # zookeeper stuff if shouldConnectToZooKeeper: ezdiscovery.connect('localhost:2181') try: self.__common_services = list(ezdiscovery.get_common_services()) except Exception: self.__log.error("Unable to get commone services") raise self.__refreshEndPoints() self.__refreshCommonEndPoints()
def test_get_common_services(self): """Test fetching common services.""" # Make a few common services and and an external, ensure they return # properly. ezdiscovery.register_common_endpoint('foo', 'localhost', 8000) ezdiscovery.register_common_endpoint('bar', 'localhost', 8001) ezdiscovery.register_endpoint('harry', 'sally', 'localhost', 8080) self.assertEqual(2, len(ezdiscovery.get_common_services()))
def __refreshCommonEndPoints(self): try: for service in ezdiscovery.get_common_services(): try: endPoints = ezdiscovery.get_common_endpoints(service) self._addEndpoints(service, endPoints) except Exception as e: self.__log.warn("No common service " + service + " was found.") except Exception as e: self.__log.warn("Failed to get common services. This might be okay if no common service has been defined.")