You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2019/02/20 21:36:03 UTC

[atlas] branch branch-1.0 updated: ATLAS-3051: on container entity-delete, contained entities in composition relationship should be deleted

This is an automated email from the ASF dual-hosted git repository.

madhan pushed a commit to branch branch-1.0
in repository https://gitbox.apache.org/repos/asf/atlas.git


The following commit(s) were added to refs/heads/branch-1.0 by this push:
     new 8ff1dbb  ATLAS-3051: on container entity-delete, contained entities in composition relationship should be deleted
8ff1dbb is described below

commit 8ff1dbb4eeda7a9f4ee29de4ba0089828168a0df
Author: Madhan Neethiraj <ma...@apache.org>
AuthorDate: Tue Feb 19 17:58:10 2019 -0800

    ATLAS-3051: on container entity-delete, contained entities in composition relationship should be deleted
    
    Change-Id: I6a5c2d19cd2bc96a32050150e88108fa63623d97
    (cherry picked from commit a0e4cd1aacb2047ff5af075a43ff9e38c49e2b85)
---
 .../apache/atlas/model/typedef/AtlasStructDef.java |  5 ++-
 .../org/apache/atlas/type/AtlasEntityType.java     | 42 +++++++++++++++++++---
 .../apache/atlas/type/AtlasRelationshipType.java   | 30 +++++++++++++---
 .../ogm/glossary/AtlasGlossaryCategoryDTO.java     |  2 ++
 .../ogm/glossary/AtlasGlossaryTermDTO.java         |  2 ++
 .../ogm/profiles/AtlasSavedSearchDTO.java          | 12 +++++--
 .../ogm/profiles/AtlasUserProfileDTO.java          |  9 ++---
 .../repository/store/graph/v1/DeleteHandlerV1.java |  6 +---
 8 files changed, 86 insertions(+), 22 deletions(-)

diff --git a/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java b/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
index a4d6bed..d244388 100644
--- a/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
+++ b/intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
@@ -289,8 +289,11 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
         public AtlasAttributeDef() { this(null, null); }
 
         public AtlasAttributeDef(String name, String typeName) {
-            this(name, typeName, false, Cardinality.SINGLE, COUNT_NOT_SET, COUNT_NOT_SET, false, false, false, null);
+            this(name, typeName, false, Cardinality.SINGLE);
+        }
 
+        public AtlasAttributeDef(String name, String typeName, boolean isOptional, Cardinality cardinality) {
+            this(name, typeName, isOptional, cardinality, COUNT_NOT_SET, COUNT_NOT_SET, false, false, false, null);
         }
 
         public AtlasAttributeDef(String name, String typeName, boolean isOptional, Cardinality cardinality,
diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java b/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java
index 0d63325..7166caa 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java
@@ -68,6 +68,7 @@ public class AtlasEntityType extends AtlasStructType {
     private Set<String>                              typeAndAllSuperTypes       = Collections.emptySet();
     private Map<String, AtlasAttribute>              relationshipAttributes     = Collections.emptyMap();
     private Map<String, List<AtlasRelationshipType>> relationshipAttributesType = Collections.emptyMap();
+    private List<AtlasAttribute>                     ownedRefAttributes         = Collections.emptyList();
     private String                                   typeAndAllSubTypesQryStr   = "";
     private boolean                                  isInternalType             = false;
     private Map<String, AtlasAttribute>              headerAttributes           = Collections.emptyMap();
@@ -207,12 +208,27 @@ public class AtlasEntityType extends AtlasStructType {
             }
         }
 
-        subTypes = Collections.unmodifiableSet(subTypes);
-        allSubTypes = Collections.unmodifiableSet(allSubTypes);
-        typeAndAllSubTypes = Collections.unmodifiableSet(typeAndAllSubTypes);
-        typeAndAllSubTypesQryStr = ""; // will be computed on next access
-        relationshipAttributes = Collections.unmodifiableMap(relationshipAttributes);
+        ownedRefAttributes = new ArrayList<>();
+
+        for (AtlasAttribute attribute : allAttributes.values()) {
+            if (attribute.isOwnedRef()) {
+                ownedRefAttributes.add(attribute);
+            }
+        }
+
+        for (AtlasAttribute attribute : relationshipAttributes.values()) {
+            if (attribute.isOwnedRef()) {
+                ownedRefAttributes.add(attribute);
+            }
+        }
+
+        subTypes                   = Collections.unmodifiableSet(subTypes);
+        allSubTypes                = Collections.unmodifiableSet(allSubTypes);
+        typeAndAllSubTypes         = Collections.unmodifiableSet(typeAndAllSubTypes);
+        typeAndAllSubTypesQryStr   = ""; // will be computed on next access
+        relationshipAttributes     = Collections.unmodifiableMap(relationshipAttributes);
         relationshipAttributesType = Collections.unmodifiableMap(relationshipAttributesType);
+        ownedRefAttributes         = Collections.unmodifiableList(ownedRefAttributes);
 
         entityDef.setSubTypes(subTypes);
     }
