Search in sources :

Example 91 with UnManagedVolume

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

the class VplexBackendIngestionContext method getUnmanagedVplexMirrors.

/**
 * Returns a Map of UnManagedVolume objects that are parts
 * of a VplexMirror to their device context path from the
 * VPLEX API.
 *
 * @return a map of UnManagedVolume to device context paths
 */
public Map<UnManagedVolume, String> getUnmanagedVplexMirrors() {
    if (null != unmanagedMirrors) {
        return unmanagedMirrors;
    }
    if (!isDiscoveryInProgress()) {
        // first check the database for this unmanaged volume's backend mirrors
        StringSet mirrorMapFromTheDatabase = extractValuesFromStringSet(SupportedVolumeInformation.VPLEX_MIRROR_MAP.toString(), _unmanagedVirtualVolume.getVolumeInformation());
        if (null != mirrorMapFromTheDatabase && !mirrorMapFromTheDatabase.isEmpty()) {
            _logger.info("fetching mirror map from database");
            for (String mirrorEntry : mirrorMapFromTheDatabase) {
                // extract 'n' parse the mirror info from the database
                // pair[0] is the native id of the mirror
                // pair[1] is the device context path from the VPLEX API
                String[] pair = mirrorEntry.split("=");
                UnManagedVolume mirrorVolume = null;
                String contextPath = pair[1];
                // find the mirror UnManagedVolume object
                URIQueryResultList unManagedVolumeList = new URIQueryResultList();
                _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeInfoNativeIdConstraint(pair[0]), unManagedVolumeList);
                if (unManagedVolumeList.iterator().hasNext()) {
                    mirrorVolume = _dbClient.queryObject(UnManagedVolume.class, unManagedVolumeList.iterator().next());
                }
                // add to the map that will be returned from this method
                if (null != mirrorVolume && null != contextPath) {
                    if (null == unmanagedMirrors) {
                        unmanagedMirrors = new HashMap<UnManagedVolume, String>();
                    }
                    unmanagedMirrors.put(mirrorVolume, contextPath);
                    // now remove the mirror from the list of regular backend volumes
                    // so that it won't be ingested that way
                    Iterator<UnManagedVolume> itr = getUnmanagedBackendVolumes().iterator();
                    while (itr.hasNext()) {
                        if (mirrorVolume.getId().toString().equals(itr.next().getId().toString())) {
                            itr.remove();
                        }
                    }
                }
            }
            if (null != unmanagedMirrors && !unmanagedMirrors.isEmpty()) {
                _logger.info("found mirror map: " + unmanagedMirrors);
                return unmanagedMirrors;
            }
        }
    }
    unmanagedMirrors = new HashMap<UnManagedVolume, String>();
    // to check for native mirrors
    if (!_shouldCheckForMirrors) {
        return unmanagedMirrors;
    }
    // if we're in discovery only mode, don't check again during ingestion
    if (isIngestionInProgress() && isInDiscoveryOnlyMode()) {
        return unmanagedMirrors;
    }
    // if the mirror map couldn't be found in the database,
    // we will query the VPLEX API for this information
    long start = System.currentTimeMillis();
    _logger.info("getting unmanaged mirrors");
    if (!getMirrorMap().isEmpty()) {
        for (Entry<String, Map<String, VPlexDeviceInfo>> mirrorMapEntry : getMirrorMap().entrySet()) {
            _logger.info("looking at mirrors for device leg on cluster " + mirrorMapEntry.getKey());
            Map<String, VPlexDeviceInfo> slotToDeviceMap = mirrorMapEntry.getValue();
            if (null != slotToDeviceMap && !slotToDeviceMap.isEmpty()) {
                // figure out the source and target (mirror) UnManagedVolumes for this leg
                UnManagedVolume associatedVolumeSource = null;
                UnManagedVolume associatedVolumeMirror = null;
                // source will be in slot-0, target/mirror will be in slot-1
                for (Entry<String, VPlexDeviceInfo> entry : slotToDeviceMap.entrySet()) {
                    if (SLOT_0.equals(entry.getKey())) {
                        _logger.info("looking at slot-0");
                        associatedVolumeSource = getAssociatedVolumeForComponentDevice(entry.getValue());
                    }
                    if (SLOT_1.equals(entry.getKey())) {
                        _logger.info("looking at slot-1");
                        associatedVolumeMirror = getAssociatedVolumeForComponentDevice(entry.getValue());
                    }
                }
                // once found, wire them together:
                if (null != associatedVolumeMirror && null != associatedVolumeSource) {
                    // 1. remove the mirror volume from the general backend volumes
                    _logger.info("removing mirror volume {} from associated " + "vols and adding to mirrors", associatedVolumeMirror.getLabel());
                    getUnmanagedBackendVolumes().remove(associatedVolumeMirror);
                    // 2. add the mirror the unmanagedMirrors map that will be returned by this method
                    unmanagedMirrors.put(associatedVolumeMirror, slotToDeviceMap.get("1").getPath());
                    // 3. update the source volume with the target mirror information
                    StringSet set = new StringSet();
                    set.add(associatedVolumeMirror.getNativeGuid());
                    _logger.info("adding mirror set {} to source unmanaged volume {}", set, associatedVolumeSource);
                    associatedVolumeSource.putVolumeInfo(SupportedVolumeInformation.VPLEX_NATIVE_MIRROR_TARGET_VOLUME.toString(), set);
                    _logger.info("setting VPLEX_BACKEND_CLUSTER_ID on mirrored volumes: " + mirrorMapEntry.getKey());
                    StringSet clusterIds = new StringSet();
                    clusterIds.add(mirrorMapEntry.getKey());
                    associatedVolumeSource.putVolumeInfo(SupportedVolumeInformation.VPLEX_BACKEND_CLUSTER_ID.name(), clusterIds);
                    // 4. update the target volume with the source volume information
                    set = new StringSet();
                    set.add(associatedVolumeSource.getNativeGuid());
                    associatedVolumeMirror.putVolumeInfo(SupportedVolumeInformation.VPLEX_NATIVE_MIRROR_SOURCE_VOLUME.toString(), set);
                    associatedVolumeMirror.putVolumeInfo(SupportedVolumeInformation.VPLEX_BACKEND_CLUSTER_ID.name(), clusterIds);
                    // 5. need to go ahead and persist any changes to backend volume info
                    _dbClient.updateObject(associatedVolumeSource);
                    _dbClient.updateObject(associatedVolumeMirror);
                } else {
                    String reason = "couldn't find all associated device components in mirror device: ";
                    reason += " associatedVolumeSource is " + associatedVolumeSource;
                    reason += " and associatedVolumeMirror is " + associatedVolumeMirror;
                    _logger.error(reason);
                    throw VPlexApiException.exceptions.backendIngestionContextLoadFailure(reason);
                }
            }
        }
    }
    _logger.info("unmanaged mirrors found: " + unmanagedMirrors);
    _tracker.fetchMirrors = System.currentTimeMillis() - start;
    if (!unmanagedMirrors.isEmpty()) {
        StringSet mirrorEntries = new StringSet();
        for (Entry<UnManagedVolume, String> mirrorEntry : unmanagedMirrors.entrySet()) {
            mirrorEntries.add(mirrorEntry.getKey().getNativeGuid() + "=" + mirrorEntry.getValue());
        }
        if (mirrorEntries != null && !mirrorEntries.isEmpty()) {
            _logger.info("setting VPLEX_MIRROR_MAP: " + mirrorEntries);
            _unmanagedVirtualVolume.putVolumeInfo(SupportedVolumeInformation.VPLEX_MIRROR_MAP.name(), mirrorEntries);
        }
        // need to update the backend volumes because a mirror target shouldn't be considered a direct backend volume
        updateUnmanagedBackendVolumesInParent();
    }
    return unmanagedMirrors;
}
Also used : URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) StringSet(com.emc.storageos.db.client.model.StringSet) VPlexDeviceInfo(com.emc.storageos.vplex.api.VPlexDeviceInfo) HashMap(java.util.HashMap) Map(java.util.Map) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) TreeMap(java.util.TreeMap) StringMap(com.emc.storageos.db.client.model.StringMap)

