Search in sources :

Example 6 with ColumnFamily

use of com.netflix.astyanax.model.ColumnFamily in project coprhd-controller by CoprHD.

the class UserToOrdersMigration method process.

@Override
public void process() throws MigrationCallbackException {
    log.info("Adding new index records for class: {} field: {} annotation: {} name={}", new Object[] { Order.class, Order.SUBMITTED_BY_USER_ID, ClassNameTimeSeries.class.getName(), name });
    DataObjectType doType = TypeMap.getDoType(Order.class);
    ColumnField field = doType.getColumnField(Order.SUBMITTED_BY_USER_ID);
    newIndexCF = field.getIndexCF();
    ColumnFamily<String, IndexColumnName> userToOrders = new ColumnFamily<>(SOURCE_INDEX_CF_NAME, StringSerializer.get(), IndexColumnNameSerializer.get());
    DbClientImpl client = (DbClientImpl) dbClient;
    ks = client.getKeyspace(Order.class);
    MutationBatch mutationBatch = ks.prepareMutationBatch();
    long m = 0;
    try {
        OperationResult<Rows<String, IndexColumnName>> result = ks.prepareQuery(userToOrders).getAllRows().setRowLimit(1000).withColumnRange(new RangeBuilder().setLimit(0).build()).execute();
        ColumnList<IndexColumnName> cols;
        for (Row<String, IndexColumnName> row : result.getResult()) {
            RowQuery<String, IndexColumnName> rowQuery = ks.prepareQuery(userToOrders).getKey(row.getKey()).autoPaginate(true).withColumnRange(new RangeBuilder().setLimit(5).build());
            while (!(cols = rowQuery.execute().getResult()).isEmpty()) {
                m++;
                for (Column<IndexColumnName> col : cols) {
                    String indexKey = row.getKey();
                    String orderId = col.getName().getTwo();
                    ClassNameTimeSeriesIndexColumnName newCol = new ClassNameTimeSeriesIndexColumnName(col.getName().getOne(), orderId, col.getName().getTimeUUID());
                    mutationBatch.withRow(newIndexCF, indexKey).putEmptyColumn(newCol, null);
                    if (m % 10000 == 0) {
                        mutationBatch.execute();
                    }
                }
            }
        }
        mutationBatch.execute();
    } catch (Exception e) {
        log.error("Migration to {} failed e=", newIndexCF.getName(), e);
    }
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) ColumnField(com.emc.storageos.db.client.impl.ColumnField) RangeBuilder(com.netflix.astyanax.util.RangeBuilder) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) ClassNameTimeSeries(com.emc.storageos.db.client.model.ClassNameTimeSeries) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) IndexColumnName(com.emc.storageos.db.client.impl.IndexColumnName) MutationBatch(com.netflix.astyanax.MutationBatch) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) Rows(com.netflix.astyanax.model.Rows)

Example 7 with ColumnFamily

use of com.netflix.astyanax.model.ColumnFamily in project coprhd-controller by CoprHD.

the class InternalDbClientImpl method countTimeSeries.

public int countTimeSeries(String cfName, Calendar startTime, Calendar endTime) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd/HH");
    String startTimeStr = dateFormat.format(startTime.getTime());
    String endTimeStr = dateFormat.format(endTime.getTime());
    int recordCount = 0;
    try {
        Keyspace keyspace = getLocalKeyspace();
        ColumnFamily<String, String> cf = new ColumnFamily<String, String>(cfName, StringSerializer.get(), StringSerializer.get());
        List<String> keys = genTimeSeriesKeys(startTime, endTime);
        for (String key : keys) {
            recordCount += keyspace.prepareQuery(cf).getKey(key).getCount().execute().getResult();
        }
        System.out.println(String.format("Column Family %s's record count between %s and %s is: %s", cfName, startTimeStr, endTimeStr, recordCount));
        return recordCount;
    } catch (ConnectionException e) {
        System.err.println(String.format("Exception=%s", e));
        throw DatabaseException.retryables.connectionFailed(e);
    }
}
Also used : Keyspace(com.netflix.astyanax.Keyspace) SimpleDateFormat(java.text.SimpleDateFormat) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) ColumnFamily(com.netflix.astyanax.model.ColumnFamily)

Example 8 with ColumnFamily

use of com.netflix.astyanax.model.ColumnFamily 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)

Example 9 with ColumnFamily

use of com.netflix.astyanax.model.ColumnFamily in project coprhd-controller by CoprHD.

the class DbConsistencyCheckerHelperTest method testClassNameTimeSeriesIndex.

