use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.
the class TaskMapper method toTask.
public static TaskResourceRep toTask(DataObject resource, List<? extends DataObject> assocResources, String taskId, Operation operation) {
TaskResourceRep task = toTask(resource, taskId, operation);
List<NamedRelatedResourceRep> associatedReps = new ArrayList<NamedRelatedResourceRep>();
for (DataObject assoc : assocResources) {
associatedReps.add(toNamedRelatedResource(assoc));
}
task.setAssociatedResources(associatedReps);
return task;
}
use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.
the class InternalDbClient method resetFields.
public void resetFields(Class<? extends DataObject> clazz, Map<String, ColumnField> setFields, boolean ignore) throws Exception {
DataObjectType doType = TypeMap.getDoType(clazz);
if (doType == null) {
throw new IllegalArgumentException();
}
try {
Keyspace ks = getKeyspace(clazz);
OperationResult<Rows<String, CompositeColumnName>> result = ks.prepareQuery(doType.getCF()).getAllRows().setRowLimit(DEFAULT_PAGE_SIZE).execute();
Iterator<Row<String, CompositeColumnName>> it = result.getResult().iterator();
RemovedColumnsList removedList = new RemovedColumnsList();
List<DataObject> objects = new ArrayList<>(DEFAULT_PAGE_SIZE);
String key = null;
Exception lastEx = null;
while (it.hasNext()) {
try {
Row<String, CompositeColumnName> row = it.next();
if (row.getColumns().size() == 0) {
continue;
}
key = row.getKey();
DataObject obj = DataObject.createInstance(clazz, URI.create(key));
obj.trackChanges();
objects.add(obj);
Iterator<Column<CompositeColumnName>> columnIterator = row.getColumns().iterator();
while (columnIterator.hasNext()) {
Column<CompositeColumnName> column = columnIterator.next();
ColumnField columnField = setFields.get(column.getName().getOne());
if (columnField != null) {
columnField.deserialize(column, obj);
removedList.add(key, column);
}
}
if (objects.size() == DEFAULT_PAGE_SIZE) {
boolean retryFailedWriteWithLocalQuorum = shouldRetryFailedWriteWithLocalQuorum(clazz);
RowMutator mutator = new RowMutator(ks, retryFailedWriteWithLocalQuorum);
_indexCleaner.removeColumnAndIndex(mutator, doType, removedList);
persistObject(objects);
objects.clear();
removedList.clear();
}
} catch (Exception e) {
String message = String.format("DB migration failed reason: reset data key='%s'", key);
log.error(message);
log.error("e=", e);
if (ignore) {
lastEx = e;
continue;
}
throw e;
}
}
if (lastEx != null) {
throw lastEx;
}
if (!objects.isEmpty()) {
boolean retryFailedWriteWithLocalQuorum = shouldRetryFailedWriteWithLocalQuorum(clazz);
RowMutator mutator = new RowMutator(ks, retryFailedWriteWithLocalQuorum);
_indexCleaner.removeColumnAndIndex(mutator, doType, removedList);
persistObject(objects);
}
} catch (ConnectionException e) {
throw DatabaseException.retryables.connectionFailed(e);
} catch (final InstantiationException e) {
throw DatabaseException.fatals.queryFailed(e);
} catch (final IllegalAccessException e) {
throw DatabaseException.fatals.queryFailed(e);
}
}
use of com.emc.storageos.db.client.model.DataObject 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.model.DataObject in project coprhd-controller by CoprHD.
the class InternalDbClient method generateFieldIndex.
// TODO geo : migration only works for local keyspace; need to expand to use local or global
public <T extends DataObject> void generateFieldIndex(Class<T> clazz, String fieldName) {
DataObjectType doType = TypeMap.getDoType(clazz);
if (doType == null) {
throw new IllegalArgumentException();
}
ColumnField columnField = doType.getColumnField(fieldName);
if (columnField == null) {
throw new IllegalArgumentException();
}
List<URI> allrecs = queryByType(clazz, false);
Keyspace ks = getKeyspace(clazz);
Iterator<URI> recIt = allrecs.iterator();
List<URI> batch = getNextBatch(recIt);
while (!batch.isEmpty()) {
Rows<String, CompositeColumnName> rows = queryRowsWithAColumn(ks, batch, doType.getCF(), columnField);
List<T> objects = new ArrayList<T>(rows.size());
Iterator<Row<String, CompositeColumnName>> it = rows.iterator();
while (it.hasNext()) {
Row<String, CompositeColumnName> row = it.next();
try {
if (row.getColumns().size() == 0) {
continue;
}
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.deserialize(column, obj);
}
// set changed for ChangeTracking structures
columnField.setChanged(obj);
objects.add(clazz.cast(obj));
} catch (final InstantiationException e) {
throw DatabaseException.fatals.queryFailed(e);
} catch (final IllegalAccessException e) {
throw DatabaseException.fatals.queryFailed(e);
}
}
updateAndReindexObject(objects);
batch = getNextBatch(recIt);
}
}
use of com.emc.storageos.db.client.model.DataObject 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());
}
Aggregations