Search in sources :

Example 1 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class RPDeviceController method doDisableImageCopies.

/**
 * It is possible that RP snapshots are exported to more than one host and hence part of more than one ExportGroup.
 * If the same snapshot
 * is part of more than one active ExportGroup, do not disable Image Access on the RP CG.
 *
 * @param snapshot
 *            snapshot to be unexported
 * @return true if it is safe to disable image access on the CG, false otherwise
 */
public boolean doDisableImageCopies(BlockSnapshot snapshot) {
    ContainmentConstraint constraint = ContainmentConstraint.Factory.getBlockObjectExportGroupConstraint(snapshot.getId());
    URIQueryResultList exportGroupIdsForSnapshot = new URIQueryResultList();
    _dbClient.queryByConstraint(constraint, exportGroupIdsForSnapshot);
    Iterator<URI> exportGroupIdsForSnapshotIter = exportGroupIdsForSnapshot.iterator();
    Set<URI> exportGroupURIs = new HashSet<URI>();
    while (exportGroupIdsForSnapshotIter.hasNext()) {
        exportGroupURIs.add(exportGroupIdsForSnapshotIter.next());
    }
    if (exportGroupURIs.size() > 1) {
        _log.info(String.format("Snapshot %s is in %d active exportGroups. Not safe to disable the CG", snapshot.getEmName(), exportGroupURIs.size()));
        return false;
    }
    _log.info("Safe to disable image access on the CG");
    return true;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet)

Example 2 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class RPDeviceController method getVolumesForRestore.

/**
 * Gets a list of volume IDs to be restored. If the snapshot corresponds to
 * a consistency group, we must get all the volumes associated to other
 * BlockSnapshots that share the same snapset label. Secondly, if the snapshot's
 * parent volume is a VPlex backing volume, we must lookup the associated
 * VPlex volume and use that.
 *
 * @param snapshot
 *            the snapshot to restore.
 * @param volume
 *            the volume to be restored.
 * @return a list of volume IDs to be restored.
 */
private List<URI> getVolumesForRestore(BlockSnapshot snapshot, Volume volume) {
    List<URI> volumeURIs = new ArrayList<URI>();
    URI cgURI = snapshot.getConsistencyGroup();
    if (NullColumnValueGetter.isNullURI(cgURI)) {
        // If the snapshot is not in a CG, delete the replication set
        // for only the requested volume.
        volumeURIs.add(volume.getId());
    } else {
        // Otherwise, get all snapshots in the snapset, get the parent volume for each
        // snapshot. If the parent is a VPlex backing volume, get the VLPEX volume
        // using the snapshot parent.
        List<BlockSnapshot> cgSnaps = ControllerUtils.getSnapshotsPartOfReplicationGroup(snapshot, _dbClient);
        for (BlockSnapshot cgSnapshot : cgSnaps) {
            URIQueryResultList queryResults = new URIQueryResultList();
            _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeByAssociatedVolumesConstraint(cgSnapshot.getParent().getURI().toString()), queryResults);
            URI vplexVolumeURI = null;
            if (queryResults.iterator().hasNext()) {
                vplexVolumeURI = queryResults.iterator().next();
                if (vplexVolumeURI != null) {
                    volumeURIs.add(vplexVolumeURI);
                }
            } else {
                volumeURIs.add(cgSnapshot.getParent().getURI());
            }
        }
    }
    return volumeURIs;
}
Also used : ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 3 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class RPHelper method cleanupSnapshots.

/**
 * Validate Block snapshots that correspond to RP bookmarks. Some may no longer exist in the RP system, and we
 * need to mark them as invalid.
 *
 * The strategy is as follows:
 * 1. Get all of the protection sets associated with the protection system
 * 2. Are there any Block Snapshots of type RP? (if not, don't bother cleaning up)
 * 3. Query the RP Appliance for all bookmarks for that CG (protection set)
 * 4. Find each block snapshot of type RP for each site
 * 5. If you can't find the bookmark in the RP list, move the block snapshot to inactive
 *
 * @param protectionSystem Protection System
 */
