Search in sources :

Example 26 with FCZoneReference

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

the class NetworkDeviceController method findFCZoneReferenceForVolGroupKey.

/**
 * Looks in the database for a zone for the same volume and export group and key
 *
 * @param exportGroupURI -- the export group URI
 * @param volumeURI -- the volume URI
 * @param refKey -- the FCZoneReference key which is the concatenation of the initiator
 *            and storage port WWNs. Note that this key is formed by sorting the WWNs
 * @param newOrExisting - OUT param in String[0] puts "New" or "Existing" indicating
 *            whether a New FCZoneReference was persisted.
 * @return The zone reference instance if found, null otherwise
 */
private FCZoneReference findFCZoneReferenceForVolGroupKey(URI exportGroupURI, URI volumeURI, String refKey, String[] newOrExisting) {
    Map<String, FCZoneReference> volRefMap = _networkScheduler.makeExportToReferenceMap(refKey);
    String volExportKey = make2UriKey(volumeURI, exportGroupURI);
    if (volRefMap.containsKey(volExportKey)) {
        FCZoneReference ref = volRefMap.get(volExportKey);
        // If we have an active reference, don't make another
        if (ref != null && ref.getInactive() == false) {
            _log.info(String.format("Existing zone reference: vol %s group %s refkey %s", volumeURI, exportGroupURI, refKey));
            newOrExisting[0] = "Existing";
            return ref;
        }
    }
    return null;
}
Also used : FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 27 with FCZoneReference

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

the class NetworkDeviceController method createFCZoneReference.

/**
 * Creates an instance of FCZoneReference
 *
 * @param info the zone info containing the zone, its network,
 *            its network system, ...
 * @param initiator the zone initiator
 * @param volume volume the FCZoneReference volume
 * @param exportGroup the FCZoneReference export group
 * @return an instance of FCZoneReference
 */
private static FCZoneReference createFCZoneReference(ZoneInfo info, URI volumeURI, ExportGroup exportGroup) {
    FCZoneReference ref = new FCZoneReference();
    ref.setPwwnKey(info.getZoneReferenceKey());
    ref.setFabricId(info.getFabricId());
    ref.setNetworkSystemUri(URI.create(info.getNetworkSystemId()));
    ref.setVolumeUri(volumeURI);
    ref.setGroupUri(exportGroup.getId());
    ref.setZoneName(info.getZoneName());
    ref.setId(URIUtil.createId(FCZoneReference.class));
    ref.setLabel(FCZoneReference.makeLabel(ref.getPwwnKey(), volumeURI.toString()));
    ref.setExistingZone(true);
    return ref;
}
Also used : FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 28 with FCZoneReference

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

the class NetworkScheduler method unexportVolumes.

/**
 * Called from the unexportVolume call. and others. This method builds the NetworkFabricInfo to be passed to the
 * NetworkDeviceController for automatic unzoning.
 *
 * @param volUris Collection of URIs for volumes whose references are to be deleted
 * @param exportGroupUris List of URIs of all the export groups being processed that might contain the volumes.
 * @param storagePortUri the URI of the StoragePort
 * @param initiatorPort String WWPN with colons
 * @param hasExistingVolumes If true, will not mark a zone as last reference, keeping them from being deleted
 * @return List<NetworkFCZoneInfo> detailing zones to be removed or at least unreferenced
 * @throws IOException
 */
