Search in sources :

Example 11 with FileExportRule

use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.

the class FileSystemExportToFileSystemExportRuleMigration method createFSExportRules.

private List<FileExportRule> createFSExportRules(FileShare fileShare) {
    List<FileExportRule> fsExpRuleList = new ArrayList<FileExportRule>();
    FSExportMap fsExportMap = fileShare.getFsExports();
    if (fsExportMap != null) {
        for (String exportKey : fsExportMap.keySet()) {
            FileExport fsExport = fsExportMap.get(exportKey);
            FileExportRule expRule = new FileExportRule();
            expRule.setId(URIUtil.createId(FileExportRule.class));
            copyFileExportData(fsExport, expRule);
            // Set fileSystemId in the end as setFileSystemId() calculates
            // fsExportIndex with exportPath and security flavor
            expRule.setFileSystemId(fileShare.getId());
            fsExpRuleList.add(expRule);
        }
    }
    return fsExpRuleList;
}
Also used : FileExportRule(com.emc.storageos.db.client.model.FileExportRule) ArrayList(java.util.ArrayList) FileExport(com.emc.storageos.db.client.model.FileExport) FSExportMap(com.emc.storageos.db.client.model.FSExportMap)

Example 12 with FileExportRule

use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.

the class VNXeExportFileSystemJob method updateExportRules.

private void updateExportRules(URI uri, FileExport fileExport, DbClient dbClient) {
    List<FileExportRule> existingRules = queryFileExports(uri, dbClient);
    FileExportRule newRule = getFileExportRule(uri, fileExport);
    if (existingRules != null && existingRules.isEmpty()) {
        newRule.setId(URIUtil.createId(FileExportRule.class));
        _logger.info("No Existing rules available for this FS Export and so creating the rule now {}", newRule);
        dbClient.createObject(newRule);
    } else {
        _logger.debug("Checking inside for ExitingRule(s) available for this export");
        boolean isRuleFound = false;
        for (FileExportRule rule : existingRules) {
            _logger.debug("Available Export Rule {} - Matching with New Rule {}", rule, newRule);
            if (newRule.getFsExportIndex() != null && rule.getFsExportIndex().equals(newRule.getFsExportIndex())) {
                isRuleFound = true;
                _logger.info("Match Found : Skipping this Rule as alreday available {}", newRule);
                break;
            }
        }
        if (!isRuleFound) {
            _logger.info("Creating new Export Rule {}", newRule);
            newRule.setId(URIUtil.createId(FileExportRule.class));
            dbClient.createObject(newRule);
        }
    }
}
Also used : FileExportRule(com.emc.storageos.db.client.model.FileExportRule)

Example 13 with FileExportRule

use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.

the class VNXeExportFileSystemJob method queryFileExports.

private List<FileExportRule> queryFileExports(URI uri, DbClient dbClient) {
    List<FileExportRule> fileExportRules = null;
    try {
        ContainmentConstraint containmentConstraint;
        if (isFile) {
            _logger.info("Querying all ExportRules Using FsId {}", uri);
            containmentConstraint = ContainmentConstraint.Factory.getFileExportRulesConstraint(uri);
        } else {
            _logger.info("Querying all ExportRules Using Snapshot Id {}", uri);
            containmentConstraint = ContainmentConstraint.Factory.getSnapshotExportRulesConstraint(uri);
        }
        fileExportRules = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, FileExportRule.class, containmentConstraint);
    } catch (Exception e) {
        _logger.error("Error while querying {}", e);
    }
    return fileExportRules;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) FileExportRule(com.emc.storageos.db.client.model.FileExportRule)

Example 14 with FileExportRule

use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.

the class VNXeModifyExportJob method updateExportRules.

/**
 * update FileShare after exported in VNXe
 *
 * @param fsOjb fileShare object in vipr
 * @param dbClient DbClient
 * @param vnxeApiClient VNXeApiClient
 */