public static void cleanupSnapshots(DbClient dbClient, ProtectionSystem protectionSystem) throws RecoverPointException {
    // 1. Get all of the protection sets associated with the protection system
    Set<URI> protectionSetIDs = new HashSet<URI>();
    Set<Integer> cgIDs = new HashSet<Integer>();
    URIQueryResultList list = new URIQueryResultList();
    Constraint constraint = ContainmentConstraint.Factory.getProtectionSystemProtectionSetConstraint(protectionSystem.getId());
    dbClient.queryByConstraint(constraint, list);
    Iterator<URI> it = list.iterator();
    while (it.hasNext()) {
        URI protectionSetId = it.next();
        // Get all snapshots that are part of this protection set.
        URIQueryResultList plist = new URIQueryResultList();
        Constraint pconstraint = ContainmentConstraint.Factory.getProtectionSetBlockSnapshotConstraint(protectionSetId);
        dbClient.queryByConstraint(pconstraint, plist);
        if (plist.iterator().hasNext()) {
            // OK, we know there are snapshots for this protection set/CG.
            // Retrieve all of the bookmarks associated with this protection set/CG later on by adding to the list now
            ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, protectionSetId);
            if (protectionSet != null && !protectionSet.getInactive()) {
                protectionSetIDs.add(protectionSet.getId());
                cgIDs.add(Integer.valueOf(protectionSet.getProtectionId()));
            }
        }
    }
    // 2. No reason to bother the RPAs if there are no protection sets for this protection system.
    if (protectionSetIDs.isEmpty()) {
        _log.info("Block Snapshot of RP Bookmarks cleanup not run for this protection system. No Protections or RP Block Snapshots found on protection system: " + protectionSystem.getLabel());
        return;
    }
    // 3. Query the RP appliance for all of the bookmarks for these CGs in one call
    BiosCommandResult result = getRPBookmarks(protectionSystem, cgIDs);
    GetBookmarksResponse bookmarkMap = (GetBookmarksResponse) result.getObjectList().get(0);
    // 4. Go through each protection set's snapshots and see if they're there.
    it = protectionSetIDs.iterator();
    while (it.hasNext()) {
        URI protectionSetId = it.next();
        ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, protectionSetId);
        // The map should have an entry for that CG with an empty list if it looked and couldn't find any. (a successful empty set)
        if (protectionSet.getProtectionId() != null && bookmarkMap.getCgBookmarkMap() != null && bookmarkMap.getCgBookmarkMap().containsKey(new Integer(protectionSet.getProtectionId()))) {
            // list to avoid issues further down.
            if (bookmarkMap.getCgBookmarkMap().get(new Integer(protectionSet.getProtectionId())) == null) {
                bookmarkMap.getCgBookmarkMap().put(new Integer(protectionSet.getProtectionId()), new ArrayList<RPBookmark>());
            }
            // Get all snapshots that are part of this protection set.
            URIQueryResultList plist = new URIQueryResultList();
            Constraint pconstraint = ContainmentConstraint.Factory.getProtectionSetBlockSnapshotConstraint(protectionSetId);
            dbClient.queryByConstraint(pconstraint, plist);
            Iterator<URI> snapshotIter = plist.iterator();
            while (snapshotIter.hasNext()) {
                URI snapshotId = snapshotIter.next();
                BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, snapshotId);
                boolean deleteSnapshot = true;
                if (snapshot.getInactive()) {
                    // Don't bother deleting or processing if the snapshot is already on its way out.
                    deleteSnapshot = false;
                } else if (snapshot.getEmCGGroupCopyId() == null) {
                    // If something bad happened and we weren't able to get the site information off of the snapshot
                    _log.info("Found that ViPR Snapshot corresponding to RP Bookmark is missing Site information, thus not analyzing for automated deletion. " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmName());
                    deleteSnapshot = false;
                } else if (!bookmarkMap.getCgBookmarkMap().get(Integer.valueOf(protectionSet.getProtectionId())).isEmpty()) {
                    for (RPBookmark bookmark : bookmarkMap.getCgBookmarkMap().get(Integer.valueOf(protectionSet.getProtectionId()))) {
                        // bookmark (from RP) vs. snapshot (from ViPR)
                        if (snapshot.getEmName().equalsIgnoreCase(bookmark.getBookmarkName()) && snapshot.getEmCGGroupCopyId().equals(bookmark.getCGGroupCopyUID().getGlobalCopyUID().getCopyUID())) {
                            deleteSnapshot = false;
                            _log.info("Found that ViPR Snapshot corresponding to RP Bookmark still exists, thus saving in ViPR: " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmCGGroupCopyId() + ":" + snapshot.getEmName());
                        }
                    }
                } else {
                    // Just for debugging, otherwise useless
                    _log.debug("Found that ViPR Snapshot corresponding to RP Bookmark doesn't exist, thus going to delete from ViPR: " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmCGGroupCopyId() + ":" + snapshot.getEmName());
                }
                if (deleteSnapshot) {
                    // 5. We couldn't find the bookmark, and the query for it was successful, so it's time to mark it as gone
                    _log.info("Found that ViPR Snapshot corresponding to RP Bookmark no longer exists, thus deleting in ViPR: " + snapshot.getId() + " - " + protectionSet.getLabel() + ":" + snapshot.getEmInternalSiteName() + ":" + snapshot.getEmCGGroupCopyId() + ":" + snapshot.getEmName());
                    dbClient.markForDeletion(snapshot);
                }
            }
        } else if (protectionSet.getProtectionId() == null) {
            _log.error("Can not determine the consistency group ID of protection set: " + protectionSet.getLabel() + ", can not perform any cleanup of snapshots.");
        } else {
            _log.info("No consistency groups were found associated with protection system: " + protectionSystem.getLabel() + ", can not perform cleanup of snapshots.");
        }
    }
}
Also used : GetBookmarksResponse(com.emc.storageos.recoverpoint.responses.GetBookmarksResponse) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) UnManagedProtectionSet(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedProtectionSet) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) RPBookmark(com.emc.storageos.recoverpoint.objectmodel.RPBookmark) HashSet(java.util.HashSet)

