Search in sources :

Example 81 with DbClient

use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.

the class DbClientTest method testCreationTime.

@Test
public void testCreationTime() throws Exception {
    _logger.info("Starting testCreationTime");
    DbClient dbClient = _dbClient;
    StorageSystem system = new StorageSystem();
    system.setId(URIUtil.createId(StorageSystem.class));
    dbClient.createObject(system);
    Thread.sleep(100);
    StorageSystem hit = dbClient.queryObject(StorageSystem.class, system.getId());
    Calendar now = Calendar.getInstance();
    Calendar then = hit.getCreationTime();
    Assert.assertNotNull(then);
    Assert.assertTrue(String.format("then(%s) is not before now(%s), should be %s", then.toString(), now.toString(), system.getCreationTime().toString()), then.before(now));
    system.setLabel("Update");
    dbClient.persistObject(system);
    hit = dbClient.queryObject(StorageSystem.class, system.getId());
    Calendar thenAgain = hit.getCreationTime();
    Assert.assertNotNull(thenAgain);
    Assert.assertEquals(thenAgain, then);
    _logger.info("Finished testing CreationTime");
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) Calendar(java.util.Calendar) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Test(org.junit.Test)

Example 82 with DbClient

use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.

the class DbClientTest method testAlternateIdFromStringSet.

/**
 * Tests object lookup by alias
 *
 * @throws IOException
 */
@Test
public void testAlternateIdFromStringSet() throws IOException {
    _logger.info("Starting testAlternateIdFromStringSet");
    DbClient dbClient = _dbClient;
    String altId = UUID.randomUUID().toString();
    // persist
    AuthnProvider provider = new AuthnProvider();
    provider.setId(URIUtil.createId(AuthnProvider.class));
    provider.setLabel("test-provider");
    provider.setDescription("test provider");
    StringSet domains = new StringSet();
    domains.add("test1.com");
    domains.add("test2.com");
    provider.setDomains(domains);
    dbClient.persistObject(provider);
    // verify
    AuthnProvider stdQueryResult = dbClient.queryObject(AuthnProvider.class, provider.getId());
    Assert.assertTrue(stdQueryResult.getId().equals(provider.getId()));
    Assert.assertTrue(stdQueryResult.getLabel().equals(provider.getLabel()));
    Assert.assertEquals(stdQueryResult.getDomains().size(), provider.getDomains().size());
    for (String domain : domains) {
        Assert.assertTrue(stdQueryResult.getDomains().contains(domain));
    }
    // query by altid
    for (String domain : domains) {
        URIQueryResultList altIdResult = new URIQueryResultList();
        dbClient.queryByConstraint(AlternateIdConstraint.Factory.getAuthnProviderDomainConstraint(domain), altIdResult);
        Assert.assertTrue(altIdResult.iterator().hasNext());
    }
    stdQueryResult.getDomains().remove("test2.com");
    domains.remove("test2.com");
    domains.add("test3.com");
    stdQueryResult.getDomains().add("test3.com");
    dbClient.persistObject(stdQueryResult);
    stdQueryResult = dbClient.queryObject(AuthnProvider.class, provider.getId());
    Assert.assertTrue(stdQueryResult.getId().equals(provider.getId()));
    Assert.assertTrue(stdQueryResult.getLabel().equals(provider.getLabel()));
    // query by altid
    for (String domain : domains) {
        URIQueryResultList altIdResult = new URIQueryResultList();
        dbClient.queryByConstraint(AlternateIdConstraint.Factory.getAuthnProviderDomainConstraint(domain), altIdResult);
        Assert.assertTrue(altIdResult.iterator().hasNext());
    }
    URIQueryResultList altIdResult = new URIQueryResultList();
    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getAuthnProviderDomainConstraint("test-subtenant"), altIdResult);
    Assert.assertFalse(altIdResult.iterator().hasNext());
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) AuthnProvider(com.emc.storageos.db.client.model.AuthnProvider) StringSet(com.emc.storageos.db.client.model.StringSet) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Test(org.junit.Test)

Example 83 with DbClient

use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.

the class DbClientTest method testQueryField.