private void updateExportRules(VNXeApiClient vnxeApiClient, DbClient dbClient, FileShare fileObj, VNXeNfsShare nfsShare) {
    _logger.info("updating file export. ");
    try {
        // Modify Existing Exports
        FileExportRule newRule = new FileExportRule();
        URI snapshotId = null;
        if (!isFile) {
            snapshotId = getTaskCompleter().getId();
        }
        // Copy the properties to build the index id to query DB for existing Export Rule
        copyPropertiesToSave(newRule, rule, fileObj, dbClient, snapshotId);
        newRule = getAvailableExportRule(newRule, dbClient);
        // it updates the existing one with new information and upon keeping/appending to old one.
        if (newRule != null) {
            newRule.setInactive(true);
            _logger.info("Removing Existing DB Export Rule {}", rule);
            dbClient.persistObject(newRule);
        }
        if (!isDeleteRule) {
            newRule = new FileExportRule();
            newRule.setId(URIUtil.createId(FileExportRule.class));
            if (nfsShare != null) {
                if (nfsShare.getReadOnlyHosts() != null) {
                    Set<String> hosts = new HashSet<String>();
                    for (VNXeBase hostId : nfsShare.getReadOnlyHosts()) {
                        hosts.add(vnxeApiClient.getHostById(hostId.getId()).getName());
                    }
                    rule.setReadOnlyHosts(hosts);
                }
                if (nfsShare.getReadWriteHosts() != null) {
                    Set<String> hosts = new HashSet<String>();
                    for (VNXeBase hostId : nfsShare.getReadWriteHosts()) {
                        hosts.add(vnxeApiClient.getHostById(hostId.getId()).getName());
                    }
                    rule.setReadWriteHosts(hosts);
                }
                if (nfsShare.getRootAccessHosts() != null) {
                    Set<String> hosts = new HashSet<String>();
                    for (VNXeBase hostId : nfsShare.getRootAccessHosts()) {
                        hosts.add(vnxeApiClient.getHostById(hostId.getId()).getName());
                    }
                    rule.setRootHosts(hosts);
                }
            }
            // Now, Copy the properties again into the rule came out of DB, before updating.
            copyPropertiesToSave(newRule, rule, fileObj, dbClient, snapshotId);
            _logger.info("Storing New DB Export Rule {}", newRule);
            dbClient.createObject(newRule);
        }
    } catch (Exception e) {
        _logger.info("Error While executing CRUD Operations {}", e);
    }
}
Also used : VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) HashSet(java.util.HashSet)

Example 15 with FileExportRule

use of com.emc.storageos.db.client.model.FileExportRule in project coprhd-controller by CoprHD.

the class VNXeUnexportFileSystemJob method updateExportRule.

private void updateExportRule(DbClient dbClient, FileExportRule rule) {
    // Query Existing Export rule and if found set to delete.
    URIQueryResultList dbresult = new URIQueryResultList();
    if (!isFile && rule.getSnapshotExportIndex() != null) {
        dbClient.queryByConstraint(AlternateIdConstraint.Factory.getSnapshotExportRuleConstraint(rule.getSnapshotExportIndex()), dbresult);
    } else if (rule.getFsExportIndex() != null) {
        dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFileExportRuleConstraint(rule.getFsExportIndex()), dbresult);
    }
    Iterator<URI> it = dbresult.iterator();
    while (it.hasNext()) {
        if (dbresult.iterator().hasNext()) {
            rule = dbClient.queryObject(FileExportRule.class, it.next());
            if (rule != null && !rule.getInactive()) {
                _logger.info("Existing DB Model found {}", rule);
                rule.setInactive(true);
                dbClient.persistObject(rule);
                break;
            }
        }
    }
}
Also used : FileExportRule(com.emc.storageos.db.client.model.FileExportRule) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

FileExportRule (com.emc.storageos.db.client.model.FileExportRule)37 URI (java.net.URI)13 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)11 URISyntaxException (java.net.URISyntaxException)11 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)10 FileShare (com.emc.storageos.db.client.model.FileShare)10 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)10 ExportRule (com.emc.storageos.model.file.ExportRule)10 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)10 ArrayList (java.util.ArrayList)8 ControllerException (com.emc.storageos.volumecontroller.ControllerException)7 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)6 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)6 Snapshot (com.emc.storageos.db.client.model.Snapshot)6 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)6 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)5 FileExport (com.emc.storageos.db.client.model.FileExport)5 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)5 WorkflowException (com.emc.storageos.workflow.WorkflowException)5 StringSet (com.emc.storageos.db.client.model.StringSet)4