Commit e4921452 by Madhan Neethiraj

ATLAS-2984: export should include type defintions of relationships referenced by entities

parent 9a555373
...@@ -32,6 +32,7 @@ import org.apache.atlas.model.typedef.AtlasBaseTypeDef; ...@@ -32,6 +32,7 @@ import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef; import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef; import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef; import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.model.typedef.AtlasStructDef; import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasTypesDef; import org.apache.atlas.model.typedef.AtlasTypesDef;
...@@ -43,6 +44,7 @@ import org.apache.atlas.type.AtlasClassificationType; ...@@ -43,6 +44,7 @@ import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType; import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasEnumType; import org.apache.atlas.type.AtlasEnumType;
import org.apache.atlas.type.AtlasMapType; import org.apache.atlas.type.AtlasMapType;
import org.apache.atlas.type.AtlasRelationshipType;
import org.apache.atlas.type.AtlasStructType; import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasStructType.AtlasAttribute; import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
...@@ -175,6 +177,12 @@ public class ExportService { ...@@ -175,6 +177,12 @@ public class ExportService {
typesDef.getEnumDefs().add(enumDef); typesDef.getEnumDefs().add(enumDef);
} }
for (String relationshipType : context.relationshipTypes) {
AtlasRelationshipDef relationshipDef = typeRegistry.getRelationshipDefByName(relationshipType);
typesDef.getRelationshipDefs().add(relationshipDef);
}
} }
private AtlasExportResult.OperationStatus[] processItems(AtlasExportRequest request, ExportContext context) { private AtlasExportResult.OperationStatus[] processItems(AtlasExportRequest request, ExportContext context) {
...@@ -611,6 +619,8 @@ public class ExportService { ...@@ -611,6 +619,8 @@ public class ExportService {
addStructType((AtlasStructType)type, context); addStructType((AtlasStructType)type, context);
} else if (type instanceof AtlasEnumType) { } else if (type instanceof AtlasEnumType) {
addEnumType((AtlasEnumType)type, context); addEnumType((AtlasEnumType)type, context);
} else if (type instanceof AtlasRelationshipType) {
addRelationshipType((AtlasRelationshipType)type, context);
} }
} }
...@@ -619,6 +629,7 @@ public class ExportService { ...@@ -619,6 +629,7 @@ public class ExportService {
context.entityTypes.add(entityType.getTypeName()); context.entityTypes.add(entityType.getTypeName());
addAttributeTypes(entityType, context); addAttributeTypes(entityType, context);
addRelationshipTypes(entityType, context);
if (CollectionUtils.isNotEmpty(entityType.getAllSuperTypes())) { if (CollectionUtils.isNotEmpty(entityType.getAllSuperTypes())) {
for (String superType : entityType.getAllSuperTypes()) { for (String superType : entityType.getAllSuperTypes()) {
...@@ -656,12 +667,30 @@ public class ExportService { ...@@ -656,12 +667,30 @@ public class ExportService {
} }
} }
private void addRelationshipType(AtlasRelationshipType relationshipType, ExportContext context) {
if (!context.relationshipTypes.contains(relationshipType.getTypeName())) {
context.relationshipTypes.add(relationshipType.getTypeName());
addAttributeTypes(relationshipType, context);
addEntityType(relationshipType.getEnd1Type(), context);
addEntityType(relationshipType.getEnd2Type(), context);
}
}
private void addAttributeTypes(AtlasStructType structType, ExportContext context) { private void addAttributeTypes(AtlasStructType structType, ExportContext context) {
for (AtlasAttributeDef attributeDef : structType.getStructDef().getAttributeDefs()) { for (AtlasAttributeDef attributeDef : structType.getStructDef().getAttributeDefs()) {
addType(attributeDef.getTypeName(), context); addType(attributeDef.getTypeName(), context);
} }
} }
private void addRelationshipTypes(AtlasEntityType entityType, ExportContext context) {
for (List<AtlasRelationshipType> relationshipTypes : entityType.getRelationshipAttributesType().values()) {
for (AtlasRelationshipType relationshipType : relationshipTypes) {
addRelationshipType(relationshipType, context);
}
}
}
private List<Map<String, Object>> executeGremlinQuery(String query, ExportContext context) { private List<Map<String, Object>> executeGremlinQuery(String query, ExportContext context) {
try { try {
return (List<Map<String, Object>>) atlasGraph.executeGremlinScript(context.scriptEngine, context.bindings, query, false); return (List<Map<String, Object>>) atlasGraph.executeGremlinScript(context.scriptEngine, context.bindings, query, false);
...@@ -724,6 +753,7 @@ public class ExportService { ...@@ -724,6 +753,7 @@ public class ExportService {
final Set<String> classificationTypes = new HashSet<>(); final Set<String> classificationTypes = new HashSet<>();
final Set<String> structTypes = new HashSet<>(); final Set<String> structTypes = new HashSet<>();
final Set<String> enumTypes = new HashSet<>(); final Set<String> enumTypes = new HashSet<>();
final Set<String> relationshipTypes = new HashSet<>();
final AtlasExportResult result; final AtlasExportResult result;
private final ZipSink sink; private final ZipSink sink;
......
...@@ -28,6 +28,7 @@ import org.apache.atlas.type.AtlasClassificationType; ...@@ -28,6 +28,7 @@ import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType; import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasEnumType; import org.apache.atlas.type.AtlasEnumType;
import org.apache.atlas.type.AtlasMapType; import org.apache.atlas.type.AtlasMapType;
import org.apache.atlas.type.AtlasRelationshipType;
import org.apache.atlas.type.AtlasStructType; import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeRegistry;
...@@ -35,6 +36,8 @@ import org.apache.commons.collections.CollectionUtils; ...@@ -35,6 +36,8 @@ import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List;
class ExportTypeProcessor { class ExportTypeProcessor {
private static final Logger LOG = LoggerFactory.getLogger(ExportTypeProcessor.class); private static final Logger LOG = LoggerFactory.getLogger(ExportTypeProcessor.class);
...@@ -106,6 +109,8 @@ class ExportTypeProcessor { ...@@ -106,6 +109,8 @@ class ExportTypeProcessor {
addStructType((AtlasStructType)type, context); addStructType((AtlasStructType)type, context);
} else if (type instanceof AtlasEnumType) { } else if (type instanceof AtlasEnumType) {
addEnumType((AtlasEnumType)type, context); addEnumType((AtlasEnumType)type, context);
} else if (type instanceof AtlasRelationshipType) {
addRelationshipType((AtlasRelationshipType)type, context);
} }
} }
...@@ -114,6 +119,7 @@ class ExportTypeProcessor { ...@@ -114,6 +119,7 @@ class ExportTypeProcessor {
context.entityTypes.add(entityType.getTypeName()); context.entityTypes.add(entityType.getTypeName());
addAttributeTypes(entityType, context); addAttributeTypes(entityType, context);
addRelationshipTypes(entityType, context);
if (CollectionUtils.isNotEmpty(entityType.getAllSuperTypes())) { if (CollectionUtils.isNotEmpty(entityType.getAllSuperTypes())) {
for (String superType : entityType.getAllSuperTypes()) { for (String superType : entityType.getAllSuperTypes()) {
...@@ -151,9 +157,27 @@ class ExportTypeProcessor { ...@@ -151,9 +157,27 @@ class ExportTypeProcessor {
} }
} }
private void addRelationshipType(AtlasRelationshipType relationshipType, ExportService.ExportContext context) {
if (!context.relationshipTypes.contains(relationshipType.getTypeName())) {
context.relationshipTypes.add(relationshipType.getTypeName());
addAttributeTypes(relationshipType, context);
addEntityType(relationshipType.getEnd1Type(), context);
addEntityType(relationshipType.getEnd2Type(), context);
}
}
private void addAttributeTypes(AtlasStructType structType, ExportService.ExportContext context) { private void addAttributeTypes(AtlasStructType structType, ExportService.ExportContext context) {
for (AtlasStructDef.AtlasAttributeDef attributeDef : structType.getStructDef().getAttributeDefs()) { for (AtlasStructDef.AtlasAttributeDef attributeDef : structType.getStructDef().getAttributeDefs()) {
addType(attributeDef.getTypeName(), context); addType(attributeDef.getTypeName(), context);
} }
} }
private void addRelationshipTypes(AtlasEntityType entityType, ExportService.ExportContext context) {
for (List<AtlasRelationshipType> relationshipTypes : entityType.getRelationshipAttributesType().values()) {
for (AtlasRelationshipType relationshipType : relationshipTypes) {
addRelationshipType(relationshipType, context);
}
}
}
} }
...@@ -75,5 +75,6 @@ public class ImportTypeDefProcessor { ...@@ -75,5 +75,6 @@ public class ImportTypeDefProcessor {
result.incrementMeticsCounter("typedef:enum", typeDefinitionMap.getEnumDefs().size()); result.incrementMeticsCounter("typedef:enum", typeDefinitionMap.getEnumDefs().size());
result.incrementMeticsCounter("typedef:entitydef", typeDefinitionMap.getEntityDefs().size()); result.incrementMeticsCounter("typedef:entitydef", typeDefinitionMap.getEntityDefs().size());
result.incrementMeticsCounter("typedef:struct", typeDefinitionMap.getStructDefs().size()); result.incrementMeticsCounter("typedef:struct", typeDefinitionMap.getStructDefs().size());
result.incrementMeticsCounter("typedef:relationship", typeDefinitionMap.getRelationshipDefs().size());
} }
} }
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