Search in sources :

Example 11 with DataObjectScanner

use of com.emc.storageos.db.common.DataObjectScanner 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

DataObjectScanner (com.emc.storageos.db.common.DataObjectScanner)11 DbVersionInfo (com.emc.storageos.coordinator.client.model.DbVersionInfo)4 ServiceImpl (com.emc.storageos.coordinator.common.impl.ServiceImpl)4 DbServiceImpl (com.emc.storageos.db.server.impl.DbServiceImpl)3 SchemaUtil (com.emc.storageos.db.server.impl.SchemaUtil)3 ArrayList (java.util.ArrayList)3 CoordinatorClientInetAddressMap (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap)2 DbServiceStatusChecker (com.emc.storageos.db.common.DbServiceStatusChecker)2 DependencyChecker (com.emc.storageos.db.common.DependencyChecker)2 DependencyTracker (com.emc.storageos.db.common.DependencyTracker)2 StubBeaconImpl (com.emc.storageos.db.server.util.StubBeaconImpl)2 PasswordUtils (com.emc.storageos.security.password.PasswordUtils)2 JmxServerWrapper (com.emc.storageos.services.util.JmxServerWrapper)2 File (java.io.File)2 DrUtil (com.emc.storageos.coordinator.client.service.DrUtil)1 DualInetAddress (com.emc.storageos.coordinator.client.service.impl.DualInetAddress)1 ConfigurationImpl (com.emc.storageos.coordinator.common.impl.ConfigurationImpl)1 DbClientContext (com.emc.storageos.db.client.impl.DbClientContext)1 EncryptionProviderImpl (com.emc.storageos.db.client.impl.EncryptionProviderImpl)1 MigrationHandlerImpl (com.emc.storageos.db.server.impl.MigrationHandlerImpl)1