use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class VirtualArrayService method getComputeSystems.
/**
* Fetches all Compute Systems that are visible in the vArray
*
* First determine physical connectivity to any switches in the vArrray.
* 1. From the vArray, determine the networks. (Call this Network Set)
* 2. From the networks, get the physical switches that are attached.
* 3. For each physical switch, iterate through the networks and get the FC endpoints.
* 4. Look for any of the FIC ports in any of the FC endpoints on any of the
* networks on the physical switch. When a FIC port matches, call this FIC
* Port.
* 5. If found, then there is physical connectivity.
*
* With physical connectivity Established:
* 1. Given the FIC Port from step (4), pull the VSAN or VSANs assigned to
* it on UCS.
* 2. If the set contains one of the networks from the Network
* Set in (1), we have connectivity to that vArray.
*
* @param id
* the URN of a ViPR VirtualArray.
* @brief List all Compute Systems that are visible in the vArray
* @return List of Compute Systems
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/compute-systems")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR }, acls = { ACL.USE })
public ComputeSystemBulkRep getComputeSystems(@PathParam("id") URI id) {
_log.info("get connected CS for vArray: {}", id);
// Get and validate the varray with the passed id.
ArgValidator.checkFieldUriType(id, VirtualArray.class, "id");
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, id);
ArgValidator.checkEntityNotNull(varray, id, isIdEmbeddedInURL(id));
BulkIdParam matchingCsIds = new BulkIdParam();
// get varray networks
List<Network> networks = CustomQueryUtility.queryActiveResourcesByRelation(_dbClient, id, Network.class, "connectedVirtualArrays");
// collect network vsanIds and switch ids
Set<String> networkVsanIds = new HashSet<>();
Set<String> nsIds = new HashSet<>();
for (Network network : networks) {
if (StorageProtocol.Transport.FC.name().equalsIgnoreCase(network.getTransportType()) && DiscoveredSystemObject.RegistrationStatus.REGISTERED.name().equals(network.getRegistrationStatus())) {
networkVsanIds.add(network.getNativeId());
if (network.getNetworkSystems() != null) {
nsIds.addAll(network.getNetworkSystems());
}
}
}
_log.info("vArray has these networks: {}", networkVsanIds);
// use only registered network systems
Set<URI> nsUris = new HashSet<>();
for (String nsUri : nsIds) {
nsUris.add(URI.create(nsUri));
}
List<NetworkSystem> nsList = _dbClient.queryObject(NetworkSystem.class, nsUris);
for (NetworkSystem ns : nsList) {
if (!DiscoveredSystemObject.RegistrationStatus.REGISTERED.name().equals(ns.getRegistrationStatus())) {
nsIds.remove(ns.getId().toString());
}
}
_log.info("the networks run on these network systems: {}", nsIds);
if (networkVsanIds.isEmpty() || nsIds.isEmpty()) {
// no networks in the array - exit early
return new ComputeSystemBulkRep();
}
// for every switch get FCEndpoint.remotePortName(s)
Set<String> connectedEndpoints = new HashSet<String>();
for (String nsId : nsIds) {
URIQueryResultList uriList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getNetworkSystemFCPortConnectionConstraint(URI.create(nsId)), uriList);
List<URI> epIds = new ArrayList<URI>();
Iterator<URI> iter = uriList.iterator();
while (iter.hasNext()) {
epIds.add(iter.next());
}
List<FCEndpoint> eps = _dbClient.queryObjectField(FCEndpoint.class, "remotePortName", epIds);
for (FCEndpoint ep : eps) {
connectedEndpoints.add(ep.getRemotePortName());
}
}
_log.debug("all connected endpoints: {}", connectedEndpoints);
// get all CS
List<URI> csIds = _dbClient.queryByType(ComputeSystem.class, true);
List<ComputeSystem> csList = _dbClient.queryObject(ComputeSystem.class, csIds);
for (ComputeSystem cs : csList) {
if (!DiscoveredSystemObject.RegistrationStatus.REGISTERED.name().equals(cs.getRegistrationStatus())) {
// skip not registered CS
continue;
}
boolean connected = false;
_log.info("evaluating uplinks of cs: {}", cs.getLabel());
// loop thru UplinkPorts to find matches
URIQueryResultList uris = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeFabricUplinkPortConstraint(cs.getId()), uris);
List<ComputeFabricUplinkPort> uplinkPorts = _dbClient.queryObject(ComputeFabricUplinkPort.class, uris, true);
for (ComputeFabricUplinkPort port : uplinkPorts) {
if (connectedEndpoints.contains(port.getWwpn())) {
_log.info("found matching endpoint: {}", port.getWwpn());
if (!Collections.disjoint(port.getVsans(), networkVsanIds)) {
_log.info("and networks overlap: {}", port.getVsans());
matchingCsIds.getIds().add(cs.getId());
connected = true;
break;
}
}
}
if (connected) {
// skip uplink port channel matching as we are already connected
continue;
}
// now loop thru UplinkPortChannels to find matches
uris = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeUplinkPortChannelConstraint(cs.getId()), uris);
List<ComputeFabricUplinkPortChannel> uplinkPortChannels = _dbClient.queryObject(ComputeFabricUplinkPortChannel.class, uris, true);
for (ComputeFabricUplinkPortChannel port : uplinkPortChannels) {
if (connectedEndpoints.contains(port.getWwpn())) {
_log.info("found matching endpoint: {}", port.getWwpn());
if (!Collections.disjoint(port.getVsans(), networkVsanIds)) {
_log.info("and networks overlap: {}", port.getVsans());
matchingCsIds.getIds().add(cs.getId());
connected = true;
break;
}
}
}
}
_log.info("these CS are connected to the vArray: {}", matchingCsIds.getIds());
if (matchingCsIds.getIds().isEmpty()) {
return new ComputeSystemBulkRep();
}
ComputeSystemBulkRep computeSystemReps = computeSystemService.getBulkResources(matchingCsIds);
return mapValidServiceProfileTemplatesToComputeSystem(computeSystemReps, varray.getId());
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class RPCommunicationInterface method getRPArrayMappings.
/**
* For an RP configuration, determine the arrays that each site can see.
*
* @param system RP system
* @return command result object, object list [0] has List<SiteArrays>
* @throws RecoverPointException
*/
public BiosCommandResult getRPArrayMappings(ProtectionSystem system) throws RecoverPointException {
_log.info("getRPArrayMappings {} - start", system.getId());
RecoverPointClient rp = RPHelper.getRecoverPointClient(system);
Set<RPSite> sites = rp.getAssociatedRPSites();
// For determining which storage system to use with the RPA, we will look at the Network created as a result of
// a NetworkSystem (aka switch or Fabric Manager) discovery. We look at each NetworkSystem to check if the RPA WWN(aka RP Initiator)
// is in one of the
// Networks/VSANs and if we do find a match then we look at the arrays in that Network/VSAN and determine which one to use.
// For now, this code assumes there are Networks/VSANs created on the switch, might need to tweak this if there are no
// Networks/VSANs.
// One more important note : Networks/VSANs have be configured on the switch in order for zoning to work and NetworkSystem to
// discover.
// No Networks/VSANs on the switch means, none of this will work and zoning has to be done by the end-user prior to using StorageOS.
// Get all the NetworkSystems already in the system (if there are any NetworkSystems configured).
// Possible zoning candidates can be identified only if there is a NetworkSystem configured.
List<SiteArrays> rpSiteArrays = new ArrayList<SiteArrays>();
List<URI> networkSystemList = _dbClient.queryByType(NetworkSystem.class, true);
boolean isNetworkSystemConfigured = false;
if (networkSystemList.iterator().hasNext()) {
List<URI> allNetworks = _dbClient.queryByType(Network.class, true);
// Transfer to a reset-able list
List<URI> networks = new ArrayList<>();
for (URI networkURI : allNetworks) {
networks.add(networkURI);
}
for (RPSite site : sites) {
// Get the initiators for this site.
Map<String, Map<String, String>> rpaWWNs = rp.getInitiatorWWNs(site.getInternalSiteName());
SiteArrays siteArrays = new SiteArrays();
siteArrays.setArrays(new HashSet<String>());
siteArrays.setSite(site);
// Add an RP site -> initiators entry to the protection system
StringSet siteInitiators = new StringSet();
for (String rpaId : rpaWWNs.keySet()) {
siteInitiators.addAll(rpaWWNs.get(rpaId).keySet());
}
system.putSiteIntitiatorsEntry(site.getInternalSiteName(), siteInitiators);
// trying to find a valid Storage Port (of which they will not return a result).
for (String rpaId : rpaWWNs.keySet()) {
_log.info(String.format("Discovering RPA %s initiators for RPA Cluster %s(%s)...", rpaId, site.getSiteName(), site.getInternalSiteName()));
boolean foundNetworkForRPA = false;
for (Map.Entry<String, String> rpaWWN : rpaWWNs.get(rpaId).entrySet()) {
Initiator initiator = new Initiator();
initiator.addInternalFlags(Flag.RECOVERPOINT);
// Remove all non alpha-numeric characters, excluding "_", from the hostname
String rpClusterName = site.getSiteName().replaceAll(NON_ALPHA_NUMERICS, "");
initiator.setClusterName(rpClusterName);
initiator.setProtocol("FC");
initiator.setIsManualCreation(false);
// Group RP initiators by their RPA. This will ensure that separate IGs are created for each RPA
// A child RP IG will be created containing all the RPA IGs
String hostName = rpClusterName + RPA + rpaId;
hostName = hostName.replaceAll(NON_ALPHA_NUMERICS, "");
initiator.setHostName(hostName);
initiator.setInitiatorPort(rpaWWN.getKey());
initiator.setInitiatorNode(rpaWWN.getValue());
// Either get the existing initiator or create a new if needed
initiator = getOrCreateNewInitiator(initiator);
_log.info(String.format("RPA Initiator %s detected: [port: %s, node: %s, host: %s, cluster: %s]", initiator.getInitiatorPort(), initiator.getInitiatorPort(), initiator.getInitiatorNode(), initiator.getHostName(), initiator.getClusterName()));
// Find the network associated with this initiator
for (URI networkURI : networks) {
Network network = _dbClient.queryObject(Network.class, networkURI);
StringMap discoveredEndpoints = network.getEndpointsMap();
if (discoveredEndpoints.containsKey(initiator.getInitiatorPort().toUpperCase())) {
_log.info(String.format("RPA Initiator %s is associated to Network %s.", initiator.getInitiatorPort().toUpperCase(), network.getLabel()));
// Set this to true as we found the RP initiators in a Network on the Network system
isNetworkSystemConfigured = true;
foundNetworkForRPA = true;
for (String discoveredEndpoint : discoveredEndpoints.keySet()) {
// in that NetworkVSAN.
if (discoveredEndpoint.startsWith(RP_INITIATOR_PREFIX)) {
continue;
}
// Add the found endpoints to the list
siteArrays.getArrays().add(discoveredEndpoint);
}
}
}
}
if (!foundNetworkForRPA) {
// This is not an error to the end-user. When they add a network system, everything will rediscover correctly.
_log.warn(String.format("RPA %s initiators for RPA Cluster %s(%s) are not seen in any configured network.", rpaId, site.getSiteName(), site.getInternalSiteName()));
}
}
// add to the list
rpSiteArrays.add(siteArrays);
}
}
// If its a non RP4.0 system, then query the normal way and find out the targets/arrays from the RPAs.
if (!rp.getAssociatedRPSites().isEmpty()) {
_log.info("site1 version: " + rp.getAssociatedRPSites().iterator().next().getSiteVersion());
}
if (!isNetworkSystemConfigured) {
// This is not an error to the end-user. When they add a network system, everything will rediscover correctly.
_log.warn("Network systems are required when configuring RecoverPoint.");
}
_log.info("getRPArrayMappings {} - complete", system.getId());
BiosCommandResult result = new BiosCommandResult();
result.setCommandSuccess(true);
result.setCommandStatus(Operation.Status.ready.name());
List<Object> returnList = new ArrayList<Object>();
returnList.add(rpSiteArrays);
result.setObjectList(returnList);
return result;
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class ComputeSystemService method isServiceProfileTemplateValidForVarrays.
/*
* Check whether the SPT's vsans are in atleast one of the varrays' networks. If yes, valid.
*/
public boolean isServiceProfileTemplateValidForVarrays(StringSet varrayIds, URI sptId) {
boolean isValid = true;
UCSServiceProfileTemplate template = (UCSServiceProfileTemplate) _dbClient.queryObject(sptId);
Set<String> networkVsanIds = new HashSet<String>();
URIQueryResultList uriVhbas = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getServiceProfileTemplateComputeElemetHBAsConstraint(sptId), uriVhbas);
List<ComputeElementHBA> vhbas = _dbClient.queryObject(ComputeElementHBA.class, uriVhbas, true);
// Filter out SPTs without any vhbas
if ((vhbas == null) || vhbas.isEmpty()) {
isValid = false;
_log.info("ServiceProfileTemplate " + template.getLabel() + " does not have any vhbas and hence is not valid for use.");
return isValid;
}
for (String varrayId : varrayIds) {
// get varray networks
List<Network> networks = CustomQueryUtility.queryActiveResourcesByRelation(_dbClient, URI.create(varrayId), Network.class, "connectedVirtualArrays");
// collect network vsanIds
Set<String> varrayNetworkVsanIds = new HashSet<String>();
for (Network network : networks) {
if (StorageProtocol.Transport.FC.name().equalsIgnoreCase(network.getTransportType())) {
varrayNetworkVsanIds.add(network.getNativeId());
// _log.debug("varray vsan :"+ network.getNativeId());
}
}
if (networkVsanIds.isEmpty()) {
networkVsanIds.addAll(varrayNetworkVsanIds);
} else {
networkVsanIds.retainAll(varrayNetworkVsanIds);
}
for (ComputeElementHBA vhba : vhbas) {
String vsanId = vhba.getVsanId();
_log.debug("vhba vsan:" + vsanId);
if (!networkVsanIds.contains(vsanId)) {
isValid = false;
_log.error("SPT " + template.getLabel() + " has hba on vsan " + vsanId + " not included in varray " + varrayId);
return isValid;
}
}
}
if (template.getUpdating()) {
isValid = isUpdatingSPTValidForVarrays(varrayIds, template);
}
return isValid;
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class ComputeSystemService method isSanBootTargetValidForVarrays.
private boolean isSanBootTargetValidForVarrays(StringSet varrayIds, StringSet portWWPNs) {
_log.debug("validate San Boot targets for varrays");
boolean isValid = true;
for (String varrayId : varrayIds) {
List<URI> validStorageSystems = new ArrayList<URI>();
Map<URI, List<URI>> storageSystemToPortMap = new HashMap<URI, List<URI>>();
List<URI> vsanURIs = new ArrayList<URI>();
URIQueryResultList storagePortURIs = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVirtualArrayStoragePortsConstraint(varrayId.toString()), storagePortURIs);
Map<URI, List<StoragePort>> vsanToPortMap = new HashMap<URI, List<StoragePort>>();
for (URI uri : storagePortURIs) {
StoragePort storagePort = _dbClient.queryObject(StoragePort.class, uri);
URI storageSystemURI = storagePort.getStorageDevice();
List<URI> portList = storageSystemToPortMap.get(storageSystemURI);
if (portList == null) {
portList = new ArrayList<URI>();
}
portList.add(storagePort.getId());
storageSystemToPortMap.put(storageSystemURI, portList);
URI networkURI = storagePort.getNetwork();
List<StoragePort> vsanPorts = vsanToPortMap.get(networkURI);
if (vsanPorts == null) {
vsanPorts = new ArrayList<StoragePort>();
}
vsanPorts.add(storagePort);
vsanToPortMap.put(networkURI, vsanPorts);
if (portWWPNs.contains(storagePort.getPortNetworkId())) {
validStorageSystems.add(storageSystemURI);
vsanURIs.add(networkURI);
}
}
if (validStorageSystems.isEmpty()) {
_log.error("San boot target wwpns do not belong to any storage systems associated to the varray: " + varrayId);
isValid = false;
return isValid;
}
for (URI vsanURI : vsanURIs) {
List<StoragePort> connectedPorts = vsanToPortMap.get(vsanURI);
Network currentVsan = _dbClient.queryObject(Network.class, vsanURI);
for (StoragePort port : connectedPorts) {
if (!portWWPNs.contains(port.getPortNetworkId())) {
_log.error("Virtual array " + varrayId + " has ports other than those in the template connected to vsan:" + currentVsan.getLabel());
isValid = false;
return isValid;
}
}
}
URIQueryResultList storagePoolURIs = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVirtualArrayStoragePoolsConstraint(varrayId.toString()), storagePoolURIs);
Map<URI, List<URI>> storageSystemToPoolMap = new HashMap<URI, List<URI>>();
for (URI uri : storagePoolURIs) {
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, uri);
if ((storagePool != null) && (CompatibilityStatus.COMPATIBLE.toString().equals(storagePool.getCompatibilityStatus())) && (RegistrationStatus.REGISTERED.toString().equals(storagePool.getRegistrationStatus())) && DiscoveryStatus.VISIBLE.toString().equals(storagePool.getDiscoveryStatus())) {
URI storageSystemURI = storagePool.getStorageDevice();
List<URI> storagePoolList = storageSystemToPoolMap.get(storageSystemURI);
if (storagePoolList == null) {
storagePoolList = new ArrayList<URI>();
}
storagePoolList.add(storagePool.getId());
storageSystemToPoolMap.put(storageSystemURI, storagePoolList);
}
}
for (URI uri : storageSystemToPoolMap.keySet()) {
if (!validStorageSystems.contains(uri)) {
_log.error("virtual array " + varrayId + " has storage pools from storage systems other than the storage system whose ports are in the SPT's san boot target");
isValid = false;
return isValid;
}
}
}
return isValid;
}
use of com.emc.storageos.db.client.model.Network in project coprhd-controller by CoprHD.
the class NetworkUtil method checkNotUsedByActiveFileExport.
/**
* If any endpoint is used in an active File Export, throws an exception
*
* @param endpoints endpoints being added
* @param varrays endpoints belong to
*
* Assumes endpoint formats have been validated.
*/
public static void checkNotUsedByActiveFileExport(String endpoint, DbClient dbClient) {
Network network = NetworkUtil.getEndpointNetwork(endpoint, dbClient);
if (network != null) {
Set<String> netVArrayIds = network.getConnectedVirtualArrays();
if ((netVArrayIds != null) && (!netVArrayIds.isEmpty())) {
Iterator<String> netVArrayIdsIter = netVArrayIds.iterator();
while (netVArrayIdsIter.hasNext()) {
String varrayId = netVArrayIdsIter.next();
List<FileShare> fileShares = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, FileShare.class, AlternateIdConstraint.Factory.getConstraint(FileShare.class, "varray", varrayId));
for (FileShare fileShare : fileShares) {
FSExportMap fsExports = fileShare.getFsExports();
if (fsExports != null) {
Iterator<FileExport> it = fsExports.values().iterator();
while (it.hasNext()) {
FileExport fileExport = it.next();
if (fileExport.getClients().contains(endpoint) || fileExport.getStoragePort().contains(endpoint)) {
throw APIException.badRequests.endpointsCannotBeUpdatedActiveExport(endpoint);
}
}
}
}
}
}
}
}
Aggregations