use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.
the class VPlexVnxMaskingOrchestrator method getPortGroups.
/**
* Returns the set of port groups that should be used.
* Each port group is a map of Network to a list of Storage Ports in that Network.
* Since at most we can construct two InitiatorGroups, we try to construct
* two PortGroups.
*
* @return Sets of PortGroups, where each Port Group is a map of Network URI
* to a List of Storage Ports.
*/
@Override
public Set<Map<URI, List<List<StoragePort>>>> getPortGroups(Map<URI, List<StoragePort>> allocatablePorts, Map<URI, NetworkLite> networkMap, URI varrayURI, int nInitiatorGroups, Map<URI, Map<String, Integer>> switchToPortNumber, Map<URI, PortAllocationContext> contextMap, StringBuilder errorMessages) {
Set<Map<URI, List<List<StoragePort>>>> portGroups = new HashSet<Map<URI, List<List<StoragePort>>>>();
// Determine the network with the fewest ports. It will determine how many
// port groups can be made.
int minPorts = Integer.MAX_VALUE;
for (URI networkURI : allocatablePorts.keySet()) {
int numPorts = allocatablePorts.get(networkURI).size();
if (numPorts < minPorts) {
minPorts = numPorts;
}
}
// Figure out the number of ports in each network per port group (PG).
// Then figure out the number of port groups to be generated,
// which will always be one or two.
boolean oneNetwork = allocatablePorts.keySet().size() == 1;
int numPG = 1;
if (nInitiatorGroups == 2 && minPorts >= 2 && !oneNetwork) {
numPG = 2;
}
if (numPG == 0) {
return portGroups;
}
_log.info(String.format("Number Port Groups %d", numPG));
// Make a map per Network of number of ports to allocate.
Map<URI, Integer> portsAllocatedPerNetwork = new HashMap<URI, Integer>();
for (URI netURI : allocatablePorts.keySet()) {
// Calculate the number of ports to be allocated for this net. It is:
// the number of allocatable ports / numPG.
Integer nports = allocatablePorts.get(netURI).size() / numPG;
portsAllocatedPerNetwork.put(netURI, nports);
}
StoragePortsAllocator allocator = new StoragePortsAllocator();
for (int i = 0; i < numPG; i++) {
Map<URI, List<List<StoragePort>>> portGroup = new HashMap<URI, List<List<StoragePort>>>();
StringSet portNames = new StringSet();
for (URI netURI : allocatablePorts.keySet()) {
NetworkLite net = networkMap.get(netURI);
Map<String, Integer> switchCountMap = null;
if (switchToPortNumber != null) {
switchCountMap = switchToPortNumber.get(netURI);
}
PortAllocationContext context = null;
if (contextMap != null) {
context = contextMap.get(netURI);
}
List<StoragePort> allocatedPorts = allocatePorts(allocator, allocatablePorts.get(netURI), portsAllocatedPerNetwork.get(netURI), net, varrayURI, switchCountMap, context);
if (portGroup.get(netURI) == null) {
portGroup.put(netURI, new ArrayList<List<StoragePort>>());
}
portGroup.get(netURI).add(allocatedPorts);
allocatablePorts.get(netURI).removeAll(allocatedPorts);
for (StoragePort port : allocatedPorts) {
portNames.add(port.getPortName());
}
}
portGroups.add(portGroup);
_log.info(String.format("Port Group %d: %s", i, portNames.toString()));
// Reinitialize the context in the allocator; we want redundancy within PG
if (allocator.getContext() != null) {
allocator.getContext().reinitialize();
}
}
return portGroups;
}
use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.
the class MdsNetworkSystemDevice method getRoutedZone.
/**
* Construct an in memory ivr zone, if applied.
*
* @param dialog dialog session to borderNetworkSystem
* @param zone
* @param borderNetworkSystem ivr border network which has a dialog session open
* @return an ivr zone
*/
private IvrZone getRoutedZone(MDSDialog dialog, Zone zone, NetworkSystem borderNetworkSystem) {
IvrZone ivrZone = null;
// member vsan in ivr zone
Set<String> vsanIds = Sets.newHashSet();
if (zone != null && zone.getMembers() != null && zone.getMembers().size() == 2) {
ivrZone = new IvrZone(zone.getName());
List<IvrZoneMember> ivrZoneMembers = ivrZone.getMembers();
// Map<String, String> aliasDatabase = dialog.showDeviceAliasDatabase();
// map zone member address to corresponded network system
Map<String, NetworkLite> networkLiteMap = new HashMap<String, NetworkLite>();
// to list of ivr zone member.
for (ZoneMember zoneMember : zone.getMembers()) {
// TODO - need to revisit if ViPR decides to support alias for IVR
if (StringUtils.isEmpty(zoneMember.getAddress())) {
break;
}
NetworkLite networkLite = NetworkUtil.getEndpointNetworkLite(zoneMember.getAddress().trim(), _dbClient, vsanIds);
if (networkLite != null) {
// cached networklite for later reference
networkLiteMap.put(zoneMember.getAddress(), networkLite);
// if pwwn 's parent network is a routed network, construct an ivr zone member
Set<String> routedNetworks = networkLite.getRoutedNetworks();
if (routedNetworks != null && !routedNetworks.isEmpty()) {
Integer networkVsanId = Integer.valueOf(networkLite.getNativeId());
ivrZoneMembers.add(new IvrZoneMember(zoneMember.getAddress(), networkVsanId));
vsanIds.add(networkVsanId.toString());
}
}
}
/*
* if ivr zone members are in the same network, then they are not routed.
* Then, null out ivr zone.
*/
if (areIvrZoneMembersInSameNetwork(ivrZoneMembers) || ivrZoneMembers.size() <= 1) {
ivrZoneMembers.clear();
ivrZone = null;
} else {
// loop through to get ivr networksystem to later perform ivr cli on
for (IvrZoneMember ivrZoneMember : ivrZoneMembers) {
// if no ivr network system was set for ivr zone, find and set it
if (ivrZone.getIvrNetworkSystem() == null) {
NetworkLite networkLite = networkLiteMap.get(ivrZoneMember.getPwwn());
ivrZone.setIvrNetworkSystem(getIvrNetworkSystem(dialog, borderNetworkSystem, networkLite));
}
// if an ivr network system is set, exit loop
if (ivrZone.getIvrNetworkSystem() != null) {
break;
}
}
}
}
return ivrZone;
}
use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.
the class RecoverPointScheduler method isRpSiteConnectedToVarray.
/**
* Determines if the RP site is connected to the passed virtual array.
*
* @param storageSystemURI Storage System ID
* @param protectionSystemURI Protection Systen ID
* @param siteId RP Site ID
* @param virtualArray the virtual array to check for RP site connectivity
* @return True if the RP Site is connected to the varray, false otherwise.
*/
public boolean isRpSiteConnectedToVarray(URI storageSystemURI, URI protectionSystemURI, String siteId, VirtualArray virtualArray) {
ProtectionSystem protectionSystem = dbClient.queryObject(ProtectionSystem.class, protectionSystemURI);
StringSet siteInitiators = protectionSystem.getSiteInitiators().get(siteId);
boolean connected = false;
for (String wwn : siteInitiators) {
NetworkLite network = NetworkUtil.getEndpointNetworkLite(wwn, dbClient);
// The network is connected if it is assigned or implicitly connected to the varray
if (RPHelper.isNetworkConnectedToVarray(network, virtualArray)) {
connected = true;
break;
}
}
// Check to make sure the RP site is connected to the varray
return (connected && RPHelper.rpInitiatorsInStorageConnectedNetwork(storageSystemURI, protectionSystemURI, siteId, virtualArray.getId(), dbClient));
}
use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.
the class BlockStorageScheduler method updateZoningMap.
/**
* Updates the ExportMask's zoning map after the initiator to port associations
* have been discovered from an array like Cinder. This routine is needed when we
* are masking first, and cannot tell the array what ports are assigned to what initiators,
* i.e. rather the array tells us what it did. In particular, this is applicable to storage
* arrays managed by Southbound SDK drivers.
* This routine is not needed when the array can be told what initiators to map to what ports.
* 1. All zoning map entries for the initiators in the mask are removed.
* 2. For the targets in the mask, they are paired with the initiators they can service,
* i.e. that are on the same or a routeable network, and are usable in the varray,
* and the corresponding zones are put in the zoning map.
* Then the path parameters are enforced, based on the path parameter data discovered from
* the ExportMask.
* 3. Any initiators with more than paths_per_initiator ports are reduced to have
* only pathsPerInitiator number of ports. We try not to remove the same port from
* multiple initiators. (Note: we do not declare it an error if there are fewer
* than pathsPerInitiator ports assigned to an initiator.)
* 4. Then we verify we are not over maxPaths. This is done by counting up the number of
* paths currently in the mask, and if there are excess, cycling through the networks
* (starting with the network with the most initiators) and removing initiators until
* we are under paths per initiator.
* 5. Finally we sum up the paths in the mask, and verify that we have at least as
* many as minPaths.
*
* @param mask -- The ExportMask being manipulated
* @param varray -- The Virtual Array (normally from the ExportGroup)
* @param exportGroupURI -- URI of the ExportGroup
*
* Assumption: the export mask has up to date initiators and storage ports
*/
public void updateZoningMap(ExportMask mask, URI varray, URI exportGroupURI) {
// Convert the volumes to a Collection.
List<URI> volumeURIs = ExportMaskUtils.getVolumeURIs(mask);
// Determine the number of paths required for the volumes in the export mask.
ExportPathParams pathParams = calculateExportPathParamForVolumes(volumeURIs, 0, mask.getStorageDevice(), exportGroupURI);
_log.info(String.format("Updating zoning map for ExportMask %s (%s) pathParams %s", mask.getMaskName(), mask.getId(), pathParams.toString()));
// Data structures for mapping Network to Initiators and Network to StoragePorts
Map<URI, Set<Initiator>> network2InitiatorsMap = new HashMap<URI, Set<Initiator>>();
Map<URI, Set<StoragePort>> network2PortsMap = new HashMap<URI, Set<StoragePort>>();
_log.debug("Export Mask before zoning map update -" + mask.toString());
// so it is not considered by getInitiatorPortsInMask().
for (String initiatorURIStr : mask.getZoningMap().keySet()) {
mask.removeZoningMapEntry(initiatorURIStr);
}
mask.setZoningMap(null);
// corresponding to the Initiator.
for (String initiatorURIStr : mask.getInitiators()) {
Initiator initiator = _dbClient.queryObject(Initiator.class, URI.create(initiatorURIStr));
if (initiator == null || initiator.getInactive()) {
continue;
}
// Add the initiator to the net2InitiatorsMap
NetworkLite initiatorNetwork = getInitiatorNetwork(initiator, _dbClient);
if (!network2InitiatorsMap.containsKey(initiatorNetwork.getId())) {
network2InitiatorsMap.put(initiatorNetwork.getId(), new HashSet<Initiator>());
}
network2InitiatorsMap.get(initiatorNetwork.getId()).add(initiator);
List<URI> storagePortList = ExportUtils.getPortsInInitiatorNetwork(mask, initiator, _dbClient);
if (storagePortList.isEmpty()) {
continue;
}
StringSet storagePorts = new StringSet();
for (URI portURI : storagePortList) {
StoragePort port = _dbClient.queryObject(StoragePort.class, portURI);
URI portNetworkId = port.getNetwork();
if (!DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name().equals(port.getCompatibilityStatus()) || !DiscoveryStatus.VISIBLE.name().equals(port.getDiscoveryStatus()) || NullColumnValueGetter.isNullURI(portNetworkId) || !port.getRegistrationStatus().equals(StoragePort.RegistrationStatus.REGISTERED.name()) || StoragePort.OperationalStatus.NOT_OK.equals(StoragePort.OperationalStatus.valueOf(port.getOperationalStatus())) || StoragePort.PortType.valueOf(port.getPortType()) != StoragePort.PortType.frontend) {
_log.debug("Storage port {} is not selected because it is inactive, is not compatible, is not visible, not on a network, " + "is not registered, has a status other than OK, or is not a frontend port", port.getLabel());
continue;
}
// Network cnnectivity was checked in getInitiatorPortsInMask()
if (port.getTaggedVirtualArrays().contains(varray.toString())) {
storagePorts.add(portURI.toString());
if (!network2PortsMap.containsKey(portNetworkId)) {
network2PortsMap.put(portNetworkId, new HashSet<StoragePort>());
}
network2PortsMap.get(portNetworkId).add(port);
} else {
_log.debug("Storage port {} is not selected because it is not in the specified varray {}", port.getLabel(), varray.toString());
}
}
mask.addZoningMapEntry(initiatorURIStr, storagePorts);
}
_log.debug("Export Mask after zoning map update -" + mask.toString());
// Now that we have constructed an initial cut at the zoning map, enforce the path parameters.
// 1. Ensure that no initiator has more than the paths_per_initiator variable allows.
// For every initiator, make sure it doesn't have more than paths_per_initiator ports.
// Try not to remove the same port multiple times.
Set<String> removedPorts = new HashSet<String>();
for (URI networkURI : network2InitiatorsMap.keySet()) {
for (Initiator initiator : network2InitiatorsMap.get(networkURI)) {
StringSet ports = mask.getZoningMap().get(initiator.getId().toString());
if ((null == ports) || (ports.size() <= pathParams.getPathsPerInitiator())) {
continue;
}
_log.info(String.format("Limiting paths for initiator %s to %s; initial ports %s", initiator.getInitiatorPort(), pathParams.getPathsPerInitiator().toString(), ports));
boolean removedPort = true;
outer: while (removedPort && ports.size() > pathParams.getPathsPerInitiator()) {
// First try not removing an already removed port
removedPort = false;
for (String port : ports) {
if (!removedPorts.contains(port)) {
removedPorts.add(port);
ports.remove(port);
removedPort = true;
continue outer;
}
}
// As a last resort, remove a port that is duplicated
for (String port : ports) {
removedPorts.add(port);
ports.remove(port);
removedPort = true;
continue outer;
}
}
_log.info(String.format("Limited ports for initiator %s to %s", initiator.getInitiatorPort(), ports));
}
}
// Now check that the total number of entries is not higher than maxPaths.
// Remove paths from Networks with the most initiators to the list by removing initiators.
ExportPathParams currentPathParams = calculateExportPathParamForExportMask(_dbClient, mask);
Integer overMaxPaths = currentPathParams.getMaxPaths() - pathParams.getMaxPaths();
// Make a sorted map of initiator count to networks.
SortedMap<Integer, Set<URI>> initiatorCountToNetwork = new TreeMap<Integer, Set<URI>>();
for (URI networkURI : network2InitiatorsMap.keySet()) {
Integer count = network2InitiatorsMap.get(networkURI).size();
if (!initiatorCountToNetwork.containsKey(count)) {
initiatorCountToNetwork.put(count, new HashSet<URI>());
}
initiatorCountToNetwork.get(count).add(networkURI);
}
while (overMaxPaths > 0) {
// Go backwards from last key (highest count) to first (lowest count).
Integer lastKey = initiatorCountToNetwork.lastKey();
Integer firstKey = initiatorCountToNetwork.firstKey();
for (Integer count = lastKey; overMaxPaths > 0 && count >= firstKey; count--) {
// Remove an Initiator from each network
Set<URI> networks = initiatorCountToNetwork.get(count);
if (networks == null) {
continue;
}
for (URI networkURI : networks) {
Iterator<Initiator> iter = network2InitiatorsMap.get(networkURI).iterator();
if (iter.hasNext()) {
// Remove an initiator
Initiator initiator = iter.next();
StringSet ports = mask.getZoningMap().get(initiator.getId().toString());
overMaxPaths -= ports.size();
_log.info(String.format("Removing initiator %s to comply with maxPaths", initiator.getInitiatorPort()));
mask.removeZoningMapEntry(initiator.getId().toString());
network2InitiatorsMap.get(networkURI).remove(initiator);
}
if (overMaxPaths <= 0) {
break;
}
}
}
}
// Finally, count the resulting number of paths, and make sure it is over minPaths.
Integer pathCount = 0;
Integer initiatorCount = 0;
for (String initiatorId : mask.getZoningMap().keySet()) {
initiatorCount++;
StringSet ports = mask.getZoningMap().get(initiatorId);
pathCount += ports.size();
}
_log.info(String.format("ExportMask %s (%s) pathCount %s", mask.getMaskName(), mask.getId(), pathCount.toString()));
if (pathCount < pathParams.getMinPaths()) {
throw PlacementException.exceptions.cannotAllocateMinPaths(pathParams.getMinPaths(), initiatorCount, pathParams.getPathsPerInitiator(), pathParams.getMinPaths(), pathParams.getMaxPaths());
}
// Save the updated ExportMask
_dbClient.updateObject(mask);
}
use of com.emc.storageos.util.NetworkLite in project coprhd-controller by CoprHD.
the class BlockStorageScheduler method selectStoragePorts.
/**
* Return list of storage ports for the passed storage device connected
* to the given network and with connectivity to the passed virtual
* array.
*
* Port must be REGISTERED, and the OperationalStatus must not be NOT_OK
* and it must be a frontend port.
*
* @param storageSystemURI The URI of the storage system
* @param networkURI The URI of the network.
* @param varrayURI The URI of the virtual array.
*
* @return The list of storage ports.
*/
public List<StoragePort> selectStoragePorts(URI storageSystemURI, URI networkURI, URI varrayURI) {
NetworkLite networkLite = NetworkUtil.getNetworkLite(networkURI, _dbClient);
_log.info("Selecting ports for network {} {}", networkLite.getLabel(), networkLite.getId());
// The list of storage ports in networkURI
List<StoragePort> spList = new ArrayList<StoragePort>();
// The list of storage ports in networks that are routed to networkURI
List<StoragePort> rspList = new ArrayList<StoragePort>();
List<String> unroutedPorts = new ArrayList<String>();
List<String> routedPorts = new ArrayList<String>();
List<String> notRegisteredOrOk = new ArrayList<String>();
List<String> notInVarray = new ArrayList<String>();
List<String> wrongNetwork = new ArrayList<String>();
URIQueryResultList sports = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePortConstraint(storageSystemURI), sports);
Iterator<URI> it = sports.iterator();
while (it.hasNext()) {
StoragePort sp = _dbClient.queryObject(StoragePort.class, it.next());
if (sp.getInactive() || sp.getNetwork() == null || !DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name().equals(sp.getCompatibilityStatus()) || !DiscoveryStatus.VISIBLE.name().equals(sp.getDiscoveryStatus()) || !sp.getRegistrationStatus().equals(StoragePort.RegistrationStatus.REGISTERED.name()) || StoragePort.OperationalStatus.NOT_OK.equals(StoragePort.OperationalStatus.valueOf(sp.getOperationalStatus())) || StoragePort.PortType.valueOf(sp.getPortType()) != StoragePort.PortType.frontend) {
_log.debug("Storage port {} is not selected because it is inactive, is not compatible, " + "is not visible, has no network assignment, " + "is not registered, has a status other than OK, or is not a frontend port", sp.getLabel());
notRegisteredOrOk.add(portName(sp));
continue;
}
if (sp.getNetwork().equals(networkURI) || (networkLite != null && networkLite.hasRoutedNetworks(sp.getNetwork()))) {
// Now make sure the port has connectivity/assignment
// to the passed virtual array.
StringSet spVArrayIds = sp.getTaggedVirtualArrays();
if (spVArrayIds != null && spVArrayIds.contains(varrayURI.toString())) {
if (sp.getNetwork().equals(networkURI)) {
spList.add(sp);
unroutedPorts.add(portName(sp));
} else {
_log.debug("Storage port {} is not in the requested network {} " + "but it is routed to it.", sp.getNativeGuid(), networkURI);
rspList.add(sp);
// Duplicate list with just name for better error message.
routedPorts.add(portName(sp));
}
} else {
_log.debug("Storage port {} not selected because it is not connected " + "or assigned to requested virtual array {}", sp.getNativeGuid(), varrayURI);
notInVarray.add(portName(sp));
}
} else {
_log.debug("Storage port {} not selected because its network {} " + "is not the requested network {}", new Object[] { sp.getNativeGuid(), sp.getNetwork(), networkURI });
wrongNetwork.add(portName(sp));
}
}
if (!notRegisteredOrOk.isEmpty()) {
_log.info("Ports not selected because they are inactive, have no network assignment, " + "are not registered, bad operational status, or not type front-end: " + Joiner.on(" ").join(notRegisteredOrOk));
}
if (!notInVarray.isEmpty()) {
_log.info("Ports not selected because they are not assigned to the requested virtual array: " + varrayURI + " " + Joiner.on(" ").join(notInVarray));
}
if (!wrongNetwork.isEmpty()) {
_log.info("Ports not selected because they are not in the requested network: " + networkURI + " " + Joiner.on(" ").join(wrongNetwork));
}
if (!rspList.isEmpty() && !spList.isEmpty()) {
_log.info("Ports not selected because they are routed and local ports are available: " + networkURI + " " + Joiner.on(" ").join(routedPorts));
}
_log.info("Ports that were selected: " + (spList.isEmpty() ? Joiner.on(" ").join(routedPorts) : Joiner.on(" ").join(unroutedPorts)));
return spList.isEmpty() ? rspList : spList;
}
Aggregations