Search in sources :

Example 36 with Network

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

the class MdsNetworkSystemDevice method determineRoutedNetworks.

/*
     * (non-Javadoc)
     * @see com.emc.storageos.networkcontroller.impl.NetworkSystemDevice#determineRoutedNetworks(com.emc.storageos.db.client.model.NetworkSystem)
     */
@Override
public void determineRoutedNetworks(NetworkSystem networkSystem) throws NetworkDeviceControllerException {
    MDSDialog dialog = null;
    /* Example output "show ivr vsan-topology"
		 * 	AFID  SWITCH WWN                 Active   Cfg. VSANS
		 * 	-----------------------------------------------------------
		 * 	1  20:00:00:0d:ec:dc:86:40 *   yes      no  1,3,11,99,200
		 * 	1  20:00:00:2a:6a:33:13:10     yes      no  1-3,10,78,99,200
		 */
    // 1. Build a map of switchWWN to NetworkSystem for all the discovered NetworkSystems
    Map<String, NetworkSystem> switchWWNToNetworkSystemMap = new HashMap<String, NetworkSystem>();
    for (URI discoveredNetworkSystemUri : NetworkUtil.getDiscoveredNetworkSystems(_dbClient)) {
        NetworkSystem discoveredNetworkSystem = _dbClient.queryObject(NetworkSystem.class, discoveredNetworkSystemUri);
        try {
            if (discoveredNetworkSystem.getSystemType().equalsIgnoreCase(NetworkSystem.Type.mds.toString())) {
                dialog = setUpDialog(discoveredNetworkSystem);
                String switchWWN = dialog.showSwitchWwn();
                switchWWNToNetworkSystemMap.put(switchWWN, discoveredNetworkSystem);
                _log.info(String.format("NetworkSystem : %s - WWN : %s", switchWWNToNetworkSystemMap.get(switchWWN).getLabel(), switchWWN));
            }
        } catch (Exception e) {
            _log.info(String.format("Couldnt fetch the switch WWN information for %s, ignoring it", discoveredNetworkSystem.getLabel()));
        } finally {
            disconnect(dialog);
        }
    }
    // Build a map of Switch WWN to their VSANs from the topology map
    try {
        dialog = setUpDialog(networkSystem);
        String currentNetworkSytemWWN = dialog.showSwitchWwn();
        Map<String, Set<Integer>> switchWWNToVsans = new HashMap<>();
        List<IvrVsanConfiguration> ivrVsansList = dialog.showIvrVsanTopology();
        for (IvrVsanConfiguration ivrVsan : ivrVsansList) {
            Set<Integer> vsans = new HashSet<Integer>();
            vsans.addAll(ivrVsan.getVsans());
            for (IntRange ivrVsanRange : ivrVsan.getVsansRanges()) {
                for (int range = ivrVsanRange.getMinimumInteger(); range <= ivrVsanRange.getMaximumInteger(); range++) {
                    vsans.add(range);
                }
            }
            switchWWNToVsans.put(ivrVsan.getSwitchWwn(), vsans);
        }
        // 3. Check to make sure that the current Network system (that is being discovered) is in the ivr vsan-topology map.
        if (!switchWWNToVsans.containsKey(currentNetworkSytemWWN)) {
            _log.info(String.format("Currently discovered NetworkSystem with WWN %s is not part of the ivr vsan-topology, returning.", currentNetworkSytemWWN));
            return;
        }
        // 4. Loop through all the switch WWNs from the topology map and check if they are discovered.
        // If yes, then all the networks of that network-system are routable to all the other networks from other discovered switches that are also in the vsan-topology map.
        // Since this map is constructed from the output of "show ivr vsan-topology", the switch WWNs listed in that output are
        // all routable to each others for the networks that belong to them.
        // NOTE: The assumption here is that there exists a transit VSAN between the switches that are on the IVR path. ViPR will not check for existence of transit
        // networks, but it is required for inter VSAN routing in IVR configurations.
        List<Network> routedNetworks = new ArrayList<Network>();
        for (Entry<String, Set<Integer>> switchWWNToVsan : switchWWNToVsans.entrySet()) {
            String switchKey = switchWWNToVsan.getKey();
            Set<Integer> vsanValues = switchWWNToVsan.getValue();
            if (switchWWNToNetworkSystemMap.containsKey(switchKey)) {
                NetworkSystem ns = switchWWNToNetworkSystemMap.get(switchKey);
                URIQueryResultList networkSystemNetworkUriList = new URIQueryResultList();
                // Fetch all the networks of this networkSystem
                _dbClient.queryByConstraint(ContainmentConstraint.Factory.getNetworkSystemNetworkConstraint(ns.getId()), networkSystemNetworkUriList);
                for (URI networkSystemNetworkUri : networkSystemNetworkUriList) {
                    Network networkSystemNetwork = _dbClient.queryObject(Network.class, networkSystemNetworkUri);
                    if (vsanValues.contains(Integer.parseInt(networkSystemNetwork.getNativeId())) && !routedNetworks.contains(networkSystemNetwork)) {
                        if (!routedNetworks.contains(networkSystemNetwork)) {
                            _log.info("Routable Network: " + networkSystemNetwork.getLabel() + " from  Switch : " + ns.getLabel());
                            routedNetworks.add(networkSystemNetwork);
                        } else {
                            _log.info(String.format("Routed network %s already included in the list", networkSystemNetwork.getLabel()));
                        }
                    }
                }
            }
        }
        // Again, transit VSANs are required for routing to happen, but ViPR will not check for existence of transit VSANs.
        for (Network network1 : routedNetworks) {
            network1.setRoutedNetworks(new StringSet());
            for (Network network2 : routedNetworks) {
                if (network1.getNativeGuid().toString().equalsIgnoreCase(network2.getNativeGuid().toString())) {
                    _log.info(String.format("%s is same as %s no routed network update required", network1.getLabel(), network2.getLabel()));
                    continue;
                }
                _log.info(String.format("%s can route to %s", network1.getLabel().toString(), network2.getLabel().toString()));
                network1.getRoutedNetworks().add(network2.getId().toString());
            }
        }
        _log.debug("Calling dbUpdate for : " + routedNetworks.size() + " networks");
        for (Network rn : routedNetworks) {
            _log.info(rn.toString());
        }
        _dbClient.updateObject(routedNetworks);
    } catch (Exception ex) {
        _log.error("Cannot determine routable networks for networks on  " + networkSystem.getLabel() + " : " + ex.getLocalizedMessage());
        throw ex;
    } finally {
        disconnect(dialog);
    }
}
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) IntRange(org.apache.commons.lang.math.IntRange) ArrayList(java.util.ArrayList) URI(java.net.URI) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) FCEndpoint(com.emc.storageos.db.client.model.FCEndpoint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Network(com.emc.storageos.db.client.model.Network) StringSet(com.emc.storageos.db.client.model.StringSet) HashSet(java.util.HashSet)

Example 37 with Network

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

the class ExternalDeviceCommunicationInterface method getNetworkForStoragePort.

/**
 * Returns Network object based on storage port information.
 *
 * @param driverPort [in] - storage port instance
 * @return Network object
 */
private Network getNetworkForStoragePort(StoragePort driverPort) {
    Network network;
    List<Network> results = CustomQueryUtility.queryActiveResourcesByAltId(_dbClient, Network.class, "nativeId", driverPort.getNetworkId());
    if (results == null || results.isEmpty()) {
        network = new Network();
        network.setId(URIUtil.createId(Network.class));
        network.setTransportType(driverPort.getTransportType());
        network.setNativeId(driverPort.getNetworkId());
        network.setLabel(driverPort.getNetworkId());
        network.setRegistrationStatus(DiscoveredDataObject.RegistrationStatus.REGISTERED.name());
        network.setInactive(false);
        _dbClient.createObject(network);
        _log.info("Created a new network {}.", network.getLabel());
    } else {
        network = results.get(0);
    }
    return network;
}
Also used : Network(com.emc.storageos.db.client.model.Network)

Example 38 with Network

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

the class NetworkConnectedVirtualArraysMigration method process.

/**
 * Add assigned virtual arrays to connected virtual arrays.
 * Starting 2.0, connected virtual arrays includes assigned,
 * connected via port-virtualArray associations, and connected
 * via routed networks
 */
@Override
public void process() throws MigrationCallbackException {
    DbClient dbClient = getDbClient();
    try {
        List<URI> networkUris = dbClient.queryByType(Network.class, true);
        Iterator<Network> networks = dbClient.queryIterativeObjects(Network.class, networkUris);
        List<Network> updated = new ArrayList<Network>();
        while (networks.hasNext()) {
            Network network = networks.next();
            log.info("Updating connected virtual arrays for network {}", network.getLabel());
            if (network.getAssignedVirtualArrays() != null) {
                if (network.getConnectedVirtualArrays() != null) {
                    for (String assignedVarrayUri : network.getAssignedVirtualArrays()) {
                        log.info("Adding virtual array {} to connected virtual arrays", assignedVarrayUri);
                        network.getConnectedVirtualArrays().add(assignedVarrayUri);
                    }
                } else {
                    log.info("Setting connected virtual arrays to {}", network.getAssignedVirtualArrays());
                    network.setConnectedVirtualArrays(new StringSet(network.getAssignedVirtualArrays()));
                }
                updated.add(network);
            }
        }
        dbClient.updateAndReindexObject(updated);
    } catch (Exception e) {
        log.error("Exception occured while updating Network connectedVirtualArrays");
        log.error(e.getMessage(), e);
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) Network(com.emc.storageos.db.client.model.Network) ArrayList(java.util.ArrayList) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)

Example 39 with Network

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

the class DbClientTest method testCfWithMutipleRelationIndex.

@Test
public void testCfWithMutipleRelationIndex() {
    _logger.info("Starting testCompareIndexes");
    DbClient dbClient = _dbClient;
    URI varrayId1 = URIUtil.createId(VirtualArray.class);
    VirtualArray varray1 = new VirtualArray();
    varray1.setId(varrayId1);
    varray1.setLabel("varray1");
    dbClient.createObject(varray1);
    Network nw1 = new Network();
    nw1.setId(URIUtil.createId(Network.class));
    nw1.setLabel("networkObj");
    StringSet varrayStrSet1 = new StringSet();
    varrayStrSet1.add(varrayId1.toString());
    nw1.setAssignedVirtualArrays(varrayStrSet1);
    dbClient.createObject(nw1);
    List<Network> assignedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId1, Network.class, "assignedVirtualArrays");
    Assert.assertTrue(assignedNetworks.iterator().hasNext());
    Assert.assertEquals(assignedNetworks.size(), 1);
    List<Network> connectedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId1, Network.class, "connectedVirtualArrays");
    Assert.assertFalse(connectedNetworks.iterator().hasNext());
    URI varrayId2 = URIUtil.createId(VirtualArray.class);
    VirtualArray varray2 = new VirtualArray();
    varray2.setId(varrayId2);
    varray2.setLabel("varray2");
    dbClient.createObject(varray2);
    StringSet varrayStrSet2 = new StringSet();
    varrayStrSet2.add(varrayId1.toString());
    varrayStrSet2.add(varrayId2.toString());
    nw1.setConnectedVirtualArrays(varrayStrSet2);
    dbClient.persistObject(nw1);
    assignedNetworks.clear();
    assignedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId1, Network.class, "assignedVirtualArrays");
    Assert.assertTrue(assignedNetworks.iterator().hasNext());
    Assert.assertEquals(assignedNetworks.size(), 1);
    connectedNetworks.clear();
    connectedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId2, Network.class, "connectedVirtualArrays");
    Assert.assertTrue(connectedNetworks.iterator().hasNext());
    Assert.assertEquals(connectedNetworks.size(), 1);
    connectedNetworks.clear();
    connectedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId1, Network.class, "connectedVirtualArrays");
    Assert.assertTrue(connectedNetworks.iterator().hasNext());
    Assert.assertEquals(connectedNetworks.size(), 1);
    assignedNetworks.clear();
    assignedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId2, Network.class, "assignedVirtualArrays");
    Assert.assertFalse(assignedNetworks.iterator().hasNext());
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) DbClient(com.emc.storageos.db.client.DbClient) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) Network(com.emc.storageos.db.client.model.Network) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Test(org.junit.Test)

