Search in sources :

Example 16 with ContainmentConstraint

use of com.emc.storageos.db.client.constraint.ContainmentConstraint in project coprhd-controller by CoprHD.

the class DbIndexTest method testRelationIndexMap.

@Test
public void testRelationIndexMap() {
    URI id = URIUtil.createId(ExportGroup.class);
    URI pid0 = URIUtil.createId(Volume.class);
    URI pid1 = URIUtil.createId(Volume.class);
    ContainmentConstraint constraint0 = ContainmentConstraint.Factory.getVolumeExportGroupConstraint(pid0);
    ContainmentConstraint constraint1 = ContainmentConstraint.Factory.getVolumeExportGroupConstraint(pid1);
    {
        ExportGroup obj = new ExportGroup();
        obj.setId(id);
        obj.setVolumes(new StringMap());
        obj.getVolumes().put(pid0.toString(), "1");
        _dbClient.createObject(obj);
    }
    verifyContain(constraint0, id, 1);
    verifyContain(constraint1, null, 0);
    {
        ExportGroup obj = _dbClient.queryObject(ExportGroup.class, id);
        obj.getVolumes().put(pid1.toString(), "2");
        _dbClient.persistObject(obj);
    }
    verifyContain(constraint0, id, 1);
    verifyContain(constraint1, id, 1);
    {
        ExportGroup obj = _dbClient.queryObject(ExportGroup.class, id);
        obj.getVolumes().remove(pid0.toString());
        _dbClient.persistObject(obj);
    }
    verifyContain(constraint1, id, 1);
    verifyContain(constraint0, null, 0);
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) URI(java.net.URI) Test(org.junit.Test)

Example 17 with ContainmentConstraint

use of com.emc.storageos.db.client.constraint.ContainmentConstraint in project coprhd-controller by CoprHD.

the class FileOperationUtils method queryDBFSMounts.

public static List<MountInfo> queryDBFSMounts(URI fsId, DbClient dbClient) {
    _log.info("Querying File System mounts using FsId {}", fsId);
    List<MountInfo> fsMounts = new ArrayList<MountInfo>();
    try {
        ContainmentConstraint containmentConstraint = ContainmentConstraint.Factory.getFileMountsConstraint(fsId);
        List<FileMountInfo> fsDBMounts = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, FileMountInfo.class, containmentConstraint);
        if (fsDBMounts != null && !fsDBMounts.isEmpty()) {
            for (FileMountInfo dbMount : fsDBMounts) {
                MountInfo mountInfo = new MountInfo();
                getMountInfo(dbMount, mountInfo);
                fsMounts.add(mountInfo);
            }
        }
        return fsMounts;
    } catch (Exception e) {
        _log.error("Error while querying {}", e);
    }
    return fsMounts;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ArrayList(java.util.ArrayList) FileMountInfo(com.emc.storageos.db.client.model.FileMountInfo) FileMountInfo(com.emc.storageos.db.client.model.FileMountInfo) MountInfo(com.emc.storageos.model.file.MountInfo)

Example 18 with ContainmentConstraint

use of com.emc.storageos.db.client.constraint.ContainmentConstraint 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)

Example 19 with ContainmentConstraint

use of com.emc.storageos.db.client.constraint.ContainmentConstraint in project coprhd-controller by CoprHD.

the class DependencyChecker method checkDependencies.

/**
 * checks to see if any references exist for this uri
 * uses dependency list created from relational indices
 *
 * @param uri id of the DataObject
 * @param type DataObject class name
 * @param onlyActive if true, checks for active references only (expensive)
 * @param excludeTypes optional list of classes that can be excluded as dependency
 * @return null if no references exist on this uri, return the type of the dependency if exist
 */
