Search in sources :

Example 1 with CompositeColumnName

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

the class FieldValueTimeUUIDPair method handleDataObjectClass.

public void handleDataObjectClass(Class<? extends DataObject> clazz) throws Exception {
    log.info("proccess model class {}", clazz);
    InternalDbClient dbClient = (InternalDbClient) getDbClient();
    DataObjectType doType = TypeMap.getDoType(clazz);
    Keyspace keyspace = dbClient.getLocalContext().getKeyspace();
    ColumnFamilyQuery<String, CompositeColumnName> query = keyspace.prepareQuery(doType.getCF());
    OperationResult<Rows<String, CompositeColumnName>> result = query.getAllRows().setRowLimit(100).execute();
    int totalCount = 0;
    List<Row<String, CompositeColumnName>> rows = new ArrayList<Row<String, CompositeColumnName>>();
    for (Row<String, CompositeColumnName> objRow : result.getResult()) {
        boolean inactiveObject = false;
        totalCount++;
        for (Column<CompositeColumnName> column : objRow.getColumns()) {
            if (DataObject.INACTIVE_FIELD_NAME.equals(column.getName().getOne()) && column.getBooleanValue()) {
                inactiveObject = true;
                break;
            }
        }
        if (inactiveObject) {
            continue;
        }
        rows.add(objRow);
        if (rows.size() > REBUILD_INDEX_BATCH_SIZE) {
            try {
                executor.submit(new RebuildIndexTask(doType, rows, keyspace));
                rows = new ArrayList<Row<String, CompositeColumnName>>();
            } catch (Exception e) {
                log.warn("Failed to submit rebuild index task, this may be caused by thread pool is full, try in next round", e);
            }
        }
    }
    executor.submit(new RebuildIndexTask(doType, rows, keyspace));
    log.info("Total data object count is {} for model {}", totalCount, clazz.getName());
    return;
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) InternalDbClient(com.emc.storageos.db.client.upgrade.InternalDbClient) ArrayList(java.util.ArrayList) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Keyspace(com.netflix.astyanax.Keyspace) Row(com.netflix.astyanax.model.Row) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) Rows(com.netflix.astyanax.model.Rows)

Example 2 with CompositeColumnName

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

the class RowMutationTest method setupTest.

@Before
public void setupTest() {
    volumeCF = new ColumnFamily<String, CompositeColumnName>("Volume", StringSerializer.get(), CompositeColumnNameSerializer.get());
    indexCF = new ColumnFamily<String, IndexColumnName>("LabelPrefixIndex", StringSerializer.get(), IndexColumnNameSerializer.get());
    noExistCF = new ColumnFamily<String, CompositeColumnName>("no_exits_CF", StringSerializer.get(), CompositeColumnNameSerializer.get());
    rowMutator = new RowMutator(((DbClientImpl) this.getDbClient()).getLocalContext().getKeyspace(), false);
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) RowMutator(com.emc.storageos.db.client.impl.RowMutator) Before(org.junit.Before)

Example 3 with CompositeColumnName

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

the class RowMutationTest method insertRecordAndIndexColumnWithError.

@Test
public void insertRecordAndIndexColumnWithError() 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()), "");
    // insert error column
    ColumnListMutation<CompositeColumnName> no_columnList = rowMutator.getRecordColumnList(noExistCF, rowKey);
    no_columnList.putColumn(new CompositeColumnName("test"), 20);
    try {
        rowMutator.execute();
        Assert.fail();
    } catch (Exception e) {
    // expected exception
    }
    // no volume should be created
    Volume volume = (Volume) this.getDbClient().queryObject(URI.create(rowKey));
    Assert.assertNull(volume);
    // no index should be created
    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(), 0);
}
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) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) CqlStatementResult(com.netflix.astyanax.cql.CqlStatementResult) Test(org.junit.Test)

Example 4 with CompositeColumnName

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

the class DbConsistencyCheckerHelperTest method testCheckIndexingCF_SkipRecordWithNoInactiveColumn.

