Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions FrameworkSystem/Client/UserProfileClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,6 @@ def getUserProfileNames(self, permission=dict()):
it returns the available profile names by not taking account the permission: ReadAccess and PublishAccess
"""
return self.__getRPCClient().getUserProfileNames(permission)

def listStatesForWeb(self, permission={}):
return self.__getRPCClient().listStatesForWeb(permission)
25 changes: 23 additions & 2 deletions FrameworkSystem/DB/UserProfileDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import sys
import hashlib

import cachetools
Comment thread
fstagni marked this conversation as resolved.

from DIRAC import S_OK, S_ERROR, gLogger, gConfig
from DIRAC.Core.Utilities import Time
from DIRAC.ConfigurationSystem.Client.Helpers import Registry
Expand Down Expand Up @@ -76,6 +78,7 @@ def __init__(self):
"""
self.__permValues = ['USER', 'GROUP', 'VO', 'ALL']
self.__permAttrs = ['ReadAccess', 'PublishAccess']
self.__cache = cachetools.TTLCache(1024, 15)
DB.__init__(self, 'UserProfileDB', 'Framework/UserProfileDB')
retVal = self.__initializeDB()
if not retVal['OK']:
Expand Down Expand Up @@ -123,14 +126,32 @@ def __getGroupId(self, groupName, insertIfMissing=True):
def __getVOId(self, voName, insertIfMissing=True):
return self.__getObjId(voName, 'VO', 'up_VOs', insertIfMissing)

def __getFieldsCached(self, tableName, outFields, condDict):
"""Call getFields with a TTL cache

The UserProfileDB is written in such a way that repeatedly makes the same
DB queries thousands of times. To workaround this, use a simple short-lived
TTL cache to dramatically improve performance.
"""
key = (tableName, tuple(outFields), tuple(sorted(condDict.items())))
if key not in self.__cache:
result = self.getFields(tableName, outFields, condDict)
if not result['OK']:
return result
data = result['Value']
if len(data) > 0:
objId = data[0][0]
self.updateFields(tableName, ['LastAccess'], ['UTC_TIMESTAMP()'], {'Id': objId})
self.__cache[key] = result
return self.__cache[key]

def __getObjId(self, objValue, varName, tableName, insertIfMissing=True):
result = self.getFields(tableName, ['Id'], {varName: objValue})
result = self.__getFieldsCached(tableName, ['Id'], {varName: objValue})
if not result['OK']:
return result
data = result['Value']
if len(data) > 0:
objId = data[0][0]
self.updateFields(tableName, ['LastAccess'], ['UTC_TIMESTAMP()'], {'Id': objId})
return S_OK(objId)
if not insertIfMissing:
return S_ERROR("No entry %s for %s defined in the DB" % (objValue, varName))
Expand Down
26 changes: 26 additions & 0 deletions FrameworkSystem/Service/UserProfileManagerHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,32 @@ def export_deleteProfileVar(self, profileName, varName):
userGroup = credDict['group']
return gUPDB.deleteVar(userName, userGroup, profileName, varName)

types_listStatesForWeb = [dict]

def export_listStatesForWeb(self, permission):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of now there's no integration test for the UserProfileClient -> UserProfileHandler -> UserProfileDB (it should be in tests/Integration/Framework). I would say that this is a good occasion for adding it.

retVal = self.export_getUserProfileNames(permission)
if not retVal["OK"]:
return retVal
data = retVal['Value']

records = []
for i in data:
application = i.replace('Web/application/', '')
retVal = self.export_listAvailableProfileVars(i)
if not retVal['OK']:
return retVal
states = retVal['Value']
for state in states:
record = dict(zip(['user', 'group', 'vo', 'name'], state))
record['app'] = application
retVal = self.export_getProfileVarPermissions(i, record['name'])
if not retVal['OK']:
return retVal
record['permissions'] = retVal['Value']
records += [record]

return S_OK(records)

types_listAvailableProfileVars = [types.StringTypes]

def export_listAvailableProfileVars(self, profileName, filterDict={}):
Expand Down
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ M2Crypto>=0.36
Sphinx>=1.8.0
docutils>=0.15
boto3
cachetools<4
elasticsearch_dsl
future
futures
Expand Down
1 change: 1 addition & 0 deletions docs/requirements_py3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ M2Crypto==0.32
Sphinx>=1.8.0
boto3
elasticsearch_dsl
cachetools
future
futures
matplotlib
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
- boto3
- certifi
- cmreshandler >1.0.0b4
- cachetools <4
- docutils
- elasticsearch-dsl ~=6.3.1
- fts-rest
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ boto3
#asn1
M2Crypto>=0.36
autopep8==1.3.3
cachetools<4

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if this file is still used or not. If not, maybe we can remove it from v7r2?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use it in LHCbDIRAC’s CI for Python 2 and I’m not particularly eager to break that while it’s stable. I hope it can be left as is until v8.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right. Sure, let's leave it.

certifi
coverage
docutils
Expand Down