Search in sources :

Example 66 with ExportRule

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

the class FileDeviceController method queryExports.

private List<ExportRule> queryExports(FileDeviceInputOutput args) {
    List<ExportRule> rules = null;
    try {
        ContainmentConstraint containmentConstraint;
        if (args.getFileOperation()) {
            FileShare fs = args.getFs();
            _log.info("Querying all ExportRules Using FsId {}", fs.getId());
            containmentConstraint = ContainmentConstraint.Factory.getFileExportRulesConstraint(fs.getId());
        } else {
            URI snapshotId = args.getSnapshotId();
            _log.info("Querying all ExportRules Using Snapshot Id {}", snapshotId);
            containmentConstraint = ContainmentConstraint.Factory.getSnapshotExportRulesConstraint(snapshotId);
        }
        List<FileExportRule> fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, FileExportRule.class, containmentConstraint);
        rules = new ArrayList<>();
        for (FileExportRule fileExportRule : fileExportRules) {
            ExportRule rule = new ExportRule();
            getExportRule(fileExportRule, rule);
            rules.add(rule);
        }
    } catch (Exception e) {
        _log.error("Error while querying {}", e);
    }
    return rules;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ExportRule(com.emc.storageos.model.file.ExportRule) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URI(java.net.URI) 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)

Example 67 with ExportRule

use of com.emc.storageos.model.file.ExportRule 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

ExportRule (com.emc.storageos.model.file.ExportRule)67 ArrayList (java.util.ArrayList)27 FileExportRule (com.emc.storageos.db.client.model.FileExportRule)22 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)17 FileShare (com.emc.storageos.db.client.model.FileShare)16 ExportRules (com.emc.storageos.model.file.ExportRules)13 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)12 ControllerException (com.emc.storageos.volumecontroller.ControllerException)12 HashSet (java.util.HashSet)12 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)10 HashMap (java.util.HashMap)10 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)8 Snapshot (com.emc.storageos.db.client.model.Snapshot)7 FileExport (com.emc.storageos.db.client.model.FileExport)6 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)6 ViPRCoreClient (com.emc.vipr.client.ViPRCoreClient)6 URI (java.net.URI)6 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)5 VNXeException (com.emc.storageos.vnxe.VNXeException)4 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)4