Search in sources :

Example 51 with TenantOrg

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());
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) TenantOrg(com.emc.storageos.db.client.model.TenantOrg)

Example 52 with TenantOrg

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());
}
Also used : Project(com.emc.storageos.db.client.model.Project) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Test(org.junit.Test)

Example 53 with TenantOrg

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()]));
}
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 54 with TenantOrg

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);
}
Also used : Project(com.emc.storageos.db.client.model.Project) Task(com.emc.storageos.db.client.model.Task) DbClient(com.emc.storageos.db.client.DbClient) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) Volume(com.emc.storageos.db.client.model.Volume) NamedURI(com.emc.storageos.db.client.model.NamedURI) Calendar(java.util.Calendar) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) 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 55 with TenantOrg

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.");
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) DbClient(com.emc.storageos.db.client.DbClient) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter)

Aggregations

TenantOrg (com.emc.storageos.db.client.model.TenantOrg)138 URI (java.net.URI)64 NamedURI (com.emc.storageos.db.client.model.NamedURI)57 Project (com.emc.storageos.db.client.model.Project)54 Volume (com.emc.storageos.db.client.model.Volume)41 ArrayList (java.util.ArrayList)40 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)37 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)34 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)33 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)29 StringSet (com.emc.storageos.db.client.model.StringSet)29 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)28 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)26 Produces (javax.ws.rs.Produces)26 StoragePool (com.emc.storageos.db.client.model.StoragePool)25 List (java.util.List)23 Test (org.junit.Test)23 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)22 StringMap (com.emc.storageos.db.client.model.StringMap)21 Consumes (javax.ws.rs.Consumes)21