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