public List<NetworkFCZoneInfo> unexportVolumes(URI varrayURI, Collection<URI> volUris, List<URI> exportGroupUris, URI storagePortUri, String initiatorPort, boolean hasExistingVolumes) {
    List<NetworkFCZoneInfo> ourReferences = new ArrayList<NetworkFCZoneInfo>();
    VirtualArray virtualArray = _dbClient.queryObject(VirtualArray.class, varrayURI);
    if (virtualArray != null && virtualArray.getAutoSanZoning() == false) {
        _log.info("Automatic SAN zoning is disabled in virtual array: " + virtualArray.getLabel());
        return null;
    }
    initiatorPort = formatWWN(initiatorPort);
    // Get the StoragePort
    StoragePort port = null;
    try {
        port = _dbClient.queryObject(StoragePort.class, storagePortUri);
        if (port == null) {
            return null;
        }
    } catch (DatabaseException ex) {
        return null;
    }
    // See if we can find our zone references
    List<String> endPoints = new ArrayList<String>();
    endPoints.add(initiatorPort);
    endPoints.add(formatWWN(port.getPortNetworkId()));
    // Make the key for our endPoints
    String key = null;
    {
        NetworkFCZoneInfo fabricInfo = new NetworkFCZoneInfo();
        fabricInfo.setEndPoints(endPoints);
        key = fabricInfo.makeEndpointsKey();
    }
    // Create a map of the references keyed by volUri concatenated with export group URI.
    // This allows for multiple export groups to export the same volume, and the zone will not
    // be deleted until the volume's references are removed from all export groups.
    // Then we can tell if other volumes are using this.
    Map<String, FCZoneReference> volRefMap = makeExportToReferenceMap(key);
    // If there were no references at all, we don't do anything.
    if (volRefMap.isEmpty()) {
        return null;
    } else {
        // Do this for each of the Export Groups being processed.
        for (URI volUri : volUris) {
            for (URI exportGroupUri : exportGroupUris) {
                FCZoneReference ourReference = volRefMap.get(make2UriKey(volUri, exportGroupUri));
                if (ourReference == null) {
                    continue;
                }
                // We need a fabricInfo for each,
                // so as to remove the FCZoneReference that is keyed on volume/exportGroup.
                NetworkFCZoneInfo fabricInfo = createZoneInfoForRef(ourReference, volUri, initiatorPort, port.getPortNetworkId(), null, exportGroupUri);
                ourReferences.add(fabricInfo);
                volRefMap.remove(make2UriKey(volUri, exportGroupUri));
            }
        }
        // See if all the remaining entries have been marked for deletion.
        boolean live = false;
        for (FCZoneReference ref : volRefMap.values()) {
            if (ref.getInactive() == false) {
                // Here is an apparent live reference; look up the volume and make
                // sure it's still active too.
                BlockObject vol = BlockObject.fetch(_dbClient, ref.getVolumeUri());
                ExportGroup group = _dbClient.queryObject(ExportGroup.class, ref.getGroupUri());
                if (vol != null && vol.getInactive() == false && group != null && group.getInactive() == false) {
                    live = true;
                } else {
                    // mark the errant reference inactive
                    _dbClient.markForDeletion(ref);
                }
            }
        }
        // sets existingZone which will prohibit deletion.
        for (NetworkFCZoneInfo fabricInfo : ourReferences) {
            fabricInfo.setLastReference(!live);
            if (hasExistingVolumes) {
                fabricInfo.setExistingZone(true);
            }
            // Pick an alternate device, just in case
            NetworkLite portNet = getStoragePortNetwork(port);
            NetworkLite iniNet = BlockStorageScheduler.lookupNetworkLite(_dbClient, StorageProtocol.block2Transport("FC"), initiatorPort);
            List<NetworkSystem> networkSystems = getZoningNetworkSystems(iniNet, portNet);
            for (NetworkSystem ns : networkSystems) {
                if (!ns.getId().equals(fabricInfo.getNetworkDeviceId())) {
                    fabricInfo.setAltNetworkDeviceId(ns.getId());
                    break;
                }
            }
        }
        return ourReferences;
    }
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) NetworkLite(com.emc.storageos.util.NetworkLite) ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.db.client.model.StoragePort) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) URI(java.net.URI) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 29 with FCZoneReference

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

the class NetworkScheduler method getFCZoneReferencesForKey.

/**
 * Find the FCZoneReferences for a given zone reference key.
 *
 * @param key - Endpoint key consisting of concatenated WWNs
 * @return List of FCZoneReference
 */
