Search in sources :

Example 76 with DbClient

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

the class DbClientTest method testTimeSeriesWithTimestamp.

@Test
public void testTimeSeriesWithTimestamp() throws Exception {
    // org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.INFO);
    _logger.info("Starting testTimeSeriesWithTimestamp");
    final int perThreadCount = 10;
    final int numThreads = 5;
    final DbClient dbClient = _dbClient;
    // write
    final Event e = new Event();
    e.setEventType("randomstuff");
    e.setVirtualPool(URI.create("urn:storageos:VirtualPool:random"));
    e.setEventId("abc");
    e.setProjectId(URI.create("urn:storageos:Project:abcrandom"));
    e.setResourceId(URI.create("urn:storageos:FileShare:random"));
    e.setSeverity("REALLY BAD");
    e.setUserId(URI.create("urn:storageos:User:foobar"));
    e.setTimeInMillis(-1);
    // Given time for data points of time series
    final DateTime dateTime = new DateTime(2000, 1, 1, 0, 0, DateTimeZone.UTC);
    ExecutorService executor = Executors.newFixedThreadPool(numThreads);
    long duration = System.currentTimeMillis();
    for (int threadIndex = 0; threadIndex < numThreads; threadIndex++) {
        final int threadId = threadIndex;
        executor.submit(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                for (int index = 0; index < perThreadCount; index++) {
                    long millis = dateTime.getMillis() + (long) ((perThreadCount) * threadId + index) * 1000;
                    DateTime time = new DateTime(millis, DateTimeZone.UTC);
                    dbClient.insertTimeSeries(EventTimeSeries.class, time, e);
                }
                return null;
            }
        });
    }
    executor.shutdown();
    Assert.assertTrue(executor.awaitTermination(60, TimeUnit.SECONDS));
    duration = System.currentTimeMillis() - duration;
    _logger.info("Insertion throughput with batch size {} is {} records per second", 1, (perThreadCount * numThreads) / (duration / 1000f));
    // read at default granularity
    executor = Executors.newFixedThreadPool(numThreads);
    CountDownLatch latch = new CountDownLatch(numThreads * perThreadCount);
    DummyQueryResult result = new DummyQueryResult(latch);
    _logger.info("Starting query with default granularity");
    duration = System.currentTimeMillis();
    dbClient.queryTimeSeries(EventTimeSeries.class, dateTime, result, executor);
    Assert.assertTrue(latch.await(60, TimeUnit.SECONDS));
    duration = System.currentTimeMillis() - duration;
    _logger.info("Read throughput(HOUR) is {} records per second", (perThreadCount * numThreads) / (duration / 1000f));
    _logger.info("Finished testTimeSeriesWithTimestamp");
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) CountDownLatch(java.util.concurrent.CountDownLatch) 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) LocalDateTime(java.time.LocalDateTime) DateTime(org.joda.time.DateTime) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ConcurrentModificationException(java.util.ConcurrentModificationException) IOException(java.io.IOException) EventTimeSeries(com.emc.storageos.db.client.model.EventTimeSeries) ExecutorService(java.util.concurrent.ExecutorService) Event(com.emc.storageos.db.client.model.Event) DataObject(com.emc.storageos.db.client.model.DataObject) Test(org.junit.Test)

Example 77 with DbClient

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

the class DbClientTest method testQueryByType.

@Test
public void testQueryByType() {
    DbClient dbClient = _dbClient;
    List<URI> expected = new ArrayList<URI>();
    for (int i = 0; i < 10; i++) {
        AuthnProvider provider = new AuthnProvider();
        provider.setId(URIUtil.createId(AuthnProvider.class));
        provider.setLabel("provider" + i);
        dbClient.createObject(provider);
        expected.add(provider.getId());
    }
    List<AuthnProvider> providerList = new ArrayList<AuthnProvider>();
    for (int i = 10; i < 120; i++) {
        AuthnProvider provider = new AuthnProvider();
        provider.setId(URIUtil.createId(AuthnProvider.class));
        provider.setLabel("provider" + i);
        providerList.add(provider);
        expected.add(provider.getId());
        providerList.add(provider);
    }
    dbClient.createObject(providerList);
    List<URI> match = new ArrayList<URI>(expected);
    List<URI> uris = dbClient.queryByType(AuthnProvider.class, true);
    Iterator<URI> it = uris.iterator();
    Assert.assertTrue(it.hasNext());
    int apCnt = 0;
    while (it.hasNext()) {
        apCnt++;
        URI uri = it.next();
        Assert.assertTrue(match.contains(uri));
        match.remove(uri);
    }
    Assert.assertEquals(apCnt, 120);
    Assert.assertEquals(match.size(), 0);
    // query with active flag
    List<URI> activeOnly = new ArrayList<URI>(expected);
    for (int i = 0; i < 5; i++) {
        AuthnProvider provider = new AuthnProvider();
        provider.setId(expected.get(i));
        provider.setInactive(true);
        dbClient.updateAndReindexObject(provider);
        activeOnly.remove(expected.get(i));
    }
    // all query
    match = new ArrayList<URI>(expected);
    uris = dbClient.queryByType(AuthnProvider.class, false);
    it = uris.iterator();
    Assert.assertTrue(it.hasNext());
    while (it.hasNext()) {
        URI uri = it.next();
        Assert.assertTrue(String.format("URI %s is not contained in match (%d)", uri.toString(), match.size()), match.contains(uri));
        match.remove(uri);
    }
    Assert.assertEquals(0, match.size());
    // active only query - with mixed active/inactive
    uris = dbClient.queryByType(AuthnProvider.class, true);
    it = uris.iterator();
    Assert.assertTrue(it.hasNext());
    while (it.hasNext()) {
        URI uri = it.next();
        Assert.assertTrue(activeOnly.contains(uri));
        activeOnly.remove(uri);
    }
    Assert.assertEquals(0, activeOnly.size());
}
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) ArrayList(java.util.ArrayList) 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) Test(org.junit.Test)

Example 78 with DbClient

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

Example 79 with DbClient

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

the class DbClientTest method testCfWithMutipleRelationIndex.

@Test
public void testCfWithMutipleRelationIndex() {
    _logger.info("Starting testCompareIndexes");
    DbClient dbClient = _dbClient;
    URI varrayId1 = URIUtil.createId(VirtualArray.class);
    VirtualArray varray1 = new VirtualArray();
    varray1.setId(varrayId1);
    varray1.setLabel("varray1");
    dbClient.createObject(varray1);
    Network nw1 = new Network();
    nw1.setId(URIUtil.createId(Network.class));
    nw1.setLabel("networkObj");
    StringSet varrayStrSet1 = new StringSet();
    varrayStrSet1.add(varrayId1.toString());
    nw1.setAssignedVirtualArrays(varrayStrSet1);
    dbClient.createObject(nw1);
    List<Network> assignedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId1, Network.class, "assignedVirtualArrays");
    Assert.assertTrue(assignedNetworks.iterator().hasNext());
    Assert.assertEquals(assignedNetworks.size(), 1);
    List<Network> connectedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId1, Network.class, "connectedVirtualArrays");
    Assert.assertFalse(connectedNetworks.iterator().hasNext());
    URI varrayId2 = URIUtil.createId(VirtualArray.class);
    VirtualArray varray2 = new VirtualArray();
    varray2.setId(varrayId2);
    varray2.setLabel("varray2");
    dbClient.createObject(varray2);
    StringSet varrayStrSet2 = new StringSet();
    varrayStrSet2.add(varrayId1.toString());
    varrayStrSet2.add(varrayId2.toString());
    nw1.setConnectedVirtualArrays(varrayStrSet2);
    dbClient.persistObject(nw1);
    assignedNetworks.clear();
    assignedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId1, Network.class, "assignedVirtualArrays");
    Assert.assertTrue(assignedNetworks.iterator().hasNext());
    Assert.assertEquals(assignedNetworks.size(), 1);
    connectedNetworks.clear();
    connectedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId2, Network.class, "connectedVirtualArrays");
    Assert.assertTrue(connectedNetworks.iterator().hasNext());
    Assert.assertEquals(connectedNetworks.size(), 1);
    connectedNetworks.clear();
    connectedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId1, Network.class, "connectedVirtualArrays");
    Assert.assertTrue(connectedNetworks.iterator().hasNext());
    Assert.assertEquals(connectedNetworks.size(), 1);
    assignedNetworks.clear();
    assignedNetworks = CustomQueryUtility.queryActiveResourcesByRelation(dbClient, varrayId2, Network.class, "assignedVirtualArrays");
    Assert.assertFalse(assignedNetworks.iterator().hasNext());
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) DbClient(com.emc.storageos.db.client.DbClient) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) Network(com.emc.storageos.db.client.model.Network) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Test(org.junit.Test)

Example 80 with DbClient

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

the class DbClientTest method testTagIndex.

@Test
public void testTagIndex() throws Exception {
    _logger.info("Starting testTagIndex");
    final int objCount = 1000;
    final String prefix = "55";
    Set<URI> expectedResult = new HashSet<URI>();
    URI tenant = URIUtil.createId(TenantOrg.class);
    DbClient dbClient = _dbClient;
    for (int index = 0; index < objCount; index++) {
        FileShare fs = new FileShare();
        fs.setId(URIUtil.createId(FileShare.class));
        fs.setLabel("foobar");
        String tag = String.format("%1$d - test label", index);
        if (tag.startsWith(prefix)) {
            expectedResult.add(fs.getId());
        }
        ScopedLabelSet tagSet = new ScopedLabelSet();
        tagSet.add(new ScopedLabel(tenant.toString(), tag));
        fs.setTag(tagSet);
        dbClient.persistObject(fs);
    }
    List<URI> hits = dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(FileShare.class, prefix, null));
    Assert.assertEquals(hits.size(), expectedResult.size());
    for (int i = 0; i < hits.size(); i++) {
        Assert.assertTrue(expectedResult.contains(hits.get(i)));
    }
    hits = dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(FileShare.class, prefix, tenant));
    Assert.assertEquals(hits.size(), expectedResult.size());
    for (int i = 0; i < hits.size(); i++) {
        Assert.assertTrue(expectedResult.contains(hits.get(i)));
    }
    hits = dbClient.queryByConstraint(PrefixConstraint.Factory.getTagsPrefixConstraint(FileShare.class, "foobar", tenant));
    Assert.assertEquals(hits.size(), 0);
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) 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) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) HashSet(java.util.HashSet) 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