Ejemplo n.º 1
0
def migrate_clusters(my_address, host_pool):
    """Task that migrate every needed clusters from other server to
    this new one."""
    host_index = get_host_index(my_address, host_pool)
    now = ClusterDistribution(nb_active_hosts(host_pool))
    after = ClusterDistribution(nb_active_hosts(host_pool)+1)
    needed_clusters = after.clusters_for_host(host_index)
    for cluster in needed_clusters:
        host_index = now.get_host_from_cluster(cluster)
        host_address = host_pool[host_index]['address']
        req = cluster_list_request(host_address, cluster)
        data = urllib2.urlopen(req)
        index_list = json.decode(data.read())
        for index in index_list:
            req = document_request(host_address, index)
            data = urllib2.urlopen(req)
            store_document(index, data.read())

    #todo:notify other servers
    print("Migration finished successfuly")
Ejemplo n.º 2
0
 def test_distribution(self):
     distrib = ClusterDistribution(1, nb_clusters=12)
     self.assertEqual(
         distrib.distribution,
         [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
     )
     distrib = ClusterDistribution(2, nb_clusters=12)
     self.assertEqual(
         distrib.distribution,
         [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
     )
     distrib = ClusterDistribution(3, nb_clusters=12)
     self.assertEqual(
         distrib.distribution,
         [0, 1, 2, 3, 6, 7, 8, 9, 4, 5, 10, 11]
     )
     distrib = ClusterDistribution(4, nb_clusters=12)
     self.assertEqual(
         distrib.distribution,
         [0, 1, 2, 6, 7, 8, 4, 5, 10, 3, 9, 11]
     )
     self.assertEqual(
         distrib.clusters_for_host(0),
         [0, 1, 2]
     )
     self.assertEqual(
         distrib.clusters_for_host(3),
         [3, 9, 11]
     )
     self.assertEqual(
         distrib.get_host_from_cluster(3),
         3
     )
     self.assertEqual(
         distrib.get_host_from_cluster(11),
         3
     )
     self.assertEqual(
         distrib.get_host_from_cluster(2),
         0
     )