Example 40 with Network

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

the class NetworkAssignedVirtualArraysMigrationTest method verifyResults.

@Override
protected void verifyResults() throws Exception {
    List<URI> networkURIs = _dbClient.queryByType(Network.class, false);
    Iterator<Network> networksIter = _dbClient.queryIterativeObjects(Network.class, networkURIs);
    while (networksIter.hasNext()) {
        Network network = networksIter.next();
        String networkId = network.getId().toString();
        StringSet assignedVArrayIds = network.getAssignedVirtualArrays();
        if (network.getLabel().equals("NetworkWithVarray")) {
            Assert.assertTrue(String.format("Network (id=%s) should have an assigned virtual array", networkId), ((assignedVArrayIds != null) && (!assignedVArrayIds.isEmpty())));
            int count = 0;
            for (String assignedVArrayId : assignedVArrayIds) {
                Assert.assertTrue("Network has unexpected varray assignment", assignedVArrayId.equals(varrayURI.toString()));
                count++;
            }
            Assert.assertTrue("Network has incorrect varray count", count == 1);
        } else {
            Assert.assertTrue(String.format("Network (id=%s) should NOT have an assigned virtual array", networkId), ((assignedVArrayIds == null) || (assignedVArrayIds.isEmpty())));
        }
    }
}
Also used : Network(com.emc.storageos.db.client.model.Network) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI)

Aggregations

Network (com.emc.storageos.db.client.model.Network)88 URI (java.net.URI)42 ArrayList (java.util.ArrayList)38 StringSet (com.emc.storageos.db.client.model.StringSet)31 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)28 StoragePort (com.emc.storageos.db.client.model.StoragePort)25 StringMap (com.emc.storageos.db.client.model.StringMap)23 List (java.util.List)23 StoragePool (com.emc.storageos.db.client.model.StoragePool)22 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)22 Test (org.junit.Test)20 NamedURI (com.emc.storageos.db.client.model.NamedURI)19 Project (com.emc.storageos.db.client.model.Project)19 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)19 VirtualPoolCapabilityValuesWrapper (com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper)19 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)17 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)16 Produces (javax.ws.rs.Produces)16 RPProtectionRecommendation (com.emc.storageos.volumecontroller.RPProtectionRecommendation)15