Commit 4bc1c04a by nixonrodrigues

ATLAS-3946 : Filter TypeDefs in Metrics API and show types data accordingly

parent 9b1d4c38
...@@ -19,10 +19,16 @@ package org.apache.atlas.services; ...@@ -19,10 +19,16 @@ package org.apache.atlas.services;
import org.apache.atlas.annotation.AtlasService; import org.apache.atlas.annotation.AtlasService;
import org.apache.atlas.annotation.GraphTransaction; 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.instance.AtlasEntity.Status;
import org.apache.atlas.model.metrics.AtlasMetrics; 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.graphdb.AtlasGraph;
import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2; 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.AtlasEntityType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.util.AtlasMetricJVMUtil; import org.apache.atlas.util.AtlasMetricJVMUtil;
...@@ -32,6 +38,7 @@ import org.slf4j.Logger; ...@@ -32,6 +38,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -86,8 +93,11 @@ public class MetricsService { ...@@ -86,8 +93,11 @@ public class MetricsService {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@GraphTransaction @GraphTransaction
public AtlasMetrics getMetrics() { 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> activeEntityCount = new HashMap<>();
Map<String, Long> deletedEntityCount = new HashMap<>(); Map<String, Long> deletedEntityCount = new HashMap<>();
Map<String, Long> shellEntityCount = new HashMap<>(); Map<String, Long> shellEntityCount = new HashMap<>();
...@@ -100,19 +110,19 @@ public class MetricsService { ...@@ -100,19 +110,19 @@ public class MetricsService {
long unusedTypeCount = 0; long unusedTypeCount = 0;
long totalEntities = 0; long totalEntities = 0;
if (entityDefNames != null) { if (entityDefs != null) {
for (String entityDefName : entityDefNames) { for (AtlasEntityDef entityDef : entityDefs) {
long activeCount = getTypeCount(entityDefName, ACTIVE); long activeCount = getTypeCount(entityDef.getName(), ACTIVE);
long deletedCount = getTypeCount(entityDefName, DELETED); long deletedCount = getTypeCount(entityDef.getName(), DELETED);
long shellCount = getTypeShellCount(entityDefName); long shellCount = getTypeShellCount(entityDef.getName());
if (activeCount > 0) { if (activeCount > 0) {
activeEntityCount.put(entityDefName, activeCount); activeEntityCount.put(entityDef.getName(), activeCount);
totalEntities += activeCount; totalEntities += activeCount;
} }
if (deletedCount > 0) { if (deletedCount > 0) {
deletedEntityCount.put(entityDefName, deletedCount); deletedEntityCount.put(entityDef.getName(), deletedCount);
totalEntities += deletedCount; totalEntities += deletedCount;
} }
...@@ -120,14 +130,15 @@ public class MetricsService { ...@@ -120,14 +130,15 @@ public class MetricsService {
unusedTypeCount++; unusedTypeCount++;
} }
if(shellCount>0){ if (shellCount > 0) {
shellEntityCount.put(entityDefName, shellCount); shellEntityCount.put(entityDef.getName(), shellCount);
}
} }
} }
Collection<AtlasEntityType> allEntityTypes = typeRegistry.getAllEntityTypes();
for (AtlasEntityType entityType : allEntityTypes) { for (AtlasEntityDef entityDef : entityDefs) {
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityDef.getName());
long entityActiveCount = 0; long entityActiveCount = 0;
long entityDeletedCount = 0; long entityDeletedCount = 0;
long entityShellCount = 0; long entityShellCount = 0;
...@@ -148,13 +159,15 @@ public class MetricsService { ...@@ -148,13 +159,15 @@ public class MetricsService {
shellEntityCountTypeAndSubTypes.put(entityType.getTypeName(), entityShellCount); shellEntityCountTypeAndSubTypes.put(entityType.getTypeName(), entityShellCount);
} }
} }
}
if (classificationDefNames != null) {
for (String classificationDefName : classificationDefNames) { if (classificationDefs != null) {
long count = getTypeCount(classificationDefName, ACTIVE); for (AtlasClassificationDef classificationDef : classificationDefs) {
long count = getTypeCount(classificationDef.getName(), ACTIVE);
if (count > 0) { if (count > 0) {
taggedEntityCount.put(classificationDefName, count); taggedEntityCount.put(classificationDef.getName(), count);
} }
} }
} }
...@@ -226,4 +239,23 @@ public class MetricsService { ...@@ -226,4 +239,23 @@ public class MetricsService {
return CollectionUtils.isNotEmpty(allTagNames) ? allTagNames.size() : 0; 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
...@@ -171,8 +171,7 @@ public class AtlasSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -171,8 +171,7 @@ public class AtlasSecurityConfig extends WebSecurityConfigurerAdapter {
"/n/js/**", "/n/js/**",
"/ieerror.html", "/ieerror.html",
"/migration-status.html", "/migration-status.html",
"/api/atlas/admin/status", "/api/atlas/admin/status"));
"/api/atlas/admin/metrics"));
if (!keycloakEnabled) { if (!keycloakEnabled) {
matchers.add("/login.jsp"); matchers.add("/login.jsp");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment