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);
}
}
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;
}
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);
}
}
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());
}
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())));
}
}
}
Aggregations