예제 #1
0
    def __init__(self, args=None, logger=None, queue=None):
        self._args = args
        self._queue = queue
        self.logger = logger

        self._homepage_links = []
        self._cni_data = {}

        self._base_url = "http://%s:%s" % (self._args.mesos_cni_server,
                                           self._args.mesos_cni_port)
        self._pipe_start_app = None
        bottle.route('/', 'GET', self.homepage_http_get)

        # Add CNI information
        bottle.route('/add_cni_info', 'POST', self.add_cni_info)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/add_cni_info',
                       'Add CNI information'))

        # Del CNI information
        bottle.route('/del_cni_info', 'POST', self.del_cni_info)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/del_cni_info',
                       'Del CNI information'))

        if not self._pipe_start_app:
            self._pipe_start_app = bottle.app()
예제 #2
0
    def __init__(self, args=None, logger=None, q=None):
        self._args = args
        self._q = q
        self.logger = logger

        self._homepage_links = []
        self._cni_data = {}

        self._base_url = "http://%s:%s" % (self._args.listen_ip_addr,
                                           self._args.listen_port)
        self._pipe_start_app = None
        bottle.route('/', 'GET', self.homepage_http_get)

        # Add CNI information
        bottle.route('/add_cni_info', 'POST', self.add_cni_info)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/add_cni_info',
                       'Add CNI information'))

        # Get CNI information
        bottle.route('/get_cni_info', 'GET', self.get_cni_info_all)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/get_cni_info',
                       'get all CNI information'))

        # get a specific CNI information
        bottle.route('/get_cni_info/<container_id>', 'GET',
                     self.get_cni_info_all)

        # show config
        bottle.route('/config', 'GET', self.show_config)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/config', 'show cni config'))

        # show debug
        bottle.route('/stats', 'GET', self.show_stats)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/stats',
                       'show cni debug stats'))

        # cleanup
        bottle.route('/cleanup', 'GET', self.cleanup_http_get)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/cleanup',
                       'Purge deleted cni'))

        if not self._pipe_start_app:
            self._pipe_start_app = bottle.app()
    def __init__(self, args):
        self._homepage_links = []
        self._args = args
        self.service_config = args.service_config
        self._debug = {
            'hb_stray': 0,
            'msg_pubs': 0,
            'msg_subs': 0,
            'msg_query': 0,
            'msg_hbt': 0,
            'ttl_short': 0,
            'policy_rr': 0,
            'policy_lb': 0,
            'policy_fi': 0,
            'db_upd_hb': 0,
            'max_pend_pb': 0,
            'max_pend_sb': 0,
            'max_pend_hb': 0,
            'cur_pend_pb': 0,
            'cur_pend_sb': 0,
            'cur_pend_hb': 0,
            'throttle_subs': 0,
            'restarting': 0,
        }
        self._ts_use = 1
        self.short_ttl_map = {}
        self._sem = BoundedSemaphore(1)

        self._base_url = "http://%s:%s" % (self._args.listen_ip_addr,
                                           self._args.listen_port)
        self._pipe_start_app = None

        bottle.route('/', 'GET', self.homepage_http_get)

        # heartbeat
        bottle.route('/heartbeat', 'POST', self.api_heartbeat)

        # publish service
        bottle.route('/publish', 'POST', self.api_publish)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/publish',
                       'publish service'))
        bottle.route('/publish/<end_point>', 'POST', self.api_publish)

        # subscribe service
        bottle.route('/subscribe', 'POST', self.api_subscribe)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/subscribe',
                       'subscribe service'))

        # query service
        bottle.route('/query', 'POST', self.api_query)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/query', 'query service'))

        # collection - services
        bottle.route('/services', 'GET', self.show_all_services)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/services',
                       'show published services'))
        bottle.route('/services.json', 'GET', self.services_json)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/services.json',
                       'List published services in JSON format'))
        # show a specific service type
        bottle.route('/services/<service_type>', 'GET', self.show_all_services)

        # update service
        bottle.route('/service/<id>', 'PUT', self.service_http_put)

        # get service info
        bottle.route('/service/<id>', 'GET', self.service_http_get)
        bottle.route('/service/<id>/brief', 'GET', self.service_brief_http_get)

        # delete (un-publish) service
        bottle.route('/service/<id>', 'DELETE', self.service_http_delete)

        # collection - clients
        bottle.route('/clients', 'GET', self.show_all_clients)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/clients',
                       'list all subscribers'))
        bottle.route('/clients.json', 'GET', self.clients_json)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/clients.json',
                       'list all subscribers in JSON format'))

        # show config
        bottle.route('/config', 'GET', self.config_http_get)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/config',
                       'show discovery service config'))

        # show debug
        bottle.route('/stats', 'GET', self.show_stats)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/stats',
                       'show discovery service stats'))

        # cleanup
        bottle.route('/cleanup', 'GET', self.cleanup_http_get)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/cleanup',
                       'Purge inactive publishers'))

        if not self._pipe_start_app:
            self._pipe_start_app = bottle.app()

        # sandesh init
        self._sandesh = Sandesh()
        module = Module.DISCOVERY_SERVICE
        module_name = ModuleNames[module]
        node_type = Module2NodeType[module]
        node_type_name = NodeTypeNames[node_type]
        instance_id = self._args.worker_id
        self._sandesh.init_generator(module_name, socket.gethostname(),
                                     node_type_name, instance_id,
                                     self._args.collectors,
                                     'discovery_context',
                                     int(self._args.http_server_port),
                                     ['sandesh', 'uve'])
        self._sandesh.set_logging_params(enable_local_log=self._args.log_local,
                                         category=self._args.log_category,
                                         level=self._args.log_level,
                                         file=self._args.log_file)
        self._sandesh.trace_buffer_create(name="dsHeartBeatTraceBuf",
                                          size=1000)

        # DB interface initialization
        self._db_conn = self._args.zk
        self._db_conn.set_ds(self)

        # update services database (old db didn't keep HB)
        for entry in self._db_conn.service_entries():
            update = False
            if 'heartbeat' not in entry:
                entry['heartbeat'] = int(time.time())
                self._debug['db_upd_hb'] += 1
                update = True

            if update:
                self._db_conn.update_service(entry['service_type'],
                                             entry['service_id'], entry)

        # build in-memory subscriber data
        self._sub_data = {}
        for (client_id, service_type) in self._db_conn.subscriber_entries():
            self.create_sub_data(client_id, service_type)

        # must be done after we have built in-memory publisher data from db.
        self._db_conn.start_background_tasks()
