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,7 +64,11 @@ public class AtlasStructType extends AtlasType { ...@@ -59,7 +64,11 @@ 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) {
throw new AtlasBaseException(attributeDef.getTypeName() + ": unknown type for attribute "
+ structDef.getName() + "." + attributeDef.getName());
}
Cardinality cardinality = attributeDef.getCardinality(); Cardinality cardinality = attributeDef.getCardinality();
if (cardinality == Cardinality.LIST || cardinality == Cardinality.SET) { if (cardinality == Cardinality.LIST || cardinality == Cardinality.SET) {
...@@ -69,14 +78,6 @@ public class AtlasStructType extends AtlasType { ...@@ -69,14 +78,6 @@ public class AtlasStructType extends AtlasType {
} }
a.put(attributeDef.getName(), attrType); a.put(attributeDef.getName(), attrType);
} else {
String msg = attributeDef.getTypeName() + ": unknown type for attribute "
+ structDef.getName() + "." + attributeDef.getName();
LOG.error(msg);
throw new AtlasBaseException(msg);
}
} }
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; }
......
...@@ -18,12 +18,18 @@ ...@@ -18,12 +18,18 @@
package org.apache.atlas.type; package org.apache.atlas.type;
import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.typedef.*; import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_PREFIX; import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_PREFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_SUFFIX; import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_ARRAY_SUFFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_PREFIX; import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_PREFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_SUFFIX; import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_SUFFIX;
import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_KEY_VAL_SEP; import static org.apache.atlas.model.typedef.AtlasBaseTypeDef.ATLAS_TYPE_MAP_KEY_VAL_SEP;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -45,7 +51,6 @@ public class AtlasTypeRegistry { ...@@ -45,7 +51,6 @@ public class AtlasTypeRegistry {
private final TypeDefCache<AtlasClassificationDef> classificationDefs; private final TypeDefCache<AtlasClassificationDef> classificationDefs;
private final TypeDefCache<AtlasEntityDef> entityDefs; private final TypeDefCache<AtlasEntityDef> entityDefs;
public AtlasTypeRegistry() { public AtlasTypeRegistry() {
allTypes = new ConcurrentHashMap<>(); allTypes = new ConcurrentHashMap<>();
enumDefs = new TypeDefCache<>(this); enumDefs = new TypeDefCache<>(this);
...@@ -67,12 +72,6 @@ public class AtlasTypeRegistry { ...@@ -67,12 +72,6 @@ public class AtlasTypeRegistry {
registerType(new AtlasBuiltInTypes.AtlasObjectIdType()); registerType(new AtlasBuiltInTypes.AtlasObjectIdType());
} }
public void resolveReferences() throws AtlasBaseException {
for (Map.Entry<String, AtlasType> e : allTypes.entrySet()) {
e.getValue().resolveReferences(this);
}
}
public Collection<String> getAllTypeNames() { return Collections.unmodifiableSet(allTypes.keySet()); } public Collection<String> getAllTypeNames() { return Collections.unmodifiableSet(allTypes.keySet()); }
public AtlasType getType(String typeName) { public AtlasType getType(String typeName) {
...@@ -112,259 +111,385 @@ public class AtlasTypeRegistry { ...@@ -112,259 +111,385 @@ public class AtlasTypeRegistry {
} }
public void addEnumDef(AtlasEnumDef enumDef) { public void addType(AtlasBaseTypeDef typeDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.addEnumDef({})", enumDef); LOG.debug("==> AtlasTypeRegistry.addType({})", typeDef);
} }
if (typeDef == null) {
// ignore
} else if (typeDef.getClass().equals(AtlasEnumDef.class)) {
AtlasEnumDef enumDef = (AtlasEnumDef)typeDef;
enumDefs.addType(enumDef, new AtlasEnumType(enumDef)); enumDefs.addType(enumDef, new AtlasEnumType(enumDef));
} else if (typeDef.getClass().equals(AtlasStructDef.class)) {
AtlasStructDef structDef = (AtlasStructDef)typeDef;
if (LOG.isDebugEnabled()) { structDefs.addType(structDef, new AtlasStructType(structDef, this));
LOG.debug("<== AtlasTypeRegistry.addEnumDef({})", enumDef); } else if (typeDef.getClass().equals(AtlasClassificationDef.class)) {
} AtlasClassificationDef classificationDef = (AtlasClassificationDef)typeDef;
}
public Collection<AtlasEnumDef> getAllEnumDefs() { return enumDefs.getAll(); } classificationDefs.addType(classificationDef, new AtlasClassificationType(classificationDef, this));
} else if (typeDef.getClass().equals(AtlasEntityDef.class)) {
AtlasEntityDef entityDef = (AtlasEntityDef)typeDef;
public AtlasEnumDef getEnumDefByGuid(String guid) { entityDefs.addType(entityDef, new AtlasEntityType(entityDef, this));
return enumDefs.getTypeDefByGuid(guid);
} }
public AtlasEnumDef getEnumDefByName(String name) { if (LOG.isDebugEnabled()) {
return enumDefs.getTypeDefByName(name); LOG.debug("<== AtlasTypeRegistry.addType({})", typeDef);
}
} }
public void removeEnumDefByGuid(String guid) { public void addTypeWithNoRefResolve(AtlasBaseTypeDef typeDef) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.removeEnumDefByGuid({})", guid); LOG.debug("==> AtlasTypeRegistry.addTypeWithNoRefResolve({})", typeDef);
} }
AtlasEnumDef enumDef = enumDefs.getTypeDefByGuid(guid); if (typeDef == null) {
// ignore
} else if (typeDef.getClass().equals(AtlasEnumDef.class)) {
AtlasEnumDef enumDef = (AtlasEnumDef)typeDef;
if (enumDef != null) { enumDefs.addType(enumDef, new AtlasEnumType(enumDef));
enumDefs.removeTypeDefByGuid(guid); } else if (typeDef.getClass().equals(AtlasStructDef.class)) {
AtlasStructDef structDef = (AtlasStructDef)typeDef;
structDefs.addType(structDef, new AtlasStructType(structDef));
} else if (typeDef.getClass().equals(AtlasClassificationDef.class)) {
AtlasClassificationDef classificationDef = (AtlasClassificationDef)typeDef;
classificationDefs.addType(classificationDef, new AtlasClassificationType(classificationDef));
} else if (typeDef.getClass().equals(AtlasEntityDef.class)) {
AtlasEntityDef entityDef = (AtlasEntityDef)typeDef;
entityDefs.addType(entityDef, new AtlasEntityType(entityDef));
} }
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeRegistry.removeEnumDefByGuid({})", guid); LOG.debug("<== AtlasTypeRegistry.addTypeWithNoRefResolve({})", typeDef);
} }
} }
public void removeEnumDefByName(String name) { public void updateType(AtlasBaseTypeDef typeDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.removeEnumDefByName({})", name); LOG.debug("==> AtlasTypeRegistry.updateType({})", typeDef);
} }
AtlasEnumDef enumDef = enumDefs.getTypeDefByName(name); if (typeDef == null) {
// ignore
if (enumDef != null) { } else if (StringUtils.isNotBlank(typeDef.getGuid())) {
enumDefs.removeTypeDefByName(name); updateTypeByGuid(typeDef.getGuid(), typeDef);
} else if (StringUtils.isNotBlank(typeDef.getName())) {
updateTypeByName(typeDef.getName(), typeDef);
} }
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeRegistry.removeEnumDefByName({})", name); LOG.debug("<== AtlasTypeRegistry.updateType({})", typeDef);
} }
} }
public void updateTypeWithNoRefResolve(AtlasBaseTypeDef typeDef) {
public void addStructDefWithNoRefResolve(AtlasStructDef structDef) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.addStructDefWithNoRefResolve({})", structDef); LOG.debug("==> AtlasTypeRegistry.updateType({})", typeDef);
} }
structDefs.addType(structDef, new AtlasStructType(structDef)); if (typeDef == null) {
// ignore
} else if (StringUtils.isNotBlank(typeDef.getGuid())) {
updateTypeByGuidWithNoRefResolve(typeDef.getGuid(), typeDef);
} else if (StringUtils.isNotBlank(typeDef.getName())) {
updateTypeByNameWithNoRefResolve(typeDef.getName(), typeDef);
}
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeRegistry.addStructDefWithNoRefResolve({})", structDef); LOG.debug("<== AtlasTypeRegistry.updateType({})", typeDef);
} }
} }
public void addStructDef(AtlasStructDef structDef) throws AtlasBaseException { public void updateTypeByGuid(String guid, AtlasBaseTypeDef typeDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.addStructDef({})", structDef); LOG.debug("==> AtlasTypeRegistry.updateTypeByGuid({})", guid);
} }
if (guid == null || typeDef == null) {
// ignore
} else if (typeDef.getClass().equals(AtlasEnumDef.class)) {
AtlasEnumDef enumDef = (AtlasEnumDef)typeDef;
enumDefs.removeTypeDefByGuid(guid);
enumDefs.addType(enumDef, new AtlasEnumType(enumDef));
} else if (typeDef.getClass().equals(AtlasStructDef.class)) {
AtlasStructDef structDef = (AtlasStructDef)typeDef;
structDefs.removeTypeDefByGuid(guid);
structDefs.addType(structDef, new AtlasStructType(structDef, this)); structDefs.addType(structDef, new AtlasStructType(structDef, this));
} else if (typeDef.getClass().equals(AtlasClassificationDef.class)) {
AtlasClassificationDef classificationDef = (AtlasClassificationDef)typeDef;
classificationDefs.removeTypeDefByGuid(guid);
classificationDefs.addType(classificationDef, new AtlasClassificationType(classificationDef, this));
} else if (typeDef.getClass().equals(AtlasEntityDef.class)) {
AtlasEntityDef entityDef = (AtlasEntityDef)typeDef;
entityDefs.removeTypeDefByGuid(guid);
entityDefs.addType(entityDef, new AtlasEntityType(entityDef, this));
}
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeRegistry.addStructDef({})", structDef); LOG.debug("<== AtlasTypeRegistry.updateTypeByGuid({})", guid);
} }
} }
public Collection<AtlasStructDef> getAllStructDefs() { return structDefs.getAll(); } public void updateTypeByName(String name, AtlasBaseTypeDef typeDef) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
public AtlasStructDef getStructDefByGuid(String guid) { LOG.debug("==> AtlasTypeRegistry.updateEnumDefByName({})", name);
return structDefs.getTypeDefByGuid(guid);
} }
public AtlasStructDef getStructDefByName(String name) { return structDefs.getTypeDefByName(name); } if (name == null || typeDef == null) {
// ignore
} else if (typeDef.getClass().equals(AtlasEnumDef.class)) {
AtlasEnumDef enumDef = (AtlasEnumDef)typeDef;
public void removeStructDefByGuid(String guid) { enumDefs.removeTypeDefByName(name);
if (LOG.isDebugEnabled()) { enumDefs.addType(enumDef, new AtlasEnumType(enumDef));
LOG.debug("==> AtlasTypeRegistry.removeStructDefByGuid({})", guid); } else if (typeDef.getClass().equals(AtlasStructDef.class)) {
} AtlasStructDef structDef = (AtlasStructDef)typeDef;
AtlasStructDef structDef = structDefs.getTypeDefByGuid(guid); structDefs.removeTypeDefByName(name);
structDefs.addType(structDef, new AtlasStructType(structDef, this));
} else if (typeDef.getClass().equals(AtlasClassificationDef.class)) {
AtlasClassificationDef classificationDef = (AtlasClassificationDef)typeDef;
if (structDef != null) { classificationDefs.removeTypeDefByName(name);
structDefs.removeTypeDefByGuid(guid); classificationDefs.addType(classificationDef, new AtlasClassificationType(classificationDef, this));
} else if (typeDef.getClass().equals(AtlasEntityDef.class)) {
AtlasEntityDef entityDef = (AtlasEntityDef)typeDef;
entityDefs.removeTypeDefByName(name);
entityDefs.addType(entityDef, new AtlasEntityType(entityDef, this));
} }
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeRegistry.removeStructDefByGuid({})", guid); LOG.debug("<== AtlasTypeRegistry.updateEnumDefByName({})", name);
} }
} }
public void removeStructDefByName(String name) { public void updateTypeByGuidWithNoRefResolve(String guid, AtlasBaseTypeDef typeDef) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.removeStructDefByName({})", name); LOG.debug("==> AtlasTypeRegistry.updateTypeByGuidWithNoRefResolve({})", guid);
} }
AtlasStructDef structDef = structDefs.getTypeDefByName(name); if (guid == null || typeDef == null) {
// ignore
} else if (typeDef.getClass().equals(AtlasEnumDef.class)) {
AtlasEnumDef enumDef = (AtlasEnumDef)typeDef;
if (structDef != null) { enumDefs.removeTypeDefByGuid(guid);
structDefs.removeTypeDefByName(name); enumDefs.addType(enumDef, new AtlasEnumType(enumDef));
} else if (typeDef.getClass().equals(AtlasStructDef.class)) {
AtlasStructDef structDef = (AtlasStructDef)typeDef;
structDefs.removeTypeDefByGuid(guid);
structDefs.addType(structDef, new AtlasStructType(structDef));
} else if (typeDef.getClass().equals(AtlasClassificationDef.class)) {
AtlasClassificationDef classificationDef = (AtlasClassificationDef)typeDef;
classificationDefs.removeTypeDefByGuid(guid);
classificationDefs.addType(classificationDef, new AtlasClassificationType(classificationDef));
} else if (typeDef.getClass().equals(AtlasEntityDef.class)) {
AtlasEntityDef entityDef = (AtlasEntityDef)typeDef;
entityDefs.removeTypeDefByGuid(guid);
entityDefs.addType(entityDef, new AtlasEntityType(entityDef));
} }
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeRegistry.removeStructDefByName({})", name); LOG.debug("<== AtlasTypeRegistry.updateTypeByGuidWithNoRefResolve({})", guid);
} }
} }
public void updateTypeByNameWithNoRefResolve(String name, AtlasBaseTypeDef typeDef) {
public void addClassificationDefWithNoRefResolve(AtlasClassificationDef classificationDef) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.addClassificationDefWithNoRefResolve({})", classificationDef); LOG.debug("==> AtlasTypeRegistry.updateTypeByNameWithNoRefResolve({})", name);
} }
if (name == null || typeDef == null) {
// ignore
} else if (typeDef.getClass().equals(AtlasEnumDef.class)) {
AtlasEnumDef enumDef = (AtlasEnumDef)typeDef;
enumDefs.removeTypeDefByName(name);
enumDefs.addType(enumDef, new AtlasEnumType(enumDef));
} else if (typeDef.getClass().equals(AtlasStructDef.class)) {
AtlasStructDef structDef = (AtlasStructDef)typeDef;
structDefs.removeTypeDefByName(name);
structDefs.addType(structDef, new AtlasStructType(structDef));
} else if (typeDef.getClass().equals(AtlasClassificationDef.class)) {
AtlasClassificationDef classificationDef = (AtlasClassificationDef)typeDef;
classificationDefs.removeTypeDefByName(name);
classificationDefs.addType(classificationDef, new AtlasClassificationType(classificationDef)); classificationDefs.addType(classificationDef, new AtlasClassificationType(classificationDef));
} else if (typeDef.getClass().equals(AtlasEntityDef.class)) {
AtlasEntityDef entityDef = (AtlasEntityDef)typeDef;
entityDefs.removeTypeDefByName(name);
entityDefs.addType(entityDef, new AtlasEntityType(entityDef));
}
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeRegistry.addClassificationDefWithNoRefResolve({})", classificationDef); LOG.debug("<== AtlasTypeRegistry.updateTypeByNameWithNoRefResolve({})", name);
} }
} }
public void addClassificationDef(AtlasClassificationDef classificationDef) public void removeTypeByGuid(String guid) {
throws AtlasBaseException {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.addClassificationDef({})", classificationDef); LOG.debug("==> AtlasTypeRegistry.removeTypeByGuid({})", guid);
} }
classificationDefs.addType(classificationDef, new AtlasClassificationType(classificationDef, this)); if (guid != null) {
enumDefs.removeTypeDefByGuid(guid);
structDefs.removeTypeDefByGuid(guid);
classificationDefs.removeTypeDefByGuid(guid);
entityDefs.removeTypeDefByGuid(guid);
}
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeRegistry.addClassificationDef({})", classificationDef); LOG.debug("<== AtlasTypeRegistry.removeTypeByGuid({})", guid);
} }
} }
public Collection<AtlasClassificationDef> getAllClassificationDefs() { return classificationDefs.getAll(); } public void removeTypeByName(String name) {
if (LOG.isDebugEnabled()) {
public AtlasClassificationDef getClassificationDefByGuid(String guid) { LOG.debug("==> AtlasTypeRegistry.removeTypeByName({})", name);
return classificationDefs.getTypeDefByGuid(guid);
} }
public AtlasClassificationDef getClassificationDefByName(String name) { if (name != null) {
return classificationDefs.getTypeDefByName(name); enumDefs.removeTypeDefByName(name);
structDefs.removeTypeDefByName(name);
classificationDefs.removeTypeDefByName(name);
entityDefs.removeTypeDefByName(name);
} }
public void removeClassificationDefByGuid(String guid) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.removeClassificationDefByGuid({})", guid); LOG.debug("<== AtlasTypeRegistry.removeEnumDefByName({})", name);
}
} }
AtlasClassificationDef classificationDef = classificationDefs.getTypeDefByGuid(guid); public void addTypes(Collection<? extends AtlasBaseTypeDef> typeDefs) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.addTypes(length={})", (typeDefs == null ? 0 : typeDefs.size()));
}
if (classificationDef != null) { if (CollectionUtils.isNotEmpty(typeDefs)) {
classificationDefs.removeTypeDefByGuid(guid); for (AtlasBaseTypeDef typeDef : typeDefs) {
addType(typeDef);
}
} }
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeRegistry.removeClassificationDefByGuid({})", guid); LOG.debug("<== AtlasTypeRegistry.addTypes(length={})", (typeDefs == null ? 0 : typeDefs.size()));
} }
} }
public void removeClassificationDefByName(String name) { public void addTypesWithNoRefResolve(Collection<? extends AtlasBaseTypeDef> typeDefs) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.removeClassificationDefByName({})", name); LOG.debug("==> AtlasTypeRegistry.addTypes(length={})", (typeDefs == null ? 0 : typeDefs.size()));
} }
AtlasClassificationDef classificationDef = classificationDefs.getTypeDefByName(name); if (CollectionUtils.isNotEmpty(typeDefs)) {
for (AtlasBaseTypeDef typeDef : typeDefs) {
if (classificationDef != null) { addTypeWithNoRefResolve(typeDef);
classificationDefs.removeTypeDefByName(name); }
} }
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeRegistry.removeClassificationDefByName({})", name); LOG.debug("<== AtlasTypeRegistry.addTypes(length={})", (typeDefs == null ? 0 : typeDefs.size()));
} }
} }
public void updateTypes(Collection<? extends AtlasBaseTypeDef> typeDefs) throws AtlasBaseException {
public void addEntityDefWithNoRefResolve(AtlasEntityDef entityDef) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.addEntityDefWithNoRefResolve({})", entityDef); LOG.debug("==> AtlasTypeRegistry.updateTypes(length={})", (typeDefs == null ? 0 : typeDefs.size()));
} }
entityDefs.addType(entityDef, new AtlasEntityType(entityDef)); if (CollectionUtils.isNotEmpty(typeDefs)) {
for (AtlasBaseTypeDef typeDef : typeDefs) {
updateType(typeDef);
}
}
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeRegistry.addEntityDefWithNoRefResolve({})", entityDef); LOG.debug("<== AtlasTypeRegistry.updateTypes(length={})", (typeDefs == null ? 0 : typeDefs.size()));
} }
} }
public void addEntityDef(AtlasEntityDef entityDef) throws AtlasBaseException { public void updateTypesWithNoRefResolve(Collection<? extends AtlasBaseTypeDef> typeDefs) {
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("==> AtlasTypeRegistry.addEntityDef({})", entityDef); LOG.debug("==> AtlasTypeRegistry.updateTypesWithNoRefResolve(length={})", (typeDefs == null ? 0 : typeDefs.size()));
} }
entityDefs.addType(entityDef, new AtlasEntityType(entityDef, this)); if (CollectionUtils.isNotEmpty(typeDefs)) {
for (AtlasBaseTypeDef typeDef : typeDefs) {
updateTypeWithNoRefResolve(typeDef);
}
}
if (LOG.isDebugEnabled()) { if (LOG.isDebugEnabled()) {
LOG.debug("<== AtlasTypeRegistry.addEntityDef({})", entityDef); LOG.debug("<== AtlasTypeRegistry.updateTypesWithNoRefResolve(length={})", (typeDefs == null ? 0 : typeDefs.size()));
} }
} }
public Collection<AtlasEntityDef> getAllEntityDefs() { return entityDefs.getAll(); }
public AtlasEntityDef getEntityDefByGuid(String guid) { public Collection<AtlasEnumDef> getAllEnumDefs() { return enumDefs.getAll(); }
return entityDefs.getTypeDefByGuid(guid);
}
public AtlasEntityDef getEntityDefByName(String name) { public AtlasEnumDef getEnumDefByGuid(String guid) {
return entityDefs.getTypeDefByName(name); return enumDefs.getTypeDefByGuid(guid);
} }
public void removeEntityDefByGuid(String guid) { public AtlasEnumDef getEnumDefByName(String name) {
if (LOG.isDebugEnabled()) { return enumDefs.getTypeDefByName(name);
LOG.debug("==> AtlasTypeRegistry.removeEntityDefByGuid({})", guid);
} }
AtlasEntityDef entityDef = entityDefs.getTypeDefByGuid(guid);
if (entityDef != null) { public Collection<AtlasStructDef> getAllStructDefs() { return structDefs.getAll(); }
entityDefs.removeTypeDefByGuid(guid);
}
if (LOG.isDebugEnabled()) { public AtlasStructDef getStructDefByGuid(String guid) {
LOG.debug("<== AtlasTypeRegistry.removeEntityDefByGuid({})", guid); return structDefs.getTypeDefByGuid(guid);
} }
public AtlasStructDef getStructDefByName(String name) { return structDefs.getTypeDefByName(name); }
public Collection<AtlasClassificationDef> getAllClassificationDefs() { return classificationDefs.getAll(); }
public AtlasClassificationDef getClassificationDefByGuid(String guid) {
return classificationDefs.getTypeDefByGuid(guid);
} }
public void removeEntityDefByName(String name) { public AtlasClassificationDef getClassificationDefByName(String name) {
if (LOG.isDebugEnabled()) { return classificationDefs.getTypeDefByName(name);
LOG.debug("==> AtlasTypeRegistry.removeEntityDefByName({})", name);
} }
AtlasEntityDef entityDef = entityDefs.getTypeDefByName(name);
if (entityDef != null) { public Collection<AtlasEntityDef> getAllEntityDefs() { return entityDefs.getAll(); }
entityDefs.removeTypeDefByName(name);
public AtlasEntityDef getEntityDefByGuid(String guid) {
return entityDefs.getTypeDefByGuid(guid);
} }
if (LOG.isDebugEnabled()) { public AtlasEntityDef getEntityDefByName(String name) {
LOG.debug("<== AtlasTypeRegistry.removeEntityDefByName({})", name); return entityDefs.getTypeDefByName(name);
} }
public void resolveReferences() throws AtlasBaseException {
for (Map.Entry<String, AtlasType> e : allTypes.entrySet()) {
e.getValue().resolveReferences(this);
} }
}
private void registerType(AtlasType dataType) { private void registerType(AtlasType dataType) {
allTypes.put(dataType.getTypeName(), dataType); allTypes.put(dataType.getTypeName(), dataType);
...@@ -378,6 +503,7 @@ public class AtlasTypeRegistry { ...@@ -378,6 +503,7 @@ public class AtlasTypeRegistry {
allTypes.remove(typeName); allTypes.remove(typeName);
} }
class TypeDefCache<T extends AtlasBaseTypeDef> { class TypeDefCache<T extends AtlasBaseTypeDef> {
private final AtlasTypeRegistry typeRegistry; private final AtlasTypeRegistry typeRegistry;
private final Map<String, T> typeDefGuidMap = new ConcurrentHashMap<String, T>(); private final Map<String, T> typeDefGuidMap = new ConcurrentHashMap<String, T>();
...@@ -419,23 +545,24 @@ public class AtlasTypeRegistry { ...@@ -419,23 +545,24 @@ public class AtlasTypeRegistry {
public void removeTypeDefByGuid(String guid) { public void removeTypeDefByGuid(String guid) {
T typeDef = guid != null ? typeDefGuidMap.remove(guid) : null; T typeDef = guid != null ? typeDefGuidMap.remove(guid) : null;
String name = typeDef != null ? typeDef.getName() : null;
if (typeDef != null) { if (name != null) {
if (StringUtils.isNotEmpty(typeDef.getName())) { typeDefNameMap.remove(name);
typeDefNameMap.remove(typeDef.getName()); typeRegistry.unregisterTypeByName(name);
typeRegistry.unregisterTypeByName(typeDef.getName());
}
} }
} }
public void removeTypeDefByName(String name) { public void removeTypeDefByName(String name) {
T typeDef = name != null ? typeDefNameMap.get(name) : null; T typeDef = name != null ? typeDefNameMap.get(name) : null;
String guid = typeDef != null ? typeDef.getGuid() : null;
if (typeDef != null) { if (guid != null) {
if (StringUtils.isNotEmpty(typeDef.getGuid())) { typeDefGuidMap.remove(guid);
typeDefGuidMap.remove(typeDef.getGuid());
typeRegistry.unregisterTypeByName(typeDef.getName());
} }
if (name != null) {
typeRegistry.unregisterTypeByName(name);
} }
} }
} }
......
...@@ -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);
......
...@@ -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)
......
...@@ -32,12 +32,15 @@ import org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs; ...@@ -32,12 +32,15 @@ import org.apache.atlas.model.typedef.AtlasStructDef.AtlasStructDefs;
import org.apache.atlas.model.typedef.AtlasTypesDef; import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.repository.util.FilterUtil; import org.apache.atlas.repository.util.FilterUtil;
import org.apache.atlas.store.AtlasTypeDefStore; import org.apache.atlas.store.AtlasTypeDefStore;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.util.TypeDefSorter; import org.apache.atlas.util.TypeDefSorter;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate; import org.apache.commons.collections.Predicate;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -49,14 +52,39 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -49,14 +52,39 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
private static final Logger LOG = LoggerFactory.getLogger(AtlasTypeDefGraphStore.class); private static final Logger LOG = LoggerFactory.getLogger(AtlasTypeDefGraphStore.class);
protected AtlasEnumDefStore enumDefStore; private AtlasTypeRegistry typeRegistry;
protected AtlasStructDefStore structDefStore; private AtlasEnumDefStore enumDefStore;
protected AtlasClassificationDefStore classificationDefStore; private AtlasStructDefStore structDefStore;
protected AtlasEntityDefStore entityDefStore; private AtlasClassificationDefStore classificationDefStore;
private AtlasEntityDefStore entityDefStore;
protected AtlasTypeDefGraphStore() { protected AtlasTypeDefGraphStore() {
} }
protected void init(AtlasEnumDefStore enumDefStore,
AtlasStructDefStore structDefStore,
AtlasClassificationDefStore classificationDefStore,
AtlasEntityDefStore entityDefStore) throws AtlasBaseException {
AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
typeRegistry.addTypesWithNoRefResolve(enumDefStore.getAll());
typeRegistry.addTypesWithNoRefResolve(structDefStore.getAll());
typeRegistry.addTypesWithNoRefResolve(classificationDefStore.getAll());
typeRegistry.addTypesWithNoRefResolve(entityDefStore.getAll());
typeRegistry.resolveReferences();
this.enumDefStore = enumDefStore;
this.structDefStore = structDefStore;
this.classificationDefStore = classificationDefStore;
this.entityDefStore = entityDefStore;
this.typeRegistry = typeRegistry;
}
public AtlasTypeRegistry getTypeRegistry() {
return typeRegistry;
}
@Override @Override
public void init() throws AtlasBaseException { public void init() throws AtlasBaseException {
...@@ -65,55 +93,87 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -65,55 +93,87 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws AtlasBaseException { public AtlasEnumDef createEnumDef(AtlasEnumDef enumDef) throws AtlasBaseException {
return enumDefStore.create(enumDef); AtlasEnumDef ret = enumDefStore.create(enumDef);
typeRegistry.addType(ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public List<AtlasEnumDef> createEnumDefs(List<AtlasEnumDef> atlasEnumDefs) throws AtlasBaseException { public List<AtlasEnumDef> createEnumDefs(List<AtlasEnumDef> atlasEnumDefs) throws AtlasBaseException {
return enumDefStore.create(atlasEnumDefs); List<AtlasEnumDef> ret = enumDefStore.create(atlasEnumDefs);
typeRegistry.addTypes(ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public List<AtlasEnumDef> getAllEnumDefs() throws AtlasBaseException { public List<AtlasEnumDef> getAllEnumDefs() throws AtlasBaseException {
return enumDefStore.getAll(); List<AtlasEnumDef> ret = null;
Collection<AtlasEnumDef> enumDefs = typeRegistry.getAllEnumDefs();
if (enumDefs != null) {
ret = new ArrayList<>(enumDefs);
}
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEnumDef getEnumDefByName(String name) throws AtlasBaseException { public AtlasEnumDef getEnumDefByName(String name) throws AtlasBaseException {
return enumDefStore.getByName(name); AtlasEnumDef ret = typeRegistry.getEnumDefByName(name);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEnumDef getEnumDefByGuid(String guid) throws AtlasBaseException { public AtlasEnumDef getEnumDefByGuid(String guid) throws AtlasBaseException {
return enumDefStore.getByGuid(guid); AtlasEnumDef ret = typeRegistry.getEnumDefByGuid(guid);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEnumDef updateEnumDefByName(String name, AtlasEnumDef enumDef) throws AtlasBaseException { public AtlasEnumDef updateEnumDefByName(String name, AtlasEnumDef enumDef) throws AtlasBaseException {
return enumDefStore.updateByName(name, enumDef); AtlasEnumDef ret = enumDefStore.updateByName(name, enumDef);
typeRegistry.updateTypeByName(name, ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEnumDef updateEnumDefByGuid(String guid, AtlasEnumDef enumDef) throws AtlasBaseException { public AtlasEnumDef updateEnumDefByGuid(String guid, AtlasEnumDef enumDef) throws AtlasBaseException {
return enumDefStore.updateByGuid(guid, enumDef); AtlasEnumDef ret = enumDefStore.updateByGuid(guid, enumDef);
typeRegistry.updateTypeByGuid(guid, ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public void deleteEnumDefByName(String name) throws AtlasBaseException { public void deleteEnumDefByName(String name) throws AtlasBaseException {
enumDefStore.deleteByName(name); enumDefStore.deleteByName(name);
typeRegistry.removeTypeByName(name);
} }
@Override @Override
@GraphTransaction @GraphTransaction
public void deleteEnumDefByGuid(String guid) throws AtlasBaseException { public void deleteEnumDefByGuid(String guid) throws AtlasBaseException {
enumDefStore.deleteByGuid(guid); enumDefStore.deleteByGuid(guid);
typeRegistry.removeTypeByGuid(guid);
} }
@Override @Override
...@@ -125,55 +185,87 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -125,55 +185,87 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasBaseException { public AtlasStructDef createStructDef(AtlasStructDef structDef) throws AtlasBaseException {
return structDefStore.create(structDef); AtlasStructDef ret = structDefStore.create(structDef);
typeRegistry.addType(structDef);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public List<AtlasStructDef> createStructDefs(List<AtlasStructDef> structDefs) throws AtlasBaseException { public List<AtlasStructDef> createStructDefs(List<AtlasStructDef> structDefs) throws AtlasBaseException {
return structDefStore.create(structDefs); List<AtlasStructDef> ret = structDefStore.create(structDefs);
typeRegistry.addTypes(ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public List<AtlasStructDef> getAllStructDefs() throws AtlasBaseException { public List<AtlasStructDef> getAllStructDefs() throws AtlasBaseException {
return structDefStore.getAll(); List<AtlasStructDef> ret = null;
Collection<AtlasStructDef> structDefs = typeRegistry.getAllStructDefs();
if (structDefs != null) {
ret = new ArrayList<>(structDefs);
}
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasStructDef getStructDefByName(String name) throws AtlasBaseException { public AtlasStructDef getStructDefByName(String name) throws AtlasBaseException {
return structDefStore.getByName(name); AtlasStructDef ret = typeRegistry.getStructDefByName(name);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasStructDef getStructDefByGuid(String guid) throws AtlasBaseException { public AtlasStructDef getStructDefByGuid(String guid) throws AtlasBaseException {
return structDefStore.getByGuid(guid); AtlasStructDef ret = typeRegistry.getStructDefByGuid(guid);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasStructDef updateStructDefByName(String name, AtlasStructDef structDef) throws AtlasBaseException { public AtlasStructDef updateStructDefByName(String name, AtlasStructDef structDef) throws AtlasBaseException {
return structDefStore.updateByName(name, structDef); AtlasStructDef ret = structDefStore.updateByName(name, structDef);
typeRegistry.updateTypeByName(name, ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasStructDef updateStructDefByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException { public AtlasStructDef updateStructDefByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException {
return structDefStore.updateByGuid(guid, structDef); AtlasStructDef ret = structDefStore.updateByGuid(guid, structDef);
typeRegistry.updateTypeByGuid(guid, ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public void deleteStructDefByName(String name) throws AtlasBaseException { public void deleteStructDefByName(String name) throws AtlasBaseException {
structDefStore.deleteByName(name); structDefStore.deleteByName(name);
typeRegistry.removeTypeByName(name);
} }
@Override @Override
@GraphTransaction @GraphTransaction
public void deleteStructDefByGuid(String guid) throws AtlasBaseException { public void deleteStructDefByGuid(String guid) throws AtlasBaseException {
structDefStore.deleteByGuid(guid); structDefStore.deleteByGuid(guid);
typeRegistry.removeTypeByGuid(guid);
} }
@Override @Override
...@@ -184,56 +276,92 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -184,56 +276,92 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef) throws AtlasBaseException { public AtlasClassificationDef createClassificationDef(AtlasClassificationDef classificationDef)
return classificationDefStore.create(classificationDef); throws AtlasBaseException {
AtlasClassificationDef ret = classificationDefStore.create(classificationDef);
typeRegistry.addType(classificationDef);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public List<AtlasClassificationDef> createClassificationDefs(List<AtlasClassificationDef> classificationDefs) throws AtlasBaseException { public List<AtlasClassificationDef> createClassificationDefs(List<AtlasClassificationDef> classificationDefs)
return classificationDefStore.create(classificationDefs); throws AtlasBaseException {
List<AtlasClassificationDef> ret = classificationDefStore.create(classificationDefs);
typeRegistry.addTypes(ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public List<AtlasClassificationDef> getAllClassificationDefs() throws AtlasBaseException { public List<AtlasClassificationDef> getAllClassificationDefs() throws AtlasBaseException {
return classificationDefStore.getAll(); List<AtlasClassificationDef> ret = null;
Collection<AtlasClassificationDef> classificationDefs = typeRegistry.getAllClassificationDefs();
if (classificationDefs != null) {
ret = new ArrayList<>(classificationDefs);
}
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasClassificationDef getClassificationDefByName(String name) throws AtlasBaseException { public AtlasClassificationDef getClassificationDefByName(String name) throws AtlasBaseException {
return classificationDefStore.getByName(name); AtlasClassificationDef ret = typeRegistry.getClassificationDefByName(name);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasClassificationDef getClassificationDefByGuid(String guid) throws AtlasBaseException { public AtlasClassificationDef getClassificationDefByGuid(String guid) throws AtlasBaseException {
return classificationDefStore.getByGuid(guid); AtlasClassificationDef ret = typeRegistry.getClassificationDefByGuid(guid);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasClassificationDef updateClassificationDefByName(String name, AtlasClassificationDef classificationDef) throws AtlasBaseException { public AtlasClassificationDef updateClassificationDefByName(String name, AtlasClassificationDef classificationDef)
return classificationDefStore.updateByName(name, classificationDef); throws AtlasBaseException {
AtlasClassificationDef ret = classificationDefStore.updateByName(name, classificationDef);
typeRegistry.updateTypeByName(name, ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasClassificationDef updateClassificationDefByGuid(String guid, AtlasClassificationDef classificationDef) throws AtlasBaseException { public AtlasClassificationDef updateClassificationDefByGuid(String guid, AtlasClassificationDef classificationDef)
return classificationDefStore.updateByGuid(guid, classificationDef); throws AtlasBaseException {
AtlasClassificationDef ret = classificationDefStore.updateByGuid(guid, classificationDef);
typeRegistry.updateTypeByGuid(guid, ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public void deleteClassificationDefByName(String name) throws AtlasBaseException { public void deleteClassificationDefByName(String name) throws AtlasBaseException {
classificationDefStore.deleteByName(name); classificationDefStore.deleteByName(name);
typeRegistry.removeTypeByName(name);
} }
@Override @Override
@GraphTransaction @GraphTransaction
public void deleteClassificationDefByGuid(String guid) throws AtlasBaseException { public void deleteClassificationDefByGuid(String guid) throws AtlasBaseException {
classificationDefStore.deleteByGuid(guid); classificationDefStore.deleteByGuid(guid);
typeRegistry.removeTypeByGuid(guid);
} }
@Override @Override
...@@ -244,56 +372,88 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -244,56 +372,88 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEntityDef createEntityDefs(AtlasEntityDef entityDef) throws AtlasBaseException { public AtlasEntityDef createEntityDef(AtlasEntityDef entityDef) throws AtlasBaseException {
return entityDefStore.create(entityDef); AtlasEntityDef ret = entityDefStore.create(entityDef);
typeRegistry.addType(ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public List<AtlasEntityDef> createEntityDefs(List<AtlasEntityDef> entityDefs) throws AtlasBaseException { public List<AtlasEntityDef> createEntityDefs(List<AtlasEntityDef> entityDefs) throws AtlasBaseException {
return entityDefStore.create(entityDefs); List<AtlasEntityDef> ret = entityDefStore.create(entityDefs);
typeRegistry.addTypes(ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public List<AtlasEntityDef> getAllEntityDefs() throws AtlasBaseException { public List<AtlasEntityDef> getAllEntityDefs() throws AtlasBaseException {
return entityDefStore.getAll(); List<AtlasEntityDef> ret = null;
Collection<AtlasEntityDef> entityDefs = typeRegistry.getAllEntityDefs();
if (entityDefs != null) {
ret = new ArrayList<>(entityDefs);
}
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEntityDef getEntityDefByName(String name) throws AtlasBaseException { public AtlasEntityDef getEntityDefByName(String name) throws AtlasBaseException {
return entityDefStore.getByName(name); AtlasEntityDef ret = typeRegistry.getEntityDefByName(name);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEntityDef getEntityDefByGuid(String guid) throws AtlasBaseException { public AtlasEntityDef getEntityDefByGuid(String guid) throws AtlasBaseException {
return entityDefStore.getByGuid(guid); AtlasEntityDef ret = typeRegistry.getEntityDefByGuid(guid);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEntityDef updateEntityDefByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException { public AtlasEntityDef updateEntityDefByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException {
return entityDefStore.updateByName(name, entityDef); AtlasEntityDef ret = entityDefStore.updateByName(name, entityDef);
typeRegistry.updateTypeByName(name, ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasEntityDef updateEntityDefByGuid(String guid, AtlasEntityDef entityDef) throws AtlasBaseException { public AtlasEntityDef updateEntityDefByGuid(String guid, AtlasEntityDef entityDef) throws AtlasBaseException {
return entityDefStore.updateByGuid(guid, entityDef); AtlasEntityDef ret = entityDefStore.updateByGuid(guid, entityDef);
typeRegistry.updateTypeByGuid(guid, ret);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public void deleteEntityDefByName(String name) throws AtlasBaseException { public void deleteEntityDefByName(String name) throws AtlasBaseException {
entityDefStore.deleteByName(name); entityDefStore.deleteByName(name);
typeRegistry.removeTypeByName(name);
} }
@Override @Override
@GraphTransaction @GraphTransaction
public void deleteEntityDefByGuid(String guid) throws AtlasBaseException { public void deleteEntityDefByGuid(String guid) throws AtlasBaseException {
entityDefStore.deleteByGuid(guid); entityDefStore.deleteByGuid(guid);
typeRegistry.removeTypeByGuid(guid);
} }
@Override @Override
...@@ -302,110 +462,48 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore { ...@@ -302,110 +462,48 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
return entityDefStore.search(filter); return entityDefStore.search(filter);
} }
private List<? extends AtlasBaseTypeDef> createOrUpdateTypeDefs(List<? extends AtlasBaseTypeDef> typeDefs, boolean isUpdate) {
List<AtlasBaseTypeDef> ret = Collections.emptyList();
if (CollectionUtils.isNotEmpty(typeDefs)) {
AtlasBaseTypeDef typeDef = typeDefs.get(0);
if (LOG.isDebugEnabled()) {
if (isUpdate) {
LOG.debug("Updating {} {}", typeDefs.size(), typeDef.getClass().getSimpleName());
} else {
LOG.debug("Creating {} {}", typeDefs.size(), typeDef.getClass().getSimpleName());
}
}
if (typeDef instanceof AtlasEntityDef) {
List<AtlasEntityDef> entityDefs = TypeDefSorter.sortTypes((List<AtlasEntityDef>) typeDefs);
try {
if (isUpdate) {
return entityDefStore.update((List<AtlasEntityDef>) typeDefs);
} else {
return entityDefStore.create((List<AtlasEntityDef>) typeDefs);
}
} catch (AtlasBaseException ex) {
LOG.error("Failed to " + (isUpdate ? "update" : "create") + " EntityDefs", ex);
}
} else if (typeDef instanceof AtlasClassificationDef) {
List<AtlasClassificationDef> classificationDefs =
TypeDefSorter.sortTypes((List<AtlasClassificationDef>) typeDefs);
try {
if (isUpdate) {
return classificationDefStore.update((List<AtlasClassificationDef>) typeDefs);
} else {
return classificationDefStore.create((List<AtlasClassificationDef>) typeDefs);
}
} catch (AtlasBaseException ex) {
LOG.error("Failed to " + (isUpdate ? "update" : "create") + " ClassificationDefs", ex);
}
} else if (typeDef instanceof AtlasStructDef) {
try {
if (isUpdate) {
return structDefStore.update((List<AtlasStructDef>) typeDefs);
} else {
return structDefStore.create((List<AtlasStructDef>) typeDefs);
}
} catch (AtlasBaseException ex) {
LOG.error("Failed to " + (isUpdate ? "update" : "create") + " StructDefs", ex);
}
} else if (typeDef instanceof AtlasEnumDef) {
try {
if (isUpdate) {
return enumDefStore.update((List<AtlasEnumDef>) typeDefs);
} else {
return enumDefStore.create((List<AtlasEnumDef>) typeDefs);
}
} catch (AtlasBaseException ex) {
LOG.error("Failed to " + (isUpdate ? "update" : "create") + " EnumDefs", ex);
}
}
}
return ret;
}
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasTypesDef createTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException { public AtlasTypesDef createTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
AtlasTypesDef createdTypeDefs = new AtlasTypesDef();
LOG.info("Creating EnumDefs"); LOG.info("Creating EnumDefs");
List<? extends AtlasBaseTypeDef> createdEnumDefs = createOrUpdateTypeDefs(typesDef.getEnumDefs(), false); List<AtlasEnumDef> enumDefs = enumDefStore.create(typesDef.getEnumDefs());
LOG.info("Creating StructDefs"); List<AtlasStructDef> structDefs = structDefStore.create(typesDef.getStructDefs());
List<? extends AtlasBaseTypeDef> createdStructDefs = createOrUpdateTypeDefs(typesDef.getStructDefs(), false); List<AtlasClassificationDef> classifiDefs = classificationDefStore.create(typesDef.getClassificationDefs());
LOG.info("Creating ClassificationDefs"); List<AtlasEntityDef> entityDefs = entityDefStore.create(typesDef.getEntityDefs());
List<? extends AtlasBaseTypeDef> createdClassificationDefs = createOrUpdateTypeDefs(typesDef.getClassificationDefs(), false);
LOG.info("Creating EntityDefs");
List<? extends AtlasBaseTypeDef> createdEntityDefs = createOrUpdateTypeDefs(typesDef.getEntityDefs(), false);
typesDef.setEnumDefs((List<AtlasEnumDef>) createdEnumDefs);
typesDef.setStructDefs((List<AtlasStructDef>) createdStructDefs);
typesDef.setClassificationDefs((List<AtlasClassificationDef>) createdClassificationDefs);
typesDef.setEntityDefs((List<AtlasEntityDef>) createdEntityDefs);
return typesDef; // typeRegistry should be updated only after resovleReferences() returns success; until then use a temp registry
typeRegistry.addTypes(enumDefs);
typeRegistry.addTypes(structDefs);
typeRegistry.addTypes(classifiDefs);
typeRegistry.addTypes(entityDefs);
typeRegistry.resolveReferences();
AtlasTypesDef ret = new AtlasTypesDef(enumDefs, structDefs, classifiDefs, entityDefs);
return ret;
} }
@Override @Override
@GraphTransaction @GraphTransaction
public AtlasTypesDef updateTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException { public AtlasTypesDef updateTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
AtlasTypesDef createdTypeDefs = new AtlasTypesDef();
LOG.info("Updating EnumDefs"); LOG.info("Updating EnumDefs");
List<? extends AtlasBaseTypeDef> updatedEnumDefs = createOrUpdateTypeDefs(typesDef.getEnumDefs(), true); List<AtlasEnumDef> enumDefs = enumDefStore.update(typesDef.getEnumDefs());
LOG.info("Updating StructDefs"); List<AtlasStructDef> structDefs = structDefStore.update(typesDef.getStructDefs());
List<? extends AtlasBaseTypeDef> updatedStructDefs = createOrUpdateTypeDefs(typesDef.getStructDefs(), true); List<AtlasClassificationDef> classifiDefs = classificationDefStore.update(typesDef.getClassificationDefs());
LOG.info("Updating ClassificationDefs"); List<AtlasEntityDef> entityDefs = entityDefStore.update(typesDef.getEntityDefs());
List<? extends AtlasBaseTypeDef> updatedClassficationDefs = createOrUpdateTypeDefs(typesDef.getClassificationDefs(), true);
LOG.info("Updating EntityDefs");
List<? extends AtlasBaseTypeDef> updatedEntityDefs = createOrUpdateTypeDefs(typesDef.getEntityDefs(), true);
typesDef.setEnumDefs((List<AtlasEnumDef>) updatedEnumDefs);
typesDef.setStructDefs((List<AtlasStructDef>) updatedStructDefs);
typesDef.setClassificationDefs((List<AtlasClassificationDef>) updatedClassficationDefs);
typesDef.setEntityDefs((List<AtlasEntityDef>) updatedEntityDefs);
return typesDef; // typeRegistry should be updated only after resovleReferences() returns success; until then use a temp registry
typeRegistry.updateTypes(enumDefs);
typeRegistry.updateTypes(structDefs);
typeRegistry.updateTypes(classifiDefs);
typeRegistry.updateTypes(entityDefs);
typeRegistry.resolveReferences();
AtlasTypesDef ret = new AtlasTypesDef(enumDefs, structDefs, classifiDefs, entityDefs);
return ret;
} }
......
...@@ -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,24 +434,24 @@ public class AtlasStructDefStoreV1 implements AtlasStructDefStore { ...@@ -430,24 +434,24 @@ 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);
ret.setValuesMinCount(0); ret.setValuesMinCount(0);
......
...@@ -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