@Test
public void testClassNameTimeSeriesIndex() throws Exception {
    DbConsistencyCheckerHelperMock mockHelper = new DbConsistencyCheckerHelperMock((DbClientImpl) getDbClient());
    Order order = new Order();
    order.setId(URIUtil.createId(Order.class));
    order.setLabel("order1");
    order.setSubmittedByUserId("root");
    getDbClient().createObject(order);
    Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
    ColumnFamily<String, ClassNameTimeSeriesIndexColumnName> indexCF = new ColumnFamily<String, ClassNameTimeSeriesIndexColumnName>("UserToOrdersByTimeStamp", StringSerializer.get(), ClassNameTimeSeriesSerializer.get());
    ColumnFamily<String, CompositeColumnName> cf = new ColumnFamily<String, CompositeColumnName>("Order", StringSerializer.get(), CompositeColumnNameSerializer.get());
    IndexAndCf indexAndCf = new IndexAndCf(ClassNameTimeSeriesDBIndex.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) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) Test(org.junit.Test)

Example 10 with ColumnFamily

use of com.netflix.astyanax.model.ColumnFamily in project coprhd-controller by CoprHD.

the class DbConsistencyCheckerHelperTest method testCFIndexForOrder.

@Test
public void testCFIndexForOrder() throws Exception {
    DbConsistencyCheckerHelperMock mockHelper = new DbConsistencyCheckerHelperMock((DbClientImpl) getDbClient());
    Order order = new Order();
    order.setId(URIUtil.createId(Order.class));
    order.setLabel("order2");
    order.setSubmittedByUserId("Tom");
    order.setTenant("urn:storageos:TenantOrg:128e0354-c26e-438b-b1e6-1a6ceaa9b380:global");
    order.setIndexed(true);
    getDbClient().createObject(order);
    Keyspace keyspace = ((DbClientImpl) getDbClient()).getLocalContext().getKeyspace();
    ColumnFamily<String, ClassNameTimeSeriesIndexColumnName> userToOrdersByTimeStampCF = new ColumnFamily<String, ClassNameTimeSeriesIndexColumnName>("UserToOrdersByTimeStamp", StringSerializer.get(), ClassNameTimeSeriesSerializer.get());
    ColumnFamily<String, TimeSeriesIndexColumnName> allOrdersByTimeStampCF = 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, userToOrdersByTimeStampCF, keyspace);
    CheckResult checkResult = new CheckResult();
    mockHelper.checkCFIndices(TypeMap.getDoType(Order.class), true, checkResult);
    assertEquals(0, checkResult.getTotal());
    keyspace.prepareQuery(userToOrdersByTimeStampCF).withCql(String.format("delete from \"UserToOrdersByTimeStamp\" where key='%s'", order.getSubmittedByUserId())).execute();
    keyspace.prepareQuery(userToOrdersByTimeStampCF).withCql(String.format("delete from \"AllOrdersByTimeStamp\" where key='%s'", order.getTenant())).execute();
    checkResult = new CheckResult();
    mockHelper.checkCFIndices(TypeMap.getDoType(Order.class), true, checkResult);
    assertEquals(2, checkResult.getTotal());
}
Also used : Order(com.emc.storageos.db.client.model.uimodels.Order) CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) ClassNameTimeSeriesIndexColumnName(com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName) ColumnFamily(com.netflix.astyanax.model.ColumnFamily) 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) Test(org.junit.Test)

Aggregations

ColumnFamily (com.netflix.astyanax.model.ColumnFamily)13 Keyspace (com.netflix.astyanax.Keyspace)8 ClassNameTimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.ClassNameTimeSeriesIndexColumnName)7 Test (org.junit.Test)7 CompositeColumnName (com.emc.storageos.db.client.impl.CompositeColumnName)6 CheckResult (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.CheckResult)6 TimeSeriesIndexColumnName (com.emc.storageos.db.client.impl.TimeSeriesIndexColumnName)5 IndexAndCf (com.emc.storageos.db.client.impl.DbConsistencyCheckerHelper.IndexAndCf)4 IndexColumnName (com.emc.storageos.db.client.impl.IndexColumnName)4 FileShare (com.emc.storageos.db.client.model.FileShare)4 Order (com.emc.storageos.db.client.model.uimodels.Order)4 CompositeIndexColumnName (com.emc.storageos.db.client.impl.CompositeIndexColumnName)3 DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)3 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)2 TimeSeriesType (com.emc.storageos.db.client.impl.TimeSeriesType)2 ClassNameTimeSeries (com.emc.storageos.db.client.model.ClassNameTimeSeries)2 MutationBatch (com.netflix.astyanax.MutationBatch)2 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)2 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)1 ClassNameTimeSeriesSerializer (com.emc.storageos.db.client.impl.ClassNameTimeSeriesSerializer)1