Author: tmckay
Date: 2012-03-28 17:54:06 +0000 (Wed, 28 Mar 2012)
New Revision: 5275
Added:
branches/play_plumage/cumin/model/plumage.xml
Modified:
branches/play_plumage/cumin/bin/cumin-admin
branches/play_plumage/cumin/model/rosemary.xml
branches/play_plumage/cumin/python/cumin/main.py
branches/play_plumage/rosemary/python/rosemary/model.py
branches/play_plumage/rosemary/python/rosemary/sqloperation.py
Log:
Fixes to allow xml schemas with qmf_headers="False" for non-qmf classes
Modified: branches/play_plumage/cumin/bin/cumin-admin
===================================================================
--- branches/play_plumage/cumin/bin/cumin-admin 2012-03-27 20:28:39 UTC (rev 5274)
+++ branches/play_plumage/cumin/bin/cumin-admin 2012-03-28 17:54:06 UTC (rev 5275)
@@ -77,7 +77,7 @@
# cumin-admin is the mechanism for fixing the schema so we
# have to avoid the check here!
try:
- app.init(schema_version_check=False)
+ app.db_init(schema_version_check=False)
except OperationalError:
print "Can't talk to the database"
error("Run 'cumin-database check' as root for more
information")
Added: branches/play_plumage/cumin/model/plumage.xml
===================================================================
--- branches/play_plumage/cumin/model/plumage.xml (rev 0)
+++ branches/play_plumage/cumin/model/plumage.xml 2012-03-28 17:54:06 UTC (rev 5275)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<schema package="com.redhat.grid.plumage">
+ <class name="OSUtil" qmf_headers="False">
+ <property name="uuid" index="y" type="uuid"
access="RC" desc="UUID of System Image"/>
+
+ <property name="osName" type="sstr" access="RO"
desc="Operating System Name" />
+
+ <statistic name="avail" type="uint32" unit="uint32"
/>
+ <statistic name="used" type="uint32" unit="uint32"
/>
+ </class>
+</schema>
Modified: branches/play_plumage/cumin/model/rosemary.xml
===================================================================
--- branches/play_plumage/cumin/model/rosemary.xml 2012-03-27 20:28:39 UTC (rev 5274)
+++ branches/play_plumage/cumin/model/rosemary.xml 2012-03-28 17:54:06 UTC (rev 5275)
@@ -546,4 +546,21 @@
</statistic>
</class>
</package>
+
+ <package name="com.redhat.grid.plumage">
+ <class name="OSUtil">
+ <property name="osName">
+ <title>OS</title>
+ </property>
+
+ <statistic name="used">
+ <title>Used</title>
+ </statistic>
+
+ <statistic name="avail">
+ <title>Available</title>
+ </statistic>
+ </class>
+ </package>
+
</model>
Modified: branches/play_plumage/cumin/python/cumin/main.py
===================================================================
--- branches/play_plumage/cumin/python/cumin/main.py 2012-03-27 20:28:39 UTC (rev 5274)
+++ branches/play_plumage/cumin/python/cumin/main.py 2012-03-28 17:54:06 UTC (rev 5275)
@@ -165,6 +165,10 @@
inventory.Module(self, "inventory")
usergrid.Module(self, "usergrid")
+ def db_init(self, schema_version_check=True):
+ self.model.init()
+ self.database.init(schema_version_check)
+
def init(self, schema_version_check=True):
log.info("Initializing %s", self)
Modified: branches/play_plumage/rosemary/python/rosemary/model.py
===================================================================
--- branches/play_plumage/rosemary/python/rosemary/model.py 2012-03-27 20:28:39 UTC (rev
5274)
+++ branches/play_plumage/rosemary/python/rosemary/model.py 2012-03-28 17:54:06 UTC (rev
5275)
@@ -143,7 +143,7 @@
groups_by_name[name] = child
for child in elem.findall("class"):
- cls = RosemaryClass(self, child.get("name"))
+ cls = RosemaryClass(self, child.get("name"),
child.get("qmf_headers"))
cls.load(child, groups_by_name)
def extend(self, elem):
@@ -168,7 +168,7 @@
return "%s(%s)" % args
class RosemaryClass(object):
- def __init__(self, package, name):
+ def __init__(self, package, name, qmf_headers):
self._package = package
self._name = name
@@ -213,7 +213,9 @@
self._id = RosemaryAttribute(self, "_id")
- self.add_headers()
+ self.qmf_headers = qmf_headers is None or qmf_headers.lower() ==
"true"
+ if self.qmf_headers:
+ self.add_headers()
def add_headers(self):
name = "_qmf_agent_id"
@@ -355,15 +357,18 @@
SqlPrimaryKeyConstraint(self.sql_table, name, (id_col,))
def add_sql_constraints(self):
- name = "%s_qmf_id_uq" % self._name
- cols = (self._qmf_agent_id.sql_column, self._qmf_object_id.sql_column)
- SqlUniqueConstraint(self.sql_table, name, cols)
+ if self.qmf_headers:
+ name = "%s_qmf_id_uq" % self._name
+ cols = (self._qmf_agent_id.sql_column, self._qmf_object_id.sql_column)
+ SqlUniqueConstraint(self.sql_table, name, cols)
def add_sql_operations(self):
self.sql_get_new_id = SqlGetNewId(self.sql_table, self.sql_sequence)
self.sql_select_by_id = SqlSelectObject(self.sql_table)
- self.sql_select_by_qmf_id = SqlSelectObjectByQmfId(self.sql_table)
+ if self.qmf_headers:
+ self.sql_select_by_qmf_id = SqlSelectObjectByQmfId(self.sql_table)
+
self.sql_insert_object = SqlInsertObject(self.sql_table)
self.sql_update_object = SqlUpdateObject(self.sql_table)
self.sql_delete_object = SqlDeleteObject(self.sql_table)
@@ -374,16 +379,19 @@
self.sql_samples_table = table
- agent_col = SqlColumn(table, "_qmf_agent_id", sql_text)
- object_col = SqlColumn(table, "_qmf_object_id", sql_text)
+ if self.qmf_headers:
+ agent_col = SqlColumn(table, "_qmf_agent_id", sql_text)
+ object_col = SqlColumn(table, "_qmf_object_id", sql_text)
- name = "%s_qmf_id_idx" % table._name
- SqlIndex(self._package.sql_schema, name, (agent_col, object_col))
+ name = "%s_qmf_id_idx" % table._name
+ SqlIndex(self._package.sql_schema, name, (agent_col, object_col))
- SqlColumn(table, "_qmf_update_time", sql_timestamp)
+ SqlColumn(table, "_qmf_update_time", sql_timestamp)
- self.sql_samples_insert = SqlInsertObjectSamples(table)
- self.sql_samples_delete = SqlDeleteObjectSamples(table)
+ self.sql_samples_insert = SqlInsertObjectSamples(table, self.qmf_headers)
+ if self.qmf_headers:
+ # We will need another way to delete non-qmf samples
+ self.sql_samples_delete = SqlDeleteObjectSamples(table)
def get_object(self, cursor, **criteria):
sql = SqlSelect(self.sql_table)
@@ -457,12 +465,11 @@
return obj
def get_object_by_qmf_id(self, cursor, agent_id, object_id):
+ assert self.qmf_headers
obj = RosemaryObject(self, None)
obj._qmf_agent_id = agent_id
obj._qmf_object_id = object_id
-
self.load_object_by_qmf_id(cursor, obj)
-
return obj
def get_new_id(self, cursor):
@@ -494,6 +501,7 @@
def load_object_by_qmf_id(self, cursor, obj):
assert isinstance(obj, RosemaryObject)
+ assert self.qmf_headers
assert obj._qmf_agent_id, obj
assert obj._qmf_object_id, obj
@@ -600,6 +608,14 @@
self.short_title = elem.findtext("short")
self.unique = elem.get("unique", "n") == "y" and
True
formatter = elem.findtext("formatter")
+
+ # Allow overloading of optional in the extensions
+ # This is nice, because sometimes we have to mark
+ # items as optional for backwards compatibility
+ optional = elem.get("optional")
+ if optional is not None:
+ self.optional = optional == "y"
+
if formatter:
meth = getattr(util, formatter, None)
@@ -711,7 +727,7 @@
type = sql_types_by_qmf_type_string[self.type]
self.sql_column = SqlColumn(self.cls.sql_table, self.name, type)
- self.sql_column.nullable = True
+ self.sql_column.nullable = self.optional
col = SqlColumn(self.cls.sql_samples_table, self.name, type)
col.nullable = self.optional
Modified: branches/play_plumage/rosemary/python/rosemary/sqloperation.py
===================================================================
--- branches/play_plumage/rosemary/python/rosemary/sqloperation.py 2012-03-27 20:28:39 UTC
(rev 5274)
+++ branches/play_plumage/rosemary/python/rosemary/sqloperation.py 2012-03-28 17:54:06 UTC
(rev 5275)
@@ -83,7 +83,6 @@
class SqlSelectObjectByQmfId(SqlSelect):
def __init__(self, table):
super(SqlSelectObjectByQmfId, self).__init__(table)
-
self.add_filter(SqlValueFilter(self.table._qmf_agent_id))
self.add_filter(SqlValueFilter(self.table._qmf_object_id))
@@ -97,6 +96,11 @@
return "insert into %s (%s) values (%s)" % (table, cols, vals)
class SqlInsertObjectSamples(SqlOperation):
+ def __init__(self, table, qmf_headers):
+ super(SqlInsertObjectSamples, self).__init__(table)
+
+ self.qmf_headers = qmf_headers
+
def emit(self, columns, options=None):
table = getattr(self.table, "identifier", self.table)
names = [x.name for x in columns]
@@ -104,11 +108,12 @@
cols = ["\"%s\"" % x for x in names]
vals = ["%%(%s)s" % x for x in names]
- cols.append("\"_qmf_agent_id\"")
- cols.append("\"_qmf_object_id\"")
+ if self.qmf_headers:
+ cols.append("\"_qmf_agent_id\"")
+ cols.append("\"_qmf_object_id\"")
- vals.append("%(_qmf_agent_id)s")
- vals.append("%(_qmf_object_id)s")
+ vals.append("%(_qmf_agent_id)s")
+ vals.append("%(_qmf_object_id)s")
cols = ", ".join(cols)
vals = ", ".join(vals)