use of com.emc.storageos.db.client.constraint.DecommissionedConstraint in project coprhd-controller by CoprHD.
the class InternalDbClient method getUpdateList.
public List<URI> getUpdateList(Class<? extends DataObject> clazz) throws DatabaseException {
DataObjectType doType = TypeMap.getDoType(clazz);
if (doType == null) {
throw new IllegalArgumentException();
}
List<URI> keyList = queryByType(clazz, false);
List<URI> inmemKeyList = new ArrayList<URI>();
for (URI uri : keyList) {
inmemKeyList.add(uri);
}
log.info("CF({}): row count by getting all rows= {}", clazz.getSimpleName(), inmemKeyList.size());
URIQueryResultList inactiveResult = new URIQueryResultList();
DecommissionedConstraint constraint = DecommissionedConstraint.Factory.getAllObjectsConstraint(clazz, true);
constraint.setKeyspace(getKeyspace(clazz));
constraint.execute(inactiveResult);
int count = 0;
Iterator<URI> inactiveKeyIter = inactiveResult.iterator();
while (inactiveKeyIter.hasNext()) {
inmemKeyList.remove(inactiveKeyIter.next());
count++;
}
log.info("CF({}): inactive key count= {}", clazz.getSimpleName(), count);
URIQueryResultList activeResult = new URIQueryResultList();
constraint = DecommissionedConstraint.Factory.getAllObjectsConstraint(clazz, false);
constraint.setKeyspace(getKeyspace(clazz));
constraint.execute(activeResult);
count = 0;
Iterator<URI> activeKeyIter = activeResult.iterator();
while (activeKeyIter.hasNext()) {
inmemKeyList.remove(activeKeyIter.next());
count++;
}
log.info("CF({}): active key count: {}", clazz.getSimpleName(), count);
return inmemKeyList;
}
use of com.emc.storageos.db.client.constraint.DecommissionedConstraint in project coprhd-controller by CoprHD.
the class InternalDbClient method migrateToGeoDb.
// only used during migration stage in single thread, so it's safe to suppress
@SuppressWarnings("findbugs:IS2_INCONSISTENT_SYNC")
public <T extends DataObject> void migrateToGeoDb(Class<T> clazz) {
DataObjectType doType = TypeMap.getDoType(clazz);
if (doType == null) {
throw new IllegalArgumentException();
}
if (!KeyspaceUtil.isGlobal(clazz)) {
throw new IllegalArgumentException(String.format("CF %s is not a global resource", clazz.getName()));
}
// this CF ensured to be a global resource
doType.setEncryptionProvider(_geoEncryptionProvider);
// find all the records of CF <T> in local db, similar to queryByType(clazz, false)
URIQueryResultList result = new URIQueryResultList();
DecommissionedConstraint constraint = DecommissionedConstraint.Factory.getAllObjectsConstraint(clazz, null);
constraint.setKeyspace(localContext.getKeyspace());
constraint.execute(result);
Iterator<URI> recIt = result.iterator();
List<URI> batch = getNextBatch(recIt);
while (!batch.isEmpty()) {
Rows<String, CompositeColumnName> rows = queryRowsWithAllColumns(localContext.getKeyspace(), batch, doType.getCF());
Iterator<Row<String, CompositeColumnName>> it = rows.iterator();
while (it.hasNext()) {
Row<String, CompositeColumnName> row = it.next();
try {
if (row.getColumns().size() == 0) {
continue;
}
// can't simply use doType.deserialize(clazz, row, cleanList) below
// since the DataObject instance retrieved in this way doesn't have
// change tracking information within and nothing gets persisted into
// db in the end.
log.info("Migrating record {} to geo db", row.getKey());
DataObject obj = DataObject.createInstance(clazz, URI.create(row.getKey()));
obj.trackChanges();
Iterator<Column<CompositeColumnName>> columnIterator = row.getColumns().iterator();
while (columnIterator.hasNext()) {
Column<CompositeColumnName> column = columnIterator.next();
ColumnField columnField = doType.getColumnField(column.getName().getOne());
if (columnField.isEncrypted()) {
// Decrypt using the local encryption provider and later
// encrypt it again using the geo encryption provider
columnField.deserializeEncryptedColumn(column, obj, _encryptionProvider);
} else {
columnField.deserialize(column, obj);
}
// set changed for ChangeTracking structures
columnField.setChanged(obj);
}
// persist the object into geo db, similar to createObject(objects)
// only that we need to specify the keyspace explicitly here
// also we shouldn't overwrite the creation time
boolean retryFailedWriteWithLocalQuorum = shouldRetryFailedWriteWithLocalQuorum(clazz);
RowMutator mutator = new RowMutator(geoContext.getKeyspace(), retryFailedWriteWithLocalQuorum);
doType.serialize(mutator, obj);
mutator.execute();
} catch (final InstantiationException e) {
throw DatabaseException.fatals.queryFailed(e);
} catch (final IllegalAccessException e) {
throw DatabaseException.fatals.queryFailed(e);
}
}
batch = getNextBatch(recIt);
}
}
use of com.emc.storageos.db.client.constraint.DecommissionedConstraint in project coprhd-controller by CoprHD.
the class TimeConstraintTest method testTimeConstraint.
@Test
public void testTimeConstraint() {
Date before = new Date();
VirtualArray varray = new VirtualArray();
varray.setId(URIUtil.createId(VirtualArray.class));
varray.setLabel("dummy");
varray.setInactive(true);
dbclient.createObject(varray);
List<URI> allVArrays = dbclient.queryByType(VirtualArray.class, false);
Assert.assertNotNull("allVArrays should not be null", allVArrays);
Assert.assertTrue("allVArrays should show the item we created", allVArrays.iterator().hasNext());
// test time constraint against the decommissioned index on the inactive field
Date after = new Date();
DecommissionedConstraint timeConstraint = DecommissionedConstraint.Factory.getTimeConstraint(VirtualArray.class, "inactive", before, after);
URIQueryResultList results = new URIQueryResultList();
dbclient.queryByConstraint(timeConstraint, results);
Assert.assertTrue("time constraint query failed to find our test record", results.iterator().hasNext());
}
use of com.emc.storageos.db.client.constraint.DecommissionedConstraint in project coprhd-controller by CoprHD.
the class DbClientImpl method queryByType.
/**
* @param clazz object type
* @param activeOnly if true, gets only active object ids. NOTE: For classes marked with NoInactiveIndex, there could be 2 cases:
* a. The class does not use .inactive field at all, which means all object instances with .inactive == null
* b. The class does make use of .inactive field, just don't want to put it into Decommissioned index
* When querying type A classes, you can only specify activeOnly == false, otherwise you get nothing
* When querying type B classes, you can specify activeOnly freely as normal classes
* @param <T>
* @return
* @throws DatabaseException
*/
@Override
public <T extends DataObject> List<URI> queryByType(Class<T> clazz, boolean activeOnly) {
tracer.newTracer("read");
if (clazz.getAnnotation(NoInactiveIndex.class) != null) {
// A class not indexed by Decommissioned CF, we can only scan entire CF for it
return scanByType(clazz, activeOnly ? false : null, null, Integer.MAX_VALUE);
}
DataObjectType doType = TypeMap.getDoType(clazz);
if (doType == null) {
throw new IllegalArgumentException();
}
URIQueryResultList result = new URIQueryResultList();
DecommissionedConstraint constraint;
if (activeOnly) {
constraint = DecommissionedConstraint.Factory.getAllObjectsConstraint(clazz, false);
} else {
constraint = DecommissionedConstraint.Factory.getAllObjectsConstraint(clazz, null);
}
constraint.setKeyspace(getKeyspace(clazz));
constraint.execute(result);
return result;
}
Aggregations