Repository: incubator-atlas
Updated Branches:
  refs/heads/master c3808cf1f -> de9160844


ATLAS-1940: fix to remove duplicate type which causes Atlas server to fail 
during startup

Signed-off-by: Madhan Neethiraj <mad...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/de916084
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/de916084
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/de916084

Branch: refs/heads/master
Commit: de91608446514df864995d1e50a8db4276b08ad8
Parents: c3808cf
Author: nixonrodrigues <ni...@apache.org>
Authored: Fri Jul 14 19:16:23 2017 +0530
Committer: Madhan Neethiraj <mad...@apache.org>
Committed: Fri Jul 14 14:53:37 2017 -0700

----------------------------------------------------------------------
 .../store/graph/AtlasTypeDefGraphStore.java        | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/de916084/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java
----------------------------------------------------------------------
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 9d9c59d..eedcd10 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
@@ -159,6 +159,7 @@ public abstract class AtlasTypeDefGraphStore implements 
AtlasTypeDefStore, Activ
 
         return ret;
     }
+
     @Override
     public AtlasRelationshipDef getRelationshipDefByName(String name) throws 
AtlasBaseException {
         AtlasRelationshipDef ret = typeRegistry.getRelationshipDefByName(name);
@@ -680,21 +681,37 @@ public abstract class AtlasTypeDefGraphStore implements 
AtlasTypeDefStore, Activ
             for (AtlasStructDef structDef : typesDef.getStructDefs()) {
                 rectifyAttributesIfNeeded(entityNames, structDef);
             }
+            removeDuplicateTypeIfAny(typesDef.getStructDefs());
         }
 
         if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
             for (AtlasClassificationDef classificationDef : 
typesDef.getClassificationDefs()) {
                 rectifyAttributesIfNeeded(entityNames, classificationDef);
             }
+            removeDuplicateTypeIfAny(typesDef.getClassificationDefs());
         }
 
         if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
             for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
                 rectifyAttributesIfNeeded(entityNames, entityDef);
             }
+            removeDuplicateTypeIfAny(typesDef.getEntityDefs());
         }
     }
 
+    private <T extends AtlasBaseTypeDef> void removeDuplicateTypeIfAny(List<T> 
defList) {
+        final Set<String> entityDefNames = new HashSet<>();
+
+        for (int i = 0; i < defList.size(); i++) {
+            if (!entityDefNames.add((defList.get(i)).getName())) {
+                LOG.warn(" Found Duplicate Type => " + 
defList.get(i).getName());
+                defList.remove(i);
+                i--;
+            }
+        }
+    }
+
+
     private void rectifyAttributesIfNeeded(final Set<String> entityNames, 
AtlasStructDef structDef) {
         List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();
 

Reply via email to