Search in sources :

Example 21 with NetAppCException

use of com.emc.storageos.netappc.NetAppCException in project coprhd-controller by CoprHD.

the class NetAppClusterModeDevice method doExport.

@Override
public BiosCommandResult doExport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
    _log.info("NetAppClusterModeDevice doExport - start");
    // Verify inputs.
    validateExportArgs(exportList);
    List<String> rootHosts = new ArrayList<String>();
    List<String> rwHosts = new ArrayList<String>();
    List<String> roHosts = new ArrayList<String>();
    BiosCommandResult result = new BiosCommandResult();
    if (args.getFileObjExports() == null || args.getFileObjExports().isEmpty()) {
        args.initFileObjExports();
    }
    FSExportMap existingExpMap = args.getFileObjExports();
    List<FileExport> existingExportList = new ArrayList<FileExport>();
    FileExport existingExport = null;
    Iterator<String> it = existingExpMap.keySet().iterator();
    while (it.hasNext()) {
        existingExport = existingExpMap.get(it.next());
        if (existingExport.getMountPath().equals(args.getFsMountPath())) {
            _log.info("Existing export FileExport key : {} ", existingExport.getFileExportKey());
            existingExportList.add(existingExport);
        }
    }
    // If it's a sub-directory no need to take existing hosts.
    boolean isSubDir = checkIfSubDirectory(args.getFsMountPath(), exportList.get(0).getMountPath());
    if (isSubDir) {
        existingExportList = null;
        if (exportList.get(0).getMountPath().contains(SNAPSHOT)) {
            _log.error("NetAppClusterModeDevice::doExport {} : Snapshot export is not Supported", args.getSnapshotId());
            ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportSnapshot();
            serviceError.setMessage(genDetailedMessage("doExport", args.getSnapshotId().toString(), "Snapshot export is not Supported"));
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
    }
    // TODO: Revisit once new Data Model for Exports is implemented.
    Map<String, List<String>> existingHosts = null;
    if ((null != existingExportList) && (!existingExportList.isEmpty())) {
        existingHosts = sortHostsFromCurrentExports(existingExportList);
    }
    if (null != existingHosts) {
        if ((null != existingHosts.get(ROOT_HOSTS)) && (!existingHosts.get(ROOT_HOSTS).isEmpty())) {
            addNewHostsOnly(rootHosts, existingHosts.get(ROOT_HOSTS));
        }
        if ((null != existingHosts.get(RW_HOSTS)) && (!existingHosts.get(RW_HOSTS).isEmpty())) {
            addNewHostsOnly(rwHosts, existingHosts.get(RW_HOSTS));
        }
        if ((null != existingHosts.get(RO_HOSTS)) && (!existingHosts.get(RO_HOSTS).isEmpty())) {
            addNewHostsOnly(roHosts, existingHosts.get(RO_HOSTS));
        }
    }
    try {
        for (int expCount = 0; expCount < exportList.size(); expCount++) {
            FileExport export = exportList.get(expCount);
            FileExport fileExport = new FileExport(export.getClients(), export.getStoragePortName(), export.getMountPoint(), export.getSecurityType(), export.getPermissions(), export.getRootUserMapping(), export.getProtocol(), export.getStoragePort(), export.getPath(), export.getMountPath(), export.getSubDirectory(), export.getComments());
            String portGroup = null;
            FileShare fileshare = null;
            if (args.getFileOperation() == true) {
                fileshare = args.getFs();
                portGroup = findSVMName(fileshare);
            } else {
                _log.error("NetAppClusterModeDevice::doExport {} : Snapshot export is not Supported", args.getFsId());
                ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportSnapshot();
                serviceError.setMessage(genDetailedMessage("doExport", args.getSnapshotId().toString(), "Snapshot export is not Supported"));
                result = BiosCommandResult.createErrorResult(serviceError);
                return result;
            }
            NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
            List<String> endpointsList = export.getClients();
            if (endpointsList == null) {
                _log.error("NetAppClusterModeDevice::doExport {} failed:  No endpoints specified", args.getFsId());
                ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportFileSystem();
                serviceError.setMessage(FileSystemConstants.FS_ERR_NO_ENDPOINTS_SPECIFIED);
                result = BiosCommandResult.createErrorResult(serviceError);
                return result;
            }
            sortNewEndPoints(rootHosts, rwHosts, roHosts, endpointsList, export.getPermissions());
            String root_user = export.getRootUserMapping();
            String mountPath = export.getMountPath();
            String exportPath = export.getPath();
            String fsName = fileshare.getName();
            String qtreeName = null;
            if (isSubDir) {
                if (ncApi.isQtree(fileshare.getName(), export.getSubDirectory())) {
                    qtreeName = export.getSubDirectory();
                    exportPath = constructQtreePath(fileshare.getName(), export.getSubDirectory());
                } else {
                    _log.error("NetAppClusterModeDevice::doExport {} : Sub-directory export is not Supported", args.getFsId());
                    ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportFileSystem();
                    serviceError.setMessage(genDetailedMessage("doExport", args.getFsId().toString(), "Sub-directory export is not Supported"));
                    result = BiosCommandResult.createErrorResult(serviceError);
                    return result;
                }
            }
            if (!ncApi.exportFS(fsName, qtreeName, exportPath, mountPath, rootHosts, rwHosts, roHosts, root_user, export.getSecurityType())) {
                _log.error("NetAppClusterModeDevice::doExport {} failed", args.getFsId());
                ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportFileSystem();
                serviceError.setMessage(genDetailedMessage("doExport", args.getFsId().toString()));
                result = BiosCommandResult.createErrorResult(serviceError);
                return result;
            }
            args.getFileObjExports().put(fileExport.getFileExportKey(), fileExport);
            result = BiosCommandResult.createSuccessfulResult();
        }
    } catch (NetAppCException e) {
        _log.error("NetAppClusterModeDevice::doExport failed with a NetAppCException", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportFileSystem();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppClusterModeDevice::doExport failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportFileSystem();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    }
    _log.info("NetAppClusterModeDevice::doExport {} - complete", args.getFsId());
    return result;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ArrayList(java.util.ArrayList) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetAppCException(com.emc.storageos.netappc.NetAppCException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException) NetAppClusterApi(com.emc.storageos.netappc.NetAppClusterApi) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetAppCException(com.emc.storageos.netappc.NetAppCException) FileExport(com.emc.storageos.db.client.model.FileExport) ArrayList(java.util.ArrayList) List(java.util.List)

Example 22 with NetAppCException

use of com.emc.storageos.netappc.NetAppCException in project coprhd-controller by CoprHD.

the class NetAppClusterModeDevice method doDeleteShare.

@Override
public BiosCommandResult doDeleteShare(StorageSystem storage, FileDeviceInputOutput args, SMBFileShare smbFileShare) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    try {
        _log.info("NetAppClusterModeDevice doDeleteShare - start");
        FileShare fileshare = null;
        if (args.getFileOperation() == true) {
            fileshare = args.getFs();
        } else {
            URI snapShotUID = args.getSnapshotId();
            Snapshot snapshot = _dbClient.queryObject(Snapshot.class, snapShotUID);
            fileshare = _dbClient.queryObject(FileShare.class, snapshot.getParent().getURI());
        }
        // Now get the VFiler from the fileShare
        String portGroup = findSVMName(fileshare);
        NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
        SMBShareMap shares = args.getFileObjShares();
        if (shares == null || shares.isEmpty()) {
            _log.error("NetAppClusterModeDevice::doDeleteShare failed: FileShare(s) is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netappc.unableToDeleteFileShare();
            serviceError.setMessage("FileShare(s) is either missing or empty");
            result = BiosCommandResult.createErrorResult(serviceError);
        }
        SMBFileShare fileShare = shares.get(smbFileShare.getName());
        if (fileShare != null) {
            if (!ncApi.deleteShare(smbFileShare.getName())) {
                _log.error("NetAppClusterModeDevice doDeleteShare {} - failed", args.getFileObjId());
                ServiceError serviceError = DeviceControllerErrors.netappc.unableToDeleteFileShare();
                serviceError.setMessage("Deletion of CIFS File Share failed");
                result = BiosCommandResult.createErrorResult(serviceError);
            } else {
                _log.info("NetAppClusterModeDevice doDeleteShare {} - complete", args.getFileObjId());
                args.getFileObjShares().remove(smbFileShare.getName());
                args.getFileObjShares().remove(smbFileShare.getNativeId());
                result = BiosCommandResult.createSuccessfulResult();
            }
        }
    } catch (NetAppCException e) {
        _log.error("NetAppClusterModeDevice::doDeleteShare failed with a NetAppCException", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToDeleteFileShare();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppClusterModeDevice::doDeleteShare failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToDeleteFileShare();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    }
    return result;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) NetAppClusterApi(com.emc.storageos.netappc.NetAppClusterApi) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetAppCException(com.emc.storageos.netappc.NetAppCException) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) URI(java.net.URI) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetAppCException(com.emc.storageos.netappc.NetAppCException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException)

Example 23 with NetAppCException

use of com.emc.storageos.netappc.NetAppCException in project coprhd-controller by CoprHD.

the class NetAppClusterModeDevice method doRestoreFS.

@Override
public BiosCommandResult doRestoreFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    try {
        _log.info("NetAppClusterModeDevice doRestoreFS - start");
        if (null == args.getFsName()) {
            _log.error("NetAppClusterModeDevice::doRestoreFS failed:  Filesystem name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netappc.unableToRestoreFileSystem();
            serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        if (null == args.getSnapshotName()) {
            _log.error("NetAppClusterModeDevice::doRestoreFS failed:  Snapshot name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netappc.unableToRestoreFileSystem();
            serviceError.setMessage(FileSystemConstants.FS_ERR_SNAPSHOT_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        String portGroup = findSVMName(args.getFs());
        NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
        if (!ncApi.restoreSnapshot(args.getFsName(), args.getSnapshotName())) {
            _log.error("NetAppClusterModeDevice doRestoreFS {} - failed", args.getFsName());
            ServiceError serviceError = DeviceControllerErrors.netappc.unableToRestoreFileSystem();
            result = BiosCommandResult.createErrorResult(serviceError);
        } else {
            _log.info("doRestoreFS - restore of snapshot, {}  was successfully for filesystem, {} ", args.getSnapshotName(), args.getFsName());
            result = BiosCommandResult.createSuccessfulResult();
        }
    } catch (NetAppCException e) {
        _log.error("NetAppClusterModeDevice::doRestoreFS failed with a NetAppCException", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToRestoreFileSystem();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppClusterModeDevice::doRestoreFS failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToRestoreFileSystem();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    }
    return result;
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) NetAppClusterApi(com.emc.storageos.netappc.NetAppClusterApi) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetAppCException(com.emc.storageos.netappc.NetAppCException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetAppCException(com.emc.storageos.netappc.NetAppCException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) NetAppException(com.emc.storageos.netapp.NetAppException)

Aggregations

NetAppCException (com.emc.storageos.netappc.NetAppCException)23 NetAppClusterApi (com.emc.storageos.netappc.NetAppClusterApi)20 NetAppException (com.emc.storageos.netapp.NetAppException)18 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)16 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)16 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)14 ControllerException (com.emc.storageos.volumecontroller.ControllerException)12 ArrayList (java.util.ArrayList)8 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)6 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)6 IOException (java.io.IOException)6 URI (java.net.URI)6 HashMap (java.util.HashMap)6 StorageVirtualMachineInfo (com.iwave.ext.netappc.StorageVirtualMachineInfo)5 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)4 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)4 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)4 List (java.util.List)4 FileShare (com.emc.storageos.db.client.model.FileShare)3 StoragePool (com.emc.storageos.db.client.model.StoragePool)3