Search in sources :

Example 76 with Project

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

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

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

use of com.emc.storageos.db.client.model.Project 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)

Example 80 with Project

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

Project (com.emc.storageos.db.client.model.Project)191 URI (java.net.URI)98 NamedURI (com.emc.storageos.db.client.model.NamedURI)93 ArrayList (java.util.ArrayList)67 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)66 Volume (com.emc.storageos.db.client.model.Volume)58 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)55 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)50 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)47 StringSet (com.emc.storageos.db.client.model.StringSet)43 VirtualPoolCapabilityValuesWrapper (com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper)40 List (java.util.List)37 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)36 Produces (javax.ws.rs.Produces)35 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)33 Test (org.junit.Test)31 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)28 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)27 Operation (com.emc.storageos.db.client.model.Operation)27 Consumes (javax.ws.rs.Consumes)27