Beispiel #1
0
    def _set_provider_configuration(self, interface, nodes):
        """
        设置provider配置
        :param interface:
        :param nodes:
        :return:
        """
        if not nodes:
            return
        try:
            configuration_dict = {}
            for _child_node in nodes:
                _node = urllib.unquote(_child_node).decode('utf8')
                if _node.startswith('override'):
                    service_url = ServiceURL(_node)
                    key = self._to_key(interface, service_url.version, service_url.group)

                    if key not in configuration_dict:
                        configuration_dict[key] = {}
                    if service_url.location not in configuration_dict[key]:
                        configuration_dict[key][service_url.location] = []
                    configuration_dict[key][service_url.location].append(_node)

            if interface in self._service_providers:
                provider_dict = self._service_providers.get(interface)
                for provider_key, second_dict in provider_dict.iteritems():
                    for service_location, service_url in second_dict.iteritems():
                        configuration_service_urls = configuration_dict.get(provider_key, {}).get(service_location)
                        if not configuration_service_urls:
                            service_url.init_default_config()
                        else:
                            service_url.set_config(configuration_service_urls)

        except Exception as e:
            logger.warn('set provider configuration error %s', str(e))
Beispiel #2
0
 def _do_event(self, event):
     if event.startswith('register'):
         url = event[9:]
         if url.startswith('jsonrpc'):
             service_provide = ServiceURL(url)
             self._add_node(service_provide.interface, service_provide)
     if event.startswith('unregister'):
         url = event[11:]
         if url.startswith('jsonrpc'):
             service_provide = ServiceURL(url)
             self._remove_node(service_provide.interface, service_provide)
Beispiel #3
0
 def _compare_swap_nodes(self, interface, nodes, group, version):
     """
     比较,替换现有内存中的节点信息,节点url类似如下
     jsonrpc://192.168.2.1:38080/com.ofpay.demo.api.UserProvider?
     anyhost=true&application=demo-provider&default.timeout=10000&dubbo=2.4.10&
     environment=product&interface=com.ofpay.demo.api.UserProvider&
     methods=getUser,queryAll,queryUser,isLimit&owner=wenwu&pid=61578&
     side=provider&timestamp=1428904600188
     首先将url转为ServiceUrl对象,然保持到缓存中
     :param nodes: 节点列表
     :return: 不需要返回
     """
     if self._mutex.acquire():
         # 存在并发问题,需要线程锁
         try:
             # 如果已经存在,首先删除原有的服务的集合
             if interface in self._service_providers:
                 del self._service_providers[interface]
                 logger.debug("delete node {0}".format(interface))
             for child_node in nodes:
                 node = urllib.parse.unquote(child_node,
                                             encoding='utf-8',
                                             errors='replace')
                 if node.startswith('jsonrpc'):
                     service_url = ServiceURL(node,
                                              group=group,
                                              version=version)
                     self._add_node(interface, service_url)
         except Exception as e:
             logger.warn('swap json-rpc provider error %s', str(e))
         finally:
             self._mutex.release()
    def _set_provider_configuration(self, interface, nodes):
        """
        设置provider配置
        :param interface:
        :param nodes:
        :return:
        """
        if not nodes:
            return
        try:
            configuration_dict = {}
            for _child_node in nodes:
                _node = urllib.parse.unquote(_child_node,encoding='utf-8', errors='replace')
                if _node.startswith('override'):
                    service_url = ServiceURL(_node)
                    key = self._to_key(interface, service_url.version, service_url.group)

                    if key not in configuration_dict:
                        configuration_dict[key] = {}
                    if service_url.location not in configuration_dict[key]:
                        configuration_dict[key][service_url.location] = []
                    configuration_dict[key][service_url.location].append(_node)

            if interface in self._service_providers:
                provider_dict = self._service_providers.get(interface)
                for provider_key, second_dict in provider_dict.iteritems():
                    for service_location, service_url in second_dict.iteritems():
                        configuration_service_urls = configuration_dict.get(provider_key, {}).get(service_location)
                        if not configuration_service_urls:
                            service_url.init_default_config()
                        else:
                            service_url.set_config(configuration_service_urls)

        except Exception as e:
            logger.warning('set provider configuration error %s', str(e))
Beispiel #5
0
 def _compare_swap_nodes(self, interface, nodes):
     """
     比较,替换现有内存中的节点信息,节点url类似如下
     jsonrpc://192.168.2.1:38080/com.ofpay.demo.api.UserProvider?
     anyhost=true&application=demo-provider&default.timeout=10000&dubbo=2.4.10&
     environment=product&interface=com.ofpay.demo.api.UserProvider&
     methods=getUser,queryAll,queryUser,isLimit&owner=wenwu&pid=61578&
     side=provider&timestamp=1428904600188
     首先将url转为ServiceUrl对象,然保持到缓存中
     :param nodes: 节点列表
     :return: 不需要返回
     """
     # 如果已经存在,首先删除原有的服务的集合
     if interface in self._service_provides:
         del self._service_provides[interface]
     for child_node in nodes:
         node = urllib.unquote(child_node).decode('utf8')
         if node.startswith('jsonrpc'):
             service_url = ServiceURL(node)
             self._add_node(interface, service_url)