You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ni...@apache.org on 2020/09/21 05:28:50 UTC

[atlas] branch master updated (9b1d4c3 -> 74229d8)

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

nixon pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git.


    from 9b1d4c3  ATLAS-3934: docker scripts to build and run Apache Atlas in containers
     new 4bc1c04  ATLAS-3946 : Filter TypeDefs in Metrics API and show types data accordingly
     new 74229d8  ATLAS-3947 : Skip authorization for read of _ALL_ENTITY_TYPES and _ALL_CLASSIFICATION_TYPES types

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../store/graph/AtlasTypeDefGraphStore.java        |   2 +
 .../org/apache/atlas/services/MetricsService.java  | 104 ++++++++++++++-------
 .../atlas/web/security/AtlasSecurityConfig.java    |   3 +-
 3 files changed, 71 insertions(+), 38 deletions(-)


[atlas] 01/02: ATLAS-3946 : Filter TypeDefs in Metrics API and show types data accordingly

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nixon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git

commit 4bc1c04adeba25254fce924e318c26fc9b72a8dd
Author: nixonrodrigues <ni...@apache.org>
AuthorDate: Thu Sep 17 14:38:12 2020 +0530

    ATLAS-3946 : Filter TypeDefs in Metrics API and show types data accordingly
---
 .../org/apache/atlas/services/MetricsService.java  | 104 ++++++++++++++-------
 .../atlas/web/security/AtlasSecurityConfig.java    |   3 +-
 2 files changed, 69 insertions(+), 38 deletions(-)

diff --git a/repository/src/main/java/org/apache/atlas/services/MetricsService.java b/repository/src/main/java/org/apache/atlas/services/MetricsService.java
index 7917f32..e721108 100644
--- a/repository/src/main/java/org/apache/atlas/services/MetricsService.java
+++ b/repository/src/main/java/org/apache/atlas/services/MetricsService.java
@@ -19,10 +19,16 @@ package org.apache.atlas.services;
 
 import org.apache.atlas.annotation.AtlasService;
 import org.apache.atlas.annotation.GraphTransaction;
+import org.apache.atlas.authorize.AtlasAuthorizationUtils;
+import org.apache.atlas.authorize.AtlasTypesDefFilterRequest;
 import org.apache.atlas.model.instance.AtlasEntity.Status;
 import org.apache.atlas.model.metrics.AtlasMetrics;
+import org.apache.atlas.model.typedef.AtlasClassificationDef;
+import org.apache.atlas.model.typedef.AtlasEntityDef;
+import org.apache.atlas.model.typedef.AtlasTypesDef;
 import org.apache.atlas.repository.graphdb.AtlasGraph;
 import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2;
+import org.apache.atlas.type.AtlasClassificationType;
 import org.apache.atlas.type.AtlasEntityType;
 import org.apache.atlas.type.AtlasTypeRegistry;
 import org.apache.atlas.util.AtlasMetricJVMUtil;
