Search in sources :

Example 1 with ZoneInfoMap

use of com.emc.storageos.db.client.model.ZoneInfoMap in project coprhd-controller by CoprHD.

the class NetworkDeviceController method refreshZoningMap.

/**
 * Update the zoning map for as export mask previously "accepted". This applies to
 * brown field scenarios where a export mask was found on the storage array. For
 * those export masks, changes outside of the application are expected and the
 * application should get the latest state before making any changes. This
 * function is called from ExportMaskOperations#refreshZoneMap after all
 * updates to the initiators, ports and volumes were made into the export mask and
 * the export group. The update steps are as follow:
 * <ol>
 * <li>Get the current zones for those initiators that were not added by ViPR and the storage ports that exist in the mask.</li>
 * <li>Diff the current zones with those in the export mask and update the zoning map</li>
 * <li>Update the FCZoneReferences to match the zone updates</li>
 * </ol>
 * Note that ViPR does not keep FCZoneReferences only for volumes created by ViPR. As those
 * volumes are not updated by ExportMaskOperations#refreshZoneMap, no additional code
 * is needed to remove FCZoneReferences for removed volumes.
 *
 * @param exportMask the export mask being updated.
 * @param removedInitiators the list of initiators that were removed. This is needed because
 *            these were removed from the zoingMap by {@link ExportMask#removeInitiators(Collection)}
 * @param removedPorts the set of storage ports that were removed
 * @param maskUpdated a flag that indicates if an update was made to the mask that requires
 *            a zoning refresh
 * @param persist a boolean that indicates if the changes should be persisted in the db
 */
