use of com.emc.storageos.db.client.model.TenantOrg 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.TenantOrg in project coprhd-controller by CoprHD.
the class DbClientTest method testDeactivate.
@Test
public void testDeactivate() {
List<TenantOrg> tenants = createTenants(1, "tenant", "tenantIndex");
List<Project> projects = createProjects(1, tenants.iterator().next());
Project project = projects.iterator().next();
String msg = checkForDelete(project);
_logger.info(msg);
Assert.assertNull(msg);
_dbClient.markForDeletion(project);
List<URI> projectIds = new ArrayList<URI>();
projectIds.add(project.getId());
List<Project> queriedProjects = _dbClient.queryObject(Project.class, projectIds, true);
Assert.assertFalse(queriedProjects.iterator().hasNext());
}
use of com.emc.storageos.db.client.model.TenantOrg 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.model.TenantOrg in project coprhd-controller by CoprHD.
the class DbClientTest method testTaskCleanup.
@Test
public void testTaskCleanup() throws Exception {
_logger.info("Starting testTaskCleanup");
int taskCount = 100;
TenantOrg tenant = new TenantOrg();
tenant.setId(URIUtil.createId(TenantOrg.class));
tenant.setLabel("tenant-unit-test");
_dbClient.createObject(tenant);
List<Project> projects = createProjects(1, tenant);
List<Volume> volumes = createVolumes(1, "foobar", projects.get(0));
Volume volume = volumes.get(0);
volume.setTenant(new NamedURI(tenant.getId(), tenant.getLabel()));
DbClient dbClient = _dbClient;
Calendar twoWeeksAgo = Calendar.getInstance();
twoWeeksAgo.setTime(Date.from(LocalDateTime.now().minusWeeks(2).atZone(ZoneId.systemDefault()).toInstant()));
Calendar sixWeeksAgo = Calendar.getInstance();
sixWeeksAgo.setTime(Date.from(LocalDateTime.now().minusWeeks(6).atZone(ZoneId.systemDefault()).toInstant()));
Calendar sixMonthsAgo = Calendar.getInstance();
sixMonthsAgo.setTime(Date.from(LocalDateTime.now().minusMonths(6).atZone(ZoneId.systemDefault()).toInstant()));
for (int i = 0; i < taskCount; i++) {
Task task = new Task();
task.setId(URIUtil.createId(Task.class));
task.setCompletedFlag(false);
task.setDescription("test task");
task.setLabel("TEST TASK");
task.setMessage("test task");
task.setProgress(0);
task.setRequestId(UUID.randomUUID().toString());
task.setResource(new NamedURI(volume.getId(), volume.getLabel()));
task.setStartTime(sixWeeksAgo);
task.setStatus(Task.Status.pending.toString());
task.setTenant(volume.getTenant().getURI());
dbClient.createObject(task);
}
Iterator<Task> pendingTaskItr = TaskUtils.findPendingTasksForResource(dbClient, volume.getId(), volume.getTenant().getURI());
Assert.assertEquals(iteratorCount(pendingTaskItr), taskCount);
TaskUtils.cleanupPendingTasks(dbClient, volume.getId(), "TEST TASK", volume.getTenant().getURI(), sixMonthsAgo);
pendingTaskItr = TaskUtils.findPendingTasksForResource(dbClient, volume.getId(), volume.getTenant().getURI());
Assert.assertEquals(iteratorCount(pendingTaskItr), taskCount);
TaskUtils.cleanupPendingTasks(dbClient, volume.getId(), "TEST TASK", volume.getTenant().getURI(), twoWeeksAgo);
pendingTaskItr = TaskUtils.findPendingTasksForResource(dbClient, volume.getId(), volume.getTenant().getURI());
Assert.assertEquals(iteratorCount(pendingTaskItr), 0);
for (int i = 0; i < taskCount; i++) {
Task task = new Task();
task.setId(URIUtil.createId(Task.class));
task.setCompletedFlag(false);
task.setDescription("test task");
task.setLabel("TEST TASK");
task.setMessage("test task");
task.setProgress(0);
task.setRequestId(UUID.randomUUID().toString());
task.setResource(new NamedURI(volume.getId(), volume.getLabel()));
task.setStartTime(sixWeeksAgo);
task.setStatus(Task.Status.pending.toString());
task.setTenant(volume.getTenant().getURI());
dbClient.createObject(task);
}
pendingTaskItr = TaskUtils.findPendingTasksForResource(dbClient, volume.getId(), volume.getTenant().getURI());
Assert.assertEquals(iteratorCount(pendingTaskItr), taskCount);
TaskUtils.cleanupPendingTasks(dbClient, volume.getId(), "TEST TASK", volume.getTenant().getURI());
pendingTaskItr = TaskUtils.findPendingTasksForResource(dbClient, volume.getId(), volume.getTenant().getURI());
Assert.assertEquals(iteratorCount(pendingTaskItr), 0);
}
use of com.emc.storageos.db.client.model.TenantOrg in project coprhd-controller by CoprHD.
the class VDCRoleMigrationCallback method process.
@Override
public void process() throws MigrationCallbackException {
_log.info("VDC Role Migration Started ...");
DbClient dbClient = getDbClient();
TenantOrg rootTenant = findRootTenant(dbClient);
StringSetMap tenantRoles = rootTenant.getRoleAssignments();
if (tenantRoles == null) {
_log.info("No Role Assignments in original Root Tenant. Skip moving.");
return;
}
VirtualDataCenter vdc = VdcUtil.getLocalVdc();
if (vdc == null) {
throw new IllegalStateException("the CF of Local VDC is not found.");
}
// only copy VDC role assignments
copyRoleAssignments(tenantRoles, vdc);
removeRoleFromRootTenant(vdc, rootTenant);
dbClient.persistObject(vdc);
dbClient.persistObject(rootTenant);
_log.info("VDC Role Migration Done.");
}
Aggregations