From 03dc64616ca03a4ec1e831250f3305f276f53052 Mon Sep 17 00:00:00 2001 From: akshaysw Date: Fri, 14 Jun 2024 10:03:22 +0530 Subject: [PATCH 1/6] add check for product and domain update flow --- .../atlas/repository/store/graph/v2/AtlasEntityStoreV2.java | 3 ++- .../repository/store/graph/v2/preprocessor/PreProcessor.java | 5 +++++ .../v2/preprocessor/datamesh/DataDomainPreProcessor.java | 3 +++ .../v2/preprocessor/datamesh/DataProductPreProcessor.java | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java index 8d793e4740..28be3ced11 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java @@ -1529,7 +1529,8 @@ private EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean boolean skipAuthBaseConditions = diffEntity != null && MapUtils.isEmpty(diffEntity.getCustomAttributes()) && MapUtils.isEmpty(diffEntity.getBusinessAttributes()) && CollectionUtils.isEmpty(diffEntity.getClassifications()) && CollectionUtils.isEmpty(diffEntity.getLabels()); boolean skipAuthMeaningsUpdate = diffEntity != null && MapUtils.isNotEmpty(diffEntity.getRelationshipAttributes()) && diffEntity.getRelationshipAttributes().containsKey("meanings") && diffEntity.getRelationshipAttributes().size() == 1 && MapUtils.isEmpty(diffEntity.getAttributes()); boolean skipAuthStarredDetailsUpdate = diffEntity != null && MapUtils.isEmpty(diffEntity.getRelationshipAttributes()) && MapUtils.isNotEmpty(diffEntity.getAttributes()) && diffEntity.getAttributes().size() == 3 && diffEntity.getAttributes().containsKey(ATTR_STARRED_BY) && diffEntity.getAttributes().containsKey(ATTR_STARRED_COUNT) && diffEntity.getAttributes().containsKey(ATTR_STARRED_DETAILS_LIST); - if (skipAuthBaseConditions && (skipAuthMeaningsUpdate || skipAuthStarredDetailsUpdate)) { + boolean skipAuthCheck = PreProcessor.skipInitialAuthCheckTypesForMesh.contains(entity.getTypeName()); + if (skipAuthCheck || (skipAuthBaseConditions && (skipAuthMeaningsUpdate || skipAuthStarredDetailsUpdate))) { //do nothing, only diff is relationshipAttributes.meanings or starred, allow update } else { AtlasAuthorizationUtils.verifyUpdateEntityAccess(typeRegistry, entityHeader,"update entity: type=" + entity.getTypeName()); diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/PreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/PreProcessor.java index 730ef086bf..de95151a98 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/PreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/PreProcessor.java @@ -23,6 +23,11 @@ public interface PreProcessor { add(DATA_PRODUCT_ENTITY_TYPE); }}; + Set skipInitialAuthCheckTypesForMesh = new HashSet() {{ + add(DATA_DOMAIN_ENTITY_TYPE); + add(DATA_PRODUCT_ENTITY_TYPE); + }}; + void processAttributes(AtlasStruct entity, EntityMutationContext context, EntityMutations.EntityOperation operation) throws AtlasBaseException; default void processDelete(AtlasVertex vertex) throws AtlasBaseException { diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java index 5532ef0ec5..32308cd474 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java @@ -189,6 +189,9 @@ private void processUpdateDomain(AtlasEntity entity, AtlasVertex vertex) throws entity.setAttribute(QUALIFIED_NAME, vertexQnName); } + // Check if authorized to update entities + AtlasAuthorizationUtils.verifyUpdateEntityAccess(typeRegistry, new AtlasEntityHeader(entity),"update entity: type=" + entity.getTypeName()); + RequestContext.get().endMetricRecord(metricRecorder); } diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataProductPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataProductPreProcessor.java index 1e842ead52..79ac5e4474 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataProductPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataProductPreProcessor.java @@ -173,6 +173,9 @@ private void processUpdateProduct(AtlasEntity entity, AtlasVertex vertex) throws entity.setAttribute(QUALIFIED_NAME, vertexQnName); } + // Check if authorized to update entities + AtlasAuthorizationUtils.verifyUpdateEntityAccess(typeRegistry, new AtlasEntityHeader(entity),"update entity: type=" + entity.getTypeName()); + if (isDaapVisibilityChanged) { updateDaapVisibilityPolicy(entity, storedProduct); } From a971da04cc12c035bf563ee20a8659412022cce0 Mon Sep 17 00:00:00 2001 From: akshaysw Date: Fri, 14 Jun 2024 11:40:09 +0530 Subject: [PATCH 2/6] handle review comments --- .../atlas/repository/store/graph/v2/AtlasEntityStoreV2.java | 2 +- .../store/graph/v2/preprocessor/PreProcessor.java | 2 +- .../v2/preprocessor/datamesh/DataDomainPreProcessor.java | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java index 28be3ced11..3baf59b161 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java @@ -1529,7 +1529,7 @@ private EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean boolean skipAuthBaseConditions = diffEntity != null && MapUtils.isEmpty(diffEntity.getCustomAttributes()) && MapUtils.isEmpty(diffEntity.getBusinessAttributes()) && CollectionUtils.isEmpty(diffEntity.getClassifications()) && CollectionUtils.isEmpty(diffEntity.getLabels()); boolean skipAuthMeaningsUpdate = diffEntity != null && MapUtils.isNotEmpty(diffEntity.getRelationshipAttributes()) && diffEntity.getRelationshipAttributes().containsKey("meanings") && diffEntity.getRelationshipAttributes().size() == 1 && MapUtils.isEmpty(diffEntity.getAttributes()); boolean skipAuthStarredDetailsUpdate = diffEntity != null && MapUtils.isEmpty(diffEntity.getRelationshipAttributes()) && MapUtils.isNotEmpty(diffEntity.getAttributes()) && diffEntity.getAttributes().size() == 3 && diffEntity.getAttributes().containsKey(ATTR_STARRED_BY) && diffEntity.getAttributes().containsKey(ATTR_STARRED_COUNT) && diffEntity.getAttributes().containsKey(ATTR_STARRED_DETAILS_LIST); - boolean skipAuthCheck = PreProcessor.skipInitialAuthCheckTypesForMesh.contains(entity.getTypeName()); + boolean skipAuthCheck = PreProcessor.skipUpdateAuthCheckTypes.contains(entity.getTypeName()); if (skipAuthCheck || (skipAuthBaseConditions && (skipAuthMeaningsUpdate || skipAuthStarredDetailsUpdate))) { //do nothing, only diff is relationshipAttributes.meanings or starred, allow update } else { diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/PreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/PreProcessor.java index de95151a98..f0544abad4 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/PreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/PreProcessor.java @@ -23,7 +23,7 @@ public interface PreProcessor { add(DATA_PRODUCT_ENTITY_TYPE); }}; - Set skipInitialAuthCheckTypesForMesh = new HashSet() {{ + Set skipUpdateAuthCheckTypes = new HashSet() {{ add(DATA_DOMAIN_ENTITY_TYPE); add(DATA_PRODUCT_ENTITY_TYPE); }}; diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java index 32308cd474..7249ca9b2a 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java @@ -428,18 +428,18 @@ public void processDelete(AtlasVertex vertex) throws AtlasBaseException { Iterator childrens = getActiveChildrenVertices(vertex, DOMAIN_PARENT_EDGE_LABEL, DATA_PRODUCT_EDGE_LABEL); if (childrens.hasNext()){ - throw new AtlasBaseException("Domain cannot be archived because some subdomains or products are active in this domain"); + throw new AtlasBaseException(AtlasErrorCode.OPERATION_NOT_SUPPORTED, "Domain cannot be archived because some subdomains or products are active in this domain"); } // active stakeholder exists? childrens = getActiveChildrenVertices(vertex, STAKEHOLDER_EDGE_LABEL); if (childrens.hasNext()){ - throw new AtlasBaseException("Domain cannot be archived because some stakeholders are active in this domain"); + throw new AtlasBaseException(AtlasErrorCode.OPERATION_NOT_SUPPORTED, "Domain cannot be archived because some stakeholders are active in this domain"); } // active stakeholder titles exists? if(verifyStakeholderTitleExists(vertex.getProperty(QUALIFIED_NAME, String.class))){ - throw new AtlasBaseException("Domain cannot be archived because some stakeholdersTitles are active in this domain"); + throw new AtlasBaseException(AtlasErrorCode.OPERATION_NOT_SUPPORTED, "Domain cannot be archived because some stakeholdersTitles are active in this domain"); } } From 756a05eb09423925c3d8c592a313642dcaa8867f Mon Sep 17 00:00:00 2001 From: akshaysw Date: Fri, 14 Jun 2024 12:02:30 +0530 Subject: [PATCH 3/6] handle review comments --- .../store/graph/v2/AtlasEntityStoreV2.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java index 3baf59b161..02991e9ec3 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java @@ -1518,22 +1518,23 @@ private EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean // Check if authorized to update entities if (!reqContext.isImportInProgress()) { for (AtlasEntity entity : context.getUpdatedEntities()) { - AtlasEntityHeader entityHeaderWithClassifications = entityRetriever.toAtlasEntityHeaderWithClassifications(entity.getGuid()); - AtlasEntityHeader entityHeader = new AtlasEntityHeader(entity); + if(!PreProcessor.skipUpdateAuthCheckTypes.contains(entity.getTypeName())){ + AtlasEntityHeader entityHeaderWithClassifications = entityRetriever.toAtlasEntityHeaderWithClassifications(entity.getGuid()); + AtlasEntityHeader entityHeader = new AtlasEntityHeader(entity); - if(CollectionUtils.isNotEmpty(entityHeaderWithClassifications.getClassifications())) { - entityHeader.setClassifications(entityHeaderWithClassifications.getClassifications()); - } + if(CollectionUtils.isNotEmpty(entityHeaderWithClassifications.getClassifications())) { + entityHeader.setClassifications(entityHeaderWithClassifications.getClassifications()); + } - AtlasEntity diffEntity = reqContext.getDifferentialEntity(entity.getGuid()); - boolean skipAuthBaseConditions = diffEntity != null && MapUtils.isEmpty(diffEntity.getCustomAttributes()) && MapUtils.isEmpty(diffEntity.getBusinessAttributes()) && CollectionUtils.isEmpty(diffEntity.getClassifications()) && CollectionUtils.isEmpty(diffEntity.getLabels()); - boolean skipAuthMeaningsUpdate = diffEntity != null && MapUtils.isNotEmpty(diffEntity.getRelationshipAttributes()) && diffEntity.getRelationshipAttributes().containsKey("meanings") && diffEntity.getRelationshipAttributes().size() == 1 && MapUtils.isEmpty(diffEntity.getAttributes()); - boolean skipAuthStarredDetailsUpdate = diffEntity != null && MapUtils.isEmpty(diffEntity.getRelationshipAttributes()) && MapUtils.isNotEmpty(diffEntity.getAttributes()) && diffEntity.getAttributes().size() == 3 && diffEntity.getAttributes().containsKey(ATTR_STARRED_BY) && diffEntity.getAttributes().containsKey(ATTR_STARRED_COUNT) && diffEntity.getAttributes().containsKey(ATTR_STARRED_DETAILS_LIST); - boolean skipAuthCheck = PreProcessor.skipUpdateAuthCheckTypes.contains(entity.getTypeName()); - if (skipAuthCheck || (skipAuthBaseConditions && (skipAuthMeaningsUpdate || skipAuthStarredDetailsUpdate))) { - //do nothing, only diff is relationshipAttributes.meanings or starred, allow update - } else { - AtlasAuthorizationUtils.verifyUpdateEntityAccess(typeRegistry, entityHeader,"update entity: type=" + entity.getTypeName()); + AtlasEntity diffEntity = reqContext.getDifferentialEntity(entity.getGuid()); + boolean skipAuthBaseConditions = diffEntity != null && MapUtils.isEmpty(diffEntity.getCustomAttributes()) && MapUtils.isEmpty(diffEntity.getBusinessAttributes()) && CollectionUtils.isEmpty(diffEntity.getClassifications()) && CollectionUtils.isEmpty(diffEntity.getLabels()); + boolean skipAuthMeaningsUpdate = diffEntity != null && MapUtils.isNotEmpty(diffEntity.getRelationshipAttributes()) && diffEntity.getRelationshipAttributes().containsKey("meanings") && diffEntity.getRelationshipAttributes().size() == 1 && MapUtils.isEmpty(diffEntity.getAttributes()); + boolean skipAuthStarredDetailsUpdate = diffEntity != null && MapUtils.isEmpty(diffEntity.getRelationshipAttributes()) && MapUtils.isNotEmpty(diffEntity.getAttributes()) && diffEntity.getAttributes().size() == 3 && diffEntity.getAttributes().containsKey(ATTR_STARRED_BY) && diffEntity.getAttributes().containsKey(ATTR_STARRED_COUNT) && diffEntity.getAttributes().containsKey(ATTR_STARRED_DETAILS_LIST); + if (skipAuthBaseConditions && (skipAuthMeaningsUpdate || skipAuthStarredDetailsUpdate)) { + //do nothing, only diff is relationshipAttributes.meanings or starred, allow update + } else { + AtlasAuthorizationUtils.verifyUpdateEntityAccess(typeRegistry, entityHeader,"update entity: type=" + entity.getTypeName()); + } } } } From 5653f9e65082d2e005f4780bf6e1e8912f2521c7 Mon Sep 17 00:00:00 2001 From: akshaysw Date: Mon, 17 Jun 2024 12:48:04 +0530 Subject: [PATCH 4/6] handle move domain case --- .../preprocessor/datamesh/DataDomainPreProcessor.java | 10 +++++----- .../preprocessor/datamesh/DataProductPreProcessor.java | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java index 7249ca9b2a..31fb0914dd 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java @@ -140,6 +140,10 @@ private void processUpdateDomain(AtlasEntity entity, AtlasVertex vertex) throws validateStakeholderRelationship(entity); String vertexQnName = vertex.getProperty(QUALIFIED_NAME, String.class); + entity.setAttribute(QUALIFIED_NAME, vertexQnName); + // Check if authorized to update entities + AtlasAuthorizationUtils.verifyUpdateEntityAccess(typeRegistry, new AtlasEntityHeader(entity),"update entity: type=" + entity.getTypeName()); + AtlasEntity storedDomain = entityRetriever.toAtlasEntity(vertex); AtlasRelatedObjectId currentParentDomainObjectId = (AtlasRelatedObjectId) storedDomain.getRelationshipAttribute(PARENT_DOMAIN_REL_TYPE); @@ -186,12 +190,8 @@ private void processUpdateDomain(AtlasEntity entity, AtlasVertex vertex) throws if (!domainCurrentName.equals(domainNewName)) { domainExists(domainNewName, currentParentDomainQualifiedName, storedDomain.getGuid()); } - entity.setAttribute(QUALIFIED_NAME, vertexQnName); - } - - // Check if authorized to update entities - AtlasAuthorizationUtils.verifyUpdateEntityAccess(typeRegistry, new AtlasEntityHeader(entity),"update entity: type=" + entity.getTypeName()); + } RequestContext.get().endMetricRecord(metricRecorder); } diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataProductPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataProductPreProcessor.java index 79ac5e4474..328bbb521f 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataProductPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataProductPreProcessor.java @@ -123,6 +123,9 @@ private void processUpdateProduct(AtlasEntity entity, AtlasVertex vertex) throws } String vertexQnName = vertex.getProperty(QUALIFIED_NAME, String.class); + entity.setAttribute(QUALIFIED_NAME, vertexQnName); + // Check if authorized to update entities + AtlasAuthorizationUtils.verifyUpdateEntityAccess(typeRegistry, new AtlasEntityHeader(entity),"update entity: type=" + entity.getTypeName()); AtlasEntity storedProduct = entityRetriever.toAtlasEntity(vertex); AtlasRelatedObjectId currentParentDomainObjectId = (AtlasRelatedObjectId) storedProduct.getRelationshipAttribute(DATA_DOMAIN_REL_TYPE); @@ -170,12 +173,8 @@ private void processUpdateProduct(AtlasEntity entity, AtlasVertex vertex) throws if (!productCurrentName.equals(productNewName)) { productExists(productNewName, currentParentDomainQualifiedName, storedProduct.getGuid()); } - entity.setAttribute(QUALIFIED_NAME, vertexQnName); } - // Check if authorized to update entities - AtlasAuthorizationUtils.verifyUpdateEntityAccess(typeRegistry, new AtlasEntityHeader(entity),"update entity: type=" + entity.getTypeName()); - if (isDaapVisibilityChanged) { updateDaapVisibilityPolicy(entity, storedProduct); } From c7438600b37e82af03a78e625dd87d6605812857 Mon Sep 17 00:00:00 2001 From: PRATHAM2002-DS Date: Tue, 9 Jul 2024 23:31:12 +0530 Subject: [PATCH 5/6] logic to delete stakeholders before archiving domain --- .../store/graph/v2/AtlasEntityStoreV2.java | 2 +- .../datamesh/DataDomainPreProcessor.java | 75 ++++++++++++------- .../StakeholderTitlePreProcessor.java | 1 + 3 files changed, 52 insertions(+), 26 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java index 02991e9ec3..e945a05809 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasEntityStoreV2.java @@ -1834,7 +1834,7 @@ public PreProcessor getPreProcessor(String typeName) { break; case DATA_DOMAIN_ENTITY_TYPE: - preProcessor = new DataDomainPreProcessor(typeRegistry, entityRetriever, graph); + preProcessor = new DataDomainPreProcessor(typeRegistry, entityRetriever, graph, this); break; case DATA_PRODUCT_ENTITY_TYPE: diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java index 31fb0914dd..289de1ddfb 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java @@ -24,15 +24,12 @@ import org.apache.atlas.authorize.AtlasEntityAccessRequest; import org.apache.atlas.authorize.AtlasPrivilege; import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.model.instance.AtlasEntity; -import org.apache.atlas.model.instance.AtlasEntityHeader; -import org.apache.atlas.model.instance.AtlasObjectId; -import org.apache.atlas.model.instance.AtlasRelatedObjectId; -import org.apache.atlas.model.instance.AtlasStruct; -import org.apache.atlas.model.instance.EntityMutations; +import org.apache.atlas.model.instance.*; import org.apache.atlas.repository.graph.GraphHelper; import org.apache.atlas.repository.graphdb.AtlasGraph; import org.apache.atlas.repository.graphdb.AtlasVertex; +import org.apache.atlas.repository.store.graph.AtlasEntityStore; +import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; import org.apache.atlas.repository.store.graph.v2.EntityGraphRetriever; import org.apache.atlas.repository.store.graph.v2.EntityMutationContext; import org.apache.atlas.type.AtlasTypeRegistry; @@ -47,7 +44,7 @@ import static org.apache.atlas.repository.Constants.*; import static org.apache.atlas.repository.graph.GraphHelper.*; import static org.apache.atlas.repository.store.graph.v2.preprocessor.PreProcessorUtils.*; -import static org.apache.atlas.repository.store.graph.v2.preprocessor.datamesh.StakeholderTitlePreProcessor.ATTR_DOMAIN_QUALIFIED_NAMES; +import static org.apache.atlas.repository.store.graph.v2.preprocessor.datamesh.StakeholderTitlePreProcessor.*; import static org.apache.atlas.repository.util.AtlasEntityUtils.mapOf; public class DataDomainPreProcessor extends AbstractDomainPreProcessor { @@ -57,13 +54,15 @@ public class DataDomainPreProcessor extends AbstractDomainPreProcessor { private Map updatedPolicyResources; private EntityGraphRetriever retrieverNoRelation = null; private Map updatedDomainQualifiedNames; + private AtlasEntityStore entityStore; public DataDomainPreProcessor(AtlasTypeRegistry typeRegistry, EntityGraphRetriever entityRetriever, - AtlasGraph graph) { + AtlasGraph graph, AtlasEntityStore entityStore) { super(typeRegistry, entityRetriever, graph); this.updatedPolicyResources = new HashMap<>(); this.retrieverNoRelation = new EntityGraphRetriever(graph, typeRegistry, true); this.updatedDomainQualifiedNames = new HashMap<>(); + this.entityStore = entityStore; } @Override @@ -400,30 +399,42 @@ private void validateStakeholderRelationship(AtlasEntity entity) throws AtlasBas } } - public boolean verifyStakeholderTitleExists(String domainQualifiedName) throws AtlasBaseException { - - List> mustClauseList = new ArrayList(); - mustClauseList.add(mapOf("term", mapOf("__typeName.keyword", STAKEHOLDER_TITLE_ENTITY_TYPE))); + public List getStakeholderTitle(String domainQualifiedName) throws AtlasBaseException { + List> mustClauseList = new ArrayList<>(); mustClauseList.add(mapOf("term", mapOf("__state", "ACTIVE"))); - mustClauseList.add(mapOf("term", mapOf(ATTR_DOMAIN_QUALIFIED_NAMES, domainQualifiedName))); + mustClauseList.add(mapOf("term", mapOf("__typeName.keyword", STAKEHOLDER_TITLE_ENTITY_TYPE))); + List termsList = Arrays.asList( + SUPER_WILDCARD, + STAR, + domainQualifiedName + ); - Map bool = mapOf("must", mustClauseList); - Map dsl = mapOf("query", mapOf("bool", bool)); + Map termsMap = mapOf(ATTR_DOMAIN_QUALIFIED_NAMES, termsList); + Map termsFilter = mapOf("terms", termsMap); + Map filterBool = mapOf("filter", termsFilter); + Map nestedBool = mapOf("bool", filterBool); - List assets = indexSearchPaginated(dsl, null, super.discovery); + mustClauseList.add(mapOf("bool", nestedBool)); - if (CollectionUtils.isNotEmpty(assets)) { - return true; - } + Map topBool = mapOf("must", mustClauseList); + Map topFilter = mapOf("bool", topBool); + Map query = mapOf("filter", topFilter); + Map dsl = mapOf("query", mapOf("bool", query)); + + List assets = indexSearchPaginated(dsl, null, super.discovery); - return false; + return assets; } + + @Override public void processDelete(AtlasVertex vertex) throws AtlasBaseException { - AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("processProductDelete"); + AtlasPerfMetrics.MetricRecorder metricRecorder = RequestContext.get().startMetricRecord("processDomainDelete"); try{ + List stakeHolderGuids = new ArrayList<>(); + // active childrens exists? Iterator childrens = getActiveChildrenVertices(vertex, DOMAIN_PARENT_EDGE_LABEL, DATA_PRODUCT_EDGE_LABEL); @@ -433,13 +444,27 @@ public void processDelete(AtlasVertex vertex) throws AtlasBaseException { // active stakeholder exists? childrens = getActiveChildrenVertices(vertex, STAKEHOLDER_EDGE_LABEL); - if (childrens.hasNext()){ - throw new AtlasBaseException(AtlasErrorCode.OPERATION_NOT_SUPPORTED, "Domain cannot be archived because some stakeholders are active in this domain"); + while (childrens.hasNext()){ + AtlasVertex child = childrens.next(); + AtlasObjectId childId = entityRetriever.toAtlasObjectId(child); + stakeHolderGuids.add(childId.getGuid()); + } + + if (CollectionUtils.isNotEmpty(stakeHolderGuids)) { + entityStore.deleteByIds(stakeHolderGuids); } // active stakeholder titles exists? - if(verifyStakeholderTitleExists(vertex.getProperty(QUALIFIED_NAME, String.class))){ - throw new AtlasBaseException(AtlasErrorCode.OPERATION_NOT_SUPPORTED, "Domain cannot be archived because some stakeholdersTitles are active in this domain"); + List stakeholderTitles = getStakeholderTitle(vertex.getProperty(QUALIFIED_NAME, String.class)); + if (CollectionUtils.isNotEmpty(stakeholderTitles)) { + for (AtlasEntityHeader stakeholderTitle : stakeholderTitles) { + AtlasVertex stakeholderTitleVertex = entityRetriever.getEntityVertex(stakeholderTitle.getGuid()); + AtlasGraphUtilsV2.removeItemFromListPropertyValue(stakeholderTitleVertex, ATTR_DOMAIN_QUALIFIED_NAMES, vertex.getProperty(QUALIFIED_NAME, String.class)); + List domainQualifiedNames = stakeholderTitleVertex.getMultiValuedProperty(ATTR_DOMAIN_QUALIFIED_NAMES, String.class); + if (CollectionUtils.isEmpty(domainQualifiedNames)) { + entityStore.deleteById(stakeholderTitle.getGuid()); + } + } } } diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/StakeholderTitlePreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/StakeholderTitlePreProcessor.java index 97685d1ed6..799f36cb95 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/StakeholderTitlePreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/StakeholderTitlePreProcessor.java @@ -48,6 +48,7 @@ public class StakeholderTitlePreProcessor implements PreProcessor { public static final String STAR = "*/super"; + public static final String SUPER_WILDCARD = "default/domain/*/super"; public static final String ATTR_DOMAIN_QUALIFIED_NAMES = "stakeholderTitleDomainQualifiedNames"; public static final String REL_ATTR_STAKEHOLDERS = "stakeholders"; From 835ecf010b1b908a3b39e24b5642c0f5087d0149 Mon Sep 17 00:00:00 2001 From: PRATHAM2002-DS Date: Tue, 9 Jul 2024 23:37:31 +0530 Subject: [PATCH 6/6] resolved conflicts --- .../graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java | 3 ++- .../v2/preprocessor/datamesh/StakeholderTitlePreProcessor.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java index 289de1ddfb..03e7f17202 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/DataDomainPreProcessor.java @@ -18,6 +18,7 @@ package org.apache.atlas.repository.store.graph.v2.preprocessor.datamesh; +import com.sun.org.apache.bcel.internal.generic.NEW; import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.RequestContext; import org.apache.atlas.authorize.AtlasAuthorizationUtils; @@ -405,7 +406,7 @@ public List getStakeholderTitle(String domainQualifiedName) t mustClauseList.add(mapOf("term", mapOf("__typeName.keyword", STAKEHOLDER_TITLE_ENTITY_TYPE))); List termsList = Arrays.asList( - SUPER_WILDCARD, + NEW_STAR, STAR, domainQualifiedName ); diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/StakeholderTitlePreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/StakeholderTitlePreProcessor.java index 799f36cb95..b262e65ae7 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/StakeholderTitlePreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/datamesh/StakeholderTitlePreProcessor.java @@ -48,7 +48,7 @@ public class StakeholderTitlePreProcessor implements PreProcessor { public static final String STAR = "*/super"; - public static final String SUPER_WILDCARD = "default/domain/*/super"; + public static final String NEW_STAR = "default/domain/*/super"; public static final String ATTR_DOMAIN_QUALIFIED_NAMES = "stakeholderTitleDomainQualifiedNames"; public static final String REL_ATTR_STAKEHOLDERS = "stakeholders";