use of com.emc.storageos.db.client.impl.DataObjectType 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.DataObjectType in project coprhd-controller by CoprHD.
the class FieldValueTimeUUIDPair method handleDataObjectClass.
public void handleDataObjectClass(Class<? extends DataObject> clazz) throws Exception {
log.info("proccess model class {}", clazz);
InternalDbClient dbClient = (InternalDbClient) getDbClient();
DataObjectType doType = TypeMap.getDoType(clazz);
Keyspace keyspace = dbClient.getLocalContext().getKeyspace();
ColumnFamilyQuery<String, CompositeColumnName> query = keyspace.prepareQuery(doType.getCF());
OperationResult<Rows<String, CompositeColumnName>> result = query.getAllRows().setRowLimit(100).execute();
int totalCount = 0;
List<Row<String, CompositeColumnName>> rows = new ArrayList<Row<String, CompositeColumnName>>();
for (Row<String, CompositeColumnName> objRow : result.getResult()) {
boolean inactiveObject = false;
totalCount++;
for (Column<CompositeColumnName> column : objRow.getColumns()) {
if (DataObject.INACTIVE_FIELD_NAME.equals(column.getName().getOne()) && column.getBooleanValue()) {
inactiveObject = true;
break;
}
}
if (inactiveObject) {
continue;
}
rows.add(objRow);
if (rows.size() > REBUILD_INDEX_BATCH_SIZE) {
try {
executor.submit(new RebuildIndexTask(doType, rows, keyspace));
rows = new ArrayList<Row<String, CompositeColumnName>>();
} catch (Exception e) {
log.warn("Failed to submit rebuild index task, this may be caused by thread pool is full, try in next round", e);
}
}
}
executor.submit(new RebuildIndexTask(doType, rows, keyspace));
log.info("Total data object count is {} for model {}", totalCount, clazz.getName());
return;
}
use of com.emc.storageos.db.client.impl.DataObjectType in project coprhd-controller by CoprHD.
the class DbClientTest method checkAggregatedQuery.
private void checkAggregatedQuery(Iterator<AggregationQueryResultList.AggregatedEntry> it, Class<? extends DataObject> clazz, String field, Map<URI, ? extends DataObject> validatedObj) {
int count = 0;
while (it.hasNext()) {
AggregationQueryResultList.AggregatedEntry entry = it.next();
_logger.info(" " + entry.getId() + "; capacity = " + entry.getValue().toString());
DataObject obj = validatedObj.get(entry.getId());
DataObjectType doType = TypeMap.getDoType(clazz);
Object value = ColumnField.getFieldValue(doType.getColumnField(field), obj);
Assert.assertEquals(value, entry.getValue());
count++;
}
Assert.assertEquals(count, validatedObj.size());
}
use of com.emc.storageos.db.client.impl.DataObjectType 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.DataObjectType in project coprhd-controller by CoprHD.
the class DbIndexTest method testInactive.
@Test
public void testInactive() throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
// We're going to need synchronize between threads calling into DbClient
this._dbClient.threadStepLock = new ThreadLocal<DbClientTest.StepLock>();
URI vol1Uri = URIUtil.createId(Volume.class);
URI varr1Uri = URIUtil.createId(VirtualArray.class);
IndexTestData[] tests = new IndexTestData[] { new IndexTestData("Test inactive with other index", Volume.class, // Initial state
new Object[] { "personality=", "abc" }, new Object[][] { new Object[] { "inactive=", true }, new Object[] { "personality=", "ghi" } }, new IndexVerifier() {
@Override
public void verify(Class<? extends DataObject> clazz, URI id, DbClient client) {
Volume vol = (Volume) client.queryObject(clazz, id);
String per = vol.getPersonality();
DataObjectType doType = TypeMap.getDoType(clazz);
AlternateIdConstraint constraint = new AlternateIdConstraintImpl(doType.getColumnField("personality"), per);
URIQueryResultList list = new URIQueryResultList();
client.queryByConstraint(constraint, list);
for (URI elem : list) {
assertTrue("The index of .personality should be removed", !elem.equals(id));
}
}
}) };
for (int i = 0; i < tests.length; i++) {
testRaceCondition(tests[i]);
}
}
Aggregations