Example 92 with UnManagedVolume

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

the class VplexBackendIngestionContext method findBackendUnManagedVolumes.

/**
 * Find backend UnManagedVolumes for the given VPLEX UnManagedVolume.
 *
 * @param unmanagedVirtualVolume the virtual volume to find backend volumes for
 * @param dbClient a reference to the database client
 * @return the backend volume(s) for the UnManagedVolume virtual volume
 */
public static List<UnManagedVolume> findBackendUnManagedVolumes(UnManagedVolume unmanagedVirtualVolume, DbClient dbClient) {
    List<UnManagedVolume> unmanagedBackendVolumes = null;
    StringSet dbBackendVolumes = extractValuesFromStringSet(SupportedVolumeInformation.VPLEX_BACKEND_VOLUMES.toString(), unmanagedVirtualVolume.getVolumeInformation());
    if (null != dbBackendVolumes && !dbBackendVolumes.isEmpty()) {
        List<URI> umvUris = new ArrayList<URI>();
        for (String nativeId : dbBackendVolumes) {
            _logger.info("\tfound unmanaged backend volume native id " + nativeId);
            URIQueryResultList unManagedVolumeList = new URIQueryResultList();
            dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeInfoNativeIdConstraint(nativeId), unManagedVolumeList);
            if (unManagedVolumeList.iterator().hasNext()) {
                umvUris.add(unManagedVolumeList.iterator().next());
            }
        }
        if (!umvUris.isEmpty()) {
            unmanagedBackendVolumes = dbClient.queryObject(UnManagedVolume.class, umvUris, true);
            _logger.info("\treturning unmanaged backend volume objects: " + unmanagedBackendVolumes);
            return unmanagedBackendVolumes;
        }
    }
    return unmanagedBackendVolumes;
}
Also used : UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 93 with UnManagedVolume

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

