Search in sources :

Example 6 with VNXFileExport

use of com.emc.storageos.vnx.xmlapi.VNXFileExport in project coprhd-controller by CoprHD.

the class VNXFileStorageDeviceXML method updateExportRules.

@Override
public BiosCommandResult updateExportRules(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    XMLApiResult result = null;
    ApplicationContext context = null;
    // 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);
    try {
        // add the new export rule from the array into the update request.
        Map<String, ExportRule> arrayExportRuleMap = extraExportRuleFromArray(storage, args);
        if (!arrayExportRuleMap.isEmpty()) {
            if (exportModify != null) {
                // merge the end point for which sec flavor is common.
                for (ExportRule exportRule : exportModify) {
                    ExportRule arrayExportRule = arrayExportRuleMap.remove(exportRule.getSecFlavor());
                    if (arrayExportRule != null) {
                        if (exportRule.getReadOnlyHosts() != null) {
                            exportRule.getReadOnlyHosts().addAll(arrayExportRule.getReadOnlyHosts());
                        } else {
                            exportRule.setReadOnlyHosts(arrayExportRule.getReadOnlyHosts());
                        }
                        if (exportRule.getReadWriteHosts() != null) {
                            exportRule.getReadWriteHosts().addAll(arrayExportRule.getReadWriteHosts());
                        } else {
                            exportRule.setReadWriteHosts(arrayExportRule.getReadWriteHosts());
                        }
                        if (exportRule.getRootHosts() != null) {
                            exportRule.getRootHosts().addAll(arrayExportRule.getRootHosts());
                        } else {
                            exportRule.setRootHosts(arrayExportRule.getRootHosts());
                        }
                    }
                }
                // now add the remaining export rule
                exportModify.addAll(arrayExportRuleMap.values());
            } else {
                // if exportModify is null then create a new export rule and add
                exportModify = new ArrayList<ExportRule>();
                exportModify.addAll(arrayExportRuleMap.values());
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        _log.error("Not able to fetch latest Export rule from backend array.", e);
    }
    // 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());
    // If there are no Export rules and add is allowed
    if (!exportsToprocess.isEmpty() || (exportAdd != null && !exportAdd.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 modifications 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);
        // Figure out mounted or not
        SMBShareMap shares = args.getFs().getSMBFileShares();
        boolean isMounted = true;
        if (exportsToprocess.isEmpty() && (shares == null || (shares != null && shares.isEmpty()))) {
            isMounted = false;
        }
        // Mounting is only necessary for FileSystem and not snapshot for the first time export
        if (!args.getFileOperation()) {
            isMounted = false;
        }
        // To be compatible with existing export creating an empty list
        List<String> newPaths = new ArrayList<String>();
        newPaths.add(exportPath);
        try {
            context = loadContext();
            VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
            if (null == vnxComm) {
                throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
            }
            // Get DataMover Name and whether it is virtual
            StorageHADomain dm = this.getDataMover(args.getFs());
            if (dm == null) {
                Exception e = new Exception("VNX File Export Failed Data Mover not found");
                throw VNXException.exceptions.createExportFailed("VNX File Export Failed Data Mover not found", e);
            }
            List<VNXFileExport> exportList = new ArrayList<VNXFileExport>();
            for (ExportRule rule : exportsToprocess) {
                VNXFileExport vnxExp = null;
                // update the comment
                String comments = rule.getComments();
                String protocol = "nfs";
                if (rule.getReadOnlyHosts() != null && !rule.getReadOnlyHosts().isEmpty()) {
                    vnxExp = new VNXFileExport(new ArrayList<String>(rule.getReadOnlyHosts()), dm.getName(), exportPath, rule.getSecFlavor(), "ro", rule.getAnon(), protocol, args.getFs().getStoragePort().toString(), subDir, comments);
                    exportList.add(vnxExp);
                }
                if (rule.getReadWriteHosts() != null && !rule.getReadWriteHosts().isEmpty()) {
                    vnxExp = new VNXFileExport(new ArrayList<String>(rule.getReadWriteHosts()), dm.getName(), exportPath, rule.getSecFlavor(), "rw", rule.getAnon(), protocol, args.getFs().getStoragePort().toString(), subDir, comments);
                    exportList.add(vnxExp);
                }
                if (rule.getRootHosts() != null && !rule.getRootHosts().isEmpty()) {
                    vnxExp = new VNXFileExport(new ArrayList<String>(rule.getRootHosts()), dm.getName(), exportPath, rule.getSecFlavor(), "root", rule.getAnon(), protocol, args.getFs().getStoragePort().toString(), subDir, comments);
                    exportList.add(vnxExp);
                }
            }
            // existing VNXComm API. This is required to read the subsequent information down the line.
            if ((exportList != null && exportList.isEmpty()) && (exportsToRemove != null && !exportsToRemove.isEmpty())) {
                _log.info("Requested to remove all export rules");
                VNXFileExport vnxExp = new VNXFileExport(new ArrayList<String>(), dm.getName(), exportPath, "", "root", "", "", args.getFs().getStoragePort().toString(), subDir, "");
                exportList.add(vnxExp);
            }
            // List<VNXFileExport> vnxExports = getVNXFileExports(newExpList);
            if (args.getFileOperation()) {
                // Perform FileSystem export
                result = vnxComm.doExport(storage, dm, exportList, newPaths, args.getFileObj(), args.getFsNativeId(), isMounted);
            } else {
                // perform Snapshot export
                result = vnxComm.doExport(storage, dm, exportList, newPaths, args.getFileObj(), args.getSnapNativeId(), isMounted);
            }
            if (result.isCommandSuccess()) {
                _log.info("updateExportRules result.isCommandSuccess true");
            }
        } catch (VNXException e) {
            throw VNXException.exceptions.createExportFailed("VNX File Export Failed", e);
        } finally {
            clearContext(context);
        }
    }
    BiosCommandResult cmdResult = null;
    if (result.isCommandSuccess()) {
        cmdResult = BiosCommandResult.createSuccessfulResult();
    } else {
        cmdResult = BiosCommandResult.createErrorResult(DeviceControllerErrors.vnx.unableToUpdateExport(result.getMessage()));
    }
    return cmdResult;
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) ArrayList(java.util.ArrayList) VNXFileCommApi(com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi) XMLApiResult(com.emc.storageos.vnx.xmlapi.XMLApiResult) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VNXException(com.emc.storageos.vnx.xmlapi.VNXException) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) VNXException(com.emc.storageos.vnx.xmlapi.VNXException) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) ExportRule(com.emc.storageos.model.file.ExportRule) VNXFileExport(com.emc.storageos.vnx.xmlapi.VNXFileExport) StorageHADomain(com.emc.storageos.db.client.model.StorageHADomain)

