Search in sources :

Example 86 with DbClient

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");
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) Test(org.junit.Test)

Example 87 with DbClient

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);
}
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 88 with DbClient

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]);
    }
}
Also used : AlternateIdConstraintImpl(com.emc.storageos.db.client.constraint.impl.AlternateIdConstraintImpl) DbClient(com.emc.storageos.db.client.DbClient) URI(java.net.URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentPermissionsConstraint(com.emc.storageos.db.client.constraint.ContainmentPermissionsConstraint) Constraint(com.emc.storageos.db.client.constraint.Constraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) Test(org.junit.Test)

Example 89 with DbClient

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);
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) StoragePool(com.emc.storageos.db.client.model.StoragePool) ArrayList(java.util.ArrayList) URI(java.net.URI)

Example 90 with DbClient

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);
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) URI(java.net.URI)

Aggregations

DbClient (com.emc.storageos.db.client.DbClient)253 URI (java.net.URI)155 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)73 Volume (com.emc.storageos.db.client.model.Volume)67 ArrayList (java.util.ArrayList)58 Test (org.junit.Test)42 FileShare (com.emc.storageos.db.client.model.FileShare)34 NamedURI (com.emc.storageos.db.client.model.NamedURI)31 CIMObjectPath (javax.cim.CIMObjectPath)31 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)29 WBEMClient (javax.wbem.client.WBEMClient)29 StringSet (com.emc.storageos.db.client.model.StringSet)28 CIMConnectionFactory (com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory)28 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)26 MigrationCallbackException (com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)25 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)22 InternalDbClient (com.emc.storageos.db.client.upgrade.InternalDbClient)22 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)21 CIMInstance (javax.cim.CIMInstance)21 BlockObject (com.emc.storageos.db.client.model.BlockObject)20