Search in sources :

Example 1 with FCEndpoint

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

the class NetworkDiscoveryWorker method reconcileTransportZones.

/**
 * Given the updated list of end points for one network system, this function will update
 * the transport zones.
 * Require lock when reconciles vsan in fabrics that are linked through ISL. Without locking, multiple VSANs
 * could have same native gui id within the same fabric.
 *
 * @param networkSystem the network system
 * @param routedEndpoints IN/OUT parameter to get the routed endpoints map of Fabric-WWN-to-endpoints-WWN
 * @throws ControllerException
 */
private void reconcileTransportZones(NetworkSystem networkSystem, Map<String, Set<String>> routedEndpoints) throws ControllerException {
    _log.info("reconcileTransportZones for networkSystem {}", networkSystem.getId());
    ControllerServiceImpl.Lock lock = ControllerServiceImpl.Lock.getLock(ControllerServiceImpl.DISCOVERY_RECONCILE_TZ);
    try {
        _log.debug("Acquiring lock to reconcile transport zone for networkSystem {}", networkSystem.getId());
        lock.acquire();
        _log.info("Acquired lock to reconcile transport zone for networkSystem {}", networkSystem.getId());
        // get the network system's connections from the database
        Iterator<FCEndpoint> iNewEndPoints = getNetworkSystemEndPoints(networkSystem);
        // get all the transport zones we have in the DB
        List<Network> oldTransportZones = NetworkUtil.getDiscoveredNetworks(dbClient);
        _log.info("Found {} existing transport zones", oldTransportZones.size());
        // get the fabrics that exist on the network system
        Map<String, String> fabricIdsMap = getDevice().getFabricIdsMap(networkSystem);
        // get the list of fabrics added, removed, changed
        TransportZoneReconciler reconciler = new TransportZoneReconciler();
        TransportZoneReconciler.Results results = reconciler.reconcile(networkSystem, iNewEndPoints, fabricIdsMap, oldTransportZones);
        String networkSystemUri = networkSystem.getId().toString();
        for (Network tzone : results.getRemoved()) {
            List<String> removedEps = removeNetworkSystemTransportZone(tzone, networkSystemUri);
            _log.info("Removed network {} which removed discovered endpoints {}", tzone.getNativeGuid(), removedEps);
        }
        for (Network tzone : results.getAdded()) {
            handleEndpointsAdded(tzone, tzone.retrieveEndpoints());
            saveTransportZone(tzone, true);
        }
        for (Network tzone : results.getModified()) {
            if (results.getRemovedEndPoints().get(tzone) != null) {
                NetworkAssociationHelper.handleEndpointsRemoved(tzone, results.getRemovedEndPoints().get(tzone), dbClient, _coordinator);
            }
            if (results.getAddedEndPoints().get(tzone) != null) {
                handleEndpointsAdded(tzone, results.getAddedEndPoints().get(tzone));
            }
            saveTransportZone(tzone, false);
        }
        // update routed networks for routed and modified networks
        updateRoutedNetworks(networkSystem, results.getAddedAndModified(), routedEndpoints);
    } catch (Exception ex) {
        throw NetworkDeviceControllerException.exceptions.reconcileTransportZonesFailedExc(new Date().toString(), ex);
    } finally {
        try {
            _log.debug("Releasing reconcile transport zone lock for networkSystem {}", networkSystem.getId());
            lock.release();
            _log.info("Released reconcile transport zone lock for networkSystem {}", networkSystem.getId());
        } catch (Exception e) {
            _log.error("Failed to release  Lock while reconcile transport zone for network {} -->{}", networkSystem.getId(), e.getMessage());
        }
    }
}
Also used : FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) Date(java.util.Date) ControllerServiceImpl(com.emc.storageos.volumecontroller.impl.ControllerServiceImpl) Network(com.emc.storageos.db.client.model.Network)

Example 2 with FCEndpoint

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

the class NetworkDiscoveryWorker method reconcileFCEndpoints.

/**
 * Reconciles the current set of a Device's endpoints with what is persisted.
 * Updates the database accordingly.
 *
 * @param dev
 * @param currentConnections
 * @throws IOException
 */
