Search in sources :

Example 56 with NamedURI

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

the class TaskUtils method findResourceTaskIds.

public static List<NamedURI> findResourceTaskIds(DbClient dbClient, URI resourceId) {
    NamedElementQueryResultList results = new NamedElementQueryResultList();
    dbClient.queryByConstraint(ContainmentConstraint.Factory.getResourceTaskConstraint(resourceId), results);
    List<NamedURI> uris = Lists.newArrayList();
    Iterator<NamedElementQueryResultList.NamedElement> it = results.iterator();
    while (it.hasNext()) {
        NamedElementQueryResultList.NamedElement element = it.next();
        uris.add(new NamedURI(element.getId(), element.getName()));
    }
    return uris;
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList)

Example 57 with NamedURI

use of com.emc.storageos.db.client.model.NamedURI 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 58 with NamedURI

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

the class OrderScheduleTimeCallback method process.

@Override
public void process() throws MigrationCallbackException {
    log.info("Handle Order schedule time ...");
    DbClient dbClient = getDbClient();
    List<URI> orders = dbClient.queryByType(Order.class, true);
    for (URI uri : orders) {
        Order order = dbClient.queryObject(Order.class, uri);
        if (order == null)
            continue;
        if (order.getScheduledEventId() == null) {
            if (order.getExecutionWindowId() == null || order.getExecutionWindowId().getURI().equals(ExecutionWindow.NEXT)) {
                Calendar scheduleTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
                scheduleTime.setTime(order.getLastUpdated());
                order.setExecutionWindowId(new NamedURI(ExecutionWindow.NEXT, "NEXT"));
                order.setScheduledTime(scheduleTime);
            } else {
                // For original orders, set schedule time to
                // either 1) the next execution window starting time
                // or     2) the current time if it is in current execution window
                ExecutionWindow executionWindow = dbClient.queryObject(ExecutionWindow.class, order.getExecutionWindowId().getURI());
                if (executionWindow == null)
                    continue;
                ExecutionWindowHelper helper = new ExecutionWindowHelper(executionWindow);
                order.setScheduledTime(helper.getScheduledTime());
            }
            dbClient.updateObject(order);
        }
    }
    return;
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ExecutionWindowHelper(com.emc.storageos.db.client.util.ExecutionWindowHelper) DbClient(com.emc.storageos.db.client.DbClient) NamedURI(com.emc.storageos.db.client.model.NamedURI) ExecutionWindow(com.emc.storageos.db.client.model.uimodels.ExecutionWindow) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 59 with NamedURI

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

the class SchemaUtil method insertDefaultRootTenant.

/**
 * Insert default root tenant
 */
private void insertDefaultRootTenant(DbClient dbClient) {
    if (!getCfMap().containsKey(TypeMap.getDoType(TenantOrg.class).getCF().getName())) {
        _log.error("No TenantOrg CF in geodb!");
        return;
    }
    if (isRootTenantExist(dbClient)) {
        _log.info("root provider tenant exist already, skip insert");
        return;
    }
    /*
         * Following needs to move to boot strapping wizard at some point
         */
    _log.info("insert root provider tenant ...");
    TenantOrg org = new TenantOrg();
    org.setId(URIUtil.createId(TenantOrg.class));
    org.setLabel("Provider Tenant");
    org.setDescription("Root Provider Tenant");
    org.setParentTenant(new NamedURI(URI.create(TenantOrg.NO_PARENT), org.getLabel()));
    org.addRole("SID,root", "TENANT_ADMIN");
    org.setCreationTime(Calendar.getInstance());
    org.setInactive(false);
    dbClient.createObject(org);
    _log.info("The root tenant {} has been inserted", org.getId());
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) TenantOrg(com.emc.storageos.db.client.model.TenantOrg)

Example 60 with NamedURI

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

the class DbClientTest method testNamedURI.

@Test
public void testNamedURI() throws Exception {
    _logger.info("Starting named uri test");
    int objCount = 1000;
    String prefix = "99";
    URI target = URIUtil.createId(TenantOrg.class);
    Set<URI> expectedResult = new HashSet<URI>();
    DbClient dbClient = _dbClient;
    for (int index = 0; index < objCount; index++) {
        Project pj = new Project();
        pj.setId(URIUtil.createId(Project.class));
        String label = String.format("%1$d :/#$#@$\\: Test Label", index);
        pj.setLabel(label);
        pj.setTenantOrg(new NamedURI(target, label));
        if (label.startsWith(prefix)) {
            expectedResult.add(pj.getId());
        }
        dbClient.persistObject(pj);
    }
    List<URI> result = dbClient.queryByConstraint(ContainmentPrefixConstraint.Factory.getProjectUnderTenantConstraint(target, prefix));
    Assert.assertEquals(result.size(), expectedResult.size());
    for (int i = 0; i < result.size(); i++) {
        Assert.assertTrue(expectedResult.contains(result.get(i)));
    }
    String newPrefix = "xxx";
    Iterator<URI> it = expectedResult.iterator();
    while (it.hasNext()) {
        Project pj = dbClient.queryObject(Project.class, it.next());
        pj.setLabel(newPrefix + pj.getLabel());
        pj.setTenantOrg(new NamedURI(pj.getTenantOrg().getURI(), pj.getLabel()));
        dbClient.persistObject(pj);
        pj = dbClient.queryObject(Project.class, pj.getId());
    }
    result = dbClient.queryByConstraint(ContainmentPrefixConstraint.Factory.getProjectUnderTenantConstraint(target, newPrefix));
    Assert.assertEquals(result.size(), expectedResult.size());
    for (int i = 0; i < result.size(); i++) {
        Assert.assertTrue(expectedResult.contains(result.get(i)));
    }
    result = dbClient.queryByConstraint(ContainmentPrefixConstraint.Factory.getProjectUnderTenantConstraint(target, prefix));
    Assert.assertEquals(result.size(), 0);
    _logger.info("Done with named uri test");
}
Also used : Project(com.emc.storageos.db.client.model.Project) DbClient(com.emc.storageos.db.client.DbClient) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) NamedURI(com.emc.storageos.db.client.model.NamedURI) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) 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) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

NamedURI (com.emc.storageos.db.client.model.NamedURI)196 URI (java.net.URI)98 Volume (com.emc.storageos.db.client.model.Volume)74 StringSet (com.emc.storageos.db.client.model.StringSet)65 Project (com.emc.storageos.db.client.model.Project)54 ArrayList (java.util.ArrayList)46 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)43 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)42 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)36 Test (org.junit.Test)32 StoragePool (com.emc.storageos.db.client.model.StoragePool)31 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)31 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)27 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)26 StringMap (com.emc.storageos.db.client.model.StringMap)26 List (java.util.List)23 OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)20 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)20 VirtualPoolCapabilityValuesWrapper (com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper)18 FileShare (com.emc.storageos.db.client.model.FileShare)17