use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class DbClientTest method testOutOfOrderStatusUpdate.
@Test
public void testOutOfOrderStatusUpdate() throws Exception {
_logger.info("Starting out of order update test");
DbClient dbClient = _dbClient;
FileShare fs = new FileShare();
fs.setId(URIUtil.createId(FileShare.class));
fs.setLabel("foobar");
// record ready
fs.setOpStatus(new OpStatusMap());
fs.getOpStatus().put("key", new Operation("ready", "xyz"));
dbClient.persistObject(fs);
// record pending
fs = dbClient.queryObject(FileShare.class, fs.getId());
fs.getOpStatus().put("key", new Operation("pending", "xyz"));
dbClient.persistObject(fs);
// verify status is ready
fs = dbClient.queryObject(FileShare.class, fs.getId());
Assert.assertEquals(fs.getOpStatus().get("key").getStatus(), "ready");
}
use of com.emc.storageos.db.client.DbClient 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.DbClient in project coprhd-controller by CoprHD.
the class DbIndexTest method testInactive.
@Test
public void testInactive() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
// We're going to need synchronize between threads calling into DbClient
this._dbClient.threadStepLock = new ThreadLocal<DbClientTest.StepLock>();
URI vol1Uri = URIUtil.createId(Volume.class);
URI varr1Uri = URIUtil.createId(VirtualArray.class);
IndexTestData[] tests = new IndexTestData[] { new IndexTestData("Test inactive with other index", Volume.class, // Initial state
new Object[] { "personality=", "abc" }, new Object[][] { new Object[] { "inactive=", true }, new Object[] { "personality=", "ghi" } }, new IndexVerifier() {
@Override
public void verify(Class<? extends DataObject> clazz, URI id, DbClient client) {
Volume vol = (Volume) client.queryObject(clazz, id);
String per = vol.getPersonality();
DataObjectType doType = TypeMap.getDoType(clazz);
AlternateIdConstraint constraint = new AlternateIdConstraintImpl(doType.getColumnField("personality"), per);
URIQueryResultList list = new URIQueryResultList();
client.queryByConstraint(constraint, list);
for (URI elem : list) {
assertTrue("The index of .personality should be removed", !elem.equals(id));
}
}
}) };
for (int i = 0; i < tests.length; i++) {
testRaceCondition(tests[i]);
}
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class StoragePoolDiscoveryStatusMigration method process.
@Override
public void process() throws MigrationCallbackException {
DbClient dbClient = getDbClient();
List<URI> poolIds = dbClient.queryByType(StoragePool.class, true);
Iterator<StoragePool> pools = dbClient.queryIterativeObjects(StoragePool.class, poolIds);
List<StoragePool> modifiedPools = new ArrayList<StoragePool>();
while (pools.hasNext()) {
// set default value of DiscoveryStatus to VISIBLE
StoragePool pool = pools.next();
log.info("Setting discovery status of " + pool.getId() + " to " + DiscoveryStatus.VISIBLE);
pool.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
modifiedPools.add(pool);
}
dbClient.persistObject(modifiedPools);
}
use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.
the class StoragePortDiscoveryStatusMigration method process.
@Override
public void process() {
DbClient dbClient = getDbClient();
List<URI> portIds = dbClient.queryByType(StoragePort.class, true);
Iterator<StoragePort> ports = dbClient.queryIterativeObjects(StoragePort.class, portIds);
List<StoragePort> modifiedPorts = new ArrayList<StoragePort>();
while (ports.hasNext()) {
// set default value of DiscoveryStatus to VISIBLE
StoragePort port = ports.next();
log.info("Setting discovery status of " + port.getId() + " to " + DiscoveryStatus.VISIBLE);
port.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
modifiedPorts.add(port);
}
dbClient.persistObject(modifiedPorts);
}
Aggregations