Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: dca3d49cc2
Fetching contributors…

Cannot retrieve contributors at this time

150 lines (122 sloc) 5.969 kb
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'))
from command import Cmd
import common
from node import Node, NodeError
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)
Jump to Line
Something went wrong with that request. Please try again.