the class VplexBackendIngestionContext method getBackendVolumeGuids.

/**
 * Gets a List of all the backend volume native GUIDs as
 * they would appear in a Volume object (not as in an
 * UnManagedVolume object).
 *
 * @return a List of all the backend volume native GUIDs
 */
public List<String> getBackendVolumeGuids() {
    List<String> associatedVolumeGuids = new ArrayList<String>();
    for (UnManagedVolume vol : this.getUnmanagedBackendVolumes()) {
        associatedVolumeGuids.add(vol.getNativeGuid().replace(UNMANAGEDVOLUME, VOLUME));
    }
    _logger.info("associated volume guids: " + associatedVolumeGuids);
    return associatedVolumeGuids;
}
Also used : UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) ArrayList(java.util.ArrayList)

Example 94 with UnManagedVolume

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

the class VplexBackendIngestionContext method getFriendlyLabel.

/**
 * Returns a friendly label for the virtual volume based on the names of
 * the backend volumes. This should better reflect what the user originally
 * created as a label for the volume, rather than the VPLEX format (device_ or dd_).
 *
 * This is somewhat a "best effort" and will fall back on the default VPLEX label
 * format if a better name can't be determined safely.
 *
 * @return a friendly label for the virtual volume
 */
private String getFriendlyLabel() {
    String friendlyLabel = _originalVolumeLabel;
    boolean hasBackendMirror = unmanagedMirrors != null && !unmanagedMirrors.isEmpty();
    if (_unmanagedVirtualVolume.getLabel() == null || _unmanagedVirtualVolume.getLabel().startsWith(VVOL_LABEL1) || _unmanagedVirtualVolume.getLabel().startsWith(VVOL_LABEL2) || hasBackendMirror) {
        if (null != unmanagedBackendVolumes && !unmanagedBackendVolumes.isEmpty()) {
            if (unmanagedBackendVolumes.size() > VPlexApiConstants.LOCAL_BACKEND_VOLUME_COUNT) {
                // sort so that we consistently pick the same backend volume for the label
                Comparator<UnManagedVolume> sorter = new Comparator<UnManagedVolume>() {

                    public int compare(UnManagedVolume o1, UnManagedVolume o2) {
                        return o1.getLabel().compareTo(o2.getLabel());
                    }
                };
                unmanagedBackendVolumes.sort(sorter);
            }
            UnManagedVolume backendVol = unmanagedBackendVolumes.get(0);
            if (null != backendVol) {
                String baseLabel = backendVol.getLabel();
                // Remove the -0 or -1 from the backing volume label, if it's there.
                if (baseLabel.endsWith("-0") || baseLabel.endsWith("-1")) {
                    baseLabel = baseLabel.substring(0, baseLabel.length() - 2);
                }
                if (null != _originalVolumeLabel && !_originalVolumeLabel.isEmpty()) {
                    // put the existing virtual volume label inside parentheses for reference
                    friendlyLabel = baseLabel + " (" + _originalVolumeLabel + ")";
                } else {
                    friendlyLabel = baseLabel;
                }
            }
        }
    }
    _logger.info("Determined friendly label to be {} for UnManagedVolume {}", friendlyLabel, _unmanagedVirtualVolume.forDisplay());
    return friendlyLabel;
}
Also used : UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Comparator(java.util.Comparator)

