Search in sources :

Example 1 with DependencyTracker

use of com.emc.storageos.db.common.DependencyTracker in project coprhd-controller by CoprHD.

the class DbCli method queryAndDeleteObject.

/**
 * Query for a record with the given id and type, and print the contents in human readable format
 *
 * @param id
 * @param clazz
 * @param <T>
 */
private <T extends DataObject> boolean queryAndDeleteObject(URI id, Class<T> clazz, boolean force) throws Exception {
    if (_dependencyChecker == null) {
        DependencyTracker dependencyTracker = dataObjectscanner.getDependencyTracker();
        _dependencyChecker = new DependencyChecker(_dbClient, dependencyTracker);
    }
    if (_dependencyChecker.checkDependencies(id, clazz, false) != null) {
        if (!force) {
            System.out.println(String.format("Failed to delete the object %s: there are active dependencies", id));
            return false;
        }
        log.info("Force to delete object {} that has active dependencies", id);
    }
    T object = queryObject(id, clazz);
    if (object == null) {
        System.out.println(String.format("The object %s has already been deleted", id));
        return false;
    }
    if ((object.canBeDeleted() == null) || force) {
        if (object.canBeDeleted() != null) {
            log.info("Force to delete object {} that can't be deleted", id);
        }
        _dbClient.internalRemoveObjects(object);
        return true;
    }
    System.out.println(String.format("The object %s can't be deleted", id));
    return false;
}
Also used : DependencyChecker(com.emc.storageos.db.common.DependencyChecker) DependencyTracker(com.emc.storageos.db.common.DependencyTracker)

Example 2 with DependencyTracker

use of com.emc.storageos.db.common.DependencyTracker in project coprhd-controller by CoprHD.

the class DBClient method printDependencies.

public void printDependencies(String cfName, URI uri) {
    final Class type = _cfMap.get(cfName);
    if (type == null) {
        System.err.println("Unknown Column Family: " + cfName);
        return;
    }
    DataObjectScanner dataObjectscanner = (DataObjectScanner) ctx.getBean("dataObjectScanner");
    DependencyTracker dependencyTracker = dataObjectscanner.getDependencyTracker();
    String output = uri == null ? type.getSimpleName() : uri.toString();
    printDependencies(type, uri, true, "", output, dependencyTracker);
    if (uri != null) {
        if (foundReference) {
            System.out.println("\nFound references of this id: " + uri);
        } else {
            System.out.println("\nNo reference was found of this id: " + uri);
        }
    }
}
Also used : DataObjectScanner(com.emc.storageos.db.common.DataObjectScanner) DependencyTracker(com.emc.storageos.db.common.DependencyTracker)

Example 3 with DependencyTracker

use of com.emc.storageos.db.common.DependencyTracker in project coprhd-controller by CoprHD.

the class DBClient method queryAndDeleteObject.

/**
 * Query for a record with the given id and type, and print the contents in human readable format
 *
 * @param id
 * @param clazz
 * @param <T>
 */
private <T extends DataObject> boolean queryAndDeleteObject(URI id, Class<T> clazz, boolean force) throws Exception {
    DependencyTracker dependencyTracker = null;
    if (_dependencyChecker == null) {
        DataObjectScanner dataObjectscanner = (DataObjectScanner) ctx.getBean("dataObjectScanner");
        dependencyTracker = dataObjectscanner.getDependencyTracker();
        _dependencyChecker = new DependencyChecker(_dbClient, dependencyTracker);
    }
    String reference = _dependencyChecker.checkDependencies(id, clazz, false);
    if (reference != null) {
        if (!force) {
            System.err.println(String.format("Failed to delete the object %s: there are active dependencies", id));
            printReferenceWhenDeletingFailed(id, clazz, dependencyTracker);
            return false;
        }
        log.info("Force to delete object {} that has active dependencies", id);
    }
    T object = queryObject(id, clazz);
    if (object == null) {
        System.err.println(String.format("The object %s has already been deleted", id));
        return false;
    }
    if ((object.canBeDeleted() == null) || force) {
        if (object.canBeDeleted() != null) {
            log.info("Force to delete object {} that can't be deleted", id);
        }
        _dbClient.internalRemoveObjects(object);
        return true;
    }
    System.err.println(String.format("The object %s can't be deleted", id));
    printReferenceWhenDeletingFailed(id, clazz, dependencyTracker);
    return false;
}
Also used : DataObjectScanner(com.emc.storageos.db.common.DataObjectScanner) DependencyChecker(com.emc.storageos.db.common.DependencyChecker) DependencyTracker(com.emc.storageos.db.common.DependencyTracker)

Aggregations

DependencyTracker (com.emc.storageos.db.common.DependencyTracker)3 DataObjectScanner (com.emc.storageos.db.common.DataObjectScanner)2 DependencyChecker (com.emc.storageos.db.common.DependencyChecker)2