Search in sources :

Example 21 with VNXException

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

the class VNXFileStorageDeviceXML method doRestoreFS.

@Override
public BiosCommandResult doRestoreFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    _log.info("FileShare, Snapshot {} {}", args.getFsUUID(), args.getSnapshotId());
    _log.info("FSName: {}", args.getFsName());
    _log.info("SnapShotName: {}", args.getSnapshotName());
    int snapNativeId = 0;
    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.doRestoreSnapshot(storage, args.getFsNativeId(), args.getFsName(), args.getSnapNativeId(), args.getSnapshotName());
        _log.info("restoreSnapshot call result : {}", result.isCommandSuccess());
    } catch (NumberFormatException ne) {
        // Call failed
        result = new XMLApiResult();
        result.setCommandFailed();
        result.setMessage("Not valid snapshot Id " + args.getSnapNativeId());
    } catch (VNXException e) {
        throw new DeviceControllerException(e);
    } finally {
        clearContext(context);
    }
    _log.info("restoreSnapshot call result : {}", result.isCommandSuccess());
    BiosCommandResult cmdResult = null;
    if (result.isCommandSuccess()) {
        cmdResult = BiosCommandResult.createSuccessfulResult();
    } else {
        cmdResult = BiosCommandResult.createErrorResult(DeviceControllerErrors.vnx.unableToRestoreFileSystem(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) Checkpoint(com.emc.nas.vnxfile.xmlapi.Checkpoint)

Example 22 with VNXException

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

the class VNXFileStorageDeviceXML method doExpandFS.

@Override
public BiosCommandResult doExpandFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    _log.info("Call FileSystem Expand");
    // For the request to succeed to expand, the system must be mounted.
    // Below snippet helps to verify whether FS Mounted or not.
    // Note : Since, Every Export will mount the FileSystem at first, we
    // should do cross check as below whether file system is already mounted or not
    // using FSExportMap and SMBShareMap
    // If FileShare mounted then Mount is not required
    boolean isMountRequired = !(args.isFileShareMounted());
    _log.info("Mount required or not, to expand requested FileSystem {}", isMountRequired);
    Long newFsExpandSize = args.getNewFSCapacity();
    if (args.getNewFSCapacity() % BYTESPERMB == 0) {
        newFsExpandSize = newFsExpandSize / BYTESPERMB;
    } else {
        newFsExpandSize = newFsExpandSize / BYTESPERMB + 1;
    }
    _log.info("FileSystem new size translation : {} : {}", args.getNewFSCapacity(), args.getFsCapacity());
    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.expandFS(storage, args.getFs(), newFsExpandSize, isMountRequired, args.getThinProvision());
    } 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.unableToExpandFileSystem(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)

Example 23 with VNXException

use of com.emc.storageos.vnx.xmlapi.VNXException 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 24 with VNXException

use of com.emc.storageos.vnx.xmlapi.VNXException 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 25 with VNXException

use of com.emc.storageos.vnx.xmlapi.VNXException 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)

Aggregations

VNXException (com.emc.storageos.vnx.xmlapi.VNXException)43 XMLApiResult (com.emc.storageos.vnx.xmlapi.XMLApiResult)29 VNXFileCommApi (com.emc.storageos.volumecontroller.impl.plugins.provisioning.VNXFileCommApi)16 ApplicationContext (org.springframework.context.ApplicationContext)16 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)16 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)15 URISyntaxException (java.net.URISyntaxException)15 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)15 FileObject (com.emc.storageos.db.client.model.FileObject)14 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)14 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)11 ArrayList (java.util.ArrayList)11 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)10 UnManagedDiscoveredObject (com.emc.storageos.db.client.model.UnManagedDiscoveredObject)10 Checkpoint (com.emc.nas.vnxfile.xmlapi.Checkpoint)8 StorageHADomain (com.emc.storageos.db.client.model.StorageHADomain)8 VNXSnapshot (com.emc.storageos.vnx.xmlapi.VNXSnapshot)7 FileShare (com.emc.storageos.db.client.model.FileShare)6 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)6 VNXFileExport (com.emc.storageos.vnx.xmlapi.VNXFileExport)6