예제 #4
0
    def __init__(self, args):
        self._homepage_links = []
        self._args = args
        self.service_config = args.service_config
        self.cassandra_config = args.cassandra_config
        self._debug = {
            'hb_stray': 0,
            'msg_pubs': 0,
            'msg_subs': 0,
            'msg_query': 0,
            'msg_hbt': 0,
            'ttl_short': 0,
            'policy_rr': 0,
            'policy_lb': 0,
            'policy_fi': 0,
            'db_upd_hb': 0,
            'throttle_subs': 0,
            '503': 0,
            'count_lb': 0,
        }
        self._ts_use = 1
        self.short_ttl_map = {}
        self._sem = BoundedSemaphore(1)

        self._base_url = "http://%s:%s" % (self._args.listen_ip_addr,
                                           self._args.listen_port)
        self._pipe_start_app = None

        bottle.route('/', 'GET', self.homepage_http_get)

        # heartbeat
        bottle.route('/heartbeat', 'POST', self.api_heartbeat)

        # publish service
        bottle.route('/publish', 'POST', self.api_publish)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/publish',
                       'publish service'))
        bottle.route('/publish/<end_point>', 'POST', self.api_publish)

        # subscribe service
        bottle.route('/subscribe', 'POST', self.api_subscribe)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/subscribe',
                       'subscribe service'))

        # query service
        bottle.route('/query', 'POST', self.api_query)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/query', 'query service'))

        # collection - services
        bottle.route('/services', 'GET', self.show_all_services)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/services',
                       'show published services'))
        bottle.route('/services.json', 'GET', self.services_json)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/services.json',
                       'List published services in JSON format'))
        # show a specific service type
        bottle.route('/services/<service_type>', 'GET', self.show_all_services)

        # api to perform on-demand load-balance across available publishers
        bottle.route('/load-balance/<service_type>', 'POST',
                     self.api_lb_service)

        # update service
        bottle.route('/service/<id>', 'PUT', self.service_http_put)

        # get service info
        bottle.route('/service/<id>', 'GET', self.service_http_get)
        bottle.route('/service/<id>/brief', 'GET', self.service_brief_http_get)

        # delete (un-publish) service
        bottle.route('/service/<id>', 'DELETE', self.service_http_delete)

        # collection - clients
        bottle.route('/clients', 'GET', self.show_all_clients)
        bottle.route('/clients/<service_type>/<service_id>', 'GET',
                     self.show_all_clients)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/clients',
                       'list all subscribers'))
        bottle.route('/clients.json', 'GET', self.clients_json)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/clients.json',
                       'list all subscribers in JSON format'))

        # show config
        bottle.route('/config', 'GET', self.show_config)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/config',
                       'show discovery service config'))

        # show debug
        bottle.route('/stats', 'GET', self.show_stats)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/stats',
                       'show discovery service stats'))

        # cleanup
        bottle.route('/cleanup', 'GET', self.cleanup_http_get)
        self._homepage_links.append(
            LinkObject('action', self._base_url, '/cleanup',
                       'Purge inactive publishers'))

        if not self._pipe_start_app:
            self._pipe_start_app = bottle.app()

        # sandesh init
        self._sandesh = Sandesh()
        module = Module.DISCOVERY_SERVICE
        module_name = ModuleNames[module]
        node_type = Module2NodeType[module]
        node_type_name = NodeTypeNames[node_type]
        instance_id = self._args.worker_id
        disc_client = discovery_client.DiscoveryClient(
            '127.0.0.1', self._args.listen_port,
            ModuleNames[Module.DISCOVERY_SERVICE])
        self._sandesh.init_generator(
            module_name,
            socket.gethostname(),
            node_type_name,
            instance_id,
            self._args.collectors,
            'discovery_context',
            int(self._args.http_server_port), ['sandesh'],
            disc_client,
            logger_class=self._args.logger_class,
            logger_config_file=self._args.logging_conf)
        self._sandesh.set_logging_params(enable_local_log=self._args.log_local,
                                         category=self._args.log_category,
                                         level=self._args.log_level,
                                         file=self._args.log_file)
        self._sandesh.trace_buffer_create(name="dsHeartBeatTraceBuf",
                                          size=1000)

        # DB interface initialization
        self._db_connect(self._args.reset_config)

        # build in-memory subscriber data
        self._sub_data = {}
        for (client_id, service_type) in self._db_conn.subscriber_entries():
            self.create_sub_data(client_id, service_type)