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);
}
}
}
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);
}
}
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]));
}
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;
}
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);
}
}
Aggregations