Search in sources :

Example 46 with ContainmentConstraint

use of com.emc.storageos.db.client.constraint.ContainmentConstraint 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)

Example 47 with ContainmentConstraint

use of com.emc.storageos.db.client.constraint.ContainmentConstraint in project coprhd-controller by CoprHD.

the class ObjectDeviceController method queryDbBucketAcl.

private List<ObjectBucketACL> queryDbBucketAcl(ObjectDeviceInputOutput args, URI bucketId) {
    List<ObjectBucketACL> acls = new ArrayList<ObjectBucketACL>();
    try {
        ContainmentConstraint containmentConstraint = null;
        _log.info("Querying DB for ACL of Bucket {} ", args.getName());
        containmentConstraint = ContainmentConstraint.Factory.getBucketAclsConstraint(bucketId);
        List<ObjectBucketACL> bucketAclList = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, ObjectBucketACL.class, containmentConstraint);
        Iterator<ObjectBucketACL> bucketAclIter = bucketAclList.iterator();
        while (bucketAclIter.hasNext()) {
            ObjectBucketACL bucketAce = bucketAclIter.next();
            if (args.getName().equals(bucketAce.getBucketName())) {
                acls.add(bucketAce);
            }
        }
    } catch (Exception e) {
        _log.error("Error while querying DB for ACL(s) of a share {}", e);
    }
    return acls;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ArrayList(java.util.ArrayList) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) ObjectBucketACL(com.emc.storageos.db.client.model.ObjectBucketACL)

Aggregations

ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)47 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)18 ArrayList (java.util.ArrayList)17 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)15 URI (java.net.URI)15 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 ControllerException (com.emc.storageos.volumecontroller.ControllerException)11 URISyntaxException (java.net.URISyntaxException)11 FileExportRule (com.emc.storageos.db.client.model.FileExportRule)10 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)9 FileShare (com.emc.storageos.db.client.model.FileShare)7 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)7 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)6 WorkflowException (com.emc.storageos.workflow.WorkflowException)6 ContainmentConstraintImpl (com.emc.storageos.db.client.constraint.impl.ContainmentConstraintImpl)5 FileMountInfo (com.emc.storageos.db.client.model.FileMountInfo)5 CifsShareACL (com.emc.storageos.db.client.model.CifsShareACL)4 NFSShareACL (com.emc.storageos.db.client.model.NFSShareACL)4 ExportRule (com.emc.storageos.model.file.ExportRule)4 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)4