@@ -32,6 +38,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.inject.Inject;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
@@ -86,8 +93,11 @@ public class MetricsService {
     @SuppressWarnings("unchecked")
     @GraphTransaction
     public AtlasMetrics getMetrics() {
-        Collection<String> entityDefNames               = typeRegistry.getAllEntityDefNames();
-        Collection<String> classificationDefNames       = typeRegistry.getAllClassificationDefNames();
+
+        final AtlasTypesDef typesDef = getTypesDef();
+
+        Collection<AtlasEntityDef> entityDefs = typesDef.getEntityDefs();
+        Collection<AtlasClassificationDef> classificationDefs = typesDef.getClassificationDefs();
         Map<String, Long>  activeEntityCount            = new HashMap<>();
         Map<String, Long>  deletedEntityCount           = new HashMap<>();
         Map<String, Long>  shellEntityCount             = new HashMap<>();
@@ -97,22 +107,22 @@ public class MetricsService {
         Map<String, Long> shellEntityCountTypeAndSubTypes = new HashMap<>();
 
 
-        long               unusedTypeCount        = 0;
-        long               totalEntities          = 0;
+        long unusedTypeCount = 0;
+        long totalEntities = 0;
 
-        if (entityDefNames != null) {
-            for (String entityDefName : entityDefNames) {
-                long activeCount  = getTypeCount(entityDefName, ACTIVE);
-                long deletedCount = getTypeCount(entityDefName, DELETED);
-                long shellCount = getTypeShellCount(entityDefName);
+        if (entityDefs != null) {
+            for (AtlasEntityDef entityDef : entityDefs) {
+                long activeCount  = getTypeCount(entityDef.getName(), ACTIVE);
+                long deletedCount = getTypeCount(entityDef.getName(), DELETED);
+                long shellCount = getTypeShellCount(entityDef.getName());
 
                 if (activeCount > 0) {
-                    activeEntityCount.put(entityDefName, activeCount);
+                    activeEntityCount.put(entityDef.getName(), activeCount);
                     totalEntities += activeCount;
                 }
 
                 if (deletedCount > 0) {
-                    deletedEntityCount.put(entityDefName, deletedCount);
+                    deletedEntityCount.put(entityDef.getName(), deletedCount);
                     totalEntities += deletedCount;
                 }
 
@@ -120,41 +130,44 @@ public class MetricsService {
                     unusedTypeCount++;
                 }
 
-                if(shellCount>0){
-                    shellEntityCount.put(entityDefName, shellCount);
+                if (shellCount > 0) {
+                    shellEntityCount.put(entityDef.getName(), shellCount);
                 }
             }
-        }
 
-        Collection<AtlasEntityType> allEntityTypes = typeRegistry.getAllEntityTypes();
-        for (AtlasEntityType entityType : allEntityTypes) {
-            long entityActiveCount  = 0;
-            long entityDeletedCount = 0;
-            long entityShellCount   = 0;
 
-            for (String type : entityType.getTypeAndAllSubTypes()) {
-                entityActiveCount  += activeEntityCount.get(type) == null ? 0 : activeEntityCount.get(type);
-                entityDeletedCount += deletedEntityCount.get(type) == null ? 0 : deletedEntityCount.get(type);
-                entityShellCount   += shellEntityCount.get(type) == null ? 0 : shellEntityCount.get(type);
-            }
+            for (AtlasEntityDef entityDef : entityDefs) {
+                AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityDef.getName());
 
-            if (entityActiveCount > 0) {
-                activeEntityCountTypeAndSubTypes.put(entityType.getTypeName(), entityActiveCount);
-            }
-            if (entityDeletedCount > 0) {
-                deletedEntityCountTypeAndSubTypes.put(entityType.getTypeName(), entityDeletedCount);
-            }
-            if (entityShellCount > 0) {
-                shellEntityCountTypeAndSubTypes.put(entityType.getTypeName(), entityShellCount);
+                long entityActiveCount = 0;
+                long entityDeletedCount = 0;
+                long entityShellCount = 0;
+
+                for (String type : entityType.getTypeAndAllSubTypes()) {
+                    entityActiveCount += activeEntityCount.get(type) == null ? 0 : activeEntityCount.get(type);
+                    entityDeletedCount += deletedEntityCount.get(type) == null ? 0 : deletedEntityCount.get(type);
+                    entityShellCount += shellEntityCount.get(type) == null ? 0 : shellEntityCount.get(type);
+                }
+
+                if (entityActiveCount > 0) {
+                    activeEntityCountTypeAndSubTypes.put(entityType.getTypeName(), entityActiveCount);
+                }
+                if (entityDeletedCount > 0) {
+                    deletedEntityCountTypeAndSubTypes.put(entityType.getTypeName(), entityDeletedCount);
+                }
+                if (entityShellCount > 0) {
+                    shellEntityCountTypeAndSubTypes.put(entityType.getTypeName(), entityShellCount);
+                }
             }
         }
 
-        if (classificationDefNames != null) {
-            for (String classificationDefName : classificationDefNames) {
-                long count = getTypeCount(classificationDefName, ACTIVE);
+
+        if (classificationDefs != null) {
+            for (AtlasClassificationDef classificationDef : classificationDefs) {
+                long count = getTypeCount(classificationDef.getName(), ACTIVE);
 
                 if (count > 0) {
-                    taggedEntityCount.put(classificationDefName, count);
+                    taggedEntityCount.put(classificationDef.getName(), count);
                 }
             }
         }
@@ -226,4 +239,23 @@ public class MetricsService {
 
         return CollectionUtils.isNotEmpty(allTagNames) ? allTagNames.size() : 0;
     }
+
+    private AtlasTypesDef getTypesDef() {
+        AtlasTypesDef ret = new AtlasTypesDef();
+
+        Collection<AtlasEntityDef> entityDefs = typeRegistry.getAllEntityDefs();
+        if (CollectionUtils.isNotEmpty(entityDefs)) {
+            ret.getEntityDefs().addAll(entityDefs);
+        }
+
+        Collection<AtlasClassificationDef> classificationTypes = typeRegistry.getAllClassificationDefs();
+        if (CollectionUtils.isNotEmpty(classificationTypes)) {
+            ret.getClassificationDefs().addAll(classificationTypes);
+        }
+
+        AtlasAuthorizationUtils.filterTypesDef(new AtlasTypesDefFilterRequest(ret));
+
+        return ret;
+    }
+
 }
\ No newline at end of file
diff --git a/webapp/src/main/java/org/apache/atlas/web/security/AtlasSecurityConfig.java b/webapp/src/main/java/org/apache/atlas/web/security/AtlasSecurityConfig.java
index e74a9e9..c2b0574 100644
--- a/webapp/src/main/java/org/apache/atlas/web/security/AtlasSecurityConfig.java
+++ b/webapp/src/main/java/org/apache/atlas/web/security/AtlasSecurityConfig.java
@@ -171,8 +171,7 @@ public class AtlasSecurityConfig extends WebSecurityConfigurerAdapter {
             "/n/js/**",
             "/ieerror.html",
             "/migration-status.html",
-            "/api/atlas/admin/status",
-            "/api/atlas/admin/metrics"));
+            "/api/atlas/admin/status"));
 
         if (!keycloakEnabled) {
             matchers.add("/login.jsp");


[atlas] 02/02: ATLAS-3947 : Skip authorization for read of _ALL_ENTITY_TYPES and _ALL_CLASSIFICATION_TYPES types

Posted by ni...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nixon pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git

commit 74229d87043bc55a4dd83cad37db59031d624af5
Author: nixonrodrigues <ni...@apache.org>
AuthorDate: Thu Sep 17 15:49:50 2020 +0530

    ATLAS-3947 : Skip authorization for read of _ALL_ENTITY_TYPES and _ALL_CLASSIFICATION_TYPES types
    
    Change-Id: Iecd8ab427510cb37aaff99e420c25a579631dd4d
---
 .../org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
index 458ec49..9aa8fbc 100644
--- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
+++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
@@ -270,6 +270,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
             if (ret == null) {
                 throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
             }
+            return ret;
         }
 
         AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_READ, ret), "read type ", name);
@@ -322,6 +323,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
             if (ret == null) {
                 throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
             }
+            return ret;
         }
 
         AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_READ, ret), "read type ", name);