Search in sources :

Example 11 with VNXFileCommApi

use of com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi in project coprhd-controller by CoprHD.

the class VNXFileStorageDeviceXML method doCheckFSExists.

@Override
public boolean doCheckFSExists(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    _log.info("checking file system existence on array: ", args.getFsName());
    boolean isFSExists = true;
    try {
        ApplicationContext context = null;
        context = loadContext();
        VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
        if (null == vnxComm) {
            throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
        }
        isFSExists = vnxComm.checkFileSystemExists(storage, args.getFsNativeId(), args.getFsName());
    } catch (VNXException e) {
        _log.error("Querying FS existence failed");
    }
    return isFSExists;
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) VNXException(com.emc.storageos.vnx.xmlapi.VNXException) VNXFileCommApi(com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi)

Example 12 with VNXFileCommApi

use of com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi 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 13 with VNXFileCommApi

use of com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi 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 14 with VNXFileCommApi

use of com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi in project coprhd-controller by CoprHD.

the class VNXFileStorageDeviceXML method doDeleteQuotaDirectory.

@Override
public BiosCommandResult doDeleteQuotaDirectory(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    ApplicationContext context = null;
    XMLApiResult apiResult = null;
    try {
        _log.info("VNXFileStorageDeviceXML doDeleteQuotaDirectory - start");
        String fsName = args.getFsName();
        String quotaTreetreeName = args.getQuotaDirectoryName();
        QuotaDirectory quotaDir = args.getQuotaDirectory();
        if (null == fsName) {
            _log.error("VNXFileStorageDeviceXML::doDeleteQuotaDirectory failed:  Filesystem name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.vnx.unableToDeleteQuotaDir();
            serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        if (null == quotaTreetreeName) {
            _log.error("VNXFileStorageDeviceXML::doDeleteQuotaDirectory failed:  Quota Tree name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.vnx.unableToDeleteQuotaDir();
            serviceError.setMessage(FileSystemConstants.FS_ERR_QUOTADIR_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        _log.info("FSName: {}", args.getFsName());
        _log.info("Quota tree name: {}", args.getQuotaDirectoryName());
        boolean isMountRequired = !(args.isFileShareMounted());
        _log.info("Mount required or not, to delete quota dir requested {}", isMountRequired);
        // Load the context
        context = loadContext();
        VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
        if (null == vnxComm) {
            throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
        }
        // we can't delete quota, if the filsystem is not mount, We should changes quota cmd
        apiResult = vnxComm.deleteQuotaDirectory(storage, args.getFsName(), quotaTreetreeName, true, isMountRequired);
        if (apiResult.isCommandSuccess()) {
            result = BiosCommandResult.createSuccessfulResult();
        }
        _log.info("doDeleteQuotaDirectory call result : {}", apiResult.isCommandSuccess());
    } 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.unableToDeleteQuotaDir());
    }
    return cmdResult;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) 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) VNXFileCommApi(com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) XMLApiResult(com.emc.storageos.vnx.xmlapi.XMLApiResult) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 15 with VNXFileCommApi

use of com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi in project coprhd-controller by CoprHD.

the class VNXFileStorageDeviceXML method doDeleteSnapshot.

@Override
public BiosCommandResult doDeleteSnapshot(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    // generate checkpoint baseline name
    _log.info("FileShare, Snapshot {} {}", args.getFsUUID(), args.getSnapshotId());
    _log.info("FSName: {}", args.getFsName());
    _log.info("SnapShotName: {}", args.getSnapshotName());
    _log.info("SnapShotBaseline: {}", args.getSnapshotCheckPointBaseline());
    XMLApiResult result = null;
    ApplicationContext context = null;
    try {
        context = loadContext();
        VNXFileCommApi vnxComm = loadVNXFileCommunicationAPIs(context);
        if (null == vnxComm) {
            throw VNXException.exceptions.communicationFailed(VNXCOMM_ERR_MSG);
        }
        result = vnxComm.doDeleteSnapshot(storage, args.getSnapNativeId(), args.getSnapshotName(), true);
    } 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.unableToDeleteFileSnapshot(result.getMessage()));
    }
    return cmdResult;
}
Also used : 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) VNXFileCommApi(com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi) XMLApiResult(com.emc.storageos.vnx.xmlapi.XMLApiResult) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Aggregations

VNXFileCommApi (com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi)19 VNXException (com.emc.storageos.vnx.xmlapi.VNXException)18 ApplicationContext (org.springframework.context.ApplicationContext)18 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)18 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)16 XMLApiResult (com.emc.storageos.vnx.xmlapi.XMLApiResult)15 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)15 ControllerException (com.emc.storageos.volumecontroller.ControllerException)7 StorageHADomain (com.emc.storageos.db.client.model.StorageHADomain)4 VNXFileExport (com.emc.storageos.vnx.xmlapi.VNXFileExport)4 ArrayList (java.util.ArrayList)4 Checkpoint (com.emc.nas.vnxfile.xmlapi.Checkpoint)3 FileShare (com.emc.storageos.db.client.model.FileShare)3 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)3 ExportRule (com.emc.storageos.model.file.ExportRule)3 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)3 FileExport (com.emc.storageos.db.client.model.FileExport)2 VNXQuotaTree (com.emc.storageos.vnx.xmlapi.VNXQuotaTree)2 VNXSnapshot (com.emc.storageos.vnx.xmlapi.VNXSnapshot)2 HashMap (java.util.HashMap)2