Search in sources :

Example 1 with VNXFileSshApi

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

the class VNXFileCommunicationInterface method discoverPorts.

/**
 * Retrieve the Data Mover IP Interfaces (aka Storage Ports) for the specified VNX File Storage Array
 *
 * @param system storage system information including credentials.
 * @return Map of New and Existing Storage Ports
 * @throws VNXFileCollectionException
 * @throws IOException
 */
private HashMap<String, List<StoragePort>> discoverPorts(StorageSystem system, Set<StorageHADomain> movers) throws VNXFileCollectionException, VNXException, IOException {
    HashMap<String, List<StoragePort>> storagePorts = new HashMap<String, List<StoragePort>>();
    List<StoragePort> newStoragePorts = new ArrayList<StoragePort>();
    List<StoragePort> existingStoragePorts = new ArrayList<StoragePort>();
    List<PhysicalNAS> modifiedServers = new ArrayList<PhysicalNAS>();
    _logger.info("Start storage port discovery for storage system {}", system.getId());
    // Retrieve the list of data movers interfaces for the VNX File device.
    List<VNXDataMoverIntf> allDmIntfs = getPorts(system);
    List<VNXVdm> vdms = getVdmPortGroups(system);
    // Filter VDM ports
    List<VNXDataMoverIntf> dataMovers = null;
    Map<String, VNXDataMoverIntf> dmIntMap = new HashMap();
    for (VNXDataMoverIntf intf : allDmIntfs) {
        _logger.info("getPorts Adding {} : {}", intf.getName(), intf.getIpAddress());
        dmIntMap.put(intf.getName(), intf);
    }
    // Changes to fix Jira CTRL - 9151
    VNXFileSshApi sshDmApi = new VNXFileSshApi();
    sshDmApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
    // collect VDM interfaces
    for (VNXVdm vdm : vdms) {
        // Sometimes getVdmPortGroups(system) method does not collect all VDM interfaces,
        // So running Collect NFS/CIFS interfaces from nas_server -info command. This will return
        // Interfaces assigned to VDM and not thru CIFS servers
        Map<String, String> vdmIntfs = sshDmApi.getVDMInterfaces(vdm.getVdmName());
        for (String vdmIF : vdmIntfs.keySet()) {
            _logger.info("Remove VDM interface {}", vdmIF);
            dmIntMap.remove(vdmIF);
        }
    }
    // Got the filtered out DataMover Interfaces
    List<VNXDataMoverIntf> dmIntfs = new ArrayList(dmIntMap.values());
    _logger.info("Number unfiltered mover interfaces found: {}", allDmIntfs.size());
    _logger.info("Number mover interfaces found: {}", dmIntfs.size());
    // Create the list of storage ports.
    for (VNXDataMoverIntf intf : dmIntfs) {
        StoragePort port = null;
        StorageHADomain matchingHADomain = getMatchingMoverById(movers, intf.getDataMoverId());
        // Check for valid data mover
        if (null == matchingHADomain) {
            continue;
        }
        // Check if storage port was already discovered
        String portNativeGuid = NativeGUIDGenerator.generateNativeGuid(system, intf.getIpAddress(), NativeGUIDGenerator.PORT);
        port = findExistingPort(portNativeGuid);
        if (null == port) {
            // Since a port was not found, attempt with previous naming convention (ADAPTER instead of PORT)
            String oldNativeGuid = NativeGUIDGenerator.generateNativeGuid(system, intf.getIpAddress(), NativeGUIDGenerator.ADAPTER);
            port = findExistingPort(oldNativeGuid);
            if (null != port) {
                // found with old naming convention, therefore update name.
                port.setLabel(portNativeGuid);
                port.setNativeGuid(portNativeGuid);
            }
        }
        // If data mover interface was not previously discovered, add new storage port
        if (port == null) {
            port = new StoragePort();
            port.setId(URIUtil.createId(StoragePort.class));
            port.setLabel(portNativeGuid);
            port.setTransportType("IP");
            port.setNativeGuid(portNativeGuid);
            port.setStorageDevice(system.getId());
            port.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
            port.setPortName(intf.getName());
            port.setPortNetworkId(intf.getIpAddress());
            port.setPortGroup(intf.getDataMoverId());
            port.setStorageHADomain(matchingHADomain.getId());
            _logger.info("Creating new storage port using NativeGuid : {} name : {}, IP : {}", new Object[] { portNativeGuid, intf.getName(), intf.getIpAddress() });
            newStoragePorts.add(port);
        } else {
            port.setStorageHADomain(matchingHADomain.getId());
            _logger.info("Updating the existing portGroup {} with {} of port {}.", port.getPortGroup(), intf.getDataMoverId(), intf.getIpAddress());
            port.setPortGroup(intf.getDataMoverId());
            existingStoragePorts.add(port);
        }
        port.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
        port.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
        // Set storage port details to vNas
        PhysicalNAS nas = findPhysicalNasByNativeId(system, intf.getDataMoverId());
        if (nas != null) {
            if (nas.getStoragePorts() != null && !nas.getStoragePorts().isEmpty()) {
                if (nas.getStoragePorts().contains(port.getId())) {
                    nas.getStoragePorts().remove(port.getId());
                }
            }
            nas.getStoragePorts().add(port.getId().toString());
            modifiedServers.add(nas);
            _logger.info("PhysicalNAS : {} : port : {} got modified", nas.getId(), port.getPortName());
        }
    }
    // Persist the changed nas servers!!!
    if (modifiedServers != null && !modifiedServers.isEmpty()) {
        _logger.info("Modified PhysicalNAS servers size {}", modifiedServers.size());
        _dbClient.persistObject(modifiedServers);
    }
    _logger.info("Storage port discovery for storage system {} complete", system.getId());
    for (StoragePort newPort : newStoragePorts) {
        _logger.info("New Storage Port : {} : {}", newPort.getNativeGuid(), newPort.getPortName() + ":" + newPort.getId());
    }
    for (StoragePort port : existingStoragePorts) {
        _logger.info("Old Storage Port : {} : {}", port.getNativeGuid(), port.getPortName() + ":" + port.getId());
    }
    storagePorts.put(NEW, newStoragePorts);
    storagePorts.put(EXISTING, existingStoragePorts);
    return storagePorts;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) VNXDataMoverIntf(com.emc.storageos.vnx.xmlapi.VNXDataMoverIntf) VNXVdm(com.emc.storageos.vnx.xmlapi.VNXVdm) VNXFileSshApi(com.emc.storageos.vnx.xmlapi.VNXFileSshApi) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NamespaceList(com.emc.storageos.plugins.common.domainmodel.NamespaceList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageHADomain(com.emc.storageos.db.client.model.StorageHADomain) PhysicalNAS(com.emc.storageos.db.client.model.PhysicalNAS)

Example 2 with VNXFileSshApi

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

the class VNXFileCommunicationInterface method discoverUnManagedCifsShares.

private void discoverUnManagedCifsShares(AccessProfile profile) {
    // Get Storage System
    URI storageSystemId = profile.getSystemId();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
    if (null == storageSystem) {
        return;
    }
    String detailedStatusMessage = "Discovery of VNX Unmanaged Shares started";
    _logger.info(detailedStatusMessage);
    // Used to Save the CIFS ACLs to DB
    List<UnManagedCifsShareACL> newUnManagedCifsACLs = new ArrayList<UnManagedCifsShareACL>();
    List<UnManagedCifsShareACL> oldUnManagedCifsACLs = new ArrayList<UnManagedCifsShareACL>();
    try {
        // Discover port groups (data mover ids) and group names (data mover names)
        Set<StorageHADomain> activeDataMovers = discoverActiveDataMovers(storageSystem);
        // Reused from discoverAll
        // Discover ports (data mover interfaces) with the data movers in the active set.
        Map<String, List<StoragePort>> ports = discoverPorts(storageSystem, activeDataMovers);
        _logger.info("No of newly discovered port {}", ports.get(NEW).size());
        _logger.info("No of existing discovered port {}", ports.get(EXISTING).size());
        if (!ports.get(NEW).isEmpty()) {
            _dbClient.createObject(ports.get(NEW));
        }
        List<StoragePort> allPortsList = ports.get(NEW);
        allPortsList.addAll(ports.get(EXISTING));
        Map<String, List<StoragePort>> allPorts = new ConcurrentHashMap<String, List<StoragePort>>();
        for (StoragePort sPort : allPortsList) {
            _logger.debug("DM Storage Port  {}  StorageHADomain {}", sPort.getPortNetworkId(), sPort.getStorageHADomain());
            List<StoragePort> spList = allPorts.get(sPort.getStorageHADomain().toString());
            if (spList == null) {
                spList = new ArrayList<>();
            }
            spList.add(sPort);
            allPorts.put(sPort.getStorageHADomain().toString(), spList);
        }
        Map<String, List<StorageHADomain>> allVdms = discoverVdmPortGroups(storageSystem, activeDataMovers);
        if (!allVdms.get(NEW).isEmpty()) {
            _dbClient.createObject(allVdms.get(NEW));
        }
        Set<StorageHADomain> allActiveVDMs = new HashSet();
        allActiveVDMs.addAll(allVdms.get(NEW));
        allActiveVDMs.addAll(allVdms.get(EXISTING));
        activeDataMovers.addAll(allVdms.get(NEW));
        activeDataMovers.addAll(allVdms.get(EXISTING));
        Map<String, List<StoragePort>> allVdmPorts = discoverVdmPorts(storageSystem, allActiveVDMs);
        if (!allVdmPorts.get(NEW).isEmpty()) {
            _dbClient.createObject(allVdmPorts.get(NEW));
        }
        List<StoragePort> allVDMPortsList = allVdmPorts.get(NEW);
        allVDMPortsList.addAll(allVdmPorts.get(EXISTING));
        for (StoragePort sPort : allVDMPortsList) {
            List<StoragePort> spList = allPorts.get(sPort.getStorageHADomain().toString());
            _logger.debug("VDM Storage Port  {}  StorageHADomain {}", sPort.getPortNetworkId(), sPort.getStorageHADomain());
            if (spList == null) {
                spList = new ArrayList<>();
            }
            spList.add(sPort);
            allPorts.put(sPort.getStorageHADomain().toString(), spList);
        }
        List<UnManagedFileSystem> unManagedExportBatch = new ArrayList<UnManagedFileSystem>();
        for (StorageHADomain mover : activeDataMovers) {
            // Get storage port and name for the DM
            if (allPorts.get(mover.getId().toString()) == null || allPorts.get(mover.getId().toString()).isEmpty()) {
                // Did not find a single storage port for this DM, ignore it
                _logger.debug("No Ports found for {} {}", mover.getName(), mover.getAdapterName());
                continue;
            } else {
                _logger.debug("Number of  Ports found for {} : {} ", mover.getName() + ":" + mover.getAdapterName(), allPorts.get(mover.getId().toString()).size());
            }
            Collections.shuffle(allPorts.get(mover.getId().toString()));
            StoragePort storagePort = allPorts.get(mover.getId().toString()).get(0);
            if (storagePort == null) {
                // Did not find a single storage port for this DM, ignore it
                _logger.debug("StoragePort is null");
                continue;
            }
            // storagePort.setStorageHADomain(mover.getId());
            // get vnas uri
            URI moverURI = getNASUri(mover, storageSystem);
            // Retrieve FS-mountpath map for the Data Mover.
            _logger.info("Retrieving FS-mountpath map for Data Mover {}.", mover.getAdapterName());
            VNXFileSshApi sshDmApi = new VNXFileSshApi();
            sshDmApi.setConnParams(storageSystem.getIpAddress(), storageSystem.getUsername(), storageSystem.getPassword());
            Map<String, String> fileSystemMountpathMap = sshDmApi.getFsMountpathMap(mover.getAdapterName());
            Map<String, Map<String, String>> moverExportDetails = sshDmApi.getCIFSExportsForPath(mover.getAdapterName());
            Map<String, String> nameIdMap = getFsNameFsNativeIdMap(storageSystem);
            // Loop through the map and, if the file exists in DB, retrieve the
            // export, process export, and associate export with the FS
            Set<String> fsNames = fileSystemMountpathMap.keySet();
            for (String fsName : fsNames) {
                // Retrieve FS from DB. If FS found, retrieve export and process
                String fsMountPath = fileSystemMountpathMap.get(fsName);
                // Get FS ID for nativeGUID
                // VNXFileSystem vnxFileSystems = discoverNamedFileSystem(storageSystem, fsName);
                String fsId = nameIdMap.get(fsName);
                _logger.debug("Resolved FileSystem name {} to native Id {}", fsName, fsId);
                UnManagedFileSystem vnxufs = null;
                if (fsId != null) {
                    String fsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), fsId);
                    vnxufs = checkUnManagedFileSystemExistsInDB(fsNativeGuid);
                }
                if (vnxufs != null) {
                    int noOfShares = 0;
                    // Get export info
                    for (String expPath : moverExportDetails.keySet()) {
                        if (!expPath.contains(fsMountPath)) {
                            // Ignore this path as it is not among the exports
                            continue;
                        } else {
                            // We should process only FS and its sub-directory exports only.
                            String subDir = expPath.substring(fsMountPath.length());
                            if (!subDir.isEmpty() && !subDir.startsWith("/")) {
                                continue;
                            }
                            _logger.info("Path : {} ", expPath);
                        }
                        Map<String, String> fsExportInfo = moverExportDetails.get(expPath);
                        if ((fsExportInfo != null) && (fsExportInfo.size() > 0)) {
                            noOfShares += 1;
                            _logger.info("Associating FS share map for VNX UMFS {}", vnxufs.getLabel());
                            associateCifsExportWithFS(vnxufs, expPath, fsExportInfo, storagePort);
                            vnxufs.setHasShares(true);
                            vnxufs.putFileSystemCharacterstics(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_FILESYSTEM_EXPORTED.toString(), TRUE);
                            _logger.debug("Export map for VNX UMFS {} = {}", vnxufs.getLabel(), vnxufs.getUnManagedSmbShareMap());
                            List<UnManagedCifsShareACL> cifsACLs = applyCifsSecurityRules(vnxufs, expPath, fsExportInfo, storagePort);
                            _logger.info("Number of acls discovered for file system {} is {}", vnxufs.getId() + ":" + vnxufs.getLabel(), cifsACLs.size());
                            for (UnManagedCifsShareACL cifsAcl : cifsACLs) {
                                _logger.info("Unmanaged File share acl: {}", cifsAcl);
                                String fsShareNativeId = cifsAcl.getFileSystemShareACLIndex();
                                _logger.info("UMFS Share ACL index: {}", fsShareNativeId);
                                String fsUnManagedFileShareNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileShare(storageSystem, fsShareNativeId);
                                _logger.info("Native GUID {}", fsUnManagedFileShareNativeGuid);
                                cifsAcl.setNativeGuid(fsUnManagedFileShareNativeGuid);
                                // Check whether the CIFS share ACL was present in ViPR DB.
                                UnManagedCifsShareACL existingACL = checkUnManagedFsCifsACLExistsInDB(_dbClient, cifsAcl.getNativeGuid());
                                if (existingACL == null) {
                                    newUnManagedCifsACLs.add(cifsAcl);
                                } else {
                                    newUnManagedCifsACLs.add(cifsAcl);
                                    existingACL.setInactive(true);
                                    oldUnManagedCifsACLs.add(existingACL);
                                }
                            }
                            // set vNAS on umfs
                            StringSet moverSet = new StringSet();
                            moverSet.add(moverURI.toString());
                            vnxufs.putFileSystemInfo(UnManagedFileSystem.SupportedFileSystemInformation.NAS.toString(), moverSet);
                            unManagedExportBatch.add(vnxufs);
                        }
                    }
                    if (noOfShares == 0) {
                        _logger.info("FileSystem {} does not have shares ", vnxufs.getLabel());
                    }
                }
                if (unManagedExportBatch.size() >= VNXFileConstants.VNX_FILE_BATCH_SIZE) {
                    // Add UnManagedFileSystem batch
                    // Update UnManagedFilesystem
                    _dbClient.persistObject(unManagedExportBatch);
                    unManagedExportBatch.clear();
                }
                if (newUnManagedCifsACLs.size() >= VNXFileConstants.VNX_FILE_BATCH_SIZE) {
                    // create new UnManagedCifsShareACL
                    _logger.info("Saving Number of New UnManagedCifsShareACL(s) {}", newUnManagedCifsACLs.size());
                    _dbClient.createObject(newUnManagedCifsACLs);
                    newUnManagedCifsACLs.clear();
                }
                if (oldUnManagedCifsACLs.size() >= VNXFileConstants.VNX_FILE_BATCH_SIZE) {
                    // Update existing UnManagedCifsShareACL
                    _logger.info("Saving Number of Old UnManagedCifsShareACL(s) {}", oldUnManagedCifsACLs.size());
                    _dbClient.persistObject(oldUnManagedCifsACLs);
                    oldUnManagedCifsACLs.clear();
                }
            }
        }
        if (!unManagedExportBatch.isEmpty()) {
            // Update UnManagedFilesystem
            _dbClient.persistObject(unManagedExportBatch);
            unManagedExportBatch.clear();
        }
        if (!newUnManagedCifsACLs.isEmpty()) {
            // create new UnManagedCifsShareACL
            _logger.info("Saving Number of New UnManagedCifsShareACL(s) {}", newUnManagedCifsACLs.size());
            _dbClient.createObject(newUnManagedCifsACLs);
            newUnManagedCifsACLs.clear();
        }
        if (!oldUnManagedCifsACLs.isEmpty()) {
            // Update existing UnManagedCifsShareACL
            _logger.info("Saving Number of Old UnManagedCifsShareACL(s) {}", oldUnManagedCifsACLs.size());
            _dbClient.persistObject(oldUnManagedCifsACLs);
            oldUnManagedCifsACLs.clear();
        }
        // discovery succeeds
        storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.COMPLETE.toString());
        detailedStatusMessage = String.format("Discovery completed successfully for VNXFile shares: %s", storageSystemId.toString());
    } catch (Exception ex) {
        if (storageSystem != null) {
            cleanupDiscovery(storageSystem);
        }
        storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString());
        detailedStatusMessage = String.format("Discovery failed for VNXFile cifs shares %s because %s", storageSystemId.toString(), ex.getLocalizedMessage());
        _logger.error(detailedStatusMessage, ex);
    } finally {
        if (storageSystem != null) {
            try {
                // set detailed message
                storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
                _dbClient.persistObject(storageSystem);
            } catch (Exception ex) {
                _logger.error("Error while persisting object to DB", ex);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NamespaceList(com.emc.storageos.plugins.common.domainmodel.NamespaceList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageHADomain(com.emc.storageos.db.client.model.StorageHADomain) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UnManagedFileSystem(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet) UnManagedCifsShareACL(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedCifsShareACL) StoragePort(com.emc.storageos.db.client.model.StoragePort) VNXFileSshApi(com.emc.storageos.vnx.xmlapi.VNXFileSshApi) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) VNXException(com.emc.storageos.vnx.xmlapi.VNXException) IOException(java.io.IOException) VNXFileCollectionException(com.emc.storageos.plugins.metering.vnxfile.VNXFileCollectionException) UnManagedFSExportMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UnManagedSMBShareMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) CifsServerMap(com.emc.storageos.db.client.model.CifsServerMap)

Example 3 with VNXFileSshApi

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

the class VNXFileCommunicationInterface method discoverVdmPortGroups.

/**
 * Discover the Data Movers (Port Groups) for the specified VNX File storage array.
 *
 * @param system storage system information including credentials.
 * @param movers Collection of all DataMovers in the VNX File storage array
 * @return Map of New and Existing VDM port groups
 * @throws VNXFileCollectionException
 */
private HashMap<String, List<StorageHADomain>> discoverVdmPortGroups(StorageSystem system, Set<StorageHADomain> movers) throws VNXFileCollectionException, VNXException {
    HashMap<String, List<StorageHADomain>> portGroups = new HashMap();
    List<StorageHADomain> newPortGroups = new ArrayList<StorageHADomain>();
    List<StorageHADomain> existingPortGroups = new ArrayList<StorageHADomain>();
    _logger.info("Start vdm port group discovery for storage system {}", system.getId());
    List<VirtualNAS> newNasServers = new ArrayList<VirtualNAS>();
    List<VirtualNAS> existingNasServers = new ArrayList<VirtualNAS>();
    List<VNXVdm> vdms = getVdmPortGroups(system);
    _logger.debug("Number VDM found: {}", vdms.size());
    VNXFileSshApi sshDmApi = new VNXFileSshApi();
    sshDmApi.setConnParams(system.getIpAddress(), system.getUsername(), system.getPassword());
    for (VNXVdm vdm : vdms) {
        StorageHADomain portGroup = null;
        // Check supported network file sharing protocols.
        StringSet protocols = new StringSet();
        if (null == vdm) {
            _logger.debug("Null vdm in list of port groups.");
            continue;
        }
        // Check if port group was previously discovered
        URIQueryResultList results = new URIQueryResultList();
        String adapterNativeGuid = NativeGUIDGenerator.generateNativeGuid(system, vdm.getVdmName(), NativeGUIDGenerator.ADAPTER);
        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStorageHADomainByNativeGuidConstraint(adapterNativeGuid), results);
        Iterator<URI> iter = results.iterator();
        while (iter.hasNext()) {
            StorageHADomain tmpGroup = _dbClient.queryObject(StorageHADomain.class, iter.next());
            if (tmpGroup != null && !tmpGroup.getInactive() && tmpGroup.getStorageDeviceURI().equals(system.getId())) {
                portGroup = tmpGroup;
                _logger.debug("Found duplicate {} ", vdm.getVdmName());
                break;
            }
        }
        Map<String, String> vdmIntfs = sshDmApi.getVDMInterfaces(vdm.getVdmName());
        Set<String> intfs = null;
        if (vdmIntfs != null) {
            intfs = vdmIntfs.keySet();
        }
        // if NFS Interfaces are not there ignore this..
        if (vdmIntfs == null || intfs.isEmpty()) {
            // There are no interfaces for this VDM via nas_server command
            // so ignore this
            _logger.info("Ignoring VDM {} because no NFS interfaces found via ssh query", vdm.getVdmName());
        } else {
            _logger.info("Process VDM {} because  interfaces found {}", vdm.getVdmName(), vdmIntfs.keySet().size());
        }
        for (String intf : intfs) {
            String vdmCapability = vdmIntfs.get(intf);
            _logger.info("Interface {} capability [{}]", vdm.getVdmName() + ":" + intf, vdmCapability);
            if (vdmCapability.contains("cifs")) {
                _logger.info("{} has CIFS Enabled since interfaces are found ", vdm.getVdmName(), intf + ":" + vdmCapability);
                protocols.add(StorageProtocol.File.CIFS.name());
            }
            if ((vdmCapability.contains("vdm")) || (vdmCapability.contains("nfs"))) {
                _logger.info("{} has NFS Enabled since interfaces are found ", vdm.getVdmName(), intf + ":" + vdmCapability);
                protocols.add(StorageProtocol.File.NFS.name());
            }
        }
        List<VNXCifsServer> cifsServers = getCifServers(system, vdm.getVdmId(), "true");
        CifsServerMap cifsServersMap = new CifsServerMap();
        for (VNXCifsServer cifsServer : cifsServers) {
            _logger.info("Cifs Server {} for {} ", cifsServer.getName(), vdm.getVdmName());
            if (!cifsServer.getInterfaces().isEmpty()) {
                _logger.info("{} has CIFS Enabled since interfaces are found ", vdm.getVdmName(), cifsServer.getName() + ":" + cifsServer.getInterfaces());
                protocols.add(StorageProtocol.File.CIFS.name());
                NasCifsServer nasCifsServer = new NasCifsServer();
                nasCifsServer.setId(cifsServer.getId());
                nasCifsServer.setInterfaces(cifsServer.getInterfaces());
                nasCifsServer.setMoverIdIsVdm(cifsServer.getMoverIdIsVdm());
                nasCifsServer.setName(cifsServer.getName());
                nasCifsServer.setType(cifsServer.getType());
                nasCifsServer.setDomain(cifsServer.getDomain());
                cifsServersMap.put(cifsServer.getName(), nasCifsServer);
            }
        }
        if (protocols.isEmpty()) {
            // No valid interfaces found and ignore this
            _logger.info("Ignoring VDM {} because no NFS/CIFS interfaces found ", vdm.getVdmName());
            continue;
        }
        // If the data mover (aka port group) was not previously discovered
        if (portGroup == null) {
            portGroup = new StorageHADomain();
            portGroup.setId(URIUtil.createId(StorageHADomain.class));
            portGroup.setNativeGuid(adapterNativeGuid);
            portGroup.setStorageDeviceURI(system.getId());
            portGroup.setAdapterName(vdm.getVdmName());
            portGroup.setName(vdm.getVdmId());
            portGroup.setFileSharingProtocols(protocols);
            portGroup.setVirtual(true);
            portGroup.setAdapterType(StorageHADomain.HADomainType.VIRTUAL.toString());
            // Get parent Data Mover
            StorageHADomain matchingParentMover = getMatchingMoverById(movers, vdm.getMoverId());
            // Check for valid data mover
            if (null != matchingParentMover) {
                portGroup.setParentHADomainURI(matchingParentMover.getId());
            } else {
                _logger.info("Matching parent DataMover {} for {} not found ", vdm.getMoverId(), vdm.getVdmName());
            }
            _logger.info("Found Vdm {} at {}", vdm.getVdmName(), vdm.getVdmId() + "@" + vdm.getMoverId());
            newPortGroups.add(portGroup);
        } else {
            // For rediscovery if cifs is not enabled
            portGroup.setFileSharingProtocols(protocols);
            existingPortGroups.add(portGroup);
        }
        VirtualNAS existingNas = findvNasByNativeId(system, vdm.getVdmId());
        if (existingNas != null) {
            existingNas.setProtocols(protocols);
            existingNas.setCifsServersMap(cifsServersMap);
            existingNas.setNasState(vdm.getState());
            existingNas.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
            PhysicalNAS parentNas = findPhysicalNasByNativeId(system, vdm.getMoverId());
            if (parentNas != null) {
                existingNas.setParentNasUri(parentNas.getId());
            }
            existingNasServers.add(existingNas);
        } else {
            VirtualNAS vNas = createVirtualNas(system, vdm);
            if (vNas != null) {
                vNas.setProtocols(protocols);
                vNas.setCifsServersMap(cifsServersMap);
                newNasServers.add(vNas);
            }
        }
    }
    List<VirtualNAS> discoveredVNasServers = new ArrayList<VirtualNAS>();
    // Persist the NAS servers!!!
    if (existingNasServers != null && !existingNasServers.isEmpty()) {
        _logger.info("discoverVdmPortGroups - modified VirtualNAS servers size {}", existingNasServers.size());
        _dbClient.persistObject(existingNasServers);
        discoveredVNasServers.addAll(existingNasServers);
    }
    if (newNasServers != null && !newNasServers.isEmpty()) {
        _logger.info("discoverVdmPortGroups - new VirtualNAS servers size {}", newNasServers.size());
        _dbClient.createObject(newNasServers);
        discoveredVNasServers.addAll(newNasServers);
    }
    // Verify the existing vnas servers!!!
    DiscoveryUtils.checkVirtualNasNotVisible(discoveredVNasServers, _dbClient, system.getId());
    _logger.info("Vdm Port group discovery for storage system {} complete.", system.getId());
    for (StorageHADomain newDomain : newPortGroups) {
        _logger.debug("New Storage Domain : {} : {}", newDomain.getNativeGuid(), newDomain.getAdapterName() + ":" + newDomain.getId());
    }
    for (StorageHADomain domain : existingPortGroups) {
        _logger.debug("Old Storage Domain : {} : {}", domain.getNativeGuid(), domain.getAdapterName() + ":" + domain.getId());
    }
    // return portGroups;
    portGroups.put(NEW, newPortGroups);
    portGroups.put(EXISTING, existingPortGroups);
    return portGroups;
}
Also used : VNXCifsServer(com.emc.storageos.vnx.xmlapi.VNXCifsServer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) VNXVdm(com.emc.storageos.vnx.xmlapi.VNXVdm) VNXFileSshApi(com.emc.storageos.vnx.xmlapi.VNXFileSshApi) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) CifsServerMap(com.emc.storageos.db.client.model.CifsServerMap) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NamespaceList(com.emc.storageos.plugins.common.domainmodel.NamespaceList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) NasCifsServer(com.emc.storageos.db.client.model.NasCifsServer) StorageHADomain(com.emc.storageos.db.client.model.StorageHADomain) PhysicalNAS(com.emc.storageos.db.client.model.PhysicalNAS)

