rhmessaging commits: r3804 - in mgmt/trunk: cumin/python/cumin and 4 other directories.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2010-01-15 14:57:37 -0500 (Fri, 15 Jan 2010)
New Revision: 3804
Added:
mgmt/trunk/wooly/python/wooly/template.py
Modified:
mgmt/trunk/basil/python/basil/widgets.py
mgmt/trunk/cumin/python/cumin/grid/job.py
mgmt/trunk/cumin/python/cumin/grid/negotiator.py
mgmt/trunk/cumin/python/cumin/grid/slot.py
mgmt/trunk/cumin/python/cumin/messaging/binding.py
mgmt/trunk/cumin/python/cumin/messaging/broker.py
mgmt/trunk/cumin/python/cumin/messaging/queue.py
mgmt/trunk/cumin/python/cumin/stat.py
mgmt/trunk/cumin/python/cumin/widgets.py
mgmt/trunk/misc/boneyard.py
mgmt/trunk/wooly/python/wooly/__init__.py
mgmt/trunk/wooly/python/wooly/pages.py
mgmt/trunk/wooly/python/wooly/sql.py
mgmt/trunk/wooly/python/wooly/tables.py
mgmt/trunk/wooly/python/wooly/widgets.py
Log:
Move template code to its own module, and get rid of a legacy template class
Modified: mgmt/trunk/basil/python/basil/widgets.py
===================================================================
--- mgmt/trunk/basil/python/basil/widgets.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/basil/python/basil/widgets.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -69,7 +69,7 @@
self.start.default = 0
self.add_parameter(self.start)
- self.column_tmpl = Template(self, "column_html")
+ self.column_tmpl = WidgetTemplate(self, "column_html")
def render_back_href(self, session):
branch = session.branch()
Modified: mgmt/trunk/cumin/python/cumin/grid/job.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/job.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/grid/job.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -521,7 +521,7 @@
self.job = job
- self.group_tmpl = Template(self, "group_html")
+ self.group_tmpl = WidgetTemplate(self, "group_html")
def render_groups(self, session):
job = self.job.get(session)
Modified: mgmt/trunk/cumin/python/cumin/grid/negotiator.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/negotiator.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/grid/negotiator.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -505,7 +505,7 @@
def __init__(self, app, name, task):
super(EditPrioFactorForm, self).__init__(app, name, task)
- self.field_tmpl = Template(self, "field_html")
+ self.field_tmpl = WidgetTemplate(self, "field_html")
factor = Parameter(app, "factor")
self.add_parameter(factor)
@@ -606,8 +606,8 @@
def __init__(self, app, name, task):
super(EditDynamicQuotaForm, self).__init__(app, name, task)
- self.field_tmpl = Template(self, "field_html")
- self.unclaimed_tmpl = Template(self, "unclaimed_html")
+ self.field_tmpl = WidgetTemplate(self, "field_html")
+ self.unclaimed_tmpl = WidgetTemplate(self, "unclaimed_html")
quota = Parameter(app, "quota")
self.add_parameter(quota)
@@ -692,7 +692,7 @@
def __init__(self, app, name, task):
super(EditStaticQuotaForm, self).__init__(app, name, task)
- self.field_tmpl = Template(self, "field_html")
+ self.field_tmpl = WidgetTemplate(self, "field_html")
quota = Parameter(app, "quota")
self.add_parameter(quota)
@@ -749,7 +749,7 @@
def __init__(self, app, name, task):
super(EditRegroupForm, self).__init__(app, name, task)
- self.field_tmpl = Template(self, "field_html")
+ self.field_tmpl = WidgetTemplate(self, "field_html")
self.regroup = DictParameter(app, "regroup")
self.add_parameter(self.regroup)
Modified: mgmt/trunk/cumin/python/cumin/grid/slot.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/slot.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/grid/slot.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -387,7 +387,7 @@
self.slot = Attribute(app, "slot")
self.add_attribute(self.slot)
- self.info_div_tmpl = Template(self, "bg_html")
+ self.info_div_tmpl = WidgetTemplate(self, "bg_html")
def do_render(self, session):
index = self.index.get(session)
Modified: mgmt/trunk/cumin/python/cumin/messaging/binding.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/binding.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/messaging/binding.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -1,6 +1,6 @@
import logging
-from wooly import Template, Writer, Attribute, Parameter, Widget
+from wooly import WidgetTemplate, Writer, Attribute, Parameter, Widget
from wooly.forms import FormInput, FormField, Form
from wooly.parameters import DictParameter
from wooly.resources import StringCatalog
@@ -100,8 +100,8 @@
self.exchange = None
self.instance_data = None
- self.name_tmpl = Template(self, "name_html")
- self.key_tmpl = Template(self, "key_html")
+ self.name_tmpl = WidgetTemplate(self, "name_html")
+ self.key_tmpl = WidgetTemplate(self, "key_html")
self.form = None
Modified: mgmt/trunk/cumin/python/cumin/messaging/broker.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/broker.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/messaging/broker.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -280,7 +280,7 @@
def __init__(self, app, name):
super(BrokerBrowser, self).__init__(app, name)
- self.group_tmpl = Template(self, "group_html")
+ self.group_tmpl = WidgetTemplate(self, "group_html")
self.brokers = BrokerSet(app, "brokers")
self.add_child(self.brokers)
Modified: mgmt/trunk/cumin/python/cumin/messaging/queue.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/queue.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/messaging/queue.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -568,7 +568,7 @@
self.sum_props = self.SummaryProperties(app, "properties", queue)
self.add_child(self.sum_props)
- self.prop_tmpl = Template(self, "properties_html")
+ self.prop_tmpl = WidgetTemplate(self, "properties_html")
class SummaryProperties(CuminProperties):
def do_get_items(self, session):
Modified: mgmt/trunk/cumin/python/cumin/stat.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/stat.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/stat.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -119,7 +119,7 @@
self.stats = ()
self.chart_type = None
- self.stats_tmpl = Template(self, "stat_html")
+ self.stats_tmpl = WidgetTemplate(self, "stat_html")
self.duration = JSDurationSwitch(app, "duration")
self.add_child(self.duration)
Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/cumin/python/cumin/widgets.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -197,7 +197,7 @@
summary = CuminSummary(app, "summary", self.object)
self.add_child(summary)
- self.__frame_tmpl = Template(self, "frame_html")
+ self.__frame_tmpl = WidgetTemplate(self, "frame_html")
self.sticky_frame = None
def render_script(self, session):
@@ -322,12 +322,12 @@
def __init__(self, widget, template_key):
super(EditablePropertyRenderer, self).__init__(widget, template_key)
- self.__bool_template = Template(self, "bool_html")
- self.__string_template = Template(self, "string_html")
- self.__bigstring_template = Template(self, "bigstring_html")
- self.__number_template = Template(self, "number_html")
- self.__readonly_template = Template(self, "readonly_html")
- self.__orig_template = Template(self, "orig_html")
+ self.__bool_template = WidgetTemplate(self, "bool_html")
+ self.__string_template = WidgetTemplate(self, "string_html")
+ self.__bigstring_template = WidgetTemplate(self, "bigstring_html")
+ self.__number_template = WidgetTemplate(self, "number_html")
+ self.__readonly_template = WidgetTemplate(self, "readonly_html")
+ self.__orig_template = WidgetTemplate(self, "orig_html")
def render_title(self, session, item):
title = item["name"]
Modified: mgmt/trunk/misc/boneyard.py
===================================================================
--- mgmt/trunk/misc/boneyard.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/misc/boneyard.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -53,8 +53,8 @@
def __init__(self, app, name):
super(ServerBrowser.BrowserGroups, self).__init__(app, name)
- self.type_tmpl = Template(self, "type_html")
- self.group_tmpl = Template(self, "group_html")
+ self.type_tmpl = WidgetTemplate(self, "type_html")
+ self.group_tmpl = WidgetTemplate(self, "group_html")
def get_items(self, session, model):
return sorted_by(model.get_server_group_types())
Modified: mgmt/trunk/wooly/python/wooly/__init__.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/__init__.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/wooly/python/wooly/__init__.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -1,7 +1,3 @@
-import logging
-import os
-import sys
-
from parsley.threadingex import Lifecycle
from cStringIO import StringIO
from urllib import quote, unquote_plus, unquote
@@ -11,39 +7,12 @@
from wooly.profile import *
from resources import ResourceFinder, StringCatalog
+from template import *
from util import *
log = logging.getLogger("wooly")
strings = StringCatalog(__file__)
-class SessionAttribute(object):
- def __init__(self, object, name):
- self.object = object
- self.name = name
- self.default = None
-
- self.key = (self.object, self.name)
-
- def get_default(self, session):
- return copy(self.default)
-
- def get(self, session):
- value = session.get(self.key)
-
- if value is None:
- value = self.get_default(session)
-
- if value is not None:
- self.set(session, value)
-
- return value
-
- def add(self, session, value):
- self.set(session, value)
-
- def set(self, session, value):
- session.set(self.key, value)
-
# XXX make this more definitely WidgetAttribute
class Attribute(object):
def __init__(self, app, name):
@@ -155,8 +124,8 @@
self.page = None
self.frame = None
- self.__main_tmpl = Template(self, "html")
- self.__defer_tmpl = Template(self, "deferred_html")
+ self.__main_tmpl = WidgetTemplate(self, "html")
+ self.__defer_tmpl = WidgetTemplate(self, "deferred_html")
def init(self):
log.debug("Initializing %s" % self)
@@ -695,7 +664,8 @@
self.attributes = dict()
-class StringIOWriter(object):
+
+class Writer(object):
def __init__(self):
self.writer = StringIO()
@@ -709,137 +679,4 @@
return string
-class ListWriter(object):
- def __init__(self):
- self.strings = list()
-
- def write(self, string):
- self.strings.append(string)
-
- def to_string(self):
- return "".join(self.strings)
-
-class Writer(StringIOWriter):
- pass
-
-class ObjectTemplate(object):
- def __init__(self, obj, text):
- self.__object = obj
- self.__text = text
- self.__fragments = None
-
- def compile(self):
- return self.resolve(self.parse(self.__text))
-
- def parse(self, text):
- strings = list()
-
- start = 0
- end = text.find("{")
-
- while True:
- if (end == -1):
- strings.append(text[start:])
- break
-
- strings.append(text[start:end])
-
- ccurly = text.find("}", end + 1)
-
- if ccurly == -1:
- start = end
- end = -1
- else:
- ocurly = text.find("{", end + 1)
-
- if ocurly == -1:
- start = end
- end = ccurly + 1
- elif ocurly < ccurly:
- start = end
- end = ocurly
- else:
- strings.append("{" + text[end + 1:ccurly] + "}")
-
- start = ccurly + 1
- end = ocurly
-
- return strings
-
- def resolve(self, strings):
- fragments = list()
-
- for string in strings:
- if string.startswith("{") and string.endswith("}"):
- name = string[1:-1]
- method = self.find_method("render_" + name)
-
- if method:
- fragments.append(method)
- else:
- child = self.find_child(name)
-
- if child:
- fragments.append(child)
- else:
- fragments.append(string)
- else:
- fragments.append(string)
-
- return fragments
-
- def find_method(self, name):
- for cls in self.__object.__class__.__mro__:
- meth = getattr(cls, name, None)
-
- if meth and callable(meth):
- return meth
-
- def find_child(self, name):
- return None
-
- def render(self, writer, session, *args):
- # XXX do this in an init method instead
- if not self.__fragments:
- self.__fragments = self.compile()
-
- for frag in self.__fragments:
- if type(frag) is str:
- writer.write(frag)
- elif callable(frag):
- #print "tc", frag, args
-
- result = frag(self.__object, session, *args)
-
- if result is not None:
- writer.write(str(result))
- else:
- result = frag.render(session)
-
- if result is not None:
- writer.write(str(result))
-
- def __repr__(self):
- name = self.__object.__class__.__name__ + "." + self.key
- return "%s('%s')" % (self.__class__.__name__, name)
-
-class WidgetTemplate(ObjectTemplate):
- def __init__(self, widget, key):
- text = widget.get_string(key)
-
- if not text:
- raise Exception("Template '%s.%s' not found" \
- % (widget.__class__.__name__, key))
-
- super(WidgetTemplate, self).__init__(widget, text)
-
- self.widget = widget
-
- def find_child(self, name):
- return self.widget.children_by_name.get(name)
-
-# XXX eliminate this leftover alias
-class Template(WidgetTemplate):
- pass
-
from pages import ResourcePage
Modified: mgmt/trunk/wooly/python/wooly/pages.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/pages.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/wooly/python/wooly/pages.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -174,7 +174,7 @@
def __init__(self, app, name, html_page):
super(UpdatePage, self).__init__(app, name)
- self.widget_tmpl = Template(self, "widget_html")
+ self.widget_tmpl = WidgetTemplate(self, "widget_html")
self.html_page = html_page
Modified: mgmt/trunk/wooly/python/wooly/sql.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/sql.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/wooly/python/wooly/sql.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -1,10 +1,38 @@
-import logging
+from resources import *
+from template import *
+from util import *
-from wooly import *
-
strings = StringCatalog(__file__)
log = logging.getLogger("wooly.sql")
+class SessionAttribute(object):
+ def __init__(self, object, name):
+ self.object = object
+ self.name = name
+ self.default = None
+
+ self.key = (self.object, self.name)
+
+ def get_default(self, session):
+ return copy(self.default)
+
+ def get(self, session):
+ value = session.get(self.key)
+
+ if value is None:
+ value = self.get_default(session)
+
+ if value is not None:
+ self.set(session, value)
+
+ return value
+
+ def add(self, session, value):
+ self.set(session, value)
+
+ def set(self, session, value):
+ session.set(self.key, value)
+
class SqlOperation(object):
def __init__(self, app):
super(SqlOperation, self).__init__()
Modified: mgmt/trunk/wooly/python/wooly/tables.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/tables.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/wooly/python/wooly/tables.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -207,9 +207,9 @@
def __init__(self, app, name):
super(SqlTable, self).__init__(app, name)
- self.__sql_tmpl = Template(self, "sql")
- self.__count_sql_tmpl = Template(self, "count_sql")
- self.__find_sql_tmpl = Template(self, "find_sql")
+ self.__sql_tmpl = WidgetTemplate(self, "sql")
+ self.__count_sql_tmpl = WidgetTemplate(self, "count_sql")
+ self.__find_sql_tmpl = WidgetTemplate(self, "find_sql")
def render_sql(self, session, *args):
writer = Writer()
Added: mgmt/trunk/wooly/python/wooly/template.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/template.py (rev 0)
+++ mgmt/trunk/wooly/python/wooly/template.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -0,0 +1,117 @@
+from util import *
+
+class ObjectTemplate(object):
+ def __init__(self, obj, text):
+ self.__object = obj
+ self.__text = text
+ self.__fragments = None
+
+ def compile(self):
+ return self.resolve(self.parse(self.__text))
+
+ def parse(self, text):
+ strings = list()
+
+ start = 0
+ end = text.find("{")
+
+ while True:
+ if (end == -1):
+ strings.append(text[start:])
+ break
+
+ strings.append(text[start:end])
+
+ ccurly = text.find("}", end + 1)
+
+ if ccurly == -1:
+ start = end
+ end = -1
+ else:
+ ocurly = text.find("{", end + 1)
+
+ if ocurly == -1:
+ start = end
+ end = ccurly + 1
+ elif ocurly < ccurly:
+ start = end
+ end = ocurly
+ else:
+ strings.append("{" + text[end + 1:ccurly] + "}")
+
+ start = ccurly + 1
+ end = ocurly
+
+ return strings
+
+ def resolve(self, strings):
+ fragments = list()
+
+ for string in strings:
+ if string.startswith("{") and string.endswith("}"):
+ name = string[1:-1]
+ method = self.find_method("render_" + name)
+
+ if method:
+ fragments.append(method)
+ else:
+ child = self.find_child(name)
+
+ if child:
+ fragments.append(child)
+ else:
+ fragments.append(string)
+ else:
+ fragments.append(string)
+
+ return fragments
+
+ def find_method(self, name):
+ for cls in self.__object.__class__.__mro__:
+ meth = getattr(cls, name, None)
+
+ if meth and callable(meth):
+ return meth
+
+ def find_child(self, name):
+ return None
+
+ def render(self, writer, session, *args):
+ # XXX do this in an init method instead
+ if not self.__fragments:
+ self.__fragments = self.compile()
+
+ for frag in self.__fragments:
+ if type(frag) is str:
+ writer.write(frag)
+ elif callable(frag):
+ #print "tc", frag, args
+
+ result = frag(self.__object, session, *args)
+
+ if result is not None:
+ writer.write(str(result))
+ else:
+ result = frag.render(session)
+
+ if result is not None:
+ writer.write(str(result))
+
+ def __repr__(self):
+ name = self.__object.__class__.__name__ + "." + self.key
+ return "%s('%s')" % (self.__class__.__name__, name)
+
+class WidgetTemplate(ObjectTemplate):
+ def __init__(self, widget, key):
+ text = widget.get_string(key)
+
+ if not text:
+ raise Exception("Template '%s.%s' not found" \
+ % (widget.__class__.__name__, key))
+
+ super(WidgetTemplate, self).__init__(widget, text)
+
+ self.widget = widget
+
+ def find_child(self, name):
+ return self.widget.children_by_name.get(name)
Modified: mgmt/trunk/wooly/python/wooly/widgets.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/widgets.py 2010-01-15 18:47:52 UTC (rev 3803)
+++ mgmt/trunk/wooly/python/wooly/widgets.py 2010-01-15 19:57:37 UTC (rev 3804)
@@ -52,7 +52,7 @@
super(TabbedModeSet, self).__init__(app, name)
self.__tabs = list()
- self.__tab_tmpl = Template(self, "tab_html")
+ self.__tab_tmpl = WidgetTemplate(self, "tab_html")
def add_tab(self, tab):
self.__tabs.append(tab)
@@ -86,7 +86,7 @@
def __init__(self, app, name):
super(WidgetSet, self).__init__(app, name)
- self.__widget_tmpl = Template(self, "widget_html")
+ self.__widget_tmpl = WidgetTemplate(self, "widget_html")
def render_widgets(self, session, *args):
writer = Writer()
@@ -106,7 +106,7 @@
super(LinkSet, self).__init__(app, name)
self.__links = list()
- self.__link_tmpl = Template(self, "link_html")
+ self.__link_tmpl = WidgetTemplate(self, "link_html")
def add_link(self, link):
self.__links.append(link)
@@ -172,7 +172,7 @@
self.items = Attribute(app, "items")
self.add_attribute(self.items)
- self.item_tmpl = Template(self, "item_html")
+ self.item_tmpl = WidgetTemplate(self, "item_html")
def get_item_count(self, session, *args):
return len(self.get_items(session, *args))
14 years, 11 months
rhmessaging commits: r3803 - in mgmt/trunk/cumin/python/cumin: grid and 1 other directories.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2010-01-15 13:47:52 -0500 (Fri, 15 Jan 2010)
New Revision: 3803
Modified:
mgmt/trunk/cumin/python/cumin/grid/job.py
mgmt/trunk/cumin/python/cumin/messaging/brokergroup.py
mgmt/trunk/cumin/python/cumin/messaging/brokerlink.py
mgmt/trunk/cumin/python/cumin/messaging/queue.py
mgmt/trunk/cumin/python/cumin/widgets.py
Log:
CuminFieldForm is no longer used
Modified: mgmt/trunk/cumin/python/cumin/grid/job.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/job.py 2010-01-15 18:21:06 UTC (rev 3802)
+++ mgmt/trunk/cumin/python/cumin/grid/job.py 2010-01-15 18:47:52 UTC (rev 3803)
@@ -907,7 +907,7 @@
def render_title(self, session, *args):
return "Job Groups"
-class JobReasonForm(CuminFieldForm):
+class JobReasonForm(FieldSubmitForm):
def __init__(self, app, name, task, verb):
super(JobReasonForm, self).__init__(app, name)
Modified: mgmt/trunk/cumin/python/cumin/messaging/brokergroup.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/brokergroup.py 2010-01-15 18:21:06 UTC (rev 3802)
+++ mgmt/trunk/cumin/python/cumin/messaging/brokergroup.py 2010-01-15 18:47:52 UTC (rev 3803)
@@ -89,7 +89,7 @@
self.tabs.add_tab(CuminDetails(app, "details", group))
-class BrokerGroupForm(CuminFieldForm):
+class BrokerGroupForm(FieldSubmitForm):
def __init__(self, app, name, task):
super(BrokerGroupForm, self).__init__(app, name)
Modified: mgmt/trunk/cumin/python/cumin/messaging/brokerlink.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/brokerlink.py 2010-01-15 18:21:06 UTC (rev 3802)
+++ mgmt/trunk/cumin/python/cumin/messaging/brokerlink.py 2010-01-15 18:47:52 UTC (rev 3803)
@@ -301,7 +301,7 @@
def render_title(self, session):
return "Choose an Exchange"
-class RouteAddForm(CuminFieldForm):
+class RouteAddForm(FieldSubmitForm):
def __init__(self, app, name, task):
super(RouteAddForm, self).__init__(app, name)
@@ -410,7 +410,7 @@
self.object = ListParameter(app, "route", item)
self.add_parameter(self.object)
-class LinkForm(CuminFieldForm):
+class LinkForm(FieldSubmitForm):
def __init__(self, app, name):
super(LinkForm, self).__init__(app, name)
Modified: mgmt/trunk/cumin/python/cumin/messaging/queue.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/queue.py 2010-01-15 18:21:06 UTC (rev 3802)
+++ mgmt/trunk/cumin/python/cumin/messaging/queue.py 2010-01-15 18:47:52 UTC (rev 3803)
@@ -244,7 +244,7 @@
return "Exchange Bindings %s" % \
fmt_count(queue.bindings.count())
-class QueueAddForm(CuminFieldForm):
+class QueueAddForm(FieldSubmitForm):
def __init__(self, app, name, task):
super(QueueAddForm, self).__init__(app, name)
@@ -587,7 +587,7 @@
def render_prop_items(self, session):
return self.sum_props.render_items(session)
-class BindingAddForm(CuminFieldForm):
+class BindingAddForm(FieldSubmitForm):
def __init__(self, app, name, task):
super(BindingAddForm, self).__init__(app, name)
@@ -807,7 +807,7 @@
return queue is self.param.get(session) \
and "checked=\"checked\"" or None
-class MoveMessagesForm(CuminFieldForm):
+class MoveMessagesForm(FieldSubmitForm):
def __init__(self, app, name, task):
super(MoveMessagesForm, self).__init__(app, name)
Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py 2010-01-15 18:21:06 UTC (rev 3802)
+++ mgmt/trunk/cumin/python/cumin/widgets.py 2010-01-15 18:47:52 UTC (rev 3803)
@@ -301,10 +301,6 @@
def render_help_href(self, session, *args):
return "resource?name=help.html#%s" % self.path
-# XXX get rid of this!
-class CuminFieldForm(FieldSubmitForm, Frame):
- pass
-
class CuminEditableProperties(PropertySet):
def __init__(self, app, name):
self.item_renderer=EditablePropertyRenderer(self, "property_html")
14 years, 11 months
rhmessaging commits: r3802 - in mgmt/trunk: cumin/python/cumin/account and 3 other directories.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2010-01-15 13:21:06 -0500 (Fri, 15 Jan 2010)
New Revision: 3802
Modified:
mgmt/trunk/cumin/python/cumin/account/widgets.py
mgmt/trunk/cumin/python/cumin/grid/submission.py
mgmt/trunk/cumin/python/cumin/messaging/brokergroup.py
mgmt/trunk/cumin/python/cumin/messaging/brokerlink.py
mgmt/trunk/cumin/python/cumin/messaging/exchange.py
mgmt/trunk/cumin/python/cumin/messaging/queue.py
mgmt/trunk/cumin/python/cumin/widgets.py
mgmt/trunk/wooly/python/wooly/__init__.py
mgmt/trunk/wooly/python/wooly/forms.py
Log:
* Improve logging in wooly, especially in the setup phase
* Now that we have proper logging, Widget.test is not needed to
clarify where an assertion failure comes from; stop using it in
favor of simple assertions
* Refactor the init methods on Widget, Page, and Form
* Reclaim the name validate for form input checking; later we'll use
"check" for the post-init check
Modified: mgmt/trunk/cumin/python/cumin/account/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/account/widgets.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/account/widgets.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -109,7 +109,7 @@
name = self.user_name.get(session)
password = self.password.get(session)
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
try:
@@ -169,8 +169,8 @@
self.new1.input.size = 20
self.add_field(self.new1)
- def check(self, session):
- super(ChangePasswordForm, self).check(session)
+ def validate(self, session):
+ super(ChangePasswordForm, self).validate(session)
current = self.current.get(session)
new0 = self.new0.get(session)
@@ -188,7 +188,7 @@
self.errors.add(session, error)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
user = session.client_session.attributes["login_session"].user
Modified: mgmt/trunk/cumin/python/cumin/grid/submission.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/submission.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/grid/submission.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -169,12 +169,12 @@
self.attributes_.input.columns = 50
self.extra_fields.add_field(self.attributes_)
- def check(self, session):
- self.main_fields.check(session)
- self.extra_fields.check(session)
+ def validate(self, session):
+ self.main_fields.validate(session)
+ self.extra_fields.validate(session)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
scheduler = self.scheduler.get(session)
Modified: mgmt/trunk/cumin/python/cumin/messaging/brokergroup.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/brokergroup.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/messaging/brokergroup.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -100,7 +100,7 @@
class BrokerGroupAddForm(BrokerGroupForm):
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
name = self.group_name.get(session)
@@ -119,7 +119,7 @@
self.add_parameter(self.group)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
group = self.group.get(session)
Modified: mgmt/trunk/cumin/python/cumin/messaging/brokerlink.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/brokerlink.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/messaging/brokerlink.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -379,7 +379,7 @@
pass
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
link = self.link.get(session)
@@ -532,7 +532,7 @@
return self.task.get_description(session, vhost)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
vhost = self.vhost.get(session)
Modified: mgmt/trunk/cumin/python/cumin/messaging/exchange.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/exchange.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/messaging/exchange.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -367,7 +367,7 @@
self.extra_fields.add_field(self.args)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
vhost = self.vhost.get(session)
Modified: mgmt/trunk/cumin/python/cumin/messaging/queue.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/messaging/queue.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/messaging/queue.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -292,11 +292,6 @@
self.bindings = ExchangeKeysField(app, "bindings", self.vhost)
self.add_field(self.bindings)
- def validate(self, session, queue_name):
- super_error = super(QueueAddForm, self).validate(session)
- (errors, form_binding_info) = self.bindings.get_binding_errors(session, queue_name)
- return (errors or super_error, form_binding_info)
-
class AdvancedOptions(MoreFieldSet):
def render_title(self, session):
return "Advanced Options"
@@ -451,9 +446,17 @@
durable = self.durable.get(session)
policy = self.policy.get(session)
- errors, binding_info = self.validate(session, name)
+ self.validate(session)
+ errors = self.errors.get(session)
+
+ binding_errors, binding_info = self.bindings.get_binding_errors \
+ (session, name)
+
if not errors:
+ errors = binding_errors
+
+ if not errors:
invoc = self.task.start(session, vhost)
try:
@@ -531,7 +534,7 @@
return self.task.get_description(session, queue)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
queue = self.queue.get(session)
@@ -820,7 +823,7 @@
self.add_field(self.count)
def process_submit(self, session):
- self.check(session)
+ self.validate(session)
if not self.errors.get(session):
queue = self.queue.get(session)
Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/cumin/python/cumin/widgets.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -303,9 +303,7 @@
# XXX get rid of this!
class CuminFieldForm(FieldSubmitForm, Frame):
- def validate(self, session):
- self.check(session)
- return self.errors.get(session)
+ pass
class CuminEditableProperties(PropertySet):
def __init__(self, app, name):
@@ -1094,7 +1092,7 @@
def render_title(self, session):
return "Name"
- def check(self, session):
+ def validate(self, session):
name = self.get(session)
if name == "" and self.required:
@@ -1145,8 +1143,8 @@
def set_object_attr(self, attr):
self.__object = attr
- def check(self, session):
- super(UniqueNameField, self).check(session)
+ def validate(self, session):
+ super(UniqueNameField, self).validate(session)
name = self.get(session)
Modified: mgmt/trunk/wooly/python/wooly/__init__.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/__init__.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/wooly/python/wooly/__init__.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -13,6 +13,7 @@
from resources import ResourceFinder, StringCatalog
from util import *
+log = logging.getLogger("wooly")
strings = StringCatalog(__file__)
class SessionAttribute(object):
@@ -55,13 +56,16 @@
self.path = None
def init(self):
- #print "Initializing %s" % str(self)
+ log.debug("Initializing %s", self)
if self.widget and self.widget.path:
self.path = ".".join((self.widget.path, self.name))
else:
self.path = self.name
+ def check_me_merrily(self):
+ log.debug("Checking %s", self)
+
def validate(self, session):
value = self.get(session)
@@ -145,7 +149,7 @@
self.update_enabled = False
self.defer_enabled = False
- # These are set in the init() pass
+ # These are computed later in the init pass
self.ancestors = None
self.path = None
self.page = None
@@ -154,18 +158,27 @@
self.__main_tmpl = Template(self, "html")
self.__defer_tmpl = Template(self, "deferred_html")
- def test(self, expr, message=None):
- if not expr:
- if not message:
- message = "Correctness breached"
+ def init(self):
+ log.debug("Initializing %s" % self)
- raise Exception("[%s] %s" % (self, message))
+ self.init_computed_values()
- def init(self):
- #print "Initializing %s" % str(self)
+ if self.page:
+ self.page.init_widget(self)
- self.test(not self.sealed)
+ for attr in self.attributes:
+ attr.init()
+ for param in self.parameters:
+ param.init()
+
+ for child in self.children:
+ child.init()
+
+ assert not self.sealed
+ self.sealed = True
+
+ def init_computed_values(self):
ancestors = list()
widget = self.parent
@@ -173,11 +186,6 @@
ancestors.append(widget)
widget = widget.parent
- for widget in ancestors:
- if isinstance(widget, Frame):
- self.frame = widget
- break
-
self.ancestors = tuple(ancestors)
pelems = [x.name for x in reversed(ancestors)]
@@ -185,49 +193,45 @@
self.path = ".".join(pelems[1:])
self.page = self.ancestors[-1]
- self.page.init_widget(self)
- self.sealed = True
+ for widget in ancestors:
+ if isinstance(widget, Frame):
+ self.frame = widget
+ break
- self.init_children()
+ def check_me_merrily(self):
+ assert self.sealed
+ assert self.path is not None
+ assert isinstance(self.page, Page)
- def init_children(self):
for attr in self.attributes:
- attr.init()
+ attr.check_me_merrily()
- for param in self.parameters:
- param.init()
+ for param in self.attributes:
+ param.check_me_merrily()
for child in self.children:
- child.init()
-
- def check_me_merrily(self):
- self.test(self.sealed)
- self.test(self.path is not None)
- self.test(isinstance(self.page, Page))
-
- for child in self.children:
child.check_me_merrily()
def add_child(self, child):
- self.test(not self.sealed)
- self.test(isinstance(child, Widget))
- self.test(child is not self)
+ assert not self.sealed
+ assert isinstance(child, Widget)
+ assert child is not self
self.children.append(child)
self.children_by_name[child.name] = child
child.parent = self
def add_attribute(self, attribute):
- self.test(not self.sealed)
- self.test(isinstance(attribute, Attribute))
+ assert not self.sealed
+ assert isinstance(attribute, Attribute)
self.attributes.append(attribute)
attribute.widget = self
def add_parameter(self, parameter):
- self.test(not self.sealed)
- self.test(isinstance(parameter, Parameter))
+ assert not self.sealed
+ assert isinstance(parameter, Parameter)
self.parameters.append(parameter)
parameter.widget = self
@@ -262,7 +266,7 @@
return str
def show(self, session):
- self.test(self.parent)
+ assert self.parent
self.parent.show_child(session, self)
self.parent.show(session)
@@ -396,30 +400,22 @@
self.profile = self.ProfileAttribute(app, "profile")
self.add_attribute(self.profile)
- def init(self):
- self.test(not self.sealed)
- self.test(self.parent is None)
-
+ def init_computed_values(self):
self.ancestors = ()
self.path = ""
self.page = self
self.frame = self
- self.init_widget(self)
- self.init_children()
-
- self.sealed = True
-
def init_widget(self, widget):
- self.test(not self.sealed)
- self.test(isinstance(widget, Widget))
+ assert not self.sealed
+ assert isinstance(widget, Widget)
self.page_widgets.append(widget)
self.page_widgets_by_path[widget.path] = widget
def init_parameter(self, param):
- self.test(not self.sealed)
- self.test(isinstance(param, Parameter))
+ assert not self.sealed
+ assert isinstance(param, Parameter)
self.page_parameters.append(param)
self.page_parameters_by_path[param.path] = param
Modified: mgmt/trunk/wooly/python/wooly/forms.py
===================================================================
--- mgmt/trunk/wooly/python/wooly/forms.py 2010-01-14 17:21:38 UTC (rev 3801)
+++ mgmt/trunk/wooly/python/wooly/forms.py 2010-01-15 18:21:06 UTC (rev 3802)
@@ -1,8 +1,10 @@
-from wooly import *
from parameters import *
from resources import *
+from util import *
from widgets import ItemSet, escape_entity
+from wooly import *
+log = logging.getLogger("wooly.forms")
strings = StringCatalog(__file__)
class Form(Widget):
@@ -14,8 +16,8 @@
self.form_params = set()
- def check(self, session):
- pass
+ def validate(self, session):
+ log.debug("Validating %s", self)
def render_hidden_inputs(self, session, *args):
writer = Writer()
@@ -64,7 +66,7 @@
if isinstance(anc, Form):
self.form = anc
- self.test(self.form, "Not inside a form")
+ assert self.form # Not inside a form
def get_items(self, session, *args):
return self.form.errors.get(session)
@@ -91,15 +93,14 @@
def init(self):
super(FormInput, self).init()
- self.test(self.param, "Parameter not set")
-
+ assert self.param # Parameter not set
assert isinstance(self.param, Parameter)
for anc in self.ancestors:
if isinstance(anc, Form):
self.form = anc
- self.test(self.form, "Not inside a form")
+ assert self.form # Not inside a form
self.form.form_params.add(self.param)
@@ -327,16 +328,19 @@
self.required = False
self.help = None
- def init(self):
- super(FormField, self).init()
+ def init_computed_values(self):
+ super(FormField, self).init_computed_values()
for anc in self.ancestors:
if isinstance(anc, Form):
self.form = anc
- self.test(self.form, "Not inside a form")
+ def check_me_merrily(self):
+ super(FormField, self).check_me_merrily()
- def check(self, session):
+ assert self.form # Not inside a form
+
+ def validate(self, session):
pass
def render_required(self, session, *args):
@@ -362,9 +366,9 @@
self.fields.append(field)
self.add_child(field)
- def check(self, session):
+ def validate(self, session):
for field in self.fields:
- field.check(session)
+ field.validate(session)
def render_message(self, session, *args):
pass
@@ -399,7 +403,7 @@
def set(self, session, value):
return self.input.set(session, value)
- def check(self, session):
+ def validate(self, session):
value = self.get(session)
if value in ("", None) and self.required:
@@ -437,7 +441,7 @@
self.input = IntegerInput(app, "input")
self.add_child(self.input)
- def check(self, session):
+ def validate(self, session):
value = self.get(session)
if value:
@@ -631,10 +635,10 @@
def add_field(self, field):
self.content.add_field(field)
- def check(self, session):
- super(FieldSubmitForm, self).check(session)
+ def validate(self, session):
+ super(FieldSubmitForm, self).validate(session)
- self.content.check(session)
+ self.content.validate(session)
def render_content(self, session, *args):
return self.content.render(session, *args)
@@ -652,11 +656,11 @@
self.extra_fields = ShowableFieldSet(app, "extra")
self.content.add_child(self.extra_fields)
- def check(self, session):
- super(FoldingFieldSubmitForm, self).check(session)
+ def validate(self, session):
+ super(FoldingFieldSubmitForm, self).validate(session)
- self.main_fields.check(session)
- self.extra_fields.check(session)
+ self.main_fields.validate(session)
+ self.extra_fields.validate(session)
def render_content(self, session, *args):
return self.content.render(session, *args)
14 years, 11 months
rhmessaging commits: r3801 - store/branches/java/0.5-release/src/test/java/org/apache/qpid/server/store/berkeleydb.
by rhmessaging-commits@lists.jboss.org
Author: rgemmell
Date: 2010-01-14 12:21:38 -0500 (Thu, 14 Jan 2010)
New Revision: 3801
Added:
store/branches/java/0.5-release/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaroundTest.java
Log:
Add unit testing for the bindings workaround tool
Added: store/branches/java/0.5-release/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaroundTest.java
===================================================================
--- store/branches/java/0.5-release/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaroundTest.java (rev 0)
+++ store/branches/java/0.5-release/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaroundTest.java 2010-01-14 17:21:38 UTC (rev 3801)
@@ -0,0 +1,335 @@
+package org.apache.qpid.server.store.berkeleydb;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.qpid.exchange.ExchangeDefaults;
+import org.apache.qpid.framing.AMQShortString;
+import org.apache.qpid.server.configuration.VirtualHostConfiguration;
+import org.apache.qpid.server.exchange.DirectExchange;
+import org.apache.qpid.server.exchange.Exchange;
+import org.apache.qpid.server.exchange.ExchangeFactory;
+import org.apache.qpid.server.exchange.ExchangeRegistry;
+import org.apache.qpid.server.queue.AMQQueue;
+import org.apache.qpid.server.queue.AMQQueueFactory;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.util.NullApplicationRegistry;
+import org.apache.qpid.server.virtualhost.VirtualHost;
+
+public class BDBStoreBindingsWorkaroundTest extends TestCase
+{
+ private final static String STORE_PARENT_LOC = System.getProperty("QPID_WORK") + File.separator + "BindingsWorkaroundTest";
+
+ private static BDBMessageStore _store;
+ private VirtualHost _virtualHost;
+ private File BDB_DIR;
+
+ public void setUp() throws Exception
+ {
+ if(System.getProperty("QPID_HOME") == null)
+ {
+ fail("QPID_HOME is not set");
+ }
+
+ if(System.getProperty("QPID_WORK") == null)
+ {
+ fail("QPID_WORK is not set");
+ }
+
+ BDB_DIR = new File(STORE_PARENT_LOC + getName());
+
+ if (BDB_DIR.exists())
+ {
+ if(!deleteDirectory(BDB_DIR))
+ {
+ fail("Unable to clean existing BDB directory");
+ }
+ }
+
+ BDB_DIR.mkdirs();
+
+ ApplicationRegistry.initialise(new NullApplicationRegistry());
+
+ _store = new BDBMessageStore();
+ _store.configure(BDB_DIR);
+
+ PropertiesConfiguration config = new PropertiesConfiguration();
+
+ VirtualHostConfiguration vhostConfig = new VirtualHostConfiguration("test", config);
+
+ _virtualHost = new VirtualHost(vhostConfig, _store);
+ _store.setVirtualHost(_virtualHost);
+ }
+
+ public void tearDown() throws Exception
+ {
+ ApplicationRegistry.removeAll();
+
+ if (BDB_DIR.exists())
+ {
+ deleteDirectory(BDB_DIR);
+ }
+ }
+
+ private void reload() throws Exception
+ {
+ _virtualHost.close();
+
+ PropertiesConfiguration env = new PropertiesConfiguration();
+
+ env.addProperty("store.environment-path", BDB_DIR.getAbsolutePath());
+ env.addProperty("store.class", "org.apache.qpid.server.store.berkeleydb.BDBMessageStore");
+
+ _virtualHost = new VirtualHost(new VirtualHostConfiguration("test", env), null);
+
+ _store = (BDBMessageStore) _virtualHost.getMessageStore();
+ }
+
+ /**
+ * This tests that the queue bindings are NOT recovered. If this test fails, then the
+ * bindings were recovered and the default exchanges are already in the store provided.
+ */
+ public void testBindingsAreActuallyBroken() throws Exception
+ {
+ AMQShortString queueName = new AMQShortString("testBindingsAreBroken");
+ AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(queueName, true, queueName, false, _virtualHost, null);
+
+ _store.createQueue(queue, null);
+
+ AMQShortString routingKey = new AMQShortString("testBindingsAreBroken-Key");
+
+ _store.bindQueue(_virtualHost.getExchangeRegistry().getDefaultExchange(), routingKey, queue, null);
+
+ reload();
+
+ AMQQueue returnedQueue = _virtualHost.getQueueRegistry().getQueue(queueName);
+
+ assertNotNull("Exchange binding were null.", returnedQueue.getExchangeBindings());
+ assertEquals("Unexpected binding count for queue. Expected 0 bindings due to be " +
+ "recovered due to default exchanges not being entered in the store.",
+ 0, returnedQueue.getExchangeBindings().size());
+ }
+
+ /**
+ * This tests that the start method throws a FNFE when an invalid config location is specified.
+ * This is caught within the tools main() method normally.
+ */
+ public void testNonExistantConfig() throws Exception
+ {
+ BDBStoreBindingsWorkaround tool = new BDBStoreBindingsWorkaround(
+ new String[]{"-c ", String.valueOf(System.currentTimeMillis())});
+ try
+ {
+ tool.start();
+ fail("Should have thrown FileNotFoundException");
+ }
+ catch(FileNotFoundException e)
+ {
+ //expected exception
+ }
+ }
+
+ /**
+ * This tests checks that the expected Exchange names are recovered from the store.
+ */
+ public void testGetBDBExchangeNames() throws Exception
+ {
+ //verify current exchange count is 0
+ List<AMQShortString> bdbExchanges = BDBStoreBindingsWorkaround.getBDBStoreExchangeNames(_virtualHost, _store);
+ assertEquals("Unexpected existing Exchange names in the store", 0, bdbExchanges.size());
+
+ ExchangeFactory exchangeFactory = _virtualHost.getExchangeFactory();
+ ExchangeRegistry exchangeRegistry = _virtualHost.getExchangeRegistry();
+
+ //Add a new exchange to the store
+ AMQShortString exchangeName1 = new AMQShortString("testGetBDBExchangeNames1");
+ Exchange exchange1 = exchangeFactory.createExchange(exchangeName1, DirectExchange.TYPE.getName(), true, false, 0);
+ assertNotNull("Exchange is null", exchange1);
+
+ //registering currently creates the store entry as a side-effect
+ exchangeRegistry.registerExchange(exchange1);
+
+ bdbExchanges = BDBStoreBindingsWorkaround.getBDBStoreExchangeNames(_virtualHost, _store);
+ assertEquals("Expected 1 exchanges names to be returned in the name list", 1, bdbExchanges.size());
+ assertTrue("The expected exchange name was not present", bdbExchanges.contains(exchangeName1));
+
+ //Add another new exchange to the store
+ AMQShortString exchangeName2 = new AMQShortString("testGetBDBExchangeNames2");
+ Exchange exchange2 = exchangeFactory.createExchange(exchangeName2, DirectExchange.TYPE.getName(), true, false, 0);
+ assertNotNull("Exchange is null", exchange2);
+
+ //registering currently creates the store entry as a side-effect
+ exchangeRegistry.registerExchange(exchange2);
+
+ bdbExchanges = BDBStoreBindingsWorkaround.getBDBStoreExchangeNames(_virtualHost, _store);
+ assertEquals("Expected 2 exchanges names to be returned in the name list", 2, bdbExchanges.size());
+ assertTrue("The expected exchange names were not present", bdbExchanges.contains(exchangeName1));
+ assertTrue("The expected exchange names were not present", bdbExchanges.contains(exchangeName2));
+ }
+
+ /**
+ * This tests checks that given a vhost, any durable exchanges in the registry that are not
+ * already in the store are then added to it.
+ */
+ public void testAddDurableExchangesToStoreIfRequired() throws Exception
+ {
+ ExchangeFactory exchangeFactory = _virtualHost.getExchangeFactory();
+ ExchangeRegistry exchangeRegistry = _virtualHost.getExchangeRegistry();
+
+ //Create a new durable exchange and but dont register it(a side effect will add it to store)
+ AMQShortString durExchangeName = new AMQShortString("testAddDurableExchangesToStoreIfRequired.Durable");
+ Exchange durExchange = exchangeFactory.createExchange(durExchangeName, DirectExchange.TYPE.getName(), true, false, 0);
+ assertNotNull("Exchange is null", durExchange);
+
+ //Create a new non-durable exchange and but dont register it
+ AMQShortString transExchangeName = new AMQShortString("testAddDurableExchangesToStoreIfRequired.Transient");
+ Exchange transExchange = exchangeFactory.createExchange(transExchangeName, DirectExchange.TYPE.getName(), false, false, 0);
+ assertNotNull("Exchange is null", transExchange);
+
+ //verify current exchange count in the registry is 5 and verify the names (<<default>>, amq.[direct|topic|match|fanout])
+ Collection<AMQShortString> exNames = exchangeRegistry.getExchangeNames();
+ assertEquals("Unexpected number of exchanges in the registry", 5, exNames.size());
+ assertTrue(exNames.contains(ExchangeDefaults.DEFAULT_EXCHANGE_NAME));
+ assertTrue(exNames.contains(ExchangeDefaults.DIRECT_EXCHANGE_NAME));
+ assertTrue(exNames.contains(ExchangeDefaults.TOPIC_EXCHANGE_NAME));
+ assertTrue(exNames.contains(ExchangeDefaults.FANOUT_EXCHANGE_NAME));
+ assertTrue(exNames.contains(ExchangeDefaults.HEADERS_EXCHANGE_NAME));
+
+ //create a list of the Exchanges from the registry, plus the 2 created above
+ final List<Exchange> exList = new ArrayList<Exchange>();
+
+ for(AMQShortString name : exNames)
+ {
+ Exchange ex = exchangeRegistry.getExchange(name);
+ exList.add(ex);
+ }
+ exList.add(transExchange);
+ exList.add(durExchange);
+
+ Collection<VirtualHost> vhosts = new ArrayList<VirtualHost>();
+ vhosts.add(_virtualHost);
+
+ /**
+ * Override the getVhostExchanges to allow defining the list of Exchanges that the
+ * registry supposedly holds. This is required to allow returning a new non-default/amq.
+ * durable exchange that isnt already in the store, as exchange registration will
+ * currently also add it to the store.
+ */
+ BDBStoreBindingsWorkaround tool = new BDBStoreBindingsWorkaround(new String[]{})
+ {
+ protected List<Exchange> getVhostExchanges(VirtualHost vhost)
+ {
+ return exList;
+ }
+ };
+
+ //use the tool to add the records to the store if required
+ tool.addDurableExchangesToStoreIfRequired(vhosts);
+
+ //reload the vhost and recover the store.
+ reload();
+
+ exchangeFactory = _virtualHost.getExchangeFactory();
+ exchangeRegistry = _virtualHost.getExchangeRegistry();
+
+ //verify current exchange count in the registry is now 6 and verify the
+ //names (<<default>>, amq.[direct|topic|match|fanout]) + durable one created above.
+ exNames = exchangeRegistry.getExchangeNames();
+ assertEquals("Unexpected number of exchanges in the registry", 6, exNames.size());
+ assertTrue(exNames.contains(ExchangeDefaults.DEFAULT_EXCHANGE_NAME));
+ assertTrue(exNames.contains(ExchangeDefaults.DIRECT_EXCHANGE_NAME));
+ assertTrue(exNames.contains(ExchangeDefaults.TOPIC_EXCHANGE_NAME));
+ assertTrue(exNames.contains(ExchangeDefaults.FANOUT_EXCHANGE_NAME));
+ assertTrue(exNames.contains(ExchangeDefaults.HEADERS_EXCHANGE_NAME));
+ assertTrue(exNames.contains(durExchangeName));
+
+ //also confirm the names in the bdbstore
+ List<AMQShortString> bdbExchanges = BDBStoreBindingsWorkaround.getBDBStoreExchangeNames(_virtualHost, _store);
+ assertEquals("Unexpected number of exchanges in the registry", 6, bdbExchanges.size());
+ assertTrue(bdbExchanges.contains(ExchangeDefaults.DEFAULT_EXCHANGE_NAME));
+ assertTrue(bdbExchanges.contains(ExchangeDefaults.DIRECT_EXCHANGE_NAME));
+ assertTrue(bdbExchanges.contains(ExchangeDefaults.TOPIC_EXCHANGE_NAME));
+ assertTrue(bdbExchanges.contains(ExchangeDefaults.FANOUT_EXCHANGE_NAME));
+ assertTrue(bdbExchanges.contains(ExchangeDefaults.HEADERS_EXCHANGE_NAME));
+ assertTrue(bdbExchanges.contains(durExchangeName));
+ }
+
+ /**
+ * This tests checks that given a vhost, any durable exchanges in the registry that are not
+ * already in the store are then added to it.
+ */
+ public void testGetVhostExchanges() throws Exception
+ {
+ ExchangeFactory exchangeFactory = _virtualHost.getExchangeFactory();
+ ExchangeRegistry exchangeRegistry = _virtualHost.getExchangeRegistry();
+
+ //verify current exchange count in the registry is 5 and verify the names (<<default>>, amq.[direct|topic|match|fanout])
+ Collection<AMQShortString> exNames = exchangeRegistry.getExchangeNames();
+ assertEquals("Unexpected number of exchanges in the registry", 5, exNames.size());
+ assertTrue(exNames.contains(ExchangeDefaults.DEFAULT_EXCHANGE_NAME));
+ assertTrue(exNames.contains(ExchangeDefaults.DIRECT_EXCHANGE_NAME));
+ assertTrue(exNames.contains(ExchangeDefaults.TOPIC_EXCHANGE_NAME));
+ assertTrue(exNames.contains(ExchangeDefaults.FANOUT_EXCHANGE_NAME));
+ assertTrue(exNames.contains(ExchangeDefaults.HEADERS_EXCHANGE_NAME));
+
+ BDBStoreBindingsWorkaround tool = new BDBStoreBindingsWorkaround(new String[]{});
+ List<Exchange> vhostExchanges = tool.getVhostExchanges(_virtualHost);
+
+ //verify the exchanges returned from the tool are those from the vhost registry
+ assertEquals("Unexpected number of exchanges returned", 5, vhostExchanges.size());
+ assertTrue(vhostExchanges.contains(exchangeRegistry.getExchange(ExchangeDefaults.DEFAULT_EXCHANGE_NAME)));
+ assertTrue(vhostExchanges.contains(exchangeRegistry.getExchange(ExchangeDefaults.DIRECT_EXCHANGE_NAME)));
+ assertTrue(vhostExchanges.contains(exchangeRegistry.getExchange(ExchangeDefaults.TOPIC_EXCHANGE_NAME)));
+ assertTrue(vhostExchanges.contains(exchangeRegistry.getExchange(ExchangeDefaults.FANOUT_EXCHANGE_NAME)));
+ assertTrue(vhostExchanges.contains(exchangeRegistry.getExchange(ExchangeDefaults.HEADERS_EXCHANGE_NAME)));
+
+ //Create a new durable exchange and register it(a side effect will add it to store)
+ AMQShortString durExchangeName = new AMQShortString("testGetVhostExchanges.Durable");
+ Exchange durExchange = exchangeFactory.createExchange(durExchangeName, DirectExchange.TYPE.getName(), true, false, 0);
+ assertNotNull("Exchange is null", durExchange);
+ exchangeRegistry.registerExchange(durExchange);
+
+ //Create a new non-durable exchange and register it
+ AMQShortString transExchangeName = new AMQShortString("testGetVhostExchanges.Transient");
+ Exchange transExchange = exchangeFactory.createExchange(transExchangeName, DirectExchange.TYPE.getName(), false, false, 0);
+ assertNotNull("Exchange is null", transExchange);
+ exchangeRegistry.registerExchange(transExchange);
+
+ vhostExchanges = tool.getVhostExchanges(_virtualHost);
+
+ //verify the exchanges returned from the tool are those from the vhost registry
+ assertEquals("Unexpected number of exchanges returned", 7, vhostExchanges.size());
+ assertTrue(vhostExchanges.contains(exchangeRegistry.getExchange(ExchangeDefaults.DEFAULT_EXCHANGE_NAME)));
+ assertTrue(vhostExchanges.contains(exchangeRegistry.getExchange(ExchangeDefaults.DIRECT_EXCHANGE_NAME)));
+ assertTrue(vhostExchanges.contains(exchangeRegistry.getExchange(ExchangeDefaults.TOPIC_EXCHANGE_NAME)));
+ assertTrue(vhostExchanges.contains(exchangeRegistry.getExchange(ExchangeDefaults.FANOUT_EXCHANGE_NAME)));
+ assertTrue(vhostExchanges.contains(exchangeRegistry.getExchange(ExchangeDefaults.HEADERS_EXCHANGE_NAME)));
+ assertTrue(vhostExchanges.contains(exchangeRegistry.getExchange(durExchangeName)));
+ assertTrue(vhostExchanges.contains(exchangeRegistry.getExchange(transExchangeName)));
+ }
+
+
+ public static boolean deleteDirectory(File dir)
+ {
+ if (dir.isDirectory())
+ {
+ String[] children = dir.list();
+ for (int i = 0; i < children.length; i++)
+ {
+ if (!deleteDirectory(new File(dir, children[i])))
+ {
+ return false;
+ }
+ }
+ }
+
+ return (dir.delete());
+ }
+
+}
14 years, 11 months
rhmessaging commits: r3800 - store/branches/java/0.5-release/src/tools/java/org/apache/qpid/server/store/berkeleydb.
by rhmessaging-commits@lists.jboss.org
Author: rgemmell
Date: 2010-01-14 12:20:50 -0500 (Thu, 14 Jan 2010)
New Revision: 3800
Modified:
store/branches/java/0.5-release/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaround.java
Log:
Updates to aid unit testing of the process
Modified: store/branches/java/0.5-release/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaround.java
===================================================================
--- store/branches/java/0.5-release/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaround.java 2010-01-14 17:19:57 UTC (rev 3799)
+++ store/branches/java/0.5-release/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaround.java 2010-01-14 17:20:50 UTC (rev 3800)
@@ -145,7 +145,9 @@
loadVirtualHosts();
- addDurableExchangesToStoreIfRequired();
+ addDurableExchangesToStoreIfRequired(
+ ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHosts());
+
_logger.info("Workaround process complete");
}
@@ -228,7 +230,7 @@
}
}
- private static List<AMQShortString> getBDBStoreExchangeNames(final VirtualHost vhost, final BDBMessageStore store) throws AMQException, DatabaseException
+ protected static List<AMQShortString> getBDBStoreExchangeNames(final VirtualHost vhost, final BDBMessageStore store) throws AMQException, DatabaseException
{
final List<AMQShortString> exchanges = new ArrayList<AMQShortString>();
@@ -273,10 +275,24 @@
return exchanges;
}
- private static void addDurableExchangesToStoreIfRequired() throws AMQException, DatabaseException
+ protected List<Exchange> getVhostExchanges(VirtualHost vhost)
{
- Collection<VirtualHost> vhosts = ApplicationRegistry.getInstance().getVirtualHostRegistry().getVirtualHosts();
+ ExchangeRegistry registry = vhost.getExchangeRegistry();
+ Collection<AMQShortString> exchangeNames = registry.getExchangeNames();
+ List<Exchange> exchangeList = new ArrayList<Exchange>();
+
+ for(AMQShortString exchangeName : exchangeNames)
+ {
+ Exchange ex = registry.getExchange(exchangeName);
+ exchangeList.add(ex);
+ }
+
+ return exchangeList;
+ }
+
+ protected void addDurableExchangesToStoreIfRequired(Collection<VirtualHost> vhosts) throws AMQException, DatabaseException
+ {
//For each active VHost, add all durable exchanges in the ExchangeRegistry to the store if they arent already in it.
for(VirtualHost vhost : vhosts)
{
@@ -295,13 +311,12 @@
}
List<AMQShortString> bdbExchangeNames = getBDBStoreExchangeNames(vhost, store);
+ List<Exchange> vhostExchanges = getVhostExchanges(vhost);
- ExchangeRegistry registry = vhost.getExchangeRegistry();
- Collection<AMQShortString> exchangeNames = registry.getExchangeNames();
-
- for(AMQShortString exchangeName : exchangeNames)
+ for(Exchange exchange : vhostExchanges)
{
- Exchange exchange = registry.getExchange(exchangeName);
+ AMQShortString exchangeName = exchange.getName();
+
if(exchange.isDurable())
{
if(bdbExchangeNames.contains(exchangeName))
14 years, 11 months
rhmessaging commits: r3799 - store/branches/java/0.5-release/src/tools/java/org/apache/qpid/server/store/berkeleydb.
by rhmessaging-commits@lists.jboss.org
Author: rgemmell
Date: 2010-01-14 12:19:57 -0500 (Thu, 14 Jan 2010)
New Revision: 3799
Modified:
store/branches/java/0.5-release/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaround.java
Log:
Use a FileNotFoundException instead of System.exit(1) and so restrict all use of System.exit() to the main() method
Modified: store/branches/java/0.5-release/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaround.java
===================================================================
--- store/branches/java/0.5-release/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaround.java 2010-01-14 15:05:28 UTC (rev 3798)
+++ store/branches/java/0.5-release/src/tools/java/org/apache/qpid/server/store/berkeleydb/BDBStoreBindingsWorkaround.java 2010-01-14 17:19:57 UTC (rev 3799)
@@ -44,6 +44,7 @@
import com.sleepycat.je.DatabaseException;
import java.io.File;
+import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -51,6 +52,7 @@
public class BDBStoreBindingsWorkaround
{
private static final Logger _logger = LoggerFactory.getLogger(BDBStoreBindingsWorkaround.class);
+ protected static final String CONFIG_NOT_FOUND = "BROKER_CONFIG_NOT_FOUND";
private Configuration _config;
private boolean _initialised = false;
@@ -62,17 +64,26 @@
try
{
tool.start();
+
+ //Shut down the JVM gracefully, the ShutdownHook will stop the VirtualHosts.
+ System.exit(0);
}
+ catch(FileNotFoundException e)
+ {
+ if(!e.getMessage().equals(CONFIG_NOT_FOUND))
+ {
+ e.printStackTrace();
+ _logger.error("Error during workaround process");
+ }
+ }
catch (Exception e)
{
e.printStackTrace();
_logger.error("Error during workaround process");
- //Shut down the JVM, the ShutdownHook will stop the VirtualHosts if initialised.
- System.exit(1);
}
-
- //Shut down the JVM gracefully, the ShutdownHook will stop the VirtualHosts.
- System.exit(0);
+
+ //Shut down the JVM, the ShutdownHook will stop the VirtualHosts if initialised.
+ System.exit(1);
}
public BDBStoreBindingsWorkaround(String[] args) throws InitException
@@ -126,7 +137,7 @@
}
}
- protected void start() throws Exception
+ protected void start() throws FileNotFoundException, Exception
{
_initialised = false;
@@ -146,7 +157,7 @@
{
_logger.error("Config file not found:" + configFile.getAbsolutePath());
_logger.error("Options: [-c <broker config file>] : Defaults to \"$QPID_HOME/etc/config.xml\"");
- System.exit(1);
+ throw new FileNotFoundException(CONFIG_NOT_FOUND);
}
else
{
14 years, 11 months
rhmessaging commits: r3798 - mgmt/trunk/cumin/python/cumin/grid.
by rhmessaging-commits@lists.jboss.org
Author: eallen
Date: 2010-01-14 10:05:28 -0500 (Thu, 14 Jan 2010)
New Revision: 3798
Modified:
mgmt/trunk/cumin/python/cumin/grid/slot.strings
Log:
Slot activity and state are now properties of slot and not slot stats.
Modified: mgmt/trunk/cumin/python/cumin/grid/slot.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/grid/slot.strings 2010-01-13 20:49:16 UTC (rev 3797)
+++ mgmt/trunk/cumin/python/cumin/grid/slot.strings 2010-01-14 15:05:28 UTC (rev 3798)
@@ -8,8 +8,8 @@
s.accounting_group,
s.op_sys,
s.arch,
- c.activity,
- c.state,
+ s.activity,
+ s.state,
c.load_avg
from slot as s
left outer join slot_stats as c on c.id = s.stats_curr_id
@@ -29,8 +29,8 @@
s.machine,
s.system,
s.job_id,
- c.activity,
- c.state,
+ s.activity,
+ s.state,
c.load_avg
from slot as s
left outer join slot_stats as c on c.id = s.stats_curr_id
14 years, 11 months
rhmessaging commits: r3796 - in mgmt/trunk: cumin and 2 other directories.
by rhmessaging-commits@lists.jboss.org
Author: justi9
Date: 2010-01-13 14:23:07 -0500 (Wed, 13 Jan 2010)
New Revision: 3796
Modified:
mgmt/trunk/Makefile
mgmt/trunk/cumin/Makefile
mgmt/trunk/etc/Makefile.common
mgmt/trunk/mint/Makefile
Log:
Add a clean rule, and move schema clean to a new rule
Modified: mgmt/trunk/Makefile
===================================================================
--- mgmt/trunk/Makefile 2010-01-13 15:12:58 UTC (rev 3795)
+++ mgmt/trunk/Makefile 2010-01-13 19:23:07 UTC (rev 3796)
@@ -1,4 +1,4 @@
-.PHONY: help tags check-devel-env
+.PHONY: help tags check-devel-env clean
version := 0.1.$(shell svn info | fgrep "Revision:" | cut -d " " -f 2)
@@ -19,3 +19,7 @@
echo "DEVEL_HOME is not set; you need to source etc/devel.profile"; \
exit 1; \
fi
+
+clean:
+ $(MAKE) clean -C mint
+ $(MAKE) clean -C cumin
Modified: mgmt/trunk/cumin/Makefile
===================================================================
--- mgmt/trunk/cumin/Makefile 2010-01-13 15:12:58 UTC (rev 3795)
+++ mgmt/trunk/cumin/Makefile 2010-01-13 19:23:07 UTC (rev 3796)
@@ -1,4 +1,4 @@
-.phony: build install
+.phony: build install clean
include ../etc/Makefile.common
@@ -37,3 +37,5 @@
install -pm 0644 etc/cumin.* ${etc}
install -pm 0755 etc/sysvinit-cumin ${etc}
install -d ${log}
+
+clean: clean-python-files
Modified: mgmt/trunk/etc/Makefile.common
===================================================================
--- mgmt/trunk/etc/Makefile.common 2010-01-13 15:12:58 UTC (rev 3795)
+++ mgmt/trunk/etc/Makefile.common 2010-01-13 19:23:07 UTC (rev 3796)
@@ -1,3 +1,5 @@
+.PHONY: clean-python-files
+
PREFIX := /usr/local
PYTHON_LIB_DIR := ${PREFIX}/lib/python
BIN_DIR := ${PREFIX}/bin
@@ -10,3 +12,6 @@
else
VAR_DIR := ${PREFIX}/var
endif
+
+clean-python-files:
+ find python -type f -name \*.py[co] -delete
Modified: mgmt/trunk/mint/Makefile
===================================================================
--- mgmt/trunk/mint/Makefile 2010-01-13 15:12:58 UTC (rev 3795)
+++ mgmt/trunk/mint/Makefile 2010-01-13 19:23:07 UTC (rev 3796)
@@ -1,4 +1,4 @@
-.PHONY: build install schema clean
+.PHONY: build install clean schema schema-clean
include ../etc/Makefile.common
@@ -24,13 +24,14 @@
install -d ${etc}
install -pm 0644 etc/mint-vacuumdb.cron ${etc}
-schema:
+schema: schema-clean
$(MAKE) schema -C xml
$(MAKE) schema -C python/mint
$(MAKE) schema -C sql
-clean:
+schema-clean:
$(MAKE) clean -C xml
$(MAKE) clean -C python/mint
$(MAKE) clean -C sql
+clean: clean-python-files
14 years, 11 months
rhmessaging commits: r3795 - store/trunk/cpp.
by rhmessaging-commits@lists.jboss.org
Author: kpvdr
Date: 2010-01-13 10:12:58 -0500 (Wed, 13 Jan 2010)
New Revision: 3795
Modified:
store/trunk/cpp/configure.ac
Log:
Updated revision from 0.5 to 0.6 to match qpid release number.
Modified: store/trunk/cpp/configure.ac
===================================================================
--- store/trunk/cpp/configure.ac 2010-01-13 14:49:12 UTC (rev 3794)
+++ store/trunk/cpp/configure.ac 2010-01-13 15:12:58 UTC (rev 3795)
@@ -21,7 +21,7 @@
dnl
dnl Process this file with autoconf to produce a configure script.
-AC_INIT([rhm], [0.5], [rhemrg-users-list(a)redhat.com])
+AC_INIT([rhm], [0.6], [rhemrg-users-list(a)redhat.com])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([dist-bzip2])
14 years, 11 months