Example 7 with VNXFileExport

use of com.emc.storageos.vnx.xmlapi.VNXFileExport in project coprhd-controller by CoprHD.

the class VNXFileStorageDeviceXML method doUnexport.

@Override
public BiosCommandResult doUnexport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
    _log.info("doUnExport " + args.getOperationType());
    _log.info("Call FileShare UnExport");
    XMLApiResult result = null;
    ApplicationContext context = null;
    try {
        context = loadContext();
        VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
        if (null == vnxComm) {
            throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
        }
        for (int expCount = 0; expCount < exportList.size(); expCount++) {
            List<String> endPoints = new ArrayList<String>();
            FileExport export = exportList.get(expCount);
            String exportEntryKey = FileExport.exportLookupKey(export.getProtocol(), export.getSecurityType(), export.getPermissions(), export.getRootUserMapping(), export.getPath());
            FileExport fileExport = args.getFileObjExports().get(exportEntryKey);
            if (fileExport != null) {
                endPoints.addAll(fileExport.getClients());
            }
            export.setClients(endPoints);
            _log.info("FileExport:" + export.getClients() + ":" + export.getStoragePortName() + ":" + export.getStoragePort() + ":" + export.getRootUserMapping() + ":" + export.getPermissions() + ":" + export.getProtocol() + ":" + export.getSecurityType() + ":" + export.getMountPoint() + ":" + export.getPath());
        }
        List<VNXFileExport> vnxExps = getVNXFileExports(exportList);
        result = vnxComm.doUnexport(storage, vnxExps.get(0), args, false);
    } catch (VNXException e) {
        throw new DeviceControllerException(e);
    } finally {
        clearContext(context);
    }
    BiosCommandResult cmdResult = null;
    if (result.isCommandSuccess()) {
        cmdResult = BiosCommandResult.createSuccessfulResult();
    } else {
        cmdResult = BiosCommandResult.createErrorResult(DeviceControllerErrors.vnx.unableToUnexportFileSystem(result.getMessage()));
    }
    return cmdResult;
}
Also used : VNXFileCommApi(com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi) ArrayList(java.util.ArrayList) XMLApiResult(com.emc.storageos.vnx.xmlapi.XMLApiResult) Checkpoint(com.emc.nas.vnxfile.xmlapi.Checkpoint) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) VNXException(com.emc.storageos.vnx.xmlapi.VNXException) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) FileExport(com.emc.storageos.db.client.model.FileExport) VNXFileExport(com.emc.storageos.vnx.xmlapi.VNXFileExport) VNXFileExport(com.emc.storageos.vnx.xmlapi.VNXFileExport) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 8 with VNXFileExport