@Test
public void testQueryField() throws Exception {
    DbClient dbClient = _dbClient;
    OpStatusMap status = new OpStatusMap();
    String taskname = "task1";
    Operation op = new Operation(Operation.Status.pending.toString(), "test");
    op.setDescription("descr");
    status.createTaskStatus(taskname, op);
    String label = "test system";
    StorageSystem system1 = new StorageSystem();
    system1.setId(URIUtil.createId(StorageSystem.class));
    system1.setLabel(label);
    system1.setInactive(true);
    system1.setOpStatus(status);
    StorageSystem system2 = new StorageSystem();
    system2.setId(URIUtil.createId(StorageSystem.class));
    system2.setLabel(label);
    system2.setInactive(true);
    system2.setOpStatus(status);
    dbClient.persistObject(system1, system2);
    List<URI> uris = new ArrayList<URI>();
    uris.add(system1.getId());
    uris.add(system2.getId());
    List<StorageSystem> systems = dbClient.queryObjectField(StorageSystem.class, "label", uris);
    Assert.assertEquals(2, systems.size());
    Assert.assertTrue(systems.get(0).getLabel().equals(label));
    Assert.assertTrue(systems.get(1).getLabel().equals(label));
    Iterator<StorageSystem> it = dbClient.queryIterativeObjectField(StorageSystem.class, "label", uris);
    int count = 0;
    while (it.hasNext()) {
        count++;
        StorageSystem obj = it.next();
        Assert.assertTrue(obj.getLabel().equals(label));
    }
    Assert.assertEquals(2, count);
    systems = dbClient.queryObjectField(StorageSystem.class, "inactive", uris);
    Assert.assertEquals(2, systems.size());
    Assert.assertTrue(systems.get(0).getInactive());
    Assert.assertTrue(systems.get(1).getInactive());
    systems = dbClient.queryObjectField(StorageSystem.class, "status", uris);
    Assert.assertEquals(2, systems.size());
    Assert.assertNotNull(systems.get(0).getOpStatus().get(taskname));
    Assert.assertNotNull(systems.get(1).getOpStatus().get(taskname));
}
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) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Test(org.junit.Test)

Example 84 with DbClient

use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.

the class DbClientTest method testStringSetMapReplace.

@Test
public void testStringSetMapReplace() throws Exception {
    // shows behavior of AbstractChangeTrackingMapSet.clear()
    _logger.info("Starting StringSetMapReplace test");
    DbClient dbClient = _dbClient;
    ProtectionSystem ps = new ProtectionSystem();
    ps.setId(URIUtil.createId(ProtectionSystem.class));
    StringSet set1 = new StringSet();
    set1.add("test1");
    set1.add("test2");
    set1.add("test3");
    set1.add("test4");
    StringSet set2 = new StringSet();
    set2.add("test5");
    set2.add("test6");
    set2.add("test7");
    set2.add("test8");
    String key1 = "key1";
    String key2 = "key2";
    StringSetMap sMap = new StringSetMap();
    sMap.put(key1, set1);
    sMap.put(key2, set2);
    ps.setSiteInitiators(sMap);
    dbClient.createObject(ps);
    ProtectionSystem ps1 = dbClient.queryObject(ProtectionSystem.class, ps.getId());
    StringSet set3 = new StringSet();
    set3.add("test9");
    set3.add("test10");
    set3.add("test11");
    set3.add("test12");
    StringSet set4 = new StringSet();
    set4.add("test13");
    set4.add("test14");
    set4.add("test15");
    set4.add("test16");
    String key4 = "key4";
    String key3 = "key3";
    StringSetMap sMap2 = new StringSetMap();
    sMap2.put(key3, set3);
    sMap2.put(key4, set4);
    ps1.getSiteInitiators().replace(sMap2);
    Assert.assertTrue(ps1.getSiteInitiators().containsKey(key1));
    Assert.assertTrue(ps1.getSiteInitiators().get(key1).isEmpty());
    Assert.assertTrue(ps1.getSiteInitiators().containsKey(key2));
    Assert.assertTrue(ps1.getSiteInitiators().get(key2).isEmpty());
    Assert.assertTrue(ps1.getSiteInitiators().containsKey(key3));
    Assert.assertFalse(ps1.getSiteInitiators().get(key3).isEmpty());
    Assert.assertTrue(ps1.getSiteInitiators().containsKey(key4));
    Assert.assertFalse(ps1.getSiteInitiators().get(key4).isEmpty());
    dbClient.persistObject(ps1);
    ProtectionSystem ps2 = dbClient.queryObject(ProtectionSystem.class, ps.getId());
    Assert.assertFalse(ps2.getSiteInitiators().containsKey(key1));
    Assert.assertFalse(ps2.getSiteInitiators().containsKey(key2));
    Assert.assertTrue(ps2.getSiteInitiators().containsKey(key3));
    Assert.assertFalse(ps2.getSiteInitiators().get(key3).isEmpty());
    Assert.assertTrue(ps2.getSiteInitiators().containsKey(key4));
    Assert.assertFalse(ps2.getSiteInitiators().get(key4).isEmpty());
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) DbClient(com.emc.storageos.db.client.DbClient) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) StringSet(com.emc.storageos.db.client.model.StringSet) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) Test(org.junit.Test)

