Search in sources :

Example 6 with Constraint

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);
}
Also used : HashMap(java.util.HashMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) 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) Volume(com.emc.storageos.db.client.model.Volume) ArrayList(java.util.ArrayList) List(java.util.List) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 7 with Constraint

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;
}
Also used : AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) HashMap(java.util.HashMap) AggregationQueryResultList(com.emc.storageos.db.client.constraint.AggregationQueryResultList) ArrayList(java.util.ArrayList) AggregationQueryResultList(com.emc.storageos.db.client.constraint.AggregationQueryResultList) List(java.util.List) URI(java.net.URI) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint)

Example 8 with Constraint

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);
}
Also used : Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) ContainmentPermissionsConstraint(com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) ContainmentPermissionsConstraint(com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Test(org.junit.Test)

Example 9 with Constraint

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()]));
}
Also used : Project(com.emc.storageos.db.client.model.Project) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) ContainmentPermissionsConstraint(com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) Test(org.junit.Test)

Example 10 with Constraint

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");
}
Also used : Project(com.emc.storageos.db.client.model.Project) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) ContainmentPermissionsConstraint(com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ArrayList(java.util.ArrayList) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) AggregatedConstraint(com.emc.storageos.db.client.constraint.AggregatedConstraint) ContainmentPermissionsConstraint(com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) Test(org.junit.Test)

Aggregations

Constraint (com.emc.storageos.db.client.constraint.Constraint)34 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)25 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)24 URI (java.net.URI)23 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)18 ContainmentPermissionsConstraint (com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint)16 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)16 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)14 AggregatedConstraint (com.emc.storageos.db.client.constraint.AggregatedConstraint)13 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)8 NamedURI (com.emc.storageos.db.client.model.NamedURI)7 Volume (com.emc.storageos.db.client.model.Volume)5 AggregationQueryResultList (com.emc.storageos.db.client.constraint.AggregationQueryResultList)4 Project (com.emc.storageos.db.client.model.Project)4 ProtectionSet (com.emc.storageos.db.client.model.ProtectionSet)4 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)3 DataObject (com.emc.storageos.db.client.model.DataObject)3 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)3 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)2