private void reconcileFCEndpoints(NetworkSystem dev, List<FCEndpoint> currentConnections) throws IOException {
    // First, read all the existing connections from the device, and put them into a map
    // keyed by remote wwpn.
    URIQueryResultList uriList = new URIQueryResultList();
    dbClient.queryByConstraint(ContainmentConstraint.Factory.getNetworkSystemFCPortConnectionConstraint(dev.getId()), uriList);
    Map<String, FCEndpoint> existingEndpoints = new HashMap<String, FCEndpoint>();
    for (URI uriold : uriList) {
        FCEndpoint connection = dbClient.queryObject(FCEndpoint.class, uriold);
        if (connection != null) {
            existingEndpoints.put(connection.getRemotePortName().toUpperCase(), connection);
        }
    }
    // Now, scan the new endpoints, looking for added or updated records by
    // comparing them with the existing endpoints. Keep track of what was processed
    // so can do deletions on anything not seen in the currentConnections.
    List<FCEndpoint> updated = new ArrayList<FCEndpoint>();
    List<FCEndpoint> created = new ArrayList<FCEndpoint>();
    Set<String> processedWwpns = new HashSet<String>();
    int conflictingEndpoints = 0;
    for (FCEndpoint current : currentConnections) {
        String key = current.getRemotePortName().toUpperCase();
        processedWwpns.add(key);
        FCEndpoint existing = existingEndpoints.get(key);
        if (existing == null) {
            current.setNetworkDevice(dev.getId());
            current.setId(URIUtil.createId(FCEndpoint.class));
            if (WWNUtility.isValidWWN(current.getRemotePortName())) {
                created.add(current);
            } else {
                _log.info("Invalid new FCEndpoint {}, Hence not adding it to DB", current.getRemotePortName());
            }
            conflictingEndpoints += removeConflictingEndpoints(key, current.getFabricWwn(), dev.getId());
        } else {
            boolean modified = checkUpdated(existing, current);
            if (existing.getAwolCount() > 0) {
                modified = true;
                existing.setAwolCount(0);
                existing.setAwolTime(null);
            }
            if (modified) {
                if (WWNUtility.isValidWWN(existing.getRemotePortName())) {
                    updated.add(existing);
                } else {
                    _log.info("Invalid existing FCEndpoint {}, Hence not updating it to DB", existing.getRemotePortName());
                }
                conflictingEndpoints += removeConflictingEndpoints(key, current.getFabricWwn(), dev.getId());
            }
        }
    }
    // What was left were not seen this time.
    for (String key : processedWwpns) {
        existingEndpoints.remove(key);
    }
    // The remaining existingEndpoints can be processed for removal.
    // They are removed after a minimum number of samples and minimum amount of time has transpired.
    Integer removedCount = 0;
    for (FCEndpoint entry : existingEndpoints.values()) {
        int count = entry.getAwolCount();
        if (count == 0) {
            entry.setAwolTime(System.currentTimeMillis());
        }
        entry.setAwolCount(++count);
        if (count >= _minAwolSamples && (System.currentTimeMillis() - entry.getAwolTime()) > _minAwolTime) {
            removedCount++;
            dbClient.removeObject(entry);
        } else {
            // update counters
            updated.add(entry);
        }
    }
    // Persist created, modified.
    dbClient.createObject(created);
    dbClient.updateObject(updated);
    _log.info(MessageFormat.format("{0} new connections persisted", created.size()).toString());
    _log.info(MessageFormat.format("{0} updated connections persisted", updated.size()).toString());
    _log.info(MessageFormat.format("{0} missing connections", existingEndpoints.values().size()).toString());
    _log.info(MessageFormat.format("{0} removed connections", removedCount.toString()));
    _log.info(MessageFormat.format("{0} conflicting connections (removed)", conflictingEndpoints));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) HashSet(java.util.HashSet)

Example 3 with FCEndpoint

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

the class NetworkDiscoveryWorker method updatePhysicalInventory.

