ATLAS-3653: rename Namespace to BusinessMetadata
This commit is contained in:
parent
e50372820f
commit
0e947170b6
|
|
@ -29,7 +29,7 @@ public class AtlasEntityAccessRequest extends AtlasAccessRequest {
|
|||
private final String entityId;
|
||||
private final AtlasClassification classification;
|
||||
private final String label;
|
||||
private final String namespaceName;
|
||||
private final String businessMetadata;
|
||||
private final String attributeName;
|
||||
private final AtlasTypeRegistry typeRegistry;
|
||||
private final Set<String> entityClassifications;
|
||||
|
|
@ -67,14 +67,14 @@ public class AtlasEntityAccessRequest extends AtlasAccessRequest {
|
|||
this(typeRegistry, action, entity, classification, attributeName, null, null, userName, userGroups);
|
||||
}
|
||||
|
||||
public AtlasEntityAccessRequest(AtlasTypeRegistry typeRegistry, AtlasPrivilege action, AtlasEntityHeader entity, AtlasClassification classification, String attributeName, String label, String namespaceName, String userName, Set<String> userGroups) {
|
||||
public AtlasEntityAccessRequest(AtlasTypeRegistry typeRegistry, AtlasPrivilege action, AtlasEntityHeader entity, AtlasClassification classification, String attributeName, String label, String businessMetadata, String userName, Set<String> userGroups) {
|
||||
super(action, userName, userGroups);
|
||||
|
||||
this.entity = entity;
|
||||
this.entityId = super.getEntityId(entity, typeRegistry);
|
||||
this.classification = classification;
|
||||
this.label = label;
|
||||
this.namespaceName = namespaceName;
|
||||
this.businessMetadata = businessMetadata;
|
||||
this.attributeName = attributeName;
|
||||
this.typeRegistry = typeRegistry;
|
||||
this.entityClassifications = super.getClassificationNames(entity);
|
||||
|
|
@ -96,8 +96,8 @@ public class AtlasEntityAccessRequest extends AtlasAccessRequest {
|
|||
return label;
|
||||
}
|
||||
|
||||
public String getNamespaceName() {
|
||||
return namespaceName;
|
||||
public String getBusinessMetadata() {
|
||||
return businessMetadata;
|
||||
}
|
||||
|
||||
public String getAttributeName() {
|
||||
|
|
@ -122,7 +122,7 @@ public class AtlasEntityAccessRequest extends AtlasAccessRequest {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AtlasEntityAccessRequest[entity=" + entity + ", classification=" + classification + ", label=" + label + ", namespaceName=" + namespaceName + ", attributeName=" + attributeName +
|
||||
return "AtlasEntityAccessRequest[entity=" + entity + ", classification=" + classification + ", label=" + label + ", businessMetadata=" + businessMetadata + ", attributeName=" + attributeName +
|
||||
", action=" + getAction() + ", accessTime=" + getAccessTime() + ", user=" + getUser() +
|
||||
", userGroups=" + getUserGroups() + ", clientIPAddress=" + getClientIPAddress() +
|
||||
", forwardedAddresses=" + getForwardedAddresses() + ", remoteIPAddress=" + getRemoteIPAddress() + "]";
|
||||
|
|
@ -136,7 +136,7 @@ public class AtlasEntityAccessRequest extends AtlasAccessRequest {
|
|||
private AtlasEntityHeader entity;
|
||||
private AtlasClassification classification;
|
||||
private String label;
|
||||
private String namespaceName;
|
||||
private String businessMetadata;
|
||||
private String attributeName;
|
||||
|
||||
public AtlasEntityAccessRequestBuilder(AtlasTypeRegistry typeRegistry, AtlasPrivilege action) {
|
||||
|
|
@ -180,8 +180,8 @@ public class AtlasEntityAccessRequest extends AtlasAccessRequest {
|
|||
return this;
|
||||
}
|
||||
|
||||
public AtlasEntityAccessRequestBuilder setNamespaceName(String namespaceName) {
|
||||
this.namespaceName = namespaceName;
|
||||
public AtlasEntityAccessRequestBuilder setBusinessMetadata(String businessMetadata) {
|
||||
this.businessMetadata = businessMetadata;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
|
@ -193,7 +193,7 @@ public class AtlasEntityAccessRequest extends AtlasAccessRequest {
|
|||
}
|
||||
|
||||
public AtlasEntityAccessRequest build() {
|
||||
return new AtlasEntityAccessRequest(typeRegistry, action, entity, classification, attributeName, label, namespaceName, userName, userGroups);
|
||||
return new AtlasEntityAccessRequest(typeRegistry, action, entity, classification, attributeName, label, businessMetadata, userName, userGroups);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public enum AtlasPrivilege {
|
|||
|
||||
ENTITY_ADD_LABEL("entity-add-label"),
|
||||
ENTITY_REMOVE_LABEL("entity-remove-label"),
|
||||
ENTITY_UPDATE_NAMESPACE("entity-update-namespace");
|
||||
ENTITY_UPDATE_BUSINESS_METADATA("entity-update-business-metadata");
|
||||
|
||||
private final String type;
|
||||
|
||||
|
|
|
|||
|
|
@ -238,9 +238,9 @@ public final class AtlasSimpleAuthorizer implements AtlasAuthorizer {
|
|||
|
||||
if (permissions != null) {
|
||||
for (AtlasEntityPermission permission : permissions) {
|
||||
// match entity-type/entity-id/lable/namespace/attribute
|
||||
// match entity-type/entity-id/label/business-metadata/attribute
|
||||
if (isMatchAny(entityTypes, permission.getEntityTypes()) && isMatch(entityId, permission.getEntityIds()) && isMatch(attribute, permission.getAttributes())
|
||||
&& isLabelMatch(request, permission) && isNamespaceMatch(request, permission)) {
|
||||
&& isLabelMatch(request, permission) && isBusinessMetadataMatch(request, permission)) {
|
||||
// match permission/classification
|
||||
if (!hasEntityAccess) {
|
||||
if (isMatch(action, permission.getPrivileges()) && isMatch(classification, permission.getClassifications())) {
|
||||
|
|
@ -464,8 +464,8 @@ public final class AtlasSimpleAuthorizer implements AtlasAuthorizer {
|
|||
return (AtlasPrivilege.ENTITY_ADD_LABEL.equals(request.getAction()) || AtlasPrivilege.ENTITY_REMOVE_LABEL.equals(request.getAction())) ? isMatch(request.getLabel(), permission.getLabels()) : true;
|
||||
}
|
||||
|
||||
private boolean isNamespaceMatch(AtlasEntityAccessRequest request, AtlasEntityPermission permission) {
|
||||
return AtlasPrivilege.ENTITY_UPDATE_NAMESPACE.equals(request.getAction()) ? isMatch(request.getNamespaceName(), permission.getNamespaces()) : true;
|
||||
private boolean isBusinessMetadataMatch(AtlasEntityAccessRequest request, AtlasEntityPermission permission) {
|
||||
return AtlasPrivilege.ENTITY_UPDATE_BUSINESS_METADATA.equals(request.getAction()) ? isMatch(request.getBusinessMetadata(), permission.getBusinessMetadata()) : true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -205,13 +205,13 @@ public class AtlasSimpleAuthzPolicy implements Serializable {
|
|||
public static class AtlasEntityPermission implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private List<String> privileges; // name of AtlasPrivilege enum, wildcards supported
|
||||
private List<String> entityTypes; // name of entity-type, wildcards supported
|
||||
private List<String> entityIds; // value of entity-unique attribute, wildcards supported
|
||||
private List<String> classifications; // name of classification-type, wildcards supported
|
||||
private List<String> labels; // labels, wildcards supported
|
||||
private List<String> namespaces; // name of namespace-type, wildcards supported
|
||||
private List<String> attributes; // name of entity-attribute, wildcards supported
|
||||
private List<String> privileges; // name of AtlasPrivilege enum, wildcards supported
|
||||
private List<String> entityTypes; // name of entity-type, wildcards supported
|
||||
private List<String> entityIds; // value of entity-unique attribute, wildcards supported
|
||||
private List<String> classifications; // name of classification-type, wildcards supported
|
||||
private List<String> labels; // labels, wildcards supported
|
||||
private List<String> businessMetadata; // name of business-metadata, wildcards supported
|
||||
private List<String> attributes; // name of entity-attribute, wildcards supported
|
||||
|
||||
public AtlasEntityPermission() {
|
||||
}
|
||||
|
|
@ -220,14 +220,14 @@ public class AtlasSimpleAuthzPolicy implements Serializable {
|
|||
this(privileges, entityTypes, entityIds, classifications, attributes, null, null);
|
||||
}
|
||||
|
||||
public AtlasEntityPermission(List<String> privileges, List<String> entityTypes, List<String> entityIds, List<String> classifications, List<String> labels, List<String> namespaces, List<String> attributes) {
|
||||
this.privileges = privileges;
|
||||
this.entityTypes = entityTypes;
|
||||
this.entityIds = entityIds;
|
||||
this.classifications = classifications;
|
||||
this.labels = labels;
|
||||
this.namespaces = namespaces;
|
||||
this.attributes = attributes;
|
||||
public AtlasEntityPermission(List<String> privileges, List<String> entityTypes, List<String> entityIds, List<String> classifications, List<String> labels, List<String> businessMetadata, List<String> attributes) {
|
||||
this.privileges = privileges;
|
||||
this.entityTypes = entityTypes;
|
||||
this.entityIds = entityIds;
|
||||
this.classifications = classifications;
|
||||
this.labels = labels;
|
||||
this.businessMetadata = businessMetadata;
|
||||
this.attributes = attributes;
|
||||
}
|
||||
|
||||
public List<String> getPrivileges() {
|
||||
|
|
@ -270,12 +270,12 @@ public class AtlasSimpleAuthzPolicy implements Serializable {
|
|||
this.labels = labels;
|
||||
}
|
||||
|
||||
public List<String> getNamespaces() {
|
||||
return namespaces;
|
||||
public List<String> getBusinessMetadata() {
|
||||
return businessMetadata;
|
||||
}
|
||||
|
||||
public void setNamespaces(List<String> namespaces) {
|
||||
this.namespaces = namespaces;
|
||||
public void setBusinessMetadata(List<String> businessMetadata) {
|
||||
this.businessMetadata = businessMetadata;
|
||||
}
|
||||
|
||||
public List<String> getAttributes() {
|
||||
|
|
|
|||
|
|
@ -150,21 +150,21 @@ public class AtlasSimpleAuthorizerTest {
|
|||
}
|
||||
|
||||
@Test(enabled = true)
|
||||
public void testNamespaces() {
|
||||
public void testBusinessMetadata() {
|
||||
try {
|
||||
AtlasEntityAccessRequest request = new AtlasEntityAccessRequest(null, AtlasPrivilege.ENTITY_UPDATE_NAMESPACE);
|
||||
AtlasEntityAccessRequest request = new AtlasEntityAccessRequest(null, AtlasPrivilege.ENTITY_UPDATE_BUSINESS_METADATA);
|
||||
|
||||
request.setUser(USER_DATA_SCIENTIST, Collections.emptySet());
|
||||
|
||||
boolean isAccessAllowed = authorizer.isAccessAllowed(request);
|
||||
|
||||
AssertJUnit.assertEquals("user " + USER_DATA_SCIENTIST + " shouldn't be allowed to update namespace", false, isAccessAllowed);
|
||||
AssertJUnit.assertEquals("user " + USER_DATA_SCIENTIST + " shouldn't be allowed to update business-metadata", false, isAccessAllowed);
|
||||
|
||||
request.setUser(USER_DATA_STEWARD, Collections.emptySet());
|
||||
|
||||
isAccessAllowed = authorizer.isAccessAllowed(request);
|
||||
|
||||
AssertJUnit.assertEquals("user " + USER_DATA_STEWARD + " should be allowed to update namespace", true, isAccessAllowed);
|
||||
AssertJUnit.assertEquals("user " + USER_DATA_STEWARD + " should be allowed to update business-metadata", true, isAccessAllowed);
|
||||
} catch (AtlasAuthorizationException e) {
|
||||
LOG.error("Exception in AtlasSimpleAuthorizerTest", e);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,14 +25,14 @@
|
|||
],
|
||||
"relationshipPermissions": [
|
||||
{
|
||||
"privileges": [ ".*" ],
|
||||
"relationshipTypes": [ ".*" ],
|
||||
"endOneEntityType": [ ".*" ],
|
||||
"endOneEntityId": [ ".*" ],
|
||||
"endOneEntityClassification": [ ".*" ],
|
||||
"endTwoEntityType": [ ".*" ],
|
||||
"endTwoEntityId": [ ".*" ],
|
||||
"endTwoEntityClassification": [ ".*" ]
|
||||
"privileges": [ ".*" ],
|
||||
"relationshipTypes": [ ".*" ],
|
||||
"endOneEntityType": [ ".*" ],
|
||||
"endOneEntityId": [ ".*" ],
|
||||
"endOneEntityClassification": [ ".*" ],
|
||||
"endTwoEntityType": [ ".*" ],
|
||||
"endTwoEntityId": [ ".*" ],
|
||||
"endTwoEntityClassification": [ ".*" ]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -40,12 +40,12 @@
|
|||
"DATA_SCIENTIST": {
|
||||
"entityPermissions": [
|
||||
{
|
||||
"privileges": [ "entity-read", "entity-read-classification" ],
|
||||
"entityTypes": [ ".*" ],
|
||||
"entityIds": [ ".*" ],
|
||||
"classifications": [ ".*" ],
|
||||
"labels": [ ".*" ],
|
||||
"namespaces": [ ".*" ]
|
||||
"privileges": [ "entity-read", "entity-read-classification" ],
|
||||
"entityTypes": [ ".*" ],
|
||||
"entityIds": [ ".*" ],
|
||||
"classifications": [ ".*" ],
|
||||
"labels": [ ".*" ],
|
||||
"businessMetadata": [ ".*" ]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
@ -53,22 +53,22 @@
|
|||
"DATA_STEWARD": {
|
||||
"entityPermissions": [
|
||||
{
|
||||
"privileges": [ "entity-read", "entity-create", "entity-update", "entity-read-classification", "entity-add-classification", "entity-update-classification", "entity-remove-classification", "entity-add-label", "entity-remove-label", "entity-update-namespace" ],
|
||||
"entityTypes": [ ".*" ],
|
||||
"entityIds": [ ".*" ],
|
||||
"classifications": [ ".*" ],
|
||||
"labels": [ ".*" ],
|
||||
"namespaces": [ ".*" ]
|
||||
"privileges": [ "entity-read", "entity-create", "entity-update", "entity-read-classification", "entity-add-classification", "entity-update-classification", "entity-remove-classification", "entity-add-label", "entity-remove-label", "entity-update-business-metadata" ],
|
||||
"entityTypes": [ ".*" ],
|
||||
"entityIds": [ ".*" ],
|
||||
"classifications": [ ".*" ],
|
||||
"labels": [ ".*" ],
|
||||
"businessMetadata": [ ".*" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
"userRoles": {
|
||||
"admin": [ "ROLE_ADMIN" ],
|
||||
"rangertagsync": [ "DATA_SCIENTIST" ],
|
||||
"admin": [ "ROLE_ADMIN" ],
|
||||
"rangertagsync": [ "DATA_SCIENTIST" ],
|
||||
"dataScientist1": [ "DATA_SCIENTIST"],
|
||||
"dataSteward1": [ "DATA_STEWARD"]
|
||||
"dataSteward1": [ "DATA_STEWARD"]
|
||||
},
|
||||
|
||||
"groupRoles": {
|
||||
|
|
|
|||
|
|
@ -161,12 +161,12 @@ public enum AtlasErrorCode {
|
|||
INVALID_LABEL_LENGTH(400, "ATLAS-400-00-08F", "Invalid label: {0}, label size should not be greater than {1}"),
|
||||
INVALID_LABEL_CHARACTERS(400, "ATLAS-400-00-090", "Invalid label: {0}, label should contain alphanumeric characters, '_' or '-'"),
|
||||
INVALID_PROPAGATION_TYPE(400, "ATLAS-400-00-091", "Invalid propagation {0} for relationship-type={1}. Default value is {2}"),
|
||||
DUPLICATE_NAMESPACE_ATTRIBUTE(400, "ATLAS-400-00-092", "Duplicate Namespace Attributes: {0} not allowed within the same namespace: {1}"),
|
||||
APPLICABLE_ENTITY_TYPES_DELETION_NOT_SUPPORTED(400, "ATLAS-400-00-093", "Cannot remove applicableEntityTypes in Attribute Def: {0}, defined in namespace: {1}"),
|
||||
NAMESPACE_DEF_ATTRIBUTE_TYPE_INVALID(400, "ATLAS-400-00-094", "{0}.{1}: invalid attribute type. Namespace attribute cannot be of type entity/classification/struct/namespace"),
|
||||
INVALID_NAMESPACE_NAME_FOR_ENTITY_TYPE(400, "ATLAS-400-00-095", "Invalid Namespace: {0} specified for entity, applicable namespaces: {1}"),
|
||||
NAMESPACE_ATTRIBUTE_DOES_NOT_EXIST(400, "ATLAS-400-00-096", "Namespace attribute does not exist in entity: {0}"),
|
||||
NAMESPACE_ATTRIBUTE_ALREADY_EXISTS(400, "ATLAS-400-00-097", "Namespace attribute already exists in entity: {0}"),
|
||||
DUPLICATE_BUSINESS_METADATA_ATTRIBUTE(400, "ATLAS-400-00-092", "Duplicate business-metadata attributes: {0} not allowed within the same business-metadata: {1}"),
|
||||
APPLICABLE_ENTITY_TYPES_DELETION_NOT_SUPPORTED(400, "ATLAS-400-00-093", "Cannot remove applicableEntityTypes in Attribute Def: {0}, defined in business-metadata: {1}"),
|
||||
BUSINESS_METADATA_DEF_ATTRIBUTE_TYPE_INVALID(400, "ATLAS-400-00-094", "{0}.{1}: invalid attribute type. Business-metadata attribute cannot be of type entity/classification/struct/business-metadata"),
|
||||
INVALID_BUSINESS_METADATA_NAME_FOR_ENTITY_TYPE(400, "ATLAS-400-00-095", "Invalid business-metadata: {0} specified for entity, applicable business-metadata: {1}"),
|
||||
BUSINESS_METADATA_ATTRIBUTE_DOES_NOT_EXIST(400, "ATLAS-400-00-096", "Business-metadata attribute does not exist in entity: {0}"),
|
||||
BUSINESS_METADATA_ATTRIBUTE_ALREADY_EXISTS(400, "ATLAS-400-00-097", "Business-metadata attribute already exists in entity: {0}"),
|
||||
|
||||
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, NAMESPACE
|
||||
PRIMITIVE, OBJECT_ID_TYPE, ENUM, STRUCT, CLASSIFICATION, ENTITY, ARRAY, MAP, RELATIONSHIP, BUSINESS_METADATA
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
|
|||
private List<AtlasClassification> classifications;
|
||||
private List<AtlasTermAssignmentHeader> meanings;
|
||||
private Map<String, String> customAttributes;
|
||||
private Map<String, Map<String, Object>> namespaceAttributes;
|
||||
private Map<String, Map<String, Object>> businessAttributes;
|
||||
private Set<String> labels;
|
||||
|
||||
@JsonIgnore
|
||||
|
|
@ -218,7 +218,7 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
|
|||
setRelationshipAttributes(other.getRelationshipAttributes());
|
||||
setMeanings(other.getMeanings());
|
||||
setCustomAttributes(other.getCustomAttributes());
|
||||
setNamespaceAttributes(other.getNamespaceAttributes());
|
||||
setBusinessAttributes(other.getBusinessAttributes());
|
||||
setLabels(other.getLabels());
|
||||
}
|
||||
}
|
||||
|
|
@ -350,39 +350,39 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
|
|||
this.customAttributes = customAttributes;
|
||||
}
|
||||
|
||||
public Map<String, Map<String, Object>> getNamespaceAttributes() {
|
||||
return namespaceAttributes;
|
||||
public Map<String, Map<String, Object>> getBusinessAttributes() {
|
||||
return businessAttributes;
|
||||
}
|
||||
|
||||
public void setNamespaceAttributes(Map<String, Map<String, Object>> namespaceAttributes) {
|
||||
this.namespaceAttributes = namespaceAttributes;
|
||||
public void setBusinessAttributes(Map<String, Map<String, Object>> businessAttributes) {
|
||||
this.businessAttributes = businessAttributes;
|
||||
}
|
||||
|
||||
public void setNamespaceAttribute(String nsName, String nsAttrName, Object nsValue) {
|
||||
Map<String, Map<String, Object>> namespaceAttributes = this.namespaceAttributes;
|
||||
public void setBusinessAttribute(String nsName, String nsAttrName, Object nsValue) {
|
||||
Map<String, Map<String, Object>> businessAttributes = this.businessAttributes;
|
||||
|
||||
if (namespaceAttributes == null) {
|
||||
namespaceAttributes = new HashMap<>();
|
||||
if (businessAttributes == null) {
|
||||
businessAttributes = new HashMap<>();
|
||||
|
||||
this.namespaceAttributes = namespaceAttributes;
|
||||
this.businessAttributes = businessAttributes;
|
||||
}
|
||||
|
||||
Map<String, Object> namespaceAttributeMap = namespaceAttributes.get(nsName);
|
||||
Map<String, Object> businessAttributeMap = businessAttributes.get(nsName);
|
||||
|
||||
if (namespaceAttributeMap == null) {
|
||||
namespaceAttributeMap = new HashMap<>();
|
||||
if (businessAttributeMap == null) {
|
||||
businessAttributeMap = new HashMap<>();
|
||||
|
||||
namespaceAttributes.put(nsName, namespaceAttributeMap);
|
||||
businessAttributes.put(nsName, businessAttributeMap);
|
||||
}
|
||||
|
||||
namespaceAttributeMap.put(nsAttrName, nsValue);
|
||||
businessAttributeMap.put(nsAttrName, nsValue);
|
||||
}
|
||||
|
||||
public Object getNamespaceAttribute(String nsName, String nsAttrName) {
|
||||
Map<String, Map<String, Object>> namespaceAttributes = this.namespaceAttributes;
|
||||
Map<String, Object> namespaceAttributeMap = namespaceAttributes == null ? null : namespaceAttributes.get(nsName);
|
||||
public Object getBusinessAttribute(String bmName, String bmAttrName) {
|
||||
Map<String, Map<String, Object>> businessAttributes = this.businessAttributes;
|
||||
Map<String, Object> businessAttributeMap = businessAttributes == null ? null : businessAttributes.get(bmName);
|
||||
|
||||
return namespaceAttributeMap == null ? null : namespaceAttributeMap.get(nsAttrName);
|
||||
return businessAttributeMap == null ? null : businessAttributeMap.get(bmAttrName);
|
||||
}
|
||||
|
||||
public Set<String> getLabels() {
|
||||
|
|
@ -441,7 +441,7 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
|
|||
setClassifications(null);
|
||||
setMeanings(null);
|
||||
setCustomAttributes(null);
|
||||
setNamespaceAttributes(null);
|
||||
setBusinessAttributes(null);
|
||||
setLabels(null);
|
||||
}
|
||||
|
||||
|
|
@ -480,8 +480,8 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
|
|||
sb.append(", customAttributes=[");
|
||||
dumpObjects(customAttributes, sb);
|
||||
sb.append("]");
|
||||
sb.append(", namespaceAttributes=[");
|
||||
dumpObjects(namespaceAttributes, sb);
|
||||
sb.append(", businessAttributes=[");
|
||||
dumpObjects(businessAttributes, sb);
|
||||
sb.append("]");
|
||||
sb.append(", labels=[");
|
||||
dumpObjects(labels, sb);
|
||||
|
|
@ -511,7 +511,7 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
|
|||
Objects.equals(version, that.version) &&
|
||||
Objects.equals(relationshipAttributes, that.relationshipAttributes) &&
|
||||
Objects.equals(customAttributes, that.customAttributes) &&
|
||||
Objects.equals(namespaceAttributes, that.namespaceAttributes) &&
|
||||
Objects.equals(businessAttributes, that.businessAttributes) &&
|
||||
Objects.equals(labels, that.labels) &&
|
||||
Objects.equals(classifications, that.classifications);
|
||||
}
|
||||
|
|
@ -519,7 +519,7 @@ public class AtlasEntity extends AtlasStruct implements Serializable {
|
|||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), guid, homeId, isProxy, isIncomplete, provenanceType, status, createdBy, updatedBy,
|
||||
createTime, updateTime, version, relationshipAttributes, classifications, customAttributes, namespaceAttributes, labels);
|
||||
createTime, updateTime, version, relationshipAttributes, classifications, customAttributes, businessAttributes, labels);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -37,34 +37,34 @@ import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_
|
|||
@JsonIgnoreProperties(ignoreUnknown=true)
|
||||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.PROPERTY)
|
||||
public class AtlasNamespaceDef extends AtlasStructDef implements Serializable {
|
||||
public class AtlasBusinessMetadataDef 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 static final String ATTR_MAX_STRING_LENGTH = "maxStrLength";
|
||||
public static final String ATTR_VALID_PATTERN = "validPattern";
|
||||
|
||||
public AtlasNamespaceDef() {
|
||||
public AtlasBusinessMetadataDef() {
|
||||
this(null, null, null, null);
|
||||
}
|
||||
|
||||
public AtlasNamespaceDef(String name, String description) {
|
||||
public AtlasBusinessMetadataDef(String name, String description) {
|
||||
this(name, description, null, null, null);
|
||||
}
|
||||
|
||||
public AtlasNamespaceDef(String name, String description, String typeVersion) {
|
||||
public AtlasBusinessMetadataDef(String name, String description, String typeVersion) {
|
||||
this(name, description, typeVersion, null, null);
|
||||
}
|
||||
|
||||
public AtlasNamespaceDef(String name, String description, String typeVersion, List<AtlasAttributeDef> attributeDefs) {
|
||||
public AtlasBusinessMetadataDef(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 AtlasBusinessMetadataDef(String name, String description, String typeVersion, List<AtlasAttributeDef> attributeDefs, Map<String, String> options) {
|
||||
super(TypeCategory.BUSINESS_METADATA, name, description, typeVersion, attributeDefs, options);
|
||||
}
|
||||
|
||||
public AtlasNamespaceDef(AtlasNamespaceDef other) {
|
||||
public AtlasBusinessMetadataDef(AtlasBusinessMetadataDef other) {
|
||||
super(other);
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ public class AtlasNamespaceDef extends AtlasStructDef implements Serializable {
|
|||
sb = new StringBuilder();
|
||||
}
|
||||
|
||||
sb.append("AtlasNamespaceDef{");
|
||||
sb.append("AtlasBusinessMetadataDef{");
|
||||
super.toString(sb);
|
||||
sb.append('}');
|
||||
|
||||
|
|
@ -66,8 +66,8 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
|
|||
private List<AtlasRelationshipAttributeDef> relationshipAttributeDefs;
|
||||
|
||||
// this is a read-only field, any value provided during create & update operation is ignored
|
||||
// the value of this field is derived from all the namespaceDefs this entityType is referenced in
|
||||
private Map<String, List<AtlasAttributeDef>> namespaceAttributeDefs;
|
||||
// the value of this field is derived from all the businessMetadataDefs this entityType is referenced in
|
||||
private Map<String, List<AtlasAttributeDef>> businessAttributeDefs;
|
||||
|
||||
|
||||
public AtlasEntityDef() {
|
||||
|
|
@ -132,7 +132,7 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
|
|||
setSuperTypes(other.getSuperTypes());
|
||||
setSubTypes(other.getSubTypes());
|
||||
setRelationshipAttributeDefs(other.getRelationshipAttributeDefs());
|
||||
setNamespaceAttributeDefs(other.getNamespaceAttributeDefs());
|
||||
setBusinessAttributeDefs(other.getBusinessAttributeDefs());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -170,12 +170,12 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
|
|||
this.relationshipAttributeDefs = relationshipAttributeDefs;
|
||||
}
|
||||
|
||||
public Map<String, List<AtlasAttributeDef>> getNamespaceAttributeDefs() {
|
||||
return namespaceAttributeDefs;
|
||||
public Map<String, List<AtlasAttributeDef>> getBusinessAttributeDefs() {
|
||||
return businessAttributeDefs;
|
||||
}
|
||||
|
||||
public void setNamespaceAttributeDefs(Map<String, List<AtlasAttributeDef>> namespaceAttributeDefs) {
|
||||
this.namespaceAttributeDefs = namespaceAttributeDefs;
|
||||
public void setBusinessAttributeDefs(Map<String, List<AtlasAttributeDef>> businessAttributeDefs) {
|
||||
this.businessAttributeDefs = businessAttributeDefs;
|
||||
}
|
||||
|
||||
public boolean hasSuperType(String typeName) {
|
||||
|
|
@ -235,11 +235,11 @@ public class AtlasEntityDef extends AtlasStructDef implements java.io.Serializab
|
|||
}
|
||||
}
|
||||
sb.append(']');
|
||||
sb.append(", namespaceAttributeDefs={");
|
||||
if (MapUtils.isNotEmpty(namespaceAttributeDefs)) {
|
||||
sb.append(", businessAttributeDefs={");
|
||||
if (MapUtils.isNotEmpty(businessAttributeDefs)) {
|
||||
int nsIdx = 0;
|
||||
|
||||
for (Map.Entry<String, List<AtlasAttributeDef>> entry : namespaceAttributeDefs.entrySet()) {
|
||||
for (Map.Entry<String, List<AtlasAttributeDef>> entry : businessAttributeDefs.entrySet()) {
|
||||
String nsName = entry.getKey();
|
||||
List<AtlasAttributeDef> nsAttrs = entry.getValue();
|
||||
|
||||
|
|
|
|||
|
|
@ -42,20 +42,20 @@ import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.PUBLIC_
|
|||
@XmlRootElement
|
||||
@XmlAccessorType(XmlAccessType.PROPERTY)
|
||||
public class AtlasTypesDef {
|
||||
private List<AtlasEnumDef> enumDefs;
|
||||
private List<AtlasStructDef> structDefs;
|
||||
private List<AtlasClassificationDef> classificationDefs;
|
||||
private List<AtlasEntityDef> entityDefs;
|
||||
private List<AtlasRelationshipDef> relationshipDefs;
|
||||
private List<AtlasNamespaceDef> namespaceDefs;
|
||||
private List<AtlasEnumDef> enumDefs;
|
||||
private List<AtlasStructDef> structDefs;
|
||||
private List<AtlasClassificationDef> classificationDefs;
|
||||
private List<AtlasEntityDef> entityDefs;
|
||||
private List<AtlasRelationshipDef> relationshipDefs;
|
||||
private List<AtlasBusinessMetadataDef> businessMetadataDefs;
|
||||
|
||||
public AtlasTypesDef() {
|
||||
enumDefs = new ArrayList<>();
|
||||
structDefs = new ArrayList<>();
|
||||
classificationDefs = new ArrayList<>();
|
||||
entityDefs = new ArrayList<>();
|
||||
relationshipDefs = new ArrayList<>();
|
||||
namespaceDefs = new ArrayList<>();
|
||||
enumDefs = new ArrayList<>();
|
||||
structDefs = new ArrayList<>();
|
||||
classificationDefs = new ArrayList<>();
|
||||
entityDefs = new ArrayList<>();
|
||||
relationshipDefs = new ArrayList<>();
|
||||
businessMetadataDefs = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -86,18 +86,18 @@ public class AtlasTypesDef {
|
|||
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 AtlasTypesDef(List<AtlasEnumDef> enumDefs,
|
||||
List<AtlasStructDef> structDefs,
|
||||
List<AtlasClassificationDef> classificationDefs,
|
||||
List<AtlasEntityDef> entityDefs,
|
||||
List<AtlasRelationshipDef> relationshipDefs,
|
||||
List<AtlasBusinessMetadataDef> businessMetadataDefs) {
|
||||
this.enumDefs = enumDefs;
|
||||
this.structDefs = structDefs;
|
||||
this.classificationDefs = classificationDefs;
|
||||
this.entityDefs = entityDefs;
|
||||
this.relationshipDefs = relationshipDefs;
|
||||
this.businessMetadataDefs = businessMetadataDefs;
|
||||
}
|
||||
|
||||
public List<AtlasEnumDef> getEnumDefs() {
|
||||
|
|
@ -138,12 +138,12 @@ public class AtlasTypesDef {
|
|||
this.relationshipDefs = relationshipDefs;
|
||||
}
|
||||
|
||||
public void setNamespaceDefs(List<AtlasNamespaceDef> namespaceDefs) {
|
||||
this.namespaceDefs = namespaceDefs;
|
||||
public void setBusinessMetadataDefs(List<AtlasBusinessMetadataDef> businessMetadataDefs) {
|
||||
this.businessMetadataDefs = businessMetadataDefs;
|
||||
}
|
||||
|
||||
public List<AtlasNamespaceDef> getNamespaceDefs() {
|
||||
return namespaceDefs;
|
||||
public List<AtlasBusinessMetadataDef> getBusinessMetadataDefs() {
|
||||
return businessMetadataDefs;
|
||||
}
|
||||
|
||||
public boolean hasClassificationDef(String name) {
|
||||
|
|
@ -165,8 +165,8 @@ public class AtlasTypesDef {
|
|||
return hasTypeDef(relationshipDefs, name);
|
||||
}
|
||||
|
||||
public boolean hasNamespaceDef(String name) {
|
||||
return hasTypeDef(namespaceDefs, name);
|
||||
public boolean hasBusinessMetadataDef(String name) {
|
||||
return hasTypeDef(businessMetadataDefs, name);
|
||||
}
|
||||
|
||||
private <T extends AtlasBaseTypeDef> boolean hasTypeDef(Collection<T> typeDefs, String name) {
|
||||
|
|
@ -188,7 +188,7 @@ public class AtlasTypesDef {
|
|||
CollectionUtils.isEmpty(classificationDefs) &&
|
||||
CollectionUtils.isEmpty(entityDefs) &&
|
||||
CollectionUtils.isEmpty(relationshipDefs) &&
|
||||
CollectionUtils.isEmpty(namespaceDefs);
|
||||
CollectionUtils.isEmpty(businessMetadataDefs);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
|
|
@ -211,8 +211,8 @@ public class AtlasTypesDef {
|
|||
relationshipDefs.clear();
|
||||
}
|
||||
|
||||
if (namespaceDefs != null) {
|
||||
namespaceDefs.clear();
|
||||
if (businessMetadataDefs != null) {
|
||||
businessMetadataDefs.clear();
|
||||
}
|
||||
}
|
||||
public StringBuilder toString(StringBuilder sb) {
|
||||
|
|
@ -235,8 +235,8 @@ public class AtlasTypesDef {
|
|||
sb.append("}");
|
||||
sb.append("relationshipDefs={");
|
||||
AtlasBaseTypeDef.dumpObjects(relationshipDefs, sb);
|
||||
sb.append("namespaceDefs={");
|
||||
AtlasBaseTypeDef.dumpObjects(namespaceDefs, sb);
|
||||
sb.append("businessMetadataDefs={");
|
||||
AtlasBaseTypeDef.dumpObjects(businessMetadataDefs, sb);
|
||||
sb.append("}");
|
||||
|
||||
return sb;
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ package org.apache.atlas.store;
|
|||
import org.apache.atlas.exception.AtlasBaseException;
|
||||
import org.apache.atlas.model.SearchFilter;
|
||||
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
|
||||
import org.apache.atlas.model.typedef.AtlasBusinessMetadataDef;
|
||||
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;
|
||||
|
|
@ -82,26 +82,26 @@ public interface AtlasTypeDefStore {
|
|||
|
||||
AtlasRelationshipDef getRelationshipDefByGuid(String guid) throws AtlasBaseException;
|
||||
|
||||
AtlasRelationshipDef updateRelationshipDefByName(String name, AtlasRelationshipDef structDef) throws AtlasBaseException;
|
||||
AtlasRelationshipDef updateRelationshipDefByName(String name, AtlasRelationshipDef relationshipDef) throws AtlasBaseException;
|
||||
|
||||
AtlasRelationshipDef updateRelationshipDefByGuid(String guid, AtlasRelationshipDef structDef) throws AtlasBaseException;
|
||||
AtlasRelationshipDef updateRelationshipDefByGuid(String guid, AtlasRelationshipDef relationshipDef) throws AtlasBaseException;
|
||||
|
||||
/* Namespace Def operations */
|
||||
AtlasNamespaceDef getNamespaceDefByName(String name) throws AtlasBaseException;
|
||||
/* business-metadata Def operations */
|
||||
AtlasBusinessMetadataDef getBusinessMetadataDefByName(String name) throws AtlasBaseException;
|
||||
|
||||
AtlasNamespaceDef getNamespaceDefByGuid(String guid) throws AtlasBaseException;
|
||||
AtlasBusinessMetadataDef getBusinessMetadataDefByGuid(String guid) throws AtlasBaseException;
|
||||
|
||||
/* Bulk Operations */
|
||||
|
||||
AtlasTypesDef createTypesDef(AtlasTypesDef atlasTypesDef) throws AtlasBaseException;
|
||||
AtlasTypesDef createTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException;
|
||||
|
||||
AtlasTypesDef updateTypesDef(AtlasTypesDef atlasTypesDef) throws AtlasBaseException;
|
||||
AtlasTypesDef updateTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException;
|
||||
|
||||
AtlasTypesDef createUpdateTypesDef(AtlasTypesDef typesToCreateUpdate) throws AtlasBaseException;
|
||||
|
||||
AtlasTypesDef createUpdateTypesDef(AtlasTypesDef typesToCreate, AtlasTypesDef typesToUpdate) throws AtlasBaseException;
|
||||
|
||||
void deleteTypesDef(AtlasTypesDef atlasTypesDef) throws AtlasBaseException;
|
||||
void deleteTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException;
|
||||
|
||||
AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException;
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ 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.AtlasBusinessMetadataDef;
|
||||
import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -28,45 +28,45 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.atlas.model.typedef.AtlasNamespaceDef.*;
|
||||
import static org.apache.atlas.model.typedef.AtlasBusinessMetadataDef.*;
|
||||
|
||||
|
||||
public class AtlasNamespaceType extends AtlasStructType {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AtlasNamespaceType.class);
|
||||
public class AtlasBusinessMetadataType extends AtlasStructType {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AtlasBusinessMetadataType.class);
|
||||
|
||||
private final AtlasNamespaceDef namespaceDef;
|
||||
private final AtlasBusinessMetadataDef businessMetadataDef;
|
||||
|
||||
|
||||
public AtlasNamespaceType(AtlasNamespaceDef namespaceDef) {
|
||||
super(namespaceDef);
|
||||
public AtlasBusinessMetadataType(AtlasBusinessMetadataDef businessMetadataDef) {
|
||||
super(businessMetadataDef);
|
||||
|
||||
this.namespaceDef = namespaceDef;
|
||||
this.businessMetadataDef = businessMetadataDef;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidValue(Object o) {
|
||||
return true; // there is no runtime instance for Namespaces, so return true
|
||||
return true; // there is no runtime instance for businessMetadataDef, so return true
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasStruct createDefaultValue() {
|
||||
return null; // there is no runtime instance for Namespaces, so return null
|
||||
return null; // there is no runtime instance for businessMetadataDef, so return null
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getNormalizedValue(Object a) {
|
||||
return null; // there is no runtime instance for Namespaces, so return null
|
||||
return null; // there is no runtime instance for businessMetadataDef, so return null
|
||||
}
|
||||
|
||||
public AtlasNamespaceDef getNamespaceDef() {
|
||||
return namespaceDef;
|
||||
public AtlasBusinessMetadataDef getBusinessMetadataDef() {
|
||||
return businessMetadataDef;
|
||||
}
|
||||
|
||||
@Override
|
||||
void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
|
||||
super.resolveReferences(typeRegistry);
|
||||
|
||||
Map<String, AtlasNamespaceAttribute> a = new HashMap<>();
|
||||
Map<String, AtlasBusinessAttribute> a = new HashMap<>();
|
||||
|
||||
for (AtlasAttribute attribute : super.allAttributes.values()) {
|
||||
AtlasAttributeDef attributeDef = attribute.getAttributeDef();
|
||||
|
|
@ -79,9 +79,9 @@ public class AtlasNamespaceType extends AtlasStructType {
|
|||
attrType = ((AtlasMapType) attrType).getValueType();
|
||||
}
|
||||
|
||||
// check if attribute type is not struct/classification/entity/namespace
|
||||
// check if attribute type is not struct/classification/entity/business-metadata
|
||||
if (attrType instanceof AtlasStructType) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.NAMESPACE_DEF_ATTRIBUTE_TYPE_INVALID, getTypeName(), attrName);
|
||||
throw new AtlasBaseException(AtlasErrorCode.BUSINESS_METADATA_DEF_ATTRIBUTE_TYPE_INVALID, getTypeName(), attrName);
|
||||
}
|
||||
|
||||
Set<String> entityTypeNames = attribute.getOptionSet(ATTR_OPTION_APPLICABLE_ENTITY_TYPES);
|
||||
|
|
@ -99,7 +99,7 @@ public class AtlasNamespaceType extends AtlasStructType {
|
|||
}
|
||||
}
|
||||
|
||||
AtlasNamespaceAttribute nsAttribute;
|
||||
AtlasBusinessAttribute bmAttribute;
|
||||
if (attribute.getAttributeType() instanceof AtlasBuiltInTypes.AtlasStringType) {
|
||||
Integer maxStringLength = attribute.getOptionInt(ATTR_MAX_STRING_LENGTH);
|
||||
if (maxStringLength == null) {
|
||||
|
|
@ -107,12 +107,12 @@ public class AtlasNamespaceType extends AtlasStructType {
|
|||
}
|
||||
|
||||
String validPattern = attribute.getOptionString(ATTR_VALID_PATTERN);
|
||||
nsAttribute = new AtlasNamespaceAttribute(attribute, entityTypes, maxStringLength, validPattern);
|
||||
bmAttribute = new AtlasBusinessAttribute(attribute, entityTypes, maxStringLength, validPattern);
|
||||
} else {
|
||||
nsAttribute = new AtlasNamespaceAttribute(attribute, entityTypes);
|
||||
bmAttribute = new AtlasBusinessAttribute(attribute, entityTypes);
|
||||
}
|
||||
|
||||
a.put(attrName, nsAttribute);
|
||||
a.put(attrName, bmAttribute);
|
||||
}
|
||||
|
||||
super.allAttributes = Collections.unmodifiableMap(a);
|
||||
|
|
@ -123,23 +123,23 @@ public class AtlasNamespaceType extends AtlasStructType {
|
|||
super.resolveReferencesPhase2(typeRegistry);
|
||||
|
||||
for (AtlasAttribute attribute : super.allAttributes.values()) {
|
||||
AtlasNamespaceAttribute nsAttribute = (AtlasNamespaceAttribute) attribute;
|
||||
Set<AtlasEntityType> entityTypes = nsAttribute.getApplicableEntityTypes();
|
||||
AtlasBusinessAttribute bmAttribute = (AtlasBusinessAttribute) attribute;
|
||||
Set<AtlasEntityType> entityTypes = bmAttribute.getApplicableEntityTypes();
|
||||
|
||||
if (CollectionUtils.isNotEmpty(entityTypes)) {
|
||||
for (AtlasEntityType entityType : entityTypes) {
|
||||
entityType.addNamespaceAttribute(nsAttribute);
|
||||
entityType.addBusinessAttribute(bmAttribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class AtlasNamespaceAttribute extends AtlasAttribute {
|
||||
public static class AtlasBusinessAttribute extends AtlasAttribute {
|
||||
private final Set<AtlasEntityType> applicableEntityTypes;
|
||||
private final int maxStringLength;
|
||||
private final String validPattern;
|
||||
|
||||
public AtlasNamespaceAttribute(AtlasAttribute attribute, Set<AtlasEntityType> applicableEntityTypes) {
|
||||
public AtlasBusinessAttribute(AtlasAttribute attribute, Set<AtlasEntityType> applicableEntityTypes) {
|
||||
super(attribute);
|
||||
|
||||
this.maxStringLength = 0;
|
||||
|
|
@ -147,7 +147,7 @@ public class AtlasNamespaceType extends AtlasStructType {
|
|||
this.applicableEntityTypes = applicableEntityTypes;
|
||||
}
|
||||
|
||||
public AtlasNamespaceAttribute(AtlasAttribute attribute, Set<AtlasEntityType> applicableEntityTypes, int maxStringLength, String validPattern) {
|
||||
public AtlasBusinessAttribute(AtlasAttribute attribute, Set<AtlasEntityType> applicableEntityTypes, int maxStringLength, String validPattern) {
|
||||
super(attribute);
|
||||
|
||||
this.maxStringLength = maxStringLength;
|
||||
|
|
@ -156,8 +156,8 @@ public class AtlasNamespaceType extends AtlasStructType {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AtlasNamespaceType getDefinedInType() {
|
||||
return (AtlasNamespaceType) super.getDefinedInType();
|
||||
public AtlasBusinessMetadataType getDefinedInType() {
|
||||
return (AtlasBusinessMetadataType) super.getDefinedInType();
|
||||
}
|
||||
|
||||
public Set<AtlasEntityType> getApplicableEntityTypes() {
|
||||
|
|
@ -31,7 +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.type.AtlasBusinessMetadataType.AtlasBusinessAttribute;
|
||||
import org.apache.atlas.utils.AtlasEntityUtil;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
|
|
@ -77,23 +77,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 Map<String, Map<String, AtlasNamespaceAttribute>> namespaceAttributes = Collections.emptyMap();
|
||||
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 Map<String, Map<String, AtlasBusinessAttribute>> businessAttributes = 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();
|
||||
|
||||
public AtlasEntityType(AtlasEntityDef entityDef) {
|
||||
super(entityDef);
|
||||
|
|
@ -145,8 +145,8 @@ public class AtlasEntityType extends AtlasStructType {
|
|||
this.allSubTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2()
|
||||
this.typeAndAllSubTypes = new HashSet<>(); // this will be populated in resolveReferencesPhase2()
|
||||
this.relationshipAttributes = new HashMap<>(); // this will be populated in resolveReferencesPhase3()
|
||||
this.businessAttributes = new HashMap<>(); // this will be populated in resolveReferences(), from AtlasBusinessMetadataType
|
||||
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());
|
||||
|
||||
|
|
@ -240,22 +240,22 @@ public class AtlasEntityType extends AtlasStructType {
|
|||
}
|
||||
}
|
||||
|
||||
Map<String, Map<String, AtlasNamespaceAttribute>> superTypeNamespaces = superType.getNamespaceAttributes();
|
||||
Map<String, Map<String, AtlasBusinessAttribute>> superTypeBusinessMetadata = superType.getBusinessAttributes();
|
||||
|
||||
if (MapUtils.isNotEmpty(superTypeNamespaces)) {
|
||||
for (Map.Entry<String, Map<String, AtlasNamespaceAttribute>> entry : superTypeNamespaces.entrySet()) {
|
||||
String nsName = entry.getKey();
|
||||
Map<String, AtlasNamespaceAttribute> superTypeNsAttrs = entry.getValue();
|
||||
Map<String, AtlasNamespaceAttribute> nsAttrs = namespaceAttributes.get(nsName);
|
||||
if (MapUtils.isNotEmpty(superTypeBusinessMetadata)) {
|
||||
for (Map.Entry<String, Map<String, AtlasBusinessAttribute>> entry : superTypeBusinessMetadata.entrySet()) {
|
||||
String bmName = entry.getKey();
|
||||
Map<String, AtlasBusinessAttribute> superTypeBmAttrs = entry.getValue();
|
||||
Map<String, AtlasBusinessAttribute> bmAttrs = businessAttributes.get(bmName);
|
||||
|
||||
if (nsAttrs == null) {
|
||||
nsAttrs = new HashMap<>();
|
||||
if (bmAttrs == null) {
|
||||
bmAttrs = new HashMap<>();
|
||||
|
||||
namespaceAttributes.put(nsName, nsAttrs);
|
||||
businessAttributes.put(bmName, bmAttrs);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, AtlasNamespaceAttribute> nsAttrEntry : superTypeNsAttrs.entrySet()) {
|
||||
nsAttrs.put(nsAttrEntry.getKey(), nsAttrEntry.getValue());
|
||||
for (Map.Entry<String, AtlasBusinessAttribute> bmAttrEntry : superTypeBmAttrs.entrySet()) {
|
||||
bmAttrs.put(bmAttrEntry.getKey(), bmAttrEntry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -284,9 +284,9 @@ public class AtlasEntityType extends AtlasStructType {
|
|||
typeAndAllSubTypes = Collections.unmodifiableSet(typeAndAllSubTypes);
|
||||
typeAndAllSubTypesQryStr = ""; // will be computed on next access
|
||||
relationshipAttributes = Collections.unmodifiableMap(relationshipAttributes);
|
||||
businessAttributes = Collections.unmodifiableMap(businessAttributes);
|
||||
ownedRefAttributes = Collections.unmodifiableList(ownedRefAttributes);
|
||||
tagPropagationEdges = Collections.unmodifiableSet(tagPropagationEdges);
|
||||
namespaceAttributes = Collections.unmodifiableMap(namespaceAttributes);
|
||||
|
||||
entityDef.setSubTypes(subTypes);
|
||||
|
||||
|
|
@ -305,21 +305,21 @@ public class AtlasEntityType extends AtlasStructType {
|
|||
|
||||
entityDef.setRelationshipAttributeDefs(Collections.unmodifiableList(relationshipAttrDefs));
|
||||
|
||||
Map<String, List<AtlasAttributeDef>> namespaceAttributeDefs = new HashMap<>();
|
||||
Map<String, List<AtlasAttributeDef>> bmAttributeDefs = new HashMap<>();
|
||||
|
||||
for (Map.Entry<String, Map<String, AtlasNamespaceAttribute>> entry : namespaceAttributes.entrySet()) {
|
||||
String nsName = entry.getKey();
|
||||
Map<String, AtlasNamespaceAttribute> nsAttrs = entry.getValue();
|
||||
List<AtlasAttributeDef> nsAttrDefs = new ArrayList<>();
|
||||
for (Map.Entry<String, Map<String, AtlasBusinessAttribute>> entry : businessAttributes.entrySet()) {
|
||||
String bmName = entry.getKey();
|
||||
Map<String, AtlasBusinessAttribute> bmAttrs = entry.getValue();
|
||||
List<AtlasAttributeDef> bmAttrDefs = new ArrayList<>();
|
||||
|
||||
for (AtlasNamespaceAttribute nsAttr : nsAttrs.values()) {
|
||||
nsAttrDefs.add(nsAttr.getAttributeDef());
|
||||
for (AtlasBusinessAttribute bmAttr : bmAttrs.values()) {
|
||||
bmAttrDefs.add(bmAttr.getAttributeDef());
|
||||
}
|
||||
|
||||
namespaceAttributeDefs.put(nsName, nsAttrDefs);
|
||||
bmAttributeDefs.put(bmName, bmAttrDefs);
|
||||
}
|
||||
|
||||
entityDef.setNamespaceAttributeDefs(namespaceAttributeDefs);
|
||||
entityDef.setBusinessAttributeDefs(bmAttributeDefs);
|
||||
|
||||
this.parsedTemplates = parseDynAttributeTemplates();
|
||||
|
||||
|
|
@ -336,17 +336,17 @@ public class AtlasEntityType extends AtlasStructType {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AtlasNamespaceAttribute getNamespaceAttribute(String nsAttrQualifiedName) {
|
||||
AtlasNamespaceAttribute ret = null;
|
||||
public AtlasBusinessAttribute getBusinesAAttribute(String bmAttrQualifiedName) {
|
||||
AtlasBusinessAttribute ret = null;
|
||||
|
||||
if (nsAttrQualifiedName != null) {
|
||||
int idxSep = nsAttrQualifiedName.indexOf(AtlasEntityType.NS_ATTRIBUTE_NAME_SEPARATOR);
|
||||
if (bmAttrQualifiedName != null) {
|
||||
int idxSep = bmAttrQualifiedName.indexOf(AtlasEntityType.NS_ATTRIBUTE_NAME_SEPARATOR);
|
||||
|
||||
if (idxSep != -1) {
|
||||
String nsName = nsAttrQualifiedName.substring(0, idxSep);
|
||||
String nsAttrName = nsAttrQualifiedName.substring(idxSep + 1);
|
||||
String bmName = bmAttrQualifiedName.substring(0, idxSep);
|
||||
String bmAttrName = bmAttrQualifiedName.substring(idxSep + 1);
|
||||
|
||||
ret = getNamespaceAttribute(nsName, nsAttrName);
|
||||
ret = getBusinessAttribute(bmName, bmAttrName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -430,21 +430,6 @@ public class AtlasEntityType extends AtlasStructType {
|
|||
public String[] getTagPropagationEdgesArray() {
|
||||
return CollectionUtils.isNotEmpty(tagPropagationEdges) ? tagPropagationEdges.toArray(new String[tagPropagationEdges.size()]) : null;
|
||||
}
|
||||
|
||||
public Map<String, Map<String, AtlasNamespaceAttribute>> getNamespaceAttributes() {
|
||||
return namespaceAttributes;
|
||||
}
|
||||
|
||||
public Map<String, AtlasNamespaceAttribute> getNamespaceAttributes(String nsName) {
|
||||
return namespaceAttributes.get(nsName);
|
||||
}
|
||||
|
||||
public AtlasNamespaceAttribute getNamespaceAttribute(String nsName, String nsAttrName) {
|
||||
Map<String, AtlasNamespaceAttribute> nsAttrs = namespaceAttributes.get(nsName);
|
||||
AtlasNamespaceAttribute ret = nsAttrs != null ? nsAttrs.get(nsAttrName) : null;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Map<String,List<TemplateToken>> getParsedTemplates() { return parsedTemplates; }
|
||||
|
||||
|
|
@ -516,6 +501,34 @@ public class AtlasEntityType extends AtlasStructType {
|
|||
return attributes != null ? attributes.keySet() : null;
|
||||
}
|
||||
|
||||
public Map<String, Map<String, AtlasBusinessAttribute>> getBusinessAttributes() {
|
||||
return businessAttributes;
|
||||
}
|
||||
|
||||
public Map<String, AtlasBusinessAttribute> getBusinessAttributes(String bmName) {
|
||||
return businessAttributes.get(bmName);
|
||||
}
|
||||
|
||||
public AtlasBusinessAttribute getBusinessAttribute(String bmName, String bmAttrName) {
|
||||
Map<String, AtlasBusinessAttribute> bmAttrs = businessAttributes.get(bmName);
|
||||
AtlasBusinessAttribute ret = bmAttrs != null ? bmAttrs.get(bmAttrName) : null;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void addBusinessAttribute(AtlasBusinessAttribute attribute) {
|
||||
String bmName = attribute.getDefinedInType().getTypeName();
|
||||
Map<String, AtlasBusinessAttribute> bmAttrs = businessAttributes.get(bmName);
|
||||
|
||||
if (bmAttrs == null) {
|
||||
bmAttrs = new HashMap<>();
|
||||
|
||||
businessAttributes.put(bmName, bmAttrs);
|
||||
}
|
||||
|
||||
bmAttrs.put(attribute.getName(), attribute);
|
||||
}
|
||||
|
||||
public String getTypeAndAllSubTypesQryStr() {
|
||||
if (StringUtils.isEmpty(typeAndAllSubTypesQryStr)) {
|
||||
typeAndAllSubTypesQryStr = AtlasAttribute.escapeIndexQueryValue(typeAndAllSubTypes);
|
||||
|
|
@ -536,19 +549,6 @@ public class AtlasEntityType extends AtlasStructType {
|
|||
return relationshipAttributes.containsKey(attributeName);
|
||||
}
|
||||
|
||||
public void addNamespaceAttribute(AtlasNamespaceAttribute attribute) {
|
||||
String nsName = attribute.getDefinedInType().getTypeName();
|
||||
Map<String, AtlasNamespaceAttribute> nsAttrs = namespaceAttributes.get(nsName);
|
||||
|
||||
if (nsAttrs == null) {
|
||||
nsAttrs = new HashMap<>();
|
||||
|
||||
namespaceAttributes.put(nsName, nsAttrs);
|
||||
}
|
||||
|
||||
nsAttrs.put(attribute.getName(), attribute);
|
||||
}
|
||||
|
||||
public String getQualifiedAttributeName(String attrName) throws AtlasBaseException {
|
||||
AtlasAttribute ret = getAttribute(attrName);
|
||||
|
||||
|
|
@ -1207,7 +1207,7 @@ public class AtlasEntityType extends AtlasStructType {
|
|||
}
|
||||
|
||||
/* this class provides abstractions that help basic-search and dsl-search to deal with
|
||||
* system-attributes and namespace-attributes
|
||||
* system-attributes and business-metadata-attributes
|
||||
*/
|
||||
private static class AtlasRootEntityType extends AtlasEntityType {
|
||||
private AtlasTypeRegistry typeRegistry = null;
|
||||
|
|
@ -1220,16 +1220,16 @@ public class AtlasEntityType extends AtlasStructType {
|
|||
void resolveReferences(AtlasTypeRegistry typeRegistry) throws AtlasBaseException {
|
||||
super.resolveReferences(typeRegistry);
|
||||
|
||||
// save typeRegistry for use in getNamespaceAttribute()
|
||||
// save typeRegistry for use in getBusinessAttribute()
|
||||
this.typeRegistry = typeRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasNamespaceAttribute getNamespaceAttribute(String nsName, String nsAttrName) {
|
||||
AtlasNamespaceType nsType = typeRegistry != null ? typeRegistry.getNamespaceTypeByName(nsName) : null;
|
||||
AtlasAttribute nsAttr = nsType != null ? nsType.getAttribute(nsAttrName) : null;
|
||||
public AtlasBusinessAttribute getBusinessAttribute(String bmName, String bmAttrName) {
|
||||
AtlasBusinessMetadataType bmType = typeRegistry != null ? typeRegistry.getBusinessMetadataTypeByName(bmName) : null;
|
||||
AtlasAttribute bmAttr = bmType != null ? bmType.getAttribute(bmAttrName) : null;
|
||||
|
||||
return (nsAttr instanceof AtlasNamespaceAttribute) ? (AtlasNamespaceAttribute) nsAttr : null;
|
||||
return (bmAttr instanceof AtlasBusinessAttribute) ? (AtlasBusinessAttribute) bmAttr : null;
|
||||
}
|
||||
|
||||
private static AtlasEntityDef getRootEntityDef() {
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ public class AtlasStructType extends AtlasType {
|
|||
throw new AtlasBaseException(AtlasErrorCode.ATTRIBUTE_TYPE_INVALID, getTypeName(), attributeDef.getName());
|
||||
}
|
||||
|
||||
if (attrType instanceof AtlasNamespaceType) {
|
||||
if (attrType instanceof AtlasBusinessMetadataType) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.ATTRIBUTE_TYPE_INVALID, getTypeName(), attributeDef.getName());
|
||||
}
|
||||
|
||||
|
|
@ -227,7 +227,7 @@ public class AtlasStructType extends AtlasType {
|
|||
}
|
||||
|
||||
if (ret == null) {
|
||||
ret = getNamespaceAttribute(attributeName);
|
||||
ret = getBusinesAAttribute(attributeName);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -237,7 +237,7 @@ public class AtlasStructType extends AtlasType {
|
|||
return null;
|
||||
}
|
||||
|
||||
public AtlasAttribute getNamespaceAttribute(String attributeName) {
|
||||
public AtlasAttribute getBusinesAAttribute(String attributeName) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ package org.apache.atlas.type;
|
|||
import org.apache.atlas.AtlasErrorCode;
|
||||
import org.apache.atlas.exception.AtlasBaseException;
|
||||
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
|
||||
import org.apache.atlas.model.typedef.AtlasBusinessMetadataDef;
|
||||
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;
|
||||
|
|
@ -193,15 +193,15 @@ public class AtlasTypeRegistry {
|
|||
return registryData.classificationDefs.getTypeByName(name);
|
||||
}
|
||||
|
||||
public Collection<AtlasNamespaceType> getAllNamespaceTypes() {
|
||||
return registryData.namespaceDefs.getAllTypes();
|
||||
public Collection<AtlasBusinessMetadataType> getAllBusinessMetadataTypes() {
|
||||
return registryData.businessMetadataDefs.getAllTypes();
|
||||
}
|
||||
|
||||
public Collection<AtlasNamespaceDef> getAllNamespaceDefs() {
|
||||
return registryData.namespaceDefs.getAll();
|
||||
public Collection<AtlasBusinessMetadataDef> getAllBusinessMetadataDefs() {
|
||||
return registryData.businessMetadataDefs.getAll();
|
||||
}
|
||||
|
||||
public AtlasNamespaceType getNamespaceTypeByName(String name) { return registryData.namespaceDefs.getTypeByName(name); }
|
||||
public AtlasBusinessMetadataType getBusinessMetadataTypeByName(String name) { return registryData.businessMetadataDefs.getTypeByName(name); }
|
||||
|
||||
public Collection<AtlasRelationshipDef> getAllRelationshipDefs() { return registryData.relationshipDefs.getAll(); }
|
||||
|
||||
|
|
@ -229,12 +229,12 @@ public class AtlasTypeRegistry {
|
|||
return registryData.relationshipDefs.getTypeDefByName(name);
|
||||
}
|
||||
|
||||
public AtlasNamespaceDef getNamespaceDefByGuid(String guid) {
|
||||
return registryData.namespaceDefs.getTypeDefByGuid(guid);
|
||||
public AtlasBusinessMetadataDef getBusinessMetadataDefByGuid(String guid) {
|
||||
return registryData.businessMetadataDefs.getTypeDefByGuid(guid);
|
||||
}
|
||||
|
||||
public AtlasNamespaceDef getNamespaceDefByName(String name) {
|
||||
return registryData.namespaceDefs.getTypeDefByName(name);
|
||||
public AtlasBusinessMetadataDef getBusinessMetadataDefByName(String name) {
|
||||
return registryData.businessMetadataDefs.getTypeDefByName(name);
|
||||
}
|
||||
|
||||
public AtlasRelationshipType getRelationshipTypeByName(String name) { return registryData.relationshipDefs.getTypeByName(name); }
|
||||
|
|
@ -285,25 +285,24 @@ public class AtlasTypeRegistry {
|
|||
}
|
||||
|
||||
static class RegistryData {
|
||||
final TypeCache allTypes;
|
||||
final TypeDefCache<AtlasEnumDef, AtlasEnumType> enumDefs;
|
||||
final TypeDefCache<AtlasStructDef, AtlasStructType> structDefs;
|
||||
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;
|
||||
final TypeCache allTypes;
|
||||
final TypeDefCache<AtlasEnumDef, AtlasEnumType> enumDefs;
|
||||
final TypeDefCache<AtlasStructDef, AtlasStructType> structDefs;
|
||||
final TypeDefCache<AtlasClassificationDef, AtlasClassificationType> classificationDefs;
|
||||
final TypeDefCache<AtlasEntityDef, AtlasEntityType> entityDefs;
|
||||
final TypeDefCache<AtlasRelationshipDef, AtlasRelationshipType> relationshipDefs;
|
||||
final TypeDefCache<AtlasBusinessMetadataDef, AtlasBusinessMetadataType> businessMetadataDefs;
|
||||
final TypeDefCache<? extends AtlasBaseTypeDef, ? extends AtlasType>[] allDefCaches;
|
||||
|
||||
RegistryData() {
|
||||
allTypes = new TypeCache();
|
||||
enumDefs = new TypeDefCache<>(allTypes);
|
||||
structDefs = new TypeDefCache<>(allTypes);
|
||||
classificationDefs = new TypeDefCache<>(allTypes);
|
||||
entityDefs = new TypeDefCache<>(allTypes);
|
||||
relationshipDefs = new TypeDefCache<>(allTypes);
|
||||
namespaceDefs = new TypeDefCache<>(allTypes);
|
||||
allDefCaches = new TypeDefCache[] { enumDefs, structDefs, classificationDefs, entityDefs,
|
||||
relationshipDefs, namespaceDefs };
|
||||
allTypes = new TypeCache();
|
||||
enumDefs = new TypeDefCache<>(allTypes);
|
||||
structDefs = new TypeDefCache<>(allTypes);
|
||||
classificationDefs = new TypeDefCache<>(allTypes);
|
||||
entityDefs = new TypeDefCache<>(allTypes);
|
||||
relationshipDefs = new TypeDefCache<>(allTypes);
|
||||
businessMetadataDefs = new TypeDefCache<>(allTypes);
|
||||
allDefCaches = new TypeDefCache[] { enumDefs, structDefs, classificationDefs, entityDefs, relationshipDefs, businessMetadataDefs};
|
||||
|
||||
init();
|
||||
}
|
||||
|
|
@ -362,7 +361,7 @@ public class AtlasTypeRegistry {
|
|||
classificationDefs.updateGuid(typeName, guid);
|
||||
entityDefs.updateGuid(typeName, guid);
|
||||
relationshipDefs.updateGuid(typeName, guid);
|
||||
namespaceDefs.updateGuid(typeName, guid);
|
||||
businessMetadataDefs.updateGuid(typeName, guid);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -373,7 +372,7 @@ public class AtlasTypeRegistry {
|
|||
classificationDefs.removeTypeDefByGuid(guid);
|
||||
entityDefs.removeTypeDefByGuid(guid);
|
||||
relationshipDefs.removeTypeDefByGuid(guid);
|
||||
namespaceDefs.removeTypeDefByGuid(guid);
|
||||
businessMetadataDefs.removeTypeDefByGuid(guid);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -384,7 +383,7 @@ public class AtlasTypeRegistry {
|
|||
classificationDefs.removeTypeDefByName(typeName);
|
||||
entityDefs.removeTypeDefByName(typeName);
|
||||
relationshipDefs.removeTypeDefByName(typeName);
|
||||
namespaceDefs.removeTypeDefByName(typeName);
|
||||
businessMetadataDefs.removeTypeDefByName(typeName);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -395,7 +394,7 @@ public class AtlasTypeRegistry {
|
|||
classificationDefs.clear();
|
||||
entityDefs.clear();
|
||||
relationshipDefs.clear();
|
||||
namespaceDefs.clear();
|
||||
businessMetadataDefs.clear();
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
|
@ -414,7 +413,7 @@ public class AtlasTypeRegistry {
|
|||
addTypesWithNoRefResolve(parent.getAllClassificationDefs());
|
||||
addTypesWithNoRefResolve(parent.getAllEntityDefs());
|
||||
addTypesWithNoRefResolve(parent.getAllRelationshipDefs());
|
||||
addTypesWithNoRefResolve(parent.getAllNamespaceDefs());
|
||||
addTypesWithNoRefResolve(parent.getAllBusinessMetadataDefs());
|
||||
|
||||
addedTypes.clear();
|
||||
updatedTypes.clear();
|
||||
|
|
@ -494,7 +493,7 @@ public class AtlasTypeRegistry {
|
|||
addTypesWithNoRefResolve(typesDef.getClassificationDefs());
|
||||
addTypesWithNoRefResolve(typesDef.getEntityDefs());
|
||||
addTypesWithNoRefResolve(typesDef.getRelationshipDefs());
|
||||
addTypesWithNoRefResolve(typesDef.getNamespaceDefs());
|
||||
addTypesWithNoRefResolve(typesDef.getBusinessMetadataDefs());
|
||||
}
|
||||
|
||||
resolveReferences();
|
||||
|
|
@ -595,7 +594,7 @@ public class AtlasTypeRegistry {
|
|||
updateTypesWithNoRefResolve(typesDef.getClassificationDefs());
|
||||
updateTypesWithNoRefResolve(typesDef.getEntityDefs());
|
||||
updateTypesWithNoRefResolve(typesDef.getRelationshipDefs());
|
||||
updateTypesWithNoRefResolve(typesDef.getNamespaceDefs());
|
||||
updateTypesWithNoRefResolve(typesDef.getBusinessMetadataDefs());
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
|
|
@ -610,7 +609,7 @@ public class AtlasTypeRegistry {
|
|||
removeTypesWithNoRefResolve(typesDef.getClassificationDefs());
|
||||
removeTypesWithNoRefResolve(typesDef.getEntityDefs());
|
||||
removeTypesWithNoRefResolve(typesDef.getRelationshipDefs());
|
||||
removeTypesWithNoRefResolve(typesDef.getNamespaceDefs());
|
||||
removeTypesWithNoRefResolve(typesDef.getBusinessMetadataDefs());
|
||||
}
|
||||
|
||||
resolveReferences();
|
||||
|
|
@ -645,8 +644,8 @@ public class AtlasTypeRegistry {
|
|||
case RELATIONSHIP:
|
||||
registryData.relationshipDefs.removeTypeDefByName(typeDef.getName());
|
||||
break;
|
||||
case NAMESPACE:
|
||||
registryData.namespaceDefs.removeTypeDefByName(typeDef.getName());
|
||||
case BUSINESS_METADATA:
|
||||
registryData.businessMetadataDefs.removeTypeDefByName(typeDef.getName());
|
||||
break;
|
||||
}
|
||||
deletedTypes.add(typeDef);
|
||||
|
|
@ -669,8 +668,8 @@ public class AtlasTypeRegistry {
|
|||
case RELATIONSHIP:
|
||||
registryData.relationshipDefs.removeTypeDefByGuid(typeDef.getGuid());
|
||||
break;
|
||||
case NAMESPACE:
|
||||
registryData.namespaceDefs.removeTypeDefByGuid(typeDef.getGuid());
|
||||
case BUSINESS_METADATA:
|
||||
registryData.businessMetadataDefs.removeTypeDefByGuid(typeDef.getGuid());
|
||||
break;
|
||||
}
|
||||
deletedTypes.add(typeDef);
|
||||
|
|
@ -758,9 +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));
|
||||
} else if (typeDef.getClass().equals(AtlasBusinessMetadataDef.class)) {
|
||||
AtlasBusinessMetadataDef businessMetadataDef = (AtlasBusinessMetadataDef) typeDef;
|
||||
registryData.businessMetadataDefs.addType(businessMetadataDef, new AtlasBusinessMetadataType(businessMetadataDef));
|
||||
}
|
||||
|
||||
addedTypes.add(typeDef);
|
||||
|
|
@ -840,11 +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;
|
||||
} else if (typeDef.getClass().equals(AtlasBusinessMetadataDef.class)) {
|
||||
AtlasBusinessMetadataDef businessMetadataDef = (AtlasBusinessMetadataDef) typeDef;
|
||||
|
||||
registryData.namespaceDefs.removeTypeDefByGuid(guid);
|
||||
registryData.namespaceDefs.addType(namespaceDef, new AtlasNamespaceType(namespaceDef));
|
||||
registryData.businessMetadataDefs.removeTypeDefByGuid(guid);
|
||||
registryData.businessMetadataDefs.addType(businessMetadataDef, new AtlasBusinessMetadataType(businessMetadataDef));
|
||||
}
|
||||
|
||||
updatedTypes.add(typeDef);
|
||||
|
|
@ -887,11 +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;
|
||||
} else if (typeDef.getClass().equals(AtlasBusinessMetadataDef.class)) {
|
||||
AtlasBusinessMetadataDef businessMetadataDef = (AtlasBusinessMetadataDef) typeDef;
|
||||
|
||||
registryData.namespaceDefs.removeTypeDefByName(name);
|
||||
registryData.namespaceDefs.addType(namespaceDef, new AtlasNamespaceType(namespaceDef));
|
||||
registryData.businessMetadataDefs.removeTypeDefByName(name);
|
||||
registryData.businessMetadataDefs.addType(businessMetadataDef, new AtlasBusinessMetadataType(businessMetadataDef));
|
||||
}
|
||||
|
||||
updatedTypes.add(typeDef);
|
||||
|
|
|
|||
|
|
@ -28,7 +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.AtlasBusinessMetadataDef;
|
||||
import org.apache.atlas.model.typedef.AtlasRelationshipDef;
|
||||
import org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags;
|
||||
import org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory;
|
||||
|
|
@ -321,8 +321,8 @@ public class AtlasTypeUtil {
|
|||
List<AtlasClassificationDef> traits,
|
||||
List<AtlasEntityDef> classes,
|
||||
List<AtlasRelationshipDef> relations,
|
||||
List<AtlasNamespaceDef> namespaces) {
|
||||
return new AtlasTypesDef(enums, structs, traits, classes, relations, namespaces);
|
||||
List<AtlasBusinessMetadataDef> businessMetadataDefs) {
|
||||
return new AtlasTypesDef(enums, structs, traits, classes, relations, businessMetadataDefs);
|
||||
}
|
||||
|
||||
public static List<AtlasTypeDefHeader> toTypeDefHeader(AtlasTypesDef typesDef) {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,6 @@ public class DataTypes {
|
|||
TRAIT,
|
||||
CLASS,
|
||||
RELATIONSHIP,
|
||||
NAMESPACE
|
||||
BUSINESS_METADATA
|
||||
}
|
||||
}
|
||||
|
|
@ -23,11 +23,11 @@ import org.apache.atlas.model.instance.AtlasEntity;
|
|||
import org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo;
|
||||
import org.apache.atlas.model.instance.AtlasObjectId;
|
||||
import org.apache.atlas.model.instance.AtlasStruct;
|
||||
import org.apache.atlas.model.typedef.AtlasBusinessMetadataDef;
|
||||
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;
|
||||
|
|
@ -40,7 +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.AtlasBusinessMetadataDef.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;
|
||||
|
|
@ -155,14 +155,14 @@ public final class TestRelationshipUtilsV2 {
|
|||
nsAttr2.setIsOptional(true);
|
||||
nsAttr2.setIsUnique(false);
|
||||
|
||||
AtlasNamespaceDef namespaceDef = new AtlasNamespaceDef("test_namespace", "test_description", DEFAULT_VERSION, Arrays.asList(nsAttr1, nsAttr2));
|
||||
AtlasBusinessMetadataDef businessMetadataDef = new AtlasBusinessMetadataDef("test_businessMetadata", "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),
|
||||
Collections.singletonList(namespaceDef));
|
||||
Collections.singletonList(businessMetadataDef));
|
||||
}
|
||||
|
||||
public static AtlasEntitiesWithExtInfo getDepartmentEmployeeInstances() {
|
||||
|
|
@ -295,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), Collections.<AtlasNamespaceDef>emptyList());
|
||||
Arrays.asList(relationshipType1, relationshipType2, relationshipType3, relationshipType4), Collections.<AtlasBusinessMetadataDef>emptyList());
|
||||
}
|
||||
|
||||
private static List<AtlasEnumElementDef> getOrgLevelElements() {
|
||||
|
|
|
|||
|
|
@ -23,54 +23,54 @@ 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.apache.atlas.model.typedef.AtlasBusinessMetadataDef.ATTR_OPTION_APPLICABLE_ENTITY_TYPES;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotEquals;
|
||||
|
||||
public class TestAtlasNamespaceDef {
|
||||
public class TestAtlasBusinessMetadataDef {
|
||||
|
||||
@Test
|
||||
public void namespaceDefSerDes() {
|
||||
AtlasNamespaceDef namespaceDef = new AtlasNamespaceDef("test_namespace", "test_description", null);
|
||||
String jsonString = AtlasType.toJson(namespaceDef);
|
||||
public void businessMetadataDefSerDes() {
|
||||
AtlasBusinessMetadataDef businessMetadataDef = new AtlasBusinessMetadataDef("test_businessMetadata", "test_description", null);
|
||||
String jsonString = AtlasType.toJson(businessMetadataDef);
|
||||
|
||||
AtlasNamespaceDef namespaceDef1 = AtlasType.fromJson(jsonString, AtlasNamespaceDef.class);
|
||||
assertEquals(namespaceDef, namespaceDef1,
|
||||
"Incorrect serialization/deserialization of AtlasNamespaceDef");
|
||||
AtlasBusinessMetadataDef businessMetadataDef1 = AtlasType.fromJson(jsonString, AtlasBusinessMetadataDef.class);
|
||||
assertEquals(businessMetadataDef, businessMetadataDef1,
|
||||
"Incorrect serialization/deserialization of AtlasBusinessMetadataDef");
|
||||
}
|
||||
|
||||
@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");
|
||||
public void businessMetadataDefEquality() {
|
||||
AtlasBusinessMetadataDef businessMetadataDef1 = new AtlasBusinessMetadataDef("test_businessMetadata", "test_description", null);
|
||||
AtlasBusinessMetadataDef businessMetadataDef2 = new AtlasBusinessMetadataDef("test_businessMetadata", "test_description", null);
|
||||
assertEquals(businessMetadataDef1, businessMetadataDef2, "businessMetadatas should be equal because the name of the" +
|
||||
"businessMetadata 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" +
|
||||
public void businessMetadataDefUnequality() {
|
||||
AtlasBusinessMetadataDef businessMetadataDef1 = new AtlasBusinessMetadataDef("test_businessMetadata", "test_description", null);
|
||||
AtlasBusinessMetadataDef businessMetadataDef2 = new AtlasBusinessMetadataDef("test_businessMetadata1", "test_description", null);
|
||||
assertNotEquals(businessMetadataDef1, businessMetadataDef2, "businessMetadatas should not be equal since they have a" +
|
||||
"different name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namespaceDefWithNamespaceAttributes() {
|
||||
AtlasNamespaceDef namespaceDef1 = new AtlasNamespaceDef("test_namespace", "test_description", null);
|
||||
public void businessMetadataDefWithAttributes() {
|
||||
AtlasBusinessMetadataDef businessMetadataDef1 = new AtlasBusinessMetadataDef("test_businessMetadata", "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);
|
||||
businessMetadataDef1.setAttributeDefs(Arrays.asList(nsAttr1, nsAttr2));
|
||||
assertEquals(businessMetadataDef1.getAttributeDefs().size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namespaceDefWithNamespaceAttributesHavingCardinality() {
|
||||
AtlasNamespaceDef namespaceDef1 = new AtlasNamespaceDef("test_namespace", "test_description", null);
|
||||
public void businessMetadataDefWithAttributesHavingCardinality() {
|
||||
AtlasBusinessMetadataDef businessMetadataDef1 = new AtlasBusinessMetadataDef("test_businessMetadata", "test_description", null);
|
||||
AtlasStructDef.AtlasAttributeDef nsAttr1 = new AtlasStructDef.AtlasAttributeDef("attr1", "int");
|
||||
AtlasStructDef.AtlasAttributeDef nsAttr2 = new AtlasStructDef.AtlasAttributeDef("attr2", "int");
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ public class TestAtlasNamespaceDef {
|
|||
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);
|
||||
businessMetadataDef1.setAttributeDefs(Arrays.asList(nsAttr1, nsAttr2));
|
||||
assertEquals(businessMetadataDef1.getAttributeDefs().size(), 2);
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ package org.apache.atlas.query;
|
|||
|
||||
import org.apache.atlas.AtlasErrorCode;
|
||||
import org.apache.atlas.exception.AtlasBaseException;
|
||||
import org.apache.atlas.type.AtlasNamespaceType;
|
||||
import org.apache.atlas.type.AtlasBusinessMetadataType;
|
||||
import org.apache.atlas.type.AtlasType;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
|
|
@ -186,12 +186,12 @@ public class IdentifierHelper {
|
|||
private void updateTypeInfo(org.apache.atlas.query.Lookup lookup, GremlinQueryComposer.Context context) {
|
||||
parts = StringUtils.split(raw, ".");
|
||||
|
||||
// check if this is a namespace attribute
|
||||
// check if this is a business attribute
|
||||
if (parts.length == 2) {
|
||||
try {
|
||||
AtlasType type = lookup.getType(parts[0]);
|
||||
|
||||
if (type instanceof AtlasNamespaceType) {
|
||||
if (type instanceof AtlasBusinessMetadataType) {
|
||||
parts = new String[1];
|
||||
parts[0] = raw;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ 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,7 +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 Set<String> businessMetadataTypes = new HashSet<>();
|
||||
final AtlasExportResult result;
|
||||
private final ZipSink sink;
|
||||
|
||||
|
|
|
|||
|
|
@ -24,11 +24,11 @@ import org.apache.atlas.model.instance.AtlasClassification;
|
|||
import org.apache.atlas.model.instance.AtlasEntity;
|
||||
import org.apache.atlas.model.typedef.AtlasStructDef;
|
||||
import org.apache.atlas.type.AtlasArrayType;
|
||||
import org.apache.atlas.type.AtlasBusinessMetadataType;
|
||||
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;
|
||||
|
|
@ -106,8 +106,8 @@ class ExportTypeProcessor {
|
|||
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 AtlasBusinessMetadataType) {
|
||||
addBusinessMetadataType((AtlasBusinessMetadataType) type, context);
|
||||
} else if (type instanceof AtlasStructType) {
|
||||
addStructType((AtlasStructType)type, context);
|
||||
} else if (type instanceof AtlasEnumType) {
|
||||
|
|
@ -172,11 +172,11 @@ class ExportTypeProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
private void addNamespaceType(AtlasNamespaceType namespaceType, ExportService.ExportContext context) {
|
||||
if (!context.namespaceTypes.contains(namespaceType.getTypeName())) {
|
||||
context.namespaceTypes.add(namespaceType.getTypeName());
|
||||
private void addBusinessMetadataType(AtlasBusinessMetadataType businessMetadataType, ExportService.ExportContext context) {
|
||||
if (!context.businessMetadataTypes.contains(businessMetadataType.getTypeName())) {
|
||||
context.businessMetadataTypes.add(businessMetadataType.getTypeName());
|
||||
|
||||
addAttributeTypes(namespaceType, context);
|
||||
addAttributeTypes(businessMetadataType, context);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,11 +30,11 @@ import org.apache.atlas.ha.HAConfiguration;
|
|||
import org.apache.atlas.listener.ActiveStateChangeHandler;
|
||||
import org.apache.atlas.model.patches.AtlasPatch.PatchStatus;
|
||||
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
|
||||
import org.apache.atlas.model.typedef.AtlasBusinessMetadataDef;
|
||||
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;
|
||||
|
|
@ -252,10 +252,10 @@ public class AtlasTypeDefStoreInitializer implements ActiveStateChangeHandler {
|
|||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getNamespaceDefs())) {
|
||||
for (AtlasNamespaceDef namespaceDef : typesDef.getNamespaceDefs()) {
|
||||
if (!typeRegistry.isRegisteredType(namespaceDef.getName())) {
|
||||
typesToCreate.getNamespaceDefs().add(namespaceDef);
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getBusinessMetadataDefs())) {
|
||||
for (AtlasBusinessMetadataDef businessMetadataDef : typesDef.getBusinessMetadataDefs()) {
|
||||
if (!typeRegistry.isRegisteredType(businessMetadataDef.getName())) {
|
||||
typesToCreate.getBusinessMetadataDefs().add(businessMetadataDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -344,16 +344,16 @@ public class AtlasTypeDefStoreInitializer implements ActiveStateChangeHandler {
|
|||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getNamespaceDefs())) {
|
||||
for (AtlasNamespaceDef namespaceDef : typesDef.getNamespaceDefs()) {
|
||||
AtlasNamespaceDef oldNamespaceDef = typeRegistry.getNamespaceDefByName(namespaceDef.getName());
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getBusinessMetadataDefs())) {
|
||||
for (AtlasBusinessMetadataDef businessMetadataDef : typesDef.getBusinessMetadataDefs()) {
|
||||
AtlasBusinessMetadataDef oldDef = typeRegistry.getBusinessMetadataDefByName(businessMetadataDef.getName());
|
||||
|
||||
if (oldNamespaceDef == null) {
|
||||
if (oldDef == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (updateTypeAttributes(oldNamespaceDef, namespaceDef, checkTypeVersion)) {
|
||||
typesToUpdate.getNamespaceDefs().add(namespaceDef);
|
||||
if (updateTypeAttributes(oldDef, businessMetadataDef, checkTypeVersion)) {
|
||||
typesToUpdate.getBusinessMetadataDefs().add(businessMetadataDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -250,19 +250,19 @@ public interface AtlasEntityStore {
|
|||
/**
|
||||
*
|
||||
* @param guid
|
||||
* @param namespaceAttributes
|
||||
* @param businessAttrbutes
|
||||
* @param isOverwrite
|
||||
* @throws AtlasBaseException
|
||||
*/
|
||||
void addOrUpdateNamespaceAttributes(String guid, Map<String, Map<String, Object>> namespaceAttributes, boolean isOverwrite) throws AtlasBaseException;
|
||||
void addOrUpdateBusinessAttributes(String guid, Map<String, Map<String, Object>> businessAttrbutes, boolean isOverwrite) throws AtlasBaseException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param guid
|
||||
* @param namespaceAttributes
|
||||
* @param businessAttributes
|
||||
* @throws AtlasBaseException
|
||||
*/
|
||||
void removeNamespaceAttributes(String guid, Map<String, Map<String, Object>> namespaceAttributes) throws AtlasBaseException;
|
||||
void removeBusinessAttributes(String guid, Map<String, Map<String, Object>> businessAttributes) throws AtlasBaseException;
|
||||
|
||||
/**
|
||||
* Remove given labels, if labels is null/empty, no labels will be removed. If any labels in
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
|
||||
protected abstract AtlasDefStore<AtlasRelationshipDef> getRelationshipDefStore(AtlasTypeRegistry typeRegistry);
|
||||
|
||||
protected abstract AtlasDefStore<AtlasNamespaceDef> getNamespaceDefStore(AtlasTypeRegistry typeRegistry);
|
||||
protected abstract AtlasDefStore<AtlasBusinessMetadataDef> getBusinessMetadataDefStore(AtlasTypeRegistry typeRegistry);
|
||||
|
||||
public AtlasTypeRegistry getTypeRegistry() { return typeRegistry; }
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
getClassificationDefStore(ttr).getAll(),
|
||||
getEntityDefStore(ttr).getAll(),
|
||||
getRelationshipDefStore(ttr).getAll(),
|
||||
getNamespaceDefStore(ttr).getAll());
|
||||
getBusinessMetadataDefStore(ttr).getAll());
|
||||
|
||||
rectifyTypeErrorsIfAny(typesDef);
|
||||
|
||||
|
|
@ -197,8 +197,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AtlasNamespaceDef getNamespaceDefByName(String name) throws AtlasBaseException {
|
||||
AtlasNamespaceDef ret = typeRegistry.getNamespaceDefByName(name);
|
||||
public AtlasBusinessMetadataDef getBusinessMetadataDefByName(String name) throws AtlasBaseException {
|
||||
AtlasBusinessMetadataDef ret = typeRegistry.getBusinessMetadataDefByName(name);
|
||||
|
||||
if (ret == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
|
||||
|
|
@ -208,8 +208,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
}
|
||||
|
||||
@Override
|
||||
public AtlasNamespaceDef getNamespaceDefByGuid(String guid) throws AtlasBaseException {
|
||||
AtlasNamespaceDef ret = typeRegistry.getNamespaceDefByGuid(guid);
|
||||
public AtlasBusinessMetadataDef getBusinessMetadataDefByGuid(String guid) throws AtlasBaseException {
|
||||
AtlasBusinessMetadataDef ret = typeRegistry.getBusinessMetadataDefByGuid(guid);
|
||||
|
||||
if (ret == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
|
||||
|
|
@ -350,13 +350,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
@GraphTransaction
|
||||
public AtlasTypesDef createTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classifications={}, entities={}, relationships={}, namespaces={})",
|
||||
LOG.debug("==> AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classifications={}, entities={}, relationships={}, businessMetadataDefs={})",
|
||||
CollectionUtils.size(typesDef.getEnumDefs()),
|
||||
CollectionUtils.size(typesDef.getStructDefs()),
|
||||
CollectionUtils.size(typesDef.getClassificationDefs()),
|
||||
CollectionUtils.size(typesDef.getEntityDefs()),
|
||||
CollectionUtils.size(typesDef.getRelationshipDefs()),
|
||||
CollectionUtils.size(typesDef.getNamespaceDefs()));
|
||||
CollectionUtils.size(typesDef.getBusinessMetadataDefs()));
|
||||
}
|
||||
|
||||
AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
|
||||
|
|
@ -372,13 +372,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={}, namespaces={})",
|
||||
LOG.debug("<== AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={}, businessMetadataDefs={})",
|
||||
CollectionUtils.size(typesDef.getEnumDefs()),
|
||||
CollectionUtils.size(typesDef.getStructDefs()),
|
||||
CollectionUtils.size(typesDef.getClassificationDefs()),
|
||||
CollectionUtils.size(typesDef.getEntityDefs()),
|
||||
CollectionUtils.size(typesDef.getRelationshipDefs()),
|
||||
CollectionUtils.size(typesDef.getNamespaceDefs()));
|
||||
CollectionUtils.size(typesDef.getBusinessMetadataDefs()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -456,13 +456,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
@GraphTransaction
|
||||
public AtlasTypesDef updateTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasTypeDefGraphStore.updateTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships{}, namespaceDefs={})",
|
||||
LOG.debug("==> AtlasTypeDefGraphStore.updateTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships{}, businessMetadataDefs={})",
|
||||
CollectionUtils.size(typesDef.getEnumDefs()),
|
||||
CollectionUtils.size(typesDef.getStructDefs()),
|
||||
CollectionUtils.size(typesDef.getClassificationDefs()),
|
||||
CollectionUtils.size(typesDef.getEntityDefs()),
|
||||
CollectionUtils.size(typesDef.getRelationshipDefs()),
|
||||
CollectionUtils.size(typesDef.getNamespaceDefs()));
|
||||
CollectionUtils.size(typesDef.getBusinessMetadataDefs()));
|
||||
}
|
||||
|
||||
AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
|
||||
|
|
@ -487,13 +487,13 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasTypeDefGraphStore.updateTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={}, namespaceDefs={})",
|
||||
LOG.debug("<== AtlasTypeDefGraphStore.updateTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={}, businessMetadataDefs={})",
|
||||
CollectionUtils.size(typesDef.getEnumDefs()),
|
||||
CollectionUtils.size(typesDef.getStructDefs()),
|
||||
CollectionUtils.size(typesDef.getClassificationDefs()),
|
||||
CollectionUtils.size(typesDef.getEntityDefs()),
|
||||
CollectionUtils.size(typesDef.getRelationshipDefs()),
|
||||
CollectionUtils.size(typesDef.getNamespaceDefs()));
|
||||
CollectionUtils.size(typesDef.getBusinessMetadataDefs()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
@ -504,23 +504,23 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
@GraphTransaction
|
||||
public void deleteTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasTypeDefGraphStore.deleteTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={}, namespaceDefs={})",
|
||||
LOG.debug("==> AtlasTypeDefGraphStore.deleteTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={}, businessMetadataDefs={})",
|
||||
CollectionUtils.size(typesDef.getEnumDefs()),
|
||||
CollectionUtils.size(typesDef.getStructDefs()),
|
||||
CollectionUtils.size(typesDef.getClassificationDefs()),
|
||||
CollectionUtils.size(typesDef.getEntityDefs()),
|
||||
CollectionUtils.size(typesDef.getRelationshipDefs()),
|
||||
CollectionUtils.size(typesDef.getNamespaceDefs()));
|
||||
CollectionUtils.size(typesDef.getBusinessMetadataDefs()));
|
||||
}
|
||||
|
||||
AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit();
|
||||
|
||||
AtlasDefStore<AtlasEnumDef> enumDefStore = getEnumDefStore(ttr);
|
||||
AtlasDefStore<AtlasStructDef> structDefStore = getStructDefStore(ttr);
|
||||
AtlasDefStore<AtlasClassificationDef> classifiDefStore = getClassificationDefStore(ttr);
|
||||
AtlasDefStore<AtlasEntityDef> entityDefStore = getEntityDefStore(ttr);
|
||||
AtlasDefStore<AtlasRelationshipDef> relationshipDefStore = getRelationshipDefStore(ttr);
|
||||
AtlasDefStore<AtlasNamespaceDef> namespaceDefStore = getNamespaceDefStore(ttr);
|
||||
AtlasDefStore<AtlasEnumDef> enumDefStore = getEnumDefStore(ttr);
|
||||
AtlasDefStore<AtlasStructDef> structDefStore = getStructDefStore(ttr);
|
||||
AtlasDefStore<AtlasClassificationDef> classifiDefStore = getClassificationDefStore(ttr);
|
||||
AtlasDefStore<AtlasEntityDef> entityDefStore = getEntityDefStore(ttr);
|
||||
AtlasDefStore<AtlasRelationshipDef> relationshipDefStore = getRelationshipDefStore(ttr);
|
||||
AtlasDefStore<AtlasBusinessMetadataDef> businessMetadataDefStore = getBusinessMetadataDefStore(ttr);
|
||||
|
||||
List<AtlasVertex> preDeleteStructDefs = new ArrayList<>();
|
||||
List<AtlasVertex> preDeleteClassifiDefs = new ArrayList<>();
|
||||
|
|
@ -630,12 +630,12 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getNamespaceDefs())) {
|
||||
for (AtlasNamespaceDef namespaceDef : typesDef.getNamespaceDefs()) {
|
||||
if (StringUtils.isNotBlank(namespaceDef.getGuid())) {
|
||||
namespaceDefStore.deleteByGuid(namespaceDef.getGuid(), null);
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getBusinessMetadataDefs())) {
|
||||
for (AtlasBusinessMetadataDef businessMetadataDef : typesDef.getBusinessMetadataDefs()) {
|
||||
if (StringUtils.isNotBlank(businessMetadataDef.getGuid())) {
|
||||
businessMetadataDefStore.deleteByGuid(businessMetadataDef.getGuid(), null);
|
||||
} else {
|
||||
namespaceDefStore.deleteByName(namespaceDef.getName(), null);
|
||||
businessMetadataDefStore.deleteByName(businessMetadataDef.getName(), null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -672,8 +672,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
typesDef.setEnumDefs(Collections.singletonList((AtlasEnumDef) baseTypeDef));
|
||||
} else if (baseTypeDef instanceof AtlasRelationshipDef) {
|
||||
typesDef.setRelationshipDefs(Collections.singletonList((AtlasRelationshipDef) baseTypeDef));
|
||||
} else if (baseTypeDef instanceof AtlasNamespaceDef) {
|
||||
typesDef.setNamespaceDefs(Collections.singletonList((AtlasNamespaceDef) baseTypeDef));
|
||||
} else if (baseTypeDef instanceof AtlasBusinessMetadataDef) {
|
||||
typesDef.setBusinessMetadataDefs(Collections.singletonList((AtlasBusinessMetadataDef) baseTypeDef));
|
||||
} else if (baseTypeDef instanceof AtlasStructDef) {
|
||||
typesDef.setStructDefs(Collections.singletonList((AtlasStructDef) baseTypeDef));
|
||||
}
|
||||
|
|
@ -716,9 +716,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
}
|
||||
}
|
||||
|
||||
for(AtlasNamespaceType namespaceType : typeRegistry.getAllNamespaceTypes()) {
|
||||
if (searchPredicates.evaluate(namespaceType)) {
|
||||
typesDef.getNamespaceDefs().add(namespaceType.getNamespaceDef());
|
||||
for(AtlasBusinessMetadataType businessMetadataType : typeRegistry.getAllBusinessMetadataTypes()) {
|
||||
if (searchPredicates.evaluate(businessMetadataType)) {
|
||||
typesDef.getBusinessMetadataDefs().add(businessMetadataType.getBusinessMetadataDef());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -761,8 +761,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
case RELATIONSHIP:
|
||||
ret = ((AtlasRelationshipType) type).getRelationshipDef();
|
||||
break;
|
||||
case NAMESPACE:
|
||||
ret = ((AtlasNamespaceType) type).getNamespaceDef();
|
||||
case BUSINESS_METADATA:
|
||||
ret = ((AtlasBusinessMetadataType) type).getBusinessMetadataDef();
|
||||
break;
|
||||
case PRIMITIVE:
|
||||
case OBJECT_ID_TYPE:
|
||||
|
|
@ -885,18 +885,18 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
private AtlasTypesDef addToGraphStore(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
|
||||
AtlasTypesDef ret = new AtlasTypesDef();
|
||||
|
||||
AtlasDefStore<AtlasEnumDef> enumDefStore = getEnumDefStore(ttr);
|
||||
AtlasDefStore<AtlasStructDef> structDefStore = getStructDefStore(ttr);
|
||||
AtlasDefStore<AtlasClassificationDef> classifiDefStore = getClassificationDefStore(ttr);
|
||||
AtlasDefStore<AtlasEntityDef> entityDefStore = getEntityDefStore(ttr);
|
||||
AtlasDefStore<AtlasRelationshipDef> relationshipDefStore = getRelationshipDefStore(ttr);
|
||||
AtlasDefStore<AtlasNamespaceDef> nameSpaceDefStore = getNamespaceDefStore(ttr);
|
||||
AtlasDefStore<AtlasEnumDef> enumDefStore = getEnumDefStore(ttr);
|
||||
AtlasDefStore<AtlasStructDef> structDefStore = getStructDefStore(ttr);
|
||||
AtlasDefStore<AtlasClassificationDef> classifiDefStore = getClassificationDefStore(ttr);
|
||||
AtlasDefStore<AtlasEntityDef> entityDefStore = getEntityDefStore(ttr);
|
||||
AtlasDefStore<AtlasRelationshipDef> relationshipDefStore = getRelationshipDefStore(ttr);
|
||||
AtlasDefStore<AtlasBusinessMetadataDef> businessMetadataDefStore = getBusinessMetadataDefStore(ttr);
|
||||
|
||||
List<AtlasVertex> preCreateStructDefs = new ArrayList<>();
|
||||
List<AtlasVertex> preCreateClassifiDefs = new ArrayList<>();
|
||||
List<AtlasVertex> preCreateEntityDefs = new ArrayList<>();
|
||||
List<AtlasVertex> preCreateRelationshipDefs = new ArrayList<>();
|
||||
List<AtlasVertex> preCreateNamespaceDefs = new ArrayList<>();
|
||||
List<AtlasVertex> preCreateStructDefs = new ArrayList<>();
|
||||
List<AtlasVertex> preCreateClassifiDefs = new ArrayList<>();
|
||||
List<AtlasVertex> preCreateEntityDefs = new ArrayList<>();
|
||||
List<AtlasVertex> preCreateRelationshipDefs = new ArrayList<>();
|
||||
List<AtlasVertex> preCreateBusinessMetadataDefs = new ArrayList<>();
|
||||
|
||||
// for enumerations run the create
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
|
||||
|
|
@ -934,9 +934,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getNamespaceDefs())) {
|
||||
for (AtlasNamespaceDef namespaceDef : typesDef.getNamespaceDefs()) {
|
||||
preCreateNamespaceDefs.add(nameSpaceDefStore.preCreate(namespaceDef));
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getBusinessMetadataDefs())) {
|
||||
for (AtlasBusinessMetadataDef businessMetadataDef : typesDef.getBusinessMetadataDefs()) {
|
||||
preCreateBusinessMetadataDefs.add(businessMetadataDefStore.preCreate(businessMetadataDef));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -987,14 +987,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getNamespaceDefs())) {
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getBusinessMetadataDefs())) {
|
||||
int i = 0;
|
||||
for (AtlasNamespaceDef namespaceDef : typesDef.getNamespaceDefs()) {
|
||||
AtlasNamespaceDef createdDef = nameSpaceDefStore.create(namespaceDef, preCreateNamespaceDefs.get(i));
|
||||
for (AtlasBusinessMetadataDef businessMetadataDef : typesDef.getBusinessMetadataDefs()) {
|
||||
AtlasBusinessMetadataDef createdDef = businessMetadataDefStore.create(businessMetadataDef, preCreateBusinessMetadataDefs.get(i));
|
||||
|
||||
ttr.updateGuid(createdDef.getName(), createdDef.getGuid());
|
||||
|
||||
ret.getNamespaceDefs().add(createdDef);
|
||||
ret.getBusinessMetadataDefs().add(createdDef);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
|
@ -1005,12 +1005,12 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
private AtlasTypesDef updateGraphStore(AtlasTypesDef typesDef, AtlasTransientTypeRegistry ttr) throws AtlasBaseException {
|
||||
AtlasTypesDef ret = new AtlasTypesDef();
|
||||
|
||||
AtlasDefStore<AtlasEnumDef> enumDefStore = getEnumDefStore(ttr);
|
||||
AtlasDefStore<AtlasStructDef> structDefStore = getStructDefStore(ttr);
|
||||
AtlasDefStore<AtlasClassificationDef> classifiDefStore = getClassificationDefStore(ttr);
|
||||
AtlasDefStore<AtlasEntityDef> entityDefStore = getEntityDefStore(ttr);
|
||||
AtlasDefStore<AtlasRelationshipDef> relationDefStore = getRelationshipDefStore(ttr);
|
||||
AtlasDefStore<AtlasNamespaceDef> nameSpaceDefStore = getNamespaceDefStore(ttr);
|
||||
AtlasDefStore<AtlasEnumDef> enumDefStore = getEnumDefStore(ttr);
|
||||
AtlasDefStore<AtlasStructDef> structDefStore = getStructDefStore(ttr);
|
||||
AtlasDefStore<AtlasClassificationDef> classifiDefStore = getClassificationDefStore(ttr);
|
||||
AtlasDefStore<AtlasEntityDef> entityDefStore = getEntityDefStore(ttr);
|
||||
AtlasDefStore<AtlasRelationshipDef> relationDefStore = getRelationshipDefStore(ttr);
|
||||
AtlasDefStore<AtlasBusinessMetadataDef> businessMetadataDefStore = getBusinessMetadataDefStore(ttr);
|
||||
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) {
|
||||
for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) {
|
||||
|
|
@ -1042,9 +1042,9 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore {
|
|||
}
|
||||
}
|
||||
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getNamespaceDefs())) {
|
||||
for (AtlasNamespaceDef namespaceDef : typesDef.getNamespaceDefs()) {
|
||||
ret.getNamespaceDefs().add(nameSpaceDefStore.update(namespaceDef));
|
||||
if (CollectionUtils.isNotEmpty(typesDef.getBusinessMetadataDefs())) {
|
||||
for (AtlasBusinessMetadataDef businessMetadataDef : typesDef.getBusinessMetadataDefs()) {
|
||||
ret.getBusinessMetadataDefs().add(businessMetadataDefStore.update(businessMetadataDef));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,347 @@
|
|||
/**
|
||||
* 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.repository.store.graph.v2;
|
||||
|
||||
import org.apache.atlas.AtlasErrorCode;
|
||||
import org.apache.atlas.authorize.AtlasAuthorizationUtils;
|
||||
import org.apache.atlas.authorize.AtlasPrivilege;
|
||||
import org.apache.atlas.authorize.AtlasTypeAccessRequest;
|
||||
import org.apache.atlas.exception.AtlasBaseException;
|
||||
import org.apache.atlas.model.TypeCategory;
|
||||
import org.apache.atlas.model.typedef.AtlasBusinessMetadataDef;
|
||||
import org.apache.atlas.model.typedef.AtlasStructDef;
|
||||
import org.apache.atlas.repository.Constants;
|
||||
import org.apache.atlas.repository.graphdb.AtlasVertex;
|
||||
import org.apache.atlas.type.AtlasBusinessMetadataType;
|
||||
import org.apache.atlas.type.AtlasType;
|
||||
import org.apache.atlas.type.AtlasTypeRegistry;
|
||||
import org.apache.atlas.typesystem.types.DataTypes;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.apache.atlas.model.typedef.AtlasBusinessMetadataDef.ATTR_OPTION_APPLICABLE_ENTITY_TYPES;
|
||||
|
||||
public class AtlasBusinessMetadataDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasBusinessMetadataDef> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AtlasBusinessMetadataDefStoreV2.class);
|
||||
|
||||
@Inject
|
||||
public AtlasBusinessMetadataDefStoreV2(AtlasTypeDefGraphStoreV2 typeDefStore, AtlasTypeRegistry typeRegistry) {
|
||||
super(typeDefStore, typeRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasVertex preCreate(AtlasBusinessMetadataDef businessMetadataDef) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasBusinessMetadataDefStoreV2.preCreate({})", businessMetadataDef);
|
||||
}
|
||||
|
||||
validateType(businessMetadataDef);
|
||||
|
||||
AtlasType type = typeRegistry.getType(businessMetadataDef.getName());
|
||||
|
||||
if (type.getTypeCategory() != TypeCategory.BUSINESS_METADATA) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, businessMetadataDef.getName(),
|
||||
DataTypes.TypeCategory.BUSINESS_METADATA.name());
|
||||
}
|
||||
|
||||
AtlasVertex ret = typeDefStore.findTypeVertexByName(businessMetadataDef.getName());
|
||||
|
||||
if (ret != null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, businessMetadataDef.getName());
|
||||
}
|
||||
|
||||
ret = typeDefStore.createTypeVertex(businessMetadataDef);
|
||||
|
||||
updateVertexPreCreate(businessMetadataDef, (AtlasBusinessMetadataType) type, ret);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasBusinessMetadataDefStoreV2.preCreate({}): {}", businessMetadataDef, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasBusinessMetadataDef create(AtlasBusinessMetadataDef businessMetadataDef, AtlasVertex preCreateResult) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasBusinessMetadataDefStoreV2.create({}, {})", businessMetadataDef, preCreateResult);
|
||||
}
|
||||
|
||||
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, businessMetadataDef), "create businessMetadata-def ", businessMetadataDef.getName());
|
||||
|
||||
AtlasVertex vertex = (preCreateResult == null) ? preCreate(businessMetadataDef) : preCreateResult;
|
||||
|
||||
AtlasBusinessMetadataDef ret = toBusinessMetadataDef(vertex);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasBusinessMetadataDefStoreV2.create({}, {}): {}", businessMetadataDef, preCreateResult, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AtlasBusinessMetadataDef> getAll() throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasBusinessMetadataDef.getAll()");
|
||||
}
|
||||
|
||||
List<AtlasBusinessMetadataDef> ret = new ArrayList<>();
|
||||
|
||||
Iterator<AtlasVertex> vertices = typeDefStore.findTypeVerticesByCategory(DataTypes.TypeCategory.BUSINESS_METADATA);
|
||||
while (vertices.hasNext()) {
|
||||
ret.add(toBusinessMetadataDef(vertices.next()));
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasBusinessMetadataDefStoreV2.getAll(): count={}", ret.size());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasBusinessMetadataDef getByName(String name) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasBusinessMetadataDefStoreV2.getByName({})", name);
|
||||
}
|
||||
|
||||
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, DataTypes.TypeCategory.BUSINESS_METADATA);
|
||||
|
||||
if (vertex == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
|
||||
}
|
||||
|
||||
vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, String.class);
|
||||
|
||||
AtlasBusinessMetadataDef ret = toBusinessMetadataDef(vertex);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasBusinessMetadataDefStoreV2.getByName({}): {}", name, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasBusinessMetadataDef getByGuid(String guid) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasBusinessMetadataDefStoreV2.getByGuid({})", guid);
|
||||
}
|
||||
|
||||
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, DataTypes.TypeCategory.BUSINESS_METADATA);
|
||||
|
||||
if (vertex == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
|
||||
}
|
||||
|
||||
AtlasBusinessMetadataDef ret = toBusinessMetadataDef(vertex);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasBusinessMetadataDefStoreV2.getByGuid({}): {}", guid, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasBusinessMetadataDef update(AtlasBusinessMetadataDef typeDef) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasBusinessMetadataDefStoreV2.update({})", typeDef);
|
||||
}
|
||||
|
||||
validateType(typeDef);
|
||||
|
||||
AtlasBusinessMetadataDef ret = StringUtils.isNotBlank(typeDef.getGuid()) ? updateByGuid(typeDef.getGuid(), typeDef)
|
||||
: updateByName(typeDef.getName(), typeDef);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasBusinessMetadataDefStoreV2.update({}): {}", typeDef, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasBusinessMetadataDef updateByName(String name, AtlasBusinessMetadataDef typeDef) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasBusinessMetadataDefStoreV2.updateByName({}, {})", name, typeDef);
|
||||
}
|
||||
|
||||
AtlasBusinessMetadataDef existingDef = typeRegistry.getBusinessMetadataDefByName(name);
|
||||
|
||||
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update businessMetadata-def ", name);
|
||||
|
||||
validateType(typeDef);
|
||||
|
||||
AtlasType type = typeRegistry.getType(typeDef.getName());
|
||||
|
||||
if (type.getTypeCategory() != TypeCategory.BUSINESS_METADATA) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, typeDef.getName(), DataTypes.TypeCategory.BUSINESS_METADATA.name());
|
||||
}
|
||||
|
||||
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, DataTypes.TypeCategory.BUSINESS_METADATA);
|
||||
|
||||
if (vertex == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
|
||||
}
|
||||
|
||||
|
||||
updateVertexPreUpdate(typeDef, (AtlasBusinessMetadataType)type, vertex);
|
||||
|
||||
AtlasBusinessMetadataDef ret = toBusinessMetadataDef(vertex);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasBusinessMetadataDefStoreV2.updateByName({}, {}): {}", name, typeDef, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public AtlasBusinessMetadataDef updateByGuid(String guid, AtlasBusinessMetadataDef typeDef) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasBusinessMetadataDefStoreV2.updateByGuid({})", guid);
|
||||
}
|
||||
|
||||
AtlasBusinessMetadataDef existingDef = typeRegistry.getBusinessMetadataDefByGuid(guid);
|
||||
|
||||
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update businessMetadata-def ", (existingDef != null ? existingDef.getName() : guid));
|
||||
|
||||
validateType(typeDef);
|
||||
|
||||
AtlasType type = typeRegistry.getTypeByGuid(guid);
|
||||
|
||||
if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.BUSINESS_METADATA) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, typeDef.getName(), DataTypes.TypeCategory.BUSINESS_METADATA.name());
|
||||
}
|
||||
|
||||
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, DataTypes.TypeCategory.BUSINESS_METADATA);
|
||||
|
||||
if (vertex == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
|
||||
}
|
||||
|
||||
updateVertexPreUpdate(typeDef, (AtlasBusinessMetadataType)type, vertex);
|
||||
|
||||
AtlasBusinessMetadataDef ret = toBusinessMetadataDef(vertex);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasBusinessMetadataDefStoreV2.updateByGuid({}): {}", guid, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public AtlasVertex preDeleteByName(String name) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasBusinessMetadataDefStoreV2.preDeleteByName({})", name);
|
||||
}
|
||||
|
||||
AtlasBusinessMetadataDef existingDef = typeRegistry.getBusinessMetadataDefByName(name);
|
||||
|
||||
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_DELETE, existingDef), "delete businessMetadata-def ", name);
|
||||
|
||||
AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, DataTypes.TypeCategory.BUSINESS_METADATA);
|
||||
|
||||
if (ret == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasBusinessMetadataDefStoreV2.preDeleteByName({}): {}", name, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasBusinessMetadataDefStoreV2.preDeleteByGuid({})", guid);
|
||||
}
|
||||
|
||||
AtlasBusinessMetadataDef existingDef = typeRegistry.getBusinessMetadataDefByGuid(guid);
|
||||
|
||||
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_DELETE, existingDef), "delete businessMetadata-def ", (existingDef != null ? existingDef.getName() : guid));
|
||||
|
||||
AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, DataTypes.TypeCategory.BUSINESS_METADATA);
|
||||
|
||||
if (ret == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasBusinessMetadataDefStoreV2.preDeleteByGuid({}): ret={}", guid, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private void updateVertexPreCreate(AtlasBusinessMetadataDef businessMetadataDef, AtlasBusinessMetadataType businessMetadataType,
|
||||
AtlasVertex vertex) throws AtlasBaseException {
|
||||
AtlasStructDefStoreV2.updateVertexPreCreate(businessMetadataDef, businessMetadataType, vertex, typeDefStore);
|
||||
}
|
||||
|
||||
private void updateVertexPreUpdate(AtlasBusinessMetadataDef businessMetadataDef, AtlasBusinessMetadataType businessMetadataType,
|
||||
AtlasVertex vertex) throws AtlasBaseException {
|
||||
// Load up current struct definition for matching attributes
|
||||
AtlasBusinessMetadataDef currentBusinessMetadataDef = toBusinessMetadataDef(vertex);
|
||||
|
||||
// Check to verify that in an update call we only allow addition of new entity types, not deletion of existing
|
||||
// entity types
|
||||
if (CollectionUtils.isNotEmpty(businessMetadataDef.getAttributeDefs())) {
|
||||
for (AtlasStructDef.AtlasAttributeDef attributeDef : businessMetadataDef.getAttributeDefs()) {
|
||||
String updatedApplicableEntityTypesString = attributeDef.getOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES);
|
||||
Set<String> updatedApplicableEntityTypes = StringUtils.isBlank(updatedApplicableEntityTypesString) ? null : AtlasType.fromJson(updatedApplicableEntityTypesString, Set.class);
|
||||
|
||||
AtlasStructDef.AtlasAttributeDef existingAttribute = currentBusinessMetadataDef.getAttribute(attributeDef.getName());
|
||||
if (existingAttribute != null) {
|
||||
String existingApplicableEntityTypesString = existingAttribute.getOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES);
|
||||
Set<String> existingApplicableEntityTypes = StringUtils.isBlank(existingApplicableEntityTypesString) ? null : AtlasType.fromJson(existingApplicableEntityTypesString, Set.class);
|
||||
|
||||
if (existingApplicableEntityTypes != null) {
|
||||
if (!updatedApplicableEntityTypes.containsAll(existingApplicableEntityTypes)) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.APPLICABLE_ENTITY_TYPES_DELETION_NOT_SUPPORTED,
|
||||
attributeDef.getName(), businessMetadataDef.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AtlasStructDefStoreV2.updateVertexPreUpdate(businessMetadataDef, businessMetadataType, vertex, typeDefStore);
|
||||
}
|
||||
|
||||
private AtlasBusinessMetadataDef toBusinessMetadataDef(AtlasVertex vertex) throws AtlasBaseException {
|
||||
AtlasBusinessMetadataDef ret = null;
|
||||
|
||||
if (vertex != null && typeDefStore.isTypeVertex(vertex, DataTypes.TypeCategory.BUSINESS_METADATA)) {
|
||||
ret = new AtlasBusinessMetadataDef();
|
||||
|
||||
AtlasStructDefStoreV2.toStructDef(vertex, ret, typeDefStore);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ import org.apache.atlas.repository.store.graph.v1.DeleteHandlerDelegate;
|
|||
import org.apache.atlas.store.DeleteType;
|
||||
import org.apache.atlas.type.AtlasClassificationType;
|
||||
import org.apache.atlas.type.AtlasEntityType;
|
||||
import org.apache.atlas.type.AtlasNamespaceType.AtlasNamespaceAttribute;
|
||||
import org.apache.atlas.type.AtlasBusinessMetadataType.AtlasBusinessAttribute;
|
||||
import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
|
||||
import org.apache.atlas.type.AtlasType;
|
||||
import org.apache.atlas.type.AtlasTypeRegistry;
|
||||
|
|
@ -827,17 +827,18 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
|
|||
|
||||
@Override
|
||||
@GraphTransaction
|
||||
public void addOrUpdateNamespaceAttributes(String guid, Map<String, Map<String, Object>> entityNamespaces, boolean isOverwrite) throws AtlasBaseException {
|
||||
public void addOrUpdateBusinessAttributes(String guid, Map<String, Map<String, Object>> businessAttrbutes, boolean isOverwrite) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> addOrUpdateNamespaceAttributes(guid={}, entityNamespaces={}, isOverwrite={})", guid, entityNamespaces, isOverwrite);
|
||||
|
||||
LOG.debug("==> addOrUpdateBusinessAttributes(guid={}, businessAttributes={}, isOverwrite={})", guid, businessAttrbutes, isOverwrite);
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(guid)) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "guid is null/empty");
|
||||
}
|
||||
|
||||
if (MapUtils.isEmpty(entityNamespaces)) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "entityNamespaces is null/empty");
|
||||
if (MapUtils.isEmpty(businessAttrbutes)) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "businessAttributes is null/empty");
|
||||
}
|
||||
|
||||
AtlasVertex entityVertex = AtlasGraphUtilsV2.findByGuid(guid);
|
||||
|
|
@ -846,61 +847,61 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
|
|||
throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
|
||||
}
|
||||
|
||||
String typeName = getTypeName(entityVertex);
|
||||
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
|
||||
AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(entityVertex);
|
||||
Map<String, Map<String, Object>> currNamespaces = entityRetriever.getEntityNamespaces(entityVertex);
|
||||
Set<String> updatedNsNames = new HashSet<>();
|
||||
String typeName = getTypeName(entityVertex);
|
||||
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
|
||||
AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(entityVertex);
|
||||
Map<String, Map<String, Object>> currEntityBusinessAttributes = entityRetriever.getBusinessMetadata(entityVertex);
|
||||
Set<String> updatedBusinessMetadataNames = new HashSet<>();
|
||||
|
||||
for (String nsName : entityType.getNamespaceAttributes().keySet()) {
|
||||
Map<String, Object> nsAttrs = entityNamespaces.get(nsName);
|
||||
Map<String, Object> currNsAttrs = currNamespaces != null ? currNamespaces.get(nsName) : null;
|
||||
for (String bmName : entityType.getBusinessAttributes().keySet()) {
|
||||
Map<String, Object> bmAttrs = businessAttrbutes.get(bmName);
|
||||
Map<String, Object> currBmAttrs = currEntityBusinessAttributes != null ? currEntityBusinessAttributes.get(bmName) : null;
|
||||
|
||||
if (nsAttrs == null && !isOverwrite) {
|
||||
if (bmAttrs == null && !isOverwrite) {
|
||||
continue;
|
||||
} else if (MapUtils.isEmpty(nsAttrs) && MapUtils.isEmpty(currNsAttrs)) { // no change
|
||||
} else if (MapUtils.isEmpty(bmAttrs) && MapUtils.isEmpty(currBmAttrs)) { // no change
|
||||
continue;
|
||||
} else if (Objects.equals(nsAttrs, currNsAttrs)) { // no change
|
||||
} else if (Objects.equals(bmAttrs, currBmAttrs)) { // no change
|
||||
continue;
|
||||
}
|
||||
|
||||
updatedNsNames.add(nsName);
|
||||
updatedBusinessMetadataNames.add(bmName);
|
||||
}
|
||||
|
||||
AtlasEntityAccessRequestBuilder requestBuilder = new AtlasEntityAccessRequestBuilder(typeRegistry, AtlasPrivilege.ENTITY_UPDATE_NAMESPACE, entityHeader);
|
||||
AtlasEntityAccessRequestBuilder requestBuilder = new AtlasEntityAccessRequestBuilder(typeRegistry, AtlasPrivilege.ENTITY_UPDATE_BUSINESS_METADATA, entityHeader);
|
||||
|
||||
for (String nsName : updatedNsNames) {
|
||||
requestBuilder.setNamespaceName(nsName);
|
||||
for (String bmName : updatedBusinessMetadataNames) {
|
||||
requestBuilder.setBusinessMetadata(bmName);
|
||||
|
||||
AtlasAuthorizationUtils.verifyAccess(requestBuilder.build(), "add/update namespace: guid=", guid, ", namespace=", nsName);
|
||||
AtlasAuthorizationUtils.verifyAccess(requestBuilder.build(), "add/update business-metadata: guid=", guid, ", business-metadata-name=", bmName);
|
||||
}
|
||||
|
||||
validateNamespaceAttributes(entityVertex, entityType, entityNamespaces, isOverwrite);
|
||||
validateBusinessAttributes(entityVertex, entityType, businessAttrbutes, isOverwrite);
|
||||
|
||||
if (isOverwrite) {
|
||||
entityGraphMapper.setNamespaceAttributes(entityVertex, entityType, entityNamespaces);
|
||||
entityGraphMapper.setBusinessAttributes(entityVertex, entityType, businessAttrbutes);
|
||||
} else {
|
||||
entityGraphMapper.addOrUpdateNamespaceAttributes(entityVertex, entityType, entityNamespaces);
|
||||
entityGraphMapper.addOrUpdateBusinessAttributes(entityVertex, entityType, businessAttrbutes);
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== addOrUpdateNamespaceAttributes(guid={}, entityNamespaces={}, isOverwrite={})", guid, entityNamespaces, isOverwrite);
|
||||
LOG.debug("<== addOrUpdateBusinessAttributes(guid={}, businessAttributes={}, isOverwrite={})", guid, businessAttrbutes, isOverwrite);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@GraphTransaction
|
||||
public void removeNamespaceAttributes(String guid, Map<String, Map<String, Object>> entityNamespaces) throws AtlasBaseException {
|
||||
public void removeBusinessAttributes(String guid, Map<String, Map<String, Object>> businessAttributes) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> removeNamespaceAttributes(guid={}, entityNamespaces={})", guid, entityNamespaces);
|
||||
LOG.debug("==> removeBusinessAttributes(guid={}, businessAttributes={})", guid, businessAttributes);
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(guid)) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "guid is null/empty");
|
||||
}
|
||||
|
||||
if (MapUtils.isEmpty(entityNamespaces)) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "entityNamespaces is null/empty");
|
||||
if (MapUtils.isEmpty(businessAttributes)) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "businessAttributes is null/empty");
|
||||
}
|
||||
|
||||
AtlasVertex entityVertex = AtlasGraphUtilsV2.findByGuid(guid);
|
||||
|
|
@ -912,19 +913,18 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
|
|||
String typeName = getTypeName(entityVertex);
|
||||
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
|
||||
AtlasEntityHeader entityHeader = entityRetriever.toAtlasEntityHeaderWithClassifications(entityVertex);
|
||||
AtlasEntityAccessRequestBuilder requestBuilder = new AtlasEntityAccessRequestBuilder(typeRegistry, AtlasPrivilege.ENTITY_UPDATE_BUSINESS_METADATA, entityHeader);
|
||||
|
||||
AtlasEntityAccessRequestBuilder requestBuilder = new AtlasEntityAccessRequestBuilder(typeRegistry, AtlasPrivilege.ENTITY_UPDATE_NAMESPACE, entityHeader);
|
||||
for (String bmName : businessAttributes.keySet()) {
|
||||
requestBuilder.setBusinessMetadata(bmName);
|
||||
|
||||
for (String nsName : entityNamespaces.keySet()) {
|
||||
requestBuilder.setNamespaceName(nsName);
|
||||
|
||||
AtlasAuthorizationUtils.verifyAccess(requestBuilder.build(), "remove namespace: guid=", guid, ", namespace=", nsName);
|
||||
AtlasAuthorizationUtils.verifyAccess(requestBuilder.build(), "remove business-metadata: guid=", guid, ", business-metadata=", bmName);
|
||||
}
|
||||
|
||||
entityGraphMapper.removeNamespaceAttributes(entityVertex, entityType, entityNamespaces);
|
||||
entityGraphMapper.removeBusinessAttributes(entityVertex, entityType, businessAttributes);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== removeNamespaceAttributes(guid={}, entityNamespaces={})", guid, entityNamespaces);
|
||||
LOG.debug("<== removeBusinessAttributes(guid={}, businessAttributes={})", guid, businessAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1065,7 +1065,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
|
|||
}
|
||||
}
|
||||
|
||||
private EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean isPartialUpdate, boolean replaceClassifications, boolean replaceNamespaceAttributes) throws AtlasBaseException {
|
||||
private EntityMutationResponse createOrUpdate(EntityStream entityStream, boolean isPartialUpdate, boolean replaceClassifications, boolean replaceBusinessAttributes) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> createOrUpdate()");
|
||||
}
|
||||
|
|
@ -1206,7 +1206,7 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
|
|||
RequestContext.get().endMetricRecord(checkForUnchangedEntities);
|
||||
}
|
||||
|
||||
EntityMutationResponse ret = entityGraphMapper.mapAttributesAndClassifications(context, isPartialUpdate, replaceClassifications, replaceNamespaceAttributes);
|
||||
EntityMutationResponse ret = entityGraphMapper.mapAttributesAndClassifications(context, isPartialUpdate, replaceClassifications, replaceBusinessAttributes);
|
||||
|
||||
ret.setGuidAssignments(context.getGuidAssignments());
|
||||
|
||||
|
|
@ -1478,42 +1478,42 @@ public class AtlasEntityStoreV2 implements AtlasEntityStore {
|
|||
}
|
||||
}
|
||||
|
||||
private void validateNamespaceAttributes(AtlasVertex entityVertex, AtlasEntityType entityType, Map<String, Map<String, Object>> entityNamespaces, boolean isOverwrite) throws AtlasBaseException {
|
||||
private void validateBusinessAttributes(AtlasVertex entityVertex, AtlasEntityType entityType, Map<String, Map<String, Object>> businessAttributes, boolean isOverwrite) throws AtlasBaseException {
|
||||
List<String> messages = new ArrayList<>();
|
||||
|
||||
Map<String, Map<String, AtlasNamespaceAttribute>> entityTypeNamespaces = entityType.getNamespaceAttributes();
|
||||
Map<String, Map<String, AtlasBusinessAttribute>> entityTypeBusinessMetadata = entityType.getBusinessAttributes();
|
||||
|
||||
for (String nsName : entityNamespaces.keySet()) {
|
||||
if (!entityTypeNamespaces.containsKey(nsName)) {
|
||||
messages.add(nsName + ": invalid namespace for entity type " + entityType.getTypeName());
|
||||
for (String bmName : businessAttributes.keySet()) {
|
||||
if (!entityTypeBusinessMetadata.containsKey(bmName)) {
|
||||
messages.add(bmName + ": invalid business-metadata for entity type " + entityType.getTypeName());
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Map<String, AtlasNamespaceAttribute> entityTypeNsAttributes = entityTypeNamespaces.get(nsName);
|
||||
Map<String, Object> entityNsAttributes = entityNamespaces.get(nsName);
|
||||
Map<String, AtlasBusinessAttribute> entityTypeBusinessAttributes = entityTypeBusinessMetadata.get(bmName);
|
||||
Map<String, Object> entityBusinessAttributes = businessAttributes.get(bmName);
|
||||
|
||||
for (AtlasNamespaceAttribute nsAttribute : entityTypeNsAttributes.values()) {
|
||||
AtlasType attrType = nsAttribute.getAttributeType();
|
||||
String attrName = nsAttribute.getName();
|
||||
Object attrValue = entityNsAttributes.get(attrName);
|
||||
String fieldName = entityType.getTypeName() + "." + nsName + "." + attrName;
|
||||
for (AtlasBusinessAttribute bmAttribute : entityTypeBusinessAttributes.values()) {
|
||||
AtlasType attrType = bmAttribute.getAttributeType();
|
||||
String attrName = bmAttribute.getName();
|
||||
Object attrValue = entityBusinessAttributes.get(attrName);
|
||||
String fieldName = entityType.getTypeName() + "." + bmName + "." + attrName;
|
||||
|
||||
if (attrValue != null) {
|
||||
attrType.validateValue(attrValue, fieldName, messages);
|
||||
} else if (!nsAttribute.getAttributeDef().getIsOptional()) {
|
||||
} else if (!bmAttribute.getAttributeDef().getIsOptional()) {
|
||||
final boolean isAttrValuePresent;
|
||||
|
||||
if (isOverwrite) {
|
||||
isAttrValuePresent = false;
|
||||
} else {
|
||||
Object existingValue = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, nsAttribute.getVertexPropertyName(), Object.class);
|
||||
Object existingValue = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, bmAttribute.getVertexPropertyName(), Object.class);
|
||||
|
||||
isAttrValuePresent = existingValue != null;
|
||||
}
|
||||
|
||||
if (!isAttrValuePresent) {
|
||||
messages.add(fieldName + ": mandatory namespace attribute value missing in type " + entityType.getTypeName());
|
||||
messages.add(fieldName + ": mandatory business-metadata attribute value missing in type " + entityType.getTypeName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,347 +0,0 @@
|
|||
/**
|
||||
* 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.repository.store.graph.v2;
|
||||
|
||||
import org.apache.atlas.AtlasErrorCode;
|
||||
import org.apache.atlas.authorize.AtlasAuthorizationUtils;
|
||||
import org.apache.atlas.authorize.AtlasPrivilege;
|
||||
import org.apache.atlas.authorize.AtlasTypeAccessRequest;
|
||||
import org.apache.atlas.exception.AtlasBaseException;
|
||||
import org.apache.atlas.model.TypeCategory;
|
||||
import org.apache.atlas.model.typedef.AtlasNamespaceDef;
|
||||
import org.apache.atlas.model.typedef.AtlasStructDef;
|
||||
import org.apache.atlas.repository.Constants;
|
||||
import org.apache.atlas.repository.graphdb.AtlasVertex;
|
||||
import org.apache.atlas.type.AtlasNamespaceType;
|
||||
import org.apache.atlas.type.AtlasType;
|
||||
import org.apache.atlas.type.AtlasTypeRegistry;
|
||||
import org.apache.atlas.typesystem.types.DataTypes;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.apache.atlas.model.typedef.AtlasNamespaceDef.ATTR_OPTION_APPLICABLE_ENTITY_TYPES;
|
||||
|
||||
public class AtlasNamespaceDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasNamespaceDef> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AtlasNamespaceDefStoreV2.class);
|
||||
|
||||
@Inject
|
||||
public AtlasNamespaceDefStoreV2(AtlasTypeDefGraphStoreV2 typeDefStore, AtlasTypeRegistry typeRegistry) {
|
||||
super(typeDefStore, typeRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasVertex preCreate(AtlasNamespaceDef namespaceDef) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasNamespaceDefStoreV2.preCreate({})", namespaceDef);
|
||||
}
|
||||
|
||||
validateType(namespaceDef);
|
||||
|
||||
AtlasType type = typeRegistry.getType(namespaceDef.getName());
|
||||
|
||||
if (type.getTypeCategory() != TypeCategory.NAMESPACE) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, namespaceDef.getName(),
|
||||
DataTypes.TypeCategory.NAMESPACE.name());
|
||||
}
|
||||
|
||||
AtlasVertex ret = typeDefStore.findTypeVertexByName(namespaceDef.getName());
|
||||
|
||||
if (ret != null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, namespaceDef.getName());
|
||||
}
|
||||
|
||||
ret = typeDefStore.createTypeVertex(namespaceDef);
|
||||
|
||||
updateVertexPreCreate(namespaceDef, (AtlasNamespaceType) type, ret);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasNamespaceDefStoreV2.preCreate({}): {}", namespaceDef, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasNamespaceDef create(AtlasNamespaceDef namespaceDef, AtlasVertex preCreateResult) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasNamespaceDefStoreV2.create({}, {})", namespaceDef, preCreateResult);
|
||||
}
|
||||
|
||||
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_CREATE, namespaceDef), "create namespace-def ", namespaceDef.getName());
|
||||
|
||||
AtlasVertex vertex = (preCreateResult == null) ? preCreate(namespaceDef) : preCreateResult;
|
||||
|
||||
AtlasNamespaceDef ret = toNamespaceDef(vertex);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasNamespaceDefStoreV2.create({}, {}): {}", namespaceDef, preCreateResult, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AtlasNamespaceDef> getAll() throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasNamespaceDef.getAll()");
|
||||
}
|
||||
|
||||
List<AtlasNamespaceDef> ret = new ArrayList<>();
|
||||
|
||||
Iterator<AtlasVertex> vertices = typeDefStore.findTypeVerticesByCategory(DataTypes.TypeCategory.NAMESPACE);
|
||||
while (vertices.hasNext()) {
|
||||
ret.add(toNamespaceDef(vertices.next()));
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasNamespaceDefStoreV2.getAll(): count={}", ret.size());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasNamespaceDef getByName(String name) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasNamespaceDefStoreV2.getByName({})", name);
|
||||
}
|
||||
|
||||
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, DataTypes.TypeCategory.NAMESPACE);
|
||||
|
||||
if (vertex == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
|
||||
}
|
||||
|
||||
vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, String.class);
|
||||
|
||||
AtlasNamespaceDef ret = toNamespaceDef(vertex);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasNamespaceDefStoreV2.getByName({}): {}", name, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasNamespaceDef getByGuid(String guid) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasNamespaceDefStoreV2.getByGuid({})", guid);
|
||||
}
|
||||
|
||||
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, DataTypes.TypeCategory.NAMESPACE);
|
||||
|
||||
if (vertex == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
|
||||
}
|
||||
|
||||
AtlasNamespaceDef ret = toNamespaceDef(vertex);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasNamespaceDefStoreV2.getByGuid({}): {}", guid, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasNamespaceDef update(AtlasNamespaceDef typeDef) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasNamespaceDefStoreV2.update({})", typeDef);
|
||||
}
|
||||
|
||||
validateType(typeDef);
|
||||
|
||||
AtlasNamespaceDef ret = StringUtils.isNotBlank(typeDef.getGuid()) ? updateByGuid(typeDef.getGuid(), typeDef)
|
||||
: updateByName(typeDef.getName(), typeDef);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasNamespaceDefStoreV2.update({}): {}", typeDef, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AtlasNamespaceDef updateByName(String name, AtlasNamespaceDef typeDef) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasNamespaceDefStoreV2.updateByName({}, {})", name, typeDef);
|
||||
}
|
||||
|
||||
AtlasNamespaceDef existingDef = typeRegistry.getNamespaceDefByName(name);
|
||||
|
||||
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update namespace-def ", name);
|
||||
|
||||
validateType(typeDef);
|
||||
|
||||
AtlasType type = typeRegistry.getType(typeDef.getName());
|
||||
|
||||
if (type.getTypeCategory() != TypeCategory.NAMESPACE) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, typeDef.getName(), DataTypes.TypeCategory.NAMESPACE.name());
|
||||
}
|
||||
|
||||
AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, DataTypes.TypeCategory.NAMESPACE);
|
||||
|
||||
if (vertex == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
|
||||
}
|
||||
|
||||
|
||||
updateVertexPreUpdate(typeDef, (AtlasNamespaceType)type, vertex);
|
||||
|
||||
AtlasNamespaceDef ret = toNamespaceDef(vertex);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasNamespaceDefStoreV2.updateByName({}, {}): {}", name, typeDef, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public AtlasNamespaceDef updateByGuid(String guid, AtlasNamespaceDef typeDef) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasNamespaceDefStoreV2.updateByGuid({})", guid);
|
||||
}
|
||||
|
||||
AtlasNamespaceDef existingDef = typeRegistry.getNamespaceDefByGuid(guid);
|
||||
|
||||
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update namespace-def ", (existingDef != null ? existingDef.getName() : guid));
|
||||
|
||||
validateType(typeDef);
|
||||
|
||||
AtlasType type = typeRegistry.getTypeByGuid(guid);
|
||||
|
||||
if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.NAMESPACE) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, typeDef.getName(), DataTypes.TypeCategory.NAMESPACE.name());
|
||||
}
|
||||
|
||||
AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, DataTypes.TypeCategory.NAMESPACE);
|
||||
|
||||
if (vertex == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
|
||||
}
|
||||
|
||||
updateVertexPreUpdate(typeDef, (AtlasNamespaceType)type, vertex);
|
||||
|
||||
AtlasNamespaceDef ret = toNamespaceDef(vertex);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasNamespaceDefStoreV2.updateByGuid({}): {}", guid, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public AtlasVertex preDeleteByName(String name) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasNamespaceDefStoreV2.preDeleteByName({})", name);
|
||||
}
|
||||
|
||||
AtlasNamespaceDef existingDef = typeRegistry.getNamespaceDefByName(name);
|
||||
|
||||
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_DELETE, existingDef), "delete namespace-def ", name);
|
||||
|
||||
AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, DataTypes.TypeCategory.NAMESPACE);
|
||||
|
||||
if (ret == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasNamespaceDefStoreV2.preDeleteByName({}): {}", name, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> AtlasNamespaceDefStoreV2.preDeleteByGuid({})", guid);
|
||||
}
|
||||
|
||||
AtlasNamespaceDef existingDef = typeRegistry.getNamespaceDefByGuid(guid);
|
||||
|
||||
AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_DELETE, existingDef), "delete namespace-def ", (existingDef != null ? existingDef.getName() : guid));
|
||||
|
||||
AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, DataTypes.TypeCategory.NAMESPACE);
|
||||
|
||||
if (ret == null) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== AtlasNamespaceDefStoreV2.preDeleteByGuid({}): ret={}", guid, ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private void updateVertexPreCreate(AtlasNamespaceDef namespaceDef, AtlasNamespaceType namespaceType,
|
||||
AtlasVertex vertex) throws AtlasBaseException {
|
||||
AtlasStructDefStoreV2.updateVertexPreCreate(namespaceDef, namespaceType, vertex, typeDefStore);
|
||||
}
|
||||
|
||||
private void updateVertexPreUpdate(AtlasNamespaceDef namespaceDef, AtlasNamespaceType namespaceType,
|
||||
AtlasVertex vertex) throws AtlasBaseException {
|
||||
// Load up current struct definition for matching attributes
|
||||
AtlasNamespaceDef currentNamespaceDef = toNamespaceDef(vertex);
|
||||
|
||||
// Check to verify that in an update call we only allow addition of new entity types, not deletion of existing
|
||||
// entity types
|
||||
if (CollectionUtils.isNotEmpty(namespaceDef.getAttributeDefs())) {
|
||||
for (AtlasStructDef.AtlasAttributeDef attributeDef : namespaceDef.getAttributeDefs()) {
|
||||
String updatedApplicableEntityTypesString = attributeDef.getOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES);
|
||||
Set<String> updatedApplicableEntityTypes = StringUtils.isBlank(updatedApplicableEntityTypesString) ? null : AtlasType.fromJson(updatedApplicableEntityTypesString, Set.class);
|
||||
|
||||
AtlasStructDef.AtlasAttributeDef existingAttribute = currentNamespaceDef.getAttribute(attributeDef.getName());
|
||||
if (existingAttribute != null) {
|
||||
String existingApplicableEntityTypesString = existingAttribute.getOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES);
|
||||
Set<String> existingApplicableEntityTypes = StringUtils.isBlank(existingApplicableEntityTypesString) ? null : AtlasType.fromJson(existingApplicableEntityTypesString, Set.class);
|
||||
|
||||
if (existingApplicableEntityTypes != null) {
|
||||
if (!updatedApplicableEntityTypes.containsAll(existingApplicableEntityTypes)) {
|
||||
throw new AtlasBaseException(AtlasErrorCode.APPLICABLE_ENTITY_TYPES_DELETION_NOT_SUPPORTED,
|
||||
attributeDef.getName(), namespaceDef.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AtlasStructDefStoreV2.updateVertexPreUpdate(namespaceDef, namespaceType, vertex, typeDefStore);
|
||||
}
|
||||
|
||||
private AtlasNamespaceDef toNamespaceDef(AtlasVertex vertex) throws AtlasBaseException {
|
||||
AtlasNamespaceDef ret = null;
|
||||
|
||||
if (vertex != null && typeDefStore.isTypeVertex(vertex, DataTypes.TypeCategory.NAMESPACE)) {
|
||||
ret = new AtlasNamespaceDef();
|
||||
|
||||
AtlasStructDefStoreV2.toStructDef(vertex, ret, typeDefStore);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
@ -101,8 +101,8 @@ public class AtlasTypeDefGraphStoreV2 extends AtlasTypeDefGraphStore {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected AtlasDefStore<AtlasNamespaceDef> getNamespaceDefStore(AtlasTypeRegistry typeRegistry) {
|
||||
return new AtlasNamespaceDefStoreV2(this, typeRegistry);
|
||||
protected AtlasDefStore<AtlasBusinessMetadataDef> getBusinessMetadataDefStore(AtlasTypeRegistry typeRegistry) {
|
||||
return new AtlasBusinessMetadataDefStoreV2(this, typeRegistry);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -498,8 +498,8 @@ public class AtlasTypeDefGraphStoreV2 extends AtlasTypeDefGraphStore {
|
|||
case RELATIONSHIP:
|
||||
return TypeCategory.RELATIONSHIP;
|
||||
|
||||
case NAMESPACE:
|
||||
return TypeCategory.NAMESPACE;
|
||||
case BUSINESS_METADATA:
|
||||
return TypeCategory.BUSINESS_METADATA;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ import org.apache.atlas.type.AtlasBuiltInTypes;
|
|||
import org.apache.atlas.type.AtlasClassificationType;
|
||||
import org.apache.atlas.type.AtlasEntityType;
|
||||
import org.apache.atlas.type.AtlasMapType;
|
||||
import org.apache.atlas.type.AtlasNamespaceType.AtlasNamespaceAttribute;
|
||||
import org.apache.atlas.type.AtlasBusinessMetadataType.AtlasBusinessAttribute;
|
||||
import org.apache.atlas.type.AtlasStructType;
|
||||
import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
|
||||
import org.apache.atlas.type.AtlasStructType.AtlasAttribute.AtlasRelationshipEdgeDirection;
|
||||
|
|
@ -254,7 +254,7 @@ public class EntityGraphMapper {
|
|||
}
|
||||
}
|
||||
|
||||
public EntityMutationResponse mapAttributesAndClassifications(EntityMutationContext context, final boolean isPartialUpdate, final boolean replaceClassifications, boolean replaceNamespaceAttributes) throws AtlasBaseException {
|
||||
public EntityMutationResponse mapAttributesAndClassifications(EntityMutationContext context, final boolean isPartialUpdate, final boolean replaceClassifications, boolean replaceBusinessAttributes) throws AtlasBaseException {
|
||||
MetricRecorder metric = RequestContext.get().startMetricRecord("mapAttributesAndClassifications");
|
||||
|
||||
EntityMutationResponse resp = new EntityMutationResponse();
|
||||
|
|
@ -276,7 +276,7 @@ public class EntityGraphMapper {
|
|||
resp.addEntity(CREATE, constructHeader(createdEntity, entityType, vertex));
|
||||
addClassifications(context, guid, createdEntity.getClassifications());
|
||||
|
||||
addOrUpdateNamespaceAttributes(vertex, entityType, createdEntity.getNamespaceAttributes());
|
||||
addOrUpdateBusinessAttributes(vertex, entityType, createdEntity.getBusinessAttributes());
|
||||
|
||||
reqContext.cache(createdEntity);
|
||||
}
|
||||
|
|
@ -303,8 +303,8 @@ public class EntityGraphMapper {
|
|||
addClassifications(context, guid, updatedEntity.getClassifications());
|
||||
}
|
||||
|
||||
if (replaceNamespaceAttributes) {
|
||||
setNamespaceAttributes(vertex, entityType, updatedEntity.getNamespaceAttributes());
|
||||
if (replaceBusinessAttributes) {
|
||||
setBusinessAttributes(vertex, entityType, updatedEntity.getBusinessAttributes());
|
||||
}
|
||||
|
||||
reqContext.cache(updatedEntity);
|
||||
|
|
@ -420,95 +420,95 @@ public class EntityGraphMapper {
|
|||
}
|
||||
|
||||
/*
|
||||
* reset/overwrite namespace attributes of the entity with given values
|
||||
* reset/overwrite business attributes of the entity with given values
|
||||
*/
|
||||
public void setNamespaceAttributes(AtlasVertex entityVertex, AtlasEntityType entityType, Map<String, Map<String, Object>> entityNamespaces) throws AtlasBaseException {
|
||||
public void setBusinessAttributes(AtlasVertex entityVertex, AtlasEntityType entityType, Map<String, Map<String, Object>> businessAttributes) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> setNamespaceAttributes(entityVertex={}, entityType={}, entityNamespaces={}", entityVertex, entityType.getTypeName(), entityNamespaces);
|
||||
LOG.debug("==> setBusinessAttributes(entityVertex={}, entityType={}, businessAttributes={}", entityVertex, entityType.getTypeName(), businessAttributes);
|
||||
}
|
||||
|
||||
Map<String, Map<String, AtlasNamespaceAttribute>> entityTypeNamespaces = entityType.getNamespaceAttributes();
|
||||
Map<String, Map<String, AtlasBusinessAttribute>> entityTypeBusinessAttributes = entityType.getBusinessAttributes();
|
||||
|
||||
for (Map.Entry<String, Map<String, AtlasNamespaceAttribute>> entry : entityTypeNamespaces.entrySet()) {
|
||||
String nsName = entry.getKey();
|
||||
Map<String, AtlasNamespaceAttribute> entityTypeNsAttributes = entry.getValue();
|
||||
Map<String, Object> entityNsAttributes = MapUtils.isEmpty(entityNamespaces) ? null : entityNamespaces.get(nsName);
|
||||
for (Map.Entry<String, Map<String, AtlasBusinessAttribute>> entry : entityTypeBusinessAttributes.entrySet()) {
|
||||
String bmName = entry.getKey();
|
||||
Map<String, AtlasBusinessAttribute> bmAttributes = entry.getValue();
|
||||
Map<String, Object> entityBmAttributes = MapUtils.isEmpty(businessAttributes) ? null : businessAttributes.get(bmName);
|
||||
|
||||
for (AtlasNamespaceAttribute nsAttribute : entityTypeNsAttributes.values()) {
|
||||
String nsAttrName = nsAttribute.getName();
|
||||
Object nsAttrExistingValue = entityVertex.getProperty(nsAttribute.getVertexPropertyName(), Object.class);
|
||||
Object nsAttrNewValue = MapUtils.isEmpty(entityNsAttributes) ? null : entityNsAttributes.get(nsAttrName);
|
||||
for (AtlasBusinessAttribute bmAttribute : bmAttributes.values()) {
|
||||
String bmAttrName = bmAttribute.getName();
|
||||
Object bmAttrExistingValue = entityVertex.getProperty(bmAttribute.getVertexPropertyName(), Object.class);
|
||||
Object bmAttrNewValue = MapUtils.isEmpty(entityBmAttributes) ? null : entityBmAttributes.get(bmAttrName);
|
||||
|
||||
if (nsAttrExistingValue == null) {
|
||||
if (nsAttrNewValue != null) {
|
||||
if (bmAttrExistingValue == null) {
|
||||
if (bmAttrNewValue != null) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("setNamespaceAttributes(): adding {}.{}={}", nsName, nsAttribute.getName(), nsAttrNewValue);
|
||||
LOG.debug("setBusinessAttributes(): adding {}.{}={}", bmName, bmAttribute.getName(), bmAttrNewValue);
|
||||
}
|
||||
|
||||
mapAttribute(nsAttribute, nsAttrNewValue, entityVertex, CREATE, new EntityMutationContext());
|
||||
mapAttribute(bmAttribute, bmAttrNewValue, entityVertex, CREATE, new EntityMutationContext());
|
||||
}
|
||||
} else {
|
||||
if (nsAttrNewValue != null) {
|
||||
if (!Objects.equals(nsAttrExistingValue, nsAttrNewValue)) {
|
||||
if (bmAttrNewValue != null) {
|
||||
if (!Objects.equals(bmAttrExistingValue, bmAttrNewValue)) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("setNamespaceAttributes(): updating {}.{}={}", nsName, nsAttribute.getName(), nsAttrNewValue);
|
||||
LOG.debug("setBusinessAttributes(): updating {}.{}={}", bmName, bmAttribute.getName(), bmAttrNewValue);
|
||||
}
|
||||
|
||||
mapAttribute(nsAttribute, nsAttrNewValue, entityVertex, UPDATE, new EntityMutationContext());
|
||||
mapAttribute(bmAttribute, bmAttrNewValue, entityVertex, UPDATE, new EntityMutationContext());
|
||||
}
|
||||
} else {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("setNamespaceAttributes(): removing {}.{}", nsName, nsAttribute.getName());
|
||||
LOG.debug("setBusinessAttributes(): removing {}.{}", bmName, bmAttribute.getName());
|
||||
}
|
||||
|
||||
entityVertex.removeProperty(nsAttribute.getVertexPropertyName());
|
||||
entityVertex.removeProperty(bmAttribute.getVertexPropertyName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== setNamespaceAttributes(entityVertex={}, entityType={}, entityNamespaces={}", entityVertex, entityType.getTypeName(), entityNamespaces);
|
||||
LOG.debug("<== setBusinessAttributes(entityVertex={}, entityType={}, businessAttributes={}", entityVertex, entityType.getTypeName(), businessAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* add or update the given namespace attributes on the entity
|
||||
* add or update the given business attributes on the entity
|
||||
*/
|
||||
public void addOrUpdateNamespaceAttributes(AtlasVertex entityVertex, AtlasEntityType entityType, Map<String, Map<String, Object>> entityNamespaces) throws AtlasBaseException {
|
||||
public void addOrUpdateBusinessAttributes(AtlasVertex entityVertex, AtlasEntityType entityType, Map<String, Map<String, Object>> businessAttributes) throws AtlasBaseException {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> addOrUpdateNamespaceAttributes(entityVertex={}, entityType={}, entityNamespaces={}", entityVertex, entityType.getTypeName(), entityNamespaces);
|
||||
LOG.debug("==> addOrUpdateBusinessAttributes(entityVertex={}, entityType={}, businessAttributes={}", entityVertex, entityType.getTypeName(), businessAttributes);
|
||||
}
|
||||
|
||||
Map<String, Map<String, AtlasNamespaceAttribute>> entityTypeNamespaces = entityType.getNamespaceAttributes();
|
||||
Map<String, Map<String, AtlasBusinessAttribute>> entityTypeBusinessAttributes = entityType.getBusinessAttributes();
|
||||
|
||||
if (MapUtils.isNotEmpty(entityTypeNamespaces) && MapUtils.isNotEmpty(entityNamespaces)) {
|
||||
for (Map.Entry<String, Map<String, AtlasNamespaceAttribute>> entry : entityTypeNamespaces.entrySet()) {
|
||||
String nsName = entry.getKey();
|
||||
Map<String, AtlasNamespaceAttribute> entityTypeNsAttributes = entry.getValue();
|
||||
Map<String, Object> entityNsAttributes = entityNamespaces.get(nsName);
|
||||
if (MapUtils.isNotEmpty(entityTypeBusinessAttributes) && MapUtils.isNotEmpty(businessAttributes)) {
|
||||
for (Map.Entry<String, Map<String, AtlasBusinessAttribute>> entry : entityTypeBusinessAttributes.entrySet()) {
|
||||
String bmName = entry.getKey();
|
||||
Map<String, AtlasBusinessAttribute> bmAttributes = entry.getValue();
|
||||
Map<String, Object> entityBmAttributes = businessAttributes.get(bmName);
|
||||
|
||||
if (MapUtils.isEmpty(entityNsAttributes)) {
|
||||
if (MapUtils.isEmpty(entityBmAttributes)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (AtlasNamespaceAttribute nsAttribute : entityTypeNsAttributes.values()) {
|
||||
String nsAttrName = nsAttribute.getName();
|
||||
for (AtlasBusinessAttribute bmAttribute : bmAttributes.values()) {
|
||||
String bmAttrName = bmAttribute.getName();
|
||||
|
||||
if (!entityNsAttributes.containsKey(nsAttrName)) {
|
||||
if (!entityBmAttributes.containsKey(bmAttrName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Object nsAttrValue = entityNsAttributes.get(nsAttrName);
|
||||
Object existingValue = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, nsAttribute.getVertexPropertyName(), Object.class);
|
||||
Object bmAttrValue = entityBmAttributes.get(bmAttrName);
|
||||
Object existingValue = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, bmAttribute.getVertexPropertyName(), Object.class);
|
||||
|
||||
if (existingValue == null) {
|
||||
if (nsAttrValue != null) {
|
||||
mapAttribute(nsAttribute, nsAttrValue, entityVertex, CREATE, new EntityMutationContext());
|
||||
if (bmAttrValue != null) {
|
||||
mapAttribute(bmAttribute, bmAttrValue, entityVertex, CREATE, new EntityMutationContext());
|
||||
}
|
||||
} else {
|
||||
if (!Objects.equals(existingValue, nsAttrValue)) {
|
||||
mapAttribute(nsAttribute, nsAttrValue, entityVertex, UPDATE, new EntityMutationContext());
|
||||
if (!Objects.equals(existingValue, bmAttrValue)) {
|
||||
mapAttribute(bmAttribute, bmAttrValue, entityVertex, UPDATE, new EntityMutationContext());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -516,43 +516,43 @@ public class EntityGraphMapper {
|
|||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== addOrUpdateNamespaceAttributes(entityVertex={}, entityType={}, entityNamespaces={}", entityVertex, entityType.getTypeName(), entityNamespaces);
|
||||
LOG.debug("<== addOrUpdateBusinessAttributes(entityVertex={}, entityType={}, businessAttributes={}", entityVertex, entityType.getTypeName(), businessAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* remove the given namespace attributes from the entity
|
||||
* remove the given business attributes from the entity
|
||||
*/
|
||||
public void removeNamespaceAttributes(AtlasVertex entityVertex, AtlasEntityType entityType, Map<String, Map<String, Object>> entityNamespaces) {
|
||||
public void removeBusinessAttributes(AtlasVertex entityVertex, AtlasEntityType entityType, Map<String, Map<String, Object>> businessAttributes) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("==> removeNamespaceAttributes(entityVertex={}, entityType={}, entityNamespaces={}", entityVertex, entityType.getTypeName(), entityNamespaces);
|
||||
LOG.debug("==> removeBusinessAttributes(entityVertex={}, entityType={}, businessAttributes={}", entityVertex, entityType.getTypeName(), businessAttributes);
|
||||
}
|
||||
|
||||
Map<String, Map<String, AtlasNamespaceAttribute>> entityTypeNamespaces = entityType.getNamespaceAttributes();
|
||||
Map<String, Map<String, AtlasBusinessAttribute>> entityTypeBusinessAttributes = entityType.getBusinessAttributes();
|
||||
|
||||
if (MapUtils.isNotEmpty(entityTypeNamespaces) && MapUtils.isNotEmpty(entityNamespaces)) {
|
||||
for (Map.Entry<String, Map<String, AtlasNamespaceAttribute>> entry : entityTypeNamespaces.entrySet()) {
|
||||
String nsName = entry.getKey();
|
||||
Map<String, AtlasNamespaceAttribute> entityTypeNsAttributes = entry.getValue();
|
||||
if (MapUtils.isNotEmpty(entityTypeBusinessAttributes) && MapUtils.isNotEmpty(businessAttributes)) {
|
||||
for (Map.Entry<String, Map<String, AtlasBusinessAttribute>> entry : entityTypeBusinessAttributes.entrySet()) {
|
||||
String bmName = entry.getKey();
|
||||
Map<String, AtlasBusinessAttribute> bmAttributes = entry.getValue();
|
||||
|
||||
if (!entityNamespaces.containsKey(nsName)) { // nothing to remove for this namespace
|
||||
if (!businessAttributes.containsKey(bmName)) { // nothing to remove for this business-metadata
|
||||
continue;
|
||||
}
|
||||
|
||||
Map<String, Object> entityNsAttributes = entityNamespaces.get(nsName);
|
||||
Map<String, Object> entityBmAttributes = businessAttributes.get(bmName);
|
||||
|
||||
for (AtlasNamespaceAttribute nsAttribute : entityTypeNsAttributes.values()) {
|
||||
// if (entityNsAttributes is empty) remove all attributes in this namespace
|
||||
// else remove the attribute only if its given in entityNsAttributes
|
||||
if (MapUtils.isEmpty(entityNsAttributes) || entityNsAttributes.containsKey(nsAttribute.getName())) {
|
||||
entityVertex.removeProperty(nsAttribute.getVertexPropertyName());
|
||||
for (AtlasBusinessAttribute bmttribute : bmAttributes.values()) {
|
||||
// if (entityBmAttributes is empty) remove all attributes in this business-metadata
|
||||
// else remove the attribute only if its given in entityBmAttributes
|
||||
if (MapUtils.isEmpty(entityBmAttributes) || entityBmAttributes.containsKey(bmttribute.getName())) {
|
||||
entityVertex.removeProperty(bmttribute.getVertexPropertyName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("<== removeNamespaceAttributes(entityVertex={}, entityType={}, entityNamespaces={}", entityVertex, entityType.getTypeName(), entityNamespaces);
|
||||
LOG.debug("<== removeBusinessAttributes(entityVertex={}, entityType={}, businessAttributes={}", entityVertex, entityType.getTypeName(), businessAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ import org.apache.atlas.type.AtlasArrayType;
|
|||
import org.apache.atlas.type.AtlasBuiltInTypes.AtlasObjectIdType;
|
||||
import org.apache.atlas.type.AtlasEntityType;
|
||||
import org.apache.atlas.type.AtlasMapType;
|
||||
import org.apache.atlas.type.AtlasNamespaceType.AtlasNamespaceAttribute;
|
||||
import org.apache.atlas.type.AtlasBusinessMetadataType.AtlasBusinessAttribute;
|
||||
import org.apache.atlas.type.AtlasRelationshipType;
|
||||
import org.apache.atlas.type.AtlasStructType;
|
||||
import org.apache.atlas.type.AtlasStructType.AtlasAttribute;
|
||||
|
|
@ -221,33 +221,33 @@ public class EntityGraphRetriever {
|
|||
return ret;
|
||||
}
|
||||
|
||||
public Map<String, Map<String, Object>> getEntityNamespaces(AtlasVertex entityVertex) throws AtlasBaseException {
|
||||
Map<String, Map<String, Object>> ret = null;
|
||||
String entityTypeName = getTypeName(entityVertex);
|
||||
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);
|
||||
Map<String, Map<String, AtlasNamespaceAttribute>> entityTypeNamespaces = entityType != null ? entityType.getNamespaceAttributes() : null;
|
||||
public Map<String, Map<String, Object>> getBusinessMetadata(AtlasVertex entityVertex) throws AtlasBaseException {
|
||||
Map<String, Map<String, Object>> ret = null;
|
||||
String entityTypeName = getTypeName(entityVertex);
|
||||
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);
|
||||
Map<String, Map<String, AtlasBusinessAttribute>> entityTypeBm = entityType != null ? entityType.getBusinessAttributes() : null;
|
||||
|
||||
if (MapUtils.isNotEmpty(entityTypeNamespaces)) {
|
||||
for (Map.Entry<String, Map<String, AtlasNamespaceAttribute>> entry : entityTypeNamespaces.entrySet()) {
|
||||
String nsName = entry.getKey();
|
||||
Map<String, AtlasNamespaceAttribute> nsAttributes = entry.getValue();
|
||||
Map<String, Object> entityNsAttrs = null;
|
||||
if (MapUtils.isNotEmpty(entityTypeBm)) {
|
||||
for (Map.Entry<String, Map<String, AtlasBusinessAttribute>> entry : entityTypeBm.entrySet()) {
|
||||
String bmName = entry.getKey();
|
||||
Map<String, AtlasBusinessAttribute> bmAttributes = entry.getValue();
|
||||
Map<String, Object> entityBmAttrs = null;
|
||||
|
||||
for (AtlasNamespaceAttribute nsAttribute : nsAttributes.values()) {
|
||||
Object nsAttrValue = mapVertexToAttribute(entityVertex, nsAttribute, null, false, false);
|
||||
for (AtlasBusinessAttribute bmAttribute : bmAttributes.values()) {
|
||||
Object bmAttrValue = mapVertexToAttribute(entityVertex, bmAttribute, null, false, false);
|
||||
|
||||
if (nsAttrValue != null) {
|
||||
if (bmAttrValue != null) {
|
||||
if (ret == null) {
|
||||
ret = new HashMap<>();
|
||||
}
|
||||
|
||||
if (entityNsAttrs == null) {
|
||||
entityNsAttrs = new HashMap<>();
|
||||
if (entityBmAttrs == null) {
|
||||
entityBmAttrs = new HashMap<>();
|
||||
|
||||
ret.put(nsName, entityNsAttrs);
|
||||
ret.put(bmName, entityBmAttrs);
|
||||
}
|
||||
|
||||
entityNsAttrs.put(nsAttribute.getName(), nsAttrValue);
|
||||
entityBmAttrs.put(bmAttribute.getName(), bmAttrValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -622,7 +622,7 @@ public class EntityGraphRetriever {
|
|||
|
||||
mapSystemAttributes(entityVertex, entity);
|
||||
|
||||
mapNamespaceAttributes(entityVertex, entity);
|
||||
mapBusinessAttributes(entityVertex, entity);
|
||||
|
||||
mapAttributes(entityVertex, entity, entityExtInfo, isMinExtInfo, includeReferences);
|
||||
|
||||
|
|
@ -804,8 +804,8 @@ public class EntityGraphRetriever {
|
|||
}
|
||||
}
|
||||
|
||||
private void mapNamespaceAttributes(AtlasVertex entityVertex, AtlasEntity entity) throws AtlasBaseException {
|
||||
entity.setNamespaceAttributes(getEntityNamespaces(entityVertex));
|
||||
private void mapBusinessAttributes(AtlasVertex entityVertex, AtlasEntity entity) throws AtlasBaseException {
|
||||
entity.setBusinessAttributes(getBusinessMetadata(entityVertex));
|
||||
}
|
||||
|
||||
public List<AtlasClassification> getAllClassifications(AtlasVertex entityVertex) throws AtlasBaseException {
|
||||
|
|
|
|||
|
|
@ -154,8 +154,8 @@ public class FilterUtil {
|
|||
return atlasType.getTypeCategory() == TypeCategory.ENUM;
|
||||
case "RELATIONSHIP":
|
||||
return atlasType.getTypeCategory() == TypeCategory.RELATIONSHIP;
|
||||
case "NAMESPACE":
|
||||
return atlasType.getTypeCategory() == TypeCategory.NAMESPACE;
|
||||
case "BUSINESS_METADATA":
|
||||
return atlasType.getTypeCategory() == TypeCategory.BUSINESS_METADATA;
|
||||
default:
|
||||
// This shouldn't have happened
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,304 @@
|
|||
/**
|
||||
* 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.repository.store.graph.v2;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.apache.atlas.AtlasErrorCode;
|
||||
import org.apache.atlas.TestModules;
|
||||
import org.apache.atlas.exception.AtlasBaseException;
|
||||
import org.apache.atlas.model.typedef.AtlasBusinessMetadataDef;
|
||||
import org.apache.atlas.model.typedef.AtlasStructDef;
|
||||
import org.apache.atlas.model.typedef.AtlasTypesDef;
|
||||
import org.apache.atlas.type.AtlasEntityType;
|
||||
import org.apache.atlas.type.AtlasBusinessMetadataType.AtlasBusinessAttribute;
|
||||
import org.apache.atlas.type.AtlasType;
|
||||
import org.apache.atlas.type.AtlasTypeRegistry;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.atlas.model.typedef.AtlasBusinessMetadataDef.ATTR_OPTION_APPLICABLE_ENTITY_TYPES;
|
||||
|
||||
import static org.apache.atlas.utils.TestLoadModelUtils.loadBaseModel;
|
||||
import static org.apache.atlas.utils.TestLoadModelUtils.loadFsModel;
|
||||
import static org.apache.atlas.utils.TestLoadModelUtils.loadHiveModel;
|
||||
|
||||
/* Please note that for these tests, since the typeRegistry can be injected only once,
|
||||
* any new tests should make sure that they flush the type registry at the end of the test.
|
||||
* testNG does not provide a way to execute a method after each test has completed the run, hence
|
||||
* we have to manually make sure that the flushTypeRegistry method is invoked.
|
||||
*/
|
||||
@Guice(modules = TestModules.TestOnlyModule.class)
|
||||
public class AtlasBusinessMetadataDefStoreV2Test {
|
||||
|
||||
@Inject
|
||||
AtlasTypeRegistry typeRegistry;
|
||||
|
||||
@Inject
|
||||
private AtlasTypeDefGraphStoreV2 typeDefStore;
|
||||
|
||||
private AtlasTypesDef typesDefs;
|
||||
|
||||
private static int randomCount;
|
||||
private static final String TEST_BUSINESS_METADATA = "test_businessMetadata";
|
||||
private String businessMetadataName;
|
||||
@BeforeClass
|
||||
public void setup() throws IOException, AtlasBaseException {
|
||||
loadBaseModel(typeDefStore, typeRegistry);
|
||||
loadFsModel(typeDefStore, typeRegistry);
|
||||
loadHiveModel(typeDefStore, typeRegistry);
|
||||
|
||||
typesDefs = new AtlasTypesDef(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
|
||||
|
||||
businessMetadataName = TEST_BUSINESS_METADATA;
|
||||
|
||||
randomCount = 1;
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
public void setTypeDefs() {
|
||||
typesDefs = new AtlasTypesDef(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
|
||||
randomCount++;
|
||||
businessMetadataName = TEST_BUSINESS_METADATA + randomCount;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createBusinessMetadataDef() throws AtlasBaseException {
|
||||
createBusinessMetadataTypes(businessMetadataName);
|
||||
Assert.assertEquals(typeRegistry.getAllBusinessMetadataDefs().size(), 1);
|
||||
AtlasEntityType entityType = typeRegistry.getEntityTypeByName("hive_table");
|
||||
Map<String, Map<String, AtlasBusinessAttribute>> m1 = entityType.getBusinessAttributes();
|
||||
Assert.assertEquals(m1.get(businessMetadataName).size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteBusinessMetadataDefs() throws AtlasBaseException {
|
||||
createBusinessMetadataTypes(businessMetadataName);
|
||||
for (AtlasBusinessMetadataDef atlasBusinessMetaDataDef : typesDefs.getBusinessMetadataDefs()) {
|
||||
if (atlasBusinessMetaDataDef.getName().equals(businessMetadataName)) {
|
||||
typesDefs = new AtlasTypesDef(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
typesDefs.setBusinessMetadataDefs(Arrays.asList(atlasBusinessMetaDataDef));
|
||||
typeDefStore.deleteTypesDef(typesDefs);
|
||||
}
|
||||
}
|
||||
|
||||
for (AtlasBusinessMetadataDef businessMetadataDef : typeRegistry.getAllBusinessMetadataDefs()) {
|
||||
Assert.assertNotEquals(businessMetadataDef.getName(), businessMetadataName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBusinessMetadataDefs() throws AtlasBaseException {
|
||||
createBusinessMetadataTypes(businessMetadataName);
|
||||
AtlasBusinessMetadataDef businessMetadataDef = findBusinessMetadataDef(businessMetadataName);
|
||||
Assert.assertNotNull(businessMetadataDef);
|
||||
|
||||
addBusinessAttribute(businessMetadataDef, "test_businessMetadata_attribute3", Collections.singleton("hive_table"),
|
||||
String.format("array<%s>", "string"), AtlasStructDef.AtlasAttributeDef.Cardinality.LIST);
|
||||
|
||||
updateBusinessMetadataDefs(businessMetadataDef);
|
||||
typeDefStore.updateTypesDef(typesDefs);
|
||||
AtlasEntityType entityType = typeRegistry.getEntityTypeByName("hive_table");
|
||||
Map<String, Map<String, AtlasBusinessAttribute>> m1 = entityType.getBusinessAttributes();
|
||||
Assert.assertEquals(m1.get(businessMetadataName).size(), 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to verify that we cannot delete attribute defs from a businessMetadata definition
|
||||
* @throws AtlasBaseException
|
||||
*/
|
||||
@Test
|
||||
public void updateTypeDefsWithoutApplicableEntityTypes() throws AtlasBaseException {
|
||||
createBusinessMetadataTypes(businessMetadataName);
|
||||
AtlasBusinessMetadataDef businessMetadataDef = findBusinessMetadataDef(businessMetadataName);
|
||||
Assert.assertNotNull(businessMetadataDef);
|
||||
|
||||
AtlasStructDef.AtlasAttributeDef businessAttributeDef = businessMetadataDef.getAttributeDefs().iterator().next();
|
||||
businessMetadataDef.setAttributeDefs(Arrays.asList(businessAttributeDef));
|
||||
|
||||
AtlasTypesDef existingTypeDefs = typesDefs;
|
||||
|
||||
try {
|
||||
typesDefs.setBusinessMetadataDefs(Arrays.asList(businessMetadataDef));
|
||||
typeDefStore.updateTypesDef(typesDefs);
|
||||
} catch (AtlasBaseException e) {
|
||||
Assert.assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.ATTRIBUTE_DELETION_NOT_SUPPORTED);
|
||||
} finally {
|
||||
typesDefs = existingTypeDefs;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateTypeDefsDeleteApplicableEntityTypes() throws AtlasBaseException {
|
||||
createBusinessMetadataTypes(businessMetadataName);
|
||||
AtlasBusinessMetadataDef businessMetadataDef = findBusinessMetadataDef(businessMetadataName);
|
||||
Assert.assertNotNull(businessMetadataDef);
|
||||
|
||||
Iterator<AtlasStructDef.AtlasAttributeDef> it = businessMetadataDef.getAttributeDefs().iterator();
|
||||
AtlasStructDef.AtlasAttributeDef businessAttributeDef = it.next();
|
||||
AtlasStructDef.AtlasAttributeDef businessAttributeDef2 = it.next();
|
||||
|
||||
businessAttributeDef.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.emptySet()));
|
||||
|
||||
businessMetadataDef.setAttributeDefs(Arrays.asList(businessAttributeDef, businessAttributeDef2));
|
||||
|
||||
AtlasTypesDef existingTypeDefs = typesDefs;
|
||||
|
||||
try {
|
||||
typesDefs.setBusinessMetadataDefs(Arrays.asList(businessMetadataDef));
|
||||
typeDefStore.updateTypesDef(typesDefs);
|
||||
} catch (AtlasBaseException e) {
|
||||
Assert.assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.APPLICABLE_ENTITY_TYPES_DELETION_NOT_SUPPORTED);
|
||||
} finally {
|
||||
typesDefs = existingTypeDefs;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateNsAttrDefDeleteApplicableEntityTypes() throws AtlasBaseException {
|
||||
createBusinessMetadataTypes(businessMetadataName);
|
||||
|
||||
AtlasBusinessMetadataDef businessMetadataDef = findBusinessMetadataDef(businessMetadataName);
|
||||
Assert.assertNotNull(businessMetadataDef);
|
||||
|
||||
Iterator<AtlasStructDef.AtlasAttributeDef> it = businessMetadataDef.getAttributeDefs().iterator();
|
||||
AtlasStructDef.AtlasAttributeDef businessAttributeDef = it.next();
|
||||
AtlasStructDef.AtlasAttributeDef businessAttributeDef2 = it.next();
|
||||
|
||||
businessAttributeDef.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton("hive_table")));
|
||||
|
||||
businessMetadataDef.setAttributeDefs(Arrays.asList(businessAttributeDef, businessAttributeDef2));
|
||||
|
||||
AtlasTypesDef existingTypeDefs = typesDefs;
|
||||
|
||||
try {
|
||||
typesDefs.setBusinessMetadataDefs(Arrays.asList(businessMetadataDef));
|
||||
typeDefStore.updateTypesDef(typesDefs);
|
||||
} catch (AtlasBaseException e) {
|
||||
Assert.assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.APPLICABLE_ENTITY_TYPES_DELETION_NOT_SUPPORTED);
|
||||
} finally {
|
||||
typesDefs = existingTypeDefs;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateNsAttrDefAddApplicableEntityTypes() throws AtlasBaseException {
|
||||
createBusinessMetadataTypes(businessMetadataName);
|
||||
|
||||
AtlasBusinessMetadataDef businessMetadataDef = findBusinessMetadataDef(businessMetadataName);
|
||||
AtlasStructDef.AtlasAttributeDef businessAttributeDef1 = businessMetadataDef.getAttributeDefs().get(0);
|
||||
AtlasStructDef.AtlasAttributeDef businessAttributeDef2 = businessMetadataDef.getAttributeDefs().get(1);
|
||||
Set<String> applicableEntityTypes = AtlasType.fromJson(businessAttributeDef1.getOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES), Set.class);
|
||||
|
||||
if (applicableEntityTypes == null) {
|
||||
applicableEntityTypes = new HashSet<>();
|
||||
}
|
||||
|
||||
applicableEntityTypes.add("hive_column");
|
||||
businessAttributeDef1.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(applicableEntityTypes));
|
||||
businessMetadataDef.setAttributeDefs(Arrays.asList(businessAttributeDef1, businessAttributeDef2));
|
||||
|
||||
updateBusinessMetadataDefs(businessMetadataDef);
|
||||
|
||||
typeDefStore.updateTypesDef(typesDefs);
|
||||
|
||||
businessMetadataDef = findBusinessMetadataDef(businessMetadataName);
|
||||
businessAttributeDef1 = businessMetadataDef.getAttributeDefs().get(0);
|
||||
|
||||
applicableEntityTypes = AtlasType.fromJson(businessAttributeDef1.getOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES), Set.class);
|
||||
|
||||
Assert.assertEquals(applicableEntityTypes == null ? 0 : applicableEntityTypes.size(), 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateMaxStringLengthForStringTypes() throws AtlasBaseException {
|
||||
AtlasTypesDef existingTypeDefs = typesDefs;
|
||||
AtlasBusinessMetadataDef businessMetadataDef1 = new AtlasBusinessMetadataDef(businessMetadataName, "test_description", null);
|
||||
addBusinessAttribute(businessMetadataDef1, "test_businessMetadata_attribute1", new HashSet<>(Arrays.asList("hive_table", "fs_path")), "string",
|
||||
AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
|
||||
typesDefs.setBusinessMetadataDefs(Arrays.asList(businessMetadataDef1));
|
||||
try {
|
||||
typeDefStore.createTypesDef(typesDefs);
|
||||
} catch (AtlasBaseException exception) {
|
||||
Assert.assertEquals(exception.getAtlasErrorCode(), AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE);
|
||||
} finally {
|
||||
typesDefs = existingTypeDefs;
|
||||
}
|
||||
}
|
||||
|
||||
private AtlasBusinessMetadataDef createBusinessMetadataDef(String businessMetadataName) {
|
||||
AtlasBusinessMetadataDef businessMetadataDef1 = new AtlasBusinessMetadataDef(businessMetadataName, "test_description", null);
|
||||
addBusinessAttribute(businessMetadataDef1, "test_businessMetadata_attribute1", new HashSet<>(Arrays.asList("hive_table", "fs_path")), "int",
|
||||
AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
|
||||
addBusinessAttribute(businessMetadataDef1, "test_businessMetadata_attribute2", Collections.singleton("hive_table"), "int",
|
||||
AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
|
||||
return businessMetadataDef1;
|
||||
}
|
||||
|
||||
private AtlasBusinessMetadataDef createBusinessMetadataDef2(String businessMetadataName) {
|
||||
AtlasBusinessMetadataDef businessMetadataDef1 = new AtlasBusinessMetadataDef(businessMetadataName, "test_description", null);
|
||||
addBusinessAttribute(businessMetadataDef1, "test_businessMetadata_attribute1", Collections.emptySet(), "int",
|
||||
AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
|
||||
addBusinessAttribute(businessMetadataDef1, "test_businessMetadata_attribute2", Collections.singleton("hive_table"), "int",
|
||||
AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
|
||||
return businessMetadataDef1;
|
||||
}
|
||||
|
||||
private void createBusinessMetadataTypes(String businessMetadataName) throws AtlasBaseException {
|
||||
List<AtlasBusinessMetadataDef> businessMetadataDefs = new ArrayList(typesDefs.getBusinessMetadataDefs());
|
||||
businessMetadataDefs.add(createBusinessMetadataDef(businessMetadataName));
|
||||
typesDefs.setBusinessMetadataDefs(businessMetadataDefs);
|
||||
typeDefStore.createTypesDef(typesDefs);
|
||||
}
|
||||
|
||||
private void addBusinessAttribute(AtlasBusinessMetadataDef businessMetadataDef, String name, Set<String> applicableEntityTypes,
|
||||
String typeName, AtlasStructDef.AtlasAttributeDef.Cardinality cardinality) {
|
||||
AtlasStructDef.AtlasAttributeDef attributeDef = new AtlasStructDef.AtlasAttributeDef(name, typeName);
|
||||
|
||||
attributeDef.setCardinality(cardinality);
|
||||
attributeDef.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(applicableEntityTypes));
|
||||
attributeDef.setIsOptional(true);
|
||||
attributeDef.setIsUnique(false);
|
||||
|
||||
businessMetadataDef.addAttribute(attributeDef);
|
||||
}
|
||||
|
||||
private AtlasBusinessMetadataDef findBusinessMetadataDef(String businessMetadataName) {
|
||||
for (AtlasBusinessMetadataDef atlasBusinessMetaDataDef : typesDefs.getBusinessMetadataDefs()) {
|
||||
if (atlasBusinessMetaDataDef.getName().equals(businessMetadataName)) {
|
||||
return atlasBusinessMetaDataDef;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateBusinessMetadataDefs(AtlasBusinessMetadataDef atlasBusinessMetaDataDef) {
|
||||
for (int i = 0; i < typesDefs.getBusinessMetadataDefs().size(); i++) {
|
||||
if (typesDefs.getBusinessMetadataDefs().get(i).getName().equals(businessMetadataName)) {
|
||||
typesDefs.getBusinessMetadataDefs().set(i, atlasBusinessMetaDataDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,304 +0,0 @@
|
|||
/**
|
||||
* 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.repository.store.graph.v2;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.apache.atlas.AtlasErrorCode;
|
||||
import org.apache.atlas.TestModules;
|
||||
import org.apache.atlas.exception.AtlasBaseException;
|
||||
import org.apache.atlas.model.typedef.AtlasNamespaceDef;
|
||||
import org.apache.atlas.model.typedef.AtlasStructDef;
|
||||
import org.apache.atlas.model.typedef.AtlasTypesDef;
|
||||
import org.apache.atlas.type.AtlasEntityType;
|
||||
import org.apache.atlas.type.AtlasNamespaceType.AtlasNamespaceAttribute;
|
||||
import org.apache.atlas.type.AtlasType;
|
||||
import org.apache.atlas.type.AtlasTypeRegistry;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static org.apache.atlas.model.typedef.AtlasNamespaceDef.ATTR_OPTION_APPLICABLE_ENTITY_TYPES;
|
||||
|
||||
import static org.apache.atlas.utils.TestLoadModelUtils.loadBaseModel;
|
||||
import static org.apache.atlas.utils.TestLoadModelUtils.loadFsModel;
|
||||
import static org.apache.atlas.utils.TestLoadModelUtils.loadHiveModel;
|
||||
|
||||
/* Please note that for these tests, since the typeRegistry can be injected only once,
|
||||
* any new tests should make sure that they flush the type registry at the end of the test.
|
||||
* testNG does not provide a way to execute a method after each test has completed the run, hence
|
||||
* we have to manually make sure that the flushTypeRegistry method is invoked.
|
||||
*/
|
||||
@Guice(modules = TestModules.TestOnlyModule.class)
|
||||
public class AtlasNamespaceDefStoreV2Test {
|
||||
|
||||
@Inject
|
||||
AtlasTypeRegistry typeRegistry;
|
||||
|
||||
@Inject
|
||||
private AtlasTypeDefGraphStoreV2 typeDefStore;
|
||||
|
||||
private AtlasTypesDef typesDefs;
|
||||
|
||||
private static int randomCount;
|
||||
private static final String TEST_NAMESPACE = "test_namespace";
|
||||
private String namespaceName;
|
||||
@BeforeClass
|
||||
public void setup() throws IOException, AtlasBaseException {
|
||||
loadBaseModel(typeDefStore, typeRegistry);
|
||||
loadFsModel(typeDefStore, typeRegistry);
|
||||
loadHiveModel(typeDefStore, typeRegistry);
|
||||
|
||||
typesDefs = new AtlasTypesDef(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
|
||||
|
||||
namespaceName = TEST_NAMESPACE;
|
||||
|
||||
randomCount = 1;
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
public void setTypeDefs() {
|
||||
typesDefs = new AtlasTypesDef(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
|
||||
randomCount++;
|
||||
namespaceName = TEST_NAMESPACE + randomCount;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createNamespaceTypeDef() throws AtlasBaseException {
|
||||
createNamespaceTypes(namespaceName);
|
||||
Assert.assertEquals(typeRegistry.getAllNamespaceDefs().size(), 1);
|
||||
AtlasEntityType entityType = typeRegistry.getEntityTypeByName("hive_table");
|
||||
Map<String, Map<String, AtlasNamespaceAttribute>> m1 = entityType.getNamespaceAttributes();
|
||||
Assert.assertEquals(m1.get(namespaceName).size(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteNamespaceTypeDefs() throws AtlasBaseException {
|
||||
createNamespaceTypes(namespaceName);
|
||||
for (AtlasNamespaceDef atlasNamespaceDef : typesDefs.getNamespaceDefs()) {
|
||||
if (atlasNamespaceDef.getName().equals(namespaceName)) {
|
||||
typesDefs = new AtlasTypesDef(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.emptyList(),
|
||||
Collections.emptyList());
|
||||
typesDefs.setNamespaceDefs(Arrays.asList(atlasNamespaceDef));
|
||||
typeDefStore.deleteTypesDef(typesDefs);
|
||||
}
|
||||
}
|
||||
|
||||
for (AtlasNamespaceDef namespaceDef : typeRegistry.getAllNamespaceDefs()) {
|
||||
Assert.assertNotEquals(namespaceDef.getName(), namespaceName);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateNamespaceTypeDefs() throws AtlasBaseException {
|
||||
createNamespaceTypes(namespaceName);
|
||||
AtlasNamespaceDef namespaceDef = findNamespaceDef(namespaceName);
|
||||
Assert.assertNotNull(namespaceDef);
|
||||
|
||||
addNamespaceAttribute(namespaceDef, "test_namespace_attribute3", Collections.singleton("hive_table"),
|
||||
String.format("array<%s>", "string"), AtlasStructDef.AtlasAttributeDef.Cardinality.LIST);
|
||||
|
||||
updateNamespaceTypeDefs(namespaceDef);
|
||||
typeDefStore.updateTypesDef(typesDefs);
|
||||
AtlasEntityType entityType = typeRegistry.getEntityTypeByName("hive_table");
|
||||
Map<String, Map<String, AtlasNamespaceAttribute>> m1 = entityType.getNamespaceAttributes();
|
||||
Assert.assertEquals(m1.get(namespaceName).size(), 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to verify that we cannot delete attribute defs from a namespace definition
|
||||
* @throws AtlasBaseException
|
||||
*/
|
||||
@Test
|
||||
public void updateTypeDefsWithoutApplicableEntityTypes() throws AtlasBaseException {
|
||||
createNamespaceTypes(namespaceName);
|
||||
AtlasNamespaceDef namespaceDef = findNamespaceDef(namespaceName);
|
||||
Assert.assertNotNull(namespaceDef);
|
||||
|
||||
AtlasStructDef.AtlasAttributeDef namespaceAttributeDef = namespaceDef.getAttributeDefs().iterator().next();
|
||||
namespaceDef.setAttributeDefs(Arrays.asList(namespaceAttributeDef));
|
||||
|
||||
AtlasTypesDef existingTypeDefs = typesDefs;
|
||||
|
||||
try {
|
||||
typesDefs.setNamespaceDefs(Arrays.asList(namespaceDef));
|
||||
typeDefStore.updateTypesDef(typesDefs);
|
||||
} catch (AtlasBaseException e) {
|
||||
Assert.assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.ATTRIBUTE_DELETION_NOT_SUPPORTED);
|
||||
} finally {
|
||||
typesDefs = existingTypeDefs;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateTypeDefsDeleteApplicableEntityTypes() throws AtlasBaseException {
|
||||
createNamespaceTypes(namespaceName);
|
||||
AtlasNamespaceDef namespaceDef = findNamespaceDef(namespaceName);
|
||||
Assert.assertNotNull(namespaceDef);
|
||||
|
||||
Iterator<AtlasStructDef.AtlasAttributeDef> it = namespaceDef.getAttributeDefs().iterator();
|
||||
AtlasStructDef.AtlasAttributeDef namespaceAttributeDef = it.next();
|
||||
AtlasStructDef.AtlasAttributeDef namespaceAttributeDef2 = it.next();
|
||||
|
||||
namespaceAttributeDef.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.emptySet()));
|
||||
|
||||
namespaceDef.setAttributeDefs(Arrays.asList(namespaceAttributeDef, namespaceAttributeDef2));
|
||||
|
||||
AtlasTypesDef existingTypeDefs = typesDefs;
|
||||
|
||||
try {
|
||||
typesDefs.setNamespaceDefs(Arrays.asList(namespaceDef));
|
||||
typeDefStore.updateTypesDef(typesDefs);
|
||||
} catch (AtlasBaseException e) {
|
||||
Assert.assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.APPLICABLE_ENTITY_TYPES_DELETION_NOT_SUPPORTED);
|
||||
} finally {
|
||||
typesDefs = existingTypeDefs;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateNsAttrDefDeleteApplicableEntityTypes() throws AtlasBaseException {
|
||||
createNamespaceTypes(namespaceName);
|
||||
|
||||
AtlasNamespaceDef namespaceDef = findNamespaceDef(namespaceName);
|
||||
Assert.assertNotNull(namespaceDef);
|
||||
|
||||
Iterator<AtlasStructDef.AtlasAttributeDef> it = namespaceDef.getAttributeDefs().iterator();
|
||||
AtlasStructDef.AtlasAttributeDef namespaceAttributeDef = it.next();
|
||||
AtlasStructDef.AtlasAttributeDef namespaceAttributeDef2 = it.next();
|
||||
|
||||
namespaceAttributeDef.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton("hive_table")));
|
||||
|
||||
namespaceDef.setAttributeDefs(Arrays.asList(namespaceAttributeDef, namespaceAttributeDef2));
|
||||
|
||||
AtlasTypesDef existingTypeDefs = typesDefs;
|
||||
|
||||
try {
|
||||
typesDefs.setNamespaceDefs(Arrays.asList(namespaceDef));
|
||||
typeDefStore.updateTypesDef(typesDefs);
|
||||
} catch (AtlasBaseException e) {
|
||||
Assert.assertEquals(e.getAtlasErrorCode(), AtlasErrorCode.APPLICABLE_ENTITY_TYPES_DELETION_NOT_SUPPORTED);
|
||||
} finally {
|
||||
typesDefs = existingTypeDefs;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateNsAttrDefAddApplicableEntityTypes() throws AtlasBaseException {
|
||||
createNamespaceTypes(namespaceName);
|
||||
|
||||
AtlasNamespaceDef namespaceDef = findNamespaceDef(namespaceName);
|
||||
AtlasStructDef.AtlasAttributeDef namespaceAttributeDef1 = namespaceDef.getAttributeDefs().get(0);
|
||||
AtlasStructDef.AtlasAttributeDef namespaceAttributeDef2 = namespaceDef.getAttributeDefs().get(1);
|
||||
Set<String> applicableEntityTypes = AtlasType.fromJson(namespaceAttributeDef1.getOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES), Set.class);
|
||||
|
||||
if (applicableEntityTypes == null) {
|
||||
applicableEntityTypes = new HashSet<>();
|
||||
}
|
||||
|
||||
applicableEntityTypes.add("hive_column");
|
||||
namespaceAttributeDef1.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(applicableEntityTypes));
|
||||
namespaceDef.setAttributeDefs(Arrays.asList(namespaceAttributeDef1, namespaceAttributeDef2));
|
||||
|
||||
updateNamespaceTypeDefs(namespaceDef);
|
||||
|
||||
typeDefStore.updateTypesDef(typesDefs);
|
||||
|
||||
namespaceDef = findNamespaceDef(namespaceName);
|
||||
namespaceAttributeDef1 = namespaceDef.getAttributeDefs().get(0);
|
||||
|
||||
applicableEntityTypes = AtlasType.fromJson(namespaceAttributeDef1.getOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES), Set.class);
|
||||
|
||||
Assert.assertEquals(applicableEntityTypes == null ? 0 : applicableEntityTypes.size(), 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateMaxStringLengthForStringTypes() throws AtlasBaseException {
|
||||
AtlasTypesDef existingTypeDefs = typesDefs;
|
||||
AtlasNamespaceDef namespaceDef1 = new AtlasNamespaceDef(namespaceName, "test_description", null);
|
||||
addNamespaceAttribute(namespaceDef1, "test_namespace_attribute1", new HashSet<>(Arrays.asList("hive_table", "fs_path")), "string",
|
||||
AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
|
||||
typesDefs.setNamespaceDefs(Arrays.asList(namespaceDef1));
|
||||
try {
|
||||
typeDefStore.createTypesDef(typesDefs);
|
||||
} catch (AtlasBaseException exception) {
|
||||
Assert.assertEquals(exception.getAtlasErrorCode(), AtlasErrorCode.MISSING_MANDATORY_ATTRIBUTE);
|
||||
} finally {
|
||||
typesDefs = existingTypeDefs;
|
||||
}
|
||||
}
|
||||
|
||||
private AtlasNamespaceDef createNamespaceDef(String namespaceName) {
|
||||
AtlasNamespaceDef namespaceDef1 = new AtlasNamespaceDef(namespaceName, "test_description", null);
|
||||
addNamespaceAttribute(namespaceDef1, "test_namespace_attribute1", new HashSet<>(Arrays.asList("hive_table", "fs_path")), "int",
|
||||
AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
|
||||
addNamespaceAttribute(namespaceDef1, "test_namespace_attribute2", Collections.singleton("hive_table"), "int",
|
||||
AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
|
||||
return namespaceDef1;
|
||||
}
|
||||
|
||||
private AtlasNamespaceDef createNamespaceDef2(String namespaceName) {
|
||||
AtlasNamespaceDef namespaceDef1 = new AtlasNamespaceDef(namespaceName, "test_description", null);
|
||||
addNamespaceAttribute(namespaceDef1, "test_namespace_attribute1", Collections.emptySet(), "int",
|
||||
AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
|
||||
addNamespaceAttribute(namespaceDef1, "test_namespace_attribute2", Collections.singleton("hive_table"), "int",
|
||||
AtlasStructDef.AtlasAttributeDef.Cardinality.SINGLE);
|
||||
return namespaceDef1;
|
||||
}
|
||||
|
||||
private void createNamespaceTypes(String namespaceName) throws AtlasBaseException {
|
||||
List<AtlasNamespaceDef> namespaceDefs = new ArrayList(typesDefs.getNamespaceDefs());
|
||||
namespaceDefs.add(createNamespaceDef(namespaceName));
|
||||
typesDefs.setNamespaceDefs(namespaceDefs);
|
||||
typeDefStore.createTypesDef(typesDefs);
|
||||
}
|
||||
|
||||
private void addNamespaceAttribute(AtlasNamespaceDef namespaceDef, String name, Set<String> applicableEntityTypes,
|
||||
String typeName, AtlasStructDef.AtlasAttributeDef.Cardinality cardinality) {
|
||||
AtlasStructDef.AtlasAttributeDef attributeDef = new AtlasStructDef.AtlasAttributeDef(name, typeName);
|
||||
|
||||
attributeDef.setCardinality(cardinality);
|
||||
attributeDef.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(applicableEntityTypes));
|
||||
attributeDef.setIsOptional(true);
|
||||
attributeDef.setIsUnique(false);
|
||||
|
||||
namespaceDef.addAttribute(attributeDef);
|
||||
}
|
||||
|
||||
private AtlasNamespaceDef findNamespaceDef(String namespaceName) {
|
||||
for (AtlasNamespaceDef atlasNamespaceDef : typesDefs.getNamespaceDefs()) {
|
||||
if (atlasNamespaceDef.getName().equals(namespaceName)) {
|
||||
return atlasNamespaceDef;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateNamespaceTypeDefs(AtlasNamespaceDef atlasNamespaceDef) {
|
||||
for (int i = 0; i < typesDefs.getNamespaceDefs().size(); i++) {
|
||||
if (typesDefs.getNamespaceDefs().get(i).getName().equals(namespaceName)) {
|
||||
typesDefs.getNamespaceDefs().set(i, atlasNamespaceDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -37,13 +37,13 @@ import org.apache.atlas.model.instance.EntityMutations.EntityOperation;
|
|||
import org.apache.atlas.model.lineage.AtlasLineageInfo;
|
||||
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageDirection;
|
||||
import org.apache.atlas.model.lineage.AtlasLineageInfo.LineageRelation;
|
||||
import org.apache.atlas.model.typedef.AtlasBusinessMetadataDef;
|
||||
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.model.typedef.AtlasRelationshipDef.PropagateTags;
|
||||
import org.apache.atlas.type.AtlasType;
|
||||
import org.apache.atlas.type.AtlasTypeUtil;
|
||||
import org.apache.atlas.utils.AuthenticationUtil;
|
||||
|
|
@ -56,7 +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.AtlasBusinessMetadataDef.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;
|
||||
|
|
@ -318,25 +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);
|
||||
|
||||
// Namespace definitions
|
||||
AtlasAttributeDef nsAttrDef1 = new AtlasAttributeDef("attr1", "int");
|
||||
AtlasAttributeDef nsAttrDef2 = new AtlasAttributeDef("attr2", "int");
|
||||
// BusinessMetadata definitions
|
||||
AtlasAttributeDef bmAttrDef1 = new AtlasAttributeDef("attr1", "int");
|
||||
AtlasAttributeDef bmAttrDef2 = new AtlasAttributeDef("attr2", "int");
|
||||
|
||||
nsAttrDef1.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton(TABLE_TYPE)));
|
||||
nsAttrDef1.setIsOptional(true);
|
||||
nsAttrDef1.setIsUnique(false);
|
||||
bmAttrDef1.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton(TABLE_TYPE)));
|
||||
bmAttrDef1.setIsOptional(true);
|
||||
bmAttrDef1.setIsUnique(false);
|
||||
|
||||
nsAttrDef2.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton(TABLE_TYPE)));
|
||||
nsAttrDef2.setIsOptional(true);
|
||||
nsAttrDef2.setIsUnique(false);
|
||||
bmAttrDef2.setOption(ATTR_OPTION_APPLICABLE_ENTITY_TYPES, AtlasType.toJson(Collections.singleton(TABLE_TYPE)));
|
||||
bmAttrDef2.setIsOptional(true);
|
||||
bmAttrDef2.setIsUnique(false);
|
||||
|
||||
AtlasNamespaceDef testNamespaceDef = new AtlasNamespaceDef("test_namespace", "test_description", VERSION_1);
|
||||
AtlasBusinessMetadataDef testBusinessMetadataDef = new AtlasBusinessMetadataDef("test_businessMetadata", "test_description", VERSION_1);
|
||||
|
||||
testNamespaceDef.setAttributeDefs(Arrays.asList(nsAttrDef1, nsAttrDef2));
|
||||
testBusinessMetadataDef.setAttributeDefs(Arrays.asList(bmAttrDef1, bmAttrDef2));
|
||||
|
||||
List<AtlasNamespaceDef> namespaceDefs = asList(testNamespaceDef);
|
||||
List<AtlasBusinessMetadataDef> businessMetadataDefs = asList(testBusinessMetadataDef);
|
||||
|
||||
return new AtlasTypesDef(Collections.emptyList(), Collections.emptyList(), classificationDefs, entityDefs, relationshipDefs, namespaceDefs);
|
||||
return new AtlasTypesDef(Collections.emptyList(), Collections.emptyList(), classificationDefs, entityDefs, relationshipDefs, businessMetadataDefs);
|
||||
}
|
||||
|
||||
void createEntities() throws Exception {
|
||||
|
|
|
|||
|
|
@ -857,72 +857,72 @@ public class EntityREST {
|
|||
}
|
||||
|
||||
@POST
|
||||
@Path("/guid/{guid}/namespaces")
|
||||
@Path("/guid/{guid}/businessmetata")
|
||||
@Produces(Servlets.JSON_MEDIA_TYPE)
|
||||
@Consumes(Servlets.JSON_MEDIA_TYPE)
|
||||
public void addOrUpdateNamespaceAttributes(@PathParam("guid") final String guid, @QueryParam("isOverwrite") @DefaultValue("false") boolean isOverwrite, Map<String, Map<String, Object>> entityNamespaces) throws AtlasBaseException {
|
||||
public void addOrUpdateBusinessAttributes(@PathParam("guid") final String guid, @QueryParam("isOverwrite") @DefaultValue("false") boolean isOverwrite, Map<String, Map<String, Object>> businessAttributes) throws AtlasBaseException {
|
||||
AtlasPerfTracer perf = null;
|
||||
|
||||
try {
|
||||
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
|
||||
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.addOrUpdateNamespaceAttributes(" + guid + ", isOverwrite=" + isOverwrite + ")");
|
||||
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.addOrUpdateBusinessAttributes(" + guid + ", isOverwrite=" + isOverwrite + ")");
|
||||
}
|
||||
|
||||
entitiesStore.addOrUpdateNamespaceAttributes(guid, entityNamespaces, isOverwrite);
|
||||
entitiesStore.addOrUpdateBusinessAttributes(guid, businessAttributes, isOverwrite);
|
||||
} finally {
|
||||
AtlasPerfTracer.log(perf);
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/guid/{guid}/namespaces")
|
||||
@Path("/guid/{guid}/businessmetata")
|
||||
@Produces(Servlets.JSON_MEDIA_TYPE)
|
||||
@Consumes(Servlets.JSON_MEDIA_TYPE)
|
||||
public void removeNamespaceAttributes(@PathParam("guid") final String guid, Map<String, Map<String, Object>> entityNamespaces) throws AtlasBaseException {
|
||||
public void removeBusinessAttributes(@PathParam("guid") final String guid, Map<String, Map<String, Object>> businessAttributes) throws AtlasBaseException {
|
||||
AtlasPerfTracer perf = null;
|
||||
|
||||
try {
|
||||
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
|
||||
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.removeNamespaceAttributes(" + guid + ")");
|
||||
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.removeBusinessAttributes(" + guid + ")");
|
||||
}
|
||||
|
||||
entitiesStore.removeNamespaceAttributes(guid, entityNamespaces);
|
||||
entitiesStore.removeBusinessAttributes(guid, businessAttributes);
|
||||
} finally {
|
||||
AtlasPerfTracer.log(perf);
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/guid/{guid}/namespace/{namespace}")
|
||||
@Path("/guid/{guid}/businessmetata/{bmName}")
|
||||
@Produces(Servlets.JSON_MEDIA_TYPE)
|
||||
@Consumes(Servlets.JSON_MEDIA_TYPE)
|
||||
public void addOrUpdateNamespaceAttributes(@PathParam("guid") final String guid, @PathParam("namespace") final String namespace, Map<String, Object> entityNsAttributes) throws AtlasBaseException {
|
||||
public void addOrUpdateBusinessAttributes(@PathParam("guid") final String guid, @PathParam("bmName") final String bmName, Map<String, Object> businessAttributes) throws AtlasBaseException {
|
||||
AtlasPerfTracer perf = null;
|
||||
|
||||
try {
|
||||
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
|
||||
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.addOrUpdateNamespaceAttributes(" + guid + ", " + namespace + ")");
|
||||
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.addOrUpdateBusinessAttributes(" + guid + ", " + bmName + ")");
|
||||
}
|
||||
|
||||
entitiesStore.addOrUpdateNamespaceAttributes(guid, Collections.singletonMap(namespace, entityNsAttributes), false);
|
||||
entitiesStore.addOrUpdateBusinessAttributes(guid, Collections.singletonMap(bmName, businessAttributes), false);
|
||||
} finally {
|
||||
AtlasPerfTracer.log(perf);
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/guid/{guid}/namespace/{namespace}")
|
||||
@Path("/guid/{guid}/businessmetata/{bmName}")
|
||||
@Produces(Servlets.JSON_MEDIA_TYPE)
|
||||
@Consumes(Servlets.JSON_MEDIA_TYPE)
|
||||
public void removeNamespaceAttributes(@PathParam("guid") final String guid, @PathParam("namespace") final String namespace, Map<String, Object> entityNsAttributes) throws AtlasBaseException {
|
||||
public void removeBusinessAttributes(@PathParam("guid") final String guid, @PathParam("bmName") final String bmName, Map<String, Object> businessAttributes) throws AtlasBaseException {
|
||||
AtlasPerfTracer perf = null;
|
||||
|
||||
try {
|
||||
if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
|
||||
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.removeNamespaceAttributes(" + guid + ", " + namespace + ")");
|
||||
perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "EntityREST.removeBusinessAttributes(" + guid + ", " + bmName + ")");
|
||||
}
|
||||
|
||||
entitiesStore.removeNamespaceAttributes(guid, Collections.singletonMap(namespace, entityNsAttributes));
|
||||
entitiesStore.removeBusinessAttributes(guid, Collections.singletonMap(bmName, businessAttributes));
|
||||
} finally {
|
||||
AtlasPerfTracer.log(perf);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ package org.apache.atlas.web.rest;
|
|||
import org.apache.atlas.exception.AtlasBaseException;
|
||||
import org.apache.atlas.model.SearchFilter;
|
||||
import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
|
||||
import org.apache.atlas.model.typedef.AtlasBusinessMetadataDef;
|
||||
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;
|
||||
|
|
@ -320,37 +320,37 @@ public class TypesREST {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get the namespace definition for the given guid
|
||||
* @param guid namespace guid
|
||||
* @return namespace definition
|
||||
* Get the businessMetadata definition for the given guid
|
||||
* @param guid businessMetadata guid
|
||||
* @return businessMetadata definition
|
||||
* @throws AtlasBaseException
|
||||
* @HTTP 200 On successful lookup of the the namespace definition by it's guid
|
||||
* @HTTP 200 On successful lookup of the the businessMetadata 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 {
|
||||
@Path("/businessmetadatadef/guid/{guid}")
|
||||
public AtlasBusinessMetadataDef getBusinessMetadataDefByGuid(@PathParam("guid") String guid) throws AtlasBaseException {
|
||||
Servlets.validateQueryParamLength("guid", guid);
|
||||
|
||||
AtlasNamespaceDef ret = typeDefStore.getNamespaceDefByGuid(guid);
|
||||
AtlasBusinessMetadataDef ret = typeDefStore.getBusinessMetadataDefByGuid(guid);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the namespace definition by it's name (unique)
|
||||
* @param name namespace name
|
||||
* @return namespace definition
|
||||
* Get the businessMetadata definition by it's name (unique)
|
||||
* @param name businessMetadata name
|
||||
* @return businessMetadata definition
|
||||
* @throws AtlasBaseException
|
||||
* @HTTP 200 On successful lookup of the the namespace definition by it's name
|
||||
* @HTTP 200 On successful lookup of the the businessMetadata 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 {
|
||||
@Path("/businessmetadatadef/name/{name}")
|
||||
public AtlasBusinessMetadataDef getBusinessMetadataDefByName(@PathParam("name") String name) throws AtlasBaseException {
|
||||
Servlets.validateQueryParamLength("name", name);
|
||||
|
||||
AtlasNamespaceDef ret = typeDefStore.getNamespaceDefByName(name);
|
||||
AtlasBusinessMetadataDef ret = typeDefStore.getBusinessMetadataDefByName(name);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue