use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class NetworkAssociationHelper method getNetworksMap.
/**
* Gets the networks of the storage ports organized in a map.
*
* @param endpoints the ports
* @param dbClient an instance of {@link DbClient}
* @return a map of networks and the storage ports that are associated to them.
*/
public static Map<String, Network> getNetworksMap(Collection<String> endpoints, DbClient dbClient) {
Map<String, Network> networkEndPoints = new HashMap<String, Network>();
Network network;
// when a network is found, loop and add all endpoints to its list
// this collection is used to track what is not accounted for yet
List<String> remainingEndPoints = new ArrayList<String>(endpoints);
for (String endpoint : endpoints) {
// if the endpoint is not accounted for
if (remainingEndPoints.contains(endpoint)) {
// find its network
network = NetworkUtil.getEndpointNetwork(endpoint, dbClient);
if (network != null) {
for (String ep : endpoints) {
networkEndPoints.put(ep, network);
// remove from remainingEndPoints because it is accounted for
remainingEndPoints.remove(ep);
}
}
}
}
return networkEndPoints;
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class NetworkAssociationHelper method addNetworkConnectedVarrays.
/**
* Add a list of virtual arrays to a network connected virtual array. Optionally
* cascade this update to the network's routed virtual arrays
*
* @param network the network to update
* @param varraysToAdd the virtual arrays to be added
* @param cascade if true the update will also be made to any routed networks
* @param dbClient an instance of DbClient
*/
public static void addNetworkConnectedVarrays(Network network, Set<String> varraysToAdd, boolean cascade, DbClient dbClient) {
// update the network
_log.info("Adding implicit connected virtual arrays {} for network {}", network.getId(), varraysToAdd);
network.addConnectedVirtualArrays(varraysToAdd);
dbClient.updateObject(network);
// if updating routed networks is also required
if (cascade) {
// get all the network's routed networks and make a list of all networks to update
List<Network> routedNetworks = getNetworkRoutedNetworksForUpdate(network, dbClient);
// and update all of them
for (Network net : routedNetworks) {
_log.info("Adding implicit connected virtual arrays {} for routed network {}", net.getId(), varraysToAdd);
net.addConnectedVirtualArrays(varraysToAdd);
}
dbClient.updateObject(routedNetworks);
}
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class NetworkAssociationHelper method getNetworkRoutedNetworksForUpdate.
/**
* This function returns the routed networks for a given network. It however
* only retrieves one specific field for each. This is done to reduce the
* memory footprint and because NetworkLite cannot be used for updates.
*
* @param network the network for which the routed networks are requested
* @param dbClient an instance of DbClient
* @return the routed networks for the network.
*/
private static List<Network> getNetworkRoutedNetworksForUpdate(Network network, DbClient dbClient) {
List<Network> networks = new ArrayList<Network>();
if (network.getRoutedNetworks() != null && !network.getRoutedNetworks().isEmpty()) {
Iterator<Network> networksItr = dbClient.queryIterativeObjects(Network.class, StringSetUtil.stringSetToUriList(network.getRoutedNetworks()));
while (networksItr.hasNext()) {
Network net = networksItr.next();
if (net != null) {
networks.add(net);
}
}
}
_log.debug("Found {} routed networks for network {}", networks.size(), network.getId());
return networks;
}
use of com.emc.storageos.db.client.model.Network 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());
}
}
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class NetworkUtil method getNetworkLite.
/**
* Given the URI for a Network, obtain its NetworkLite structure.
* This is done without instantiating the endpoint data in the Network
* by calling DbClient.queryObjectFields, which retrieves only certain
* fields from the database.
*
* @param networkURI
* @param client
* @return NetworkLite
*/
public static NetworkLite getNetworkLite(URI networkURI, DbClient client) {
List<URI> ids = new ArrayList<URI>();
ids.add(networkURI);
Set<String> fieldNames = new HashSet<String>();
fieldNames.addAll(NetworkLite.getColumnNames());
Collection<Network> networks = client.queryObjectFields(Network.class, fieldNames, ids);
Iterator<Network> networkIter = networks.iterator();
if (networkIter.hasNext()) {
Network network = networkIter.next();
return new NetworkLite(network);
}
throw DatabaseException.fatals.unableToFindEntity(networkURI);
}
Aggregations