r4475 - in branches/1.3.2/cumin: bin etc python/cumin
by tmckay@fedoraproject.org
Author: tmckay
Date: 2011-01-18 20:59:25 +0000 (Tue, 18 Jan 2011)
New Revision: 4475
Added:
branches/1.3.2/cumin/bin/cumin
Removed:
branches/1.3.2/cumin/bin/cumin
Modified:
branches/1.3.2/cumin/bin/cumin-admin
branches/1.3.2/cumin/bin/cumin-bench
branches/1.3.2/cumin/bin/cumin-data
branches/1.3.2/cumin/bin/cumin-smoke-test
branches/1.3.2/cumin/bin/cumin-web
branches/1.3.2/cumin/etc/sysvinit-cumin
branches/1.3.2/cumin/python/cumin/config.py
Log:
Merge in configuration changes from multiples branch.
Revisions 4467 through 4474
Deleted: branches/1.3.2/cumin/bin/cumin
===================================================================
--- branches/1.3.2/cumin/bin/cumin 2011-01-18 20:51:52 UTC (rev 4474)
+++ branches/1.3.2/cumin/bin/cumin 2011-01-18 20:59:25 UTC (rev 4475)
@@ -1,32 +0,0 @@
-#!/bin/bash
-
-function die {
- kill "$data" "$web"
-}
-
-trap die EXIT
-
-function start_data {
- cumin-data &
- data="$!"
-}
-
-function start_web {
- cumin-web &
- web="$!"
-}
-
-start_data
-start_web
-
-while [ 0 ]; do
- sleep 30
-
- if [ ! -d "/proc/$data" ]; then
- start_data
- fi
-
- if [ ! -d "/proc/$web" ]; then
- start_web
- fi
-done
Copied: branches/1.3.2/cumin/bin/cumin (from rev 4474, branches/multiples/cumin/bin/cumin)
===================================================================
--- branches/1.3.2/cumin/bin/cumin (rev 0)
+++ branches/1.3.2/cumin/bin/cumin 2011-01-18 20:59:25 UTC (rev 4475)
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+
+from optparse import OptionParser
+from time import sleep
+import subprocess
+import os
+import sys
+import signal
+
+def call_sys_exit(sig,frame):
+ sys.exit()
+
+def set_exit_handler(func):
+ if os.name == "nt":
+ try:
+ import win32api
+ win32api.SetConsoleCtrlHandler(func, True)
+ except ImportError:
+ version = ".".join(map(str, sys.version_info[:2]))
+ raise Exception("pywin32 not installed for Python " + version)
+ else:
+ signal.signal(signal.SIGTERM, func)
+
+def main():
+
+ # tuple indices, for clarity
+ PROCESS = 0
+ SECTION = 1
+ PROGRAM = 2
+
+ parser = OptionParser()
+
+ parser.add_option("--webs", dest="webs", default="web",
+ help="Configuration section names for cumin-web instances."\
+ "\nEach value implies a separate cumin-web instance.")
+
+ parser.add_option("--datas", dest="datas", default="data",
+ help="Configuration section names for cumin-data instances."\
+ "\nEach value implies a separate cumin-data instance.")
+
+ (options, args) = parser.parse_args()
+
+ # Get our list cumin-web and data instances
+ # create list elements to hold the process object, section arg, and app
+ apps = []
+ for app in options.webs.split(','):
+ apps.append([None, app, "cumin-web"])
+
+ for app in options.datas.split(','):
+ apps.append([None, app, "cumin-data"])
+
+ # Launch and babysit
+ try:
+ while True:
+ for app in apps:
+ if not app[PROCESS] or app[PROCESS].poll():
+ arg = "--section=" + app[SECTION]
+ app[PROCESS] = subprocess.Popen([app[PROGRAM], arg])
+ sleep(30)
+
+ finally:
+ for app in apps:
+ if app[PROCESS]:
+ os.kill(app[PROCESS].pid, signal.SIGTERM)
+
+if __name__ == "__main__":
+ # This is necessary so that on a SIGTERM we can call sys.exit()
+ # and cause the finally block to be executed. Ctrl-C will
+ # run the finally block anyway.
+ set_exit_handler(call_sys_exit)
+ try:
+ main()
+ except KeyboardInterrupt:
+ pass
Modified: branches/1.3.2/cumin/bin/cumin-admin
===================================================================
--- branches/1.3.2/cumin/bin/cumin-admin 2011-01-18 20:51:52 UTC (rev 4474)
+++ branches/1.3.2/cumin/bin/cumin-admin 2011-01-18 20:59:25 UTC (rev 4475)
@@ -24,14 +24,10 @@
if uid == 0:
os.setuid(file_uid)
- config = CuminConfig()
- values = config.parse()
-
- parser = CuminOptionParser(values.data)
+ parser = CuminDataOptionParser()
parser.set_usage(generate_usage())
+ config, values, opts, args = get_configuration(parser, CuminDataConfig)
- opts, args = parser.parse_args()
-
try:
name = args[0]
except IndexError:
@@ -50,7 +46,7 @@
broker_uris = [x.strip() for x in opts.brokers.split(",")]
- app = Cumin(config.home, broker_uris, opts.database)
+ app = Cumin(config.get_home(), broker_uris, opts.database)
app.check()
app.init()
Modified: branches/1.3.2/cumin/bin/cumin-bench
===================================================================
--- branches/1.3.2/cumin/bin/cumin-bench 2011-01-18 20:51:52 UTC (rev 4474)
+++ branches/1.3.2/cumin/bin/cumin-bench 2011-01-18 20:59:25 UTC (rev 4475)
@@ -8,22 +8,17 @@
from cumin.config import *
def do_main():
- config = CuminConfig()
- values = config.parse()
+ config, values, opts, args = get_configuration(CuminWebOptionParser(), CuminWebConfig)
- parser = CuminOptionParser(values.web)
-
- opts, args = parser.parse_args()
-
setup_logging(opts)
broker_uris = [x.strip() for x in opts.brokers.split(",")]
- cumin = Cumin(config.home, broker_uris, opts.database)
+ cumin = Cumin(config.get_home(), broker_uris, opts.database)
cumin.debug = True
- cumin.user = values.web.user
- cumin.update_interval = values.web.update_interval
+ cumin.user = values.user
+ cumin.update_interval = values.update_interval
cumin.check()
cumin.init()
Modified: branches/1.3.2/cumin/bin/cumin-data
===================================================================
--- branches/1.3.2/cumin/bin/cumin-data 2011-01-18 20:51:52 UTC (rev 4474)
+++ branches/1.3.2/cumin/bin/cumin-data 2011-01-18 20:59:25 UTC (rev 4475)
@@ -11,15 +11,8 @@
from mint import *
def main():
- config = CuminConfig()
- values = config.parse().data
+ config, values, opts, args = get_configuration(CuminDataOptionParser(), CuminDataConfig)
- parser = CuminOptionParser(values)
- parser.add_option("--print-stats", action="store_true")
- parser.add_option("--print-events", type="int", default=0, metavar="LEVEL")
-
- opts, args = parser.parse_args()
-
setup_logging(opts)
model_dir = os.path.join(config.home, "model")
Modified: branches/1.3.2/cumin/bin/cumin-smoke-test
===================================================================
--- branches/1.3.2/cumin/bin/cumin-smoke-test 2011-01-18 20:51:52 UTC (rev 4474)
+++ branches/1.3.2/cumin/bin/cumin-smoke-test 2011-01-18 20:59:25 UTC (rev 4475)
@@ -13,22 +13,16 @@
from cumin.util import *
def main():
- config = CuminConfig()
- values = config.parse()
+ config, values, opts, args = get_configuration(CuminWebOptionParser(), CuminWebConfig)
- parser = CuminOptionParser(values.web)
-
- parser.add_option("--host", default=values.web.host)
- parser.add_option("--port", default=values.web.port)
-
- opts, args = parser.parse_args()
-
setup_logging(opts)
- cumin = Cumin(config.home, opts.brokers, opts.database,
+ broker_uris = [x.strip() for x in opts.brokers.split(",")]
+
+ cumin = Cumin(config.get_home(), broker_uris, opts.database,
opts.host, opts.port)
- cumin.user = values.web.user
+ cumin.user = values.user
cumin.check()
cumin.init()
Modified: branches/1.3.2/cumin/bin/cumin-web
===================================================================
--- branches/1.3.2/cumin/bin/cumin-web 2011-01-18 20:51:52 UTC (rev 4474)
+++ branches/1.3.2/cumin/bin/cumin-web 2011-01-18 20:59:25 UTC (rev 4475)
@@ -11,32 +11,24 @@
from cumin.util import *
def main():
- config = CuminConfig()
- values = config.parse()
+ config, values, opts, args = get_configuration(CuminWebOptionParser(), CuminWebConfig)
- parser = CuminOptionParser(values.web)
-
- parser.add_option("--host", default=values.web.host)
- parser.add_option("--port", default=values.web.port, type=int)
-
- opts, args = parser.parse_args()
-
setup_logging(opts)
broker_uris = [x.strip() for x in opts.brokers.split(",")]
- cumin = Cumin(config.home, broker_uris, opts.database,
+ cumin = Cumin(config.get_home(), broker_uris, opts.database,
opts.host, opts.port)
cumin.debug = opts.debug
- cumin.user = values.web.user
- cumin.update_interval = values.web.update_interval
+ cumin.user = values.user
+ cumin.update_interval = values.update_interval
# set default values for form inputs
- cumin.set_form_defaults(values.web.request_memory,
- values.web.request_memory_vm,
- values.web.request_disk,
- values.web.request_disk_vm)
+ cumin.set_form_defaults(values.request_memory,
+ values.request_memory_vm,
+ values.request_disk,
+ values.request_disk_vm)
cumin.check()
cumin.init()
Modified: branches/1.3.2/cumin/etc/sysvinit-cumin
===================================================================
--- branches/1.3.2/cumin/etc/sysvinit-cumin 2011-01-18 20:51:52 UTC (rev 4474)
+++ branches/1.3.2/cumin/etc/sysvinit-cumin 2011-01-18 20:59:25 UTC (rev 4475)
@@ -11,6 +11,9 @@
test -x /usr/bin/cumin || exit 1
test -x /usr/bin/cumin-database || exit 1
+SYSCONFIG="/etc/sysconfig/cumin"
+[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
+
cumin-database check-started &> /dev/null || {
echo "Cumin's database server is not running"
echo "Run 'cumin-database start' as root"
@@ -34,7 +37,7 @@
start() {
echo -n $"Starting cumin: "
- daemon --user cumin --check $servicename $processname \&
+ daemon --user cumin --check $servicename $processname $CUMIN_OPTIONS \&
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename
Modified: branches/1.3.2/cumin/python/cumin/config.py
===================================================================
--- branches/1.3.2/cumin/python/cumin/config.py 2011-01-18 20:51:52 UTC (rev 4474)
+++ branches/1.3.2/cumin/python/cumin/config.py 2011-01-18 20:59:25 UTC (rev 4475)
@@ -17,9 +17,28 @@
if not os.path.isdir(self.home):
raise Exception("Home path '%s' is not a directory")
- web = CuminConfigSection(self, "web")
- web.log_file.default = os.path.join(self.home, "log", "web.log")
+ def get_home(self):
+ return self.home
+ def parse(self):
+ paths = list()
+
+ paths.append(os.path.join(os.sep, "etc", "cumin", "cumin.conf"))
+ paths.append(os.path.join(self.home, "etc", "cumin.conf"))
+ paths.append(os.path.join(os.path.expanduser("~"), ".cumin.conf"))
+
+ return self.parse_files(paths)
+
+class CuminWebConfig(CuminConfig):
+ def __init__(self, section_name):
+ super(CuminWebConfig, self).__init__()
+
+ self.create_section(section_name)
+
+ def create_section(self, name):
+ web = CuminConfigSection(self, name)
+ web.log_file.default = os.path.join(self.home, "log", name + ".log")
+
param = ConfigParameter(web, "update-interval", int)
param.default = 10
@@ -42,8 +61,15 @@
param = ConfigParameter(web, "request-disk-vm", int)
param.default = 5 * 1024 #MB
- data = CuminConfigSection(self, "data")
- data.log_file.default = os.path.join(self.home, "log", "data.log")
+class CuminDataConfig(CuminConfig):
+ def __init__(self, section_name):
+ super(CuminDataConfig, self).__init__()
+
+ self.create_section(section_name)
+
+ def create_section(self, name):
+ data = CuminConfigSection(self, name)
+ data.log_file.default = os.path.join(self.home, "log", name + ".log")
param = ConfigParameter(data, "packages", str)
@@ -56,15 +82,6 @@
param = ConfigParameter(data, "vacuum-interval", int)
param.default = 60 * 60 # 1 hour
- def parse(self):
- paths = list()
-
- paths.append(os.path.join(os.sep, "etc", "cumin", "cumin.conf"))
- paths.append(os.path.join(self.home, "etc", "cumin.conf"))
- paths.append(os.path.join(os.path.expanduser("~"), ".cumin.conf"))
-
- return self.parse_files(paths)
-
class CuminConfigSection(ConfigSection):
def __init__(self, config, name):
super(CuminConfigSection, self).__init__(config, name)
@@ -83,17 +100,59 @@
param = ConfigParameter(self, "debug", bool)
param.default = False
-class CuminOptionParser(OptionParser):
- def __init__(self, section):
+class CuminMultiOptionParser(OptionParser,object):
+ def __init__(self, default_section):
OptionParser.__init__(self)
- self.add_option("--database", default=section.database)
- self.add_option("--brokers", default=section.brokers)
- self.add_option("--log-file", default=section.log_file)
- self.add_option("--log-level", default=section.log_level)
- self.add_option("--debug", action="store_true", default=section.debug)
+ self.add_option("--section", default=default_section)
+
+ # We don't know defaults yet...
+ self.add_option("--database")
+ self.add_option("--brokers")
+ self.add_option("--log-file")
+ self.add_option("--log-level")
+ self.add_option("--debug", action="store_true")
self.add_option("--init-only", action="store_true")
+ def _apply_default(self, section, name):
+ try:
+ val = getattr(section, name)
+ self.set_default(name, val)
+ except:
+ pass
+
+ def set_defaults_from_section(self, section):
+ # It is possible that a section does not contain an updated
+ # default value for a particular option. Skip exception.
+ self._apply_default(section, "database")
+ self._apply_default(section, "brokers")
+ self._apply_default(section, "log_file")
+ self._apply_default(section, "log_level")
+ self._apply_default(section, "debug")
+
+class CuminWebOptionParser(CuminMultiOptionParser):
+ def __init__(self, default_section="web"):
+ super(CuminWebOptionParser, self).__init__(default_section)
+
+ # Add additional parameters for web
+ self.add_option("--host")
+ self.add_option("--port", type=int)
+
+ def set_defaults_from_section(self, section):
+ super(CuminWebOptionParser, self).set_defaults_from_section(section)
+
+ # For web, these options also have defaults in config files
+ self._apply_default(section, "host")
+ self._apply_default(section, "port")
+
+class CuminDataOptionParser(CuminMultiOptionParser):
+ def __init__(self, default_section="data"):
+ super(CuminDataOptionParser, self).__init__(default_section)
+
+ # Add additional parameters for data
+ self.add_option("--print-stats", action="store_true")
+ self.add_option("--print-events", type="int", default=0, metavar="LEVEL")
+
def setup_logging(values):
modules = ("cumin", "mint", "parsley", "rosemary", "wooly")
@@ -103,3 +162,21 @@
if values.debug:
for name in modules:
enable_logging(name, "debug", sys.stderr)
+
+def get_configuration(parser, ConfigType):
+ # First parse should return a "section" value
+ opts, args = parser.parse_args()
+ if hasattr(opts, "section"):
+ # Create config object with the given section and parse config files
+ config = ConfigType(opts.section)
+ values = config.parse()
+ if hasattr(values, opts.section):
+ # Reset defaults and parse again
+ values = getattr(values, opts.section)
+ parser.set_defaults_from_section(values)
+ opts, args = parser.parse_args()
+ else:
+ raise Exception("Section ["+opts.section+"] not present in configuration files.")
+ else:
+ raise Exception("No '--section' value available as option or default")
+ return config, values, opts, args
13 years, 3 months
r4474 - in branches/multiples/cumin: bin etc
by tmckay@fedoraproject.org
Author: tmckay
Date: 2011-01-18 20:51:52 +0000 (Tue, 18 Jan 2011)
New Revision: 4474
Added:
branches/multiples/cumin/bin/cumin
Removed:
branches/multiples/cumin/bin/cumin
branches/multiples/cumin/bin/cumin-master
Modified:
branches/multiples/cumin/etc/sysvinit-cumin
Log:
Adjust init.d script for cumin, replace /usr/bin/cumin with
what was /usr/bin/cumin-master (recently added)
Deleted: branches/multiples/cumin/bin/cumin
===================================================================
--- branches/multiples/cumin/bin/cumin 2011-01-17 20:35:28 UTC (rev 4473)
+++ branches/multiples/cumin/bin/cumin 2011-01-18 20:51:52 UTC (rev 4474)
@@ -1,32 +0,0 @@
-#!/bin/bash
-
-function die {
- kill "$data" "$web"
-}
-
-trap die EXIT
-
-function start_data {
- cumin-data &
- data="$!"
-}
-
-function start_web {
- cumin-web &
- web="$!"
-}
-
-start_data
-start_web
-
-while [ 0 ]; do
- sleep 30
-
- if [ ! -d "/proc/$data" ]; then
- start_data
- fi
-
- if [ ! -d "/proc/$web" ]; then
- start_web
- fi
-done
Copied: branches/multiples/cumin/bin/cumin (from rev 4473, branches/multiples/cumin/bin/cumin-master)
===================================================================
--- branches/multiples/cumin/bin/cumin (rev 0)
+++ branches/multiples/cumin/bin/cumin 2011-01-18 20:51:52 UTC (rev 4474)
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+
+from optparse import OptionParser
+from time import sleep
+import subprocess
+import os
+import sys
+import signal
+
+def call_sys_exit(sig,frame):
+ sys.exit()
+
+def set_exit_handler(func):
+ if os.name == "nt":
+ try:
+ import win32api
+ win32api.SetConsoleCtrlHandler(func, True)
+ except ImportError:
+ version = ".".join(map(str, sys.version_info[:2]))
+ raise Exception("pywin32 not installed for Python " + version)
+ else:
+ signal.signal(signal.SIGTERM, func)
+
+def main():
+
+ # tuple indices, for clarity
+ PROCESS = 0
+ SECTION = 1
+ PROGRAM = 2
+
+ parser = OptionParser()
+
+ parser.add_option("--webs", dest="webs", default="web",
+ help="Configuration section names for cumin-web instances."\
+ "\nEach value implies a separate cumin-web instance.")
+
+ parser.add_option("--datas", dest="datas", default="data",
+ help="Configuration section names for cumin-data instances."\
+ "\nEach value implies a separate cumin-data instance.")
+
+ (options, args) = parser.parse_args()
+
+ # Get our list cumin-web and data instances
+ # create list elements to hold the process object, section arg, and app
+ apps = []
+ for app in options.webs.split(','):
+ apps.append([None, app, "cumin-web"])
+
+ for app in options.datas.split(','):
+ apps.append([None, app, "cumin-data"])
+
+ # Launch and babysit
+ try:
+ while True:
+ for app in apps:
+ if not app[PROCESS] or app[PROCESS].poll():
+ arg = "--section=" + app[SECTION]
+ app[PROCESS] = subprocess.Popen([app[PROGRAM], arg])
+ sleep(30)
+
+ finally:
+ for app in apps:
+ if app[PROCESS]:
+ os.kill(app[PROCESS].pid, signal.SIGTERM)
+
+if __name__ == "__main__":
+ # This is necessary so that on a SIGTERM we can call sys.exit()
+ # and cause the finally block to be executed. Ctrl-C will
+ # run the finally block anyway.
+ set_exit_handler(call_sys_exit)
+ try:
+ main()
+ except KeyboardInterrupt:
+ pass
Deleted: branches/multiples/cumin/bin/cumin-master
===================================================================
--- branches/multiples/cumin/bin/cumin-master 2011-01-17 20:35:28 UTC (rev 4473)
+++ branches/multiples/cumin/bin/cumin-master 2011-01-18 20:51:52 UTC (rev 4474)
@@ -1,74 +0,0 @@
-#!/usr/bin/python
-
-from optparse import OptionParser
-from time import sleep
-import subprocess
-import os
-import sys
-import signal
-
-def call_sys_exit(sig,frame):
- sys.exit()
-
-def set_exit_handler(func):
- if os.name == "nt":
- try:
- import win32api
- win32api.SetConsoleCtrlHandler(func, True)
- except ImportError:
- version = ".".join(map(str, sys.version_info[:2]))
- raise Exception("pywin32 not installed for Python " + version)
- else:
- signal.signal(signal.SIGTERM, func)
-
-def main():
-
- # tuple indices, for clarity
- PROCESS = 0
- SECTION = 1
- PROGRAM = 2
-
- parser = OptionParser()
-
- parser.add_option("--webs", dest="webs", default="web",
- help="Configuration section names for cumin-web instances."\
- "\nEach value implies a separate cumin-web instance.")
-
- parser.add_option("--datas", dest="datas", default="data",
- help="Configuration section names for cumin-data instances."\
- "\nEach value implies a separate cumin-data instance.")
-
- (options, args) = parser.parse_args()
-
- # Get our list cumin-web and data instances
- # create list elements to hold the process object, section arg, and app
- apps = []
- for app in options.webs.split(','):
- apps.append([None, app, "cumin-web"])
-
- for app in options.datas.split(','):
- apps.append([None, app, "cumin-data"])
-
- # Launch and babysit
- try:
- while True:
- for app in apps:
- if not app[PROCESS] or app[PROCESS].poll():
- arg = "--section=" + app[SECTION]
- app[PROCESS] = subprocess.Popen([app[PROGRAM], arg])
- sleep(30)
-
- finally:
- for app in apps:
- if app[PROCESS]:
- os.kill(app[PROCESS].pid, signal.SIGTERM)
-
-if __name__ == "__main__":
- # This is necessary so that on a SIGTERM we can call sys.exit()
- # and cause the finally block to be executed. Ctrl-C will
- # run the finally block anyway.
- set_exit_handler(call_sys_exit)
- try:
- main()
- except KeyboardInterrupt:
- pass
Modified: branches/multiples/cumin/etc/sysvinit-cumin
===================================================================
--- branches/multiples/cumin/etc/sysvinit-cumin 2011-01-17 20:35:28 UTC (rev 4473)
+++ branches/multiples/cumin/etc/sysvinit-cumin 2011-01-18 20:51:52 UTC (rev 4474)
@@ -11,6 +11,9 @@
test -x /usr/bin/cumin || exit 1
test -x /usr/bin/cumin-database || exit 1
+SYSCONFIG="/etc/sysconfig/cumin"
+[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
+
cumin-database check-started &> /dev/null || {
echo "Cumin's database server is not running"
echo "Run 'cumin-database start' as root"
@@ -34,7 +37,7 @@
start() {
echo -n $"Starting cumin: "
- daemon --user cumin --check $servicename $processname \&
+ daemon --user cumin --check $servicename $processname $CUMIN_OPTIONS \&
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$servicename
13 years, 3 months
r4473 - in branches/1.3.2: cumin/python/cumin/grid wooly/python/wooly
by tmckay@fedoraproject.org
Author: tmckay
Date: 2011-01-17 20:35:28 +0000 (Mon, 17 Jan 2011)
New Revision: 4473
Modified:
branches/1.3.2/cumin/python/cumin/grid/job.py
branches/1.3.2/wooly/python/wooly/datatable.strings
Log:
Merged revision 4472 from trunk. Original comment:
BZ 668985 : Fixed job hold/release/remove form for a selection of jobs (as opposed to an individual job)
Modified: branches/1.3.2/cumin/python/cumin/grid/job.py
===================================================================
--- branches/1.3.2/cumin/python/cumin/grid/job.py 2011-01-17 19:36:06 UTC (rev 4472)
+++ branches/1.3.2/cumin/python/cumin/grid/job.py 2011-01-17 20:35:28 UTC (rev 4473)
@@ -222,16 +222,6 @@
JobSelectionRelease(app, self, "released")
JobSelectionRemove(app, self, "removed")
- def init_ids(self, app, cls):
- item = Parameter(app, "item")
-
- self.ids = ListParameter(app, "selection", item)
- self.add_parameter(self.ids)
-
- self.checkbox_column = ObjectCheckboxColumn \
- (app, "id", cls.JobId, self.ids)
- self.add_column(self.checkbox_column)
-
def create_table(self, app, name, cls):
return JobSelectorTable(app, name, cls)
@@ -270,6 +260,16 @@
self.qmf_response = Attribute(app, "qmf_response")
self.add_attribute(self.qmf_response)
+ def init_ids(self, app, cls):
+ item = Parameter(app, "item")
+
+ self.ids = ListParameter(app, "selection", item)
+ self.add_parameter(self.ids)
+
+ self.checkbox_column = ObjectCheckboxColumn \
+ (app, "id", cls.JobId, self.ids)
+ self.add_column(self.checkbox_column)
+
def get_data_values(self, session):
values = super(JobSelectorTable, self).get_data_values(session)
@@ -332,6 +332,10 @@
submission = self.selector.submission.get(osession)
self.form.submission_id.set(session, submission._id)
+ def get_item_content(self, session, item):
+ # item here is the unicode job id
+ return item
+
class JobSelectionHold(JobObjectSelectorTask):
def __init__(self, app, selector, verb):
super(JobSelectionHold, self).__init__(app, selector, verb)
@@ -366,9 +370,10 @@
self.submission_id = IntegerParameter(app, "sub")
self.add_parameter(self.submission_id)
- self.content = ReasonField(app, "fields")
- self.content.required = True
- self.replace_child(self.content)
+ self.reason = ReasonField(app, "reason")
+ self.reason.required = True
+ self.main_fields.add_field(self.reason)
+ self.add_child(self.reason)
self.verb = verb
@@ -380,7 +385,7 @@
def get_reason(self, session, verb):
""" returns <verb> by username[: <user input reason>] """
- reason = self.content.get(session)
+ reason = self.reason.get(session)
if reason:
reason = [reason]
user = session.client_session.attributes["login_session"].user
@@ -390,14 +395,18 @@
return ": ".join(reason)
def process_submit(self, session):
- selection = self.selection.get(session)
- reason = self.get_reason(session, self.verb)
+ self.validate(session)
- scheduler = self.get_scheduler(session)
+ errors = self.errors.get(session)
+ if not errors:
+ selection = self.selection.get(session)
+ reason = self.get_reason(session, self.verb)
- self.task.invoke(session, selection, scheduler, reason)
- self.task.exit_with_redirect(session)
+ scheduler = self.get_scheduler(session)
+ self.task.invoke(session, selection, scheduler, reason)
+ self.task.exit_with_redirect(session)
+
def get_scheduler(self, session):
submission_id = self.submission_id.get(session)
cls = self.app.model.com_redhat_grid.Submission
@@ -409,6 +418,11 @@
cls = self.app.model.com_redhat_grid.Scheduler
return cls.get_object(session.cursor, _id=job_server._schedulerRef_id)
+ def render_content(self, session, *args):
+ content = super(JobObjectSelectorTaskForm, self).render_content(session, *args)
+ reason = self.reason.render(session)
+ return "<table class=\"FormFieldSet\"><tbody>%s</tbody></table>%s" % (reason, content)
+
class JobAdsSet(PropertySet):
types = {0: "expression",
1: "integer",
Modified: branches/1.3.2/wooly/python/wooly/datatable.strings
===================================================================
--- branches/1.3.2/wooly/python/wooly/datatable.strings 2011-01-17 19:36:06 UTC (rev 4472)
+++ branches/1.3.2/wooly/python/wooly/datatable.strings 2011-01-17 20:35:28 UTC (rev 4473)
@@ -9,8 +9,8 @@
margin: 0 0 0 2em;
}
-table.DataTable th.controls div.paginator span.selectorOptions {
- /* allow page number to wrap to next line */
+table.DataTable th.controls div.paginator {
+ /* allow page numbers to wrap to next line */
white-space: normal;
}
@@ -37,4 +37,4 @@
[DataTableSelector.html]
<span>{title}</span>
-<span class="selectorOptions">{options}</span>
+<span>{options}</span>
13 years, 3 months
r4472 - in trunk: cumin/python/cumin/grid wooly/python/wooly
by eallen@fedoraproject.org
Author: eallen
Date: 2011-01-17 19:36:06 +0000 (Mon, 17 Jan 2011)
New Revision: 4472
Modified:
trunk/cumin/python/cumin/grid/job.py
trunk/wooly/python/wooly/datatable.strings
Log:
BZ 668985 : Fixed job hold/release/remove form for a selection of jobs (as opposed to an individual job)
Modified: trunk/cumin/python/cumin/grid/job.py
===================================================================
--- trunk/cumin/python/cumin/grid/job.py 2011-01-17 16:41:14 UTC (rev 4471)
+++ trunk/cumin/python/cumin/grid/job.py 2011-01-17 19:36:06 UTC (rev 4472)
@@ -222,16 +222,6 @@
JobSelectionRelease(app, self, "released")
JobSelectionRemove(app, self, "removed")
- def init_ids(self, app, cls):
- item = Parameter(app, "item")
-
- self.ids = ListParameter(app, "selection", item)
- self.add_parameter(self.ids)
-
- self.checkbox_column = ObjectCheckboxColumn \
- (app, "id", cls.JobId, self.ids)
- self.add_column(self.checkbox_column)
-
def create_table(self, app, name, cls):
return JobSelectorTable(app, name, cls)
@@ -270,6 +260,16 @@
self.qmf_response = Attribute(app, "qmf_response")
self.add_attribute(self.qmf_response)
+ def init_ids(self, app, cls):
+ item = Parameter(app, "item")
+
+ self.ids = ListParameter(app, "selection", item)
+ self.add_parameter(self.ids)
+
+ self.checkbox_column = ObjectCheckboxColumn \
+ (app, "id", cls.JobId, self.ids)
+ self.add_column(self.checkbox_column)
+
def get_data_values(self, session):
values = super(JobSelectorTable, self).get_data_values(session)
@@ -332,6 +332,10 @@
submission = self.selector.submission.get(osession)
self.form.submission_id.set(session, submission._id)
+ def get_item_content(self, session, item):
+ # item here is the unicode job id
+ return item
+
class JobSelectionHold(JobObjectSelectorTask):
def __init__(self, app, selector, verb):
super(JobSelectionHold, self).__init__(app, selector, verb)
@@ -366,9 +370,10 @@
self.submission_id = IntegerParameter(app, "sub")
self.add_parameter(self.submission_id)
- self.content = ReasonField(app, "fields")
- self.content.required = True
- self.replace_child(self.content)
+ self.reason = ReasonField(app, "reason")
+ self.reason.required = True
+ self.main_fields.add_field(self.reason)
+ self.add_child(self.reason)
self.verb = verb
@@ -380,7 +385,7 @@
def get_reason(self, session, verb):
""" returns <verb> by username[: <user input reason>] """
- reason = self.content.get(session)
+ reason = self.reason.get(session)
if reason:
reason = [reason]
user = session.client_session.attributes["login_session"].user
@@ -390,14 +395,18 @@
return ": ".join(reason)
def process_submit(self, session):
- selection = self.selection.get(session)
- reason = self.get_reason(session, self.verb)
+ self.validate(session)
- scheduler = self.get_scheduler(session)
+ errors = self.errors.get(session)
+ if not errors:
+ selection = self.selection.get(session)
+ reason = self.get_reason(session, self.verb)
- self.task.invoke(session, selection, scheduler, reason)
- self.task.exit_with_redirect(session)
+ scheduler = self.get_scheduler(session)
+ self.task.invoke(session, selection, scheduler, reason)
+ self.task.exit_with_redirect(session)
+
def get_scheduler(self, session):
submission_id = self.submission_id.get(session)
cls = self.app.model.com_redhat_grid.Submission
@@ -409,6 +418,11 @@
cls = self.app.model.com_redhat_grid.Scheduler
return cls.get_object(session.cursor, _id=job_server._schedulerRef_id)
+ def render_content(self, session, *args):
+ content = super(JobObjectSelectorTaskForm, self).render_content(session, *args)
+ reason = self.reason.render(session)
+ return "<table class=\"FormFieldSet\"><tbody>%s</tbody></table>%s" % (reason, content)
+
class JobAdsSet(PropertySet):
types = {0: "expression",
1: "integer",
Modified: trunk/wooly/python/wooly/datatable.strings
===================================================================
--- trunk/wooly/python/wooly/datatable.strings 2011-01-17 16:41:14 UTC (rev 4471)
+++ trunk/wooly/python/wooly/datatable.strings 2011-01-17 19:36:06 UTC (rev 4472)
@@ -9,8 +9,8 @@
margin: 0 0 0 2em;
}
-table.DataTable th.controls div.paginator span.selectorOptions {
- /* allow page number to wrap to next line */
+table.DataTable th.controls div.paginator {
+ /* allow page numbers to wrap to next line */
white-space: normal;
}
@@ -37,4 +37,4 @@
[DataTableSelector.html]
<span>{title}</span>
-<span class="selectorOptions">{options}</span>
+<span>{options}</span>
13 years, 3 months
r4471 - branches/multiples/cumin/python/cumin
by tmckay@fedoraproject.org
Author: tmckay
Date: 2011-01-17 16:41:14 +0000 (Mon, 17 Jan 2011)
New Revision: 4471
Modified:
branches/multiples/cumin/python/cumin/config.py
Log:
Delete CuminOptionParser class
Modified: branches/multiples/cumin/python/cumin/config.py
===================================================================
--- branches/multiples/cumin/python/cumin/config.py 2011-01-17 16:30:18 UTC (rev 4470)
+++ branches/multiples/cumin/python/cumin/config.py 2011-01-17 16:41:14 UTC (rev 4471)
@@ -100,17 +100,6 @@
param = ConfigParameter(self, "debug", bool)
param.default = False
-class CuminOptionParser(OptionParser):
- def __init__(self, section):
- OptionParser.__init__(self)
-
- self.add_option("--database", default=section.database)
- self.add_option("--brokers", default=section.brokers)
- self.add_option("--log-file", default=section.log_file)
- self.add_option("--log-level", default=section.log_level)
- self.add_option("--debug", action="store_true", default=section.debug)
- self.add_option("--init-only", action="store_true")
-
class CuminMultiOptionParser(OptionParser,object):
def __init__(self, default_section):
OptionParser.__init__(self)
13 years, 3 months
r4470 - in branches/multiples/cumin: bin python/cumin
by tmckay@fedoraproject.org
Author: tmckay
Date: 2011-01-17 16:30:18 +0000 (Mon, 17 Jan 2011)
New Revision: 4470
Modified:
branches/multiples/cumin/bin/cumin-admin
branches/multiples/cumin/bin/cumin-bench
branches/multiples/cumin/bin/cumin-data
branches/multiples/cumin/bin/cumin-smoke-test
branches/multiples/cumin/bin/cumin-web
branches/multiples/cumin/python/cumin/config.py
Log:
Add error checking to new config routines, fix up additional binaries
Modified: branches/multiples/cumin/bin/cumin-admin
===================================================================
--- branches/multiples/cumin/bin/cumin-admin 2011-01-17 14:55:41 UTC (rev 4469)
+++ branches/multiples/cumin/bin/cumin-admin 2011-01-17 16:30:18 UTC (rev 4470)
@@ -24,14 +24,10 @@
if uid == 0:
os.setuid(file_uid)
- config = CuminConfig()
- values = config.parse()
-
- parser = CuminOptionParser(values.data)
+ parser = CuminDataOptionParser()
parser.set_usage(generate_usage())
+ config, values, opts, args = get_configuration(parser, CuminDataConfig)
- opts, args = parser.parse_args()
-
try:
name = args[0]
except IndexError:
@@ -50,7 +46,7 @@
broker_uris = [x.strip() for x in opts.brokers.split(",")]
- app = Cumin(config.home, broker_uris, opts.database)
+ app = Cumin(config.get_home(), broker_uris, opts.database)
app.check()
app.init()
Modified: branches/multiples/cumin/bin/cumin-bench
===================================================================
--- branches/multiples/cumin/bin/cumin-bench 2011-01-17 14:55:41 UTC (rev 4469)
+++ branches/multiples/cumin/bin/cumin-bench 2011-01-17 16:30:18 UTC (rev 4470)
@@ -8,22 +8,17 @@
from cumin.config import *
def do_main():
- config = CuminConfig()
- values = config.parse()
+ config, values, opts, args = get_configuration(CuminWebOptionParser(), CuminWebConfig)
- parser = CuminOptionParser(values.web)
-
- opts, args = parser.parse_args()
-
setup_logging(opts)
broker_uris = [x.strip() for x in opts.brokers.split(",")]
- cumin = Cumin(config.home, broker_uris, opts.database)
+ cumin = Cumin(config.get_home(), broker_uris, opts.database)
cumin.debug = True
- cumin.user = values.web.user
- cumin.update_interval = values.web.update_interval
+ cumin.user = values.user
+ cumin.update_interval = values.update_interval
cumin.check()
cumin.init()
Modified: branches/multiples/cumin/bin/cumin-data
===================================================================
--- branches/multiples/cumin/bin/cumin-data 2011-01-17 14:55:41 UTC (rev 4469)
+++ branches/multiples/cumin/bin/cumin-data 2011-01-17 16:30:18 UTC (rev 4470)
@@ -11,7 +11,7 @@
from mint import *
def main():
- config, values, opts = get_configuration(CuminDataOptionParser(), CuminDataConfig)
+ config, values, opts, args = get_configuration(CuminDataOptionParser(), CuminDataConfig)
setup_logging(opts)
Modified: branches/multiples/cumin/bin/cumin-smoke-test
===================================================================
--- branches/multiples/cumin/bin/cumin-smoke-test 2011-01-17 14:55:41 UTC (rev 4469)
+++ branches/multiples/cumin/bin/cumin-smoke-test 2011-01-17 16:30:18 UTC (rev 4470)
@@ -13,22 +13,16 @@
from cumin.util import *
def main():
- config = CuminConfig()
- values = config.parse()
+ config, values, opts, args = get_configuration(CuminWebOptionParser(), CuminWebConfig)
- parser = CuminOptionParser(values.web)
-
- parser.add_option("--host", default=values.web.host)
- parser.add_option("--port", default=values.web.port)
-
- opts, args = parser.parse_args()
-
setup_logging(opts)
- cumin = Cumin(config.home, opts.brokers, opts.database,
+ broker_uris = [x.strip() for x in opts.brokers.split(",")]
+
+ cumin = Cumin(config.get_home(), broker_uris, opts.database,
opts.host, opts.port)
- cumin.user = values.web.user
+ cumin.user = values.user
cumin.check()
cumin.init()
Modified: branches/multiples/cumin/bin/cumin-web
===================================================================
--- branches/multiples/cumin/bin/cumin-web 2011-01-17 14:55:41 UTC (rev 4469)
+++ branches/multiples/cumin/bin/cumin-web 2011-01-17 16:30:18 UTC (rev 4470)
@@ -11,7 +11,7 @@
from cumin.util import *
def main():
- config, values, opts = get_configuration(CuminWebOptionParser(), CuminWebConfig)
+ config, values, opts, args = get_configuration(CuminWebOptionParser(), CuminWebConfig)
setup_logging(opts)
Modified: branches/multiples/cumin/python/cumin/config.py
===================================================================
--- branches/multiples/cumin/python/cumin/config.py 2011-01-17 14:55:41 UTC (rev 4469)
+++ branches/multiples/cumin/python/cumin/config.py 2011-01-17 16:30:18 UTC (rev 4470)
@@ -125,13 +125,21 @@
self.add_option("--debug", action="store_true")
self.add_option("--init-only", action="store_true")
+ def _apply_default(self, section, name):
+ try:
+ val = getattr(section, name)
+ self.set_default(name, val)
+ except:
+ pass
+
def set_defaults_from_section(self, section):
- # Careful, parser replaces '-' with '_' in dest fields
- self.set_default("database", section.database)
- self.set_default("brokers", section.brokers)
- self.set_default("log_file", section.log_file)
- self.set_default("log_level", section.log_level)
- self.set_default("debug", section.debug)
+ # It is possible that a section does not contain an updated
+ # default value for a particular option. Skip exception.
+ self._apply_default(section, "database")
+ self._apply_default(section, "brokers")
+ self._apply_default(section, "log_file")
+ self._apply_default(section, "log_level")
+ self._apply_default(section, "debug")
class CuminWebOptionParser(CuminMultiOptionParser):
def __init__(self, default_section="web"):
@@ -145,8 +153,8 @@
super(CuminWebOptionParser, self).set_defaults_from_section(section)
# For web, these options also have defaults in config files
- self.set_default("host", section.host)
- self.set_default("port", section.port)
+ self._apply_default(section, "host")
+ self._apply_default(section, "port")
class CuminDataOptionParser(CuminMultiOptionParser):
def __init__(self, default_section="data"):
@@ -170,7 +178,7 @@
# First parse should return a "section" value
opts, args = parser.parse_args()
if hasattr(opts, "section"):
- # Create section and parse config files
+ # Create config object with the given section and parse config files
config = ConfigType(opts.section)
values = config.parse()
if hasattr(values, opts.section):
@@ -178,4 +186,8 @@
values = getattr(values, opts.section)
parser.set_defaults_from_section(values)
opts, args = parser.parse_args()
- return config, values, opts
+ else:
+ raise Exception("Section ["+opts.section+"] not present in configuration files.")
+ else:
+ raise Exception("No '--section' value available as option or default")
+ return config, values, opts, args
13 years, 3 months
r4469 - in branches/multiples/cumin: bin python/cumin
by tmckay@fedoraproject.org
Author: tmckay
Date: 2011-01-17 14:55:41 +0000 (Mon, 17 Jan 2011)
New Revision: 4469
Modified:
branches/multiples/cumin/bin/cumin-data
branches/multiples/cumin/bin/cumin-web
branches/multiples/cumin/python/cumin/config.py
Log:
Move preamble logic in cumin-web and cumin-data into classes and a common method
Modified: branches/multiples/cumin/bin/cumin-data
===================================================================
--- branches/multiples/cumin/bin/cumin-data 2011-01-17 13:12:20 UTC (rev 4468)
+++ branches/multiples/cumin/bin/cumin-data 2011-01-17 14:55:41 UTC (rev 4469)
@@ -11,35 +11,8 @@
from mint import *
def main():
- # Configuration boot-strap issue. We need the value of
- # the --section option first to set up defaults for further
- # option parsing. This is complicated by the fact that
- # OptionParser has no way to handle options that it doesn't
- # recognize without throwing an exception. We have to create all options,
- # parse, set defaults based on section, and parse again.
+ config, values, opts = get_configuration(CuminDataOptionParser(), CuminDataConfig)
- # Get the section value first. That's all we care about right now.
- parser = CuminDataOptionParser(default_section="data")
- opts, args = parser.parse_args()
-
- # Now that we have a section name, we have to dynamically create
- # a CuminConfigSection associated with that name to guide the parse.
- config = CuminConfig()
- config.create_data_section(opts.section)
- values = config.parse()
-
- # We need to have the requested section defined in the config files
- if not hasattr(values, opts.section):
- print "Section not defined in configuration files: " + opts.section
- return
- values = getattr(values, opts.section)
-
- # Set defaults for options from the file values for requested section...
- parser.set_defaults_from_section(values)
-
- # And finally parse the options
- opts, args = parser.parse_args()
-
setup_logging(opts)
model_dir = os.path.join(config.home, "model")
Modified: branches/multiples/cumin/bin/cumin-web
===================================================================
--- branches/multiples/cumin/bin/cumin-web 2011-01-17 13:12:20 UTC (rev 4468)
+++ branches/multiples/cumin/bin/cumin-web 2011-01-17 14:55:41 UTC (rev 4469)
@@ -11,40 +11,13 @@
from cumin.util import *
def main():
- # Configuration boot-strap issue. We need the value of
- # the --section option first to set up defaults for further
- # option parsing. This is complicated by the fact that
- # OptionParser has no way to handle options that it doesn't
- # recognize without throwing an exception. We have to create all options,
- # parse, set defaults based on section, and parse again.
+ config, values, opts = get_configuration(CuminWebOptionParser(), CuminWebConfig)
- # Get the section value first. That's all we care about right now.
- parser = CuminWebOptionParser(default_section="web")
- opts, args = parser.parse_args()
-
- # Now that we have a section name, we have to dynamically create
- # a CuminConfigSection associated with that name to guide the parse.
- config = CuminConfig()
- config.create_web_section(opts.section)
- values = config.parse()
-
- # We need to have the requested section defined in the config files
- if not hasattr(values, opts.section):
- print "Section not defined in configuration files: " + opts.section
- return
- values = getattr(values, opts.section)
-
- # Set defaults for options from the file values for requested section...
- parser.set_defaults_from_section(values)
-
- # And finally parse the options
- opts, args = parser.parse_args()
-
setup_logging(opts)
broker_uris = [x.strip() for x in opts.brokers.split(",")]
- cumin = Cumin(config.home, broker_uris, opts.database,
+ cumin = Cumin(config.get_home(), broker_uris, opts.database,
opts.host, opts.port)
cumin.debug = opts.debug
Modified: branches/multiples/cumin/python/cumin/config.py
===================================================================
--- branches/multiples/cumin/python/cumin/config.py 2011-01-17 13:12:20 UTC (rev 4468)
+++ branches/multiples/cumin/python/cumin/config.py 2011-01-17 14:55:41 UTC (rev 4469)
@@ -17,8 +17,25 @@
if not os.path.isdir(self.home):
raise Exception("Home path '%s' is not a directory")
- def create_web_section(self, name):
+ def get_home(self):
+ return self.home
+ def parse(self):
+ paths = list()
+
+ paths.append(os.path.join(os.sep, "etc", "cumin", "cumin.conf"))
+ paths.append(os.path.join(self.home, "etc", "cumin.conf"))
+ paths.append(os.path.join(os.path.expanduser("~"), ".cumin.conf"))
+
+ return self.parse_files(paths)
+
+class CuminWebConfig(CuminConfig):
+ def __init__(self, section_name):
+ super(CuminWebConfig, self).__init__()
+
+ self.create_section(section_name)
+
+ def create_section(self, name):
web = CuminConfigSection(self, name)
web.log_file.default = os.path.join(self.home, "log", name + ".log")
@@ -44,8 +61,13 @@
param = ConfigParameter(web, "request-disk-vm", int)
param.default = 5 * 1024 #MB
- def create_data_section(self, name):
+class CuminDataConfig(CuminConfig):
+ def __init__(self, section_name):
+ super(CuminDataConfig, self).__init__()
+ self.create_section(section_name)
+
+ def create_section(self, name):
data = CuminConfigSection(self, name)
data.log_file.default = os.path.join(self.home, "log", name + ".log")
@@ -60,15 +82,6 @@
param = ConfigParameter(data, "vacuum-interval", int)
param.default = 60 * 60 # 1 hour
- def parse(self):
- paths = list()
-
- paths.append(os.path.join(os.sep, "etc", "cumin", "cumin.conf"))
- paths.append(os.path.join(self.home, "etc", "cumin.conf"))
- paths.append(os.path.join(os.path.expanduser("~"), ".cumin.conf"))
-
- return self.parse_files(paths)
-
class CuminConfigSection(ConfigSection):
def __init__(self, config, name):
super(CuminConfigSection, self).__init__(config, name)
@@ -121,7 +134,7 @@
self.set_default("debug", section.debug)
class CuminWebOptionParser(CuminMultiOptionParser):
- def __init__(self, default_section):
+ def __init__(self, default_section="web"):
super(CuminWebOptionParser, self).__init__(default_section)
# Add additional parameters for web
@@ -136,7 +149,7 @@
self.set_default("port", section.port)
class CuminDataOptionParser(CuminMultiOptionParser):
- def __init__(self, default_section):
+ def __init__(self, default_section="data"):
super(CuminDataOptionParser, self).__init__(default_section)
# Add additional parameters for data
@@ -152,3 +165,17 @@
if values.debug:
for name in modules:
enable_logging(name, "debug", sys.stderr)
+
+def get_configuration(parser, ConfigType):
+ # First parse should return a "section" value
+ opts, args = parser.parse_args()
+ if hasattr(opts, "section"):
+ # Create section and parse config files
+ config = ConfigType(opts.section)
+ values = config.parse()
+ if hasattr(values, opts.section):
+ # Reset defaults and parse again
+ values = getattr(values, opts.section)
+ parser.set_defaults_from_section(values)
+ opts, args = parser.parse_args()
+ return config, values, opts
13 years, 3 months
r4468 - in branches/multiples/cumin: bin python/cumin
by tmckay@fedoraproject.org
Author: tmckay
Date: 2011-01-17 13:12:20 +0000 (Mon, 17 Jan 2011)
New Revision: 4468
Modified:
branches/multiples/cumin/bin/cumin-data
branches/multiples/cumin/bin/cumin-web
branches/multiples/cumin/python/cumin/config.py
Log:
Get rid of creation of hardcoded creation of "web" and "data" sections.
Modified: branches/multiples/cumin/bin/cumin-data
===================================================================
--- branches/multiples/cumin/bin/cumin-data 2011-01-14 22:47:23 UTC (rev 4467)
+++ branches/multiples/cumin/bin/cumin-data 2011-01-17 13:12:20 UTC (rev 4468)
@@ -11,8 +11,6 @@
from mint import *
def main():
- config = CuminConfig()
-
# Configuration boot-strap issue. We need the value of
# the --section option first to set up defaults for further
# option parsing. This is complicated by the fact that
@@ -26,10 +24,8 @@
# Now that we have a section name, we have to dynamically create
# a CuminConfigSection associated with that name to guide the parse.
- if opts.section != "data":
- config.create_data_section(opts.section)
-
- # Now we can read our values from config files
+ config = CuminConfig()
+ config.create_data_section(opts.section)
values = config.parse()
# We need to have the requested section defined in the config files
Modified: branches/multiples/cumin/bin/cumin-web
===================================================================
--- branches/multiples/cumin/bin/cumin-web 2011-01-14 22:47:23 UTC (rev 4467)
+++ branches/multiples/cumin/bin/cumin-web 2011-01-17 13:12:20 UTC (rev 4468)
@@ -11,8 +11,6 @@
from cumin.util import *
def main():
- config = CuminConfig()
-
# Configuration boot-strap issue. We need the value of
# the --section option first to set up defaults for further
# option parsing. This is complicated by the fact that
@@ -26,10 +24,8 @@
# Now that we have a section name, we have to dynamically create
# a CuminConfigSection associated with that name to guide the parse.
- if opts.section != "web":
- config.create_web_section(opts.section)
-
- # Now we can read our values from config files
+ config = CuminConfig()
+ config.create_web_section(opts.section)
values = config.parse()
# We need to have the requested section defined in the config files
Modified: branches/multiples/cumin/python/cumin/config.py
===================================================================
--- branches/multiples/cumin/python/cumin/config.py 2011-01-14 22:47:23 UTC (rev 4467)
+++ branches/multiples/cumin/python/cumin/config.py 2011-01-17 13:12:20 UTC (rev 4468)
@@ -17,10 +17,6 @@
if not os.path.isdir(self.home):
raise Exception("Home path '%s' is not a directory")
- self.create_web_section("web")
-
- self.create_data_section("data")
-
def create_web_section(self, name):
web = CuminConfigSection(self, name)
13 years, 3 months
r4467 - in branches/multiples/cumin: bin python/cumin
by tmckay@fedoraproject.org
Author: tmckay
Date: 2011-01-14 22:47:23 +0000 (Fri, 14 Jan 2011)
New Revision: 4467
Added:
branches/multiples/cumin/bin/cumin-master
Modified:
branches/multiples/cumin/bin/cumin-data
branches/multiples/cumin/bin/cumin-web
branches/multiples/cumin/python/cumin/config.py
Log:
Changes to support configuration for multiple cumin-web and cumin-data instances
Modified: branches/multiples/cumin/bin/cumin-data
===================================================================
--- branches/multiples/cumin/bin/cumin-data 2011-01-14 22:38:27 UTC (rev 4466)
+++ branches/multiples/cumin/bin/cumin-data 2011-01-14 22:47:23 UTC (rev 4467)
@@ -12,14 +12,38 @@
def main():
config = CuminConfig()
- values = config.parse().data
- parser = CuminOptionParser(values)
- parser.add_option("--print-stats", action="store_true")
- parser.add_option("--print-events", type="int", default=0, metavar="LEVEL")
+ # Configuration boot-strap issue. We need the value of
+ # the --section option first to set up defaults for further
+ # option parsing. This is complicated by the fact that
+ # OptionParser has no way to handle options that it doesn't
+ # recognize without throwing an exception. We have to create all options,
+ # parse, set defaults based on section, and parse again.
+ # Get the section value first. That's all we care about right now.
+ parser = CuminDataOptionParser(default_section="data")
opts, args = parser.parse_args()
+ # Now that we have a section name, we have to dynamically create
+ # a CuminConfigSection associated with that name to guide the parse.
+ if opts.section != "data":
+ config.create_data_section(opts.section)
+
+ # Now we can read our values from config files
+ values = config.parse()
+
+ # We need to have the requested section defined in the config files
+ if not hasattr(values, opts.section):
+ print "Section not defined in configuration files: " + opts.section
+ return
+ values = getattr(values, opts.section)
+
+ # Set defaults for options from the file values for requested section...
+ parser.set_defaults_from_section(values)
+
+ # And finally parse the options
+ opts, args = parser.parse_args()
+
setup_logging(opts)
model_dir = os.path.join(config.home, "model")
Added: branches/multiples/cumin/bin/cumin-master
===================================================================
--- branches/multiples/cumin/bin/cumin-master (rev 0)
+++ branches/multiples/cumin/bin/cumin-master 2011-01-14 22:47:23 UTC (rev 4467)
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+
+from optparse import OptionParser
+from time import sleep
+import subprocess
+import os
+import sys
+import signal
+
+def call_sys_exit(sig,frame):
+ sys.exit()
+
+def set_exit_handler(func):
+ if os.name == "nt":
+ try:
+ import win32api
+ win32api.SetConsoleCtrlHandler(func, True)
+ except ImportError:
+ version = ".".join(map(str, sys.version_info[:2]))
+ raise Exception("pywin32 not installed for Python " + version)
+ else:
+ signal.signal(signal.SIGTERM, func)
+
+def main():
+
+ # tuple indices, for clarity
+ PROCESS = 0
+ SECTION = 1
+ PROGRAM = 2
+
+ parser = OptionParser()
+
+ parser.add_option("--webs", dest="webs", default="web",
+ help="Configuration section names for cumin-web instances."\
+ "\nEach value implies a separate cumin-web instance.")
+
+ parser.add_option("--datas", dest="datas", default="data",
+ help="Configuration section names for cumin-data instances."\
+ "\nEach value implies a separate cumin-data instance.")
+
+ (options, args) = parser.parse_args()
+
+ # Get our list cumin-web and data instances
+ # create list elements to hold the process object, section arg, and app
+ apps = []
+ for app in options.webs.split(','):
+ apps.append([None, app, "cumin-web"])
+
+ for app in options.datas.split(','):
+ apps.append([None, app, "cumin-data"])
+
+ # Launch and babysit
+ try:
+ while True:
+ for app in apps:
+ if not app[PROCESS] or app[PROCESS].poll():
+ arg = "--section=" + app[SECTION]
+ app[PROCESS] = subprocess.Popen([app[PROGRAM], arg])
+ sleep(30)
+
+ finally:
+ for app in apps:
+ if app[PROCESS]:
+ os.kill(app[PROCESS].pid, signal.SIGTERM)
+
+if __name__ == "__main__":
+ # This is necessary so that on a SIGTERM we can call sys.exit()
+ # and cause the finally block to be executed. Ctrl-C will
+ # run the finally block anyway.
+ set_exit_handler(call_sys_exit)
+ try:
+ main()
+ except KeyboardInterrupt:
+ pass
Property changes on: branches/multiples/cumin/bin/cumin-master
___________________________________________________________________
Name: svn:executable
+ *
Modified: branches/multiples/cumin/bin/cumin-web
===================================================================
--- branches/multiples/cumin/bin/cumin-web 2011-01-14 22:38:27 UTC (rev 4466)
+++ branches/multiples/cumin/bin/cumin-web 2011-01-14 22:47:23 UTC (rev 4467)
@@ -12,13 +12,36 @@
def main():
config = CuminConfig()
+
+ # Configuration boot-strap issue. We need the value of
+ # the --section option first to set up defaults for further
+ # option parsing. This is complicated by the fact that
+ # OptionParser has no way to handle options that it doesn't
+ # recognize without throwing an exception. We have to create all options,
+ # parse, set defaults based on section, and parse again.
+
+ # Get the section value first. That's all we care about right now.
+ parser = CuminWebOptionParser(default_section="web")
+ opts, args = parser.parse_args()
+
+ # Now that we have a section name, we have to dynamically create
+ # a CuminConfigSection associated with that name to guide the parse.
+ if opts.section != "web":
+ config.create_web_section(opts.section)
+
+ # Now we can read our values from config files
values = config.parse()
- parser = CuminOptionParser(values.web)
+ # We need to have the requested section defined in the config files
+ if not hasattr(values, opts.section):
+ print "Section not defined in configuration files: " + opts.section
+ return
+ values = getattr(values, opts.section)
- parser.add_option("--host", default=values.web.host)
- parser.add_option("--port", default=values.web.port, type=int)
+ # Set defaults for options from the file values for requested section...
+ parser.set_defaults_from_section(values)
+ # And finally parse the options
opts, args = parser.parse_args()
setup_logging(opts)
@@ -29,14 +52,14 @@
opts.host, opts.port)
cumin.debug = opts.debug
- cumin.user = values.web.user
- cumin.update_interval = values.web.update_interval
+ cumin.user = values.user
+ cumin.update_interval = values.update_interval
# set default values for form inputs
- cumin.set_form_defaults(values.web.request_memory,
- values.web.request_memory_vm,
- values.web.request_disk,
- values.web.request_disk_vm)
+ cumin.set_form_defaults(values.request_memory,
+ values.request_memory_vm,
+ values.request_disk,
+ values.request_disk_vm)
cumin.check()
cumin.init()
Modified: branches/multiples/cumin/python/cumin/config.py
===================================================================
--- branches/multiples/cumin/python/cumin/config.py 2011-01-14 22:38:27 UTC (rev 4466)
+++ branches/multiples/cumin/python/cumin/config.py 2011-01-14 22:47:23 UTC (rev 4467)
@@ -17,9 +17,15 @@
if not os.path.isdir(self.home):
raise Exception("Home path '%s' is not a directory")
- web = CuminConfigSection(self, "web")
- web.log_file.default = os.path.join(self.home, "log", "web.log")
+ self.create_web_section("web")
+ self.create_data_section("data")
+
+ def create_web_section(self, name):
+
+ web = CuminConfigSection(self, name)
+ web.log_file.default = os.path.join(self.home, "log", name + ".log")
+
param = ConfigParameter(web, "update-interval", int)
param.default = 10
@@ -42,8 +48,10 @@
param = ConfigParameter(web, "request-disk-vm", int)
param.default = 5 * 1024 #MB
- data = CuminConfigSection(self, "data")
- data.log_file.default = os.path.join(self.home, "log", "data.log")
+ def create_data_section(self, name):
+
+ data = CuminConfigSection(self, name)
+ data.log_file.default = os.path.join(self.home, "log", name + ".log")
param = ConfigParameter(data, "packages", str)
@@ -94,6 +102,51 @@
self.add_option("--debug", action="store_true", default=section.debug)
self.add_option("--init-only", action="store_true")
+class CuminMultiOptionParser(OptionParser,object):
+ def __init__(self, default_section):
+ OptionParser.__init__(self)
+
+ self.add_option("--section", default=default_section)
+
+ # We don't know defaults yet...
+ self.add_option("--database")
+ self.add_option("--brokers")
+ self.add_option("--log-file")
+ self.add_option("--log-level")
+ self.add_option("--debug", action="store_true")
+ self.add_option("--init-only", action="store_true")
+
+ def set_defaults_from_section(self, section):
+ # Careful, parser replaces '-' with '_' in dest fields
+ self.set_default("database", section.database)
+ self.set_default("brokers", section.brokers)
+ self.set_default("log_file", section.log_file)
+ self.set_default("log_level", section.log_level)
+ self.set_default("debug", section.debug)
+
+class CuminWebOptionParser(CuminMultiOptionParser):
+ def __init__(self, default_section):
+ super(CuminWebOptionParser, self).__init__(default_section)
+
+ # Add additional parameters for web
+ self.add_option("--host")
+ self.add_option("--port", type=int)
+
+ def set_defaults_from_section(self, section):
+ super(CuminWebOptionParser, self).set_defaults_from_section(section)
+
+ # For web, these options also have defaults in config files
+ self.set_default("host", section.host)
+ self.set_default("port", section.port)
+
+class CuminDataOptionParser(CuminMultiOptionParser):
+ def __init__(self, default_section):
+ super(CuminDataOptionParser, self).__init__(default_section)
+
+ # Add additional parameters for data
+ self.add_option("--print-stats", action="store_true")
+ self.add_option("--print-events", type="int", default=0, metavar="LEVEL")
+
def setup_logging(values):
modules = ("cumin", "mint", "parsley", "rosemary", "wooly")
13 years, 3 months
r4466 - branches
by tmckay@fedoraproject.org
Author: tmckay
Date: 2011-01-14 22:38:27 +0000 (Fri, 14 Jan 2011)
New Revision: 4466
Added:
branches/multiples/
Log:
Create a branch from 1.3.2 for configuration changes to support multiple
cumin-web and cumin-data instances.
Copied: branches/multiples (from rev 4465, branches/1.3.2)
13 years, 3 months