public void refreshZoningMap(ExportMask exportMask, Collection<String> removedInitiators, Collection<String> removedPorts, boolean maskUpdated, boolean persist) {
    try {
        // check if zoning is enabled for the mask
        if (!zoningEnabled(exportMask)) {
            _log.info("Zoning not enabled for export mask {}. Zoning refresh will not be done", exportMask.getMaskName());
            return;
        }
        if (!(maskUpdated || alwaysRefreshZone())) {
            _log.info("The mask ports and initiators were not modified and alwaysRefreshZones is false" + " Zoning refresh will not be done for mask {}", exportMask.getMaskName());
            return;
        }
        List<Initiator> initiators = ExportUtils.getExportMaskInitiators(exportMask, _dbClient);
        _log.info("Refreshing zones for export mask {}. \n\tCurrent initiators " + "in this mask are:  {}. \n\tStorage ports in the mask are : {}. \n\tZoningMap is : {}. " + "\n\tRemoved initiators: {}. \n\tRemoved ports: {}", new Object[] { exportMask.getMaskName(), exportMask.getInitiators(), exportMask.getStoragePorts(), exportMask.getZoningMap(), removedInitiators, removedPorts });
        Long start = System.currentTimeMillis();
        // get the current zones in the network system for initiators and ports
        List<StoragePort> storagePorts = ExportUtils.getStoragePorts(exportMask, _dbClient);
        ZoneInfoMap zoneInfoMap = getInitiatorsZoneInfoMap(initiators, storagePorts);
        // Get the full sets of initiators and ports affected. They will be used to find the FCZoneReferences to refresh
        // These sets include new initiators and ports, existing ones that did not change, as well as removed ones
        List<StoragePort> allStoragePorts = DataObjectUtils.iteratorToList(_dbClient.queryIterativeObjects(StoragePort.class, StringSetUtil.stringSetToUriList(removedPorts)));
        allStoragePorts.addAll(storagePorts);
        List<Initiator> allInitiators = DataObjectUtils.iteratorToList(_dbClient.queryIterativeObjects(Initiator.class, StringSetUtil.stringSetToUriList(removedInitiators)));
        allInitiators.addAll(initiators);
        // Make a copy of the zoning mask - Zones have already been removed for removed initiators, put them back
        // This zoning map will be used to do diff between old and new and to get zone references
        StringSetMap allZonesMap = new StringSetMap();
        StringSetMap tempMap = exportMask.getZoningMap() == null ? new StringSetMap() : exportMask.getZoningMap();
        for (String key : tempMap.keySet()) {
            // when the zoning map is removed prematurely, this ports set is empty but not null
            if (removedInitiators.contains(key) && (tempMap.get(key) == null || tempMap.get(key).isEmpty())) {
                // this was prematurely cleared, we will assume all ports
                // were zoned to make sure we clean up all FCZoneReferences
                allZonesMap.put(key, new StringSet(removedPorts));
                if (exportMask.getStoragePorts() != null) {
                    allZonesMap.get(key).addAll(exportMask.getStoragePorts());
                }
            } else {
                allZonesMap.put(key, new StringSet(tempMap.get(key)));
            }
        }
        // get all the zone references that exist in the database for this export mask.
        Map<String, List<FCZoneReference>> existingRefs = getZoneReferences(allZonesMap, allInitiators, allStoragePorts);
        // initialize results collections
        List<ZoneInfo> addedZoneInfos = new ArrayList<ZoneInfo>();
        List<ZoneInfo> updatedZoneInfos = new ArrayList<ZoneInfo>();
        List<String> removedZonesKeys = new ArrayList<String>();
        // Compare old and new zones. Initialize some loop variables.
        ZoneInfo zoneInfo = null;
        String initId = null;
        String portId = null;
        if (exportMask.getZoningMap() == null) {
            exportMask.setZoningMap(new StringSetMap());
        }
        for (Entry<String, ZoneInfo> entry : zoneInfoMap.entrySet()) {
            zoneInfo = entry.getValue();
            initId = zoneInfo.getInitiatorId();
            portId = zoneInfo.getPortId();
            if (exportMask.getZoningMap().containsKey(initId) && exportMask.getZoningMap().get(initId).contains(portId)) {
                _log.debug("Zoning between initiator {} and port {} did not change", zoneInfo.getInitiatorWwn(), zoneInfo.getPortWwn());
                // This is accounted for, let's remove it from our diff map
                allZonesMap.remove(initId, portId);
                // add the zone info so that it can be updated for changes like zone name change
                updatedZoneInfos.add(zoneInfo);
            } else {
                _log.info("New zone was found between initiator {} and port {} and will be added", zoneInfo.getInitiatorWwn(), zoneInfo.getPortWwn());
                // sometimes zones have more than one initiator or port
                if (exportMask.hasExistingInitiator(zoneInfo.getInitiatorWwn())) {
                    // This is a new entry, add it to the zoning map
                    exportMask.getZoningMap().put(initId, portId);
                    // add it to the results so that the appropriate FCZoneReferences are added
                    addedZoneInfos.add(zoneInfo);
                }
                // This zone is not expected to be in the diff map, but try anyway
                allZonesMap.remove(initId, portId);
            }
        }
        // If anything is remaining zones in the diff zoning map, these were removed in the network system
        Initiator initiator = null;
        StoragePort port = null;
        for (String key : allZonesMap.keySet()) {
            initiator = DataObjectUtils.findInCollection(allInitiators, key);
            if (allZonesMap.get(key) != null && !allZonesMap.get(key).isEmpty()) {
                for (String val : allZonesMap.get(key)) {
                    port = DataObjectUtils.findInCollection(allStoragePorts, val);
                    _log.info("Zone between initiator {} and port {} was removed from the network system" + " or no longer belongs to this mask.", key, val);
                    if (port == null || initiator == null) {
                        // the port or initiator were removed at some point
                        exportMask.getZoningMap().remove(key, val);
                        _log.info("Removed zoningMap entry between initiator {} and port {} because " + "the port and/or the initiator were removed from the mask", key, val);
                    } else if (removedInitiators.contains(key) || removedPorts.contains(val)) {
                        // the port or initiator were removed, remove the zone map entry
                        exportMask.getZoningMap().remove(key, val);
                        _log.info("Removed zoningMap entry between initiator {} and port {} because " + "the port and/or the initiator were removed from the mask", initiator.getInitiatorPort(), port.getPortNetworkId());
                    } else if (exportMask.hasExistingInitiator(WWNUtility.getUpperWWNWithNoColons(initiator.getInitiatorPort()))) {
                        exportMask.getZoningMap().remove(key, val);
                        _log.info("Removed zoningMap entry between initiator {} and port {} because " + "this was a brownfield zone for a brownfield initiator", initiator.getInitiatorPort(), port.getPortNetworkId());
                    } else {
                        _log.info("The zone between initiator {} and port {} was removed from " + " the network system but the zoningMap entry will be kept because it was" + " a ViPR initiator-port assignment", initiator.getInitiatorPort(), port.getPortNetworkId());
                    }
                    if (port != null && initiator != null) {
                        removedZonesKeys.add(FCZoneReference.makeEndpointsKey(initiator.getInitiatorPort(), port.getPortNetworkId()));
                    }
                }
            }
        }
        // get all the existing zone references from the database, these are
        refreshFCZoneReferences(exportMask, existingRefs, addedZoneInfos, updatedZoneInfos, removedZonesKeys);
        if (persist) {
            _dbClient.updateAndReindexObject(exportMask);
        }
        _log.info("Changed zones for export mask {} to {}. \nRefreshing zones took {} ms", new Object[] { exportMask.getMaskName(), exportMask.getZoningMap(), (System.currentTimeMillis() - start) });
    } catch (Exception ex) {
        _log.error("An exception occurred while updating zoning map for export mask {} with message {}", new Object[] { exportMask.getMaskName(), ex.getMessage() }, ex);
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) ZoneInfoMap(com.emc.storageos.db.client.model.ZoneInfoMap) ArrayList(java.util.ArrayList) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) ZoneInfo(com.emc.storageos.db.client.model.ZoneInfo)