Example 4 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class NetworkAssociationHelper method getEndPointPorts.

/**
 * Looks up the storage ports for a given end point. Returns empty list if a storage port could not be found.
 *
 * @param endPoint
 * @param dbClient an instance of {@link DbClient}
 * @return
 */
private static List<StoragePort> getEndPointPorts(String endPoint, DbClient dbClient) {
    URIQueryResultList portUriList = new URIQueryResultList();
    List<StoragePort> ports = new ArrayList<StoragePort>();
    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePortEndpointConstraint(endPoint), portUriList);
    Iterator<URI> itr = portUriList.iterator();
    while (itr.hasNext()) {
        StoragePort port = dbClient.queryObject(StoragePort.class, itr.next());
        if (port != null && !port.getInactive()) {
            ports.add(port);
        }
    }
    return ports;
}
Also used : StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 5 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class NetworkAssociationHelper method getVArraysNotAssignedToStoragePortInNetwork.

/**
 * Of the passed list of virtual arrays, determines those for which an
 * active storage port in the passed network has been assigned. The
 * function ignores the passed ports, which may be in the process of
 * being removed from the virtual arrays or the network.
 *
 * @param network A reference to the network.
 * @param varrayIds The id of the virtual arrays.
 * @param ignorePorts Storage ports to be ignored, or null.
 * @param dbClient A reference to a DB client.
 *
 * @return The ids of the varrays for which a storage port in the passed network
 *         is assigned.
 */
public static Set<String> getVArraysNotAssignedToStoragePortInNetwork(Network network, Set<String> varrayIds, List<URI> ignorePorts, DbClient dbClient) {
    _log.info("Getting varrays not assigned to any storage ports in network {}", network.getId());
    Set<String> varraysWithoutAssignedStoragePort = new HashSet<String>();
    // Get the URIs of the active storage ports in the passed network.
    List<URI> activeNetworkStoragePortURIs = new ArrayList<URI>();
    List<StoragePort> activeNetworkStoragePorts = CustomQueryUtility.queryActiveResourcesByAltId(dbClient, StoragePort.class, "network", network.getId().toString());
    for (StoragePort networkStoragePort : activeNetworkStoragePorts) {
        activeNetworkStoragePortURIs.add(networkStoragePort.getId());
    }
    // assigned to a storage port in the passed network.
    for (String varrayId : varrayIds) {
        boolean storagePortAssignedToVArray = false;
        // Get the storage ports assigned to the virtual array.
        URIQueryResultList queryResults = new URIQueryResultList();
        dbClient.queryByConstraint(AlternateIdConstraint.Factory.getAssignedVirtualArrayStoragePortsConstraint(varrayId), queryResults);
        Iterator<URI> resultsIter = queryResults.iterator();
        while (resultsIter.hasNext()) {
            URI storagePortURI = resultsIter.next();
            _log.info("Checking virtual array storage port {}", storagePortURI);
            // removing from the virtual array.
            if ((ignorePorts != null) && (ignorePorts.contains(storagePortURI))) {
                _log.info("Ignoring port {}", storagePortURI);
                continue;
            }
            // If so, set the flag and break.
            if (activeNetworkStoragePortURIs.contains(storagePortURI)) {
                storagePortAssignedToVArray = true;
                break;
            }
        }
        if (!storagePortAssignedToVArray) {
            _log.info("Virtual array {} does not have an assigned storage port", varrayId);
            varraysWithoutAssignedStoragePort.add(varrayId);
        }
    }
    return varraysWithoutAssignedStoragePort;
}
Also used : ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet)

Aggregations

URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)664 URI (java.net.URI)497 ArrayList (java.util.ArrayList)258 HashMap (java.util.HashMap)107 Volume (com.emc.storageos.db.client.model.Volume)97 NamedURI (com.emc.storageos.db.client.model.NamedURI)96 HashSet (java.util.HashSet)92 StoragePort (com.emc.storageos.db.client.model.StoragePort)91 StringSet (com.emc.storageos.db.client.model.StringSet)83 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)64 Produces (javax.ws.rs.Produces)55 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)54 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)54 Path (javax.ws.rs.Path)54 List (java.util.List)53 StoragePool (com.emc.storageos.db.client.model.StoragePool)49 Initiator (com.emc.storageos.db.client.model.Initiator)47 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)45 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)39 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)38