Search in sources :

Example 21 with NetAppClusterApi

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

the class NetAppClusterModeDevice method doUnexport.

@Override
public BiosCommandResult doUnexport(StorageSystem storage, FileDeviceInputOutput args, List<FileExport> exportList) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    try {
        _log.info("NetAppClusterModeDevice doUnexport: {} - start", args.getFileObjId());
        if (!args.getFileOperation()) {
            _log.error("NetAppClusterModeDevice::doUnexport {} : Snapshot unexport is not Supported", args.getSnapshotId());
            ServiceError serviceError = DeviceControllerErrors.netappc.unableToUnexportSnapshot();
            serviceError.setMessage(genDetailedMessage("doUnExport", args.getSnapshotId().toString(), "Snapshot unexport is not Supported"));
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        for (int expCount = 0; expCount < exportList.size(); expCount++) {
            FileExport export = exportList.get(expCount);
            String portGroup = findSVMName(args.getFs());
            NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
            if (export.getPermissions() == null) {
                export.setPermissions(RO_PERM);
            }
            String mountPath = export.getMountPath();
            String exportPath = export.getPath();
            if (!ncApi.unexportFS(exportPath, mountPath)) {
                _log.error("NetAppClusterModeDevice::doUnexport {} failed", args.getFsId());
                ServiceError serviceError = DeviceControllerErrors.netappc.unableToUnexportFileSystem();
                serviceError.setMessage(genDetailedMessage("doUnexport", args.getFsId().toString()));
                result = BiosCommandResult.createErrorResult(serviceError);
                return result;
            } else {
                _log.info("NetAppClusterModeDevice doUnexport {} - completed", args.getFsId());
                result = BiosCommandResult.createSuccessfulResult();
            }
        }
    } catch (NetAppCException e) {
        _log.error("NetAppClusterModeDevice::doUnexport failed with a NetAppCException", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToUnexportFileSystem();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppClusterModeDevice::doUnexport failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToUnexportFileSystem();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    }
    _log.info("NetAppClusterModeDevice doUnexport {} - complete", args.getFileObjId());
    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) FileExport(com.emc.storageos.db.client.model.FileExport) 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 22 with NetAppClusterApi

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

the class NetAppClusterModeDevice method deleteExportRules.

@Override
public BiosCommandResult deleteExportRules(StorageSystem storage, FileDeviceInputOutput args) {
    BiosCommandResult result = new BiosCommandResult();
    String portGroup = findSVMName(args.getFs());
    NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
    List<ExportRule> allExports = args.getExistingDBExportRules();
    String subDir = args.getSubDirectory();
    boolean allDirs = args.isAllDir();
    String exportPath;
    String qtreePath = "";
    if (!args.getFileOperation()) {
        _log.error("NetAppClusterModeDevice::doUnexport {} : Snapshot unexport is not Supported", args.getSnapshotId());
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToUnexportSnapshot();
        serviceError.setMessage(genDetailedMessage("doUnExport", args.getSnapshotId().toString(), "Snapshot unexport is not Supported"));
        result = BiosCommandResult.createErrorResult(serviceError);
        return result;
    } else {
        exportPath = args.getFs().getPath();
        qtreePath = exportPath;
        if (subDir != null && subDir.length() > 0) {
            exportPath = args.getFs().getPath() + "/" + subDir;
            if (ncApi.isQtree(args.getFsName(), subDir)) {
                qtreePath = constructQtreePath(args.getFsName(), subDir);
            } else {
                _log.error("NetAppClusterModeDevice::doUnexport {} : Sub-directory unexport is not Supported", args.getFsId());
                ServiceError serviceError = DeviceControllerErrors.netappc.unableToExportFileSystem();
                serviceError.setMessage(genDetailedMessage("doUnExport", args.getFsId().toString(), "Sub-directory unexport is not Supported"));
                result = BiosCommandResult.createErrorResult(serviceError);
                return result;
            }
        }
    }
    _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) {
                boolean isSubDir = checkIfSubDirectory(args.getFsMountPath(), path);
                if (isSubDir) {
                    subDir = getSubDirectory(args.getFsMountPath(), path);
                    if (ncApi.isQtree(args.getFsName(), subDir)) {
                        path = constructQtreePath(args.getFsName(), subDir);
                    }
                }
                _log.info("deleting export path : {} ", path);
                ncApi.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)) {
                    ncApi.deleteNFSExport(qtreePath);
                    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");
            ncApi.deleteNFSExport(qtreePath);
        }
    } catch (NetAppCException e) {
        _log.info("Exception:" + e.getMessage());
        throw new DeviceControllerException("Exception while performing export for {0} ", new Object[] { args.getFsId() });
    }
    _log.info("NetAppClusterModeDevice unexportFS {} - complete", args.getFsId());
    result.setCommandSuccess(true);
    result.setCommandStatus(Operation.Status.ready.name());
    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) ExportRule(com.emc.storageos.model.file.ExportRule) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HashSet(java.util.HashSet)