@Test
public void testCheckIndexingCF_SkipRecordWithNoInactiveColumn() throws Exception {
    ColumnFamily<String, CompositeColumnName> cf = new ColumnFamily<String, CompositeColumnName>("FileShare", StringSerializer.get(), CompositeColumnNameSerializer.get());
    FileShare testData = new FileShare();
    testData.setId(URIUtil.createId(FileShare.class));
    testData.setPath("path1");
    testData.setMountPath("mountPath1");
    getDbClient().createObject(testData);
    Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
    keyspace.prepareQuery(cf).withCql(String.format("delete from \"FileShare\" where key='%s' and column1='inactive'", testData.getId().toString())).execute();
    CheckResult 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("path1");
    testData.setMountPath("mountPath1");
    getDbClient().createObject(testData);
    testData = (FileShare) getDbClient().queryObject(testData.getId());
    testData.setInactive(true);
    getDbClient().updateObject(testData);
    helper.checkCFIndices(TypeMap.getDoType(FileShare.class), false, checkResult);
    assertEquals(0, checkResult.getTotal());
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) Keyspace(com.netflix.astyanax.Keyspace) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) FileShare(com.emc.storageos.db.client.model.FileShare) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) Test(org.junit.Test)

Example 5 with CompositeColumnName

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

the class DbConsistencyCheckerHelperTest method testTimeSeriesAlternateId.

@Test
public void testTimeSeriesAlternateId() throws Exception {
    DbConsistencyCheckerHelperMock mockHelper = new DbConsistencyCheckerHelperMock((DbClientImpl) getDbClient());
    Order order = new Order();
    order.setId(URIUtil.createId(Order.class));
    order.setLabel("order2");
    order.setTenant("tenant");
    order.setIndexed(true);
    getDbClient().createObject(order);
    Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
    ColumnFamily<String, TimeSeriesIndexColumnName> indexCF = new ColumnFamily<String, TimeSeriesIndexColumnName>("AllOrdersByTimeStamp", StringSerializer.get(), TimeSeriesColumnNameSerializer.get());
    ColumnFamily<String, CompositeColumnName> cf = new ColumnFamily<String, CompositeColumnName>("Order", StringSerializer.get(), CompositeColumnNameSerializer.get());
    IndexAndCf indexAndCf = new IndexAndCf(TimeSeriesDbIndex.class, indexCF, keyspace);
    CheckResult checkResult = new CheckResult();
    mockHelper.checkIndexingCF(indexAndCf, false, checkResult);
    assertEquals(0, checkResult.getTotal());
    keyspace.prepareQuery(cf).withCql(String.format("delete from \"Order\" where key='%s'", order.getId())).execute();
    checkResult = new CheckResult();
    mockHelper.checkIndexingCF(indexAndCf, false, checkResult);
    assertEquals(1, checkResult.getTotal());
    keyspace.prepareQuery(indexCF).withCql(mockHelper.getCleanIndexCQL()).execute();
    checkResult = new CheckResult();
    mockHelper.checkIndexingCF(indexAndCf, false, checkResult);
    assertEquals(0, checkResult.getTotal());
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) Keyspace(com.netflix.astyanax.Keyspace) CheckResult(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult) IndexAndCf(com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf) TimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) Test(org.junit.Test)

Aggregations

CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)14 Test (org.junit.Test)10 Keyspace (com.netflix.astyanax.Keyspace)8 CheckResult (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult)6 ColumnFamily (com.netflix.astyanax.model.ColumnFamily)6 ClassNameTimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName)5 DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)5 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)5 IndexAndCf (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf)4 TimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName)4 FileShare (com.emc.storageos.db.client.model.FileShare)4 DataObjectType (com.emc.storageos.db.client.impl.DataObjectType)3 Volume (com.emc.storageos.db.client.model.Volume)3 Order (com.emc.storageos.db.client.model.uimodels.Order)3 CompositeIndexColumnName (com.emc.storageos.db.client.impl.CompositeIndexColumnName)2 CqlStatement (com.netflix.astyanax.cql.CqlStatement)2 CqlStatementResult (com.netflix.astyanax.cql.CqlStatementResult)2 ColumnList (com.netflix.astyanax.model.ColumnList)2 ArrayList (java.util.ArrayList)2 DbConsistencyCheckerHelper (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper)1