Permalink
Browse files

Reorganize project and imports and add distutils support

  • Loading branch information...
1 parent dca3d49 commit 26d40775927054d6722ddd5f3171b8e5b44721f1 @pcmanus committed Sep 29, 2011
View
18 ccm
@@ -2,19 +2,13 @@
import os, sys
-L = os.path.realpath(__file__).split(os.path.sep)[:-1]
-root = os.path.sep.join(L)
-sys.path.append(os.path.join(root, 'cmds'))
-import command, common
-from cluster_cmds import *
-from cluster_cass_cmds import *
-from node_cmds import *
-from node_cass_cmds import *
+from ccmlib import common
+from ccmlib.cmds import command, cluster_cmds, node_cmds
def get_command(kind, cmd):
cmd_name = kind.lower().capitalize() + cmd.lower().capitalize() + "Cmd"
try:
- klass = globals()[cmd_name]
+ klass = (cluster_cmds if kind.lower() == 'cluster' else node_cmds).__dict__[cmd_name]
except KeyError:
return None
if not issubclass(klass, command.Cmd):
@@ -27,14 +21,14 @@ def print_global_usage():
print " ccm <node_name> <node_cmd> [options]"
print ""
print "Where <cluster_cmd> is one of"
- for cmd_name in cluster_cmds():
+ for cmd_name in cluster_cmds.cluster_cmds():
cmd = get_command("cluster", cmd_name)
if not cmd:
print "Internal error, unknown command {0}".format(cmd_name)
exit(1)
print " {0:14} {1}".format(cmd_name, cmd.description())
print "or <node_name> is the name of a node of the current cluster and <node_cmd> is one of"
- for cmd_name in node_cmds():
+ for cmd_name in node_cmds.node_cmds():
cmd = get_command("node", cmd_name)
if not cmd:
print "Internal error, unknown command {0}".format(cmd_name)
@@ -48,7 +42,7 @@ if len(sys.argv) <= 1:
arg1 = sys.argv[1].lower()
-if arg1 in cluster_cmds():
+if arg1 in cluster_cmds.cluster_cmds():
kind = 'cluster'
cmd = arg1
cmd_args = sys.argv[2:]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,12 +1,9 @@
import os, sys, shutil
-
-L = os.path.realpath(__file__).split(os.path.sep)[:-2]
-root = os.path.sep.join(L)
-sys.path.append(os.path.join(root, 'ccm_lib'))
from command import Cmd
-from node import Node
-from cluster import Cluster
-import common, repository
+
+from ccmlib import common, repository
+from ccmlib.node import Node, NodeError
+from ccmlib.cluster import Cluster
def cluster_cmds():
return [
@@ -274,3 +271,144 @@ def validate(self, parser, options, args):
def run(self):
repository.clean_all()
+
+class ClusterStartCmd(Cmd):
+ def description(self):
+ return "Start all the non started nodes of the current cluster"
+
+ def get_parser(self):
+ usage = "usage: ccm cluter start [options]"
+ parser = self._get_default_parser(usage, self.description())
+ parser.add_option('-v', '--verbose', action="store_true", dest="verbose",
+ help="Print standard output of cassandra process", default=False)
+ parser.add_option('--no-wait', action="store_true", dest="no_wait",
+ help="Do not wait for cassandra node to be ready", default=False)
+ return parser
+
+ def validate(self, parser, options, args):
+ Cmd.validate(self, parser, options, args, load_cluster=True)
+
+ def run(self):
+ try:
+ self.cluster.start(no_wait=self.options.no_wait,
+ verbose=self.options.verbose)
+ except NodeError as e:
+ print >> sys.stderr, str(e)
+ print >> sys.stderr, "Standard error output is:"
+ for line in e.process.stderr:
+ print >> sys.stderr, line.rstrip('\n')
+ exit(1)
+
+class ClusterStopCmd(Cmd):
+ def description(self):
+ return "Stop all the nodes of the cluster"
+
+ def get_parser(self):
+ usage = "usage: ccm cluster stop [options] name"
+ parser = self._get_default_parser(usage, self.description())
+ parser.add_option('-v', '--verbose', action="store_true", dest="verbose",
+ help="Print nodes that were not running", default=False)
+ parser.add_option('--no-wait', action="store_true", dest="no_wait",
+ help="Do not wait for the node to be stopped", default=False)
+ return parser
+
+ def validate(self, parser, options, args):
+ Cmd.validate(self, parser, options, args, load_cluster=True)
+
+ def run(self):
+ try:
+ not_running = self.cluster.stop(not self.options.no_wait)
+ if self.options.verbose and len(not_running) > 0:
+ sys.out.write("The following nodes were not running: ")
+ for node in not_running:
+ sys.out.write(node.name + " ")
+ print ""
+ except NodeError as e:
+ print >> sys.stderr, str(e)
+ exit(1)
+
+class _ClusterNodetoolCmd(Cmd):
+ def get_parser(self):
+ parser = self._get_default_parser(self.usage, self.description())
+ return parser
+
+ def description(self):
+ return self.descr_text
+
+ def validate(self, parser, options, args):
+ Cmd.validate(self, parser, options, args, load_cluster=True)
+
+ def run(self):
+ self.cluster.nodetool(self.nodetool_cmd)
+
+class ClusterFlushCmd(_ClusterNodetoolCmd):
+ usage = "usage: ccm cluster flush [options] name"
+ nodetool_cmd = 'flush'
+ descr_text = "Flush all (running) nodes of the cluster"
+
+class ClusterCompactCmd(_ClusterNodetoolCmd):
+ usage = "usage: ccm cluster compact [options] name"
+ nodetool_cmd = 'compact'
+ descr_text = "Compact all (running) node of the cluster"
+
+class ClusterStressCmd(Cmd):
+ def description(self):
+ return "Run stress using all live nodes"
+
+ def get_parser(self):
+ usage = "usage: ccm stress [options] [stress_options]"
+ parser = self._get_default_parser(usage, self.description(), ignore_unknown_options=True)
+ return parser
+
+ def validate(self, parser, options, args):
+ Cmd.validate(self, parser, options, args, load_cluster=True)
+ self.stress_options = parser.get_ignored() + args
+
+ def run(self):
+ try:
+ self.cluster.stress(self.stress_options)
+ except Exception as e:
+ print >> sys.stderr, e
+
+class ClusterUpdateconfCmd(Cmd):
+ def description(self):
+ return "Update the cassandra config files for all nodes"
+
+ def get_parser(self):
+ usage = "usage: ccm updateconf [options]"
+ parser = self._get_default_parser(usage, self.description())
+ parser.add_option('--no-hh', '--no-hinted-handoff', action="store_false",
+ dest="hinted_handoff", default=True, help="Disable hinted handoff")
+ parser.add_option('--batch-cl', '--batch-commit-log', action="store_true",
+ dest="cl_batch", default=True, help="Set commit log to batch mode")
+ parser.add_option('--rt', '--rpc-timeout', action="store", type='int',
+ dest="rpc_timeout", help="Set rpc timeout")
+ return parser
+
+ def validate(self, parser, options, args):
+ Cmd.validate(self, parser, options, args, load_cluster=True)
+
+ def run(self):
+ self.cluster.update_configuration(hh=self.options.hinted_handoff,
+ cl_batch=self.options.cl_batch,
+ rpc_timeout=self.options.rpc_timeout)
+
+class ClusterCliCmd(Cmd):
+ def description(self):
+ return "Launch cassandra cli connected to some live node (if any)"
+
+ def get_parser(self):
+ usage = "usage: ccm cli [options] [cli_options]"
+ parser = self._get_default_parser(usage, self.description(), ignore_unknown_options=True)
+ parser.add_option('-x', '--exec', type="string", dest="cmds", default=None,
+ help="Execute the specified commands and exit")
+ parser.add_option('-v', '--verbose', action="store_true", dest="verbose",
+ help="With --exec, show cli output after completion", default=False)
+ return parser
+
+ def validate(self, parser, options, args):
+ Cmd.validate(self, parser, options, args, load_cluster=True)
+ self.cli_options = parser.get_ignored() + args[1:]
+
+ def run(self):
+ self.cluster.run_cli(self.options.cmds, self.options.verbose, self.cli_options)
@@ -1,11 +1,7 @@
-from optparse import OptionParser, BadOptionError, Option
import os, sys, shutil
+from optparse import OptionParser, BadOptionError, Option
-L = os.path.realpath(__file__).split(os.path.sep)[:-2]
-root = os.path.sep.join(L)
-sys.path.append(os.path.join(root, 'ccm_lib'))
-import common
-
+from ccmlib import common
# This is fairly fragile, but handy for now
class ForgivingParser(OptionParser):
@@ -1,11 +1,109 @@
-import os, sys, time
-
-L = os.path.realpath(__file__).split(os.path.sep)[:-2]
-root = os.path.sep.join(L)
-sys.path.append(os.path.join(root, 'ccm_lib'))
+import os, sys, shutil, subprocess
from command import Cmd
-import common
-from node import Node, NodeError
+
+from ccmlib import common
+from ccmlib.node import Node
+
+def node_cmds():
+ return [
+ "show",
+ "remove",
+ "showlog",
+ "setlog",
+ "start",
+ "stop",
+ "ring",
+ "flush",
+ "compact",
+ "cleanup",
+ "repair",
+ "scrub",
+ "decommission",
+ "json",
+ "updateconf",
+ "stress",
+ "cli",
+ ]
+
+class NodeShowCmd(Cmd):
+ def description(self):
+ return "Display information on a node"
+
+ def get_parser(self):
+ usage = "usage: ccm node_name show [options]"
+ return self._get_default_parser(usage, self.description())
+
+ def validate(self, parser, options, args):
+ Cmd.validate(self, parser, options, args, node_name=True, load_cluster=True)
+
+ def run(self):
+ self.node.show()
+
+class NodeRemoveCmd(Cmd):
+ def description(self):
+ return "Remove a node (stopping it if necessary and deleting all its data)"
+
+ def get_parser(self):
+ usage = "usage: ccm node_name remove [options]"
+ return self._get_default_parser(usage, self.description())
+
+ def validate(self, parser, options, args):
+ Cmd.validate(self, parser, options, args, node_name=True, load_cluster=True)
+
+ def run(self):
+ self.cluster.remove(self.node)
+
+class NodeShowlogCmd(Cmd):
+ def description(self):
+ return "Show the log of node name (runs your $PAGER on its system.log)"
+
+ def get_parser(self):
+ usage = "usage: ccm node_name showlog [options]"
+ return self._get_default_parser(usage, self.description())
+
+ def validate(self, parser, options, args):
+ Cmd.validate(self, parser, options, args, node_name=True, load_cluster=True)
+
+ def run(self):
+ log = self.node.logfilename()
+ pager = os.environ.get('PAGER', 'less')
+ os.execvp(pager, (pager, log))
+
+class NodeSetlogCmd(Cmd):
+ def description(self):
+ return "Set node name log level (INFO, DEBUG, ...) - require a node restart"
+
+ def get_parser(self):
+ usage = "usage: ccm node_name setlog [options] level"
+ return self._get_default_parser(usage, self.description())
+
+ def validate(self, parser, options, args):
+ Cmd.validate(self, parser, options, args, node_name=True, load_cluster=True)
+
+ def run(self):
+ try:
+ self.node.set_log_level(self.level)
+ except common.ArgumentError as e:
+ print >> syst.stderr, str(e)
+ exit(1)
+
+class NodeClearCmd(Cmd):
+ def description(self):
+ return "Clear the node data & logs (and stop the node)"
+
+ def get_parser(self):
+ usage = "usage: ccm node_name_clear [options]"
+ parser = self._get_default_parser(usage, self.description())
+ parser.add_option('-a', '--all', action="store_true", dest="all",
+ help="Also clear the saved cache and node log files", default=False)
+ return parser
+
+ def validate(self, parser, options, args):
+ Cmd.validate(self, parser, options, args, node_name=True, load_cluster=True)
+
+ def run(self):
+ self.node.stop()
+ self.node.clear(self.options.all)
class NodeStartCmd(Cmd):
def description(self):
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
No changes.
Oops, something went wrong.

0 comments on commit 26d4077

Please sign in to comment.