@@ -273,6 +289,10 @@ public class AtlasEntityType extends AtlasStructType {
         return relationshipAttributes;
     }
 
+    public List<AtlasAttribute> getOwnedRefAttributes() {
+        return ownedRefAttributes;
+    }
+
     public AtlasAttribute getRelationshipAttribute(String attributeName) {
         return relationshipAttributes.get(attributeName);
     }
@@ -753,6 +773,18 @@ public class AtlasEntityType extends AtlasStructType {
                         Object    value         = entityObj.getAttribute(attributeName);
                         String    fieldName     = objName + "." + attributeName;
 
+                        if (!attribute.getAttributeDef().getIsOptional()) {
+                            // if required attribute is null, check if attribute value specified in relationship
+                            if (value == null) {
+                                value = entityObj.getRelationshipAttribute(attributeName);
+                            }
+
+                            if (value == null) {
+                                ret = false;
+                                messages.add(fieldName + ": mandatory attribute value missing in type " + getTypeName());
+                            }
+                        }
+
                         if (isValidRelationshipType(dataType) && value != null) {
                             ret = dataType.validateValue(value, fieldName, messages) && ret;
                         }
diff --git a/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java b/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java
index 264c4fc..36e459a 100644
--- a/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java
+++ b/intg/src/main/java/org/apache/atlas/type/AtlasRelationshipType.java
@@ -25,8 +25,10 @@ import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
 import org.apache.atlas.model.typedef.AtlasRelationshipDef;
 import org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory;
 import org.apache.atlas.model.typedef.AtlasRelationshipEndDef;
+import org.apache.atlas.model.typedef.AtlasStructDef;
 import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
 import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
+import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef;
 import org.apache.commons.lang.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -34,6 +36,7 @@ import org.slf4j.LoggerFactory;
 import java.util.Map;
 import java.util.Objects;
 
+import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_OWNED_REF;
 import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection;
 import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.BOTH;
 import static org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection.IN;
@@ -120,9 +123,9 @@ public class AtlasRelationshipType extends AtlasStructType {
             relationshipLabel = getLegacyEdgeLabel(end2Type, endDef2.getName());
         }
 
-        addRelationshipAttributeToEndType(endDef1, end1Type, end2Type.getTypeName(), typeRegistry, relationshipLabel);
+        addRelationshipAttributeToEndType(endDef1, end1Type, end2Type.getTypeName(), typeRegistry, relationshipLabel, relationshipDef.getRelationshipCategory());
 
-        addRelationshipAttributeToEndType(endDef2, end2Type, end1Type.getTypeName(), typeRegistry, relationshipLabel);
+        addRelationshipAttributeToEndType(endDef2, end2Type, end1Type.getTypeName(), typeRegistry, relationshipLabel, relationshipDef.getRelationshipCategory());
 
         // add relationship edge direction information
         addRelationshipEdgeDirection();
@@ -293,7 +296,7 @@ public class AtlasRelationshipType extends AtlasStructType {
     }
 
     private void addRelationshipAttributeToEndType(AtlasRelationshipEndDef endDef, AtlasEntityType entityType, String attrTypeName,
-                                                   AtlasTypeRegistry typeRegistry, String relationshipLabel) throws AtlasBaseException {
+                                                   AtlasTypeRegistry typeRegistry, String relationshipLabel, RelationshipCategory relationshipCategory) throws AtlasBaseException {
 
         String attrName = (endDef != null) ? endDef.getName() : null;
 
@@ -310,12 +313,29 @@ public class AtlasRelationshipType extends AtlasStructType {
         }
 
         if (attribute == null) { //attr doesn't exist in type - is a new relationship attribute
+            Cardinality        cardinality = endDef.getCardinality();
+            boolean            isOptional  = true;
+            AtlasConstraintDef constraint  = null;
 
-            if (endDef.getCardinality() == Cardinality.SET) {
+            if (cardinality == Cardinality.SET) {
                 attrTypeName = AtlasBaseTypeDef.getArrayTypeName(attrTypeName);
             }
 
-            attribute = new AtlasAttribute(entityType, new AtlasAttributeDef(attrName, attrTypeName),
+            if (relationshipCategory == RelationshipCategory.COMPOSITION) {
+                if (endDef.getIsContainer()) {
+                    constraint = new AtlasConstraintDef(CONSTRAINT_TYPE_OWNED_REF);
+                } else {
+                    isOptional = false;
+                }
+            }
+
+            AtlasAttributeDef attributeDef = new AtlasAttributeDef(attrName, attrTypeName, isOptional, cardinality);
+
+            if (constraint != null) {
+                attributeDef.addConstraint(constraint);
+            }
+
+            attribute = new AtlasAttribute(entityType, attributeDef,
                                            typeRegistry.getType(attrTypeName), relationshipLabel);
 
         } else {
diff --git a/repository/src/main/java/org/apache/atlas/repository/ogm/glossary/AtlasGlossaryCategoryDTO.java b/repository/src/main/java/org/apache/atlas/repository/ogm/glossary/AtlasGlossaryCategoryDTO.java
index 92b8faf..a5f1e41 100644
--- a/repository/src/main/java/org/apache/atlas/repository/ogm/glossary/AtlasGlossaryCategoryDTO.java
+++ b/repository/src/main/java/org/apache/atlas/repository/ogm/glossary/AtlasGlossaryCategoryDTO.java
@@ -20,6 +20,7 @@ package org.apache.atlas.repository.ogm.glossary;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.glossary.AtlasGlossaryCategory;
 import org.apache.atlas.model.instance.AtlasEntity;
+import org.apache.atlas.model.instance.AtlasObjectId;
 import org.apache.atlas.model.instance.AtlasRelatedObjectId;
 import org.apache.atlas.model.instance.AtlasRelationship;
 import org.apache.atlas.type.AtlasTypeRegistry;
@@ -123,6 +124,7 @@ public class AtlasGlossaryCategoryDTO extends AbstractGlossaryDTO<AtlasGlossaryC
         ret.setAttribute("name", obj.getName());
         ret.setAttribute("shortDescription", obj.getShortDescription());
         ret.setAttribute("longDescription", obj.getLongDescription());
+        ret.setAttribute("anchor", new AtlasObjectId(obj.getAnchor().getGlossaryGuid()));
 
         if (LOG.isDebugEnabled()) {
             LOG.debug("<== AtlasGlossaryCategoryDTO.toEntity() : {}", ret);
diff --git a/repository/src/main/java/org/apache/atlas/repository/ogm/glossary/AtlasGlossaryTermDTO.java b/repository/src/main/java/org/apache/atlas/repository/ogm/glossary/AtlasGlossaryTermDTO.java
index d1da4e0..a5330a9 100644
--- a/repository/src/main/java/org/apache/atlas/repository/ogm/glossary/AtlasGlossaryTermDTO.java
+++ b/repository/src/main/java/org/apache/atlas/repository/ogm/glossary/AtlasGlossaryTermDTO.java
@@ -20,6 +20,7 @@ package org.apache.atlas.repository.ogm.glossary;
 import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.glossary.AtlasGlossaryTerm;
 import org.apache.atlas.model.instance.AtlasEntity;
+import org.apache.atlas.model.instance.AtlasObjectId;
 import org.apache.atlas.model.instance.AtlasRelatedObjectId;
 import org.apache.atlas.model.instance.AtlasRelationship;
 import org.apache.atlas.type.AtlasTypeRegistry;
@@ -218,6 +219,7 @@ public class AtlasGlossaryTermDTO extends AbstractGlossaryDTO<AtlasGlossaryTerm>
         ret.setAttribute("examples", obj.getExamples());
         ret.setAttribute("abbreviation", obj.getAbbreviation());
         ret.setAttribute("usage", obj.getUsage());
+        ret.setAttribute("anchor", new AtlasObjectId(obj.getAnchor().getGlossaryGuid()));
 
         if (CollectionUtils.isNotEmpty(obj.getClassifications())) {
             if (LOG.isDebugEnabled()) {
diff --git a/repository/src/main/java/org/apache/atlas/repository/ogm/profiles/AtlasSavedSearchDTO.java b/repository/src/main/java/org/apache/atlas/repository/ogm/profiles/AtlasSavedSearchDTO.java
index 68a8744..1a24e67 100644
--- a/repository/src/main/java/org/apache/atlas/repository/ogm/profiles/AtlasSavedSearchDTO.java
+++ b/repository/src/main/java/org/apache/atlas/repository/ogm/profiles/AtlasSavedSearchDTO.java
@@ -21,6 +21,7 @@ import org.apache.atlas.exception.AtlasBaseException;
 import org.apache.atlas.model.discovery.SearchParameters;
 import org.apache.atlas.model.instance.AtlasEntity;
 import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo;
+import org.apache.atlas.model.instance.AtlasObjectId;
 import org.apache.atlas.model.profile.AtlasUserSavedSearch;
 import org.apache.atlas.repository.ogm.AbstractDataTransferObject;
 import org.apache.atlas.type.AtlasType;
@@ -29,22 +30,25 @@ import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Component;
 
 import javax.inject.Inject;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
 
 @Component
 public class AtlasSavedSearchDTO extends AbstractDataTransferObject<AtlasUserSavedSearch> {
+    private static final String ENTITY_TYPE_NAME           = "__AtlasUserSavedSearch";
     private static final String PROPERTY_NAME              = "name";
     private static final String PROPERTY_OWNER_NAME        = "ownerName";
     private static final String PROPERTY_SEARCH_PARAMETERS = "searchParameters";
     private static final String PROPERTY_UNIQUE_NAME       = "uniqueName";
     private static final String PROPERTY_SEARCH_TYPE       = "searchType";
-    private static final String PROPERTY_UI_PARAMETERS       = "uiParameters";
+    private static final String PROPERTY_UI_PARAMETERS     = "uiParameters";
+    private static final String PROPERTY_USER_PROFILE      = "userProfile";
 
     @Inject
     public AtlasSavedSearchDTO(AtlasTypeRegistry typeRegistry) {
-        super(typeRegistry, AtlasUserSavedSearch.class, "__AtlasUserSavedSearch");
+        super(typeRegistry, AtlasUserSavedSearch.class, ENTITY_TYPE_NAME);
     }
 
     @Override
@@ -76,10 +80,14 @@ public class AtlasSavedSearchDTO extends AbstractDataTransferObject<AtlasUserSav
     public AtlasEntity toEntity(AtlasUserSavedSearch obj) throws AtlasBaseException {
         AtlasEntity entity = getDefaultAtlasEntity(obj);
 
+        AtlasObjectId userProfileId = new AtlasObjectId(AtlasUserProfileDTO.ENTITY_TYPE_NAME,
+                                                        Collections.singletonMap(AtlasUserProfileDTO.PROPERTY_USER_NAME, obj.getOwnerName()));
+
         entity.setAttribute(PROPERTY_NAME, obj.getName());
         entity.setAttribute(PROPERTY_OWNER_NAME, obj.getOwnerName());
         entity.setAttribute(PROPERTY_SEARCH_TYPE, obj.getSearchType());
         entity.setAttribute(PROPERTY_UNIQUE_NAME, getUniqueValue(obj));
+        entity.setAttribute(PROPERTY_USER_PROFILE, userProfileId);
 
         if (obj.getSearchParameters() != null) {
             entity.setAttribute(PROPERTY_SEARCH_PARAMETERS, AtlasType.toJson(obj.getSearchParameters()));
diff --git a/repository/src/main/java/org/apache/atlas/repository/ogm/profiles/AtlasUserProfileDTO.java b/repository/src/main/java/org/apache/atlas/repository/ogm/profiles/AtlasUserProfileDTO.java
index 620b148..982d646 100644
--- a/repository/src/main/java/org/apache/atlas/repository/ogm/profiles/AtlasUserProfileDTO.java
+++ b/repository/src/main/java/org/apache/atlas/repository/ogm/profiles/AtlasUserProfileDTO.java
@@ -32,15 +32,16 @@ import java.util.*;
 
 @Component
 public class AtlasUserProfileDTO extends AbstractDataTransferObject<AtlasUserProfile> {
-    private final String PROPERTY_USER_NAME      = "name";
-    private final String PROPERTY_FULL_NAME      = "fullName";
-    private final String PROPERTY_SAVED_SEARCHES = "savedSearches";
+    public  static final String ENTITY_TYPE_NAME        = "__AtlasUserProfile";
+    public  static final String PROPERTY_USER_NAME      = "name";
+    private static final String PROPERTY_FULL_NAME      = "fullName";
+    private static final String PROPERTY_SAVED_SEARCHES = "savedSearches";
 
     private final AtlasSavedSearchDTO savedSearchDTO;
 
     @Inject
     public AtlasUserProfileDTO(AtlasTypeRegistry typeRegistry, AtlasSavedSearchDTO savedSearchDTO) {
-        super(typeRegistry, AtlasUserProfile.class, "__AtlasUserProfile");
+        super(typeRegistry, AtlasUserProfile.class, ENTITY_TYPE_NAME);
 
         this.savedSearchDTO = savedSearchDTO;
     }
diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
index b2bd896..d2f5fda 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
@@ -202,11 +202,7 @@ public abstract class DeleteHandlerV1 {
 
             vertexInfoMap.put(guid, new GraphHelper.VertexInfo(entity, vertex));
 
-            for (AtlasStructType.AtlasAttribute attributeInfo : entityType.getAllAttributes().values()) {
-                if (!attributeInfo.isOwnedRef()) {
-                    continue;
-                }
-
+            for (AtlasStructType.AtlasAttribute attributeInfo : entityType.getOwnedRefAttributes()) {
                 String       edgeLabel    = attributeInfo.getRelationshipEdgeLabel();
                 AtlasType    attrType     = attributeInfo.getAttributeType();
                 TypeCategory typeCategory = attrType.getTypeCategory();