Search in sources :

Example 56 with DataObject

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);
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) NamedURI(com.emc.storageos.db.client.model.NamedURI) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 57 with DataObject

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);
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ColumnList(com.netflix.astyanax.model.ColumnList) List(java.util.List) DataObjectType(com.emc.storageos.db.client.impl.DataObjectType) URI(java.net.URI)

Example 58 with DataObject

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;
}
Also used : ColumnField(com.emc.storageos.db.client.impl.ColumnField) DataObject(com.emc.storageos.db.client.model.DataObject) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 59 with DataObject

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;
}
Also used : HashMap(java.util.HashMap) DataObject(com.emc.storageos.db.client.model.DataObject)

Example 60 with DataObject

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);
    }
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ArrayList(java.util.ArrayList) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet) ContainmentConstraintImpl(com.emc.storageos.db.client.constraint.impl.ContainmentConstraintImpl) ColumnField(com.emc.storageos.db.client.impl.ColumnField) InvocationTargetException(java.lang.reflect.InvocationTargetException) DataObject(com.emc.storageos.db.client.model.DataObject) AbstractChangeTrackingMap(com.emc.storageos.db.client.model.AbstractChangeTrackingMap) DataObject(com.emc.storageos.db.client.model.DataObject) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet)

Aggregations

DataObject (com.emc.storageos.db.client.model.DataObject)154 URI (java.net.URI)62 ArrayList (java.util.ArrayList)53 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)44 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)30 Volume (com.emc.storageos.db.client.model.Volume)26 NamedURI (com.emc.storageos.db.client.model.NamedURI)24 StringSet (com.emc.storageos.db.client.model.StringSet)23 HashMap (java.util.HashMap)22 BlockObject (com.emc.storageos.db.client.model.BlockObject)17 HashSet (java.util.HashSet)17 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)16 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)14 Operation (com.emc.storageos.db.client.model.Operation)13 List (java.util.List)10 Set (java.util.Set)10 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)9 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)8