Example 2 with ZoneInfoMap

use of com.emc.storageos.db.client.model.ZoneInfoMap in project coprhd-controller by CoprHD.

the class ExternalDeviceUnManagedVolumeDiscoverer method updateZoningMap.

/**
 * Updates zoning information in the unmanaged export mask for a given set of initiators and storage ports.
 *
 * @param mask unmanaged export [IN/OUT]
 * @param initiators initiators for zone map [IN]
 * @param storagePorts storage ports for zone map [IN]
 */
private void updateZoningMap(UnManagedExportMask mask, List<com.emc.storageos.db.client.model.Initiator> initiators, List<com.emc.storageos.db.client.model.StoragePort> storagePorts) {
    ZoneInfoMap zoningMap = networkDeviceController.getInitiatorsZoneInfoMap(initiators, storagePorts);
    for (ZoneInfo zoneInfo : zoningMap.values()) {
        log.info("Found zone: {} for initiator {} and port {}", zoneInfo.getZoneName(), zoneInfo.getInitiatorWwn(), zoneInfo.getPortWwn());
    }
    mask.setZoningMap(zoningMap);
}
Also used : ZoneInfoMap(com.emc.storageos.db.client.model.ZoneInfoMap) ZoneInfo(com.emc.storageos.db.client.model.ZoneInfo)

Example 3 with ZoneInfoMap

use of com.emc.storageos.db.client.model.ZoneInfoMap in project coprhd-controller by CoprHD.

the class PortMetricsProcessor method updateUnmanagedVolumeAndInitiatorCounts.

/**
 * Updates the volumes and initiators that are mapped to the port by UnManagedExportMasks.
 * Note that if there is also a corresponding (managed) ExportMask the unmanaged information is not used.
 * (COP-16349).
 * This is called only from the processing of the port metrics.
 *
 * @param sp -- StoragePort
 * @param countMetaMembers -- count meta members instead of volumes
 * @param dbMetrics -- the MetricsKeys values from the database record to be updated
 */