use of com.emc.storageos.vnx.xmlapi.VNXFileExport in project coprhd-controller by CoprHD.

the class VNXFileStorageDeviceXML method getVNXFileExports.

private List<VNXFileExport> getVNXFileExports(FSExportMap existingExps) {
    List<VNXFileExport> vnxExports = new ArrayList<VNXFileExport>();
    if (existingExps != null && !existingExps.isEmpty()) {
        for (FileExport cur : existingExps.values()) {
            _log.debug("Added export sec, perm {} {}", cur.getSecurityType(), cur.getPermissions());
            _log.debug("             anon,path {} {}", cur.getRootUserMapping(), cur.getPath());
            VNXFileExport vnxExp = new VNXFileExport(cur.getClients(), cur.getStoragePortName(), cur.getPath(), cur.getSecurityType(), cur.getPermissions(), cur.getRootUserMapping(), cur.getProtocol(), cur.getStoragePort(), cur.getSubDirectory(), cur.getComments());
            vnxExports.add(vnxExp);
        }
    }
    return vnxExports;
}
Also used : ArrayList(java.util.ArrayList) FileExport(com.emc.storageos.db.client.model.FileExport) VNXFileExport(com.emc.storageos.vnx.xmlapi.VNXFileExport) VNXFileExport(com.emc.storageos.vnx.xmlapi.VNXFileExport)

Example 9 with VNXFileExport

use of com.emc.storageos.vnx.xmlapi.VNXFileExport in project coprhd-controller by CoprHD.

the class VNXFileCommApi method deleteAllExportsAndShares.