Example 23 with NetAppClusterApi

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

the class NetAppClusterModeDevice method updateShareACLs.

@Override
public BiosCommandResult updateShareACLs(StorageSystem storage, FileDeviceInputOutput args) {
    List<ShareACL> existingAcls = new ArrayList<ShareACL>();
    existingAcls = args.getExistingShareAcls();
    String portGroup = findSVMName(args.getFs());
    BiosCommandResult result = new BiosCommandResult();
    NetAppClusterApi ncApi = new NetAppClusterApi.Builder(storage.getIpAddress(), storage.getPortNumber(), storage.getUsername(), storage.getPassword()).https(true).svm(portGroup).build();
    try {
        processAclsForShare(ncApi, args);
        result = BiosCommandResult.createSuccessfulResult();
    } catch (Exception e) {
        _log.error("NetAppClusterModeDevice::updateShareACLs failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToUpdateCIFSShareAcl();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
        // if delete or modify fails , revert to old acl
        rollbackShareACLs(storage, args, existingAcls);
    }
    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) ArrayList(java.util.ArrayList) ShareACL(com.emc.storageos.model.file.ShareACL) 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 24 with NetAppClusterApi

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

the class NetAppClusterModeDevice method doSnapshotFS.

@Override
public BiosCommandResult doSnapshotFS(StorageSystem storage, FileDeviceInputOutput args) throws ControllerException {
    BiosCommandResult result = new BiosCommandResult();
    try {
        _log.info("NetAppClusterModeDevice doSnapshotFS - start");
        if (null == args.getFsName()) {
            _log.error("NetAppClusterModeDevice::doSnapshotFS failed:  Filesystem name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netappc.unableToCreateSnapshot();
            serviceError.setMessage(FileSystemConstants.FS_ERR_FS_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        if (null == args.getSnapshotName()) {
            _log.error("NetAppClusterModeDevice::doSnapshotFS failed:  Snapshot name is either missing or empty");
            ServiceError serviceError = DeviceControllerErrors.netappc.unableToCreateSnapshot();
            serviceError.setMessage(FileSystemConstants.FS_ERR_SNAPSHOT_NAME_MISSING_OR_EMPTY);
            result = BiosCommandResult.createErrorResult(serviceError);
            return result;
        }
        boolean failedStatus = false;
        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.createSnapshot(args.getFsName(), args.getSnapshotName())) {
            failedStatus = true;
        }
        if (failedStatus == true) {
            _log.error("NetAppClusterModeDevice doSnapshotFS {} - failed", args.getFsId());
            ServiceError serviceError = DeviceControllerErrors.netappc.unableToCreateSnapshot();
            serviceError.setMessage(genDetailedMessage("doSnapshotFS", args.getFsName()));
            result = BiosCommandResult.createErrorResult(serviceError);
        } else {
            _log.info("doSnapshotFS - Snapshot, {}  was successfully created for filesystem, {} ", args.getSnapshotName(), args.getFsName());
            // Set snapshot Path and MountPath information
            args.setSnapshotMountPath(getSnapshotMountPath(args.getFsMountPath(), args.getSnapshotName()));
            args.setSnapshotPath(getSnapshotPath(args.getFsPath(), args.getSnapshotName()));
            args.setSnapNativeId(args.getSnapshotName());
            result = BiosCommandResult.createSuccessfulResult();
        }
    } catch (NetAppCException e) {
        _log.error("NetAppClusterModeDevice::doSnapshotFS failed with a NetAppCException", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToCreateSnapshot();
        serviceError.setMessage(e.getLocalizedMessage());
        result = BiosCommandResult.createErrorResult(serviceError);
    } catch (Exception e) {
        _log.error("NetAppClusterModeDevice::doSnapshotFS failed with an Exception", e);
        ServiceError serviceError = DeviceControllerErrors.netappc.unableToCreateSnapshot();
        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)

Example 25 with NetAppClusterApi

use of com.emc.storageos.netappc.NetAppClusterApi 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)

Aggregations

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