Search in sources :

Example 16 with ExportRule

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

the class VNXFileStorageDeviceXML method extraExportRuleFromArray.

/**
 * Get the export rule which are present in array but not in CoprHD Database.
 *
 * @param storage
 * @param args
 * @return map with security flavor and export rule
 */
private Map<String, ExportRule> extraExportRuleFromArray(StorageSystem storage, FileDeviceInputOutput args) {
    // map to store the export rule grouped by sec flavor
    Map<String, ExportRule> exportRuleMap = new HashMap<>();
    Set<String> arrayReadOnlyHost = new HashSet<>();
    Set<String> arrayReadWriteHost = new HashSet<>();
    Set<String> arrayRootHost = new HashSet<>();
    Set<String> dbReadOnlyHost = new HashSet<>();
    Set<String> dbReadWriteHost = new HashSet<>();
    Set<String> dbRootHost = new HashSet<>();
    // get all export rule from CoprHD data base
    List<ExportRule> existingDBExportRules = args.getExistingDBExportRules();
    // get the all the export from the storage system.
    ApplicationContext context = null;
    context = loadContext();
    VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
    if (null == vnxComm) {
        throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
    }
    for (ExportRule exportRule : existingDBExportRules) {
        if (exportRule.getReadOnlyHosts() != null) {
            dbReadOnlyHost.addAll(exportRule.getReadOnlyHosts());
        }
        if (exportRule.getReadWriteHosts() != null) {
            dbReadWriteHost.addAll(exportRule.getReadWriteHosts());
        }
        if (exportRule.getRootHosts() != null) {
            dbRootHost.addAll(exportRule.getRootHosts());
        }
        Map<String, String> vnxExportMap = null;
        vnxExportMap = vnxComm.getNFSExport(storage, args);
        String readOnlyList = vnxExportMap.get("ro");
        String readWriteList = vnxExportMap.get("rw");
        String rootList = vnxExportMap.get("root");
        // we get multiple value each separated by :
        if (readOnlyList != null) {
            for (String readOnly : readOnlyList.split(":")) {
                if (!readOnly.equals("null")) {
                    arrayReadOnlyHost.add(readOnly);
                }
            }
        }
        if (readWriteList != null) {
            for (String readWrite : readWriteList.split(":")) {
                if (!readWrite.equals("null")) {
                    arrayReadWriteHost.add(readWrite);
                }
            }
        }
        if (rootList != null) {
            for (String root : rootList.split(":")) {
                if (!root.equals("null")) {
                    arrayRootHost.add(root);
                }
            }
        }
        // find out the change between array and CoprHD database.
        Set<String> arrayExtraReadOnlyHost = Sets.difference(arrayReadOnlyHost, dbReadOnlyHost);
        Set<String> arrayExtraReadWriteHost = Sets.difference(arrayReadWriteHost, dbReadWriteHost);
        Set<String> arrayExtraRootHost = Sets.difference(arrayRootHost, dbRootHost);
        // if change found update the exportRuleMap
        if (!arrayExtraReadOnlyHost.isEmpty() || !arrayExtraReadWriteHost.isEmpty() || !arrayExtraRootHost.isEmpty()) {
            ExportRule extraRuleFromArray = new ExportRule();
            extraRuleFromArray.setDeviceExportId(exportRule.getDeviceExportId());
            extraRuleFromArray.setAnon(exportRule.getAnon());
            extraRuleFromArray.setSecFlavor(exportRule.getSecFlavor());
            extraRuleFromArray.setExportPath(exportRule.getExportPath());
            extraRuleFromArray.setReadOnlyHosts(arrayExtraReadOnlyHost);
            extraRuleFromArray.setReadWriteHosts(arrayExtraReadWriteHost);
            extraRuleFromArray.setRootHosts(arrayExtraRootHost);
            exportRuleMap.put(exportRule.getSecFlavor(), extraRuleFromArray);
        }
    }
    return exportRuleMap;
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) HashMap(java.util.HashMap) VNXFileCommApi(com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi) ExportRule(com.emc.storageos.model.file.ExportRule) HashSet(java.util.HashSet)

Example 17 with ExportRule

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

the class VNXeStorageDevice method processDeleteRules.

private void processDeleteRules(List<ExportRule> exportDelete, ExportRule existingRule, List<ExportRule> exportsToRemove, List<ExportRule> exportsToAdd) {
    for (ExportRule oldExport : exportDelete) {
        if (oldExport.getSecFlavor().equals(existingRule.getSecFlavor())) {
            _logger.info("Deleting Export Rule {}", existingRule);
            exportsToRemove.add(existingRule);
            ExportRule rule = new ExportRule();
            rule.setSecFlavor("sys");
            rule.setAnon("root");
            rule.setExportPath(existingRule.getExportPath());
            rule.setDeviceExportId(existingRule.getDeviceExportId());
            exportsToAdd.add(rule);
            break;
        }
    }
}
Also used : ExportRule(com.emc.storageos.model.file.ExportRule)

