Search in sources :

Example 1 with VFNetInfo

use of com.iwave.ext.netapp.VFNetInfo in project coprhd-controller by CoprHD.

the class NetAppFileCommunicationInterface method discoverPorts.

private Map<String, List<StoragePort>> discoverPorts(StorageSystem storageSystem, List<VFilerInfo> vFilers, List<StorageHADomain> haDomains) throws NetAppFileCollectionException {
    URI storageSystemId = storageSystem.getId();
    HashMap<String, List<StoragePort>> storagePorts = new HashMap<String, List<StoragePort>>();
    List<StoragePort> newStoragePorts = new ArrayList<StoragePort>();
    List<StoragePort> existingStoragePorts = new ArrayList<StoragePort>();
    // Discover storage ports
    try {
        _logger.info("discoverPorts for storage system {} - start", storageSystemId);
        StoragePort storagePort = null;
        if (vFilers != null && !vFilers.isEmpty()) {
            for (VFilerInfo filer : vFilers) {
                for (VFNetInfo intf : filer.getInterfaces()) {
                    if (intf.getNetInterface().equals(MANAGEMENT_INTERFACE)) {
                        continue;
                    }
                    URIQueryResultList results = new URIQueryResultList();
                    String portNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, intf.getIpAddress(), NativeGUIDGenerator.PORT);
                    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePortByNativeGuidConstraint(portNativeGuid), results);
                    storagePort = null;
                    if (results.iterator().hasNext()) {
                        StoragePort tmpPort = _dbClient.queryObject(StoragePort.class, results.iterator().next());
                        if (tmpPort.getStorageDevice().equals(storageSystem.getId()) && tmpPort.getPortGroup().equals(filer.getName())) {
                            storagePort = tmpPort;
                            _logger.debug("found duplicate intf {}", intf.getIpAddress());
                        }
                    }
                    if (storagePort == null) {
                        storagePort = new StoragePort();
                        storagePort.setId(URIUtil.createId(StoragePort.class));
                        storagePort.setTransportType("IP");
                        storagePort.setNativeGuid(portNativeGuid);
                        storagePort.setLabel(portNativeGuid);
                        storagePort.setStorageDevice(storageSystemId);
                        storagePort.setPortName(intf.getIpAddress());
                        storagePort.setPortNetworkId(intf.getIpAddress());
                        storagePort.setPortGroup(filer.getName());
                        storagePort.setStorageHADomain(findMatchingHADomain(filer.getName(), haDomains));
                        storagePort.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
                        _logger.info("Creating new storage port using NativeGuid : {}", portNativeGuid);
                        newStoragePorts.add(storagePort);
                    } else {
                        existingStoragePorts.add(storagePort);
                    }
                    storagePort.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
                    storagePort.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
                }
            }
        } else {
            // Check if storage port was already discovered
            URIQueryResultList results = new URIQueryResultList();
            String portNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem, storageSystem.getIpAddress(), NativeGUIDGenerator.PORT);
            _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePortByNativeGuidConstraint(portNativeGuid), results);
            if (results.iterator().hasNext()) {
                StoragePort tmpPort = _dbClient.queryObject(StoragePort.class, results.iterator().next());
                if (tmpPort.getStorageDevice().equals(storageSystem.getId()) && tmpPort.getPortGroup().equals(storageSystem.getSerialNumber())) {
                    storagePort = tmpPort;
                    _logger.debug("found duplicate dm intf {}", storageSystem.getSerialNumber());
                }
            }
            if (storagePort == null) {
                // Create NetApp storage port for IP address
                storagePort = new StoragePort();
                storagePort.setId(URIUtil.createId(StoragePort.class));
                storagePort.setTransportType("IP");
                storagePort.setNativeGuid(portNativeGuid);
                storagePort.setLabel(portNativeGuid);
                storagePort.setStorageDevice(storageSystemId);
                storagePort.setPortName(storageSystem.getIpAddress());
                storagePort.setPortNetworkId(storageSystem.getIpAddress());
                storagePort.setPortGroup(storageSystem.getSerialNumber());
                storagePort.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
                _logger.info("Creating new storage port using NativeGuid : {}", portNativeGuid);
                newStoragePorts.add(storagePort);
            } else {
                existingStoragePorts.add(storagePort);
            }
            storagePort.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
        }
        _logger.info("discoverPorts for storage system {} - complete", storageSystemId);
        storagePorts.put(NEW, newStoragePorts);
        storagePorts.put(EXISTING, existingStoragePorts);
        return storagePorts;
    } catch (Exception e) {
        _logger.error("discoverPorts failed. Storage system: " + storageSystemId, e);
        throw new NetAppFileCollectionException("discoverPorts failed. Storage system: " + storageSystemId, e);
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) NetAppException(com.emc.storageos.netapp.NetAppException) NetAppFileCollectionException(com.emc.storageos.plugins.metering.netapp.NetAppFileCollectionException) IOException(java.io.IOException) VFilerInfo(com.iwave.ext.netapp.VFilerInfo) VFNetInfo(com.iwave.ext.netapp.VFNetInfo) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) NetAppFileCollectionException(com.emc.storageos.plugins.metering.netapp.NetAppFileCollectionException)

Aggregations

URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 StoragePort (com.emc.storageos.db.client.model.StoragePort)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 NetAppException (com.emc.storageos.netapp.NetAppException)1 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)1 NetAppFileCollectionException (com.emc.storageos.plugins.metering.netapp.NetAppFileCollectionException)1 VFNetInfo (com.iwave.ext.netapp.VFNetInfo)1 VFilerInfo (com.iwave.ext.netapp.VFilerInfo)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1