use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.
the class ProtectionSystemService method checkForVolumes.
/**
* checks for the existence of any volumes associated with a protection sysem
* also compiles a list of empty protection sets associated with the protection system that can be deleted
*
* @param system protection system
* @param protectionSetsToDelete (return) empty list to be populated by this method
* @return true if volumes exist; else false
*/
private boolean checkForVolumes(URI id, List<ProtectionSet> protectionSetsToDelete) {
boolean volumesExist = false;
URIQueryResultList list = new URIQueryResultList();
Constraint constraint = ContainmentConstraint.Factory.getProtectionSystemProtectionSetConstraint(id);
_dbClient.queryByConstraint(constraint, list);
Iterator<URI> it = list.iterator();
while (it.hasNext()) {
URI protectionSetId = it.next();
ProtectionSet protectionSet = _dbClient.queryObject(ProtectionSet.class, protectionSetId);
if (protectionSet != null && !protectionSet.getInactive()) {
if (protectionSet.getVolumes() != null && !protectionSet.getVolumes().isEmpty()) {
for (String volId : protectionSet.getVolumes()) {
Volume vol = _dbClient.queryObject(Volume.class, URI.create(volId));
if (vol != null && !vol.getInactive()) {
volumesExist = true;
break;
}
}
}
if (!volumesExist) {
// there are no volumes in this protection set, we can delete it
protectionSetsToDelete.add(protectionSet);
}
}
}
return volumesExist;
}
use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.
the class ResourceService method getDiscoveredComputeObjects.
/**
* Retrieves the list of objects with acls based on the tenant information.
*
* @param tenantId to used to filter the objects.
* @param clzz class of objects.
* @return the filtered list of objects with acls.
*/
protected <T extends DiscoveredComputeSystemWithAcls> Iterator<T> getDiscoveredComputeObjects(URI tenantId, Class<T> clzz) {
PermissionsKey permissionKey = new PermissionsKey(PermissionsKey.Type.TENANT, tenantId.toString());
URIQueryResultList resultURIs = new URIQueryResultList();
Constraint aclConstraint = ContainmentPermissionsConstraint.Factory.getDiscoveredObjsWithPermissionsConstraint(permissionKey.toString(), Vcenter.class);
_dbClient.queryByConstraint(aclConstraint, resultURIs);
List<URI> uris = new ArrayList<URI>();
for (URI result : resultURIs) {
uris.add(result);
}
Iterator<T> dataObjects = new ArrayList<T>().iterator();
if (uris != null && !uris.isEmpty()) {
dataObjects = _dbClient.queryIterativeObjectField(clzz, DATAOBJECT_NAME_FIELD, uris);
}
return dataObjects;
}
use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionUtils method volumeHasSnapshotSession.
/**
* Determines if the passed volume has a snapshot session.
*
* @param volume A reference to the volume.
* @param dbClient A reference to a database client.
*
* @return true if the volume has an active session, false otherwise.
*/
public static boolean volumeHasSnapshotSession(Volume volume, DbClient dbClient) {
Constraint constraint = null;
URI cgURI = volume.getConsistencyGroup();
if (NullColumnValueGetter.isNullURI(cgURI)) {
constraint = ContainmentConstraint.Factory.getParentSnapshotSessionConstraint(volume.getId());
} else {
constraint = ContainmentConstraint.Factory.getBlockSnapshotSessionByConsistencyGroup(cgURI);
}
List<BlockSnapshotSession> snapSessions = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, BlockSnapshotSession.class, constraint);
return !snapSessions.isEmpty();
}
use of com.emc.storageos.db.client.constraint.Constraint 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.");
}
}
}
use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.
the class DbClientTest method testContainmentPrefixConstraintWithPageinate.
@Test
public void testContainmentPrefixConstraintWithPageinate() throws Exception {
TenantOrg tenant = new TenantOrg();
tenant.setId(URIUtil.createId(TenantOrg.class));
_dbClient.createObject(tenant);
String prefix = "99";
List<Project> projects = createProjects(1000, tenant);
Constraint constraint = ContainmentPrefixConstraint.Factory.getProjectUnderTenantConstraint(tenant.getId(), prefix);
queryInPaginate(constraint, URIQueryResultList.class, 11, 3);
_dbClient.removeObject(projects.toArray(new Project[projects.size()]));
}
Aggregations