Search in sources :

Example 91 with DataObject

use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.

the class GarbageCollectionExecutorLoop method run.

@Override
public void run() {
    InterProcessLock lock = null;
    try {
        lock = getLockForGC();
        if (lock == null) {
            log.info("Can't get GC lock, wait for next run.");
            return;
        }
    } catch (Exception e) {
        log.warn("Failed to acquire ZK lock for GC", e);
        return;
    }
    long beginTime = System.currentTimeMillis();
    log.info("Begin to GC...");
    try {
        if (!preGC()) {
            // can't run GC now
            return;
        }
        int maxLevels = dependencyTracker.getLevels();
        for (int i = 0; i < maxLevels; i++) {
            log.info("Now processing level {}", i);
            List<Class<? extends DataObject>> list = new ArrayList(dependencyTracker.getTypesInLevel(i));
            Collections.shuffle(list);
            for (Class<? extends DataObject> clazz : list) {
                if (canRunGCOnClass(clazz)) {
                    GarbageCollectionRunnable gc = genGCTask(clazz);
                    futures.add(executorPool.submit(gc));
                }
            }
            waitTasksToComplete();
        }
    } finally {
        try {
            postGC();
        } finally {
            releaseLockForGC(lock);
            log.info("GC is finished, consume time: {} seconds", (System.currentTimeMillis() - beginTime) / 1000);
        }
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) ArrayList(java.util.ArrayList) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) ExecutionException(java.util.concurrent.ExecutionException)

Example 92 with DataObject

use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.

the class GarbageCollectionRunnable method run.

@Override
public void run() {
    log.info("Starting GC loop: type: {}", type.getSimpleName());
    try {
        URIQueryResultList list = getDecommissionedObjectsOfType(type);
        int found = 0, deleted = 0;
        for (Iterator<URI> iterator = list.iterator(); iterator.hasNext(); ) {
            URI uri = iterator.next();
            found++;
            log.debug("GC checks dependencies for {}", uri);
            try {
                if (!canBeGC(uri)) {
                    continue;
                }
                DataObject obj = dbClient.queryObject(type, uri);
                if (obj != null) {
                    log.info("No dependencies found. Removing {}", uri);
                    ((DbClientImpl) dbClient).internalRemoveObjects(obj);
                    deleted++;
                }
            } catch (DatabaseException ex) {
                log.warn("Exception from database access: ", ex);
            // To Do - we should skip the whole loop and retry later?
            }
        }
        if (found > 0) {
            log.info(String.format("Done GC loop: type: %s, processed %s, deleted %s", type.getSimpleName(), found, deleted));
        }
    } catch (Exception e) {
        log.error("Exception e=", e);
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 93 with DataObject

use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.

the class DbsvcTestBase method cleanupDataObjectCF.

protected void cleanupDataObjectCF(Class<? extends DataObject> clazz) {
    List<URI> uriList = _dbClient.queryByType(clazz, false);
    List<DataObject> dataObjects = new ArrayList<DataObject>();
    for (URI uri : uriList) {
        try {
            DataObject dataObject = clazz.newInstance();
            dataObject.setId(uri);
            dataObjects.add(dataObject);
        } catch (Exception e) {
            _log.error("Failed to create instance of Class {} e", clazz, e);
        }
    }
    _dbClient.internalRemoveObjects(dataObjects.toArray(new DataObject[0]));
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) ArrayList(java.util.ArrayList) URI(java.net.URI) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException)

Example 94 with DataObject

use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.

the class DependencyChecker method checkIfAnyActive.

/**
 * Checks if any of the uris from the list are active
 *
 * @param uris
 * @param type
 * @return true if active uri found, false otherwise
 */
public boolean checkIfAnyActive(URIQueryResultList uris, Class<? extends DataObject> type) {
    Iterator<URI> uriIterator = uris.iterator();
    while (uriIterator.hasNext()) {
        int added = 0, found = 0;
        List<URI> urisToQuery = new ArrayList<URI>();
        for (int i = 0; (i < 100) && uriIterator.hasNext(); i++) {
            urisToQuery.add(uriIterator.next());
            added++;
        }
        List<? extends DataObject> results = _dbClient.queryObjectField(type, "inactive", urisToQuery);
        for (DataObject obj : results) {
            found++;
            if (!obj.getInactive()) {
                return true;
            }
        }
        if (found != added) {
            return true;
        }
    }
    return false;
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) ArrayList(java.util.ArrayList) URI(java.net.URI) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint)

Example 95 with DataObject

use of com.emc.storageos.db.client.model.DataObject in project coprhd-controller by CoprHD.

the class DependencyInterceptor method addMutilpleDependencies.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void addMutilpleDependencies(DependencyTracker tracker, Class sourceClazz, ColumnField field) {
    Annotation a = this.getRelationAnnotation(field);
    Class<? extends DataObject>[] refTypes;
    if (a instanceof RelationIndex) {
        refTypes = ((RelationIndex) a).types();
    } else {
        refTypes = ((NamedRelationIndex) a).types();
    }
    for (Class<? extends DataObject> type : refTypes) {
        log.info("{} depends on {}:" + field.getName(), type.getSimpleName(), sourceClazz.getSimpleName());
        tracker.addDependency(type, sourceClazz, field);
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) NamedRelationIndex(com.emc.storageos.db.client.model.NamedRelationIndex) RelationIndex(com.emc.storageos.db.client.model.RelationIndex) Annotation(java.lang.annotation.Annotation)

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