Example #1
0
    def load(path, name):
        cluster_path = os.path.join(path, name)
        filename = os.path.join(cluster_path, 'cluster.conf')
        with open(filename, 'r') as f:
            data = yaml.load(f)
        try:
            cassandra_dir = None
            if 'cassandra_dir' in data:
                cassandra_dir = data['cassandra_dir']
                repository.validate(cassandra_dir)

            cluster = Cluster(path,
                              data['name'],
                              cassandra_dir=cassandra_dir,
                              create_directory=False)
            node_list = data['nodes']
            seed_list = data['seeds']
            if 'partitioner' in data:
                cluster.partitioner = data['partitioner']
            if 'config_options' in data:
                cluster._config_options = data['config_options']
            if 'log_level' in data:
                cluster.__log_level = data['log_level']
        except KeyError as k:
            raise common.LoadError("Error Loading " + filename +
                                   ", missing property:" + k)

        for node_name in node_list:
            cluster.nodes[node_name] = Node.load(cluster_path, node_name,
                                                 cluster)
        for seed_name in seed_list:
            cluster.seeds.append(cluster.nodes[seed_name])

        return cluster
Example #2
0
 def load(path, name, cluster):
     """
     Load a node from from the path on disk to the config files, the node name and the
     cluster the node is part of.
     """
     node_path = os.path.join(path, name)
     filename = os.path.join(node_path, 'node.conf')
     with open(filename, 'r') as f:
         data = yaml.load(f)
     try:
         itf = data['interfaces']
         initial_token = None
         if 'initial_token' in data:
             initial_token = data['initial_token']
         remote_debug_port = 2000
         if 'remote_debug_port' in data:
             remote_debug_port = data['remote_debug_port']
         binary_interface = None
         if 'binary' in itf and itf['binary'] is not None:
             binary_interface = tuple(itf['binary'])
         node = Node(data['name'], cluster, data['auto_bootstrap'], tuple(itf['thrift']), tuple(itf['storage']), data['jmx_port'], remote_debug_port, initial_token, save=False, binary_interface=binary_interface)
         node.status = data['status']
         if 'pid' in data:
             node.pid = int(data['pid'])
         if 'cassandra_dir' in data:
             node.__cassandra_dir = data['cassandra_dir']
         if 'config_options' in data:
             node.__config_options = data['config_options']
         if 'data_center' in data:
             node.data_center = data['data_center']
         return node
     except KeyError as k:
         raise common.LoadError("Error Loading " + filename + ", missing property: " + str(k))