/**
 * Update the network system physical inventory and creates/updates the discovered FC transport
 * zones as needed. The physical inventory is primarily the FCEndpoints (FCPortConnections),
 * which contains a record for each endpoint logged into the Fiber Channel Nameserver database.
 * The endpoints per fabric (vsan) constitute an FC transport zone which get created/updated
 * based on the FCEndpoints discovered.
 *
 * @param uri - Device URI
 */
public void updatePhysicalInventory(URI uri) throws ControllerException {
    // Retrieve the storage device info from the database.
    long start = System.currentTimeMillis();
    NetworkSystem networkDev = getDeviceObject(uri);
    String msg = "unknown status";
    NetworkSystemDevice networkDevice = getDevice();
    if (networkDevice == null) {
        throw NetworkDeviceControllerException.exceptions.updatePhysicalInventoryFailedNull(uri.toString(), networkDev.getSystemType());
    }
    try {
        // === Reconcile the FCEndpoints of this device ===
        List<FCEndpoint> currentConnections = new ArrayList<FCEndpoint>();
        // IN/OUT parameter to get the routed endpoints map - Fabric-WWN-to-endpoints-WWN
        Map<String, Set<String>> routedEndpoints = new HashMap<String, Set<String>>();
        try {
            currentConnections = networkDevice.getPortConnections(networkDev, routedEndpoints);
            msg = MessageFormat.format("Retrieved {0} connections from device {1} at {2}", new Integer(currentConnections.size()), uri, new Date());
            _log.info(msg);
        } catch (Exception e) {
            msg = MessageFormat.format("Discovery failed getting port connections for Network System : {0}", uri.toString());
            throw (e);
        }
        try {
            reconcileFCEndpoints(networkDev, currentConnections);
        } catch (Exception e) {
            msg = MessageFormat.format("Discovery failed reconciling FC endpoints for Network System : {0}", uri.toString());
            throw (e);
        }
        // ==== Reconcile the discovered transport zones ======
        try {
            reconcileTransportZones(networkDev, routedEndpoints);
        } catch (Exception e) {
            msg = MessageFormat.format("Discovery failed reconciling networks for Network System : {0}", uri.toString());
            throw (e);
        }
        try {
            networkDev.setUptime(networkDevice.getUptime(networkDev));
        } catch (Exception e) {
            msg = MessageFormat.format("Discovery failed setting version/uptime for Network System : {0}", uri.toString());
            throw (e);
        }
        // discovery succeeds
        msg = MessageFormat.format("Discovery completed successfully for Network System : {0}", uri.toString());
    } catch (Exception ex) {
        Date date = new Date();
        throw NetworkDeviceControllerException.exceptions.updatePhysicalInventoryFailedExc(uri.toString(), date.toString(), ex);
    } finally {
        if (networkDev != null) {
            try {
                // set detailed message
                networkDev.setLastDiscoveryStatusMessage(msg);
                dbClient.updateObject(networkDev);
                _log.info("Discovery took {}", (System.currentTimeMillis() - start));
            } catch (DatabaseException ex) {
                _log.error("Error while persisting object to DB", ex);
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) ArrayList(java.util.ArrayList) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) Date(java.util.Date) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 4 with FCEndpoint

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

the class TransportZoneReconciler method getNewTransportZones.

private HashMap<String, Network> getNewTransportZones(NetworkSystem network, Iterator<FCEndpoint> iEndPoints, Map<String, String> fabricIdsMap) throws Exception {
    HashMap<String, Network> newTransportZones = new HashMap<String, Network>();
    // first create empty transport zones
    Network tz = null;
    for (String wwn : fabricIdsMap.keySet()) {
        tz = createTransportZone(network, wwn, fabricIdsMap.get(wwn));
        newTransportZones.put(wwn, tz);
    }
    while (iEndPoints.hasNext()) {
        FCEndpoint endpoint = iEndPoints.next();
        if (endpoint == null || endpoint.getInactive() || // this should never happen
        !newTransportZones.containsKey(endpoint.getFabricWwn())) {
            continue;
        }
        newTransportZones.get(endpoint.getFabricWwn()).addEndpoints(Collections.singletonList(endpoint.getRemotePortName().toUpperCase()), true);
    }
    return newTransportZones;
}
Also used : HashMap(java.util.HashMap) Network(com.emc.storageos.db.client.model.Network) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint)

Example 5 with FCEndpoint

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

the class BrocadeNetworkSMIS method getFCEndpointsByFabric.

/**
 * Get FCEndpoints instances by getting TopologyView instances by fabric. This method
 * of getting TopologyView instances can be slow in some environments thus the need
 * for the alternate function {@link #getFCEndpointsByFabric(WBEMClient, Map, Map, Map, Map)} which is faster but requires more
 * memory. The user can select the function best suitable
 * using config item controller_ns_brocade_discovery_by_fabric_association
 *
 * @param client
 *            WBEMClient
 * @param routedConnections
 *            IN/OUT - A map where routed endpoints will be stored
 * @param fabricsByIds
 *            a map of fabric name to fabric WWN
 * @param deviceNameCache
 *            a map to cache switch names
 * @param logicalToPhysicalSwitchMap
 *            a map to cache logical switches and their container physical switch
 * @return a map of endpoint Wwn to its FCEndpoint instance
 * @throws WBEMException
 */
private Map<String, FCEndpoint> getFCEndpointsByFabric(WBEMClient client, Map<String, Set<String>> routedConnections, Map<String, String> fabricsByIds, Map<String, String> deviceNameCache, Map<String, String> logicalToPhysicalSwitchMap) throws WBEMException {
    long start = System.currentTimeMillis();
    _log.info("Getting topology by fabric");
    Map<String, FCEndpoint> portConnections = new HashMap<String, FCEndpoint>();
    CIMObjectPath path = CimObjectPathCreator.createInstance(_fabric_path, _namespace);
    CloseableIterator<CIMInstance> it = null;
    try {
        it = client.enumerateInstances(path, false, true, true, null);
        while (it.hasNext()) {
            CIMInstance ins = it.next();
            String fabricWwn = formatWWN(cimStringProperty(ins, _name));
            String fabricName = cimStringProperty(ins, _element_name);
            _log.info("Fabric: " + fabricName + " (" + fabricWwn + ")");
            CloseableIterator<CIMInstance> topit = client.associatorInstances(ins.getObjectPath(), _Brocade_TopologyViewInFabric, _Brocade_TopologyView, null, null, false, null);
            try {
                CIMInstance topins = null;
                while (topit.hasNext()) {
                    topins = topit.next();
                    _log.debug(topins.toString());
                    processTopologyViewInstance(client, topins, portConnections, routedConnections, fabricsByIds.get(fabricWwn), fabricWwn, deviceNameCache, logicalToPhysicalSwitchMap);
                }
            } finally {
                if (topit != null) {
                    topit.close();
                }
            }
        }
    } finally {
        if (it != null) {
            it.close();
        }
    }
    _log.info("Getting topology by fabric took " + (System.currentTimeMillis() - start));
    return portConnections;
}
Also used : HashMap(java.util.HashMap) CIMObjectPath(javax.cim.CIMObjectPath) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) CIMInstance(javax.cim.CIMInstance)

Aggregations

FCEndpoint (com.emc.storageos.db.client.model.FCEndpoint)19 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)6 URI (java.net.URI)6 HashMap (java.util.HashMap)6 ControllerException (com.emc.storageos.volumecontroller.ControllerException)5 ArrayList (java.util.ArrayList)5 CIMInstance (javax.cim.CIMInstance)5 CIMObjectPath (javax.cim.CIMObjectPath)5 Network (com.emc.storageos.db.client.model.Network)4 HashSet (java.util.HashSet)4 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)3 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)3 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)2 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)2 IOException (java.io.IOException)2 Date (java.util.Date)2 MapVirtualArray (com.emc.storageos.api.mapper.functions.MapVirtualArray)1 ComputeFabricUplinkPort (com.emc.storageos.db.client.model.ComputeFabricUplinkPort)1 ComputeFabricUplinkPortChannel (com.emc.storageos.db.client.model.ComputeFabricUplinkPortChannel)1