private void updateUnmanagedVolumeAndInitiatorCounts(StoragePort sp, boolean countMetaMembers, StringMap dbMetrics) {
    Long volumeCount = 0L;
    Long initiatorCount = 0L;
    // Find all the Export Masks containing the port.
    URIQueryResultList queryResult = new URIQueryResultList();
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getUnManagedMaskByPort(sp.getId().toString()), queryResult);
    Iterator<URI> maskIt = queryResult.iterator();
    while (maskIt.hasNext()) {
        UnManagedExportMask umask = _dbClient.queryObject(UnManagedExportMask.class, maskIt.next());
        if (umask != null && umask.getInactive() == false && !checkForMatchingExportMask(umask.getMaskName(), umask.getNativeId(), umask.getStorageSystemUri())) {
            StringSet unmanagedVolumeUris = umask.getUnmanagedVolumeUris();
            Long unmanagedVolumes = (unmanagedVolumeUris != null ? unmanagedVolumeUris.size() : 0L);
            if (countMetaMembers && unmanagedVolumeUris != null) {
                unmanagedVolumes = 0L;
                // For VMAX2, count the meta-members instead of the volumes.
                for (String unmanagedVolumeUri : unmanagedVolumeUris) {
                    UnManagedVolume uVolume = _dbClient.queryObject(UnManagedVolume.class, URI.create(unmanagedVolumeUri));
                    Long metaMemberCount = getUnManagedVolumeMetaMemberCount(uVolume);
                    unmanagedVolumes += (metaMemberCount != null ? metaMemberCount : 1L);
                }
            }
            // Determine initiator count from zoning map in unmanaged export mask.
            // If the zoningInfoMap is empty, assume one initiator.
            Long unmanagedInitiators = 0L;
            ZoneInfoMap zoneInfoMap = umask.getZoningMap();
            if (!zoneInfoMap.isEmpty()) {
                for (ZoneInfo info : zoneInfoMap.values()) {
                    if (info.getPortWwn().equals(sp.getPortNetworkId())) {
                        unmanagedInitiators += 1L;
                    }
                }
            } else {
                // Assume one initiator for the unmanaged mask
                unmanagedInitiators += 1L;
            }
            _log.info(String.format("Port %s UnManagedExportMask %s " + "unmanagedVolumes %d unmanagedInitiators %d", sp.getPortName(), umask.getMaskName(), unmanagedVolumes, unmanagedInitiators));
            volumeCount += unmanagedVolumes;
            initiatorCount += unmanagedInitiators;
        }
    }
    MetricsKeys.putLong(MetricsKeys.unmanagedInitiatorCount, initiatorCount, dbMetrics);
    MetricsKeys.putLong(MetricsKeys.unmanagedVolumeCount, volumeCount, dbMetrics);
}
Also used : UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) StringSet(com.emc.storageos.db.client.model.StringSet) ZoneInfoMap(com.emc.storageos.db.client.model.ZoneInfoMap) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ZoneInfo(com.emc.storageos.db.client.model.ZoneInfo) UnManagedExportMask(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedExportMask)

Example 4 with ZoneInfoMap

use of com.emc.storageos.db.client.model.ZoneInfoMap in project coprhd-controller by CoprHD.

the class VNXUnityUnManagedObjectDiscoverer method updateZoningMap.

/**
 * Set mask zoning map
 *
 * @param mask
 * @param initiators
 * @param storagePorts
 */
private void updateZoningMap(UnManagedExportMask mask, List<Initiator> initiators, List<StoragePort> storagePorts) {
    ZoneInfoMap zoningMap = networkDeviceController.getInitiatorsZoneInfoMap(initiators, storagePorts);
    for (ZoneInfo zoneInfo : zoningMap.values()) {
        log.info("Found zone: {} for initiator {} and port {}", new Object[] { zoneInfo.getZoneName(), zoneInfo.getInitiatorWwn(), zoneInfo.getPortWwn() });
    }
    mask.setZoningMap(zoningMap);
}
Also used : ZoneInfoMap(com.emc.storageos.db.client.model.ZoneInfoMap) ZoneInfo(com.emc.storageos.db.client.model.ZoneInfo)

Example 5 with ZoneInfoMap

use of com.emc.storageos.db.client.model.ZoneInfoMap in project coprhd-controller by CoprHD.

the class XtremIOUnManagedVolumeDiscoverer method updateZoningMap.

private void updateZoningMap(UnManagedExportMask mask, List<Initiator> initiators, List<StoragePort> storagePorts) {
    ZoneInfoMap zoningMap = networkDeviceController.getInitiatorsZoneInfoMap(initiators, storagePorts);
    for (ZoneInfo zoneInfo : zoningMap.values()) {
        log.info("Found zone: {} for initiator {} and port {}", new Object[] { zoneInfo.getZoneName(), zoneInfo.getInitiatorWwn(), zoneInfo.getPortWwn() });
    }
    mask.setZoningMap(zoningMap);
}
Also used : ZoneInfoMap(com.emc.storageos.db.client.model.ZoneInfoMap) ZoneInfo(com.emc.storageos.db.client.model.ZoneInfo)

Aggregations

ZoneInfoMap (com.emc.storageos.db.client.model.ZoneInfoMap)9 ZoneInfo (com.emc.storageos.db.client.model.ZoneInfo)7 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)4 StoragePort (com.emc.storageos.db.client.model.StoragePort)3 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Initiator (com.emc.storageos.db.client.model.Initiator)2 StringMap (com.emc.storageos.db.client.model.StringMap)2 StringSet (com.emc.storageos.db.client.model.StringSet)2 NetworkFCZoneInfo (com.emc.storageos.networkcontroller.NetworkFCZoneInfo)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)1 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)1 UnManagedExportMask (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedExportMask)1 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)1 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)1