Commit e5fe91a4 by Madhan Neethiraj Committed by Suma Shivaprasad

ATLAS-1225: Updated AtlasTypeDefGraphStore to use AtlasTypesRegistry, to reduce query to Graph DB

parent 51d24ae3
...@@ -195,7 +195,16 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable { ...@@ -195,7 +195,16 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
sb.append("AtlasStructDef{"); sb.append("AtlasStructDef{");
super.toString(sb); super.toString(sb);
sb.append(", attributeDefs=["); sb.append(", attributeDefs=[");
dumpObjects(attributeDefs, sb); if (CollectionUtils.isNotEmpty(attributeDefs)) {
int i = 0;
for (AtlasAttributeDef attributeDef : attributeDefs) {
attributeDef.toString(sb);
if (i > 0) {
sb.append(", ");
}
i++;
}
}
sb.append("]"); sb.append("]");
sb.append('}'); sb.append('}');
...@@ -287,7 +296,6 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable { ...@@ -287,7 +296,6 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
} }
} }
public String getName() { public String getName() {
return name; return name;
} }
...@@ -350,7 +358,6 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable { ...@@ -350,7 +358,6 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
isIndexable = idexable; isIndexable = idexable;
} }
public StringBuilder toString(StringBuilder sb) { public StringBuilder toString(StringBuilder sb) {
if (sb == null) { if (sb == null) {
sb = new StringBuilder(); sb = new StringBuilder();
...@@ -410,7 +417,6 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable { ...@@ -410,7 +417,6 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
} }
} }
/** /**
* REST serialization friendly list. * REST serialization friendly list.
*/ */
......
...@@ -114,7 +114,7 @@ public interface AtlasTypeDefStore { ...@@ -114,7 +114,7 @@ public interface AtlasTypeDefStore {
/*************************/ /*************************/
/** EntityDef operation **/ /** EntityDef operation **/
/*************************/ /*************************/
AtlasEntityDef createEntityDefs(AtlasEntityDef entityDef) throws AtlasBaseException; AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasBaseException;
List<AtlasEntityDef> createEntityDefs(List<AtlasEntityDef> entityDefs) throws AtlasBaseException; List<AtlasEntityDef> createEntityDefs(List<AtlasEntityDef> entityDefs) throws AtlasBaseException;
......
...@@ -84,6 +84,22 @@ public class AtlasArrayType extends AtlasType { ...@@ -84,6 +84,22 @@ public class AtlasArrayType extends AtlasType {
this.resolveReferences(typeRegistry); this.resolveReferences(typeRegistry);
} }
public String getElementTypeName() {
return elementTypeName;
}
public int getMinCount() {
return minCount;
}
public int getMaxCount() {
return maxCount;
}
public AtlasType getElementType() {
return elementType;
}
@Override @Override
public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
elementType = typeRegistry.getType(elementTypeName); elementType = typeRegistry.getType(elementTypeName);
......
...@@ -22,6 +22,7 @@ import java.util.Collections; ...@@ -22,6 +22,7 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.AtlasEnumDef; import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef; import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef;
...@@ -59,6 +60,10 @@ public class AtlasEnumType extends AtlasType { ...@@ -59,6 +60,10 @@ public class AtlasEnumType extends AtlasType {
} }
@Override @Override
public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
}
@Override
public Object createDefaultValue() { public Object createDefaultValue() {
return defaultValue; return defaultValue;
} }
......
...@@ -64,6 +64,26 @@ public class AtlasMapType extends AtlasType { ...@@ -64,6 +64,26 @@ public class AtlasMapType extends AtlasType {
resolveReferences(typeRegistry); resolveReferences(typeRegistry);
} }
public String getKeyTypeName() {
return keyTypeName;
}
public String getValueTypeName() {
return valueTypeName;
}
public AtlasType getKeyType() {
return keyType;
}
public AtlasType getValueType() {
return valueType;
}
public void setKeyType(AtlasType keyType) {
this.keyType = keyType;
}
@Override @Override
public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
this.keyType = typeRegistry.getType(keyTypeName); this.keyType = typeRegistry.getType(keyTypeName);
......
...@@ -38,6 +38,7 @@ public class AtlasStructType extends AtlasType { ...@@ -38,6 +38,7 @@ public class AtlasStructType extends AtlasType {
private Map<String, AtlasType> attrTypes = Collections.emptyMap(); private Map<String, AtlasType> attrTypes = Collections.emptyMap();
public AtlasStructType(AtlasStructDef structDef) { public AtlasStructType(AtlasStructDef structDef) {
super(structDef.getName()); super(structDef.getName());
...@@ -52,6 +53,10 @@ public class AtlasStructType extends AtlasType { ...@@ -52,6 +53,10 @@ public class AtlasStructType extends AtlasType {
this.resolveReferences(typeRegistry); this.resolveReferences(typeRegistry);
} }
public AtlasType getAttributeType(String attributeName) { return attrTypes.get(attributeName); }
public AtlasAttributeDef getAttributeDef(String attributeName) { return structDef.getAttribute(attributeName); }
@Override @Override
public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
Map<String, AtlasType> a = new HashMap<String, AtlasType>(); Map<String, AtlasType> a = new HashMap<String, AtlasType>();
...@@ -59,24 +64,20 @@ public class AtlasStructType extends AtlasType { ...@@ -59,24 +64,20 @@ public class AtlasStructType extends AtlasType {
for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) { for (AtlasAttributeDef attributeDef : structDef.getAttributeDefs()) {
AtlasType attrType = typeRegistry.getType(attributeDef.getTypeName()); AtlasType attrType = typeRegistry.getType(attributeDef.getTypeName());
if (attrType != null) { if (attrType == null) {
Cardinality cardinality = attributeDef.getCardinality(); throw new AtlasBaseException(attributeDef.getTypeName() + ": unknown type for attribute "
+ structDef.getName() + "." + attributeDef.getName());
if (cardinality == Cardinality.LIST || cardinality == Cardinality.SET) { }
attrType = new AtlasArrayType(attrType,
attributeDef.getValuesMinCount(),
attributeDef.getValuesMaxCount());
}
a.put(attributeDef.getName(), attrType);
} else {
String msg = attributeDef.getTypeName() + ": unknown type for attribute "
+ structDef.getName() + "." + attributeDef.getName();
LOG.error(msg); Cardinality cardinality = attributeDef.getCardinality();
throw new AtlasBaseException(msg); if (cardinality == Cardinality.LIST || cardinality == Cardinality.SET) {
attrType = new AtlasArrayType(attrType,
attributeDef.getValuesMinCount(),
attributeDef.getValuesMaxCount());
} }
a.put(attributeDef.getName(), attrType);
} }
this.attrTypes = Collections.unmodifiableMap(a); this.attrTypes = Collections.unmodifiableMap(a);
......
...@@ -41,7 +41,6 @@ public abstract class AtlasType { ...@@ -41,7 +41,6 @@ public abstract class AtlasType {
} }
public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException { public void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
} }
public String getTypeName() { return typeName; } public String getTypeName() { return typeName; }
......
...@@ -157,7 +157,13 @@ public final class ModelTestUtil { ...@@ -157,7 +157,13 @@ public final class ModelTestUtil {
ret.setDefaultValue(ret.getElementDefs().get(idxDefault).getValue()); ret.setDefaultValue(ret.getElementDefs().get(idxDefault).getValue());
} }
typesRegistry.addEnumDef(ret); try {
typesRegistry.addType(ret);
} catch (AtlasBaseException excp) {
LOG.error("failed to create enum-def", excp);
ret = null;
}
return ret; return ret;
} }
...@@ -176,7 +182,7 @@ public final class ModelTestUtil { ...@@ -176,7 +182,7 @@ public final class ModelTestUtil {
ret.setAttributeDefs(newAttributeDefsWithAllBuiltInTypes(PREFIX_ATTRIBUTE_NAME)); ret.setAttributeDefs(newAttributeDefsWithAllBuiltInTypes(PREFIX_ATTRIBUTE_NAME));
try { try {
typesRegistry.addStructDef(ret); typesRegistry.addType(ret);
} catch (AtlasBaseException excp) { } catch (AtlasBaseException excp) {
LOG.error("failed to create struct-def", excp); LOG.error("failed to create struct-def", excp);
...@@ -214,7 +220,7 @@ public final class ModelTestUtil { ...@@ -214,7 +220,7 @@ public final class ModelTestUtil {
} }
try { try {
typesRegistry.addEntityDef(ret); typesRegistry.addType(ret);
} catch (AtlasBaseException excp) { } catch (AtlasBaseException excp) {
LOG.error("failed to create entity-def", excp); LOG.error("failed to create entity-def", excp);
...@@ -261,7 +267,7 @@ public final class ModelTestUtil { ...@@ -261,7 +267,7 @@ public final class ModelTestUtil {
} }
try { try {
typesRegistry.addClassificationDef(ret); typesRegistry.addType(ret);
} catch (AtlasBaseException excp) { } catch (AtlasBaseException excp) {
LOG.error("failed to create classification-def", excp); LOG.error("failed to create classification-def", excp);
......
...@@ -35,7 +35,7 @@ public class TestAtlasEntityType { ...@@ -35,7 +35,7 @@ public class TestAtlasEntityType {
private final List<Object> invalidValues = new ArrayList<Object>(); private final List<Object> invalidValues = new ArrayList<Object>();
{ {
entityType = getEntityType(ModelTestUtil.getEntityDefWithSuperTypes()); entityType = getEntityType(ModelTestUtil.getEntityDefWithSuperTypes());
AtlasEntity invalidValue1 = entityType.createDefaultValue(); AtlasEntity invalidValue1 = entityType.createDefaultValue();
AtlasEntity invalidValue2 = entityType.createDefaultValue(); AtlasEntity invalidValue2 = entityType.createDefaultValue();
......
...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al ...@@ -9,6 +9,7 @@ ATLAS-1060 Add composite indexes for exact match performance improvements for al
ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai) ATLAS-1127 Modify creation and modification timestamps to Date instead of Long(sumasai)
ALL CHANGES: ALL CHANGES:
ATLAS-1225 Optimize AtlasTypeDefGraphStore to use typeRegistry (mneethiraj via sumasai)
ATLAS-1221 build failure in windows SyntaxError: invalid syntax (zhangqiang2 via shwethags) ATLAS-1221 build failure in windows SyntaxError: invalid syntax (zhangqiang2 via shwethags)
ATLAS-1226 Servlet init-params in web.xml are unused (mneethiraj via shwethags) ATLAS-1226 Servlet init-params in web.xml are unused (mneethiraj via shwethags)
ATLAS-1224 Minor fixes for hive and falcon bridge twiki (ayubkhan via sumasai) ATLAS-1224 Minor fixes for hive and falcon bridge twiki (ayubkhan via sumasai)
......
...@@ -31,8 +31,6 @@ import org.apache.commons.collections.CollectionUtils; ...@@ -31,8 +31,6 @@ import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import sun.security.provider.certpath.Vertex;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
......
...@@ -21,6 +21,7 @@ import org.apache.atlas.exception.AtlasBaseException; ...@@ -21,6 +21,7 @@ import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.SearchFilter;
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.AtlasStructDef.AtlasStructDefs; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs;
import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.graphdb.AtlasVertex;
...@@ -381,7 +382,7 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { ...@@ -381,7 +382,7 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore {
String propertyKey = AtlasGraphUtilsV1.getPropertyKey(ret, attrName); String propertyKey = AtlasGraphUtilsV1.getPropertyKey(ret, attrName);
String attribJson = atlasVertex.getProperty(propertyKey, String.class); String attribJson = atlasVertex.getProperty(propertyKey, String.class);
attributeDefs.add(toAttributeDefFromJson(attribJson)); attributeDefs.add(toAttributeDefFromJson(AtlasType.fromJson(attribJson, Map.class)));
} }
} }
ret.setAttributeDefs(attributeDefs); ret.setAttributeDefs(attributeDefs);
...@@ -412,14 +413,17 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { ...@@ -412,14 +413,17 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore {
} }
private static String toJsonFromAttributeDef(AtlasAttributeDef attributeDef) { private static String toJsonFromAttributeDef(AtlasAttributeDef attributeDef) {
Boolean isComposite = Boolean.FALSE;
String reverseAttribName = null;
Map<String, Object> attribInfo = new HashMap<String, Object>(); Map<String, Object> attribInfo = new HashMap<String, Object>();
attribInfo.put("name", attributeDef.getName()); attribInfo.put("name", attributeDef.getName());
attribInfo.put("dataType", attributeDef.getTypeName()); attribInfo.put("dataType", attributeDef.getTypeName());
attribInfo.put("isUnique", attributeDef.isUnique()); attribInfo.put("isUnique", attributeDef.isUnique());
attribInfo.put("isIndexable", attributeDef.isIndexable()); attribInfo.put("isIndexable", attributeDef.isIndexable());
attribInfo.put("isComposite", Boolean.FALSE); attribInfo.put("isComposite", isComposite);
attribInfo.put("reverseAttributeName", ""); attribInfo.put("reverseAttributeName", reverseAttribName);
Map<String, Object> multiplicity = new HashMap<String, Object>(); Map<String, Object> multiplicity = new HashMap<String, Object>();
multiplicity.put("lower", attributeDef.getValuesMinCount()); multiplicity.put("lower", attributeDef.getValuesMinCount());
multiplicity.put("upper", attributeDef.getValuesMaxCount()); multiplicity.put("upper", attributeDef.getValuesMaxCount());
...@@ -430,23 +434,23 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { ...@@ -430,23 +434,23 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore {
return AtlasType.toJson(attribInfo); return AtlasType.toJson(attribInfo);
} }
private static AtlasAttributeDef toAttributeDefFromJson(String json) { private static AtlasAttributeDef toAttributeDefFromJson(Map attribInfo) {
Map attribInfo = AtlasType.fromJson(json, Map.class);
AtlasAttributeDef ret = new AtlasAttributeDef(); AtlasAttributeDef ret = new AtlasAttributeDef();
ret.setName((String) attribInfo.get("name")); ret.setName((String) attribInfo.get("name"));
ret.setTypeName((String) attribInfo.get("dataType")); ret.setTypeName((String) attribInfo.get("dataType"));
ret.setUnique((Boolean) attribInfo.get("isUnique")); ret.setUnique((Boolean) attribInfo.get("isUnique"));
ret.setIndexable((Boolean) attribInfo.get("isIndexable")); ret.setIndexable((Boolean) attribInfo.get("isIndexable"));
/* /*
attributeMap.put("isComposite", isComposite); String reverseAttribName = (String)attribInfo.get("reverseAttributeName");
attributeMap.put("reverseAttributeName", reverseAttributeName); Boolean isComposite = (Boolean) attribInfo.get("isComposite");
*/ */
Map multiplicity = AtlasType.fromJson((String) attribInfo.get("multiplicity"), Map.class); Map multiplicity = AtlasType.fromJson((String) attribInfo.get("multiplicity"), Map.class);
Number minCount = (Number) multiplicity.get("lower"); Number minCount = (Number) multiplicity.get("lower");
Number maxCount = (Number) multiplicity.get("upper"); Number maxCount = (Number) multiplicity.get("upper");
Boolean isUnique = (Boolean) multiplicity.get("isUnique"); Boolean isUnique = (Boolean) multiplicity.get("isUnique");
if (minCount == null || minCount.intValue() == 0) { if (minCount == null || minCount.intValue() == 0) {
ret.setOptional(true); ret.setOptional(true);
......
...@@ -60,15 +60,29 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { ...@@ -60,15 +60,29 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore {
public AtlasTypeDefGraphStoreV1() { public AtlasTypeDefGraphStoreV1() {
super(); super();
enumDefStore = new AtlasEnumDefStoreV1(this); LOG.info("==> AtlasTypeDefGraphStoreV1()");
structDefStore = new AtlasStructDefStoreV1(this);
classificationDefStore = new AtlasClassificationDefStoreV1(this); try {
entityDefStore = new AtlasEntityDefStoreV1(this); init();
} catch(AtlasBaseException excp) {
LOG.error("failed to initialize types from graph store", excp);
}
LOG.info("<== AtlasTypeDefGraphStoreV1()");
} }
@Override @Override
public void init() { public void init() throws AtlasBaseException {
LOG.info("==> AtlasTypeDefGraphStoreV1.init()");
super.init();
super.init(new AtlasEnumDefStoreV1(this),
new AtlasStructDefStoreV1(this),
new AtlasClassificationDefStoreV1(this),
new AtlasEntityDefStoreV1(this));
LOG.info("<== AtlasTypeDefGraphStoreV1.init()");
} }
public AtlasGraph getAtlasGraph() { return atlasGraph; } public AtlasGraph getAtlasGraph() { return atlasGraph; }
......
...@@ -350,7 +350,7 @@ public class TypesREST { ...@@ -350,7 +350,7 @@ public class TypesREST {
AtlasEntityDef ret = null; AtlasEntityDef ret = null;
try { try {
ret = typeDefStore.createEntityDefs(entityDef); ret = typeDefStore.createEntityDef(entityDef);
return ret; return ret;
} catch (AtlasBaseException ex) { } catch (AtlasBaseException ex) {
throw new WebApplicationException(Servlets.getErrorResponse(ex, Response.Status.BAD_REQUEST)); throw new WebApplicationException(Servlets.getErrorResponse(ex, Response.Status.BAD_REQUEST));
......
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