use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class NetworkUtil method getEndpointNetwork.
/**
* Get the network the endpoint is associated with if any
*
* @param endpoint
* @param dbClient
* @return a reference to a network
* Assumes endpoint formats have been validated.
*/
public static Network getEndpointNetwork(String endpoint, DbClient dbClient) {
_log.debug("Finding network for endpoint {}", endpoint);
URIQueryResultList networkList = new URIQueryResultList();
Iterator<URI> iterator;
URI networkUri = null;
Network network;
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getEndpointNetworkConstraint(endpoint), networkList);
iterator = networkList.iterator();
while (iterator.hasNext()) {
networkUri = iterator.next();
network = dbClient.queryObject(Network.class, networkUri);
if (network != null && network.getInactive() == false) {
_log.info("network {} for endpoint {} was found", networkUri, endpoint);
return network;
} else {
_log.info("network {} for endpoint {} was deleted or is inactive", networkUri, endpoint);
}
}
_log.info("network could not be found for endpoint {}", endpoint);
return null;
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class DataSourceFactory method createZoneNameDataSource.
/**
* Creates a data source for resolving a zone name using the provided
* parameters. This is a utility function created for the purpose of
* reducing clutter in the export code.
*
* @param hostName the name of the host for which the zone will be created
* @param initiator the initiator for which the zone will be created
* @param port the instance of the port for which the zone will be created
* @param storageSystem the instance of the storage system of the zone's port
* @param nativeId the nativeId of the network where the zone will be created
* @return a data source populated with the properties needed to resolve
* a zone name
*/
public DataSource createZoneNameDataSource(String hostName, Initiator initiator, StoragePort port, String nativeId, StorageSystem storageSystem) {
// we want to avoid looking up the network because of all the endpoints
Network network = new Network();
network.setNativeId(nativeId);
return createZoneNameDataSource(getHostByName(hostName), initiator, port, network, storageSystem);
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class TransportZoneReconciler method handleRemovedTransportZone.
/**
* This function handles transport zones that were seen on the network
* system before but cannot be found by fabric WWN search in the new list of
* transport zone. The possible scenario are :
* <ol>
* <li>The fabric was indeed removed from the network system</li>
* <li>The fabric still exists but under a new WWN (case when principal switch changes or fragmentation)</li>
* <li>The fabric was discovered while fragmented and assumed to be an isolated fabric but now it is merging again and so, for all
* practical purposes, the old WWN should be removed</li>
* </ol>
*
* @param tzone
* - the zone that cannot be matched by WWN to a new zone
* @param networkUri
* - the URI of the network system
* @param newTransportZones
* - The collection of transport zones discovered on the network system
* @param oldTransportZones
* - The collection of all transport zones discovered and active
* @return The new transport zone that has been determined to be the match of tzone.
* @throws IOException
*/
private Network handleRemovedTransportZone(Network tzone, URI networkUri, HashMap<String, Network> newTransportZones, Collection<Network> oldTransportZones, Results results) throws IOException {
Network newTransportZone = null;
String uri = networkUri.toString();
if (tzone.getNetworkSystems().contains(uri)) {
// first we check if it is removed, fragmented or has a new WWN
// If we find a network with the same fabricId, the network either merging and has new WWN
newTransportZone = findByFabricId(tzone, newTransportZones);
if (newTransportZone == null) {
// this transport zone no longer exists
_log.info("Existing network {} did not match any in the " + " new networks by name or by WWN. It must have been removed.", tzone.getLabel());
results.getRemoved().add(tzone);
} else {
// new principal switch? merging?
_log.info("Existing network {} matches {} in the " + " new networks by name. Reconciling the two.", tzone.getLabel(), newTransportZone.getLabel());
// find if an existing network matched by fabricId and WWN
Network oldTransportZone = findMatchByFabricIdAndWwn(newTransportZone, oldTransportZones);
if (oldTransportZone != null) {
_log.info("The fabric must have fragmented and is now merging." + "User changes will be merged also any endpoints found will be added.");
// merge user changes to the other fragment and remove from this one so it can be deleted
oldTransportZone.addEndpoints(getUserCreatedEndPoints(tzone), false);
tzone.removeEndpoints(getUserCreatedEndPoints(tzone));
if (tzone.getAssignedVirtualArrays() != null) {
oldTransportZone.addAssignedVirtualArrays(tzone.getAssignedVirtualArrays());
tzone.removeAssignedVirtualArrays(tzone.getAssignedVirtualArrays());
}
// remove the fragment
results.getRemoved().add(tzone);
// we are removing the old - the new one is NOT a match
newTransportZone = null;
} else {
// either fragmenting or principal switch change -
// Update the old transportZone
_log.info("Either the fabric is fragmenting or the principal " + "switch has changed. Adding new endpoints and keeping old ones.");
mergeNetworks(tzone, newTransportZone);
results.getModified().add(tzone);
}
}
}
return newTransportZone;
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class TransportZoneReconciler method reconcile.
/**
* Given the old transport zones and the new fabrics and end points
* returns the lists of what needs to be updated, deleted and added.
*
* @param network - The network system being refreshed
* @param iEndPoints - the iterator of new end points
* @param fabricIdsMap - the list of all fabrics on the network system
* @param oldTransportZones - the old transport zones
* @throws Exception
* @return A results object containing lists of added, removed and modified
* transport zone
*/
public Results reconcile(NetworkSystem network, Iterator<FCEndpoint> iEndPoints, Map<String, String> fabricIdsMap, List<Network> oldTransportZones) throws Exception {
// compute the new transport zones for the network system being
// refreshed from the end points
HashMap<String, Network> newTransportZones = getNewTransportZones(network, iEndPoints, fabricIdsMap);
_log.info("Reconciling {} new networks with " + "the existing {} networks", newTransportZones.size(), oldTransportZones.size());
// a list to keep track of used names - needed when generating new names
// to avoid duplications
List<String> existingTransportZoneNames = new ArrayList<String>();
// This is the map used to track what has not been accounted for - i.e.
// new transport zones
HashMap<String, Network> mutableMap = new HashMap<String, Network>(newTransportZones);
Results results = new Results();
// reconcile
for (Network transportZone : oldTransportZones) {
existingTransportZoneNames.add(transportZone.getLabel());
if (transportZone.getDiscovered() == true) {
String fabricWwn = parseWWNFromGuid(transportZone.getNativeGuid());
if (newTransportZones.containsKey(fabricWwn)) {
_log.info("Checking if existing network {} " + " needs updating.", transportZone.getLabel());
handleUpdatedTransportZone(network, transportZone, newTransportZones.get(fabricWwn), results);
mutableMap.remove(fabricWwn);
} else if (transportZone.getNetworkSystems().contains(network.getId().toString())) {
_log.info("Existing network is not found." + " Checking if it is removed or modified", transportZone.getLabel());
Network newTZ = handleRemovedTransportZone(transportZone, network.getId(), newTransportZones, oldTransportZones, results);
if (newTZ != null) {
// we figured the old transport zone has changed WWN
// so we're using one and throwing away one
mutableMap.remove(NetworkUtil.getNetworkWwn(newTZ));
}
}
}
}
// transport zones
for (String wwn : mutableMap.keySet()) {
Network newTZ = mutableMap.get(wwn);
newTZ.setLabel(getUniqueTransportZoneName(newTZ.getLabel(), existingTransportZoneNames));
results.getAdded().add(newTZ);
}
return results;
}
use of com.emc.storageos.db.client.model.Network 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;
}
Aggregations