use of com.emc.storageos.vplex.api.VPlexPortInfo in project coprhd-controller by CoprHD.
the class VPlexCommunicationInterface method discoverPorts.
/**
* Discovers and creates the ports for the passed VPlex virtual storage
* system.
*
* @param client The VPlex API client.
* @param vplexStorageSystem A reference to the VPlex storage system.
* @param autoUpgradePortsMap a map of port wwns to StoragePorts from the
* original cluster in a local to metro auto upgrade situation
*
* @throws VPlexCollectionException When an error occurs discovering the
* VPlex ports.
*/
private void discoverPorts(VPlexApiClient client, StorageSystem vplexStorageSystem, List<StoragePort> allPorts, Map<String, StoragePort> autoUpgradePortsMap) throws VPlexCollectionException {
List<StoragePort> newStoragePorts = new ArrayList<StoragePort>();
List<StoragePort> existingStoragePorts = new ArrayList<StoragePort>();
List<Initiator> newInitiatorPorts = new ArrayList<Initiator>();
try {
// Get the port information from the VPlex.
String initiatorHostName = null;
List<VPlexPortInfo> portInfoList = client.getPortInfo(false);
Map<String, VPlexTargetInfo> portTargetMap = client.getTargetInfoForPorts(portInfoList);
for (VPlexPortInfo portInfo : portInfoList) {
s_logger.debug("VPlex port info: {}", portInfo.toString());
if (null == portInfo.getPortWwn()) {
s_logger.info("Not a FC port, skipping port {}", portInfo.getName());
continue;
}
// StoragePort instances for these ports.
if ((!portInfo.isFrontendPort()) && (!portInfo.isBackendPort())) {
s_logger.debug("Not a front/back-end port, skipping port {}", portInfo.getName());
continue;
}
String portWWN = WWNUtility.getWWNWithColons(portInfo.getPortWwn());
String portType = portInfo.isBackendPort() ? PortType.backend.name() : PortType.frontend.name();
s_logger.info("Found {} port {}", portType, portWWN);
// WWN.
if ((portWWN == null) || (portWWN.equals(OFFLINE_PORT_WWN))) {
s_logger.info("Skipping port {} with WWN {}", portInfo.getName(), portWWN);
continue;
}
// See if the port already exists in the DB. If not we need to
// create it.
StoragePort storagePort = findPortInDB(vplexStorageSystem, portInfo, autoUpgradePortsMap);
if (storagePort == null) {
s_logger.info("Creating new port {}", portWWN);
storagePort = new StoragePort();
storagePort.setId(URIUtil.createId(StoragePort.class));
storagePort.setPortNetworkId(portWWN);
storagePort.setPortName(portInfo.getName());
storagePort.setStorageDevice(vplexStorageSystem.getId());
String nativeGuid = NativeGUIDGenerator.generateNativeGuid(_dbClient, storagePort);
storagePort.setNativeGuid(nativeGuid);
storagePort.setLabel(nativeGuid);
storagePort.setPortType(portType);
// Always FC
storagePort.setTransportType(StorageProtocol.Block.FC.name());
setHADomainForStoragePort(vplexStorageSystem, storagePort, portInfo);
storagePort.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
newStoragePorts.add(storagePort);
} else {
existingStoragePorts.add(storagePort);
}
// CTRL-4701 - if we got to this point, the VPLEX firmware was validated as compatible,
// so, the storage port should be marked compatible as well
storagePort.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name());
storagePort.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
// Port speed is current port speed and should be updated
// for existing ports.
storagePort.setPortSpeed(portInfo.getCurrentSpeed(SpeedUnits.GBITS_PER_SECOND));
// Set or update the port operational status.
storagePort.setOperationalStatus(getPortOperationalStatus(portInfo, portTargetMap));
// list.
if (portInfo.isBackendPort()) {
Initiator initiatorPort = findInitiatorInDB(portInfo);
if (initiatorPort == null) {
s_logger.info("Creating initiator for backend port", portWWN);
if (initiatorHostName == null) {
initiatorHostName = getInitiatorHostName(vplexStorageSystem);
}
s_logger.info("Host name is {}", initiatorHostName);
initiatorPort = new Initiator(StorageProtocol.Block.FC.name(), portWWN, WWNUtility.getWWNWithColons(portInfo.getNodeWwn()), initiatorHostName, false);
initiatorPort.setId(URIUtil.createId(Initiator.class));
newInitiatorPorts.add(initiatorPort);
}
}
}
// Persist changes to new and exiting ports and initiators.
_dbClient.createObject(newStoragePorts);
_dbClient.updateObject(existingStoragePorts);
_dbClient.createObject(newInitiatorPorts);
allPorts.addAll(newStoragePorts);
allPorts.addAll(existingStoragePorts);
List<StoragePort> notVisiblePorts = DiscoveryUtils.checkStoragePortsNotVisible(allPorts, _dbClient, vplexStorageSystem.getId());
if (notVisiblePorts != null && !notVisiblePorts.isEmpty()) {
allPorts.addAll(notVisiblePorts);
}
} catch (Exception e) {
s_logger.error("Error discovering ports for the VPLEX storage system {}:", vplexStorageSystem.getIpAddress(), e);
throw VPlexCollectionException.exceptions.failedPortsDiscovery(vplexStorageSystem.getId().toString(), e.getLocalizedMessage(), e);
}
}
Aggregations