Ejemplo n.º 1
0
    def _check_request(self, application_name, intent_map):
        if application_name in settings.LEGACY_APPLICATION_LIST:
            return

        im = InstanceManagement(
            self.huskar_client, application_name, SERVICE_SUBDOMAIN)
        im.set_context(self.from_application_name, self.from_cluster_name)
        for intent, icluster_names in intent_map.iteritems():
            if not icluster_names:   # pragma: no cover  # TODO: fix
                continue
            dest_cluster_blacklist = settings.ROUTE_DEST_CLUSTER_BLACKLIST.get(
                application_name, [])
            if self.hijack_mode is self.Mode.checking:
                if icluster_names & set(dest_cluster_blacklist):
                    continue

            if len(icluster_names) > 1:
                logger.info(
                    '[%s]Unstable: %s %s -> %s %s', self.hijack_mode.value,
                    self.from_application_name, self.from_cluster_name,
                    application_name, intent_map)
                capture_message(
                    '[%s]RouteHijack unstable' % self.hijack_mode.value,
                    extra={
                        'from_application_name': (
                            self.from_application_name),
                        'from_cluster_name': self.from_cluster_name,
                        'application_name': application_name,
                        'intent_map': repr(intent_map),
                        'intent': intent,
                    })
                continue

            resolved_name = im.resolve_cluster_name(intent)
            cluster_name = list(icluster_names)[0]
            cluster_name = (
                im.resolve_cluster_name(cluster_name) or cluster_name)
            if resolved_name != cluster_name:
                logger.info(
                    '[%s]Mismatch: %s %s -> %s %s %s %s',
                    self.hijack_mode.value, self.from_application_name,
                    self.from_cluster_name, application_name, intent_map,
                    resolved_name, cluster_name)
                if self.hijack_mode is self.Mode.checking:
                    capture_message(
                        '[%s]RouteHijack mismatch' % self.hijack_mode.value,
                        extra={
                            'from_application_name': (
                                self.from_application_name),
                            'from_cluster_name': self.from_cluster_name,
                            'application_name': application_name,
                            'cluster_name': cluster_name,
                            'intent_map': repr(intent_map),
                            'intent': intent,
                            'resolved_name': resolved_name,
                        })
                self.analyse_mismatch(application_name, cluster_name,
                                      resolved_name, intent, intent_map)
Ejemplo n.º 2
0
    def set_link(cls, application_name, cluster_name, link):
        im = InstanceManagement(huskar_client, application_name,
                                SERVICE_SUBDOMAIN)

        if not im.list_instance_keys(link, resolve=False):
            raise ServiceLinkError('the target cluster is empty.')

        present_link_generator = (im.resolve_cluster_name(c) == cluster_name
                                  for c in im.list_cluster_names())
        if any(present_link_generator):
            raise ServiceLinkError(('{} has been linked, cluster can only be '
                                    'linked once').format(cluster_name))

        if im.resolve_cluster_name(link):
            raise ServiceLinkError(
                ('there is a link under {}, cluster can only be '
                 'linked once').format(link))

        if not cls._set_link(application_name, cluster_name, link):
            raise ServiceLinkExisted('{} is already linked to {}'.format(
                cluster_name, link))