[rhmessaging-commits] rhmessaging commits: r1613 - in mgmt: cumin/bin and 4 other directories.
rhmessaging-commits at lists.jboss.org
rhmessaging-commits at lists.jboss.org
Sat Jan 26 00:12:23 EST 2008
Author: justi9
Date: 2008-01-26 00:12:23 -0500 (Sat, 26 Jan 2008)
New Revision: 1613
Added:
mgmt/cumin/doc/
mgmt/cumin/doc/installation.txt
Modified:
mgmt/cumin-test-0/etc/cumin.conf
mgmt/cumin/bin/cumin
mgmt/cumin/bin/cumin-test
mgmt/cumin/python/cumin/__init__.py
mgmt/cumin/python/cumin/model.py
mgmt/cumin/python/cumin/util.py
mgmt/mint/python/mint/__init__.py
Log:
Overhauls the scripts for starting cumin.
* Makes debug=on the default for the cumin-test-0 instance
* Moves connection configuration into MintModel init
* Proxies the init and check methods on CuminModel to MintModel
* Introduces a Config class for reading basic config parameters from
various sources
* Rewrites cumin and cumin-test to use the new facilities
* Adds the interim installation notes to the doc dir
Modified: mgmt/cumin/bin/cumin
===================================================================
--- mgmt/cumin/bin/cumin 2008-01-25 20:26:45 UTC (rev 1612)
+++ mgmt/cumin/bin/cumin 2008-01-26 05:12:23 UTC (rev 1613)
@@ -1,97 +1,68 @@
#!/usr/bin/env python
import sys, os
+from wooly.server import WebServer
-if "CUMIN_HOME" not in os.environ:
- os.environ["CUMIN_HOME"] = "/usr/share/cumin"
+from cumin import *
+from cumin.util import *
def usage():
- print """
-Usage: cumin OPTIONS
+ print """Usage: cumin OPTIONS...
Options:
- --port PORT
- --data DATABASE-URL
-""",
+ -h, --help Print this message
+ --data URL Use database url URL
+ --port PORT Run web server on port PORT
+ --debug Enable debugging"""
+
sys.exit(1)
-from ConfigParser import SafeConfigParser
+def do_main(home, data, port, debug):
+ app = Cumin(home, data)
-def load_args(argv):
- args = dict()
+ if debug:
+ app.enable_debug()
- sconf = os.path.expandvars("${CUMIN_HOME}/etc/cumin.conf")
- hconf = os.path.expanduser("~/.cumin.conf")
+ try:
+ app.check()
+ except Exception, e:
+ if hasattr(e, "message"):
+ print e.message
- conf = SafeConfigParser()
- rconfs = conf.read((sconf, hconf))
+ sys.exit(1)
- if rconfs:
- print "Config files read:"
+ app.init()
- for name in rconfs:
- print " " + name
+ server = WebServer(app, port)
- if (conf.has_section("main")):
- for key, value in conf.items("main"):
- args[key] = value
-
- key = None
+ try:
+ server.run()
+ except KeyboardInterrupt:
+ pass
- for arg in sys.argv:
- if arg.startswith("--"):
- key = arg[2:]
- args[key] = None
- elif key:
- args[key] = arg
- key = None
+def main():
+ if "-h" in sys.argv or "--help" in sys.argv:
+ usage()
- if args:
- print "Config parameters set:"
+ if "CUMIN_HOME" not in os.environ:
+ os.environ["CUMIN_HOME"] = "/usr/share/cumin"
- for key in args:
- print " " + key + " " + args[key]
+ config = Config()
+ config.add_param("data", "s", "postgresql://cumin@localhost/cumin")
+ config.add_param("port", "i", 80)
+ config.add_param("debug", "b", False)
- return args
+ config.load_file(os.path.expandvars("${CUMIN_HOME}/etc/cumin.conf"))
+ config.load_file(os.path.expanduser("~/.cumin.conf"))
+ config.load_args(sys.argv)
-from sqlobject import *
+ config.show()
-args = load_args(sys.argv)
-
-try:
- connuri = args["data"]
- conn = connectionForURI(connuri)
- sqlhub.processConnection = conn
-except KeyError:
- print "No data source"
- usage()
-
-try:
- sqlhub.getConnection().getConnection()
-except Exception, e:
- if hasattr(e, "message") and e.message.find("does not exist"):
- print "Database not found; run cumin-database-init"
- sys.exit(1)
- else:
- print "Failed connecting to database"
- raise e
-
-from wooly.server import WebServer
-from cumin import *
-
-def do_main(port):
- app = Cumin()
- app.enable_debug()
-
- server = WebServer(app, port)
- server.run()
-
-def main():
- port = int(args.get("port", 80))
+ home = os.environ["CUMIN_HOME"]
+ data = config.get("data")
+ port = config.get("port")
+ debug = config.get("debug")
- try:
- do_main(port)
- except KeyboardInterrupt:
- pass
+ do_main(home, data, port, debug)
if __name__ == "__main__":
main()
Modified: mgmt/cumin/bin/cumin-test
===================================================================
--- mgmt/cumin/bin/cumin-test 2008-01-25 20:26:45 UTC (rev 1612)
+++ mgmt/cumin/bin/cumin-test 2008-01-26 05:12:23 UTC (rev 1613)
@@ -1,97 +1,80 @@
#!/usr/bin/env python
import sys, os
+from time import time
+from wooly.devel import BenchmarkHarness
+from cumin import *
+from cumin.demo import *
+from cumin.model import *
+
def usage():
- print """
-Usage: cumin-test OPTIONS
+ print """Usage: cumin-test OPTIONS...
Options:
- --port PORT
--data DATABASE-URL
--bench [HITS]
--profile
- --no-debug
-""",
+ --debug"""
sys.exit(1)
-from ConfigParser import SafeConfigParser
+def do_main(home, data, bench_hits, debug):
+ app = Cumin(home, data)
-def load_args(argv):
- args = dict()
+ if debug or bench_hits:
+ app.enable_debug()
- conf = SafeConfigParser()
- conf.read(os.path.expanduser("~/.cumin.conf"))
+ try:
+ app.check()
+ except Exception, e:
+ if hasattr(e, "message"):
+ print e.message
- if (conf.has_section("main")):
- for key, value in conf.items("main"):
- args[key] = value
-
- key = None
+ sys.exit(1)
- for arg in sys.argv:
- if arg.startswith("--"):
- key = arg[2:]
- args[key] = None
- elif key:
- args[key] = arg
- key = None
+ app.init()
- if args:
- print "Parameters:"
+ harness = BenchmarkHarness(app)
- for key in args:
- print " %10s %s" % (key, args[key])
+ try:
+ harness.run(bench_hits)
+ except KeyboardInterrupt:
+ pass
- return args
+def main():
+ if "-h" in sys.argv or "--help" in sys.argv:
+ usage()
-from sqlobject import *
+ if "CUMIN_HOME" not in os.environ:
+ os.environ["CUMIN_HOME"] = "/usr/share/cumin"
-args = load_args(sys.argv)
+ config = Config()
+ config.add_param("data", "s", "postgresql://cumin@localhost/cumin")
+ config.add_param("port", "i", 80)
+ config.add_param("debug", "b", True)
+ config.add_param("bench", "i", 1000)
+ config.add_param("profile", "b", False)
-try:
- connuri = args["data"]
- conn = connectionForURI(connuri)
- sqlhub.processConnection = conn
-except KeyError:
- print "No data source"
- usage()
+ config.load_file(os.path.expandvars("${CUMIN_HOME}/etc/cumin.conf"))
+ config.load_file(os.path.expanduser("~/.cumin.conf"))
+ config.load_args(sys.argv)
-from time import time
-from wooly.devel import BenchmarkHarness
-from wooly.server import WebServer
+ config.show()
-from cumin import *
-from cumin.demo import *
-from cumin.model import *
+ home = os.environ["CUMIN_HOME"]
+ data = config.get("data")
+ bench = config.get("bench")
+ profile = config.get("profile")
+ debug = config.get("debug")
-def do_main(port, bench_hits, debug=True):
- app = Cumin()
-
- if debug or bench_hits:
- app.enable_debug()
-
- if bench_hits:
- harness = BenchmarkHarness(app)
- harness.run(bench_hits)
- else:
- server = WebServer(app, port)
- server.run()
-
-def main():
- in_port = int(args.get("port", 9090))
- in_profile = "profile" in args
- in_debug = "no-debug" not in args
- in_bench = "bench" in args and int(args.get("bench", None) or 1000) or 0
-
- if in_profile:
+ if profile:
from profile import Profile
from pstats import Stats
prof = Profile()
try:
- statement = "do_main(%i, %r, %r)" % \
- (in_port, in_bench, in_debug)
+ statement = "do_main('%s', '%s', %i, %r)" \
+ % (home, data, bench, debug)
prof.run(statement)
@@ -113,10 +96,7 @@
stats.strip_dirs()
else:
- try:
- do_main(in_port, in_bench, in_debug)
- except KeyboardInterrupt:
- pass
+ do_main(home, data, bench, debug)
if __name__ == "__main__":
main()
Added: mgmt/cumin/doc/installation.txt
===================================================================
--- mgmt/cumin/doc/installation.txt (rev 0)
+++ mgmt/cumin/doc/installation.txt 2008-01-26 05:12:23 UTC (rev 1613)
@@ -0,0 +1,55 @@
+Thanks for evaluating our preview release of the MRG management web
+UI.
+
+The following instructions assume you are running as root, unless
+otherwise indicated:
+
+1. Install packages
+
+ First, use yum to install the management packages. If you haven't
+ already, you may want to install the messaging packages as well.
+
+ # yum install mrg-management
+ # yum install mrg-messaging
+
+2. Prepare the database
+
+ In order to access the database, you must change the authentication
+ method of the postgresql database.
+
+ First start the postgresql service to initialize the postgresql
+ database files.
+
+ # service postgresql start
+
+ Now, edit the following authentication config file. For each local
+ connection line, change "ident sameuser" to "trust".
+
+ # vi /var/lib/pgsql/data/pg_hba.conf
+
+ Now you can restart the database:
+
+ # service postgresql restart
+
+ Load the cumin database and schema:
+
+ # cumin-database-init
+
+3. Start a managed broker
+
+ To make your local broker manageable, edit /etc/rhmd.conf and add
+ "mgmt=yes" on its own line.
+
+4. Start cumin (cumin is the name of the web console)
+
+ As root:
+
+ # cumin
+
+ As an unprivileged user:
+
+ $ cumin --port 8080 # On an unprivileged port
+
+ In a browser, go to localhost (or localhost:8080). You should be
+ able to click "Register Brokers" and add brokers by their address
+ and port.
Modified: mgmt/cumin/python/cumin/__init__.py
===================================================================
--- mgmt/cumin/python/cumin/__init__.py 2008-01-25 20:26:45 UTC (rev 1612)
+++ mgmt/cumin/python/cumin/__init__.py 2008-01-26 05:12:23 UTC (rev 1613)
@@ -19,20 +19,14 @@
from stat import StatChartPage
class Cumin(Application):
- def __init__(self):
+ def __init__(self, home, data_url):
super(Cumin, self).__init__()
- try:
- self.home = os.environ["CUMIN_HOME"]
- except KeyError:
- sys.exit(1)
-
+ self.home = home
self.add_resource_dir(os.path.join(self.home, "resources"))
- self.model = CuminModel()
-
+ self.model = CuminModel(data_url)
self.broker_connect_thread = BrokerConnectThread(self.model)
- self.broker_connect_thread.start()
self.cumin_page = CuminPage(self, "cumin.html")
self.set_default_page(self.cumin_page)
@@ -46,8 +40,20 @@
self.add_page(ClientXmlPage(self, "client.xml"))
self.add_page(StatChartPage(self, "stats.png"))
+ def check(self):
+ if not os.path.isdir(self.home):
+ raise Exception \
+ ("Error: cumin home '%s' not found or not a directory" \
+ % self.home)
+
+ self.model.check()
+
+ def init(self):
+ self.model.init()
+ self.broker_connect_thread.start()
+
class CuminServer(WebServer):
- def __init__(self, port=9090):
+ def __init__(self, port):
model = DummyModel()
app = Cumin(model)
Modified: mgmt/cumin/python/cumin/model.py
===================================================================
--- mgmt/cumin/python/cumin/model.py 2008-01-25 20:26:45 UTC (rev 1612)
+++ mgmt/cumin/python/cumin/model.py 2008-01-26 05:12:23 UTC (rev 1613)
@@ -7,8 +7,8 @@
from formats import *
class CuminModel(object):
- def __init__(self):
- self.data = MintModel()
+ def __init__(self, data_url):
+ self.data = MintModel(data_url)
self.classes = list()
@@ -17,6 +17,12 @@
self.binding = CuminBinding(self)
self.client = CuminClient(self)
self.session = CuminSession(self)
+
+ def check(self):
+ self.data.check()
+
+ def init(self):
+ self.data.init()
def add_class(self, cls):
self.classes.append(cls)
Modified: mgmt/cumin/python/cumin/util.py
===================================================================
--- mgmt/cumin/python/cumin/util.py 2008-01-25 20:26:45 UTC (rev 1612)
+++ mgmt/cumin/python/cumin/util.py 2008-01-26 05:12:23 UTC (rev 1613)
@@ -1,4 +1,5 @@
from time import mktime
+from ConfigParser import SafeConfigParser
def sorted_by(seq, attr="name"):
return sorted(seq, cmp, lambda x: getattr(x, attr))
@@ -25,3 +26,109 @@
class Identifiable(object):
def __init__(self, id=None):
self.id = id
+
+class Config(object):
+ def __init__(self):
+ self.__params = list()
+ self.__param_specs = dict() # param name => (type, default)
+ self.__values = dict()
+
+ self.verbose = True
+
+ def add_param(self, name, type, default):
+ self.__params.append(name)
+ self.__param_specs[name] = (type, default)
+
+ def set(self, name, value):
+ self.__values[name] = value
+ return value
+
+ def unmarshal(self, name, string):
+ type, default = self.__param_specs[name]
+
+ if type == "i":
+ value = int(string)
+ elif type == "b":
+ value = bool(string)
+ elif type == "s":
+ value = string
+ else:
+ raise Error("Invalid type '%s'" % type)
+
+ return value
+
+ def get(self, name):
+ if name not in self.__params:
+ raise Error("Parameter '%s' not found" % name)
+
+ type, default = self.__param_specs[name]
+
+ if name in self.__values:
+ value = self.__values.get(name)
+ else:
+ value = default
+
+ return value
+
+ def load_file(self, file):
+ print "Looking for config file '%s':" % file,
+
+ conf = SafeConfigParser()
+ found = conf.read(file)
+
+ if found:
+ print "found"
+ else:
+ print "not found"
+
+ params = dict()
+
+ if (conf.has_section("main")):
+ for key, value in conf.items("main"):
+ params[key] = value
+
+ self.load_string_params(params)
+
+ def load_args(self, argv):
+ params = dict()
+ key = None
+
+ for arg in argv:
+ if arg.startswith("--"):
+ key = arg[2:]
+ params[key] = None
+ elif key:
+ params[key] = arg
+ key = None
+
+ self.load_string_params(params)
+
+ def load_string_params(self, params):
+ for name, value in params.items():
+ if name in self.__params:
+ self.set(name, self.unmarshal(name, value))
+ else:
+ print "Warning: ignoring unrecognized parameter '%s'" % name
+
+ def require(self, params):
+ missing = list()
+
+ for param in params:
+ if param not in self.__values:
+ missing.append(param)
+
+ return missing
+
+ def show(self):
+ print "Configuration:"
+
+ for param in self.__params:
+ type, default = self.__param_specs[param]
+ value = self.get(param)
+
+ if param in self.__values:
+ flag = ""
+ else:
+ flag = " [default]"
+
+ print " %s = %s%s" % (param, value, flag)
Modified: mgmt/cumin-test-0/etc/cumin.conf
===================================================================
--- mgmt/cumin-test-0/etc/cumin.conf 2008-01-25 20:26:45 UTC (rev 1612)
+++ mgmt/cumin-test-0/etc/cumin.conf 2008-01-26 05:12:23 UTC (rev 1613)
@@ -1,3 +1,3 @@
[main]
-data: postgresql://cumin@localhost/cumin
port: 9090
+debug: True
Modified: mgmt/mint/python/mint/__init__.py
===================================================================
--- mgmt/mint/python/mint/__init__.py 2008-01-25 20:26:45 UTC (rev 1612)
+++ mgmt/mint/python/mint/__init__.py 2008-01-26 05:12:23 UTC (rev 1613)
@@ -119,13 +119,27 @@
class MintModel:
- def __init__(self, debug=False):
+ def __init__(self, data_url, debug=False):
+ self.data_url = data_url
self.currentMethodId = 1
self.outstandingMethodCalls = dict()
self.connectedBrokers = dict()
self.debug = debug
self.lock = Lock()
+ def check(self):
+ try:
+ connectionForURI(self.data_url)
+ except Exception, e:
+ if hasattr(e, "message") and e.message.find("does not exist"):
+ print "Database not found; run cumin-database-init"
+
+ raise e
+
+ def init(self):
+ conn = connectionForURI(self.data_url)
+ sqlhub.processConnection = conn
+
def setDebug(self, debug=True):
self.debug = debug
More information about the rhmessaging-commits
mailing list