Search in sources :

Example 16 with ExportRules

use of com.emc.storageos.model.file.ExportRules in project coprhd-controller by CoprHD.

the class FileDeviceController method doCRUDExports.

private void doCRUDExports(FileExportUpdateParams param, FileShare fs, FileDeviceInputOutput args) throws Exception {
    try {
        // create new exports
        ExportRules exportRules = param.getExportRulesToAdd();
        List<ExportRule> rules;
        if (exportRules != null) {
            rules = exportRules.getExportRules();
            if (rules != null && !rules.isEmpty()) {
                for (ExportRule exportRule : rules) {
                    FileExportRule rule = new FileExportRule();
                    rule.setId(URIUtil.createId(FileExportRule.class));
                    copyPropertiesToSave(rule, exportRule, fs, args);
                    _log.info("Storing New DB Export Rule {}", rule);
                    _dbClient.createObject(rule);
                }
            }
        }
        // Modify Existing Exports
        exportRules = param.getExportRulesToModify();
        if (exportRules != null) {
            rules = exportRules.getExportRules();
            if (rules != null && !rules.isEmpty()) {
                for (ExportRule exportRule : rules) {
                    FileExportRule rule = new FileExportRule();
                    // Copy the properties to build the index id to query DB for existing Export Rule
                    copyPropertiesToSave(rule, exportRule, fs, args);
                    rule = getAvailableExportRule(rule, args);
                    // Remove the existing and create the new one.
                    // Don't Update the existing one as persist object will create a new StringSet rather
                    // it updates the existing one with new information and upon keeping/appending to old one.
                    rule.setInactive(true);
                    _log.info("Removing Existing DB Export Rule {}", rule);
                    _dbClient.updateObject(rule);
                    FileExportRule newRule = new FileExportRule();
                    newRule.setId(URIUtil.createId(FileExportRule.class));
                    // Now, Copy the properties again into the rule came out of DB, before updating.
                    copyPropertiesToSave(newRule, exportRule, fs, args);
                    _log.info("Storing New DB Export Rule {}", newRule);
                    _dbClient.createObject(newRule);
                }
            }
        }
        // Delete Existing Exports
        exportRules = param.getExportRulesToDelete();
        if (exportRules != null) {
            rules = exportRules.getExportRules();
            if (rules != null && !rules.isEmpty()) {
                for (ExportRule exportRule : rules) {
                    FileExportRule rule = new FileExportRule();
                    copyPropertiesToSave(rule, exportRule, fs, args);
                    rule = getAvailableExportRule(rule, args);
                    rule.setInactive(true);
                    _log.info("Marking DB Export Rule Inactive {}", rule);
                    _dbClient.updateObject(rule);
                }
            }
            // Delete the ExportMap entry if there are no export rules for this file system or sub directory
            FSExportMap fsNFSExportMap = fs.getFsExports();
            ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileExportRulesConstraint(fs.getId());
            List<FileExportRule> fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileExportRule.class, containmentConstraint);
            Set<String> fileExportMapKeys = fsNFSExportMap.keySet();
            Iterator<String> keySetIterator = fileExportMapKeys.iterator();
            HashSet<String> keystoRemove = new HashSet<String>();
            while (keySetIterator.hasNext()) {
                String fileExportMapKey = keySetIterator.next();
                FileExport fileExport = fsNFSExportMap.get(fileExportMapKey);
                boolean exportRuleExists = false;
                for (FileExportRule fileExportRule : fileExportRules) {
                    if (fileExportRule.getExportPath().equals(fileExport.getMountPath())) {
                        exportRuleExists = true;
                        break;
                    }
                }
                if (!exportRuleExists) {
                    keystoRemove.add(fileExportMapKey);
                }
            }
            for (String key : keystoRemove) {
                _log.info("Deleting file export map entry : {} for key : {}", fsNFSExportMap.get(key), key);
                fsNFSExportMap.remove(key);
            }
            _dbClient.updateObject(fs);
        }
    } catch (Exception e) {
        _log.info("Error While executing CRUD Operations {}", e);
    }
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ExportRules(com.emc.storageos.model.file.ExportRules) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) FileExport(com.emc.storageos.db.client.model.FileExport) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ExportRule(com.emc.storageos.model.file.ExportRule) HashSet(java.util.HashSet)

Aggregations

ExportRules (com.emc.storageos.model.file.ExportRules)16 ExportRule (com.emc.storageos.model.file.ExportRule)13 FileExportRule (com.emc.storageos.db.client.model.FileExportRule)6 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)4 FlashException (controllers.util.FlashException)4 ExportOperationErrorType (com.emc.storageos.model.file.FileExportUpdateParams.ExportOperationErrorType)3 FileShareExportUpdateParams (com.emc.storageos.model.file.FileShareExportUpdateParams)3 SnapshotExportUpdateParams (com.emc.storageos.model.file.SnapshotExportUpdateParams)3 HashSet (java.util.HashSet)3 DeactivateFileSnapshotExportRule (com.emc.sa.service.vipr.file.tasks.DeactivateFileSnapshotExportRule)2 DeactivateFileSystemExportRule (com.emc.sa.service.vipr.file.tasks.DeactivateFileSystemExportRule)2 FindFileSnapshotExportRules (com.emc.sa.service.vipr.file.tasks.FindFileSnapshotExportRules)2 FindFileSystemExportRules (com.emc.sa.service.vipr.file.tasks.FindFileSystemExportRules)2 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)2 FileShare (com.emc.storageos.db.client.model.FileShare)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 FileShareRestRep (com.emc.storageos.model.file.FileShareRestRep)2 FileSnapshotRestRep (com.emc.storageos.model.file.FileSnapshotRestRep)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)2