Skip to content
Browse files

FIX: removed ugly or unused methods from RSS.Utils ( whoRaised,

RPCError, unpack, protect2, list_, xml_append )
  • Loading branch information...
1 parent a5010df commit 8138376355b91398f372e219f30fcb6d42315c3b @ubeda committed
Showing with 90 additions and 52 deletions.
  1. +51 −10 ResourceStatusSystem/Utilities/Synchronizer.py
  2. +39 −42 ResourceStatusSystem/Utilities/Utils.py
View
61 ResourceStatusSystem/Utilities/Synchronizer.py
@@ -156,18 +156,35 @@ def getGOCTier(sitesList):
else:
gt = getGOCTier( DIRACSitesOfGridSites )
- Utils.protect2(self.rsClient.addOrModifyGridSite, gridSiteName, gt)
- Utils.protect2(self.rsClient.addOrModifySite, site, tier, gridSiteName )
+ #Utils.protect2(self.rsClient.addOrModifyGridSite, gridSiteName, gt)
+ res = self.rsClient.addOrModifyGridSite( gridSiteName, gt )
+ if not res[ 'OK' ]:
+ gLogger.error( res[ 'Message' ] )
+ return res
+
+ #Utils.protect2(self.rsClient.addOrModifySite, site, tier, gridSiteName )
+ res = self.rsClient.addOrModifySite( site, tier, gridSiteName )
+ if not res[ 'OK' ]:
+ gLogger.error( res[ 'Message' ] )
+ return res
elif siteType == "DIRAC":
- Utils.protect2(self.rsClient.addOrModifySite, site, tier, "NULL" )
+ #Utils.protect2(self.rsClient.addOrModifySite, site, tier, "NULL" )
+ res = self.rsClient.addOrModifySite( site, tier, "NULL" )
+ if not res[ 'OK' ]:
+ gLogger.error( res[ 'Message' ] )
+ return res
################################################################################
# _syncResources HELPER functions
def __updateService(self, site, type_):
service = type_ + '@' + site
- Utils.protect2(self.rsClient.addOrModifyService, service, type_, site )
+ #Utils.protect2(self.rsClient.addOrModifyService, service, type_, site )
+ res = self.rsClient.addOrModifyService( service, type_, site )
+ if not res[ 'OK' ]:
+ gLogger.error( res[ 'Message' ] )
+ return res
def __getServiceEndpointInfo(self, node):
#res = Utils.unpack( self.GOCDBClient.getServiceEndpointInfo( 'hostname', node ) )
@@ -225,7 +242,11 @@ def __syncNode(self, NodeInCS, resourcesInDB, resourceType, serviceType, site =
continue
assert(type(siteInGOCDB) == str)
- Utils.protect2(self.rsClient.addOrModifyResource, node, resourceType, serviceType, site, siteInGOCDB )
+ #Utils.protect2(self.rsClient.addOrModifyResource, node, resourceType, serviceType, site, siteInGOCDB )
+ res = self.rsClient.addOrModifyResource( node, resourceType, serviceType, site, siteInGOCDB )
+ if not res[ 'OK' ]:
+ gLogger.error( res[ 'Message' ] )
+ return res
resourcesInDB.add( node )
################################################################################
@@ -316,7 +337,11 @@ def _syncStorageElements( self ):
# Remove storageElements that are in DB but not in CS
for se in DBSEs - CSSEs:
- Utils.protect2(self.rsClient.removeElement, 'StorageElement', se )
+ #Utils.protect2(self.rsClient.removeElement, 'StorageElement', se )
+ res = self.rsClient.removeElement( 'StorageElement', se )
+ if not res[ 'OK' ]:
+ gLogger.error( res[ 'Message' ] )
+ return res
# Add new storage elements
gLogger.info("Updating %d StorageElements in DB (%d on CS vs %d on DB)" % (len(CSSEs - DBSEs), len(CSSEs), len(DBSEs)))
@@ -336,7 +361,11 @@ def _syncStorageElements( self ):
gLogger.warn("%s is not in GOCDB!!!" % srm)
continue
siteInGOCDB = siteInGOCDB[ 0 ][ 'SITENAME' ]
- Utils.protect2(self.rsClient.addOrModifyStorageElement, SE, srm, siteInGOCDB )
+ #Utils.protect2(self.rsClient.addOrModifyStorageElement, SE, srm, siteInGOCDB )
+ res = self.rsClient.addOrModifyStorageElement( SE, srm, siteInGOCDB )
+ if not res[ 'OK' ]:
+ gLogger.error( res[ 'Message' ] )
+ return res
################################################################################
@@ -362,7 +391,11 @@ def _syncServices(self):
if resource[ 'Value' ] == []:
gLogger.info("Deleting Service %s since it has no corresponding resources." % service_name)
- Utils.protect2(self.rsClient.removeElement, "Service", service_name)
+ #Utils.protect2(self.rsClient.removeElement, "Service", service_name)
+ res = self.rsClient.removeElement( "Service", service_name )
+ if not res[ 'OK' ]:
+ gLogger.error( res[ 'Message' ] )
+ return res
elif service_type == "Storage":
res = self.rsClient.getSite( siteName = site_name, meta = { 'columns' : 'GridSiteName'} )
if res[ 'OK' ]:
@@ -373,7 +406,11 @@ def _syncServices(self):
if res:
if self.rsClient.getResource( gridSiteName = res[0], serviceType = service_type ) == []:
gLogger.info("Deleting Service %s since it has no corresponding resources." % service_name)
- Utils.protect2(self.rsClient.removeElement, "Service", service_name)
+ #Utils.protect2(self.rsClient.removeElement, "Service", service_name)
+ res = self.rsClient.removeElement( "Service", service_name )
+ if not res[ 'OK' ]:
+ gLogger.error( res[ 'Message' ] )
+ return res
def _syncRegistryUsers(self):
users = CS.getTypedDictRootedAt("Users", root= "/Registry")
@@ -411,7 +448,11 @@ def _syncRegistryUsers(self):
return res
for u in usersToDel:
- Utils.protect2(self.rmClient.deleteUserRegistryCache, u)
+ #Utils.protect2(self.rmClient.deleteUserRegistryCache, u)
+ res = self.rmClient.deleteUserRegistryCache( u )
+ if not res[ 'OK' ]:
+ gLogger.error( res[ 'Message' ] )
+ return res
################################################################################
#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF
View
81 ResourceStatusSystem/Utilities/Utils.py
@@ -25,9 +25,6 @@ def getTypedList( stringValue ):
def where(c, f):
return "Class " + str(c.__class__.__name__) + ", in Function " + (f.__name__)
-def whoRaised(x):
- return "Exception: " + str(x.__class__.__name__) +", raised by " + str(x)
-
def convertTime(t, inTo = None):
if inTo is None or inTo in ('second', 'seconds'):
@@ -135,30 +132,30 @@ def canonicalURL(url):
# RPC utils
-class RPCError(Exception):
- pass
-
-def unpack(dirac_value):
- if type(dirac_value) != dict:
- raise ValueError, "Not a DIRAC value."
- if 'OK' not in dirac_value.keys():
- raise ValueError, "Not a DIRAC value."
- try:
- return dirac_value['Value']
- except KeyError:
- raise RPCError, dirac_value['Message']
-
-def protect2(f, *args, **kw):
- """Wrapper protect"""
- try:
- ret = f(*args, **kw)
- if type(ret) == dict and ret['OK'] == False:
- print "function " + f.f.__name__ + " called with " + str( args )
- print "%s\n" % ret['Message']
- return ret
- except Exception as e:
- print "function " + str(f) + " called with " + str(args)
- raise e
+#class RPCError(Exception):
+# pass
+#
+#def unpack(dirac_value):
+# if type(dirac_value) != dict:
+# raise ValueError, "Not a DIRAC value."
+# if 'OK' not in dirac_value.keys():
+# raise ValueError, "Not a DIRAC value."
+# try:
+# return dirac_value['Value']
+# except KeyError:
+# raise RPCError, dirac_value['Message']
+
+#def protect2(f, *args, **kw):
+# """Wrapper protect"""
+# try:
+# ret = f(*args, **kw)
+# if type(ret) == dict and ret['OK'] == False:
+# print "function " + f.f.__name__ + " called with " + str( args )
+# print "%s\n" % ret['Message']
+# return ret
+# except Exception as e:
+# print "function " + str(f) + " called with " + str(args)
+# raise e
# (Duck) type checking
@@ -179,10 +176,10 @@ def typedobj_of_string(s):
# List utils
-def list_(a):
- """Same as list() except if arg is a string, in this case, return
- [a]"""
- return (list(a) if type(a) != str else [a])
+#def list_(a):
+# """Same as list() except if arg is a string, in this case, return
+# [a]"""
+# return (list(a) if type(a) != str else [a])
def list_flatten(l):
try:
@@ -229,17 +226,17 @@ def dictMatch(dict1, dict2):
# XML utils
-def xml_append(doc, tag, value_=None, elt_=None, **kw):
- new_elt = doc.createElement(tag)
- for k in kw:
- new_elt.setAttribute(k, str(kw[k]))
- if value_ != None:
- textnode = doc.createTextNode(str(value_))
- new_elt.appendChild(textnode)
- if elt_ != None:
- return elt_.appendChild(new_elt)
- else:
- return doc.documentElement.appendChild(new_elt)
+#def xml_append(doc, tag, value_=None, elt_=None, **kw):
+# new_elt = doc.createElement(tag)
+# for k in kw:
+# new_elt.setAttribute(k, str(kw[k]))
+# if value_ != None:
+# textnode = doc.createTextNode(str(value_))
+# new_elt.appendChild(textnode)
+# if elt_ != None:
+# return elt_.appendChild(new_elt)
+# else:
+# return doc.documentElement.appendChild(new_elt)
################################################################################
#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF

0 comments on commit 8138376

Please sign in to comment.
Something went wrong with that request. Please try again.