http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/6b9399e0/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java index 17b7e17..aefd168 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasTypeDefGraphStore.java @@ -26,24 +26,13 @@ import org.apache.atlas.listener.ActiveStateChangeHandler; import org.apache.atlas.listener.ChangedTypeDefs; import org.apache.atlas.listener.TypeDefChangeListener; import org.apache.atlas.model.SearchFilter; -import org.apache.atlas.model.typedef.AtlasBaseTypeDef; -import org.apache.atlas.model.typedef.AtlasClassificationDef; -import org.apache.atlas.model.typedef.AtlasEntityDef; -import org.apache.atlas.model.typedef.AtlasEnumDef; -import org.apache.atlas.model.typedef.AtlasStructDef; +import org.apache.atlas.model.typedef.*; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef; -import org.apache.atlas.model.typedef.AtlasTypesDef; import org.apache.atlas.repository.util.FilterUtil; import org.apache.atlas.store.AtlasTypeDefStore; -import org.apache.atlas.type.AtlasClassificationType; -import org.apache.atlas.type.AtlasEntityType; -import org.apache.atlas.type.AtlasEnumType; -import org.apache.atlas.type.AtlasStructType; -import org.apache.atlas.type.AtlasType; -import org.apache.atlas.type.AtlasTypeRegistry; +import org.apache.atlas.type.*; import org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry; -import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.util.AtlasRepositoryConfiguration; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; @@ -83,6 +72,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ protected abstract AtlasEntityDefStore getEntityDefStore(AtlasTypeRegistry typeRegistry); + protected abstract AtlasRelationshipDefStore getRelationshipDefStore(AtlasTypeRegistry typeRegistry); + @Override public void init() throws AtlasBaseException { AtlasTransientTypeRegistry ttr = null; @@ -96,7 +87,8 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ AtlasTypesDef typesDef = new AtlasTypesDef(getEnumDefStore(ttr).getAll(), getStructDefStore(ttr).getAll(), getClassificationDefStore(ttr).getAll(), - getEntityDefStore(ttr).getAll()); + getEntityDefStore(ttr).getAll(), + getRelationshipDefStore(ttr).getAll()); rectifyTypeErrorsIfAny(typesDef); @@ -167,6 +159,27 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ return ret; } + @Override + public AtlasRelationshipDef getRelationshipDefByName(String name) throws AtlasBaseException { + AtlasRelationshipDef ret = typeRegistry.getRelationshipDefByName(name); + + if (ret == null) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); + } + + return ret; + } + + @Override + public AtlasRelationshipDef getRelationshipDefByGuid(String guid) throws AtlasBaseException { + AtlasRelationshipDef ret = typeRegistry.getRelationshipDefByGuid(guid); + + if (ret == null) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); + } + + return ret; + } @Override @GraphTransaction @@ -268,21 +281,36 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ @GraphTransaction public AtlasEntityDef updateEntityDefByGuid(String guid, AtlasEntityDef entityDef) throws AtlasBaseException { AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); - tryUpdateByGUID(guid, entityDef, ttr); - return getEntityDefStore(ttr).updateByGuid(guid, entityDef); } @Override @GraphTransaction + public AtlasRelationshipDef updateRelationshipDefByName(String name, AtlasRelationshipDef relationshipDef) throws AtlasBaseException { + AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); + tryUpdateByName(name, relationshipDef, ttr); + return getRelationshipDefStore(ttr).updateByName(name, relationshipDef); + } + + @Override + @GraphTransaction + public AtlasRelationshipDef updateRelationshipDefByGuid(String guid, AtlasRelationshipDef relationshipDef) throws AtlasBaseException { + AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); + tryUpdateByGUID(guid, relationshipDef, ttr); + return getRelationshipDefStore(ttr).updateByGuid(guid, relationshipDef); + } + + @Override + @GraphTransaction public AtlasTypesDef createTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { - LOG.debug("==> AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classifications={}, entities={})", + LOG.debug("==> AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classifications={}, entities={}, relationships={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), - CollectionUtils.size(typesDef.getEntityDefs())); + CollectionUtils.size(typesDef.getEntityDefs()), + CollectionUtils.size(typesDef.getRelationshipDefs())); } AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); @@ -292,11 +320,12 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ AtlasTypesDef ret = addToGraphStore(typesDef, ttr); if (LOG.isDebugEnabled()) { - LOG.debug("<== AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classfications={}, entities={})", + LOG.debug("<== AtlasTypeDefGraphStore.createTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), - CollectionUtils.size(typesDef.getEntityDefs())); + CollectionUtils.size(typesDef.getEntityDefs()), + CollectionUtils.size(typesDef.getRelationshipDefs())); } return ret; @@ -359,11 +388,12 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ @GraphTransaction public AtlasTypesDef updateTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { - LOG.debug("==> AtlasTypeDefGraphStore.updateTypesDef(enums={}, structs={}, classfications={}, entities={})", + LOG.debug("==> AtlasTypeDefGraphStore.updateTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships{})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), - CollectionUtils.size(typesDef.getEntityDefs())); + CollectionUtils.size(typesDef.getEntityDefs()), + CollectionUtils.size(typesDef.getRelationshipDefs())); } AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); @@ -397,11 +427,12 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ @GraphTransaction public void deleteTypesDef(AtlasTypesDef typesDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { - LOG.debug("==> AtlasTypeDefGraphStore.deleteTypesDef(enums={}, structs={}, classfications={}, entities={})", + LOG.debug("==> AtlasTypeDefGraphStore.deleteTypesDef(enums={}, structs={}, classfications={}, entities={}, relationships={})", CollectionUtils.size(typesDef.getEnumDefs()), CollectionUtils.size(typesDef.getStructDefs()), CollectionUtils.size(typesDef.getClassificationDefs()), - CollectionUtils.size(typesDef.getEntityDefs())); + CollectionUtils.size(typesDef.getEntityDefs()), + CollectionUtils.size(typesDef.getRelationshipDefs())); } AtlasTransientTypeRegistry ttr = lockTypeRegistryAndReleasePostCommit(); @@ -410,11 +441,25 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ AtlasStructDefStore structDefStore = getStructDefStore(ttr); AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr); AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr); + AtlasRelationshipDefStore relationshipDefStore = getRelationshipDefStore(ttr); List<Object> preDeleteStructDefs = new ArrayList<>(); List<Object> preDeleteClassifiDefs = new ArrayList<>(); List<Object> preDeleteEntityDefs = new ArrayList<>(); + List<Object> preDeleteRelationshipDefs = new ArrayList<>(); + // pre deletes + + // do the relationships first. + if (CollectionUtils.isNotEmpty(typesDef.getRelationshipDefs())) { + for (AtlasRelationshipDef relationshipDef : typesDef.getRelationshipDefs()) { + if (StringUtils.isNotBlank(relationshipDef.getGuid())) { + preDeleteRelationshipDefs.add(relationshipDefStore.preDeleteByGuid(relationshipDef.getGuid())); + } else { + preDeleteRelationshipDefs.add(relationshipDefStore.preDeleteByName(relationshipDef.getName())); + } + } + } if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) { for (AtlasStructDef structDef : typesDef.getStructDefs()) { if (StringUtils.isNotBlank(structDef.getGuid())) { @@ -445,6 +490,21 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ } } + // run the actual deletes + + // run the relationshipDef delete first - in case there is a enumDef or entityDef dependancy that is going to be deleted. + if (CollectionUtils.isNotEmpty(typesDef.getRelationshipDefs())) { + int i = 0; + for (AtlasRelationshipDef relationshipDef : typesDef.getRelationshipDefs()) { + if (StringUtils.isNotBlank(relationshipDef.getGuid())) { + relationshipDefStore.deleteByGuid(relationshipDef.getGuid(), preDeleteRelationshipDefs.get(i)); + } else { + relationshipDefStore.deleteByName(relationshipDef.getName(), preDeleteRelationshipDefs.get(i)); + } + i++; + } + } + if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) { int i = 0; for (AtlasStructDef structDef : typesDef.getStructDefs()) { @@ -532,6 +592,12 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ } } + for(AtlasRelationshipType relationshipType : typeRegistry.getAllRelationshipTypes()) { + if (searchPredicates.evaluate(relationshipType)) { + typesDef.getRelationshipDefs().add(relationshipType.getRelationshipDef()); + } + } + return typesDef; } @@ -691,11 +757,14 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ AtlasStructDefStore structDefStore = getStructDefStore(ttr); AtlasClassificationDefStore classifiDefStore = getClassificationDefStore(ttr); AtlasEntityDefStore entityDefStore = getEntityDefStore(ttr); + AtlasRelationshipDefStore relationshipDefStore = getRelationshipDefStore(ttr); List<Object> preCreateStructDefs = new ArrayList<>(); List<Object> preCreateClassifiDefs = new ArrayList<>(); List<Object> preCreateEntityDefs = new ArrayList<>(); + List<Object> preCreateRelationshipDefs = new ArrayList<>(); + // for enumerations run the create if (CollectionUtils.isNotEmpty(typesDef.getEnumDefs())) { for (AtlasEnumDef enumDef : typesDef.getEnumDefs()) { AtlasEnumDef createdDef = enumDefStore.create(enumDef); @@ -705,6 +774,7 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ ret.getEnumDefs().add(createdDef); } } + // run the preCreates if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) { for (AtlasStructDef structDef : typesDef.getStructDefs()) { @@ -724,6 +794,12 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ } } + if (CollectionUtils.isNotEmpty(typesDef.getRelationshipDefs())) { + for (AtlasRelationshipDef relationshipDef : typesDef.getRelationshipDefs()) { + preCreateRelationshipDefs.add(relationshipDefStore.preCreate(relationshipDef)); + } + } + if (CollectionUtils.isNotEmpty(typesDef.getStructDefs())) { int i = 0; for (AtlasStructDef structDef : typesDef.getStructDefs()) { @@ -759,6 +835,17 @@ public abstract class AtlasTypeDefGraphStore implements AtlasTypeDefStore, Activ i++; } } + if (CollectionUtils.isNotEmpty(typesDef.getRelationshipDefs())) { + int i = 0; + for (AtlasRelationshipDef relationshipDef : typesDef.getRelationshipDefs()) { + AtlasRelationshipDef createdDef = relationshipDefStore.create(relationshipDef, preCreateRelationshipDefs.get(i)); + + ttr.updateGuid(createdDef.getName(), createdDef.getGuid()); + + ret.getRelationshipDefs().add(createdDef); + i++; + } + } return ret; }
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/6b9399e0/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipDefStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipDefStoreV1.java new file mode 100644 index 0000000..96cd8d1 --- /dev/null +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasRelationshipDefStoreV1.java @@ -0,0 +1,409 @@ +/** + * 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.v1; + +import org.apache.atlas.AtlasErrorCode; +import org.apache.atlas.exception.AtlasBaseException; +import org.apache.atlas.model.typedef.AtlasRelationshipDef; +import org.apache.atlas.model.typedef.AtlasRelationshipDef.RelationshipCategory; +import org.apache.atlas.model.typedef.AtlasRelationshipDef.PropagateTags; +import org.apache.atlas.model.typedef.AtlasRelationshipEndPointDef; +import org.apache.atlas.repository.Constants; +import org.apache.atlas.repository.graphdb.AtlasVertex; +import org.apache.atlas.repository.store.graph.AtlasRelationshipDefStore; +import org.apache.atlas.type.AtlasRelationshipType; +import org.apache.atlas.type.AtlasType; +import org.apache.atlas.type.AtlasTypeRegistry; +import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; +import org.apache.commons.lang.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * RelationshipDef store in v1 format. + */ +public class AtlasRelationshipDefStoreV1 extends AtlasAbstractDefStoreV1 implements AtlasRelationshipDefStore { + private static final Logger LOG = LoggerFactory.getLogger(AtlasRelationshipDefStoreV1.class); + + public AtlasRelationshipDefStoreV1(AtlasTypeDefGraphStoreV1 typeDefStore, AtlasTypeRegistry typeRegistry) { + super(typeDefStore, typeRegistry); + } + + @Override + public AtlasVertex preCreate(AtlasRelationshipDef relationshipDef) throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> AtlasRelationshipDefStoreV1.preCreate({})", relationshipDef); + } + + validateType(relationshipDef); + + AtlasType type = typeRegistry.getType(relationshipDef.getName()); + + if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name()); + } + + AtlasVertex ret = typeDefStore.findTypeVertexByName(relationshipDef.getName()); + + if (ret != null) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_ALREADY_EXISTS, relationshipDef.getName()); + } + + ret = typeDefStore.createTypeVertex(relationshipDef); + + updateVertexPreCreate(relationshipDef, (AtlasRelationshipType) type, ret); + + if (LOG.isDebugEnabled()) { + LOG.debug("<== AtlasRelationshipDefStoreV1.preCreate({}): {}", relationshipDef, ret); + } + + return ret; + } + + @Override + public AtlasRelationshipDef create(AtlasRelationshipDef relationshipDef, Object preCreateResult) + throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> AtlasRelationshipDefStoreV1.create({}, {})", relationshipDef, preCreateResult); + } + + AtlasVertex vertex; + + if (preCreateResult == null || !(preCreateResult instanceof AtlasVertex)) { + vertex = preCreate(relationshipDef); + } else { + vertex = (AtlasVertex) preCreateResult; + } + + AtlasRelationshipDef ret = toRelationshipDef(vertex); + + if (LOG.isDebugEnabled()) { + LOG.debug("<== AtlasRelationshipDefStoreV1.create({}, {}): {}", relationshipDef, preCreateResult, ret); + } + + return ret; + } + + @Override + public List<AtlasRelationshipDef> getAll() throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> AtlasRelationshipDefStoreV1.getAll()"); + } + + List<AtlasRelationshipDef> ret = new ArrayList<>(); + Iterator<AtlasVertex> vertices = typeDefStore.findTypeVerticesByCategory(TypeCategory.RELATIONSHIP); + + while (vertices.hasNext()) { + ret.add(toRelationshipDef(vertices.next())); + } + + if (LOG.isDebugEnabled()) { + LOG.debug("<== AtlasRelationshipDefStoreV1.getAll(): count={}", ret.size()); + } + + return ret; + } + + @Override + public AtlasRelationshipDef getByName(String name) throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> AtlasRelationshipDefStoreV1.getByName({})", name); + } + + AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.RELATIONSHIP); + + if (vertex == null) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); + } + + vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, TypeCategory.class); + + AtlasRelationshipDef ret = toRelationshipDef(vertex); + + if (LOG.isDebugEnabled()) { + LOG.debug("<== AtlasRelationshipDefStoreV1.getByName({}): {}", name, ret); + } + + return ret; + } + + @Override + public AtlasRelationshipDef getByGuid(String guid) throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> AtlasRelationshipDefStoreV1.getByGuid({})", guid); + } + + AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP); + + if (vertex == null) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); + } + + AtlasRelationshipDef ret = toRelationshipDef(vertex); + + if (LOG.isDebugEnabled()) { + LOG.debug("<== AtlasRelationshipDefStoreV1.getByGuid({}): {}", guid, ret); + } + + return ret; + } + + @Override + public AtlasRelationshipDef update(AtlasRelationshipDef relationshipDef) throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> AtlasRelationshipDefStoreV1.update({})", relationshipDef); + } + + validateType(relationshipDef); + + AtlasRelationshipDef ret = StringUtils.isNotBlank(relationshipDef.getGuid()) + ? updateByGuid(relationshipDef.getGuid(), relationshipDef) + : updateByName(relationshipDef.getName(), relationshipDef); + + if (LOG.isDebugEnabled()) { + LOG.debug("<== AtlasRelationshipDefStoreV1.update({}): {}", relationshipDef, ret); + } + + return ret; + } + + @Override + public AtlasRelationshipDef updateByName(String name, AtlasRelationshipDef relationshipDef) + throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> AtlasRelationshipDefStoreV1.updateByName({}, {})", name, relationshipDef); + } + + validateType(relationshipDef); + + AtlasType type = typeRegistry.getType(relationshipDef.getName()); + + if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name()); + } + + AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.RELATIONSHIP); + + if (vertex == null) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); + } + + updateVertexPreUpdate(relationshipDef, (AtlasRelationshipType) type, vertex); + + AtlasRelationshipDef ret = toRelationshipDef(vertex); + + if (LOG.isDebugEnabled()) { + LOG.debug("<== AtlasRelationshipDefStoreV1.updateByName({}, {}): {}", name, relationshipDef, ret); + } + + return ret; + } + + @Override + public AtlasRelationshipDef updateByGuid(String guid, AtlasRelationshipDef relationshipDef) + throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> AtlasRelationshipDefStoreV1.updateByGuid({})", guid); + } + + validateType(relationshipDef); + + AtlasType type = typeRegistry.getTypeByGuid(guid); + + if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name()); + } + + AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP); + + if (vertex == null) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); + } + + updateVertexPreUpdate(relationshipDef, (AtlasRelationshipType) type, vertex); + // TODO delete / create edges to entitytypes + AtlasRelationshipDef ret = toRelationshipDef(vertex); + + if (LOG.isDebugEnabled()) { + LOG.debug("<== AtlasRelationshipDefStoreV1.updateByGuid({}): {}", guid, ret); + } + + return ret; + } + + @Override + public AtlasVertex preDeleteByName(String name) throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> AtlasRelationshipDefStoreV1.preDeleteByName({})", name); + } + + AtlasVertex ret = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.RELATIONSHIP); + + if (ret == null) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); + } + + if (AtlasGraphUtilsV1.typeHasInstanceVertex(name)) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, name); + } + + // TODO delete the edges to the other types + + if (LOG.isDebugEnabled()) { + LOG.debug("<== AtlasRelationshipDefStoreV1.preDeleteByName({}): {}", name, ret); + } + + return ret; + } + + @Override + public void deleteByName(String name, Object preDeleteResult) throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> AtlasRelationshipDefStoreV1.deleteByName({}, {})", name, preDeleteResult); + } + + AtlasVertex vertex; + + if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) { + vertex = preDeleteByName(name); + } else { + vertex = (AtlasVertex) preDeleteResult; + } + + typeDefStore.deleteTypeVertex(vertex); + + if (LOG.isDebugEnabled()) { + LOG.debug("<== AtlasRelationshipDefStoreV1.deleteByName({}, {})", name, preDeleteResult); + } + } + + @Override + public AtlasVertex preDeleteByGuid(String guid) throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> AtlasRelationshipDefStoreV1.preDeleteByGuid({})", guid); + } + + AtlasVertex ret = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP); + + if (ret == null) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); + } + + String typeName = AtlasGraphUtilsV1.getProperty(ret, Constants.TYPENAME_PROPERTY_KEY, String.class); + + if (AtlasGraphUtilsV1.typeHasInstanceVertex(typeName)) { + throw new AtlasBaseException(AtlasErrorCode.TYPE_HAS_REFERENCES, typeName); + } + + // TODO delete the edges to the other types + + if (LOG.isDebugEnabled()) { + LOG.debug("<== AtlasRelationshipDefStoreV1.preDeleteByGuid({}): {}", guid, ret); + } + + return ret; + } + + @Override + public void deleteByGuid(String guid, Object preDeleteResult) throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> AtlasRelationshipDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult); + } + + AtlasVertex vertex; + + if (preDeleteResult == null || !(preDeleteResult instanceof AtlasVertex)) { + vertex = preDeleteByGuid(guid); + } else { + vertex = (AtlasVertex) preDeleteResult; + } + + typeDefStore.deleteTypeVertex(vertex); + + if (LOG.isDebugEnabled()) { + LOG.debug("<== AtlasRelationshipDefStoreV1.deleteByGuid({}, {})", guid, preDeleteResult); + } + } + + private void updateVertexPreCreate(AtlasRelationshipDef relationshipDef, AtlasRelationshipType relationshipType, + AtlasVertex vertex) throws AtlasBaseException { + AtlasStructDefStoreV1.updateVertexPreCreate(relationshipDef, relationshipType, vertex, typeDefStore); + // Update endpoints + vertex.setProperty(Constants.RELATIONSHIPTYPE_ENDPOINT1_KEY, AtlasType.toJson(relationshipDef.getEndPointDef1())); + vertex.setProperty(Constants.RELATIONSHIPTYPE_ENDPOINT2_KEY, AtlasType.toJson(relationshipDef.getEndPointDef2())); + // Update RelationshipCategory + vertex.setProperty(Constants.RELATIONSHIPTYPE_CATEGORY_KEY, relationshipDef.getRelationshipCategory().name()); + vertex.setProperty(Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, relationshipDef.getPropagateTags().name()); + } + + private void updateVertexPreUpdate(AtlasRelationshipDef relationshipDef, AtlasRelationshipType relationshipType, + AtlasVertex vertex) throws AtlasBaseException { + AtlasStructDefStoreV1.updateVertexPreUpdate(relationshipDef, relationshipType, vertex, typeDefStore); + vertex.setProperty(Constants.RELATIONSHIPTYPE_ENDPOINT1_KEY, AtlasType.toJson(relationshipDef.getEndPointDef1())); + vertex.setProperty(Constants.RELATIONSHIPTYPE_ENDPOINT2_KEY, AtlasType.toJson(relationshipDef.getEndPointDef2())); + // Update RelationshipCategory + vertex.setProperty(Constants.RELATIONSHIPTYPE_CATEGORY_KEY, relationshipDef.getRelationshipCategory().name()); + vertex.setProperty(Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, relationshipDef.getPropagateTags().name()); + } + + private AtlasRelationshipDef toRelationshipDef(AtlasVertex vertex) throws AtlasBaseException { + AtlasRelationshipDef ret = null; + + if (vertex != null && typeDefStore.isTypeVertex(vertex, TypeCategory.RELATIONSHIP)) { + String name = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class); + String description = vertex.getProperty(Constants.TYPEDESCRIPTION_PROPERTY_KEY, String.class); + String version = vertex.getProperty(Constants.TYPEVERSION_PROPERTY_KEY, String.class); + String endPoint1Str = vertex.getProperty(Constants.RELATIONSHIPTYPE_ENDPOINT1_KEY, String.class); + String endPoint2Str = vertex.getProperty(Constants.RELATIONSHIPTYPE_ENDPOINT2_KEY, String.class); + String relationStr = vertex.getProperty(Constants.RELATIONSHIPTYPE_CATEGORY_KEY, String.class); + String propagateStr = vertex.getProperty(Constants.RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, String.class); + + // set the endpoints + AtlasRelationshipEndPointDef endPointDef1 = AtlasType.fromJson(endPoint1Str, AtlasRelationshipEndPointDef.class); + AtlasRelationshipEndPointDef endPointDef2 = AtlasType.fromJson(endPoint2Str, AtlasRelationshipEndPointDef.class); + + // set the relationship Category + RelationshipCategory relationshipCategory = null; + for (RelationshipCategory value : RelationshipCategory.values()) { + if (value.name().equals(relationStr)) { + relationshipCategory = value; + } + } + + // set the propagateTags + PropagateTags propagateTags = null; + for (PropagateTags value : PropagateTags.values()) { + if (value.name().equals(propagateStr)) { + propagateTags = value; + } + } + + ret = new AtlasRelationshipDef(name, description, version, relationshipCategory, propagateTags, endPointDef1, endPointDef2); + + // add in the attributes + AtlasStructDefStoreV1.toStructDef(vertex, ret, typeDefStore); + } + + return ret; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/6b9399e0/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java index f0c8380..2ba4144 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasTypeDefGraphStoreV1.java @@ -19,6 +19,17 @@ package org.apache.atlas.repository.store.graph.v1; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; + +import static org.apache.atlas.repository.Constants.TYPE_CATEGORY_PROPERTY_KEY; +import static org.apache.atlas.repository.Constants.VERTEX_TYPE_PROPERTY_KEY; +import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.VERTEX_TYPE; + +import java.util.Date; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.UUID; import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.listener.TypeDefChangeListener; @@ -31,6 +42,7 @@ import org.apache.atlas.repository.graphdb.AtlasVertex; import org.apache.atlas.repository.store.graph.AtlasClassificationDefStore; import org.apache.atlas.repository.store.graph.AtlasEntityDefStore; import org.apache.atlas.repository.store.graph.AtlasEnumDefStore; +import org.apache.atlas.repository.store.graph.AtlasRelationshipDefStore; import org.apache.atlas.repository.store.graph.AtlasStructDefStore; import org.apache.atlas.repository.store.graph.AtlasTypeDefGraphStore; import org.apache.atlas.type.AtlasType; @@ -45,16 +57,6 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.inject.Singleton; -import java.util.Date; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.UUID; - -import static org.apache.atlas.repository.Constants.TYPE_CATEGORY_PROPERTY_KEY; -import static org.apache.atlas.repository.Constants.VERTEX_TYPE_PROPERTY_KEY; -import static org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1.VERTEX_TYPE; /** @@ -110,6 +112,12 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { } @Override + protected AtlasRelationshipDefStore getRelationshipDefStore(AtlasTypeRegistry typeRegistry) { + return new AtlasRelationshipDefStoreV1(this, typeRegistry); + } + + + @Override @PostConstruct public void init() throws AtlasBaseException { LOG.debug("==> AtlasTypeDefGraphStoreV1.init()"); @@ -124,34 +132,34 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { @VisibleForTesting public AtlasVertex findTypeVertexByName(String typeName) { Iterator results = atlasGraph.query().has(VERTEX_TYPE_PROPERTY_KEY, VERTEX_TYPE) - .has(Constants.TYPENAME_PROPERTY_KEY, typeName) - .vertices().iterator(); + .has(Constants.TYPENAME_PROPERTY_KEY, typeName) + .vertices().iterator(); return (results != null && results.hasNext()) ? (AtlasVertex) results.next() : null; } AtlasVertex findTypeVertexByNameAndCategory(String typeName, TypeCategory category) { Iterator results = atlasGraph.query().has(VERTEX_TYPE_PROPERTY_KEY, VERTEX_TYPE) - .has(Constants.TYPENAME_PROPERTY_KEY, typeName) - .has(TYPE_CATEGORY_PROPERTY_KEY, category) - .vertices().iterator(); + .has(Constants.TYPENAME_PROPERTY_KEY, typeName) + .has(TYPE_CATEGORY_PROPERTY_KEY, category) + .vertices().iterator(); return (results != null && results.hasNext()) ? (AtlasVertex) results.next() : null; } AtlasVertex findTypeVertexByGuid(String typeGuid) { Iterator<AtlasVertex> vertices = atlasGraph.query().has(VERTEX_TYPE_PROPERTY_KEY, VERTEX_TYPE) - .has(Constants.GUID_PROPERTY_KEY, typeGuid) - .vertices().iterator(); + .has(Constants.GUID_PROPERTY_KEY, typeGuid) + .vertices().iterator(); return (vertices != null && vertices.hasNext()) ? vertices.next() : null; } AtlasVertex findTypeVertexByGuidAndCategory(String typeGuid, TypeCategory category) { Iterator<AtlasVertex> vertices = atlasGraph.query().has(VERTEX_TYPE_PROPERTY_KEY, VERTEX_TYPE) - .has(Constants.GUID_PROPERTY_KEY, typeGuid) - .has(TYPE_CATEGORY_PROPERTY_KEY, category) - .vertices().iterator(); + .has(Constants.GUID_PROPERTY_KEY, typeGuid) + .has(TYPE_CATEGORY_PROPERTY_KEY, category) + .vertices().iterator(); return (vertices != null && vertices.hasNext()) ? vertices.next() : null; } @@ -159,8 +167,8 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { Iterator<AtlasVertex> findTypeVerticesByCategory(TypeCategory category) { return (Iterator<AtlasVertex>) atlasGraph.query().has(VERTEX_TYPE_PROPERTY_KEY, VERTEX_TYPE) - .has(TYPE_CATEGORY_PROPERTY_KEY, category) - .vertices().iterator(); + .has(TYPE_CATEGORY_PROPERTY_KEY, category) + .vertices().iterator(); } AtlasVertex createTypeVertex(AtlasBaseTypeDef typeDef) { @@ -246,7 +254,6 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { for (AtlasEdge edge : edges) { atlasGraph.removeEdge(edge); } - atlasGraph.removeVertex(vertex); } @@ -343,7 +350,7 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { } void createSuperTypeEdges(AtlasVertex vertex, Set<String> superTypes, TypeCategory typeCategory) - throws AtlasBaseException { + throws AtlasBaseException { Set<String> currentSuperTypes = getSuperTypeNames(vertex); if (CollectionUtils.isNotEmpty(superTypes)) { @@ -385,6 +392,9 @@ public class AtlasTypeDefGraphStoreV1 extends AtlasTypeDefGraphStore { case ENUM: return TypeCategory.ENUM; + + case RELATIONSHIP: + return TypeCategory.RELATIONSHIP; } return null; http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/6b9399e0/typesystem/src/main/java/org/apache/atlas/typesystem/types/DataTypes.java ---------------------------------------------------------------------- diff --git a/typesystem/src/main/java/org/apache/atlas/typesystem/types/DataTypes.java b/typesystem/src/main/java/org/apache/atlas/typesystem/types/DataTypes.java index 21d5f1a..f9f4abe 100755 --- a/typesystem/src/main/java/org/apache/atlas/typesystem/types/DataTypes.java +++ b/typesystem/src/main/java/org/apache/atlas/typesystem/types/DataTypes.java @@ -86,7 +86,8 @@ public class DataTypes { MAP, STRUCT, TRAIT, - CLASS + CLASS, + RELATIONSHIP } public static abstract class PrimitiveType<T> extends AbstractDataType<T> { http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/6b9399e0/webapp/src/main/java/org/apache/atlas/examples/CreateTypesFromJsonFileUtil.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/examples/CreateTypesFromJsonFileUtil.java b/webapp/src/main/java/org/apache/atlas/examples/CreateTypesFromJsonFileUtil.java new file mode 100644 index 0000000..82d6f2e --- /dev/null +++ b/webapp/src/main/java/org/apache/atlas/examples/CreateTypesFromJsonFileUtil.java @@ -0,0 +1,109 @@ +/** + * 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.examples; + +import java.io.Console; +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; + +import org.apache.atlas.ApplicationProperties; +import org.apache.atlas.AtlasBaseClient; +import org.apache.atlas.AtlasClientV2; +import org.apache.atlas.AtlasException; +import org.apache.atlas.model.typedef.AtlasTypesDef; +import org.apache.atlas.type.AtlasType; +import org.apache.atlas.utils.AuthenticationUtil; +import org.apache.commons.configuration.Configuration; + +import com.google.common.annotations.VisibleForTesting; + +/** + * A driver that sets up types supplied in a file. + */ +public class CreateTypesFromJsonFileUtil extends AtlasBaseClient{ + public static final String ATLAS_REST_ADDRESS = "atlas.rest.address"; + + public static void main(String[] args) throws Exception { + + Console console = System.console(); + if (console == null) { + System.err.println("No console."); + System.exit(1); + } + String[] basicAuthUsernamePassword = null; + if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) { + basicAuthUsernamePassword = AuthenticationUtil.getBasicAuthenticationInput(); + } + AtlasClientV2 atlasClientV2 = getAtlasClientV2(args, basicAuthUsernamePassword); + + + String createFileName = console.readLine("Enter fileName containing TypeDefs for create:- "); + File createFile = new File(createFileName); + String createJsonStr = new String( Files.readAllBytes(createFile.toPath()), StandardCharsets.UTF_8); + + System.err.println("create json is :\n" + createJsonStr); + + runTypeCreation(createJsonStr,atlasClientV2); +// String updateFileName = console.readLine("Enter fileName containing TypeDefs for update:- "); +// File updateFile = new File(updateFileName); +// String updateJsonStr = new String( Files.readAllBytes(updateFile.toPath()), StandardCharsets.UTF_8); +// System.err.println("update json is :\n" + updateJsonStr); +// runTypeUpdate(updateJsonStr,atlasClientV2); + } + + @VisibleForTesting + static void runTypeCreation(String jsonStr,AtlasClientV2 atlasClientV2) throws Exception { + AtlasTypesDef typesDef = AtlasType.fromJson(jsonStr, AtlasTypesDef.class); + atlasClientV2.createAtlasTypeDefs(typesDef); + } + @VisibleForTesting + static void runTypeUpdate(String jsonStr,AtlasClientV2 atlasClientV2) throws Exception { + AtlasTypesDef typesDef = AtlasType.fromJson(jsonStr, AtlasTypesDef.class); + atlasClientV2.updateAtlasTypeDefs(typesDef); + } + + private static AtlasClientV2 getAtlasClientV2(String[] args, String[] basicAuthUsernamePassword) throws AtlasException { + String[] urls = getServerUrl(args); + + AtlasClientV2 atlasClientV2; + + if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) { + atlasClientV2 =new AtlasClientV2(urls,basicAuthUsernamePassword); + } else { + atlasClientV2 = new AtlasClientV2(urls); + } + return atlasClientV2; + } + + static String[] getServerUrl(String[] args) throws AtlasException { + if (args.length > 0) { + return args[0].split(","); + } + + Configuration configuration = ApplicationProperties.get(); + String[] urls = configuration.getStringArray(ATLAS_REST_ADDRESS); + if (urls == null || urls.length == 0) { + System.out.println("Usage: quick_start.py <atlas endpoint of format <http/https>://<atlas-fqdn>:<atlas port> like http://localhost:21000>"); + System.exit(-1); + } + + return urls; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/6b9399e0/webapp/src/main/java/org/apache/atlas/examples/UpdateTypesFromJsonFileUtil.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/examples/UpdateTypesFromJsonFileUtil.java b/webapp/src/main/java/org/apache/atlas/examples/UpdateTypesFromJsonFileUtil.java new file mode 100644 index 0000000..3b67706 --- /dev/null +++ b/webapp/src/main/java/org/apache/atlas/examples/UpdateTypesFromJsonFileUtil.java @@ -0,0 +1,108 @@ +/** + * 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.examples; + +import com.google.common.annotations.VisibleForTesting; +import org.apache.atlas.ApplicationProperties; +import org.apache.atlas.AtlasBaseClient; +import org.apache.atlas.AtlasClientV2; +import org.apache.atlas.AtlasException; +import org.apache.atlas.model.typedef.AtlasTypesDef; +import org.apache.atlas.type.AtlasType; +import org.apache.atlas.utils.AuthenticationUtil; +import org.apache.commons.configuration.Configuration; + +import java.io.Console; +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; + +/** + * A driver that sets up types supplied in a file. + */ +public class UpdateTypesFromJsonFileUtil extends AtlasBaseClient{ + public static final String ATLAS_REST_ADDRESS = "atlas.rest.address"; + + public static void main(String[] args) throws Exception { + + Console console = System.console(); + if (console == null) { + System.err.println("No console."); + System.exit(1); + } + String[] basicAuthUsernamePassword = null; + if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) { + basicAuthUsernamePassword = AuthenticationUtil.getBasicAuthenticationInput(); + } + AtlasClientV2 atlasClientV2 = getAtlasClientV2(args, basicAuthUsernamePassword); + + + String createFileName = console.readLine("Enter fileName containing TypeDefs for create:- "); + File createFile = new File(createFileName); + String createJsonStr = new String( Files.readAllBytes(createFile.toPath()), StandardCharsets.UTF_8); + + System.err.println("create json is :\n" + createJsonStr); + + runTypeCreation(createJsonStr,atlasClientV2); +// String updateFileName = console.readLine("Enter fileName containing TypeDefs for update:- "); +// File updateFile = new File(updateFileName); +// String updateJsonStr = new String( Files.readAllBytes(updateFile.toPath()), StandardCharsets.UTF_8); +// System.err.println("update json is :\n" + updateJsonStr); +// runTypeUpdate(updateJsonStr,atlasClientV2); + } + + @VisibleForTesting + static void runTypeCreation(String jsonStr,AtlasClientV2 atlasClientV2) throws Exception { + AtlasTypesDef typesDef = AtlasType.fromJson(jsonStr, AtlasTypesDef.class); + atlasClientV2.createAtlasTypeDefs(typesDef); + } + @VisibleForTesting + static void runTypeUpdate(String jsonStr,AtlasClientV2 atlasClientV2) throws Exception { + AtlasTypesDef typesDef = AtlasType.fromJson(jsonStr, AtlasTypesDef.class); + atlasClientV2.updateAtlasTypeDefs(typesDef); + } + + private static AtlasClientV2 getAtlasClientV2(String[] args, String[] basicAuthUsernamePassword) throws AtlasException { + String[] urls = getServerUrl(args); + + AtlasClientV2 atlasClientV2; + + if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) { + atlasClientV2 =new AtlasClientV2(urls,basicAuthUsernamePassword); + } else { + atlasClientV2 = new AtlasClientV2(urls); + } + return atlasClientV2; + } + + static String[] getServerUrl(String[] args) throws AtlasException { + if (args.length > 0) { + return args[0].split(","); + } + + Configuration configuration = ApplicationProperties.get(); + String[] urls = configuration.getStringArray(ATLAS_REST_ADDRESS); + if (urls == null || urls.length == 0) { + System.out.println("Usage: quick_start.py <atlas endpoint of format <http/https>://<atlas-fqdn>:<atlas port> like http://localhost:21000>"); + System.exit(-1); + } + + return urls; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/6b9399e0/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java index 08121d8..f70593a 100755 --- a/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java +++ b/webapp/src/main/java/org/apache/atlas/web/resources/TypesResource.java @@ -266,7 +266,7 @@ public class TypesResource { * Return the list of type names in the type system which match the specified filter. * * @return list of type names - * @param typeCategory returns types whose category is the given typeCategory + * @param typeCategory returns types whose relationshipCategory is the given typeCategory * @param supertype returns types which contain the given supertype * @param notsupertype returns types which do not contain the given supertype * http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/6b9399e0/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java index c32f36e..59ea338 100644 --- a/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java +++ b/webapp/src/main/java/org/apache/atlas/web/rest/TypesREST.java @@ -19,13 +19,7 @@ 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.AtlasClassificationDef; -import org.apache.atlas.model.typedef.AtlasEntityDef; -import org.apache.atlas.model.typedef.AtlasEnumDef; -import org.apache.atlas.model.typedef.AtlasStructDef; -import org.apache.atlas.model.typedef.AtlasTypeDefHeader; -import org.apache.atlas.model.typedef.AtlasTypesDef; +import org.apache.atlas.model.typedef.*; import org.apache.atlas.store.AtlasTypeDefStore; import org.apache.atlas.type.AtlasTypeUtil; import org.apache.atlas.utils.AtlasPerfTracer; @@ -37,14 +31,7 @@ import org.springframework.stereotype.Service; import javax.inject.Inject; import javax.inject.Singleton; import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; +import javax.ws.rs.*; import javax.ws.rs.core.Context; import java.util.List; import java.util.Set; @@ -269,7 +256,39 @@ public class TypesREST { return ret; } + /** + * Get the relationship definition by it's name (unique) + * @param name relationship name + * @return relationship definition + * @throws AtlasBaseException + * @HTTP 200 On successful lookup of the the relationship definition by it's name + * @HTTP 404 On Failed lookup for the given name + */ + @GET + @Path("/relationshipdef/name/{name}") + @Produces(Servlets.JSON_MEDIA_TYPE) + public AtlasRelationshipDef getRelationshipDefByName(@PathParam("name") String name) throws AtlasBaseException { + AtlasRelationshipDef ret = typeDefStore.getRelationshipDefByName(name); + + return ret; + } + /** + * Get the relationship definition for the given guid + * @param guid relationship guid + * @return relationship definition + * @throws AtlasBaseException + * @HTTP 200 On successful lookup of the the relationship definition by it's guid + * @HTTP 404 On Failed lookup for the given guid + */ + @GET + @Path("/relationshipdef/guid/{guid}") + @Produces(Servlets.JSON_MEDIA_TYPE) + public AtlasRelationshipDef getRelationshipDefByGuid(@PathParam("guid") String guid) throws AtlasBaseException { + AtlasRelationshipDef ret = typeDefStore.getRelationshipDefByGuid(guid); + + return ret; + } /* Bulk API operation */ /**