Example 18 with ExportRule

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

the class VNXeStorageDevice method extraExportRuleFromArray.

/**
 * Get the export rule which are present in array but not in CoprHD Database.
 *
 * @param storage
 * @param args
 * @return map with security flavor and export rule
 */
private Map<String, ExportRule> extraExportRuleFromArray(StorageSystem storage, FileDeviceInputOutput args) {
    // map to store the export rule grouped by sec flavor
    Map<String, ExportRule> exportRuleMap = new HashMap<>();
    List<VNXeNfsShare> exportsList = new ArrayList<VNXeNfsShare>();
    Set<String> arrayReadOnlyHost = new HashSet<>();
    Set<String> arrayReadWriteHost = new HashSet<>();
    Set<String> arrayRootHost = new HashSet<>();
    Set<String> dbReadOnlyHost = new HashSet<>();
    Set<String> dbReadWriteHost = new HashSet<>();
    Set<String> dbRootHost = new HashSet<>();
    // get all export rule from CoprHD data base
    List<ExportRule> existingDBExportRules = args.getExistingDBExportRules();
    // get the all the export from the storage system.
    VNXeApiClient apiClient = getVnxeClient(storage);
    for (ExportRule exportRule : existingDBExportRules) {
        if (exportRule.getReadOnlyHosts() != null) {
            dbReadOnlyHost.addAll(exportRule.getReadOnlyHosts());
        }
        if (exportRule.getReadWriteHosts() != null) {
            dbReadWriteHost.addAll(exportRule.getReadWriteHosts());
        }
        if (exportRule.getRootHosts() != null) {
            dbRootHost.addAll(exportRule.getRootHosts());
        }
        String vnxeExportId = exportRule.getDeviceExportId();
        if (vnxeExportId != null) {
            List<VNXeNfsShare> vnxeExports = null;
            vnxeExports = apiClient.getNfsSharesForFileSystem(args.getFs().getNativeId());
            exportsList.addAll(vnxeExports);
            for (VNXeNfsShare vnXeNfsShare : vnxeExports) {
                List<VNXeBase> hostIdReadOnly = vnXeNfsShare.getReadOnlyHosts();
                for (VNXeBase vnXeBase : hostIdReadOnly) {
                    VNXeHost host = apiClient.getHostById(vnXeBase.getId());
                    arrayReadOnlyHost.add(host.getName());
                }
                List<VNXeBase> hostIdReadWrite = vnXeNfsShare.getReadWriteHosts();
                for (VNXeBase vnXeBase : hostIdReadWrite) {
                    VNXeHost host = apiClient.getHostById(vnXeBase.getId());
                    arrayReadWriteHost.add(host.getName());
                }
                List<VNXeBase> hostIdRootHost = vnXeNfsShare.getRootAccessHosts();
                for (VNXeBase vnXeBase : hostIdRootHost) {
                    VNXeHost host = apiClient.getHostById(vnXeBase.getId());
                    arrayRootHost.add(host.getName());
                }
            }
        }
        // find out the change between array and CoprHD database.
        Set<String> arrayExtraReadOnlyHost = Sets.difference(arrayReadOnlyHost, dbReadOnlyHost);
        Set<String> arrayExtraReadWriteHost = Sets.difference(arrayReadWriteHost, dbReadWriteHost);
        Set<String> arrayExtraRootHost = Sets.difference(arrayRootHost, dbRootHost);
        // if change found update the exportRuleMap
        if (!arrayExtraReadOnlyHost.isEmpty() || !arrayExtraReadWriteHost.isEmpty() || !arrayExtraRootHost.isEmpty()) {
            ExportRule extraRuleFromArray = new ExportRule();
            extraRuleFromArray.setDeviceExportId(exportRule.getDeviceExportId());
            extraRuleFromArray.setAnon(exportRule.getAnon());
            extraRuleFromArray.setSecFlavor(exportRule.getSecFlavor());
            extraRuleFromArray.setExportPath(exportRule.getExportPath());
            extraRuleFromArray.setReadOnlyHosts(arrayExtraReadOnlyHost);
            extraRuleFromArray.setReadWriteHosts(arrayExtraReadWriteHost);
            extraRuleFromArray.setRootHosts(arrayExtraRootHost);
            exportRuleMap.put(exportRule.getSecFlavor(), extraRuleFromArray);
        }
    }
    return exportRuleMap;
}
Also used : HashMap(java.util.HashMap) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) ArrayList(java.util.ArrayList) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) VNXeNfsShare(com.emc.storageos.vnxe.models.VNXeNfsShare) ExportRule(com.emc.storageos.model.file.ExportRule) HashSet(java.util.HashSet)

