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());
}
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());
}
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;
}
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;
}
Aggregations