public String checkDependencies(URI uri, Class<? extends DataObject> type, boolean onlyActive, List<Class<? extends DataObject>> excludeTypes) {
    List<DependencyTracker.Dependency> dependencies = _dependencyTracker.getDependencies(type);
    // no dependencies - nothing to do
    if (dependencies.isEmpty()) {
        return null;
    }
    for (DependencyTracker.Dependency dependency : dependencies) {
        if (excludeTypes != null) {
            if (excludeTypes.contains(dependency.getType())) {
                continue;
            }
        }
        // Query relational index to see if any dependents exist
        ContainmentConstraint constraint = new ContainmentConstraintImpl(uri, dependency.getType(), dependency.getColumnField());
        URIQueryResultList list = new URIQueryResultList();
        _dbClient.queryByConstraint(constraint, list);
        if (list.iterator().hasNext()) {
            if (!onlyActive || checkIfAnyActive(list, dependency.getType())) {
                _log.info("{}: active references of type {} found", uri.toString(), dependency.getType().getSimpleName());
                return dependency.getType().getSimpleName();
            }
        }
    }
    return null;
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ContainmentConstraintImpl(com.emc.storageos.db.client.constraint.impl.ContainmentConstraintImpl) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 20 with ContainmentConstraint

use of com.emc.storageos.db.client.constraint.ContainmentConstraint in project coprhd-controller by CoprHD.

the class VNXeDeleteShareJob method deleteShareACLsFromDB.

private void deleteShareACLsFromDB(DbClient dbClient, FileObject fsObj) {
    try {
        ContainmentConstraint containmentConstraint = null;
        if (isFile && fsObj != null) {
            _logger.info("Querying DB for Share ACLs of share {} of filesystemId {} ", smbShare.getName(), fsObj.getId());
            containmentConstraint = ContainmentConstraint.Factory.getFileCifsShareAclsConstraint(fsObj.getId());
        } else if (!isFile && fsObj != null) {
            URI snapshotId = fsObj.getId();
            _logger.info("Querying DB for Share ACLs of share {} of SnapshotId {} ", smbShare.getName(), fsObj.getId());
            containmentConstraint = ContainmentConstraint.Factory.getSnapshotCifsShareAclsConstraint(snapshotId);
        }
        List<CifsShareACL> shareAclList = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, CifsShareACL.class, containmentConstraint);
        List<CifsShareACL> deleteAclList = new ArrayList<CifsShareACL>();
        if (!shareAclList.isEmpty()) {
            Iterator<CifsShareACL> shareAclIter = shareAclList.iterator();
            while (shareAclIter.hasNext()) {
                CifsShareACL shareAcl = shareAclIter.next();
                if (smbShare.getName().equals(shareAcl.getShareName())) {
                    shareAcl.setInactive(true);
                    deleteAclList.add(shareAcl);
                }
            }
            if (!deleteAclList.isEmpty()) {
                _logger.info("Deleting ACLs of share {} of filesystem {}", smbShare.getName(), fsObj.getLabel());
                dbClient.persistObject(deleteAclList);
            }
        }
    } catch (Exception e) {
        _logger.error("Error while querying DB for ACL(s) of a share {}", e);
    }
}
Also used : ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ArrayList(java.util.ArrayList) URI(java.net.URI) CifsShareACL(com.emc.storageos.db.client.model.CifsShareACL)

Aggregations

ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)47 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)18 ArrayList (java.util.ArrayList)17 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)15 URI (java.net.URI)15 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)12 ControllerException (com.emc.storageos.volumecontroller.ControllerException)11 URISyntaxException (java.net.URISyntaxException)11 FileExportRule (com.emc.storageos.db.client.model.FileExportRule)10 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)9 FileShare (com.emc.storageos.db.client.model.FileShare)7 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)7 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)6 WorkflowException (com.emc.storageos.workflow.WorkflowException)6 ContainmentConstraintImpl (com.emc.storageos.db.client.constraint.impl.ContainmentConstraintImpl)5 FileMountInfo (com.emc.storageos.db.client.model.FileMountInfo)5 CifsShareACL (com.emc.storageos.db.client.model.CifsShareACL)4 NFSShareACL (com.emc.storageos.db.client.model.NFSShareACL)4 ExportRule (com.emc.storageos.model.file.ExportRule)4 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)4