Search in sources :

Example 41 with StorageHADomain

use of com.emc.storageos.db.client.model.StorageHADomain in project coprhd-controller by CoprHD.

the class StoragePortHADomainPopulater method createStorageAdapter.

private StorageHADomain createStorageAdapter(StorageSystem storageSystem, DbClient dbClient) {
    String cinderHostName = "";
    URI providerUri = storageSystem.getActiveProviderURI();
    StorageProvider provider = dbClient.queryObject(StorageProvider.class, providerUri);
    if (null != provider && null != provider.getKeys()) {
        cinderHostName = provider.getKeyValue("CINDER_HOST_NAME");
    }
    String adapterNativeGUID = generateNativeGuid(storageSystem, cinderHostName, "ADAPTER");
    StorageHADomain adapter = new StorageHADomain();
    adapter.setStorageDeviceURI(storageSystem.getId());
    adapter.setId(URIUtil.createId(StorageHADomain.class));
    adapter.setAdapterName(cinderHostName);
    adapter.setLabel(cinderHostName);
    adapter.setNativeGuid(adapterNativeGUID);
    adapter.setNumberofPorts("1");
    adapter.setAdapterType(StorageHADomain.HADomainType.FRONTEND.name());
    adapter.setInactive(false);
    dbClient.createObject(adapter);
    return adapter;
}
Also used : StorageProvider(com.emc.storageos.db.client.model.StorageProvider) StorageHADomain(com.emc.storageos.db.client.model.StorageHADomain) URI(java.net.URI)

Example 42 with StorageHADomain

use of com.emc.storageos.db.client.model.StorageHADomain in project coprhd-controller by CoprHD.

the class CinderStoragePortOperations method create.

/**
 * Creates an instance of new storage port
 * and associates it with the storage system.
 *
 * @param portNetworkId
 * @param transportType
 */
private void create(String portNetworkId, String transportType) {
    logger.info("Start create storage port for portNetworkId={}" + " and transportType={}", portNetworkId, transportType);
    StorageHADomain adapter = CinderUtils.getStorageAdapter(storageSystem, dbClient);
    StoragePort port = new StoragePort();
    port.setId(URIUtil.createId(StoragePort.class));
    port.setStorageDevice(storageSystem.getId());
    String portName = generatePortName();
    logger.debug("New storage port name is = {}", portName);
    String nativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, portName, NativeGUIDGenerator.PORT);
    port.setNativeGuid(nativeGuid);
    port.setPortNetworkId(portNetworkId);
    port.setStorageHADomain(adapter.getId());
    port.setRegistrationStatus(DiscoveredDataObject.RegistrationStatus.REGISTERED.toString());
    // always treat it as a frontend port
    port.setPortType(PortType.frontend.name());
    port.setOperationalStatus(OperationalStatus.OK.toString());
    port.setTransportType(transportType);
    port.setLabel(portName);
    port.setPortName(portName);
    port.setPortGroup("Cinder-PortGroup");
    port.setCompatibilityStatus(CompatibilityStatus.COMPATIBLE.name());
    port.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
    dbClient.createObject(port);
    // Add it to the new ports list
    newStoragePortsList.add(port);
    // Add it to the local list
    allStoragePortsList.add(port);
    logger.info("End create storage port for portNetworkId={}" + " and transportType={}", portNetworkId, transportType);
}
Also used : StoragePort(com.emc.storageos.db.client.model.StoragePort) StorageHADomain(com.emc.storageos.db.client.model.StorageHADomain)

Example 43 with StorageHADomain

use of com.emc.storageos.db.client.model.StorageHADomain 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 44 with StorageHADomain

use of com.emc.storageos.db.client.model.StorageHADomain 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")) {
                _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 45 with StorageHADomain

use of com.emc.storageos.db.client.model.StorageHADomain 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

StorageHADomain (com.emc.storageos.db.client.model.StorageHADomain)80 URI (java.net.URI)41 StoragePort (com.emc.storageos.db.client.model.StoragePort)35 ArrayList (java.util.ArrayList)33 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)26 HashMap (java.util.HashMap)22 List (java.util.List)20 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)19 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)18 StringSet (com.emc.storageos.db.client.model.StringSet)17 VNXException (com.emc.storageos.vnx.xmlapi.VNXException)12 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)11 NamespaceList (com.emc.storageos.plugins.common.domainmodel.NamespaceList)11 URISyntaxException (java.net.URISyntaxException)11 LinkedList (java.util.LinkedList)10 IOException (java.io.IOException)9 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)8 XMLApiResult (com.emc.storageos.vnx.xmlapi.XMLApiResult)8 HashSet (java.util.HashSet)8 Map (java.util.Map)7