Search in sources :

Example 51 with ExportRule

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

the class IsilonFileStorageDevice method extraExportRuleFromArray.

/**
 * Get the export rule which are present in arry 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<IsilonExport> exportsList = new ArrayList<IsilonExport>();
    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.
    IsilonApi isi = getIsilonDevice(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 isilonExportId = exportRule.getDeviceExportId();
        if (isilonExportId != null) {
            IsilonExport isilonExport = null;
            String zoneName = getZoneName(args.getvNAS());
            if (zoneName != null) {
                isilonExport = isi.getExport(isilonExportId, zoneName);
            } else {
                isilonExport = isi.getExport(isilonExportId);
            }
            exportsList.add(isilonExport);
            arrayReadOnlyHost.addAll(isilonExport.getReadOnlyClients());
            arrayReadWriteHost.addAll(isilonExport.getReadWriteClients());
            arrayRootHost.addAll(isilonExport.getRootClients());
        }
        // 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 : IsilonExport(com.emc.storageos.isilon.restapi.IsilonExport) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ExportRule(com.emc.storageos.model.file.ExportRule) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) HashSet(java.util.HashSet)

Example 52 with ExportRule

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

the class NetAppFileStorageDevice method deleteExportRules.

@Override
public BiosCommandResult deleteExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).build();
    List<ExportRule> allExports = args.getExistingDBExportRules();
    String subDir = args.getSubDirectory();
    boolean allDirs = args.isAllDir();
    FileShare fs = args.getFs();
    String exportPath;
    String subDirExportPath = "";
    subDir = args.getSubDirectory();
    if (!args.getFileOperation()) {
        exportPath = args.getSnapshotPath();
        if (subDir != null && subDir.length() > 0) {
            subDirExportPath = args.getSnapshotPath() + "/" + subDir;
        }
    } else {
        exportPath = args.getFs().getPath();
        if (subDir != null && subDir.length() > 0) {
            subDirExportPath = args.getFs().getPath() + "/" + subDir;
        }
    }
    _log.info("exportPath : {}", exportPath);
    args.setExportPath(exportPath);
    _log.info("Number of existing exports found {}", allExports.size());
    try {
        if (allDirs) {
            Set<String> allPaths = new HashSet<String>();
            // ALL EXPORTS
            _log.info("Deleting all exports specific to filesystem at device and rules from DB including sub dirs rules and exports");
            for (ExportRule rule : allExports) {
                allPaths.add(rule.getExportPath());
            }
            for (String path : allPaths) {
                _log.info("deleting export path : {} ", path);
                nApi.deleteNFSExport(path);
            }
        } else if (subDir != null && !subDir.isEmpty()) {
            // Filter for a specific Sub Directory export
            _log.info("Deleting all subdir exports rules at ViPR and  sub directory export at device {}", subDir);
            for (ExportRule rule : allExports) {
                if (rule.getExportPath().endsWith("/" + subDir)) {
                    nApi.deleteNFSExport(subDirExportPath);
                    break;
                }
            }
        } else {
            // Filter for No SUBDIR - main export rules with no sub dirs
            _log.info("Deleting all export rules  from DB and export at device not included sub dirs");
            nApi.deleteNFSExport(exportPath);
        }
    } catch (NetAppException e) {
        _log.info("Exception:" + e.getMessage());
        throw new DeviceControllerException("Exception while performing export for {0} ", new Object[] { args.getFsId() });
    }
    _log.info("NetAppFileStorageDevice exportFS {} - complete", args.getFsId());
    result.setCommandSuccess(true);
    result.setCommandStatus(Operation.Status.ready.name());
    return result;
}
Also used : FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) NetAppException(com.emc.storageos.netapp.NetAppException) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ExportRule(com.emc.storageos.model.file.ExportRule) NetAppApi(com.emc.storageos.netapp.NetAppApi) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HashSet(java.util.HashSet)

Example 53 with ExportRule

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

the class NetAppFileStorageDevice method updateExportRules.

@Override
public BiosCommandResult updateExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    // Requested Export Rules
    List<ExportRule> exportAdd = args.getExportRulesToAdd();
    List<ExportRule> exportDelete = args.getExportRulesToDelete();
    List<ExportRule> exportModify = args.getExportRulesToModify();
    // To be processed export rules
    List<ExportRule> exportsToRemove = new ArrayList<>();
    List<ExportRule> exportsToAdd = new ArrayList<>();
    String exportPath;
    String subDir = args.getSubDirectory();
    if (!args.getFileOperation()) {
        exportPath = args.getSnapshotPath();
        if (subDir != null && subDir.length() > 0) {
            exportPath = args.getSnapshotPath() + "/" + subDir;
        }
    } else {
        exportPath = args.getFs().getPath();
        if (subDir != null && subDir.length() > 0) {
            exportPath = args.getFs().getPath() + "/" + subDir;
        }
    }
    _log.info("exportPath : {}", exportPath);
    args.setExportPath(exportPath);
    // ALL EXPORTS
    List<ExportRule> existingDBExportRule = args.getExistingDBExportRules();
    List<ExportRule> exportsToprocess = new ArrayList<>();
    for (ExportRule rule : existingDBExportRule) {
        if (rule.getExportPath().equalsIgnoreCase(exportPath)) {
            exportsToprocess.add(rule);
        }
    }
    _log.info("Number of existng Rules found {}", exportsToprocess.size());
    // Handle Modified export Rules
    if (exportsToprocess != null && !exportsToprocess.isEmpty()) {
        for (ExportRule existingRule : exportsToprocess) {
            for (ExportRule modifiedrule : exportModify) {
                if (modifiedrule.getSecFlavor().equals(existingRule.getSecFlavor())) {
                    _log.info("Modifying Export Rule from {}, To {}", existingRule, modifiedrule);
                    // use a separate list to avoid concurrent modification exception for now.
                    exportsToRemove.add(existingRule);
                    exportsToAdd.add(modifiedrule);
                }
            }
        }
        // Handle Add export Rules
        if (exportAdd != null && !exportAdd.isEmpty()) {
            for (ExportRule newExport : exportAdd) {
                _log.info("Adding Export Rule {}", newExport);
                exportsToAdd.add(newExport);
            }
        }
        // Handle Delete export Rules
        if (exportDelete != null && !exportDelete.isEmpty()) {
            for (ExportRule existingRule : exportsToprocess) {
                for (ExportRule oldExport : exportDelete) {
                    if (oldExport.getSecFlavor().equals(existingRule.getSecFlavor())) {
                        _log.info("Deleting Export Rule {}", existingRule);
                        exportsToRemove.add(existingRule);
                    }
                }
            }
        }
        // No of exports found to remove from the list
        _log.info("No of exports found to remove from the existing exports list {}", exportsToRemove.size());
        exportsToprocess.removeAll(exportsToRemove);
        _log.info("No of exports found to add to the existing exports list {}", exportsToAdd.size());
        exportsToprocess.addAll(exportsToAdd);
        if (exportsToprocess.isEmpty() && !exportsToRemove.isEmpty()) {
            // If all exports rules deleted, export will get deleted too. So set back to its defaults
            ExportRule rule = new ExportRule();
            rule.setSecFlavor("sys");
            rule.setAnon("root");
            java.util.Set<String> roHosts = new HashSet<>();
            roHosts.add("Default");
            rule.setReadOnlyHosts(roHosts);
            exportsToprocess.add(rule);
        }
    } else {
        if (exportsToprocess == null) {
            exportsToprocess = new ArrayList<>();
        }
        exportsToprocess.addAll(exportAdd);
        exportsToprocess.addAll(exportModify);
    }
    // if only delete provided with no existing rules -- How do we handle this? [GOPI]
    _log.info("Number of Export Rules to update after processing found {}", exportsToprocess.size());
    BiosCommandResult result = new BiosCommandResult();
    try {
        String portGroup = null;
        if (args.getFileOperation() == true) {
            FileShare fileshare = args.getFs();
            portGroup = findVfilerName(fileshare);
        } else {
            // Get the FS from the snapshot
            URI snapshotUID = args.getSnapshotId();
            Snapshot snapshot = _dbClient.queryObject(Snapshot.class, snapshotUID);
            FileShare fileshare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
            portGroup = findVfilerName(fileshare);
        }
        NetAppApi nApi = new NetAppApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).vFiler(portGroup).build();
        if (!nApi.modifyNFSShare(exportPath, exportsToprocess)) {
            _log.error("NetAppFileStorageDevice updateFSExportRules {} - failed", args.getFsId());
            result.setMessage("NetAppFileStorageDevice updateFSExportRules {} - failed");
            result.setCommandStatus(Operation.Status.error.name());
            return result;
        }
        if ((args.getFileOperation() == true) && args.getSubDirectory() == null) {
            nApi.setQtreemode(exportPath, UNIX_QTREE_SETTING);
        }
    } catch (NetAppException e) {
        _log.info("Exception:" + e.getMessage());
        throw new DeviceControllerException("Exception while performing export for {0} ", new Object[] { args.getFsId() });
    }
    _log.info("NetAppFileStorageDevice updateFSExportRules {} - complete", args.getFsId());
    result.setCommandSuccess(true);
    result.setCommandStatus(Operation.Status.ready.name());
    return result;
}
Also used : ArrayList(java.util.ArrayList) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URI(java.net.URI) NetAppException(com.emc.storageos.netapp.NetAppException) Snapshot(com.emc.storageos.db.client.model.Snapshot) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ExportRule(com.emc.storageos.model.file.ExportRule) NetAppApi(com.emc.storageos.netapp.NetAppApi) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HashSet(java.util.HashSet)

Example 54 with ExportRule

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

the class LinuxHostMountAdapter method addToFSTab.

@Override
public void addToFSTab(URI hostId, String mountPath, URI resId, String subDirectory, String security, String fsType) {
    mountUtils = new LinuxMountUtils(dbClient.queryObject(Host.class, hostId));
    FileShare fs = dbClient.queryObject(FileShare.class, resId);
    ExportRule export = FileOperationUtils.findExport(fs, subDirectory, security, dbClient);
    String options = "nolock,sec=" + security;
    // Add to etc/fstab
    mountUtils.addToFSTab(mountPath, export.getMountPoint(), fsType, options);
}
Also used : ExportRule(com.emc.storageos.model.file.ExportRule) FileShare(com.emc.storageos.db.client.model.FileShare)

Example 55 with ExportRule

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

the class FileOrchestrationDeviceController method addStepsToReplicateNFSExportRules.

/**
 * Child workflow for replicating source file system NFS export Rules to target.
 *
 * @param systemTarget
 *            - URI of target StorageSystem where source NFS shares has to be replicated.
 * @param fsURI
 *            -URI of the source FileSystem
 * @param taskId
 */