public List<FCZoneReference> getFCZoneReferencesForKey(String key) {
    List<FCZoneReference> list = new ArrayList<FCZoneReference>();
    URIQueryResultList uris = new URIQueryResultList();
    Iterator<FCZoneReference> itFCZoneReference = null;
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFCZoneReferenceKeyConstraint(key), uris);
    itFCZoneReference = _dbClient.queryIterativeObjects(FCZoneReference.class, DataObjectUtils.iteratorToList(uris), true);
    if (itFCZoneReference.hasNext()) {
        while (itFCZoneReference.hasNext()) {
            list.add(itFCZoneReference.next());
        }
    } else {
        _log.info("No FC Zone References for key found");
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 30 with FCZoneReference

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

the class NetworkScheduler method selectExistingZoneForInitiatorPort.

/**
 * Search the list of existing zones for the initiator-port pair to decide which to use.
 * Preference is given to zones according to this priority:
 * <ol>
 * <li>The zone is in ViPR DB and was created by ViPR</li>
 * <li>The zone is in ViPR DB but was not created by ViPR</li>
 * <li>The zone follows the single initiator-target pair per zone</li>
 * <li>The last zone in the list</li>
 * </ol>
 * If no zone can be found for the initiator-port pair, null is returned.
 *
 * @param network the network of the initiator
 * @param initiatorWwn the initiator WWN
 * @param portWwn the target WWN
 * @param existingZones a list of zones found on the network system for the initiator
 * @return an instance of Zone if one is found, otherwise null.
 */
public Zone selectExistingZoneForInitiatorPort(NetworkLite network, String initiatorWwn, String portWwn, List<Zone> existingZones) {
    // If we did not find zones, we need to create zones even if we have FCZoneReference
    if (existingZones == null || existingZones.isEmpty()) {
        return null;
    }
    // initialize variables
    boolean existingZone = true;
    Zone foundZone = null;
    // Find the FCZoneReference in ViPR for the port-initiator key and the network
    String key = FCZoneReference.makeEndpointsKey(initiatorWwn, portWwn);
    List<FCZoneReference> fcZoneRefs = getFCZoneReferencesForKey(key);
    if (!fcZoneRefs.isEmpty()) {
        Zone matchedZone = null;
        _log.info("Found {} FCZoneReference for key {}", fcZoneRefs.size(), key);
        // try to re-use zones known to ViPR as a first preference
        for (FCZoneReference fcZoneRef : fcZoneRefs) {
            // make sure the FCZoneReference matches the network and its network system a
            if (network.getNetworkSystems().contains(fcZoneRef.getNetworkSystemUri().toString()) && network.getNativeId().equals(fcZoneRef.getFabricId())) {
                _log.debug("Found an FCZoneReference for zone {}", fcZoneRef.getZoneName());
                // do still have the zone on the network system
                matchedZone = findZoneByNameAndPort(fcZoneRef.getZoneName(), portWwn, existingZones);
                if (matchedZone != null) {
                    _log.debug("Found the zone for FCZoneReference {} in the initiator existing zones", fcZoneRef.getZoneName());
                    _log.debug(matchedZone.getLogString());
                    foundZone = matchedZone;
                    // if the zone was created by ViPR, the search ended
                    if (!fcZoneRef.getExistingZone()) {
                        existingZone = false;
                        _log.debug("Selected zone {} because it was created by ViPR", foundZone.getName());
                        break;
                    }
                }
            }
        }
    }
    if (foundZone != null) {
        _log.debug("Selected existing Zone {} as it is already used by ViPR", foundZone.getName());
    } else {
        outer: for (Zone curZone : existingZones) {
            for (ZoneMember member : curZone.getMembers()) {
                if (member.getAddress() != null && member.getAddress().equals(portWwn)) {
                    foundZone = curZone;
                    if (curZone.getMembers().size() == 2) {
                        // if the zone has only 2 members, the search ended
                        _log.debug("Selected existing Zone {} as it has only 2 members", foundZone.getName());
                        break outer;
                    }
                }
            }
        }
    }
    if (foundZone != null) {
        foundZone.setExistingZone(existingZone);
    }
    return foundZone;
}
Also used : Zone(com.emc.storageos.networkcontroller.impl.mds.Zone) ZoneMember(com.emc.storageos.networkcontroller.impl.mds.ZoneMember) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Aggregations

FCZoneReference (com.emc.storageos.db.client.model.FCZoneReference)34 URI (java.net.URI)15 ArrayList (java.util.ArrayList)14 StoragePort (com.emc.storageos.db.client.model.StoragePort)10 HashMap (java.util.HashMap)8 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)6 Volume (com.emc.storageos.db.client.model.Volume)6 Initiator (com.emc.storageos.db.client.model.Initiator)5 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)5 List (java.util.List)5 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)4 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)4 NetworkFCZoneInfo (com.emc.storageos.networkcontroller.NetworkFCZoneInfo)4 Zone (com.emc.storageos.networkcontroller.impl.mds.Zone)4 ZoneMember (com.emc.storageos.networkcontroller.impl.mds.ZoneMember)4 DbClient (com.emc.storageos.db.client.DbClient)3 BlockObject (com.emc.storageos.db.client.model.BlockObject)3 BulkList (com.emc.storageos.api.service.impl.response.BulkList)2 ExportMask (com.emc.storageos.db.client.model.ExportMask)2 Network (com.emc.storageos.db.client.model.Network)2