def _create_dep_message(self, *args): """ :rtype: ApplicationDependenciesMessage """ mes = ApplicationDependenciesMessage() for path in args: data = { path: {"configuration_path": path, "dependencies": list()} } mes.update(data) return mes
def __init__(self, configuration, zoo_keeper, web_socket_clients, time_estimate_cache): """ :type configuration: zoom.config.configuration.Configuration :type zoo_keeper: kazoo.client.KazooClient :type web_socket_clients: list """ self._cache = ApplicationDependenciesMessage() self._configuration = configuration self._zoo_keeper = zoo_keeper self._web_socket_clients = web_socket_clients self._time_estimate_cache = time_estimate_cache self._message_throttle = MessageThrottle(configuration, web_socket_clients)
def test_update(self): path = '/foo' mes = ApplicationDependenciesMessage() d1 = {"configuration_path": path, "dependencies": list()} # test dict gets update data = {path: d1} mes.update(data) self.assertEqual(mes.application_dependencies, data) # test data change for same key d2 = d1.copy() d2['dependencies'] = [1, 2, 3] data = {path: d2} mes.update(data) self.assertEqual(mes.application_dependencies.get(path), d2)
def _on_update_path(self, path): try: message = ApplicationDependenciesMessage() self._walk(path, message) self._cache.update(message.application_dependencies) self._recalc_downstream_dependencies() self._message_throttle.add_message(message) self._time_estimate_cache.update_dependencies( self._cache.application_dependencies) except Exception: logging.exception('An unhandled Exception has occurred for path: ' '{0}'.format(path))
class DataStore(object): def __init__(self, configuration, zoo_keeper, task_server): """ :type configuration: zoom.config.configuration.Configuration :type zoo_keeper: kazoo.client.KazooClient :type task_server: zoom.www.entities.task_server.TaskServer """ self._configuration = configuration self._zoo_keeper = zoo_keeper self._task_server = task_server self._alert_exceptions = list() self._pd = \ PagerDuty(self._configuration.pagerduty_subdomain, self._configuration.pagerduty_api_token, self._configuration.pagerduty_default_svc_key, alert_footer=self._configuration.pagerduty_alert_footer) self._alert_manager = AlertManager( configuration.alert_path, configuration.override_node, configuration.application_state_path, zoo_keeper, self._pd, self._alert_exceptions) self._web_socket_clients = list() self._time_estimate_cache = TimeEstimateCache(self._configuration, self._web_socket_clients) self._application_dependency_cache = \ ApplicationDependencyCache(self._configuration, self._zoo_keeper, self._web_socket_clients, self._time_estimate_cache) self._application_state_cache = \ ApplicationStateCache(self._configuration, self._zoo_keeper, self._web_socket_clients, self._time_estimate_cache) self._global_cache = GlobalCache(self._configuration, self._zoo_keeper, self._web_socket_clients) self._pd_svc_list_cache = {} def start(self): logging.info('Starting data store.') self._global_cache.start() self._application_state_cache.start() self._application_dependency_cache.start() self._time_estimate_cache.start() self._alert_manager.start() def stop(self): logging.info('Stopping data store.') self._global_cache.stop() self._application_state_cache.stop() self._application_dependency_cache.stop() self._time_estimate_cache.stop() self._alert_manager.stop() @connected_with_return(ApplicationStatesMessage()) def load_application_state_cache(self): """ :rtype: zoom.messages.application_states.ApplicationStatesMessage """ logging.info('Loading application states.') return self._application_state_cache.load() @connected_with_return(ApplicationDependenciesMessage()) def load_application_dependency_cache(self): """ :rtype: zoom.messages.application_dependencies.ApplicationDependenciesMessage """ logging.info('Loading application dependencies.') return self._application_dependency_cache.load() @connected_with_return(TimeEstimateMessage()) def load_time_estimate_cache(self): """ :rtype: zoom.messages.timing_estimate.TimeEstimateMessage """ return self._time_estimate_cache.load() def get_start_time(self, path): """ :rtype: dict """ return self._time_estimate_cache.get_graphite_data(path) @connected_with_return(GlobalModeMessage('{"mode":"Unknown"}')) def get_global_mode(self): """ :rtype: zoom.messages.global_mode_message.GlobalModeMessage """ logging.info('Loading global mode.') return self._global_cache.get_mode() def reload(self): """ Clear all cache objects and send reloaded data as updates. """ # restart client to destroy any existing watches # self._zoo_keeper.restart() logging.info('Reloading all cache types.') self._task_server.clear_all_tasks() self._global_cache.on_update() self._application_state_cache.reload() self._application_dependency_cache.reload() self._time_estimate_cache.reload() self._alert_manager.start() self._pd_svc_list_cache = self._pd.get_service_dict() return {'cache_clear': 'okay'} def load(self): """ Clear all cache objects and send reloaded data as updates. """ logging.info('Loading all cache types.') self._global_cache.on_update() self._application_state_cache.load() self._application_dependency_cache.load() self._time_estimate_cache.load() self._pd_svc_list_cache = self._pd.get_service_dict() return {'cache_load': 'okay'} @property def pd_client(self): """ :rtype: zoom.common.pagerduty.PagerDuty """ return self._pd @property def web_socket_clients(self): """ :rtype: list """ return self._web_socket_clients @property def application_state_cache(self): """ :rtype: zoom.www.cache.application_state_cache.ApplicationStateCache """ return self._application_state_cache @property def alert_exceptions(self): """ :rtype: list """ return self._alert_exceptions @property def pagerduty_services(self): """ :rtype: dict """ return self._pd_svc_list_cache