Commit 6d94f39c by Aadarsh Jajodia Committed by Sarath Subramanian

ATLAS-3486: Introduce Atlas NamespaceDef

parent b5fe0896
......@@ -161,6 +161,11 @@ public enum AtlasErrorCode {
INVALID_LABEL_LENGTH(400, "ATLAS-400-00-9B", "Invalid label: {0}, label size should not be greater than {1}"),
INVALID_LABEL_CHARACTERS(400, "ATLAS-400-00-9C", "Invalid label: {0}, label should contain alphanumeric characters, '_' or '-'"),
INVALID_PROPAGATION_TYPE(400, "ATLAS-400-00-9D", "Invalid propagation {0} for relationship-type={1}. Default value is {2}"),
DUPLICATE_NAMESPACE_ATTRIBUTE(400, "ATLAS-400-00-094", "Duplicate Namespace Attributes: {0} not allowed within the same namespace: {1}"),
APPLICABLE_ENTITY_TYPES_DELETION_NOT_SUPPORTED(400, "ATLAS-400-00-095", "Cannot remove applicableEntityTypes in Attribute Def: {1}, defined in namespace: {2}"),
NAMESPACE_DEF_MANDATORY_ATTRIBUTE_NOT_ALLOWED(400, "ATLAS-400-00-096", "{0}.{1} : namespaces can not have mandatory attribute"),
NAMESPACE_DEF_UNIQUE_ATTRIBUTE_NOT_ALLOWED(400, "ATLAS-400-00-097", "{0}.{1} : namespaces can not have unique attribute"),
NAMESPACE_DEF_ATTRIBUTE_TYPE_INVALID(400, "ATLAS-400-00-098", "{0}.{1}: invalid attribute type. Namespace attribute cannot be of type entity/classification/struct/namespace"),
UNAUTHORIZED_ACCESS(403, "ATLAS-403-00-001", "{0} is not authorized to perform {1}"),
......
......@@ -18,5 +18,5 @@
package org.apache.atlas.model;
public enum TypeCategory {
PRIMITIVE, OBJECT_ID_TYPE, ENUM, STRUCT, CLASSIFICATION, ENTITY, ARRAY, MAP, RELATIONSHIP
PRIMITIVE, OBJECT_ID_TYPE, ENUM, STRUCT, CLASSIFICATION, ENTITY, ARRAY, MAP, RELATIONSHIP, NAMESPACE
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.model.typedef;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.apache.atlas.model.TypeCategory;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_ONLY;
@JsonAutoDetect(getterVisibility=PUBLIC_ONLY, setterVisibility=PUBLIC_ONLY, fieldVisibility=NONE)
@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown=true)
@XmlRootElement
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AtlasNamespaceDef extends AtlasStructDef implements Serializable {
private static final long serialVersionUID = 1L;
public static final String ATTR_OPTION_APPLICABLE_ENTITY_TYPES = "applicableEntityTypes";
public static final String ATTR_MAX_STRING_LENGTH = "maxStrLength";
public static final String ATTR_VALID_PATTERN = "validPattern";
public AtlasNamespaceDef() {
this(null, null, null, null);
}
public AtlasNamespaceDef(String name, String description) {
this(name, description, null, null, null);
}
public AtlasNamespaceDef(String name, String description, String typeVersion) {
this(name, description, typeVersion, null, null);
}
public AtlasNamespaceDef(String name, String description, String typeVersion, List<AtlasAttributeDef> attributeDefs) {
this(name, description, typeVersion, attributeDefs, null);
}
public AtlasNamespaceDef(String name, String description, String typeVersion, List<AtlasAttributeDef> attributeDefs, Map<String, String> options) {
super(TypeCategory.NAMESPACE, name, description, typeVersion, attributeDefs, options);
}
public AtlasNamespaceDef(AtlasNamespaceDef other) {
super(other);
}
@Override
public String toString() {
return toString(new StringBuilder()).toString();
}
@Override
public StringBuilder toString(StringBuilder sb) {
if (sb == null) {
sb = new StringBuilder();
}
sb.append("AtlasNamespaceDef{");
super.toString(sb);
sb.append('}');
return sb;
}
}
\ No newline at end of file
......@@ -290,9 +290,9 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
private String description;
private int searchWeight = DEFAULT_SEARCHWEIGHT;
private IndexType indexType = null;
private List<AtlasConstraintDef> constraints;
private Map<String, String> options;
private String displayName;
public AtlasAttributeDef() { this(null, null); }
......@@ -373,9 +373,18 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
setDescription((other.getDescription()));
setSearchWeight(other.getSearchWeight());
setIndexType(other.getIndexType());
setDisplayName(other.getDisplayName());
}
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getDisplayName() {
return displayName;
}
public int getSearchWeight() {
return searchWeight;
}
......@@ -510,6 +519,22 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
getOptions().get(AtlasAttributeDef.ATTRDEF_OPTION_SOFT_REFERENCE).equals(STRING_TRUE);
}
@JsonIgnore
public void setOption(String name, String value) {
if (this.options == null) {
this.options = new HashMap<>();
}
this.options.put(name, value);
}
@JsonIgnore
public String getOption(String name) {
Map<String, String> option = this.options;
return option != null ? option.get(name) : null;
}
public String getDescription() {
return description;
}
......@@ -538,6 +563,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
sb.append(", options='").append(options).append('\'');
sb.append(", searchWeight='").append(searchWeight).append('\'');
sb.append(", indexType='").append(indexType).append('\'');
sb.append(", displayName='").append(displayName).append('\'');
sb.append(", constraints=[");
if (CollectionUtils.isNotEmpty(constraints)) {
int i = 0;
......@@ -574,12 +600,13 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
Objects.equals(constraints, that.constraints) &&
Objects.equals(options, that.options) &&
Objects.equals(searchWeight, that.searchWeight) &&
Objects.equals(indexType, that.indexType);
Objects.equals(indexType, that.indexType) &&
Objects.equals(displayName, that.displayName);
}
@Override
public int hashCode() {
return Objects.hash(name, typeName, isOptional, cardinality, valuesMinCount, valuesMaxCount, isUnique, isIndexable, includeInNotification, defaultValue, constraints, options, description, searchWeight, indexType);
return Objects.hash(name, typeName, isOptional, cardinality, valuesMinCount, valuesMaxCount, isUnique, isIndexable, includeInNotification, defaultValue, constraints, options, description, searchWeight, indexType, displayName);
}
@Override
......
......@@ -47,6 +47,7 @@ public class AtlasTypesDef {
private List<AtlasClassificationDef> classificationDefs;
private List<AtlasEntityDef> entityDefs;
private List<AtlasRelationshipDef> relationshipDefs;
private List<AtlasNamespaceDef> namespaceDefs;
public AtlasTypesDef() {
enumDefs = new ArrayList<>();
......@@ -54,6 +55,7 @@ public class AtlasTypesDef {
classificationDefs = new ArrayList<>();
entityDefs = new ArrayList<>();
relationshipDefs = new ArrayList<>();
namespaceDefs = new ArrayList<>();
}
/**
......@@ -66,7 +68,7 @@ public class AtlasTypesDef {
*/
public AtlasTypesDef(List<AtlasEnumDef> enumDefs, List<AtlasStructDef> structDefs,
List<AtlasClassificationDef> classificationDefs, List<AtlasEntityDef> entityDefs) {
this(enumDefs, structDefs, classificationDefs, entityDefs,new ArrayList<AtlasRelationshipDef>());
this(enumDefs, structDefs, classificationDefs, entityDefs, new ArrayList<>(), new ArrayList<>());
}
/**
* Create the TypesDef. This created definitions for each of the types.
......@@ -81,12 +83,23 @@ public class AtlasTypesDef {
List<AtlasClassificationDef> classificationDefs,
List<AtlasEntityDef> entityDefs,
List<AtlasRelationshipDef> relationshipDefs) {
this(enumDefs, structDefs, classificationDefs, entityDefs, relationshipDefs, new ArrayList<>());
}
public AtlasTypesDef(List<AtlasEnumDef> enumDefs,
List<AtlasStructDef> structDefs,
List<AtlasClassificationDef> classificationDefs,
List<AtlasEntityDef> entityDefs,
List<AtlasRelationshipDef> relationshipDefs,
List<AtlasNamespaceDef> namespaceDefs) {
this.enumDefs = enumDefs;
this.structDefs = structDefs;
this.classificationDefs = classificationDefs;
this.entityDefs = entityDefs;
this.relationshipDefs = relationshipDefs;
this.namespaceDefs = namespaceDefs;
}
public List<AtlasEnumDef> getEnumDefs() {
return enumDefs;
}
......@@ -125,6 +138,14 @@ public class AtlasTypesDef {
this.relationshipDefs = relationshipDefs;
}
public void setNamespaceDefs(List<AtlasNamespaceDef> namespaceDefs) {
this.namespaceDefs = namespaceDefs;
}
public List<AtlasNamespaceDef> getNamespaceDefs() {
return namespaceDefs;
}
public boolean hasClassificationDef(String name) {
return hasTypeDef(classificationDefs, name);
}
......@@ -144,6 +165,9 @@ public class AtlasTypesDef {
return hasTypeDef(relationshipDefs, name);
}
public boolean hasNamespaceDef(String name) {
return hasTypeDef(namespaceDefs, name);
}
private <T extends AtlasBaseTypeDef> boolean hasTypeDef(Collection<T> typeDefs, String name) {
if (CollectionUtils.isNotEmpty(typeDefs)) {
......@@ -163,7 +187,8 @@ public class AtlasTypesDef {
CollectionUtils.isEmpty(structDefs) &&
CollectionUtils.isEmpty(classificationDefs) &&
CollectionUtils.isEmpty(entityDefs) &&
CollectionUtils.isEmpty(relationshipDefs);
CollectionUtils.isEmpty(relationshipDefs) &&
CollectionUtils.isEmpty(namespaceDefs);
}
public void clear() {
......@@ -185,6 +210,10 @@ public class AtlasTypesDef {
if (relationshipDefs != null) {
relationshipDefs.clear();
}
if (namespaceDefs != null) {
namespaceDefs.clear();
}
}
public StringBuilder toString(StringBuilder sb) {
if (sb == null) {
......@@ -206,6 +235,8 @@ public class AtlasTypesDef {
sb.append("}");
sb.append("relationshipDefs={");
AtlasBaseTypeDef.dumpObjects(relationshipDefs, sb);
sb.append("namespaceDefs={");
AtlasBaseTypeDef.dumpObjects(namespaceDefs, sb);
sb.append("}");
return sb;
......
......@@ -23,6 +23,7 @@ import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasNamespaceDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
......@@ -85,6 +86,11 @@ public interface AtlasTypeDefStore {
AtlasRelationshipDef updateRelationshipDefByGuid(String guid, AtlasRelationshipDef structDef) throws AtlasBaseException;
/* Namespace Def operations */
AtlasNamespaceDef getNamespaceDefByName(String name) throws AtlasBaseException;
AtlasNamespaceDef getNamespaceDefByGuid(String guid) throws AtlasBaseException;
/* Bulk Operations */
AtlasTypesDef createTypesDef(AtlasTypesDef atlasTypesDef) throws AtlasBaseException;
......
......@@ -31,6 +31,7 @@ import org.apache.atlas.model.typedef.AtlasEntityDef.AtlasRelationshipAttributeD
import org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.type.AtlasBuiltInTypes.AtlasObjectIdType;
import org.apache.atlas.type.AtlasNamespaceType.AtlasNamespaceAttribute;
import org.apache.atlas.utils.AtlasEntityUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
......@@ -47,6 +48,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* class that implements behaviour of an entity-type.
*/
......@@ -72,22 +74,23 @@ public class AtlasEntityType extends AtlasStructType {
private final AtlasEntityDef entityDef;
private final String typeQryStr;
private List<AtlasEntityType> superTypes = Collections.emptyList();
private Set<String> allSuperTypes = Collections.emptySet();
private Set<String> subTypes = Collections.emptySet();
private Set<String> allSubTypes = Collections.emptySet();
private Set<String> typeAndAllSubTypes = Collections.emptySet();
private Set<String> typeAndAllSuperTypes = Collections.emptySet();
private Map<String, Map<String, AtlasAttribute>> relationshipAttributes = Collections.emptyMap();
private List<AtlasAttribute> ownedRefAttributes = Collections.emptyList();
private String typeAndAllSubTypesQryStr = "";
private boolean isInternalType = false;
private Map<String, AtlasAttribute> headerAttributes = Collections.emptyMap();
private Map<String, AtlasAttribute> minInfoAttributes = Collections.emptyMap();
private List<AtlasAttribute> dynAttributes = Collections.emptyList();
private List<AtlasAttribute> dynEvalTriggerAttributes = Collections.emptyList();
private Map<String,List<TemplateToken>> parsedTemplates = Collections.emptyMap();
private Set<String> tagPropagationEdges = Collections.emptySet();
private List<AtlasEntityType> superTypes = Collections.emptyList();
private Set<String> allSuperTypes = Collections.emptySet();
private Set<String> subTypes = Collections.emptySet();
private Set<String> allSubTypes = Collections.emptySet();
private Set<String> typeAndAllSubTypes = Collections.emptySet();
private Set<String> typeAndAllSuperTypes = Collections.emptySet();
private Map<String, Map<String, AtlasAttribute>> relationshipAttributes = Collections.emptyMap();
private List<AtlasAttribute> ownedRefAttributes = Collections.emptyList();
private String typeAndAllSubTypesQryStr = "";
private boolean isInternalType = false;
private Map<String, AtlasAttribute> headerAttributes = Collections.emptyMap();
private Map<String, AtlasAttribute> minInfoAttributes = Collections.emptyMap();
private List<AtlasAttribute> dynAttributes = Collections.emptyList();
private List<AtlasAttribute> dynEvalTriggerAttributes = Collections.emptyList();
private Map<String,List<TemplateToken>> parsedTemplates = Collections.emptyMap();
private Set<String> tagPropagationEdges = Collections.emptySet();
private Map<String, List<AtlasNamespaceAttribute>> namespaceAttributes = Collections.emptyMap();
public AtlasEntityType(AtlasEntityDef entityDef) {
super(entityDef);
......@@ -140,6 +143,7 @@ public class AtlasEntityType extends AtlasStructType {
this.typeAndAllSubTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2()
this.relationshipAttributes = new HashMap<>(); // this will be populated in resolveReferencesPhase3()
this.tagPropagationEdges = new HashSet<>(); // this will be populated in resolveReferencesPhase2()
this.namespaceAttributes = new HashMap<>(); // this will be populated in resolveReferences(), from AtlasNamespaceType
this.typeAndAllSubTypes.add(this.getTypeName());
......@@ -259,6 +263,7 @@ public class AtlasEntityType extends AtlasStructType {
relationshipAttributes = Collections.unmodifiableMap(relationshipAttributes);
ownedRefAttributes = Collections.unmodifiableList(ownedRefAttributes);
tagPropagationEdges = Collections.unmodifiableSet(tagPropagationEdges);
namespaceAttributes = Collections.unmodifiableMap(namespaceAttributes);
entityDef.setSubTypes(subTypes);
......@@ -361,6 +366,14 @@ public class AtlasEntityType extends AtlasStructType {
public String[] getTagPropagationEdgesArray() {
return CollectionUtils.isNotEmpty(tagPropagationEdges) ? tagPropagationEdges.toArray(new String[tagPropagationEdges.size()]) : null;
}
public Map<String, List<AtlasNamespaceAttribute>> getNamespaceAttributes() {
return namespaceAttributes;
}
public List<AtlasNamespaceAttribute> getNamespaceAttributes(String nsName) {
return namespaceAttributes.get(nsName);
}
public Map<String,List<TemplateToken>> getParsedTemplates() { return parsedTemplates; }
......@@ -452,6 +465,19 @@ public class AtlasEntityType extends AtlasStructType {
return relationshipAttributes.containsKey(attributeName);
}
public void addNamespaceAttribute(AtlasNamespaceAttribute attribute) {
String nsName = attribute.getDefinedInType().getTypeName();
List<AtlasNamespaceAttribute> attributes = namespaceAttributes.get(nsName);
if (attributes == null) {
attributes = new ArrayList<>();
namespaceAttributes.put(nsName, attributes);
}
attributes.add(attribute);
}
public String getQualifiedAttributeName(String attrName) throws AtlasBaseException {
AtlasAttribute ret = getAttribute(attrName);
......
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.type;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.instance.AtlasStruct;
import org.apache.atlas.model.typedef.AtlasNamespaceDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
import static org.apache.atlas.model.typedef.AtlasNamespaceDef.*;
public class AtlasNamespaceType extends AtlasStructType {
private static final Logger LOG = LoggerFactory.getLogger(AtlasNamespaceType.class);
private final AtlasNamespaceDef namespaceDef;
public AtlasNamespaceType(AtlasNamespaceDef namespaceDef) {
super(namespaceDef);
this.namespaceDef = namespaceDef;
}
@Override
public boolean isValidValue(Object o) {
return true; // there is no runtime instance for Namespaces, so return true
}
@Override
public AtlasStruct createDefaultValue() {
return null; // there is no runtime instance for Namespaces, so return null
}
@Override
public Object getNormalizedValue(Object a) {
return null; // there is no runtime instance for Namespaces, so return null
}
public AtlasNamespaceDef getNamespaceDef() {
return namespaceDef;
}
@Override
void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
super.resolveReferences(typeRegistry);
Map<String, AtlasNamespaceAttribute> a = new HashMap<>();
for (AtlasAttribute attribute : super.allAttributes.values()) {
AtlasAttributeDef attributeDef = attribute.getAttributeDef();
String attrName = attribute.getName();
AtlasType attrType = attribute.getAttributeType();
if (attrType instanceof AtlasArrayType) {
attrType = ((AtlasArrayType) attrType).getElementType();
} else if (attrType instanceof AtlasMapType) {
attrType = ((AtlasMapType) attrType).getValueType();
}
// check if attribute type is not struct/classification/entity/namespace
if (attrType instanceof AtlasStructType) {
throw new AtlasBaseException(AtlasErrorCode.NAMESPACE_DEF_ATTRIBUTE_TYPE_INVALID, getTypeName(), attrName);
}
if (!attributeDef.getIsOptional()) {
throw new AtlasBaseException(AtlasErrorCode.NAMESPACE_DEF_MANDATORY_ATTRIBUTE_NOT_ALLOWED, getTypeName(), attrName);
}
if (attributeDef.getIsUnique()) {
throw new AtlasBaseException(AtlasErrorCode.NAMESPACE_DEF_UNIQUE_ATTRIBUTE_NOT_ALLOWED, getTypeName(), attrName);
}
Set<String> entityTypeNames = attribute.getOptionSet(ATTR_OPTION_APPLICABLE_ENTITY_TYPES);
Set<AtlasEntityType> entityTypes = new HashSet<>();
if (CollectionUtils.isNotEmpty(entityTypeNames)) {
for (String entityTypeName : entityTypeNames) {
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);
if (entityType == null) {
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, entityTypeName);
}
entityTypes.add(entityType);
}
} else {
throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, attributeDef.getName(), "options." + ATTR_OPTION_APPLICABLE_ENTITY_TYPES);
}
AtlasNamespaceAttribute nsAttribute;
if (attribute.getAttributeType() instanceof AtlasBuiltInTypes.AtlasStringType) {
Integer maxStringLength = attribute.getOptionInt(ATTR_MAX_STRING_LENGTH);
if (maxStringLength == null) {
throw new AtlasBaseException(AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE, attributeDef.getName(), "options." + ATTR_MAX_STRING_LENGTH);
}
String validPattern = attribute.getOptionString(ATTR_VALID_PATTERN);
nsAttribute = new AtlasNamespaceAttribute(attribute, entityTypes, maxStringLength, validPattern);
} else {
nsAttribute = new AtlasNamespaceAttribute(attribute, entityTypes);
}
a.put(attrName, nsAttribute);
}
super.allAttributes = Collections.unmodifiableMap(a);
}
@Override
void resolveReferencesPhase2(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
super.resolveReferencesPhase2(typeRegistry);
for (AtlasAttribute attribute : super.allAttributes.values()) {
AtlasNamespaceAttribute nsAttribute = (AtlasNamespaceAttribute) attribute;
Set<AtlasEntityType> entityTypes = nsAttribute.getApplicableEntityTypes();
if (CollectionUtils.isNotEmpty(entityTypes)) {
for (AtlasEntityType entityType : entityTypes) {
entityType.addNamespaceAttribute(nsAttribute);
}
}
}
}
public static class AtlasNamespaceAttribute extends AtlasAttribute {
private final Set<AtlasEntityType> applicableEntityTypes;
private final int maxStringLength;
private final String validPattern;
public AtlasNamespaceAttribute(AtlasAttribute attribute, Set<AtlasEntityType> applicableEntityTypes) {
super(attribute);
this.maxStringLength = 0;
this.validPattern = null;
this.applicableEntityTypes = applicableEntityTypes;
}
public AtlasNamespaceAttribute(AtlasAttribute attribute, Set<AtlasEntityType> applicableEntityTypes,
int maxStringLength, String validPattern) {
super(attribute);
this.maxStringLength = maxStringLength;
this.validPattern = validPattern;
this.applicableEntityTypes = applicableEntityTypes;
}
@Override
public AtlasNamespaceType getDefinedInType() {
return (AtlasNamespaceType) super.getDefinedInType();
}
public Set<AtlasEntityType> getApplicableEntityTypes() {
return applicableEntityTypes;
}
public String getValidPattern() {
return validPattern;
}
public int getMaxStringLength() {
return maxStringLength;
}
}
}
......@@ -112,6 +112,10 @@ public class AtlasStructType extends AtlasType {
throw new AtlasBaseException(AtlasErrorCode.ATTRIBUTE_TYPE_INVALID, getTypeName(), attributeDef.getName());
}
if (attrType instanceof AtlasNamespaceType) {
throw new AtlasBaseException(AtlasErrorCode.ATTRIBUTE_TYPE_INVALID, getTypeName(), attributeDef.getName());
}
a.put(attributeDef.getName(), attribute);
}
......@@ -794,6 +798,26 @@ public class AtlasStructType extends AtlasType {
this(definedInType, attrDef, attributeType, null, null);
}
public AtlasAttribute(AtlasAttribute other) {
this.definedInType = other.definedInType;
this.attributeType = other.attributeType;
this.attributeDef = other.attributeDef;
this.qualifiedName = other.qualifiedName;
this.vertexPropertyName = other.vertexPropertyName;
this.vertexUniquePropertyName = other.vertexUniquePropertyName;
this.isOwnedRef = other.isOwnedRef;
this.isObjectRef = other.isObjectRef;
this.inverseRefAttributeName = other.inverseRefAttributeName;
this.inverseRefAttribute = other.inverseRefAttribute;
this.relationshipName = other.relationshipName;
this.relationshipEdgeLabel = other.relationshipEdgeLabel;
this.relationshipEdgeDirection = other.relationshipEdgeDirection;
this.isLegacyAttribute = other.isLegacyAttribute;
this.indexFieldName = other.indexFieldName;
this.isDynAttribute = false;
this.isDynAttributeEvalTrigger = false;
}
public AtlasStructType getDefinedInType() { return definedInType; }
public AtlasStructDef getDefinedInDef() { return definedInType.getStructDef(); }
......@@ -860,6 +884,27 @@ public class AtlasStructType extends AtlasType {
public void setIsDynAttributeEvalTrigger(boolean isDynAttributeEvalTrigger) { this.isDynAttributeEvalTrigger = isDynAttributeEvalTrigger; }
public Set<String> getOptionSet(String optionName) {
String strValue = attributeDef.getOption(optionName);
Set<String> ret = StringUtils.isBlank(strValue) ? null : AtlasType.fromJson(strValue, Set.class);
return ret;
}
public Integer getOptionInt(String optionName) {
String strValue = attributeDef.getOption(optionName);
Integer ret = StringUtils.isBlank(strValue) ? null : Integer.parseInt(strValue);
return ret;
}
public String getOptionString(String optionName) {
String strValue = attributeDef.getOption(optionName);
String ret = StringUtils.isBlank(strValue) ? null : strValue;
return ret;
}
public static String getEdgeLabel(String property) {
return "__" + property;
}
......
......@@ -23,6 +23,7 @@ import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasNamespaceDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
......@@ -192,6 +193,15 @@ public class AtlasTypeRegistry {
return registryData.classificationDefs.getTypeByName(name);
}
public Collection<AtlasNamespaceType> getAllNamespaceTypes() {
return registryData.namespaceDefs.getAllTypes();
}
public Collection<AtlasNamespaceDef> getAllNamespaceDefs() {
return registryData.namespaceDefs.getAll();
}
public Collection<AtlasRelationshipDef> getAllRelationshipDefs() { return registryData.relationshipDefs.getAll(); }
public Collection<AtlasEntityDef> getAllEntityDefs() { return registryData.entityDefs.getAll(); }
......@@ -217,6 +227,15 @@ public class AtlasTypeRegistry {
public AtlasRelationshipDef getRelationshipDefByName(String name) {
return registryData.relationshipDefs.getTypeDefByName(name);
}
public AtlasNamespaceDef getNamespaceDefByGuid(String guid) {
return registryData.namespaceDefs.getTypeDefByGuid(guid);
}
public AtlasNamespaceDef getNamespaceDefByName(String name) {
return registryData.namespaceDefs.getTypeDefByName(name);
}
public AtlasRelationshipType getRelationshipTypeByName(String name) { return registryData.relationshipDefs.getTypeByName(name); }
public AtlasTransientTypeRegistry lockTypeRegistryForUpdate() throws AtlasBaseException {
......@@ -271,6 +290,7 @@ public class AtlasTypeRegistry {
final TypeDefCache<AtlasClassificationDef, AtlasClassificationType> classificationDefs;
final TypeDefCache<AtlasEntityDef, AtlasEntityType> entityDefs;
final TypeDefCache<AtlasRelationshipDef, AtlasRelationshipType> relationshipDefs;
final TypeDefCache<AtlasNamespaceDef, AtlasNamespaceType> namespaceDefs;
final TypeDefCache<? extends AtlasBaseTypeDef, ? extends AtlasType>[] allDefCaches;
RegistryData() {
......@@ -280,7 +300,9 @@ public class AtlasTypeRegistry {
classificationDefs = new TypeDefCache<>(allTypes);
entityDefs = new TypeDefCache<>(allTypes);
relationshipDefs = new TypeDefCache<>(allTypes);
allDefCaches = new TypeDefCache[] { enumDefs, structDefs, classificationDefs, entityDefs, relationshipDefs };
namespaceDefs = new TypeDefCache<>(allTypes);
allDefCaches = new TypeDefCache[] { enumDefs, structDefs, classificationDefs, entityDefs,
relationshipDefs, namespaceDefs };
init();
}
......@@ -339,6 +361,7 @@ public class AtlasTypeRegistry {
classificationDefs.updateGuid(typeName, guid);
entityDefs.updateGuid(typeName, guid);
relationshipDefs.updateGuid(typeName, guid);
namespaceDefs.updateGuid(typeName, guid);
}
}
......@@ -349,6 +372,7 @@ public class AtlasTypeRegistry {
classificationDefs.removeTypeDefByGuid(guid);
entityDefs.removeTypeDefByGuid(guid);
relationshipDefs.removeTypeDefByGuid(guid);
namespaceDefs.removeTypeDefByGuid(guid);
}
}
......@@ -359,6 +383,7 @@ public class AtlasTypeRegistry {
classificationDefs.removeTypeDefByName(typeName);
entityDefs.removeTypeDefByName(typeName);
relationshipDefs.removeTypeDefByName(typeName);
namespaceDefs.removeTypeDefByName(typeName);
}
}
......@@ -369,7 +394,7 @@ public class AtlasTypeRegistry {
classificationDefs.clear();
entityDefs.clear();
relationshipDefs.clear();
namespaceDefs.clear();
init();
}
}
......@@ -388,6 +413,7 @@ public class AtlasTypeRegistry {
addTypesWithNoRefResolve(parent.getAllClassificationDefs());
addTypesWithNoRefResolve(parent.getAllEntityDefs());
addTypesWithNoRefResolve(parent.getAllRelationshipDefs());
addTypesWithNoRefResolve(parent.getAllNamespaceDefs());
addedTypes.clear();
updatedTypes.clear();
......@@ -467,6 +493,7 @@ public class AtlasTypeRegistry {
addTypesWithNoRefResolve(typesDef.getClassificationDefs());
addTypesWithNoRefResolve(typesDef.getEntityDefs());
addTypesWithNoRefResolve(typesDef.getRelationshipDefs());
addTypesWithNoRefResolve(typesDef.getNamespaceDefs());
}
resolveReferences();
......@@ -567,6 +594,7 @@ public class AtlasTypeRegistry {
updateTypesWithNoRefResolve(typesDef.getClassificationDefs());
updateTypesWithNoRefResolve(typesDef.getEntityDefs());
updateTypesWithNoRefResolve(typesDef.getRelationshipDefs());
updateTypesWithNoRefResolve(typesDef.getNamespaceDefs());
}
if (LOG.isDebugEnabled()) {
......@@ -581,6 +609,7 @@ public class AtlasTypeRegistry {
removeTypesWithNoRefResolve(typesDef.getClassificationDefs());
removeTypesWithNoRefResolve(typesDef.getEntityDefs());
removeTypesWithNoRefResolve(typesDef.getRelationshipDefs());
removeTypesWithNoRefResolve(typesDef.getNamespaceDefs());
}
resolveReferences();
......@@ -615,6 +644,9 @@ public class AtlasTypeRegistry {
case RELATIONSHIP:
registryData.relationshipDefs.removeTypeDefByName(typeDef.getName());
break;
case NAMESPACE:
registryData.namespaceDefs.removeTypeDefByName(typeDef.getName());
break;
}
deletedTypes.add(typeDef);
}
......@@ -636,6 +668,9 @@ public class AtlasTypeRegistry {
case RELATIONSHIP:
registryData.relationshipDefs.removeTypeDefByGuid(typeDef.getGuid());
break;
case NAMESPACE:
registryData.namespaceDefs.removeTypeDefByGuid(typeDef.getGuid());
break;
}
deletedTypes.add(typeDef);
}
......@@ -722,6 +757,9 @@ public class AtlasTypeRegistry {
AtlasRelationshipDef relationshipDef = (AtlasRelationshipDef) typeDef;
registryData.relationshipDefs.addType(relationshipDef, new AtlasRelationshipType(relationshipDef));
} else if (typeDef.getClass().equals(AtlasNamespaceDef.class)) {
AtlasNamespaceDef namespaceDef = (AtlasNamespaceDef) typeDef;
registryData.namespaceDefs.addType(namespaceDef, new AtlasNamespaceType(namespaceDef));
}
addedTypes.add(typeDef);
......@@ -801,6 +839,11 @@ public class AtlasTypeRegistry {
registryData.relationshipDefs.removeTypeDefByGuid(guid);
registryData.relationshipDefs.addType(relationshipDef, new AtlasRelationshipType(relationshipDef));
} else if (typeDef.getClass().equals(AtlasNamespaceDef.class)) {
AtlasNamespaceDef namespaceDef = (AtlasNamespaceDef) typeDef;
registryData.namespaceDefs.removeTypeDefByGuid(guid);
registryData.namespaceDefs.addType(namespaceDef, new AtlasNamespaceType(namespaceDef));
}
updatedTypes.add(typeDef);
......@@ -843,6 +886,11 @@ public class AtlasTypeRegistry {
registryData.relationshipDefs.removeTypeDefByName(name);
registryData.relationshipDefs.addType(relationshipDef, new AtlasRelationshipType(relationshipDef));
} else if (typeDef.getClass().equals(AtlasNamespaceDef.class)) {
AtlasNamespaceDef namespaceDef = (AtlasNamespaceDef) typeDef;
registryData.namespaceDefs.removeTypeDefByName(name);
registryData.namespaceDefs.addType(namespaceDef, new AtlasNamespaceType(namespaceDef));
}
updatedTypes.add(typeDef);
......
......@@ -28,6 +28,7 @@ import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef;
import org.apache.atlas.model.typedef.AtlasNamespaceDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags;
import org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory;
......@@ -315,6 +316,15 @@ public class AtlasTypeUtil {
return new AtlasTypesDef(enums, structs, traits, classes, relations);
}
public static AtlasTypesDef getTypesDef(List<AtlasEnumDef> enums,
List<AtlasStructDef> structs,
List<AtlasClassificationDef> traits,
List<AtlasEntityDef> classes,
List<AtlasRelationshipDef> relations,
List<AtlasNamespaceDef> namespaces) {
return new AtlasTypesDef(enums, structs, traits, classes, relations, namespaces);
}
public static List<AtlasTypeDefHeader> toTypeDefHeader(AtlasTypesDef typesDef) {
List<AtlasTypeDefHeader> headerList = new LinkedList<>();
if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
......
......@@ -30,6 +30,7 @@ public class DataTypes {
STRUCT,
TRAIT,
CLASS,
RELATIONSHIP
RELATIONSHIP,
NAMESPACE
}
}
\ No newline at end of file
......@@ -27,10 +27,12 @@ import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef;
import org.apache.atlas.model.typedef.AtlasNamespaceDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.model.typedef.AtlasRelationshipEndDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.type.AtlasType;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
......@@ -38,6 +40,7 @@ import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import static org.apache.atlas.model.typedef.AtlasNamespaceDef.ATTR_OPTION_APPLICABLE_ENTITY_TYPES;
import static org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags.BOTH;
import static org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags.ONE_TO_TWO;
import static org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory.AGGREGATION;
......@@ -141,11 +144,25 @@ public final class TestRelationshipUtilsV2 {
new AtlasRelationshipEndDef(PERSON_TYPE, "sibling", SINGLE),
new AtlasRelationshipEndDef(PERSON_TYPE, "sibling", SINGLE));
AtlasStructDef.AtlasAttributeDef nsAttr1 = new AtlasStructDef.AtlasAttributeDef("attr1", "int");
AtlasStructDef.AtlasAttributeDef nsAttr2 = new AtlasStructDef.AtlasAttributeDef("attr2", "int");
nsAttr1.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton(DEPARTMENT_TYPE)));
nsAttr1.setIsOptional(true);
nsAttr1.setIsUnique(false);
nsAttr2.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton(DEPARTMENT_TYPE)));
nsAttr2.setIsOptional(true);
nsAttr2.setIsUnique(false);
AtlasNamespaceDef namespaceDef = new AtlasNamespaceDef("test_namespace", "test_description", DEFAULT_VERSION, Arrays.asList(nsAttr1, nsAttr2));
return new AtlasTypesDef(Collections.singletonList(orgLevelType),
Collections.singletonList(addressType),
Collections.singletonList(securityClearanceType),
Arrays.asList(personType, employeeType, departmentType, managerType),
Arrays.asList(employeeDepartmentType, employeeManagerType, employeeMentorsType, employeeFriendsType, personSiblingType));
Arrays.asList(employeeDepartmentType, employeeManagerType, employeeMentorsType, employeeFriendsType, personSiblingType),
Collections.singletonList(namespaceDef));
}
public static AtlasEntitiesWithExtInfo getDepartmentEmployeeInstances() {
......@@ -278,7 +295,7 @@ public final class TestRelationshipUtilsV2 {
new AtlasRelationshipEndDef(TYPE_A, "mapToB", SET));
return new AtlasTypesDef(Collections.<AtlasEnumDef>emptyList(), Collections.<AtlasStructDef>emptyList(), Collections.<AtlasClassificationDef>emptyList(), Arrays.asList(aType, bType),
Arrays.asList(relationshipType1, relationshipType2, relationshipType3, relationshipType4));
Arrays.asList(relationshipType1, relationshipType2, relationshipType3, relationshipType4), Collections.<AtlasNamespaceDef>emptyList());
}
private static List<AtlasEnumElementDef> getOrgLevelElements() {
......
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.atlas.model.typedef;
import org.apache.atlas.type.AtlasType;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.Collections;
import static org.apache.atlas.model.typedef.AtlasNamespaceDef.ATTR_OPTION_APPLICABLE_ENTITY_TYPES;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
public class TestAtlasNamespaceDef {
@Test
public void namespaceDefSerDes() {
AtlasNamespaceDef namespaceDef = new AtlasNamespaceDef("test_namespace", "test_description", null);
String jsonString = AtlasType.toJson(namespaceDef);
AtlasNamespaceDef namespaceDef1 = AtlasType.fromJson(jsonString, AtlasNamespaceDef.class);
assertEquals(namespaceDef, namespaceDef1,
"Incorrect serialization/deserialization of AtlasNamespaceDef");
}
@Test
public void namespaceDefEquality() {
AtlasNamespaceDef namespaceDef1 = new AtlasNamespaceDef("test_namespace", "test_description", null);
AtlasNamespaceDef namespaceDef2 = new AtlasNamespaceDef("test_namespace", "test_description", null);
assertEquals(namespaceDef1, namespaceDef2, "Namespaces should be equal because the name of the" +
"namespace is same");
}
@Test
public void namespaceDefUnequality() {
AtlasNamespaceDef namespaceDef1 = new AtlasNamespaceDef("test_namespace", "test_description", null);
AtlasNamespaceDef namespaceDef2 = new AtlasNamespaceDef("test_namespace1", "test_description", null);
assertNotEquals(namespaceDef1, namespaceDef2, "Namespaces should not be equal since they have a" +
"different name");
}
@Test
public void namespaceDefWithNamespaceAttributes() {
AtlasNamespaceDef namespaceDef1 = new AtlasNamespaceDef("test_namespace", "test_description", null);
AtlasStructDef.AtlasAttributeDef nsAttr1 = new AtlasStructDef.AtlasAttributeDef("attr1", "int");
AtlasStructDef.AtlasAttributeDef nsAttr2 = new AtlasStructDef.AtlasAttributeDef("attr2", "int");
nsAttr1.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton("hive_table")));
nsAttr2.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton("hive_table")));
namespaceDef1.setAttributeDefs(Arrays.asList(nsAttr1, nsAttr2));
assertEquals(namespaceDef1.getAttributeDefs().size(), 2);
}
@Test
public void namespaceDefWithNamespaceAttributesHavingCardinality() {
AtlasNamespaceDef namespaceDef1 = new AtlasNamespaceDef("test_namespace", "test_description", null);
AtlasStructDef.AtlasAttributeDef nsAttr1 = new AtlasStructDef.AtlasAttributeDef("attr1", "int");
AtlasStructDef.AtlasAttributeDef nsAttr2 = new AtlasStructDef.AtlasAttributeDef("attr2", "int");
nsAttr1.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton("hive_table")));
nsAttr2.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton("hive_table")));
nsAttr2.setCardinality(AtlasStructDef.AtlasAttributeDef.Cardinality.SET);
namespaceDef1.setAttributeDefs(Arrays.asList(nsAttr1, nsAttr2));
assertEquals(namespaceDef1.getAttributeDefs().size(), 2);
}
}
\ No newline at end of file
......@@ -33,6 +33,7 @@ import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasNamespaceDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.repository.Constants;
......
......@@ -347,6 +347,7 @@ public class ExportService {
final Set<String> structTypes = new HashSet<>();
final Set<String> enumTypes = new HashSet<>();
final Set<String> relationshipTypes = new HashSet<>();
final Set<String> namespaceTypes = new HashSet<>();
final AtlasExportResult result;
private final ZipSink sink;
......
......@@ -28,6 +28,7 @@ import org.apache.atlas.type.AtlasClassificationType;
import org.apache.atlas.type.AtlasEntityType;
import org.apache.atlas.type.AtlasEnumType;
import org.apache.atlas.type.AtlasMapType;
import org.apache.atlas.type.AtlasNamespaceType;
import org.apache.atlas.type.AtlasRelationshipType;
import org.apache.atlas.type.AtlasStructType;
import org.apache.atlas.type.AtlasType;
......@@ -103,12 +104,14 @@ class ExportTypeProcessor {
addEntityType((AtlasEntityType)type, context);
} else if (type instanceof AtlasClassificationType) {
addClassificationType((AtlasClassificationType)type, context);
} else if (type instanceof AtlasRelationshipType) {
addRelationshipType(type.getTypeName(), context);
} else if (type instanceof AtlasNamespaceType) {
addNamespaceType((AtlasNamespaceType) type, context);
} else if (type instanceof AtlasStructType) {
addStructType((AtlasStructType)type, context);
} else if (type instanceof AtlasEnumType) {
addEnumType((AtlasEnumType)type, context);
} else if (type instanceof AtlasRelationshipType) {
addRelationshipType(type.getTypeName(), context);
}
}
......@@ -169,6 +172,14 @@ class ExportTypeProcessor {
}
}
private void addNamespaceType(AtlasNamespaceType namespaceType, ExportService.ExportContext context) {
if (!context.namespaceTypes.contains(namespaceType.getTypeName())) {
context.namespaceTypes.add(namespaceType.getTypeName());
addAttributeTypes(namespaceType, context);
}
}
private void addAttributeTypes(AtlasStructType structType, ExportService.ExportContext context) {
for (AtlasStructDef.AtlasAttributeDef attributeDef : structType.getStructDef().getAttributeDefs()) {
addType(attributeDef.getTypeName(), context);
......
......@@ -34,13 +34,13 @@ import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef;
import org.apache.atlas.model.typedef.AtlasNamespaceDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory;
import org.apache.atlas.model.typedef.AtlasRelationshipEndDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graph.GraphBackedSearchIndexer;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.patches.AtlasPatchRegistry;
......@@ -55,7 +55,6 @@ import org.apache.commons.collections.MapUtils;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jute.Index;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
......@@ -253,6 +252,14 @@ public class AtlasTypeDefStoreInitializer implements ActiveStateChangeHandler {
}
}
if (CollectionUtils.isNotEmpty(typesDef.getNamespaceDefs())) {
for (AtlasNamespaceDef namespaceDef : typesDef.getNamespaceDefs()) {
if (!typeRegistry.isRegisteredType(namespaceDef.getName())) {
typesToCreate.getNamespaceDefs().add(namespaceDef);
}
}
}
return typesToCreate;
}
......@@ -337,6 +344,20 @@ public class AtlasTypeDefStoreInitializer implements ActiveStateChangeHandler {
}
}
if (CollectionUtils.isNotEmpty(typesDef.getNamespaceDefs())) {
for (AtlasNamespaceDef namespaceDef : typesDef.getNamespaceDefs()) {
AtlasNamespaceDef oldNamespaceDef = typeRegistry.getNamespaceDefByName(namespaceDef.getName());
if (oldNamespaceDef == null) {
continue;
}
if (updateTypeAttributes(oldNamespaceDef, namespaceDef, checkTypeVersion)) {
typesToUpdate.getNamespaceDefs().add(namespaceDef);
}
}
}
return typesToUpdate;
}
......
......@@ -19,17 +19,6 @@ package org.apache.atlas.repository.store.graph.v2;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import static org.apache.atlas.repository.Constants.TYPE_CATEGORY_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.VERTEX_TYPE_PROPERTY_KEY;
import static org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2.VERTEX_TYPE;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.RequestContext;
import org.apache.atlas.annotation.GraphTransaction;
......@@ -37,8 +26,12 @@ import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.listener.TypeDefChangeListener;
import org.apache.atlas.model.typedef.*;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.graphdb.*;
import org.apache.atlas.repository.store.graph.*;
import org.apache.atlas.repository.graphdb.AtlasEdge;
import org.apache.atlas.repository.graphdb.AtlasEdgeDirection;
import org.apache.atlas.repository.graphdb.AtlasGraph;
import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.AtlasDefStore;
import org.apache.atlas.repository.store.graph.AtlasTypeDefGraphStore;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeRegistry;
import org.apache.atlas.typesystem.types.DataTypes.TypeCategory;
......@@ -50,6 +43,16 @@ import org.springframework.stereotype.Component;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import static org.apache.atlas.repository.Constants.TYPE_CATEGORY_PROPERTY_KEY;
import static org.apache.atlas.repository.Constants.VERTEX_TYPE_PROPERTY_KEY;
import static org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2.VERTEX_TYPE;
/**
......@@ -97,6 +100,10 @@ public class AtlasTypeDefGraphStoreV2 extends AtlasTypeDefGraphStore {
return new AtlasRelationshipDefStoreV2(this, typeRegistry);
}
@Override
protected AtlasDefStore<AtlasNamespaceDef> getNamespaceDefStore(AtlasTypeRegistry typeRegistry) {
return new AtlasNamespaceDefStoreV2(this, typeRegistry);
}
@Override
@GraphTransaction
......@@ -490,6 +497,9 @@ public class AtlasTypeDefGraphStoreV2 extends AtlasTypeDefGraphStore {
case RELATIONSHIP:
return TypeCategory.RELATIONSHIP;
case NAMESPACE:
return TypeCategory.NAMESPACE;
}
return null;
......
......@@ -19,7 +19,6 @@
package org.apache.atlas.examples;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.ApplicationProperties;
import org.apache.atlas.AtlasClientV2;
......@@ -40,10 +39,12 @@ import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection;
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasNamespaceDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags;
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import org.apache.atlas.model.typedef.AtlasTypesDef;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags;
import org.apache.atlas.type.AtlasType;
import org.apache.atlas.type.AtlasTypeUtil;
import org.apache.atlas.utils.AuthenticationUtil;
import org.apache.commons.collections.CollectionUtils;
......@@ -55,6 +56,7 @@ import java.util.*;
import static java.util.Arrays.asList;
import static org.apache.atlas.AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME;
import static org.apache.atlas.model.typedef.AtlasNamespaceDef.ATTR_OPTION_APPLICABLE_ENTITY_TYPES;
import static org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory.AGGREGATION;
import static org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory.COMPOSITION;
import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality.SET;
......@@ -316,7 +318,25 @@ public class QuickStartV2 {
List<AtlasRelationshipDef> relationshipDefs = asList(tableDatabaseTypeDef, viewDatabaseTypeDef, viewTablesTypeDef, tableColumnsTypeDef, tableStorageDescTypeDef, processProcessExecutionTypeDef);
List<AtlasClassificationDef> classificationDefs = asList(dimClassifDef, factClassifDef, piiClassifDef, metricClassifDef, etlClassifDef, jdbcClassifDef, logClassifDef);
return new AtlasTypesDef(Collections.emptyList(), Collections.emptyList(), classificationDefs, entityDefs, relationshipDefs);
// Namespace definitions
AtlasAttributeDef nsAttrDef1 = new AtlasAttributeDef("attr1", "int");
AtlasAttributeDef nsAttrDef2 = new AtlasAttributeDef("attr2", "int");
nsAttrDef1.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton(TABLE_TYPE)));
nsAttrDef1.setIsOptional(true);
nsAttrDef1.setIsUnique(false);
nsAttrDef2.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton(TABLE_TYPE)));
nsAttrDef2.setIsOptional(true);
nsAttrDef2.setIsUnique(false);
AtlasNamespaceDef testNamespaceDef = new AtlasNamespaceDef("test_namespace", "test_description", VERSION_1);
testNamespaceDef.setAttributeDefs(Arrays.asList(nsAttrDef1, nsAttrDef2));
List<AtlasNamespaceDef> namespaceDefs = asList(testNamespaceDef);
return new AtlasTypesDef(Collections.emptyList(), Collections.emptyList(), classificationDefs, entityDefs, relationshipDefs, namespaceDefs);
}
void createEntities() throws Exception {
......
......@@ -23,6 +23,7 @@ import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
import org.apache.atlas.model.typedef.AtlasClassificationDef;
import org.apache.atlas.model.typedef.AtlasEntityDef;
import org.apache.atlas.model.typedef.AtlasEnumDef;
import org.apache.atlas.model.typedef.AtlasNamespaceDef;
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
import org.apache.atlas.model.typedef.AtlasStructDef;
import org.apache.atlas.model.typedef.AtlasTypeDefHeader;
......@@ -317,6 +318,43 @@ public class TypesREST {
return ret;
}
/**
* Get the namespace definition for the given guid
* @param guid namespace guid
* @return namespace definition
* @throws AtlasBaseException
* @HTTP 200 On successful lookup of the the namespace definition by it's guid
* @HTTP 404 On Failed lookup for the given guid
*/
@GET
@Path("/namespacedef/guid/{guid}")
public AtlasNamespaceDef getNamespaceDefByGuid(@PathParam("guid") String guid) throws AtlasBaseException {
Servlets.validateQueryParamLength("guid", guid);
AtlasNamespaceDef ret = typeDefStore.getNamespaceDefByGuid(guid);
return ret;
}
/**
* Get the namespace definition by it's name (unique)
* @param name namespace name
* @return namespace definition
* @throws AtlasBaseException
* @HTTP 200 On successful lookup of the the namespace definition by it's name
* @HTTP 404 On Failed lookup for the given name
*/
@GET
@Path("/namespacedef/name/{name}")
public AtlasNamespaceDef getNamespaceDefByName(@PathParam("name") String name) throws AtlasBaseException {
Servlets.validateQueryParamLength("name", name);
AtlasNamespaceDef ret = typeDefStore.getNamespaceDefByName(name);
return ret;
}
/* Bulk API operation */
/**
......
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