use of com.emc.storageos.db.client.constraint.impl.ContainmentConstraintImpl in project coprhd-controller by CoprHD.
the class DbIndexTest method verifyRelationDbIndex.
private void verifyRelationDbIndex(DataObject obj, ColumnField field, Object val, boolean indexByKey, DbClient client) {
switch(field.getType()) {
case Primitive:
{
ContainmentConstraint constraint = new ContainmentConstraintImpl((URI) val, obj.getClass(), field);
verifyContain(constraint, obj.getId(), -1, client);
}
break;
case TrackingMap:
for (String key : ((AbstractChangeTrackingMap<String>) val).keySet()) {
ContainmentConstraint constraint = new ContainmentConstraintImpl(URI.create(key), obj.getClass(), field);
verifyContain(constraint, obj.getId(), -1, client);
}
break;
case TrackingSet:
for (String key : (AbstractChangeTrackingSet<String>) val) {
ContainmentConstraint constraint = new ContainmentConstraintImpl(URI.create(key), obj.getClass(), field);
verifyContain(constraint, obj.getId(), -1, client);
}
break;
case Id:
case NamedURI:
case NestedObject:
case TrackingSetMap:
default:
throw new IllegalArgumentException(String.format("Field type %s is not supported by RelationDbIndex", field.getType().toString()));
}
}
use of com.emc.storageos.db.client.constraint.impl.ContainmentConstraintImpl 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);
}
}
use of com.emc.storageos.db.client.constraint.impl.ContainmentConstraintImpl 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;
}
use of com.emc.storageos.db.client.constraint.impl.ContainmentConstraintImpl in project coprhd-controller by CoprHD.
the class InternalDbClientImpl method getReferUris.
public List<URI> getReferUris(URI targetUri, Class<? extends DataObject> type, Dependency dependency) {
List<URI> references = new ArrayList<>();
if (targetUri == null) {
return references;
}
ContainmentConstraint constraint = new ContainmentConstraintImpl(targetUri, dependency.getType(), dependency.getColumnField());
URIQueryResultList result = new URIQueryResultList();
this.queryByConstraint(constraint, result);
Iterator<URI> resultIt = result.iterator();
if (resultIt.hasNext()) {
references.add(resultIt.next());
}
return references;
}
use of com.emc.storageos.db.client.constraint.impl.ContainmentConstraintImpl in project coprhd-controller by CoprHD.
the class ModelClientImpl method findBy.
@Override
public <T extends DataObject> List<NamedElement> findBy(Class<T> clazz, String columnField, URI id) throws DatabaseException {
LOG.debug("findBy({}, {}, {})", new Object[] { clazz, columnField, id });
DataObjectType doType = TypeMap.getDoType(clazz);
ColumnField field = doType.getColumnField(columnField);
ContainmentConstraint constraint = new ContainmentConstraintImpl(id, clazz, field);
return queryNamedElementsByConstraint(constraint);
}
Aggregations