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;
}
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);
}
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;
}
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());
}
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");
}
Aggregations