Example 4 with VNXFileSshApi

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

the class VNXFileCommunicationInterface method discoverUnmanagedExports.

private void discoverUnmanagedExports(AccessProfile profile) {
    // Get Storage System
    URI storageSystemId = profile.getSystemId();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
    if (null == storageSystem) {
        return;
    }
    String detailedStatusMessage = "Discovery of VNX Unmanaged Exports started";
    try {
        // Discover port groups (data mover ids) and group names (data mover names)
        Set<StorageHADomain> activeDataMovers = discoverActiveDataMovers(storageSystem);
        // Reused from discoverAll
        // Discover ports (data mover interfaces) with the data movers in the active set.
        Map<String, List<StoragePort>> ports = discoverPorts(storageSystem, activeDataMovers);
        _logger.info("No of newly discovered port {}", ports.get(NEW).size());
        _logger.info("No of existing discovered port {}", ports.get(EXISTING).size());
        if (!ports.get(NEW).isEmpty()) {
            _dbClient.createObject(ports.get(NEW));
        }
        List<StoragePort> allPortsList = ports.get(NEW);
        allPortsList.addAll(ports.get(EXISTING));
        Map<String, List<StoragePort>> allPorts = new ConcurrentHashMap<String, List<StoragePort>>();
        for (StoragePort sPort : allPortsList) {
            _logger.debug("DM Storage Port  {}  StorageHADomain {}", sPort.getPortNetworkId(), sPort.getStorageHADomain());
            List<StoragePort> spList = allPorts.get(sPort.getStorageHADomain().toString());
            if (spList == null) {
                spList = new ArrayList<>();
            }
            spList.add(sPort);
            allPorts.put(sPort.getStorageHADomain().toString(), spList);
        }
        Map<String, List<StorageHADomain>> allVdms = discoverVdmPortGroups(storageSystem, activeDataMovers);
        if (!allVdms.get(NEW).isEmpty()) {
            _dbClient.createObject(allVdms.get(NEW));
        }
        Set<StorageHADomain> allActiveVDMs = new HashSet();
        allActiveVDMs.addAll(allVdms.get(NEW));
        allActiveVDMs.addAll(allVdms.get(EXISTING));
        activeDataMovers.addAll(allVdms.get(NEW));
        activeDataMovers.addAll(allVdms.get(EXISTING));
        Map<String, List<StoragePort>> allVdmPorts = discoverVdmPorts(storageSystem, allActiveVDMs);
        if (!allVdmPorts.get(NEW).isEmpty()) {
            _dbClient.createObject(allVdmPorts.get(NEW));
        }
        List<StoragePort> allVDMPortsList = allVdmPorts.get(NEW);
        allVDMPortsList.addAll(allVdmPorts.get(EXISTING));
        for (StoragePort sPort : allVDMPortsList) {
            List<StoragePort> spList = allPorts.get(sPort.getStorageHADomain().toString());
            _logger.debug("VDM Storage Port  {}  StorageHADomain {}", sPort.getPortNetworkId(), sPort.getStorageHADomain());
            if (spList == null) {
                spList = new ArrayList<>();
            }
            spList.add(sPort);
            allPorts.put(sPort.getStorageHADomain().toString(), spList);
        }
        List<UnManagedFileSystem> unManagedExportBatch = new ArrayList<>();
        List<StorageHADomain> moversAndVDMs = new ArrayList<>();
        moversAndVDMs.addAll(activeDataMovers);
        moversAndVDMs.addAll(allActiveVDMs);
        for (StorageHADomain mover : moversAndVDMs) {
            _logger.info("Processing DataMover/VDM {} {}", mover.getId(), mover.getAdapterName());
            // Get storage port and name for the DM
            if (allPorts.get(mover.getId().toString()) == null || allPorts.get(mover.getId().toString()).isEmpty()) {
                // Did not find a single storage port for this DM, ignore it
                _logger.info("No Ports found for {} {}", mover.getName(), mover.getAdapterName());
                continue;
            } else {
                _logger.info("Number of  Ports found for {} : {} ", mover.getName() + ":" + mover.getAdapterName(), allPorts.get(mover.getId().toString()).size());
            }
            Collections.shuffle(allPorts.get(mover.getId().toString()));
            StoragePort storagePort = allPorts.get(mover.getId().toString()).get(0);
            if (storagePort == null) {
                // Did not find a single storage port for this DM, ignore it
                _logger.info("StoragePort is null");
                continue;
            }
            // storagePort.setStorageHADomain(mover.getId());
            // Retrieve FS-mountpath map for the Data Mover.
            _logger.info("Retrieving FS-mountpath map for Data Mover {}.", mover.getAdapterName());
            VNXFileSshApi sshDmApi = new VNXFileSshApi();
            sshDmApi.setConnParams(storageSystem.getIpAddress(), storageSystem.getUsername(), storageSystem.getPassword());
            Map<String, String> fileSystemMountpathMap = sshDmApi.getFsMountpathMap(mover.getAdapterName());
            Map<String, Map<String, String>> moverExportDetails = sshDmApi.getNFSExportsForPath(mover.getAdapterName());
            Map<String, String> nameIdMap = getFsNameFsNativeIdMap(storageSystem);
            // Loop through the map and, if the file exists in DB, retrieve the
            // export, process export, and associate export with the FS
            Set<String> fsNames = fileSystemMountpathMap.keySet();
            for (String fsName : fsNames) {
                // Retrieve FS from DB. If FS found, retrieve export and process
                String fsMountPath = fileSystemMountpathMap.get(fsName);
                // Get FS ID for nativeGUID
                // VNXFileSystem vnxFileSystems = discoverNamedFileSystem(storageSystem, fsName);
                String fsId = nameIdMap.get(fsName);
                _logger.info("Resolved FileSystem name {} to native Id : Path {}", fsName, fsId + ":" + fsMountPath);
                UnManagedFileSystem vnxufs = null;
                if (fsId != null) {
                    String fsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), fsId);
                    vnxufs = checkUnManagedFileSystemExistsInDB(fsNativeGuid);
                }
                if (vnxufs != null) {
                    // Get export info
                    int noOfExports = 0;
                    for (String expPath : moverExportDetails.keySet()) {
                        if (!expPath.contains(fsMountPath)) {
                            // Ingore this path as it is not among the exports
                            continue;
                        } else {
                            _logger.info("Path : {} ", expPath);
                            noOfExports++;
                        }
                        Map<String, String> fsExportInfo = moverExportDetails.get(expPath);
                        if ((fsExportInfo != null) && (fsExportInfo.size() > 0)) {
                            // If multiple security flavors, do not add to ViPR DB
                            String securityFlavors = fsExportInfo.get(VNXFileConstants.SECURITY_TYPE);
                            if (securityFlavors == null || securityFlavors.length() == 0) {
                                securityFlavors = "sys";
                            }
                            if (securityFlavors != null) {
                                String[] securityFlavorArr = securityFlavors.split(VNXFileConstants.SECURITY_SEPARATORS);
                                if (securityFlavorArr.length > 1) {
                                    _logger.info("FileSystem " + fsMountPath + " has a complex export with multiple security flavors, hence ignoring the filesystem and NOT bringing into ViPR DB");
                                    vnxufs.setInactive(true);
                                } else {
                                    _logger.info("FileSystem " + fsMountPath + " storage port :" + storagePort + " has a valid export with single security flavors {}, hence processing the filesystem and  bringing into ViPR DB", securityFlavors);
                                    vnxufs.setInactive(false);
                                    associateExportWithFS(vnxufs, expPath, fsExportInfo, fsMountPath, storagePort);
                                }
                            }
                        }
                    }
                    _logger.info("No of exports found for path {} = {} ", fsMountPath, noOfExports);
                    if (noOfExports == 0) {
                        _logger.info("FileSystem " + fsMountPath + " does not have valid ViPR exports, hence this filesystem cannot be brought into ViPR DB");
                        vnxufs.putFileSystemCharacterstics(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_INGESTABLE.toString(), FALSE);
                        vnxufs.putFileSystemCharacterstics(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_FILESYSTEM_EXPORTED.toString(), FALSE);
                        vnxufs.setInactive(true);
                    }
                    _logger.info("UnManaged File System {} valid or invalid {}", vnxufs.getLabel(), vnxufs.getInactive());
                    unManagedExportBatch.add(vnxufs);
                    if (unManagedExportBatch.size() >= VNXFileConstants.VNX_FILE_BATCH_SIZE) {
                        _logger.info("Updating {} UnManagedFileSystem in db", unManagedExportBatch.size());
                        // Add UnManagedFileSystem batch
                        _partitionManager.updateInBatches(unManagedExportBatch, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILESYSTEM);
                        unManagedExportBatch.clear();
                    }
                }
            }
        }
        if (!unManagedExportBatch.isEmpty()) {
            _logger.info("Updating {} UnManagedFileSystem in db", unManagedExportBatch.size());
            // Update UnManagedFilesystem
            _partitionManager.updateInBatches(unManagedExportBatch, Constants.DEFAULT_PARTITION_SIZE, _dbClient, UNMANAGED_FILESYSTEM);
            unManagedExportBatch.clear();
        }
        // discovery succeeds
        detailedStatusMessage = String.format("Discovery completed successfully for VNXFile export: %s", storageSystemId.toString());
    } catch (Exception ex) {
        if (storageSystem != null) {
            cleanupDiscovery(storageSystem);
        }
        detailedStatusMessage = String.format("Discovery failed for VNXFile exports %s because %s", storageSystemId.toString(), ex.getLocalizedMessage());
        _logger.error(detailedStatusMessage, ex);
    } finally {
        if (storageSystem != null) {
            try {
                // set detailed message
                storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
                _dbClient.persistObject(storageSystem);
            } catch (Exception ex) {
                _logger.error("Error while persisting object to DB", ex);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NamespaceList(com.emc.storageos.plugins.common.domainmodel.NamespaceList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageHADomain(com.emc.storageos.db.client.model.StorageHADomain) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UnManagedFileSystem(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet) StoragePort(com.emc.storageos.db.client.model.StoragePort) VNXFileSshApi(com.emc.storageos.vnx.xmlapi.VNXFileSshApi) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) VNXException(com.emc.storageos.vnx.xmlapi.VNXException) IOException(java.io.IOException) VNXFileCollectionException(com.emc.storageos.plugins.metering.vnxfile.VNXFileCollectionException) UnManagedFSExportMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UnManagedSMBShareMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) CifsServerMap(com.emc.storageos.db.client.model.CifsServerMap)

Example 5 with VNXFileSshApi

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

the class VNXFileCommunicationInterface method discoverUnmanagedNewExports.

private void discoverUnmanagedNewExports(AccessProfile profile) {
    // Get Storage System
    URI storageSystemId = profile.getSystemId();
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemId);
    if (null == storageSystem) {
        return;
    }
    String detailedStatusMessage = "Discovery of VNX Unmanaged Exports started";
    _logger.info(detailedStatusMessage);
    // Used to Save the rules to DB
    List<UnManagedFileExportRule> newUnManagedExportRules = new ArrayList<UnManagedFileExportRule>();
    List<UnManagedFileExportRule> oldUnManagedExportRules = new ArrayList<UnManagedFileExportRule>();
    try {
        // Verification Utility
        UnManagedExportVerificationUtility validationUtility = new UnManagedExportVerificationUtility(_dbClient);
        // Discover port groups (data mover ids) and group names (data mover names)
        Set<StorageHADomain> activeDataMovers = discoverActiveDataMovers(storageSystem);
        // Reused from discoverAll
        // Discover ports (data mover interfaces) with the data movers in the active set.
        Map<String, List<StoragePort>> ports = discoverPorts(storageSystem, activeDataMovers);
        _logger.info("No of newly discovered port {}", ports.get(NEW).size());
        _logger.info("No of existing discovered port {}", ports.get(EXISTING).size());
        if (!ports.get(NEW).isEmpty()) {
            _dbClient.createObject(ports.get(NEW));
        }
        List<StoragePort> allPortsList = ports.get(NEW);
        allPortsList.addAll(ports.get(EXISTING));
        Map<String, List<StoragePort>> allPorts = new ConcurrentHashMap<String, List<StoragePort>>();
        for (StoragePort sPort : allPortsList) {
            _logger.debug("DM Storage Port  {}  StorageHADomain {}", sPort.getPortNetworkId(), sPort.getStorageHADomain());
            List<StoragePort> spList = allPorts.get(sPort.getStorageHADomain().toString());
            if (spList == null) {
                spList = new ArrayList<>();
            }
            spList.add(sPort);
            allPorts.put(sPort.getStorageHADomain().toString(), spList);
        }
        Map<String, List<StorageHADomain>> allVdms = discoverVdmPortGroups(storageSystem, activeDataMovers);
        if (!allVdms.get(NEW).isEmpty()) {
            _dbClient.createObject(allVdms.get(NEW));
        }
        Set<StorageHADomain> allActiveVDMs = new HashSet();
        allActiveVDMs.addAll(allVdms.get(NEW));
        allActiveVDMs.addAll(allVdms.get(EXISTING));
        activeDataMovers.addAll(allVdms.get(NEW));
        activeDataMovers.addAll(allVdms.get(EXISTING));
        Map<String, List<StoragePort>> allVdmPorts = discoverVdmPorts(storageSystem, allActiveVDMs);
        if (!allVdmPorts.get(NEW).isEmpty()) {
            _dbClient.createObject(allVdmPorts.get(NEW));
        }
        List<StoragePort> allVDMPortsList = allVdmPorts.get(NEW);
        allVDMPortsList.addAll(allVdmPorts.get(EXISTING));
        for (StoragePort sPort : allVDMPortsList) {
            List<StoragePort> spList = allPorts.get(sPort.getStorageHADomain().toString());
            _logger.debug("VDM Storage Port  {}  StorageHADomain {}", sPort.getPortNetworkId(), sPort.getStorageHADomain());
            if (spList == null) {
                spList = new ArrayList<>();
            }
            spList.add(sPort);
            allPorts.put(sPort.getStorageHADomain().toString(), spList);
        }
        List<UnManagedFileSystem> unManagedExportBatch = new ArrayList<>();
        for (StorageHADomain mover : activeDataMovers) {
            // Get storage port and name for the DM
            if (allPorts.get(mover.getId().toString()) == null || allPorts.get(mover.getId().toString()).isEmpty()) {
                // Did not find a single storage port for this DM, ignore it
                _logger.debug("No Ports found for {} {}", mover.getName(), mover.getAdapterName());
                continue;
            } else {
                _logger.debug("Number of  Ports found for {} : {} ", mover.getName() + ":" + mover.getAdapterName(), allPorts.get(mover.getId().toString()).size());
            }
            Collections.shuffle(allPorts.get(mover.getId().toString()));
            StoragePort storagePort = allPorts.get(mover.getId().toString()).get(0);
            if (storagePort == null) {
                // Did not find a single storage port for this DM, ignore it
                _logger.debug("StoragePort is null");
                continue;
            }
            // storagePort.setStorageHADomain(mover.getId());
            // get vnas uri
            URI moverURI = getNASUri(mover, storageSystem);
            // Retrieve FS-mountpath map for the Data Mover.
            _logger.info("Retrieving FS-mountpath map for Data Mover {}.", mover.getAdapterName());
            VNXFileSshApi sshDmApi = new VNXFileSshApi();
            sshDmApi.setConnParams(storageSystem.getIpAddress(), storageSystem.getUsername(), storageSystem.getPassword());
            Map<String, String> fileSystemMountpathMap = sshDmApi.getFsMountpathMap(mover.getAdapterName());
            Map<String, Map<String, String>> moverExportDetails = sshDmApi.getNFSExportsForPath(mover.getAdapterName());
            Map<String, String> nameIdMap = getFsNameFsNativeIdMap(storageSystem);
            // Loop through the map and, if the file exists in DB, retrieve the
            // export, process export, and associate export with the FS
            Set<String> fsNames = fileSystemMountpathMap.keySet();
            for (String fsName : fsNames) {
                // Retrieve FS from DB. If FS found, retrieve export and process
                String fsMountPath = fileSystemMountpathMap.get(fsName);
                // Get FS ID for nativeGUID
                // VNXFileSystem vnxFileSystems = discoverNamedFileSystem(storageSystem, fsName);
                String fsId = nameIdMap.get(fsName);
                _logger.debug("Resolved FileSystem name {} to native Id {}", fsName, fsId);
                UnManagedFileSystem vnxufs = null;
                if (fsId != null) {
                    String fsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), fsId);
                    vnxufs = checkUnManagedFileSystemExistsInDB(fsNativeGuid);
                }
                if (vnxufs != null) {
                    // Get export info
                    int noOfExports = 0;
                    boolean inValidExports = false;
                    for (String expPath : moverExportDetails.keySet()) {
                        if (!expPath.contains(fsMountPath)) {
                            // Ingore this path as it is not among the exports
                            continue;
                        } else {
                            // We should process only FS and its sub-directory exports only.
                            String subDir = expPath.substring(fsMountPath.length());
                            if (!subDir.isEmpty() && !subDir.startsWith("/")) {
                                continue;
                            }
                            _logger.info("Path : {} ", expPath);
                            noOfExports++;
                        }
                        // Used as for rules validation
                        List<UnManagedFileExportRule> unManagedExportRules = new ArrayList<UnManagedFileExportRule>();
                        Map<String, String> fsExportInfo = moverExportDetails.get(expPath);
                        if ((fsExportInfo != null) && (fsExportInfo.size() > 0)) {
                            // If multiple security flavors, do not add to ViPR DB
                            String securityFlavors = fsExportInfo.get(VNXFileConstants.SECURITY_TYPE);
                            if (securityFlavors == null || securityFlavors.length() == 0) {
                                securityFlavors = "sys";
                            }
                            if (securityFlavors != null) {
                                String fsMountPoint = storagePort.getPortNetworkId() + ":" + expPath;
                                _logger.info("Associating FS export map for VNX UMFS {}", vnxufs.getLabel());
                                associateExportWithFS(vnxufs, expPath, fsExportInfo, expPath, storagePort);
                                _logger.debug("Export map for VNX UMFS {} = {}", vnxufs.getLabel(), vnxufs.getFsUnManagedExportMap());
                                List<UnManagedFileExportRule> exportRules = applyAllSecurityRules(vnxufs.getId(), expPath, fsMountPoint, securityFlavors, fsExportInfo);
                                _logger.info("Number of export rules discovered for file system {} is {}", vnxufs.getId() + ":" + vnxufs.getLabel(), exportRules.size());
                                for (UnManagedFileExportRule dbExportRule : exportRules) {
                                    _logger.info("Unmanaged File Export Rule : {}", dbExportRule);
                                    String fsExportRulenativeId = dbExportRule.getFsExportIndex();
                                    _logger.info("Native Id using to build Native Guid {}", fsExportRulenativeId);
                                    String fsUnManagedFileExportRuleNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileExportRule(storageSystem, fsExportRulenativeId);
                                    _logger.info("Native GUID {}", fsUnManagedFileExportRuleNativeGuid);
                                    dbExportRule.setNativeGuid(fsUnManagedFileExportRuleNativeGuid);
                                    dbExportRule.setFileSystemId(vnxufs.getId());
                                    dbExportRule.setId(URIUtil.createId(UnManagedFileExportRule.class));
                                    // Build all export rules list.
                                    unManagedExportRules.add(dbExportRule);
                                }
                                // apply as per API SVC Validations.
                                if (!unManagedExportRules.isEmpty()) {
                                    boolean isAllRulesValid = validationUtility.validateUnManagedExportRules(unManagedExportRules, false);
                                    if (isAllRulesValid) {
                                        _logger.info("Validating rules success for export {}", expPath);
                                        for (UnManagedFileExportRule exportRule : unManagedExportRules) {
                                            UnManagedFileExportRule existingRule = checkUnManagedFsExportRuleExistsInDB(_dbClient, exportRule.getNativeGuid());
                                            if (existingRule == null) {
                                                newUnManagedExportRules.add(exportRule);
                                            } else {
                                                // Remove the existing rule.
                                                existingRule.setInactive(true);
                                                _dbClient.persistObject(existingRule);
                                                newUnManagedExportRules.add(exportRule);
                                            }
                                        }
                                        vnxufs.setHasExports(true);
                                        vnxufs.putFileSystemCharacterstics(UnManagedFileSystem.SupportedFileSystemCharacterstics.IS_FILESYSTEM_EXPORTED.toString(), TRUE);
                                        // Set the correct storage port
                                        if (null != storagePort) {
                                            StringSet storagePorts = new StringSet();
                                            storagePorts.add(storagePort.getId().toString());
                                            vnxufs.getFileSystemInformation().put(UnManagedFileSystem.SupportedFileSystemInformation.STORAGE_PORT.toString(), storagePorts);
                                        }
                                        _dbClient.persistObject(vnxufs);
                                        _logger.info("File System {} has Exports and their size is {}", vnxufs.getId(), newUnManagedExportRules.size());
                                    } else {
                                        _logger.warn("Validating rules failed for export {}. Ignoring to import these rules into ViPR DB", vnxufs);
                                        inValidExports = true;
                                    }
                                } else {
                                    _logger.warn("Export discovery failed for  {}. Ignoring to import these rules into ViPR DB", vnxufs);
                                    inValidExports = true;
                                }
                                // Adding this additional logic to avoid OOM
                                if (newUnManagedExportRules.size() == MAX_UMFS_RECORD_SIZE) {
                                    _logger.info("Saving Number of New UnManagedFileExportRule(s) {}", newUnManagedExportRules.size());
                                    _dbClient.createObject(newUnManagedExportRules);
                                    newUnManagedExportRules.clear();
                                }
                                // Adding this additional logic to avoid OOM
                                if (oldUnManagedExportRules.size() == MAX_UMFS_RECORD_SIZE) {
                                    _logger.info("Saving Number of Existing UnManagedFileExportRule(s) {}", oldUnManagedExportRules.size());
                                    _dbClient.persistObject(oldUnManagedExportRules);
                                    oldUnManagedExportRules.clear();
                                }
                            }
                        }
                    }
                    _logger.info("No of exports found for path {} = {} ", fsMountPath, noOfExports);
                    if (noOfExports == 0) {
                        _logger.info("FileSystem {} does not have any exports ", vnxufs.getLabel());
                        vnxufs.setHasExports(false);
                    }
                    // Don't consider the unmanaged file systems with invalid exports!!!
                    if (inValidExports) {
                        _logger.info("Ignoring unmanaged file system {}, due to invalid exports", vnxufs.getLabel());
                        vnxufs.setInactive(true);
                    }
                    // set the vNAS uri in umfs
                    StringSet moverSet = new StringSet();
                    moverSet.add(moverURI.toString());
                    vnxufs.putFileSystemInfo(UnManagedFileSystem.SupportedFileSystemInformation.NAS.toString(), moverSet);
                    _logger.info("nas server id {} and fs name {}", mover.getName(), fsName);
                    unManagedExportBatch.add(vnxufs);
                    if (unManagedExportBatch.size() >= VNXFileConstants.VNX_FILE_BATCH_SIZE) {
                        // Add UnManagedFileSystem batch
                        // Update UnManagedFilesystem
                        _dbClient.persistObject(unManagedExportBatch);
                        unManagedExportBatch.clear();
                    }
                }
            }
        }
        if (!unManagedExportBatch.isEmpty()) {
            // Update UnManagedFilesystem
            _dbClient.persistObject(unManagedExportBatch);
            unManagedExportBatch.clear();
        }
        if (!newUnManagedExportRules.isEmpty()) {
            // create new UnManagedExportFules
            _logger.info("Saving Number of New UnManagedFileExportRule(s) {}", newUnManagedExportRules.size());
            _dbClient.createObject(newUnManagedExportRules);
            newUnManagedExportRules.clear();
        }
        if (!oldUnManagedExportRules.isEmpty()) {
            // Update exisiting UnManagedExportFules
            _logger.info("Saving Number of Old UnManagedFileExportRule(s) {}", oldUnManagedExportRules.size());
            _dbClient.persistObject(oldUnManagedExportRules);
            oldUnManagedExportRules.clear();
        }
        // discovery succeeds
        storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.COMPLETE.toString());
        detailedStatusMessage = String.format("Discovery completed successfully for VNXFile export: %s", storageSystemId.toString());
    } catch (Exception ex) {
        if (storageSystem != null) {
            cleanupDiscovery(storageSystem);
        }
        storageSystem.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.ERROR.toString());
        detailedStatusMessage = String.format("Discovery failed for VNXFile exports %s because %s", storageSystemId.toString(), ex.getLocalizedMessage());
        _logger.error(detailedStatusMessage, ex);
    } finally {
        if (storageSystem != null) {
            try {
                // set detailed message
                storageSystem.setLastDiscoveryStatusMessage(detailedStatusMessage);
                _dbClient.persistObject(storageSystem);
            } catch (Exception ex) {
                _logger.error("Error while persisting object to DB", ex);
            }
        }
    }
}
Also used : UnManagedExportVerificationUtility(com.emc.storageos.volumecontroller.impl.utils.UnManagedExportVerificationUtility) UnManagedFileExportRule(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileExportRule) ArrayList(java.util.ArrayList) URI(java.net.URI) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NamespaceList(com.emc.storageos.plugins.common.domainmodel.NamespaceList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageHADomain(com.emc.storageos.db.client.model.StorageHADomain) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UnManagedFileSystem(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet) StoragePort(com.emc.storageos.db.client.model.StoragePort) VNXFileSshApi(com.emc.storageos.vnx.xmlapi.VNXFileSshApi) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) URISyntaxException(java.net.URISyntaxException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) VNXException(com.emc.storageos.vnx.xmlapi.VNXException) IOException(java.io.IOException) VNXFileCollectionException(com.emc.storageos.plugins.metering.vnxfile.VNXFileCollectionException) UnManagedFSExportMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFSExportMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UnManagedSMBShareMap(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedSMBShareMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) CifsServerMap(com.emc.storageos.db.client.model.CifsServerMap)

Aggregations

VNXFileSshApi (com.emc.storageos.vnx.xmlapi.VNXFileSshApi)7 ArrayList (java.util.ArrayList)7 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)6 StorageHADomain (com.emc.storageos.db.client.model.StorageHADomain)6 NamespaceList (com.emc.storageos.plugins.common.domainmodel.NamespaceList)6 HashMap (java.util.HashMap)6 LinkedList (java.util.LinkedList)6 List (java.util.List)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 StoragePort (com.emc.storageos.db.client.model.StoragePort)5 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)5 VNXException (com.emc.storageos.vnx.xmlapi.VNXException)5 URI (java.net.URI)5 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)4 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)4 CifsServerMap (com.emc.storageos.db.client.model.CifsServerMap)4 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)4 StringSet (com.emc.storageos.db.client.model.StringSet)4 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)4 VNXFileCollectionException (com.emc.storageos.plugins.metering.vnxfile.VNXFileCollectionException)4