use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.
the class BlockObjectMultipleConsistencyGroupsMigration method consolidateDuplicates.
/**
* searches for protection sets with duplicate names and consolidates into one protection set
*
* @return
*/
private void consolidateDuplicates() {
Map<String, List<ProtectionSet>> labelURIListMap = new HashMap<String, List<ProtectionSet>>();
List<URI> protectionSetURIs = dbClient.queryByType(ProtectionSet.class, true);
log.info("Scanning ProtectionSets for duplicate names.");
for (URI protectionSetURI : protectionSetURIs) {
ProtectionSet protectionSet = dbClient.queryObject(ProtectionSet.class, protectionSetURI);
if (protectionSet == null || protectionSet.getInactive()) {
log.info("Skipping null or inactive protection set {}", protectionSetURI);
continue;
}
if (!labelURIListMap.containsKey(protectionSet.getLabel())) {
labelURIListMap.put(protectionSet.getLabel(), new ArrayList<ProtectionSet>());
}
labelURIListMap.get(protectionSet.getLabel()).add(protectionSet);
}
List<ProtectionSet> protectionSetsToDelete = new ArrayList<ProtectionSet>();
List<ProtectionSet> protectionSetsToPersist = new ArrayList<ProtectionSet>();
List<Volume> volumesToPersist = new ArrayList<Volume>();
List<BlockSnapshot> snapsToPersist = new ArrayList<BlockSnapshot>();
for (Entry<String, List<ProtectionSet>> entry : labelURIListMap.entrySet()) {
if (entry.getValue().size() > 1) {
log.info("Duplicate protection sets found {} | {}", entry.getKey(), entry.getValue().toArray());
ProtectionSet protectionSet = entry.getValue().iterator().next();
for (ProtectionSet duplicate : entry.getValue()) {
if (duplicate.getId().equals(protectionSet.getId())) {
continue;
}
log.info(String.format("duplicating %s protection set %s to %s)", protectionSet.getLabel(), duplicate.getId(), protectionSet.getId()));
// add the volumes from the duplicate to the original
protectionSet.getVolumes().addAll(duplicate.getVolumes());
// reset the protection set id on the volumes in the duplicate
for (String volid : duplicate.getVolumes()) {
Volume vol = dbClient.queryObject(Volume.class, URI.create(volid));
if (vol == null || vol.getInactive()) {
log.info("Skipping null or inactive volume {}", volid);
continue;
}
log.info(String.format("Changing protection set id on volume %s from %s to %s", vol.getId(), vol.getProtectionSet().getURI(), protectionSet.getId()));
vol.setProtectionSet(new NamedURI(protectionSet.getId(), protectionSet.getLabel()));
volumesToPersist.add(vol);
}
// reset any block snapshot that points to the duplicate protection set
URIQueryResultList blockSnapIds = new URIQueryResultList();
Constraint constraint = ContainmentConstraint.Factory.getProtectionSetBlockSnapshotConstraint(duplicate.getId());
dbClient.queryByConstraint(constraint, blockSnapIds);
Iterator<URI> itr = blockSnapIds.iterator();
while (itr.hasNext()) {
URI snapId = itr.next();
BlockSnapshot snap = dbClient.queryObject(BlockSnapshot.class, snapId);
if (snap == null || snap.getInactive()) {
log.info("Skipping null or inactive volume {}", snapId);
continue;
}
log.info(String.format("Changing protection set id on snapshot %s from %s to %s", snap.getId(), snap.getProtectionSet(), protectionSet.getId()));
snap.setProtectionSet(protectionSet.getId());
snapsToPersist.add(snap);
}
log.info("deleting duplicate protection set {}", duplicate.getId());
protectionSetsToDelete.add(duplicate);
}
protectionSetsToPersist.add(protectionSet);
}
}
dbClient.persistObject(protectionSetsToPersist);
dbClient.persistObject(volumesToPersist);
dbClient.persistObject(snapsToPersist);
dbClient.markForDeletion(protectionSetsToDelete);
}
use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.
the class TaskScrubberExecutor method findTasksForTenantNotPending.
/**
* returns non-pending task ids for a tenant
*
* @param dbClient
* @return a map of task ids in buckets of 10k each
*/
private Map<String, List<URI>> findTasksForTenantNotPending(URI tenantId) {
log.debug("searching for completed tasks for tenant {}", tenantId);
Constraint constraint = AggregatedConstraint.Factory.getAggregationConstraint(Task.class, "tenant", tenantId.toString(), "taskStatus");
AggregationQueryResultList queryResults = new AggregationQueryResultList();
dbClient.queryByConstraint(constraint, queryResults);
Iterator<AggregationQueryResultList.AggregatedEntry> it = queryResults.iterator();
Map<String, List<URI>> notPendingTasks = new HashMap<String, List<URI>>();
int batch = 0;
int count = 0;
// only used for logging
int totalCount = 0;
while (it.hasNext()) {
AggregationQueryResultList.AggregatedEntry entry = it.next();
if (!entry.getValue().equals(Task.Status.pending.name())) {
if (notPendingTasks.get(Integer.toString(batch)) == null) {
notPendingTasks.put(Integer.toString(batch), new ArrayList<URI>());
}
notPendingTasks.get(Integer.toString(batch)).add(entry.getId());
totalCount++;
count++;
if (count >= MAXIMUM_TASK_IN_ONE_QUERY) {
batch++;
count = 0;
}
}
}
log.debug("found {} completed tasks for tenant {}", totalCount, tenantId);
return notPendingTasks;
}
use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.
the class DbClientTest method testContainmentLabelPaginateConstraint.
@Test
public void testContainmentLabelPaginateConstraint() throws Exception {
Project project = new Project();
project.setId(URIUtil.createId(Project.class));
_dbClient.createObject(project);
int objCount = 10;
List<Volume> volumns = createVolumes(objCount, "bar", project);
Constraint constraint = ContainmentPrefixConstraint.Factory.getFullMatchConstraint(Volume.class, "project", project.getId(), "bar");
queryInPaginate(constraint, URIQueryResultList.class, objCount, pageSize);
}
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()]));
}
use of com.emc.storageos.db.client.constraint.Constraint in project coprhd-controller by CoprHD.
the class DbClientTest method testLabelPaginateConstraint.
@Test
public void testLabelPaginateConstraint() throws Exception {
int objCount = 10;
List<Project> projects = new ArrayList<>(objCount);
for (int index = 0; index < objCount; index++) {
Project pj = new Project();
pj.setId(URIUtil.createId(Project.class));
pj.setLabel("foo");
_dbClient.createObject(pj);
projects.add(pj);
}
Constraint constraint = PrefixConstraint.Factory.getFullMatchConstraint(Project.class, "label", "foo");
queryInPaginate(constraint, URIQueryResultList.class, objCount, 3);
_logger.info("Cleanup project objects");
}
Aggregations