Skip to content
Snippets Groups Projects
Commit dcfcccfa authored by sveseli's avatar sveseli
Browse files

introduce timer for directory processing; fix for updating file permissions...

introduce timer for directory processing; fix for updating file permissions when directory processing is used
parent 759724ab
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,7 @@ class LdapLinuxPlatformUtility: ...@@ -23,6 +23,7 @@ class LdapLinuxPlatformUtility:
CHOWN_CMD = '/bin/chown' CHOWN_CMD = '/bin/chown'
GPASSWD_CMD = '/usr/bin/gpasswd' GPASSWD_CMD = '/usr/bin/gpasswd'
NSCD_CMD = '/usr/sbin/nscd' NSCD_CMD = '/usr/sbin/nscd'
FIND_CMD = '/bin/find'
CONFIG_SECTION_NAME = 'LdapLinuxPlatformUtility' CONFIG_SECTION_NAME = 'LdapLinuxPlatformUtility'
REFRESH_AUTH_FILES_COMMAND_KEY = 'refreshauthfilescommand' REFRESH_AUTH_FILES_COMMAND_KEY = 'refreshauthfilescommand'
...@@ -337,6 +338,13 @@ class LdapLinuxPlatformUtility: ...@@ -337,6 +338,13 @@ class LdapLinuxPlatformUtility:
except Exception, ex: except Exception, ex:
logger.warn('Failed to refresh auth files: %s' % (str(ex))) logger.warn('Failed to refresh auth files: %s' % (str(ex)))
@classmethod
def chmodPathForFilesInDirectory(cls, directoryPath, fileMode):
logger = cls.getLogger()
logger.debug('Modifying permissions for all files in directory %s to %s' % (directoryPath, fileMode))
cmd = '%s %s -type f -exec chmod %s {} \;' % (cls.FIND_CMD, directoryPath, fileMode)
cls.executeCommand(cmd)
####################################################################### #######################################################################
# Testing. # Testing.
......
...@@ -12,6 +12,7 @@ class LinuxUtility: ...@@ -12,6 +12,7 @@ class LinuxUtility:
SETFACL_CMD = '/usr/bin/setfacl' SETFACL_CMD = '/usr/bin/setfacl'
CHOWN_CMD = '/bin/chown' CHOWN_CMD = '/bin/chown'
GPASSWD_CMD = '/usr/bin/gpasswd' GPASSWD_CMD = '/usr/bin/gpasswd'
FIND_CMD = '/bin/find'
@classmethod @classmethod
def getLogger(cls): def getLogger(cls):
...@@ -23,6 +24,11 @@ class LinuxUtility: ...@@ -23,6 +24,11 @@ class LinuxUtility:
p = DmSubprocess('%s %s' % (cls.SUDO_CMD, cmd)) p = DmSubprocess('%s %s' % (cls.SUDO_CMD, cmd))
p.run() p.run()
@classmethod
def executeCommand(cls, cmd):
p = DmSubprocess('%s' % (cmd))
p.run()
@classmethod @classmethod
def createGroup(cls, name): def createGroup(cls, name):
""" Create group if it does not exist. """ """ Create group if it does not exist. """
...@@ -92,6 +98,13 @@ class LinuxUtility: ...@@ -92,6 +98,13 @@ class LinuxUtility:
cmd = '%s -R \:%s "%s"' % (cls.CHOWN_CMD, groupName, path) cmd = '%s -R \:%s "%s"' % (cls.CHOWN_CMD, groupName, path)
cls.executeSudoCommand(cmd) cls.executeSudoCommand(cmd)
@classmethod
def chmodPathForFilesInDirectory(cls, directoryPath, fileMode):
logger = cls.getLogger()
logger.debug('Modifying permissions for all files in directory %s to %s' % (directoryPath, fileMode))
cmd = '%s %s -type f -exec chmod %s {} \;' % (cls.FIND_CMD, directoryPath, fileMode)
cls.executeCommand(cmd)
####################################################################### #######################################################################
# Testing. # Testing.
......
...@@ -28,8 +28,11 @@ class ExperimentManager(Singleton): ...@@ -28,8 +28,11 @@ class ExperimentManager(Singleton):
RSYNC_SCRIPT_PERMISSIONS_MODE = 0755 RSYNC_SCRIPT_PERMISSIONS_MODE = 0755
FILE_PERMISSIONS_MODE = 0640 FILE_PERMISSIONS_MODE = 0640
FILE_PERMISSIONS_MODE_STRING = '0640'
DIR_PERMISSIONS_MODE = 0750 DIR_PERMISSIONS_MODE = 0750
DIRECTORY_PROCESSING_DELAY_IN_SECONDS = 1
# Singleton. # Singleton.
__instanceLock = threading.RLock() __instanceLock = threading.RLock()
__instance = None __instance = None
...@@ -173,7 +176,6 @@ class ExperimentManager(Singleton): ...@@ -173,7 +176,6 @@ class ExperimentManager(Singleton):
if self.manageStoragePermissions: if self.manageStoragePermissions:
self.createExperimentGroup(experiment) self.createExperimentGroup(experiment)
@ThreadingUtility.synchronize
def processExperimentFile(self, experimentFilePath, experiment, fileInfo={}): def processExperimentFile(self, experimentFilePath, experiment, fileInfo={}):
experimentName = experiment.get('name') experimentName = experiment.get('name')
self.updateExperimentWithStorageDataDirectory(experiment) self.updateExperimentWithStorageDataDirectory(experiment)
...@@ -181,29 +183,30 @@ class ExperimentManager(Singleton): ...@@ -181,29 +183,30 @@ class ExperimentManager(Singleton):
filePath = os.path.join(storageDirectory, experimentFilePath) filePath = os.path.join(storageDirectory, experimentFilePath)
fileInfo['filePath'] = filePath fileInfo['filePath'] = filePath
fileInfo['experiment'] = experiment fileInfo['experiment'] = experiment
if os.path.exists(filePath): if not os.path.exists(filePath):
self.logger.debug('Processing file path %s (fileInfo: %s)' % (filePath, fileInfo)) self.logger.error('File path %s does not exist' % filePath)
if self.manageStoragePermissions: return
self.logger.debug('Modifying permissions for %s' % filePath)
OsUtility.chmodPath(filePath, fileMode=self.FILE_PERMISSIONS_MODE) if self.manageStoragePermissions:
self.logger.debug('Changing group owner for %s to %s' % (filePath, experimentName)) self.logger.debug('Setting permissions for %s to %s' % (filePath,self.FILE_PERMISSIONS_MODE_STRING))
self.platformUtility.changePathGroupOwner(filePath, experimentName) OsUtility.chmodPath(filePath, fileMode=self.FILE_PERMISSIONS_MODE)
# Recursively modify subdirectory permissions self.logger.debug('Changing group owner for %s to %s' % (filePath, experimentName))
dirPath = os.path.dirname(filePath) self.platformUtility.changePathGroupOwner(filePath, experimentName)
while (os.path.abspath(dirPath) != os.path.abspath(storageDirectory)):
if self.pathTracker.get(dirPath) is None: # Recursively modify subdirectory permissions
self.logger.debug('Changing group owner for experiment subdirectory %s to %s' % (dirPath, experimentName)) dirPath = os.path.dirname(filePath)
self.platformUtility.changePathGroupOwner(dirPath, experimentName) while (os.path.abspath(dirPath) != os.path.abspath(storageDirectory)):
ownerUpdateTime = time.time() if self.pathTracker.get(dirPath) is None:
self.pathTracker.put(dirPath, ownerUpdateTime) self.logger.debug('Changing group owner for experiment subdirectory %s to %s' % (dirPath, experimentName))
else: self.platformUtility.changePathGroupOwner(dirPath, experimentName)
self.logger.debug('Group owner for experiment subdirectory %s is already set to %s' % (dirPath, experimentName)) ownerUpdateTime = time.time()
dirPath = os.path.dirname(dirPath) self.pathTracker.put(dirPath, ownerUpdateTime)
else:
self.logger.debug('Processing file %s' % filePath) self.logger.debug('Group owner for experiment subdirectory %s is already set to %s' % (dirPath, experimentName))
self.fileProcessingManager.processFile(fileInfo) dirPath = os.path.dirname(dirPath)
else:
self.logger.debug('File path %s does not exist' % filePath) self.logger.debug('Processing file path %s (fileInfo: %s)' % (filePath, fileInfo))
self.fileProcessingManager.processFile(fileInfo)
def statExperimentFile(self, experimentFilePath, experiment, fileInfo={}): def statExperimentFile(self, experimentFilePath, experiment, fileInfo={}):
experimentName = experiment.get('name') experimentName = experiment.get('name')
...@@ -220,7 +223,6 @@ class ExperimentManager(Singleton): ...@@ -220,7 +223,6 @@ class ExperimentManager(Singleton):
self.logger.debug('File path %s does not exist' % filePath) self.logger.debug('File path %s does not exist' % filePath)
raise ObjectNotFound('File %s does not exist' % filePath) raise ObjectNotFound('File %s does not exist' % filePath)
@ThreadingUtility.synchronize
def processExperimentDirectory(self, experimentDirectoryPath, experiment, directoryInfo={}): def processExperimentDirectory(self, experimentDirectoryPath, experiment, directoryInfo={}):
experimentName = experiment.get('name') experimentName = experiment.get('name')
self.updateExperimentWithStorageDataDirectory(experiment) self.updateExperimentWithStorageDataDirectory(experiment)
...@@ -228,26 +230,46 @@ class ExperimentManager(Singleton): ...@@ -228,26 +230,46 @@ class ExperimentManager(Singleton):
directoryPath = os.path.join(storageDirectory, experimentDirectoryPath) directoryPath = os.path.join(storageDirectory, experimentDirectoryPath)
directoryInfo['directoryPath'] = directoryPath directoryInfo['directoryPath'] = directoryPath
directoryInfo['experiment'] = experiment directoryInfo['experiment'] = experiment
if os.path.exists(directoryPath):
self.logger.debug('Processing directory path %s (directoryInfo: %s)' % (directoryPath, directoryInfo)) if not self.manageStoragePermissions:
if self.manageStoragePermissions: self.logger.error('Skipping permission management for directory path %s' % directoryPath)
self.logger.debug('Modifying permissions for directory %s to %s' % (directoryPath, self.DIR_PERMISSIONS_MODE)) return
OsUtility.chmodPath(directoryPath, dirMode=self.DIR_PERMISSIONS_MODE)
self.logger.debug('Changing group owner for %s to %s' % (directoryPath, experimentName)) self.logger.debug('Processing directory path %s in background' % (directoryPath))
self.platformUtility.recursivelyChangePathGroupOwner(directoryPath, experimentName) timer = threading.Timer(self.DIRECTORY_PROCESSING_DELAY_IN_SECONDS, self.__processExperimentDirectory, args=[experimentDirectoryPath, experiment, directoryInfo])
# Recursively modify subdirectory permissions timer.start()
dirPath = os.path.dirname(directoryPath)
while (os.path.abspath(dirPath) != os.path.abspath(storageDirectory)): def __processExperimentDirectory(self, experimentDirectoryPath, experiment, directoryInfo={}):
if self.pathTracker.get(dirPath) is None: experimentName = experiment.get('name')
self.logger.debug('Changing group owner for experiment subdirectory %s to %s' % (dirPath, experimentName)) storageDirectory = experiment.get('storageDirectory')
self.platformUtility.changePathGroupOwner(dirPath, experimentName) directoryPath = directoryInfo.get('directoryPath')
ownerUpdateTime = time.time()
self.pathTracker.put(dirPath, ownerUpdateTime) if not os.path.exists(directoryPath):
else: self.logger.error('Directory path %s does not exist' % directoryPath)
self.logger.debug('Group owner for experiment subdirectory %s is already set to %s' % (dirPath, experimentName)) return
dirPath = os.path.dirname(dirPath)
else: # Modify ownership
self.logger.debug('Directory path %s does not exist' % directoryPath) self.logger.debug('Processing directory path %s (directoryInfo: %s)' % (directoryPath, directoryInfo))
self.logger.debug('Modifying permissions for directory %s to %s' % (directoryPath, self.DIR_PERMISSIONS_MODE))
OsUtility.chmodPath(directoryPath, dirMode=self.DIR_PERMISSIONS_MODE)
self.logger.debug('Changing group owner for %s to %s' % (directoryPath, experimentName))
self.platformUtility.recursivelyChangePathGroupOwner(directoryPath, experimentName)
# Recursively modify subdirectory permissions
dirPath = os.path.dirname(directoryPath)
while (os.path.abspath(dirPath) != os.path.abspath(storageDirectory)):
if self.pathTracker.get(dirPath) is None:
self.logger.debug('Changing group owner for experiment subdirectory %s to %s' % (dirPath, experimentName))
self.platformUtility.changePathGroupOwner(dirPath, experimentName)
ownerUpdateTime = time.time()
self.pathTracker.put(dirPath, ownerUpdateTime)
else:
self.logger.debug('Group owner for experiment subdirectory %s is already set to %s' % (dirPath, experimentName))
dirPath = os.path.dirname(dirPath)
# Update file permissions
self.logger.debug('Changing permissions for all files in %s for experiment %s' % (directoryPath, experimentName))
self.platformUtility.chmodPathForFilesInDirectory(directoryPath, self.FILE_PERMISSIONS_MODE_STRING)
@ThreadingUtility.synchronize @ThreadingUtility.synchronize
def start(self): def start(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment