Search in sources :

Example 6 with IndexColumnName

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

the class PersistingChangesTest method getIndexRecordCount.

private int getIndexRecordCount(String fieldName) throws ConnectionException {
    Keyspace keyspace = ((DbClientTest.DbClientImplUnitTester) dbClient).getLocalContext().getKeyspace();
    DataObjectType doType = TypeMap.getDoType(Volume.class);
    ColumnField field = doType.getColumnField(fieldName);
    ColumnFamilyQuery<String, IndexColumnName> query = keyspace.prepareQuery(field.getIndexCF());
    OperationResult<Rows<String, IndexColumnName>> result = query.getAllRows().execute();
    int count = 0;
    for (Row<String, IndexColumnName> row : result.getResult()) {
        _log.debug("{}, RowKey={}, Columns Size={}", ++count, row.getKey(), row.getColumns().size());
        for (Column<IndexColumnName> column : row.getColumns()) {
            _log.debug("\t, Column Name={}, String Value={}.", column.getName(), column.getStringValue());
        }
    }
    return count;
}
Also used : IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) Keyspace(com.netflix.astyanax.Keyspace) ColumnField(com.emc.storageos.db.client.impl.ColumnField) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) com.emc.storageos.db.client.constraint(com.emc.storageos.db.client.constraint) DbClientTest(com.emc.storageos.db.server.DbClientTest) Rows(com.netflix.astyanax.model.Rows)

Example 7 with IndexColumnName

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

the class RowMutationTest method insertDataObject.

@Test
public void insertDataObject() throws ConnectionException {
    String prefix = "AA";
    Volume volume = new Volume();
    URI id = URIUtil.createId(Volume.class);
    URI pool = URIUtil.createId(StoragePool.class);
    volume.setId(id);
    volume.setLabel(prefix + "volume");
    volume.setPool(pool);
    volume.setNativeGuid(prefix + "native_guid-2");
    volume.setNativeId(prefix + "native_id-2");
    volume.setCompositionType(prefix + "compositionType");
    volume.setInactive(false);
    volume.setAllocatedCapacity(1000L);
    volume.setProvisionedCapacity(2000L);
    this.getDbClient().updateObject(volume);
    Volume target = (Volume) this.getDbClient().queryObject(id);
    Assert.assertNotNull(target);
    Assert.assertEquals(target.getLabel(), volume.getLabel());
    Assert.assertEquals(target.getPool(), volume.getPool());
    Assert.assertEquals(target.getNativeGuid(), volume.getNativeGuid());
    Assert.assertEquals(target.getNativeId(), volume.getNativeId());
    Assert.assertEquals(target.getCompositionType(), volume.getCompositionType());
    Assert.assertEquals(target.getAllocatedCapacity(), volume.getAllocatedCapacity());
    Assert.assertEquals(target.getProvisionedCapacity(), volume.getProvisionedCapacity());
    CqlStatement statement = ((DbClientImpl) this.getDbClient()).getLocalContext().getKeyspace().prepareCqlStatement();
    String cql = String.format("select * from \"LabelPrefixIndex\" where key='%s' and column1='Volume' and column2='%s' and column3='%s' and column4='%s'", prefix.toLowerCase(), volume.getLabel().toLowerCase(), volume.getLabel(), volume.getId().toString());
    CqlStatementResult result = statement.withCql(cql).execute().getResult();
    Rows<String, IndexColumnName> rows = result.getRows(indexCF);
    Assert.assertEquals(rows.size(), 1);
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) CqlStatement(com.netflix.astyanax.cql.CqlStatement) URI(java.net.URI) CqlStatementResult(com.netflix.astyanax.cql.CqlStatementResult) Test(org.junit.Test)

Example 8 with IndexColumnName

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

the class RowMutationTest method insertRecordAndIndexColumn.

@Test
public void insertRecordAndIndexColumn() throws ConnectionException {
    String rowKey = URIUtil.createId(Volume.class).toString();
    String volumeLabel = "volume label";
    // insert data object
    ColumnListMutation<CompositeColumnName> columnList = rowMutator.getRecordColumnList(volumeCF, rowKey);
    columnList.putColumn(new CompositeColumnName("allocatedCapacity"), 20);
    columnList.putColumn(new CompositeColumnName("label"), volumeLabel);
    // insert related index
    rowMutator.getIndexColumnList(indexCF, "vo").putColumn(new IndexColumnName("Volume", volumeLabel, volumeLabel, rowKey, rowMutator.getTimeUUID()), "");
    rowMutator.execute();
    // verify data object information
    Volume volume = (Volume) this.getDbClient().queryObject(URI.create(rowKey));
    Assert.assertNotNull(volume);
    Assert.assertEquals(volume.getAllocatedCapacity().longValue(), 20L);
    Assert.assertEquals(volume.getLabel(), volumeLabel);
    // verify index information
    CqlStatement statement = ((DbClientImpl) this.getDbClient()).getLocalContext().getKeyspace().prepareCqlStatement();
    String cql = String.format("select * from \"LabelPrefixIndex\" where key='%s' and column1='Volume' and column2='%s' and column3='%s' and column4='%s'", "vo", volumeLabel, volumeLabel, rowKey);
    CqlStatementResult result = statement.withCql(cql).execute().getResult();
    Rows<String, IndexColumnName> rows = result.getRows(indexCF);
    Assert.assertEquals(rows.size(), 1);
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) Volume(com.emc.storageos.db.client.model.Volume) IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) CqlStatement(com.netflix.astyanax.cql.CqlStatement) CqlStatementResult(com.netflix.astyanax.cql.CqlStatementResult) Test(org.junit.Test)

Example 9 with IndexColumnName

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

the class DbConsistencyCheckerHelperTest method testCheckCFIndexing.

@Test
public void testCheckCFIndexing() throws Exception {
    ColumnFamily<String, CompositeColumnName> cf = new ColumnFamily<String, CompositeColumnName>("FileShare", StringSerializer.get(), CompositeColumnNameSerializer.get());
    ColumnFamily<String, IndexColumnName> indexCF = new ColumnFamily<String, IndexColumnName>("AltIdIndex", StringSerializer.get(), IndexColumnNameSerializer.get());
    Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
    FileShare testData = new FileShare();
    testData.setId(URIUtil.createId(FileShare.class));
    testData.setPath("A1");
    testData.setMountPath("A2");
    getDbClient().createObject(testData);
    keyspace.prepareQuery(indexCF).withCql(String.format("delete from \"AltIdIndex\" where key='%s'", "A1")).execute();
    CheckResult checkResult = new CheckResult();
    helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
    assertEquals(1, checkResult.getTotal());
    keyspace.prepareQuery(indexCF).withCql(String.format("delete from \"AltIdIndex\" where key='%s'", "A2")).execute();
    checkResult = new CheckResult();
    helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
    assertEquals(2, checkResult.getTotal());
    helper = new DbConsistencyCheckerHelper((DbClientImpl) getDbClient()) {

        @Override
        protected boolean isDataObjectRemoved(Class<? extends DataObject> clazz, String key) {
            return true;
        }
    };
    checkResult = new CheckResult();
    helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
    assertEquals(0, checkResult.getTotal());
    testData = new FileShare();
    testData.setId(URIUtil.createId(FileShare.class));
    testData.setPath("A'A'");
    testData.setMountPath("A2");
    getDbClient().createObject(testData);
    checkResult = new CheckResult();
    helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
    assertEquals(0, checkResult.getTotal());
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) DbConsistencyCheckerHelper(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper) FileShare(com.emc.storageos.db.client.model.FileShare) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) CompositeIndexColumnName(com.emc.storageos.db.client.impl.CompositeIndexColumnName) TimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) Keyspace(com.netflix.astyanax.Keyspace) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) Test(org.junit.Test)

Aggregations

IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)9 DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)6 Test (org.junit.Test)6 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)5 ClassNameTimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName)4 Keyspace (com.netflix.astyanax.Keyspace)4 ColumnFamily (com.netflix.astyanax.model.ColumnFamily)4 CompositeIndexColumnName (com.emc.storageos.db.client.impl.CompositeIndexColumnName)3 TimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName)3 FileShare (com.emc.storageos.db.client.model.FileShare)3 Volume (com.emc.storageos.db.client.model.Volume)3 CqlStatement (com.netflix.astyanax.cql.CqlStatement)3 CqlStatementResult (com.netflix.astyanax.cql.CqlStatementResult)3 ColumnField (com.emc.storageos.db.client.impl.ColumnField)2 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)2 CheckResult (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult)2 MutationBatch (com.netflix.astyanax.MutationBatch)2 Rows (com.netflix.astyanax.model.Rows)2 com.emc.storageos.db.client.constraint (com.emc.storageos.db.client.constraint)1 DbConsistencyCheckerHelper (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper)1