Exemple #1
0
 def get_node_for_alias(self, addr, port):
     try:
         if self.is_present_as_alias(addr, port):
             return self.nodes[self.aliases[Node.create_key(addr, port)]]
     except Exception:
         pass
     return None
Exemple #2
0
    def test_update_aliases(self):
        cl = self.get_cluster_mock(3)
        aliases = {}
        endpoints = [('127.0.0.1', 3000)]
        key1 = Node.create_key('127.0.0.2', 3000)
        cl.update_aliases(aliases, endpoints, key1)
        expected = {'127.0.0.1:3000': '127.0.0.2:3000'}
        self.assertEqual(aliases, expected, "update_aliases did not return the expected result")

        key2 = Node.create_key('127.0.0.3', 3000)
        cl.update_aliases(aliases, endpoints, key2)
        self.assertEqual(aliases, expected, "update_aliases did not return the expected result")

        n = cl.nodes[key1]
        n.alive = False
        cl.nodes[key1] = n
        cl.update_aliases(aliases, endpoints, key2)
        expected = {'127.0.0.1:3000': '127.0.0.3:3000'}
        self.assertEqual(aliases, expected, "update_aliases did not return the expected result")
Exemple #3
0
 def update_aliases(self, aliases, endpoints, key):
     for e in endpoints:
         try:
             addr = e[0]
             port = e[1]
             node_key = Node.create_key(addr, port)
             if len(aliases) == 0 or not node_key in aliases:
                 # same node's service addresses not added already
                 aliases[node_key] = key
             else:
                 # same node's service addresses added already
                 # Ex. NIC down IP available in service list
                 # Avoid creation of two nodes
                 aliases_node_key = aliases[node_key]
                 if aliases_node_key != key:
                     node = self.nodes[aliases_node_key]
                     if not node.alive:
                         aliases[node_key] = key
         except Exception:
             pass
Exemple #4
0
    def get_down_nodes(self):
        cluster_down_nodes = []
        for k in self.nodes.keys():
            try:
                node = self.nodes[k]
                if not node.alive:
                    # in case of using alumni services, we might have offline
                    # nodes which can't detect online nodes
                    continue
                alumni_peers = util.flatten(node.get_alumni_peers())
                peers = util.flatten(node.get_peers())
                not_visible = set(alumni_peers) - set(peers)
                if len(not_visible) >= 1:
                    for n in not_visible:
                        _key = Node.create_key(n[0], n[1])
                        if _key not in cluster_down_nodes:
                            cluster_down_nodes.append(_key)
            except Exception:
                pass

        return cluster_down_nodes
Exemple #5
0
 def is_present_as_alias(self, addr, port, aliases=None):
     if not aliases:
         aliases = self.aliases
     return Node.create_key(addr, port) in aliases