Example 19 with ExportRule

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

the class FileOperationUtils method findExport.

public static ExportRule findExport(FileShare fs, String subDirectory, String securityType, DbClient dbClient) {
    dbClient.queryByType(FileShare.class, true);
    List<ExportRule> exportList = getExportRules(fs.getId(), false, subDirectory, dbClient);
    for (ExportRule export : exportList) {
        List<String> securityTypes = Arrays.asList(export.getSecFlavor().split("\\s*,\\s*"));
        if (securityTypes.contains(securityType)) {
            return export;
        }
    }
    throw new IllegalArgumentException("No exports found for the provided security type and subdirectory.");
}
Also used : ExportRule(com.emc.storageos.model.file.ExportRule) FileExportRule(com.emc.storageos.db.client.model.FileExportRule)

Example 20 with ExportRule

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

the class FileStorageUtils method updateFileSnapshotExport.

public static String updateFileSnapshotExport(URI fileSnapshotId, String subDirectory, FileExportRule[] fileExportRules) {
    List<ExportRule> exportRuleList = getFileSnapshotExportRules(fileSnapshotId, false, subDirectory);
    Set<String> existingRuleSet = Sets.newHashSet();
    for (ExportRule rule : exportRuleList) {
        existingRuleSet.add(rule.getSecFlavor());
    }
    List<ExportRule> exportRuleListToAdd = Lists.newArrayList();
    List<ExportRule> exportRuleListToModify = Lists.newArrayList();
    for (FileExportRule rule : fileExportRules) {
        ExportRule exportRule = new ExportRule();
        exportRule.setFsID(fileSnapshotId);
        exportRule.setSecFlavor(rule.security);
        String rootUserMapping = rule.rootUserMapping;
        String domain = rule.domain;
        if (StringUtils.isNotBlank(domain)) {
            rootUserMapping = domain.trim() + "\\" + rootUserMapping.trim();
        }
        exportRule.setAnon(rootUserMapping);
        Set<String> exportHosts = new HashSet<String>(rule.exportHosts);
        switch(rule.getPermission()) {
            case "ro":
                exportRule.setReadOnlyHosts(exportHosts);
                break;
            case "rw":
                exportRule.setReadWriteHosts(exportHosts);
                break;
            case "root":
                exportRule.setRootHosts(exportHosts);
                break;
            default:
                break;
        }
        if (existingRuleSet.contains(exportRule.getSecFlavor())) {
            exportRuleListToModify.add(exportRule);
        } else {
            exportRuleListToAdd.add(exportRule);
        }
    }
    SnapshotExportUpdateParams params = new SnapshotExportUpdateParams();
    if (!exportRuleListToAdd.isEmpty()) {
        ExportRules exportRulesToAdd = new ExportRules();
        exportRulesToAdd.setExportRules(exportRuleListToAdd);
        params.setExportRulesToAdd(exportRulesToAdd);
    }
    if (!exportRuleListToModify.isEmpty()) {
        ExportRules exportRulesToModify = new ExportRules();
        exportRulesToModify.setExportRules(exportRuleListToModify);
        params.setExportRulesToModify(exportRulesToModify);
    }
    Task<FileSnapshotRestRep> task = execute(new UpdateFileSnapshotExport(fileSnapshotId, subDirectory, params));
    addAffectedResource(task);
    String exportId = task.getResourceId().toString();
    logInfo("file.storage.export.task", exportId, task.getOpId());
    return exportId;
}
Also used : SnapshotExportUpdateParams(com.emc.storageos.model.file.SnapshotExportUpdateParams) FileSnapshotRestRep(com.emc.storageos.model.file.FileSnapshotRestRep) FindFileSnapshotExportRules(com.emc.sa.service.vipr.file.tasks.FindFileSnapshotExportRules) FindFileSystemExportRules(com.emc.sa.service.vipr.file.tasks.FindFileSystemExportRules) ExportRules(com.emc.storageos.model.file.ExportRules) DeactivateFileSystemExportRule(com.emc.sa.service.vipr.file.tasks.DeactivateFileSystemExportRule) DeactivateFileSnapshotExportRule(com.emc.sa.service.vipr.file.tasks.DeactivateFileSnapshotExportRule) ExportRule(com.emc.storageos.model.file.ExportRule) HashSet(java.util.HashSet) UpdateFileSnapshotExport(com.emc.sa.service.vipr.file.tasks.UpdateFileSnapshotExport)

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