From d36ed91b6c8edecdc0da28daf2baf5abca7cafc3 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 20 Jan 2012 15:38:35 +0100 Subject: [PATCH] add another column in RegRecord, separate from 'type' to act as a discriminator remove the RegAuthority* subclasses and use RegAuthority instead --- sfa/importer/sfa-import-plc.py | 5 +++++ sfa/importer/sfaImport.py | 11 +++++------ sfa/storage/persistentobjs.py | 33 +++++++-------------------------- 3 files changed, 17 insertions(+), 32 deletions(-) diff --git a/sfa/importer/sfa-import-plc.py b/sfa/importer/sfa-import-plc.py index 1c38bc55..e10e572d 100755 --- a/sfa/importer/sfa-import-plc.py +++ b/sfa/importer/sfa-import-plc.py @@ -147,6 +147,7 @@ def main(): sfaImporter.AuthHierarchy.create_auth(urn) auth_info = sfaImporter.AuthHierarchy.get_auth_info(urn) auth_record = RegAuthority() + auth_record.type='authority' auth_record.hrn=site_hrn auth_record.gid=auth_info.get_gid_object() auth_record.pointer=site['site_id'] @@ -169,6 +170,7 @@ def main(): sfaImporter.AuthHierarchy.create_auth(urn) auth_info = sfaImporter.AuthHierarchy.get_auth_info(urn) auth_record = RegAuthority() + auth_record.type='authority' auth_record.hrn=site_hrn auth_record.gid=auth_info.get_gid_object() auth_record.pointer=site['site_id'] @@ -199,6 +201,7 @@ def main(): urn = hrn_to_urn(hrn, 'node') node_gid = sfaImporter.AuthHierarchy.create_gid(urn, create_uuid(), pkey) node_record = RegNode () + node_record.type='node' node_record.hrn=hrn node_record.gid=node_gid node_record.pointer =node['node_id'] @@ -225,6 +228,7 @@ def main(): urn = hrn_to_urn(hrn, 'slice') slice_gid = sfaImporter.AuthHierarchy.create_gid(urn, create_uuid(), pkey) slice_record = RegSlice () + slice_record.type='slice' slice_record.hrn=hrn slice_record.gid=slice_gid slice_record.pointer=slice['slice_id'] @@ -274,6 +278,7 @@ def main(): urn = hrn_to_urn(hrn, 'user') person_gid = sfaImporter.AuthHierarchy.create_gid(urn, create_uuid(), pkey) person_record = RegUser () + person_record.type='user' person_record.hrn=hrn person_record.gid=person_gid person_record.pointer=person['person_id'] diff --git a/sfa/importer/sfaImport.py b/sfa/importer/sfaImport.py index 8d09b81b..a9d6bd7c 100644 --- a/sfa/importer/sfaImport.py +++ b/sfa/importer/sfaImport.py @@ -17,7 +17,6 @@ from sfa.trust.trustedroots import TrustedRoots from sfa.trust.hierarchy import Hierarchy from sfa.trust.gid import create_uuid from sfa.storage.persistentobjs import RegRecord, RegAuthority, RegUser -from sfa.storage.persistentobjs import RegAuthoritySa, RegAuthorityAm, RegAuthoritySm from sfa.storage.alchemy import dbsession def _un_unicode(str): @@ -92,6 +91,7 @@ class sfaImport: # create the db record if it doesnt already exist auth_info = self.AuthHierarchy.get_auth_info(hrn) auth_record = RegAuthority() + auth_record.type='authority' auth_record.hrn=hrn auth_record.gid=auth_info.get_gid_object() auth_record.authority=get_authority(hrn) @@ -112,6 +112,7 @@ class sfaImport: auth_info = self.AuthHierarchy.get_auth_info(hrn) user_record = RegUser() + user_record.type='user' user_record.hrn=hrn user_record.gid=auth_info.get_gid_object() user_record.authority=get_authority(hrn) @@ -127,17 +128,15 @@ class sfaImport: # just create certs for all sfa interfaces even if they # aren't enabled hrn = self.config.SFA_INTERFACE_HRN - reg_classes_info = [ (RegAuthoritySa, 'authority+sa'), - (RegAuthorityAm, 'authority+am'), - (RegAuthoritySm, 'authority+sm'), ] auth_info = self.AuthHierarchy.get_auth_info(hrn) pkey = auth_info.get_pkey_object() - for (reg_class, type) in reg_classes_info: + for type in [ 'authority+sa', 'authority+am', 'authority+sm', ]: urn = hrn_to_urn(hrn, type) gid = self.AuthHierarchy.create_gid(urn, create_uuid(), pkey) # xxx this should probably use a RegAuthority, or a to-be-defined RegPeer object # but for now we have to preserve the authority+<> stuff - interface_record = reg_class() + interface_record = RegAuthority() + interface_record.type=type interface_record.hrn=hrn interface_record.gid= gid interface_record.authority=get_authority(hrn) diff --git a/sfa/storage/persistentobjs.py b/sfa/storage/persistentobjs.py index 2b28a570..b79fb9be 100644 --- a/sfa/storage/persistentobjs.py +++ b/sfa/storage/persistentobjs.py @@ -102,13 +102,16 @@ class AlchemyObj: ############################## # various kinds of records are implemented as an inheritance hierarchy # RegRecord is the base class for all actual variants +# a first draft was using 'type' as the discriminator for the inheritance +# but we had to define another more internal column (classtype) so we +# accomodate variants in types like authority+am and the like class RegRecord (Base,AlchemyObj): # xxx tmp would be 'records' __tablename__ = 'records' record_id = Column (Integer, primary_key=True) # this is the discriminator that tells which class to use -# classtype = Column (String) + classtype = Column (String) type = Column (String) hrn = Column (String) gid = Column (String) @@ -118,13 +121,12 @@ class RegRecord (Base,AlchemyObj): date_created = Column (DateTime) last_updated = Column (DateTime) # use the 'type' column to decide which subclass the object is of - __mapper_args__ = { 'polymorphic_on' : type } + __mapper_args__ = { 'polymorphic_on' : classtype } fields = [ 'type', 'hrn', 'gid', 'authority', 'peer_authority' ] - def __init__ (self, type='unknown', hrn=None, gid=None, authority=None, peer_authority=None, + def __init__ (self, type=None, hrn=None, gid=None, authority=None, peer_authority=None, pointer=None, dict=None): -# managed by alchemy's polymorphic stuff -# self.type=type + if type: self.type=type if hrn: self.hrn=hrn if gid: if isinstance(gid, StringTypes): self.gid=gid @@ -207,25 +209,6 @@ class RegNode (RegRecord): def __repr__ (self): return RegRecord.__repr__(self).replace("Record","Node") -# because we use 'type' as the discriminator here, the only way to have type set to -# e.g. authority+sa is to define a separate class -# this currently is not used at all though, just to check if all this stuff really is useful -# if so it would make more sense to store that in the authorities table instead -class RegAuthoritySa (RegRecord): - __tablename__ = 'authorities_sa' - __mapper_args__ = { 'polymorphic_identity' : 'authority+sa' } - record_id = Column (Integer, ForeignKey ("records.record_id"), primary_key=True) - -class RegAuthorityAm (RegRecord): - __tablename__ = 'authorities_am' - __mapper_args__ = { 'polymorphic_identity' : 'authority+am' } - record_id = Column (Integer, ForeignKey ("records.record_id"), primary_key=True) - -class RegAuthoritySm (RegRecord): - __tablename__ = 'authorities_sm' - __mapper_args__ = { 'polymorphic_identity' : 'authority+sm' } - record_id = Column (Integer, ForeignKey ("records.record_id"), primary_key=True) - ############################## def init_tables(dbsession): logger.info("Initializing db schema and builtin types") @@ -275,5 +258,3 @@ def make_record_xml (xml): xml_dict = xml_record.todict() logger.info("load from xml, keys=%s"%xml_dict.keys()) return make_record_dict (xml_dict) - - -- 2.43.0