Example 85 with DbClient

use of com.emc.storageos.db.client.DbClient in project coprhd-controller by CoprHD.

the class DbClientTest method testStringSetMapRemove.

@Test
public void testStringSetMapRemove() throws Exception {
    // shows behavior of AbstractChangeTrackingMapSet.clear()
    _logger.info("Starting StringSetMap3 test");
    DbClient dbClient = _dbClient;
    ProtectionSystem ps = new ProtectionSystem();
    ps.setId(URIUtil.createId(ProtectionSystem.class));
    StringSet set1 = new StringSet();
    set1.add("test1");
    set1.add("test2");
    set1.add("test3");
    set1.add("test4");
    StringSet set2 = new StringSet();
    set2.add("test5");
    set2.add("test6");
    set2.add("test7");
    set2.add("test8");
    String key1 = "key1";
    String key2 = "key2";
    StringSetMap sMap = new StringSetMap();
    sMap.put(key1, set1);
    sMap.put(key2, set2);
    ps.setSiteInitiators(sMap);
    dbClient.createObject(ps);
    ProtectionSystem ps1 = dbClient.queryObject(ProtectionSystem.class, ps.getId());
    StringSet set3 = new StringSet();
    set3.add("test9");
    set3.add("test10");
    set3.add("test11");
    set3.add("test12");
    StringSet set4 = new StringSet();
    set4.add("test13");
    set4.add("test14");
    set4.add("test15");
    set4.add("test16");
    String key4 = "key4";
    String key3 = "key3";
    StringSetMap sMap2 = new StringSetMap();
    sMap2.put(key3, set3);
    sMap2.put(key4, set4);
    ps1.getSiteInitiators().remove(key1);
    ps1.getSiteInitiators().remove(key2);
    ps1.getSiteInitiators().putAll(sMap2);
    Assert.assertTrue(ps1.getSiteInitiators().containsKey(key1));
    Assert.assertTrue(ps1.getSiteInitiators().get(key1).isEmpty());
    Assert.assertTrue(ps1.getSiteInitiators().containsKey(key2));
    Assert.assertTrue(ps1.getSiteInitiators().get(key2).isEmpty());
    Assert.assertTrue(ps1.getSiteInitiators().containsKey(key3));
    Assert.assertFalse(ps1.getSiteInitiators().get(key3).isEmpty());
    Assert.assertTrue(ps1.getSiteInitiators().containsKey(key4));
    Assert.assertFalse(ps1.getSiteInitiators().get(key4).isEmpty());
    dbClient.persistObject(ps1);
    ProtectionSystem ps2 = dbClient.queryObject(ProtectionSystem.class, ps.getId());
    Assert.assertFalse(ps2.getSiteInitiators().containsKey(key1));
    Assert.assertFalse(ps2.getSiteInitiators().containsKey(key2));
    Assert.assertTrue(ps2.getSiteInitiators().containsKey(key3));
    Assert.assertFalse(ps2.getSiteInitiators().get(key3).isEmpty());
    Assert.assertTrue(ps2.getSiteInitiators().containsKey(key4));
    Assert.assertFalse(ps2.getSiteInitiators().get(key4).isEmpty());
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) DbClient(com.emc.storageos.db.client.DbClient) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) StringSet(com.emc.storageos.db.client.model.StringSet) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) Test(org.junit.Test)

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