コード例 #1
0
    def test_walk_children(self):
        cache = ApplicationStateCache(self.configuration, self.zoo_keeper,
                                      self.web_socket_clients, 
                                      self.time_estimate_cache)
        app_state1 = ApplicationStateMock()
        app_state1.mock_dict = {'key': 'value'}
        app_state1.configuration_path = "path1/foo"

        app_state2 = ApplicationStateMock()
        app_state2.mock_dict = {'key': 'value'}
        app_state2.configuration_path = "path1/bar"

        result = ApplicationStatesMessage()
        compare = dict()
        compare.update({'path1/bar': app_state2.to_dictionary()})
        compare.update({'path1/foo': app_state1.to_dictionary()})

        self.zoo_keeper.connected = True
        self.zoo_keeper.get_children('path1', watch=mox.IgnoreArg()).AndReturn(['foo', 'bar'])
        self.zoo_keeper.get_children('path1/foo', watch=mox.IgnoreArg()).AndReturn([])
        self.zoo_keeper.get_children('path1/bar', watch=mox.IgnoreArg()).AndReturn([])

        self.mox.StubOutWithMock(cache, "_get_application_state")
        cache._get_application_state('path1/foo').AndReturn(app_state2)
        cache._get_application_state('path1/bar').AndReturn(app_state1)

        self.mox.ReplayAll()
         
        cache._walk('path1', result)
        self.assertEquals(result, compare)

        self.mox.VerifyAll()
コード例 #2
0
ファイル: data_store.py プロジェクト: joseroubert08/zoom
    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 = {}
コード例 #3
0
    def test_walk_children(self):
        cache = ApplicationStateCache(self.configuration, self.zoo_keeper,
                                      self.web_socket_clients,
                                      self.time_estimate_cache)
        app_state1 = ApplicationStateMock()
        app_state1.mock_dict = {'key': 'value'}
        app_state1.configuration_path = "path1/foo"

        app_state2 = ApplicationStateMock()
        app_state2.mock_dict = {'key': 'value'}
        app_state2.configuration_path = "path1/bar"

        result = ApplicationStatesMessage()
        compare = dict()
        compare.update({'path1/bar': app_state2.to_dictionary()})
        compare.update({'path1/foo': app_state1.to_dictionary()})

        self.zoo_keeper.connected = True
        self.zoo_keeper.get_children('path1', watch=mox.IgnoreArg()).AndReturn(
            ['foo', 'bar'])
        self.zoo_keeper.get_children('path1/foo',
                                     watch=mox.IgnoreArg()).AndReturn([])
        self.zoo_keeper.get_children('path1/bar',
                                     watch=mox.IgnoreArg()).AndReturn([])

        self.mox.StubOutWithMock(cache, "_get_application_state")
        cache._get_application_state('path1/foo').AndReturn(app_state2)
        cache._get_application_state('path1/bar').AndReturn(app_state1)

        self.mox.ReplayAll()

        cache._walk('path1', result)
        self.assertEquals(result, compare)

        self.mox.VerifyAll()
コード例 #4
0
ファイル: data_store.py プロジェクト: brian-johnson-spot/zoom
    def __init__(self, configuration, zoo_keeper, task_server):
        """
        :type configuration: zoom.config.configuration.Configuration
        :type zoo_keeper: zoom.www.entities.zoo_keeper.ZooKeeper
        :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 = {}
コード例 #5
0
ファイル: data_store.py プロジェクト: brian-johnson-spot/zoom
class DataStore(object):
    def __init__(self, configuration, zoo_keeper, task_server):
        """
        :type configuration: zoom.config.configuration.Configuration
        :type zoo_keeper: zoom.www.entities.zoo_keeper.ZooKeeper
        :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
コード例 #6
0
 def test_construct(self):
     self.mox.ReplayAll()
     ApplicationStateCache(self.configuration, self.zoo_keeper,
                           self.web_socket_clients,
                           self.time_estimate_cache)
     self.mox.VerifyAll()
コード例 #7
0
 def _create_app_state_cache(self):
     return ApplicationStateCache(self.configuration, self.zoo_keeper,
                                  self.web_socket_clients,
                                  self.time_estimate_cache)
コード例 #8
0
ファイル: data_store.py プロジェクト: joseroubert08/zoom
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