Commit de916084 by nixonrodrigues Committed by Madhan Neethiraj

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

parent c3808cf1
...@@ -159,6 +159,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ ...@@ -159,6 +159,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ
return ret; return ret;
} }
@Override @Override
public AtlasRelationshipDef getRelationshipDefByName(String name) throws AtlasBaseException { public AtlasRelationshipDef getRelationshipDefByName(String name) throws AtlasBaseException {
AtlasRelationshipDef ret = typeRegistry.getRelationshipDefByName(name); AtlasRelationshipDef ret = typeRegistry.getRelationshipDefByName(name);
...@@ -680,21 +681,37 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ ...@@ -680,21 +681,37 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ
for (AtlasStructDef structDef : typesDef.getStructDefs()) { for (AtlasStructDef structDef : typesDef.getStructDefs()) {
rectifyAttributesIfNeeded(entityNames, structDef); rectifyAttributesIfNeeded(entityNames, structDef);
} }
removeDuplicateTypeIfAny(typesDef.getStructDefs());
} }
if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) { if (CollectionUtils.isNotEmpty(typesDef.getClassificationDefs())) {
for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) { for (AtlasClassificationDef classificationDef : typesDef.getClassificationDefs()) {
rectifyAttributesIfNeeded(entityNames, classificationDef); rectifyAttributesIfNeeded(entityNames, classificationDef);
} }
removeDuplicateTypeIfAny(typesDef.getClassificationDefs());
} }
if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) { if (CollectionUtils.isNotEmpty(typesDef.getEntityDefs())) {
for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) { for (AtlasEntityDef entityDef : typesDef.getEntityDefs()) {
rectifyAttributesIfNeeded(entityNames, entityDef); 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) { private void rectifyAttributesIfNeeded(final Set<String> entityNames, AtlasStructDef structDef) {
List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs(); List<AtlasAttributeDef> attributeDefs = structDef.getAttributeDefs();
......
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