public void addStepsToReplicateNFSExportRules(URI systemTarget, URI fsURI, String taskId) {
    s_logger.info("Generating steps for Replicating NFS export rules to Target Cluster");
    FileWorkflowCompleter completer = new FileWorkflowCompleter(fsURI, taskId);
    Workflow workflow = null;
    FileShare targetFileShare = null;
    try {
        FileShare sourceFileShare = s_dbClient.queryObject(FileShare.class, fsURI);
        if (sourceFileShare.getPersonality().equals(PersonalityTypes.SOURCE.name())) {
            List<String> targetfileUris = new ArrayList<String>();
            targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
            targetFileShare = s_dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
        } else {
            targetFileShare = s_dbClient.queryObject(FileShare.class, sourceFileShare.getParentFileShare());
        }
        workflow = this._workflowService.getNewWorkflow(this, REPLICATE_NFS_EXPORT_RULES_TO_TARGET_WF_NAME, false, taskId, completer);
        FSExportMap sourceFSExportMap = sourceFileShare.getFsExports();
        FSExportMap targetFSExportMap = targetFileShare.getFsExports();
        if (sourceFSExportMap == null && targetFSExportMap != null) {
            // There are no export rule on source but there are on target!!
            List<ExportRule> exportRulesToDelete;
            HashMap<String, List<ExportRule>> targetExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(targetFileShare, s_dbClient);
            for (String exportPath : targetExportRuleMap.keySet()) {
                FileExportUpdateParams params = new FileExportUpdateParams();
                if (exportPath.equals(targetFileShare.getPath())) {
                    // File system export rules....
                    exportRulesToDelete = targetExportRuleMap.get(targetFileShare.getPath());
                } else {
                    // Sub directory export rules....
                    String subDir = exportPath.split(targetFileShare.getPath())[1];
                    exportRulesToDelete = targetExportRuleMap.get(targetFileShare.getPath() + subDir);
                    params.setSubDir(subDir.substring(1));
                }
                ExportRules deleteExportRules = new ExportRules();
                deleteExportRules.setExportRules(exportRulesToDelete);
                params.setExportRulesToDelete(deleteExportRules);
                updateFSExportRulesOnTarget(workflow, systemTarget, targetFileShare, exportPath, params);
            }
        } else if (targetFSExportMap != null && sourceFSExportMap != null) {
            // Both source and target have export rules!!
            HashMap<String, List<ExportRule>> sourceExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(sourceFileShare, s_dbClient);
            HashMap<String, List<ExportRule>> targetExportRuleMap = FileOrchestrationUtils.getFSExportRuleMap(targetFileShare, s_dbClient);
            for (String exportPath : sourceExportRuleMap.keySet()) {
                FileExportUpdateParams params = new FileExportUpdateParams();
                List<ExportRule> exportRulesToAdd = new ArrayList<ExportRule>();
                List<ExportRule> exportRulesToDelete = new ArrayList<ExportRule>();
                List<ExportRule> exportRulesToModify = new ArrayList<ExportRule>();
                List<ExportRule> sourceExportRules;
                List<ExportRule> targetExportRules;
                HashMap<String, ExportRule> srcExportRuleSecFlvMap;
                HashMap<String, ExportRule> trgtExportRuleSecFlvMap;
                if (exportPath.equals(sourceFileShare.getPath())) {
                    // File system export rules....
                    sourceExportRules = sourceExportRuleMap.get(exportPath);
                    targetExportRules = targetExportRuleMap.get(targetFileShare.getPath());
                } else {
                    // Sub directory export rules....
                    sourceExportRules = sourceExportRuleMap.get(exportPath);
                    String subDir = exportPath.split(sourceFileShare.getPath())[1];
                    targetExportRules = targetExportRuleMap.get(targetFileShare.getPath() + subDir);
                    params.setSubDir(subDir.substring(1));
                }
                if (sourceExportRules != null && targetExportRules != null) {
                    srcExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(sourceExportRules);
                    trgtExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(targetExportRules);
                    FileOrchestrationUtils.checkForExportRuleToAdd(sourceFileShare, targetFileShare, srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToAdd);
                    FileOrchestrationUtils.checkForExportRuleToDelete(srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToDelete);
                    sourceExportRules.removeAll(exportRulesToAdd);
                    targetExportRules.removeAll(exportRulesToDelete);
                    srcExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(sourceExportRules);
                    trgtExportRuleSecFlvMap = FileOrchestrationUtils.getExportRuleSecFlvMap(targetExportRules);
                    FileOrchestrationUtils.checkForExportRuleToModify(srcExportRuleSecFlvMap, trgtExportRuleSecFlvMap, exportRulesToModify);
                    if (!exportRulesToAdd.isEmpty()) {
                        ExportRules addExportRules = new ExportRules();
                        addExportRules.setExportRules(exportRulesToAdd);
                        params.setExportRulesToAdd(addExportRules);
                    }
                    if (!exportRulesToDelete.isEmpty()) {
                        ExportRules deleteExportRules = new ExportRules();
                        deleteExportRules.setExportRules(exportRulesToDelete);
                        params.setExportRulesToDelete(deleteExportRules);
                    }
                    if (!exportRulesToModify.isEmpty()) {
                        ExportRules modifyExportRules = new ExportRules();
                        modifyExportRules.setExportRules(exportRulesToModify);
                        params.setExportRulesToModify(modifyExportRules);
                    }
                    if (params.retrieveAllExports() != null && !params.retrieveAllExports().isEmpty()) {
                        updateFSExportRulesOnTarget(workflow, systemTarget, targetFileShare, exportPath, params);
                    }
                }
            }
        }
        String successMessage = String.format("Replicating source File System : %s, NFS Exports Rules to Target System finished successfully", sourceFileShare.getLabel());
        workflow.executePlan(completer, successMessage);
    } catch (Exception ex) {
        s_logger.error("Could not replicate source filesystem NFS Exports Rules : " + fsURI, ex);
        String opName = ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER.getName();
        ServiceError serviceError = DeviceControllerException.errors.updateFileShareExportRulesFailed(fsURI.toString(), opName, ex);
        completer.error(s_dbClient, this._locker, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Workflow(com.emc.storageos.workflow.Workflow) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) FileWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FileWorkflowCompleter) FileExportUpdateParams(com.emc.storageos.model.file.FileExportUpdateParams) ExportRules(com.emc.storageos.model.file.ExportRules) ExportRule(com.emc.storageos.model.file.ExportRule) List(java.util.List) ArrayList(java.util.ArrayList)

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