use of com.emc.storageos.db.client.impl.ColumnField in project coprhd-controller by CoprHD.
the class AggregationIndexTimeUUIDMigration method removeTimeUUIDIndexedFields.
private void removeTimeUUIDIndexedFields(Class<? extends DataObject> clazz) throws Exception {
DataObjectType doType = TypeMap.getDoType(clazz);
Collection<ColumnField> fields = doType.getColumnFields();
Map<String, ColumnField> uuidFields = new HashMap<>();
for (ColumnField field : fields) {
DbIndex index = field.getIndex();
if (index != null && index instanceof AggregateDbIndex) {
uuidFields.put(field.getName(), field);
}
}
// true: ignore exception while accessing db
getInternalDbClient().resetFields(clazz, uuidFields, true);
}
use of com.emc.storageos.db.client.impl.ColumnField in project coprhd-controller by CoprHD.
the class DbIndexTest method isEqual.
public static boolean isEqual(DataObject obj, Object[] ops) {
DataObject shouldBe = createInitial(obj.getClass(), obj.getId(), ops);
// Get DataObjectType
DataObjectType doType = TypeMap.getDoType(obj.getClass());
for (ColumnField field : doType.getColumnFields()) {
if (!shouldBe.isChanged(field.getName())) {
continue;
}
Method readMethod = field.getPropertyDescriptor().getReadMethod();
try {
Object shouldBeVal = readMethod.invoke(shouldBe);
Object realVal = readMethod.invoke(obj);
if (!equalsObject(realVal, shouldBeVal)) {
return false;
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
return true;
}
use of com.emc.storageos.db.client.impl.ColumnField 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.ColumnField in project coprhd-controller by CoprHD.
the class StaleRelationURICleanupMigration method doRelationURICleanup.
protected boolean doRelationURICleanup(DataObjectType doType, DataObject dataObject, String relationField) {
boolean isChanged = false;
try {
ColumnField columnField = doType.getColumnField(relationField);
Object fieldValue = columnField.getFieldValue(columnField, dataObject);
List<String> relationURIList = getURIListFromDataObject(fieldValue);
List<String> validRelationURIList = queryValidRelationURIList((DbClientImpl) getDbClient(), relationField, relationURIList);
// get invalid URI list
List<String> invalidURIs = ListUtils.subtract(relationURIList, validRelationURIList);
if (!invalidURIs.isEmpty()) {
totalStaleURICount += invalidURIs.size();
log.info("Stale/invalid URI found for class: {}, key: {}, field: {}", doType.getDataObjectClass().getSimpleName(), dataObject.getId(), relationField);
log.info(StringUtils.join(invalidURIs, ","));
isChanged = true;
saveNewURIListToObject(dataObject, columnField, fieldValue, invalidURIs);
}
} catch (Exception e) {
log.error("Failed to run migration handler for class{}, {}", doType.getDataObjectClass().getSimpleName(), relationField, e);
}
return isChanged;
}
use of com.emc.storageos.db.client.impl.ColumnField 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);
}
}
Aggregations