Example 95 with UnManagedVolume

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

the class VplexBackendIngestionContext method getAssociatedVolumeForComponentDevice.

/**
 * Finds the backend associated UnManagedVolume for the given VPlexDeviceInfo
 * object. It does this by finding the overlap between the context paths
 * of the VPlexDeviceInfo and VPlexStorageVolumeInfo objects and then using
 * the WWN to locate the related UnManagedVolume.
 *
 * @param device the VPlexDeviceInfo object to search for
 * @return an UnManagedVolume matching the VPlexDeviceInfo.
 */
private UnManagedVolume getAssociatedVolumeForComponentDevice(VPlexDeviceInfo device) {
    String devicePath = device.getPath();
    _logger.info("associated volume device context path: " + devicePath);
    for (Entry<String, VPlexStorageVolumeInfo> entry : getBackendVolumeWwnToInfoMap().entrySet()) {
        String storageVolumePath = entry.getValue().getPath();
        _logger.info("\tstorage volume context path: " + storageVolumePath);
        // context paths should overlap if the device contains the storage volume...
        if (null != storageVolumePath && storageVolumePath.startsWith(devicePath)) {
            _logger.info("\t\tthis storage volume is a match, trying to find unmanaged backend volume");
            for (UnManagedVolume vol : getUnmanagedBackendVolumes()) {
                _logger.info("\t\t\tlooking at " + vol.getNativeGuid());
                if (vol.getWwn().equalsIgnoreCase(entry.getKey())) {
                    _logger.info("\t\t\t\tit's a match for " + vol.getWwn());
                    return vol;
                }
            }
        }
    }
    return null;
}
Also used : VPlexStorageVolumeInfo(com.emc.storageos.vplex.api.VPlexStorageVolumeInfo) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)

Aggregations

UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)146 StringSet (com.emc.storageos.db.client.model.StringSet)66 URI (java.net.URI)53 Volume (com.emc.storageos.db.client.model.Volume)48 ArrayList (java.util.ArrayList)48 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)33 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)31 BlockObject (com.emc.storageos.db.client.model.BlockObject)30 HashMap (java.util.HashMap)29 HashSet (java.util.HashSet)24 NamedURI (com.emc.storageos.db.client.model.NamedURI)19 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)19 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)18 DataObject (com.emc.storageos.db.client.model.DataObject)13 UnManagedExportMask (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedExportMask)13 CIMObjectPath (javax.cim.CIMObjectPath)13 UnManagedProtectionSet (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet)12 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)11 Map (java.util.Map)11 StringMap (com.emc.storageos.db.client.model.StringMap)10