Permalink
Browse files

Fix a bunch of bugs and add some comments

  • Loading branch information...
1 parent 018110a commit 2e76e05505a44c321a142fc7125158f9eb057306 @pcmanus committed Oct 21, 2011
Showing with 175 additions and 48 deletions.
  1. +31 −11 ccmlib/cluster.py
  2. +8 −8 ccmlib/cmds/node_cmds.py
  3. +136 −29 ccmlib/node.py
View
@@ -1,6 +1,6 @@
# ccm clusters
-import common, yaml, os, subprocess, shutil, repository, time
+import common, yaml, os, subprocess, shutil, repository, time, re
from node import Node, NodeError
class Cluster():
@@ -18,7 +18,11 @@ def __init__(self, path, name, partitioner=None, cassandra_dir=None, create_dire
try:
if cassandra_version is None:
- self.__cassandra_dir = cassandra_dir
+ # at this point, cassandra_dir should always not be None, but
+ # we keep this for backward compatibility (in loading old cluster)
+ if cassandra_dir is not None:
+ self.__cassandra_dir = os.path.abspath(cassandra_dir)
+ self.__version = self.__get_version_from_build()
else:
self.__cassandra_dir = repository.setup(cassandra_version, verbose)
self.__version = cassandra_version
@@ -27,7 +31,8 @@ def __init__(self, path, name, partitioner=None, cassandra_dir=None, create_dire
common.validate_cassandra_dir(self.__cassandra_dir)
self.__update_config()
except:
- shutil.rmtree(self.get_path())
+ if create_directory:
+ shutil.rmtree(self.get_path())
raise
def set_partitioner(self, partitioner):
@@ -39,8 +44,10 @@ def set_cassandra_dir(self, cassandra_dir=None, cassandra_version=None, verbose=
if cassandra_version is None:
self.__cassandra_dir = cassandra_dir
common.validate_cassandra_dir(cassandra_dir)
+ self.__version = self.__get_version_from_build()
else:
self.__cassandra_dir = repository.setup(cassandra_version, verbose=verbose)
+ self.__version = cassandra_version
self.__update_config()
for node in self.nodes.values():
node.import_config_files()
@@ -54,8 +61,6 @@ def nodelist(self):
return [ self.nodes[name] for name in sorted(self.nodes.keys()) ]
def version(self):
- if self.__version is None:
- raise common.CCMError("Version is not set")
return self.__version
@staticmethod
@@ -65,14 +70,16 @@ def load(path, name):
with open(filename, 'r') as f:
data = yaml.load(f)
try:
- cluster = Cluster(path, data['name'], create_directory=False)
+ 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 'cassandra_dir' in data:
- cluster.__cassandra_dir = data['cassandra_dir']
- repository.validate(cluster.__cassandra_dir)
if 'config_options' in data:
cluster._config_options = data['config_options']
except KeyError as k:
@@ -92,6 +99,7 @@ def add(self, node, is_seed):
if is_seed:
self.seeds.append(node)
self.__update_config()
+ node._save()
return self
def populate(self, node_count, tokens=None):
@@ -189,7 +197,9 @@ def start(self, no_wait=False, verbose=False):
if not node.is_running():
raise NodeError("Error starting {0}.".format(node.name), p)
- if not no_wait:
+ if not no_wait and self.version() >= "0.8":
+ # 0.7 gossip messages seems less predictible that from 0.8 onwards and
+ # I don't care enough
for node, mark in marks:
for other_node, _ in marks:
if other_node is not node:
@@ -258,6 +268,16 @@ def decommission(self):
def removeToken(self, token):
self.nodetool("removeToken " + str(token))
+ def __get_version_from_build(self):
+ cassandra_dir = self.get_cassandra_dir()
+ build = os.path.join(cassandra_dir, 'build.xml')
+ with open(build) as f:
+ for line in f:
+ match = re.search('name="base\.version" value="([0-9.]+)[^"]*"', line)
+ if match:
+ return match.group(1)
+ raise common.CCMError("Cannot find version")
+
def __update_config(self):
node_list = [ node.name for node in self.nodes.values() ]
seed_list = [ node.name for node in self.seeds ]
@@ -274,5 +294,5 @@ def __update_config(self):
def __update_pids(self, started):
for node, p in started:
- node.update_pid(p)
+ node._update_pid(p)
View
@@ -242,9 +242,9 @@ def description(self):
def get_parser(self):
usage = "usage: ccm node_name json [options] [file]"
parser = self._get_default_parser(usage, self.description())
- parser.add_option('-k', '--keyspace', type="string", dest="keyspace",
+ parser.add_option('-k', '--keyspace', type="string", dest="keyspace", default=None,
help="The keyspace to use [use all keyspaces by default]")
- parser.add_option('-c', '--column-families', type="string", dest="cfs",
+ parser.add_option('-c', '--column-families', type="string", dest="cfs", default=None,
help="Comma separated list of column families to use (requires -k to be set)")
parser.add_option('-e', '--enumerate-keys', action="store_true", dest="enumerate_keys",
help="Only enumerate keys (i.e, call sstable2keys)", default=False)
@@ -254,14 +254,14 @@ def validate(self, parser, options, args):
Cmd.validate(self, parser, options, args, node_name=True, load_cluster=True)
self.keyspace = options.keyspace
self.column_families = None
- if len(args) > 0:
- self.datafile = args[0]
- if not self.keyspace:
+ self.datafile = None
+ if len(args) > 1:
+ self.datafile = args[1]
+ if self.keyspace is None:
print >> sys.stderr, "You need a keyspace specified (option -k) if you specify a file"
exit(1)
- elif options.cfs:
- self.datafile = None
- if not self.keyspace:
+ elif options.cfs is not None:
+ if self.keyspace is None:
print >> sys.stderr, "You need a keyspace specified (option -k) if you specify column families"
exit(1)
self.column_families = options.cfs.split(',')
Oops, something went wrong.

0 comments on commit 2e76e05

Please sign in to comment.