Author: nunofsantos
Date: 2007-11-29 16:27:40 -0500 (Thu, 29 Nov 2007)
New Revision: 1400
Modified:
mgmt/mint/python/mint/__init__.py
Log:
update in-memory map of original_ids upon reading an existing obj from the db
Modified: mgmt/mint/python/mint/__init__.py
===================================================================
--- mgmt/mint/python/mint/__init__.py 2007-11-29 20:45:22 UTC (rev 1399)
+++ mgmt/mint/python/mint/__init__.py 2007-11-29 21:27:40 UTC (rev 1400)
@@ -15,36 +15,41 @@
except TypeError:
pass
+
class BrokerRegistration(SQLObject):
name = StringCol(length=1000, default=None)
host = StringCol(length=1000, default=None)
port = SmallIntCol(default=None)
broker = ForeignKey("Broker", cascade="null", default=None)
+
class BrokerGroup(SQLObject):
name = StringCol(length=1000, default=None)
+ brokers = MultipleJoin("Broker")
Broker.sqlmeta.addJoin(RelatedJoin("BrokerGroup",
joinMethodName="groups"))
-BrokerGroup.sqlmeta.addJoin(RelatedJoin("Broker",
joinMethodName="brokers"))
+
class BrokerCluster(SQLObject):
name = StringCol(length=1000, default=None)
+ brokers = MultipleJoin("Broker")
fk = ForeignKey("BrokerCluster", cascade="null",
default=None, name="brokerCluster")
Broker.sqlmeta.addColumn(fk)
setattr(Broker, "cluster", fk)
-BrokerCluster.sqlmeta.addJoin(MultipleJoin("Broker",
joinMethodName="brokers"))
+
class BrokerProfile(SQLObject):
name = StringCol(length=1000, default=None)
-
+ brokers = MultipleJoin("Broker")
+
fk = ForeignKey("BrokerProfile", cascade="null",
default=None, name="brokerProfile")
Broker.sqlmeta.addColumn(fk)
setattr(Broker, "profile", fk)
-BrokerProfile.sqlmeta.addJoin(MultipleJoin("Broker",
joinMethodName="brokers"))
+
class ConfigProperty(SQLObject):
name = StringCol(length=1000, default=None)
value = StringCol(length=1000, default=None)
@@ -54,6 +59,7 @@
BrokerProfile.sqlmeta.addJoin(MultipleJoin("ConfigProperty",
joinMethodName="properties"))
+
class OriginalIdDict:
def __init__(self):
self.idMap = dict()
@@ -62,23 +68,33 @@
self.idMap[idOriginal] = obj
def getByOriginalId(self, objType, idOriginal, create=False, args={}):
+ obj = None
if (idOriginal in self.idMap):
#print "\n\n=============== %s %d found\n\n" % (objType.__name__,
idOriginal)
- return self.idMap[idOriginal]
- elif (create):
- #print "\n\n=============== %s %d NOT found, creating\n\n" %
(objType.__name__, idOriginal)
- obj = objType.__new__(objType)
- obj.__init__()
- self.idMap[idOriginal] = obj
- return obj
+ obj = self.idMap[idOriginal]
else:
- #print "\n\n=============== %s %d NOT found, NOT creating\n\n" %
(objType.__name__, idOriginal)
- return None
+ try:
+ obj = eval("objType.selectBy(idOriginal=idOriginal)[:1][0]")
+ self.idMap[idOriginal] = obj
+ except:
+ if (create):
+ #print "\n\n=============== %s %d NOT found, creating\n\n" %
(objType.__name__, idOriginal)
+ obj = objType.__new__(objType)
+ obj.__init__()
+ self.idMap[idOriginal] = obj
+ else:
+ print "\n\n=============== %s %d NOT found, NOT creating\n\n" %
(objType.__name__, idOriginal)
+ #pass
+ else:
+ #print "\n\n=============== %s %d found AFTER QUERY\n\n" %
(objType.__name__, idOriginal)
+ pass
+ return obj
def getByIndexAttrib(self, objType, indexAttrib, indexValue, create=False, args={}):
###FIX
return None
+
class ConnectedBroker:
def __init__(self, managedBroker):
self.managedBroker = managedBroker
@@ -116,11 +132,12 @@
def convertRefKey(self, k):
return k.replace("Ref", "")
- def findParentKey(self, d):
+ def findParentKeys(self, d):
+ keys = []
for key in d.keys():
if (key.endswith("Ref")):
- return key
- return ""
+ keys.append(key)
+ return keys
def configCallback(self, broker, objectName, list, timestamps):
self.log("\nCONFIG---------------------------------------------------")
@@ -131,17 +148,9 @@
d["recTime"] = datetime.fromtimestamp(timestamps[0]/1000000000)
d["creationTime"] = datetime.fromtimestamp(timestamps[1]/1000000000)
self.log(d)
- ###FIX
- if (objectName == "broker"):
- # needs special handling until schema is sendind info about systems
- d.pop("systemRef")
- # d["system"] = connectedBroker.getByOriginalId(System, 0)
- d["system"] = System.selectBy(idOriginal=0)[:1][0]
- connectedBroker.objs.set(0, d["system"])
- else:
- parentKey = self.findParentKey(d)
- d[self.convertRefKey(parentKey)] = connectedBroker.getByOriginalId(schema.Vhost,
d.pop(parentKey))
- ###FIX
+ for parentKey in self.findParentKeys(d):
+ convertedKey = self.convertRefKey(parentKey)
+ d[convertedKey] =
connectedBroker.getByOriginalId(schema.schemaNameToClassMap[convertedKey],
d.pop(parentKey))
obj = connectedBroker.getByOriginalId(schema.schemaNameToClassMap[objectName],
d["idOriginal"], create=True)
obj.set(**d)
self.log("END
CONFIG---------------------------------------------------\n")