private XMLApiResult deleteAllExportsAndShares(StorageSystem system, StorageHADomain dataMover, FileShare fs, Snapshot snapshot) {
    FSExportMap exports;
    SMBShareMap shares;
    XMLApiResult result = new XMLApiResult();
    result.setCommandSuccess();
    String fileId = fs.getId().toString();
    FileObject fObj = fs;
    _log.info("deleteAllExportsAndShares for {} {}", fs.getName(), snapshot);
    boolean fileOperation = false;
    if (snapshot == null) {
        // FileShare operation
        _log.info("deleteAllExportsAndShares FileShare delete operation");
        exports = fs.getFsExports();
        shares = fs.getSMBFileShares();
        fileOperation = true;
        fObj = fs;
    } else {
        _log.info("deleteAllExportsAndShares Snapshot delete operation");
        exports = snapshot.getFsExports();
        shares = snapshot.getSMBFileShares();
        fObj = snapshot;
        fileId = snapshot.getId().toString();
    }
    int exportsToUnExport = 0;
    Set<String> keys = new HashSet();
    if (exports != null) {
        exportsToUnExport = exports.size();
        keys = exports.keySet();
    }
    int noOfShares = 0;
    if (shares != null) {
        noOfShares = shares.size();
    }
    _log.info("Number of NFS exports {}  SMB Shares found {} for File/Snapshot Id {}", new Object[] { exportsToUnExport, noOfShares, fileId });
    // To avoid concurrent modification exceptions
    Set<String> exportKeys = new HashSet();
    exportKeys.addAll(keys);
    FileDeviceInputOutput args = new FileDeviceInputOutput();
    args.setFileOperation(fileOperation);
    args.addFSFileObject(fs);
    if (fileOperation) {
        args.setFileOperation(true);
        args.addFSFileObject(fs);
    } else {
        args.setFileOperation(false);
        args.addFSFileObject(fs);
        args.addSnapshot(snapshot);
    }
    for (String key : exportKeys) {
        FileExport exp = exports.get(key);
        VNXFileExport fileExport = new VNXFileExport(exp.getClients(), exp.getStoragePortName(), exp.getPath(), exp.getSecurityType(), exp.getPermissions(), exp.getRootUserMapping(), exp.getProtocol(), exp.getStoragePort(), exp.getSubDirectory(), exp.getComments());
        fileExport.setStoragePort(fs.getStoragePort().toString());
        boolean deleteMount = false;
        if (exportsToUnExport == 1 && noOfShares == 0 && fileOperation) {
            deleteMount = true;
        }
        XMLApiResult status = doUnexport(system, fileExport, args, deleteMount);
        if (!status.isCommandSuccess()) {
            String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
            result.setCommandFailed();
            result.setMessage(errMsg);
            return result;
        } else {
            fObj.getFsExports().remove(key);
            _log.info("Export removed : " + key);
            exportsToUnExport--;
        }
        // Persist the object after exports removed
        _dbClient.persistObject(fObj);
    }
    // Now Let Handle SMB/CIFS Shares
    keys = new HashSet<>();
    int noOfSharesToDelete = 0;
    if (shares != null) {
        keys = shares.keySet();
        noOfSharesToDelete = keys.size();
    }
    int noOfExports = 0;
    if (exports != null) {
        noOfExports = exports.size();
    }
    _log.info("Number of CIFS/SMB Shares {}  NFS Exports found {} for File/Snapshot Id {}", new Object[] { noOfSharesToDelete, noOfExports, fileId });
    // To avoid concurrent modification exceptions
    Set<String> shareKeys = new HashSet();
    shareKeys.addAll(keys);
    for (String key : shareKeys) {
        SMBFileShare share = shares.get(key);
        _log.info("Delete SMB/CIFS Share {} from FS/Snapshot {}", share.getName(), fileId);
        boolean deleteMount = false;
        if (noOfSharesToDelete == 1 && noOfExports == 0 && fileOperation) {
            deleteMount = true;
        }
        XMLApiResult status = doDeleteShare(system, dataMover, share.getName(), fs.getMountPath(), deleteMount, args);
        if (!status.isCommandSuccess()) {
            _log.info("SMBFileShare deletion failed key {} : {} ", key, share.getName());
            String errMsg = (String) _provExecutor.getKeyMap().get(VNXFileConstants.FAULT_DESC);
            result.setCommandFailed();
            result.setMessage(errMsg);
            return result;
        } else {
            fObj.getSMBFileShares().remove(key);
            _log.info("SMBFileShare removed : " + key);
            noOfSharesToDelete--;
        }
        // Persist the object after SMBShares removed
        _dbClient.persistObject(fObj);
    }
    return result;
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) XMLApiResult(com.emc.storageos.vnx.xmlapi.XMLApiResult) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Checkpoint(com.emc.nas.vnxfile.xmlapi.Checkpoint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) FileExport(com.emc.storageos.db.client.model.FileExport) VNXFileExport(com.emc.storageos.vnx.xmlapi.VNXFileExport) VNXFileExport(com.emc.storageos.vnx.xmlapi.VNXFileExport) FileObject(com.emc.storageos.db.client.model.FileObject) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) HashSet(java.util.HashSet)

Aggregations

VNXFileExport (com.emc.storageos.vnx.xmlapi.VNXFileExport)9 ArrayList (java.util.ArrayList)8 XMLApiResult (com.emc.storageos.vnx.xmlapi.XMLApiResult)7 FileExport (com.emc.storageos.db.client.model.FileExport)6 VNXException (com.emc.storageos.vnx.xmlapi.VNXException)6 StorageHADomain (com.emc.storageos.db.client.model.StorageHADomain)4 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)4 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)4 VNXFileCommApi (com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi)4 ApplicationContext (org.springframework.context.ApplicationContext)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)4 FileObject (com.emc.storageos.db.client.model.FileObject)3 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)3 ControllerException (com.emc.storageos.volumecontroller.ControllerException)3 HashSet (java.util.HashSet)3 Checkpoint (com.emc.nas.vnxfile.xmlapi.Checkpoint)2 FSExportMap (com.emc.storageos.db.client.model.FSExportMap)2 FileShare (com.emc.storageos.db.client.model.FileShare)2 SMBShareMap (com.emc.storageos.db.client.model.SMBShareMap)2 URISyntaxException (java.net.URISyntaxException)2