use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class DbIndexTest method verify.
@Override
public void verify(Class<? extends DataObject> clazz, URI id, DbClient client) {
// Get meta data about the object, field and index we're going to test
DataObjectType doType = TypeMap.getDoType(clazz);
ColumnField field = doType.getColumnField(fieldName);
if (field == null) {
throw new NullPointerException(String.format("Cannot find field %s from class %s", fieldName, clazz.getSimpleName()));
}
DbIndex index = field.getIndex();
// Load object first
DataObject obj = (DataObject) client.queryObject(clazz, id);
// Get current value of indexed field
Object val = null;
try {
val = field.getPropertyDescriptor().getReadMethod().invoke(obj);
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Assert.fail("Cannot get field value");
}
boolean indexByKey = field.getPropertyDescriptor().getReadMethod().getAnnotation(IndexByKey.class) != null;
// See which type the index is, and call corresponding verification functions
if (index instanceof AltIdDbIndex) {
verifyAltIdDbIndex(obj, field, val, indexByKey, client);
} else if (index instanceof RelationDbIndex) {
verifyRelationDbIndex(obj, field, val, indexByKey, client);
} else if (index instanceof NamedRelationDbIndex) {
verifyNamedRelationDbIndex(obj, field, val, indexByKey, client);
} else if (index instanceof PrefixDbIndex) {
verifyPrefixDbIndex(obj, field, val, indexByKey, client);
} else if (index instanceof DecommissionedDbIndex) {
verifyDecommissionedDbIndex(obj, field, val, indexByKey, client);
} else if (index instanceof PermissionsDbIndex) {
verifyPermissionsDbIndex(obj, field, val, indexByKey, client);
} else if (index instanceof ScopedLabelDbIndex) {
verifyScopedLabelDbIndex(obj, field, val, indexByKey, client);
} else {
System.out.printf("Unsupported index type %s%n", index.getClass().getSimpleName());
}
}
use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class StaleIndexCleanerMigration method getAllIndexCFs.
private Map<String, IndexAndCf> getAllIndexCFs() {
Map<String, IndexAndCf> allIdxCfs = new TreeMap<>();
for (DataObjectType objType : TypeMap.getAllDoTypes()) {
if (KeyspaceUtil.isLocal(objType.getDataObjectClass())) {
Map<String, IndexAndCf> idxCfs = checkHelper.getIndicesOfCF(objType);
allIdxCfs.putAll(idxCfs);
}
}
return allIdxCfs;
}
use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class StaleRelationURICleanupMigration method process.
@Override
public void process() throws MigrationCallbackException {
initRelationFields();
DbClientImpl dbClient = (DbClientImpl) getDbClient();
for (Entry<Class<? extends DataObject>, List<String>> entry : relationFields.entrySet()) {
DataObjectType doType = TypeMap.getDoType(entry.getKey());
// for each class, query out all objects iteratively
List<URI> uriList = dbClient.queryByType(entry.getKey(), true);
Iterator<DataObject> resultIterator = (Iterator<DataObject>) dbClient.queryIterativeObjects(entry.getKey(), uriList, true);
while (resultIterator.hasNext()) {
DataObject dataObject = resultIterator.next();
boolean isChanged = false;
for (String relationField : entry.getValue()) {
isChanged |= doRelationURICleanup(doType, dataObject, relationField);
}
if (isChanged) {
totalModifiedObject++;
dbClient.updateObject(dataObject);
}
}
}
log.info("Totally found {} stale/invalid URI keys", totalStaleURICount);
log.info("Totally {} data objects have been modifed to remove stale/invalid URI", totalModifiedObject);
}
use of com.emc.storageos.db.client.impl.DataObjectType 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);
}
}
use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class DataObjectUtils method getPropertyValue.
/**
* This function returns the property value for an object of {@link DataObject} subtype.
*
* @param clzz the object class that should be a subtype of {@link DataObject}
* @param dataObject the instance of clzz
* @param property the string name of the property
* @return the value of the property
*/
public static <T extends DataObject> Object getPropertyValue(Class<T> clzz, DataObject dataObject, String property) {
try {
DataObjectType doType = TypeMap.getDoType(clzz);
ColumnField field = doType.getColumnField(property);
return field.getPropertyDescriptor().getReadMethod().invoke(dataObject);
} catch (Exception ex) {
throw DatabaseException.fatals.failedToReadPropertyValue(clzz, property, ex);
}
}
Aggregations