use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.
the class BlockSnapshotSessionMigrationTest method prepareSingleSnapshotData.
/**
* Prepares single volume test data.
*/
private void prepareSingleSnapshotData() {
// A list of database object instances to be created.
ArrayList<DataObject> newObjectsToBeCreated = new ArrayList<DataObject>();
// Create some snapshots on a storage system that does not support
// snapshot sessions. Snapshots on VNX do not currently support
// snapshot sessions.
StorageSystem system = new StorageSystem();
URI systemURI = URIUtil.createId(StorageSystem.class);
system.setId(systemURI);
system.setSystemType(DiscoveredDataObject.Type.vnxblock.name());
newObjectsToBeCreated.add(system);
for (int i = 0; i < SNAPSHOT_COUNT; i++) {
BlockSnapshot snapshot = new BlockSnapshot();
URI snapshotURI = URIUtil.createId(BlockSnapshot.class);
snapshot.setId(snapshotURI);
snapshot.setLabel(BASE_SNAPSHOT_NAME + i);
snapshot.setSnapsetLabel(snapshot.getLabel());
URI projectURI = URIUtil.createId(Project.class);
snapshot.setProject(new NamedURI(projectURI, PROJECT_NAME));
URI parentURI = URIUtil.createId(Volume.class);
snapshot.setParent(new NamedURI(parentURI, PARENT_NAME + i));
snapshot.setSettingsInstance(BASE_SETTINGS_INSTANCE + i);
snapshot.setStorageController(systemURI);
newObjectsToBeCreated.add(snapshot);
}
// Now create some BlockSnapshot instances on a storage system
// that does support snapshot sessions. VMAX3 is the only storage
// system for which we currently support snapshot sessions. We
// set up the system so that the method on StorageSystem
// "checkIfVmax3" returns true.
system = new StorageSystem();
systemURI = URIUtil.createId(StorageSystem.class);
system.setId(systemURI);
system.setSystemType(DiscoveredDataObject.Type.vmax.name());
system.setFirmwareVersion(VMAX3_SYSTEM_FW_VERSION);
newObjectsToBeCreated.add(system);
for (int i = 0; i < SNAPVX_SNAPSHOT_COUNT; i++) {
BlockSnapshot snapshot = new BlockSnapshot();
URI snapshotURI = URIUtil.createId(BlockSnapshot.class);
snapshot.setId(snapshotURI);
snapshot.setLabel(BASE_SNAPVX_SNAPSHOT_NAME + i);
snapshot.setSnapsetLabel(snapshot.getLabel());
URI projectURI = URIUtil.createId(Project.class);
snapshot.setProject(new NamedURI(projectURI, PROJECT_NAME));
URI parentURI = URIUtil.createId(Volume.class);
snapshot.setParent(new NamedURI(parentURI, PARENT_NAME + i));
snapshot.setSettingsInstance(BASE_SETTINGS_INSTANCE + i);
snapshot.setStorageController(systemURI);
newObjectsToBeCreated.add(snapshot);
_linkedTargetsMap.put(snapshotURI.toString(), snapshot);
}
// Create the database objects.
_dbClient.createObject(newObjectsToBeCreated);
}
use of com.emc.storageos.db.client.model.DataObject 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.model.DataObject 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.model.DataObject in project coprhd-controller by CoprHD.
the class DataObjectUtils method mapByProperty.
/**
* Utility functions that returns a map of a collection of objects
* by a selected property. If the property is null for an object, the
* object will not be added to the map.
*
* @param col the objects collection
* @param property the property name
* @return a map of object by their property
*/
public static <T extends DataObject> Map<String, T> mapByProperty(Collection<T> col, String property) {
Map<String, T> map = new HashMap<String, T>();
Object prop = null;
for (T t : col) {
prop = getPropertyValue(t.getClass(), t, property);
if (prop != null) {
map.put(prop.toString(), t);
}
}
return map;
}
use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.
the class DbDependencyPurger method purge.
private <T extends DataObject> void purge(T dataObj, Set<URI> visited) throws DatabaseException {
if (dataObj == null || visited.contains(dataObj.getId())) {
return;
}
visited.add(dataObj.getId());
Class<? extends DataObject> type = dataObj.getClass();
List<DependencyTracker.Dependency> dependencyList = _dependencyTracker.getDependencies(type);
try {
for (DependencyTracker.Dependency dependence : dependencyList) {
// Query relational index to see if any dependents exist
Class<? extends DataObject> childType = dependence.getType();
ColumnField childField = dependence.getColumnField();
ContainmentConstraint constraint = new ContainmentConstraintImpl(dataObj.getId(), childType, childField);
URIQueryResultList list = new URIQueryResultList();
_dbClient.queryByConstraint(constraint, list);
if (!list.iterator().hasNext()) {
continue;
}
// used to remove efficiently identical URIs from the list.
HashSet<URI> childSet = new HashSet();
while (list.iterator().hasNext()) {
childSet.clear();
while (list.iterator().hasNext()) {
childSet.add(list.iterator().next());
if (childSet.size() >= MAX_PERSISTENCE_LIMIT) {
break;
}
}
List<URI> childUriList = new ArrayList(childSet);
List<? extends DataObject> children = _dbClient.queryObjectField(childType, childField.getName(), childUriList);
List<DataObject> decommissionedChildren = new ArrayList();
for (DataObject childObj : children) {
switch(childField.getType()) {
case TrackingSet:
case TrackingMap:
// assume @indexByKey is set
java.beans.PropertyDescriptor pd = childField.getPropertyDescriptor();
Object fieldValue = pd.getReadMethod().invoke(childObj);
boolean deactivateChildObj = false;
if (fieldValue != null) {
// should be always true.
if (AbstractChangeTrackingMap.class.isAssignableFrom(pd.getPropertyType())) {
AbstractChangeTrackingMap<?> trackingMap = (AbstractChangeTrackingMap<?>) fieldValue;
trackingMap.remove(dataObj.getId().toString());
if (trackingMap.isEmpty() && childField.deactivateIfEmpty()) {
deactivateChildObj = true;
}
} else if (AbstractChangeTrackingSet.class.isAssignableFrom(pd.getPropertyType())) {
AbstractChangeTrackingSet trackingSet = (AbstractChangeTrackingSet) fieldValue;
trackingSet.remove(dataObj.getId().toString());
if (trackingSet.isEmpty() && childField.deactivateIfEmpty()) {
deactivateChildObj = true;
}
}
if (deactivateChildObj) {
purge(childObj, visited);
childObj.setInactive(true);
_log.info("Deactivated db_object: type = {}, id = {}", childType.toString(), childObj.getId());
}
}
break;
default:
{
purge(childObj, visited);
childObj.setInactive(true);
_log.info("Deactivated db_object: type = {}, id = {}", childType.toString(), childObj.getId());
}
}
decommissionedChildren.add(childObj);
}
_dbClient.persistObject(decommissionedChildren);
}
}
}// should never get here....
catch (IllegalAccessException | InvocationTargetException | IllegalArgumentException e) {
_log.error("Unexpected purge error", e);
throw DatabaseException.fatals.purgeFailed(e);
}
}
Aggregations