Search in sources :

Example 11 with CompositeColumnName

use of com.emc.storageos.db.client.impl.CompositeColumnName 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 12 with CompositeColumnName

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

Example 13 with CompositeColumnName

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

the class DBClient method printBeanProperties.

/**
 * @param clazz
 * @param object
 * @param criterias
 *            Filter with some verify simple criteria
 * @return Whether this record is print out
 * @throws Exception
 */
private <T extends DataObject> boolean printBeanProperties(Class<T> clazz, T object, Map<String, String> criterias) throws Exception {
    Map<String, String> localCriterias = new HashMap<>(criterias);
    StringBuilder record = new StringBuilder();
    record.append("id: " + object.getId().toString() + "\n");
    boolean isPrint = true;
    BeanInfo bInfo;
    try {
        bInfo = Introspector.getBeanInfo(clazz);
    } catch (IntrospectionException ex) {
        log.error("Unexpected exception getting bean info", ex);
        throw new RuntimeException("Unexpected exception getting bean info", ex);
    }
    PropertyDescriptor[] pds = bInfo.getPropertyDescriptors();
    Object objValue;
    Class type;
    Set<String> ignoreList = new HashSet<>();
    for (PropertyDescriptor pd : pds) {
        // skip class property
        if (pd.getName().equals("class") || pd.getName().equals("id")) {
            continue;
        }
        Name nameAnnotation = pd.getReadMethod().getAnnotation(Name.class);
        String objKey;
        if (nameAnnotation == null) {
            objKey = pd.getName();
        } else {
            objKey = nameAnnotation.value();
        }
        objValue = pd.getReadMethod().invoke(object);
        if (!localCriterias.isEmpty()) {
            if (localCriterias.containsKey(objKey)) {
                if (!localCriterias.get(objKey).equalsIgnoreCase(String.valueOf(objValue))) {
                    isPrint = false;
                    break;
                } else {
                    localCriterias.remove(objKey);
                }
            }
        }
        if (objValue == null) {
            ignoreList.add(objKey);
            continue;
        }
        if (isEmptyStr(objValue)) {
            ignoreList.add(objKey);
            continue;
        }
        record.append("\t" + objKey + " = ");
        Encrypt encryptAnnotation = pd.getReadMethod().getAnnotation(Encrypt.class);
        if (encryptAnnotation != null) {
            record.append("*** ENCRYPTED CONTENT ***\n");
            continue;
        }
        type = pd.getPropertyType();
        if (type == URI.class) {
            record.append("URI: " + objValue + "\n");
        } else if (type == StringMap.class) {
            record.append("StringMap " + objValue + "\n");
        } else if (type == StringSet.class) {
            record.append("StringSet " + objValue + "\n");
        } else if (type == OpStatusMap.class) {
            record.append("OpStatusMap " + objValue + "\n");
        } else {
            record.append(objValue + "\n");
        }
    }
    if (this.showModificationTime) {
        Column<CompositeColumnName> latestField = _dbClient.getLatestModifiedField(TypeMap.getDoType(clazz), object.getId(), ignoreList);
        if (latestField != null) {
            record.append(String.format("The latest modified time is %s on Field(%s).\n", new Date(latestField.getTimestamp() / 1000), latestField.getName().getOne()));
        }
    }
    if (isPrint) {
        if (!localCriterias.isEmpty()) {
            String errMsg = String.format("The filters %s are not available for the CF %s", localCriterias.keySet(), clazz);
            throw new IllegalArgumentException(errMsg);
        }
        System.out.println(record.toString());
    }
    return isPrint;
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) StringMap(com.emc.storageos.db.client.model.StringMap) PropertyDescriptor(java.beans.PropertyDescriptor) HashMap(java.util.HashMap) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) Encrypt(com.emc.storageos.db.client.model.Encrypt) Date(java.util.Date) Name(com.emc.storageos.db.client.model.Name) CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) DataObject(com.emc.storageos.db.client.model.DataObject) HashSet(java.util.HashSet)

Example 14 with CompositeColumnName

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

the class InternalDbClientImpl method getLatestModifiedField.

public Column<CompositeColumnName> getLatestModifiedField(DataObjectType type, URI id, Set<String> ignoreList) {
    Column<CompositeColumnName> latestField = null;
    ColumnFamily<String, CompositeColumnName> cf = type.getCF();
    Keyspace ks = this.getKeyspace(type.getDataObjectClass());
    Rows<String, CompositeColumnName> rows = this.queryRowsWithAllColumns(ks, Lists.newArrayList(id), cf);
    if (rows.isEmpty()) {
        log.warn("Can not find the latest modified field of {}", id);
        return latestField;
    }
    long latestTimeStampe = 0;
    for (Column<CompositeColumnName> column : rows.iterator().next().getColumns()) {
        if (ignoreList != null && ignoreList.contains(column.getName().getOne())) {
            continue;
        }
        if (column.getTimestamp() > latestTimeStampe) {
            latestTimeStampe = column.getTimestamp();
            latestField = column;
        }
    }
    return latestField;
}
Also used : CompositeColumnName(com.emc.storageos.db.client.impl.CompositeColumnName) Keyspace(com.netflix.astyanax.Keyspace)

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