http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/memory/MemRepository.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/memory/MemRepository.java b/repository/src/main/java/org/apache/atlas/repository/memory/MemRepository.java deleted file mode 100755 index aef06a4..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/memory/MemRepository.java +++ /dev/null @@ -1,299 +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.memory; - -import org.apache.atlas.AtlasException; -import org.apache.atlas.repository.DiscoverInstances; -import org.apache.atlas.repository.IRepository; -import org.apache.atlas.repository.RepositoryException; -import org.apache.atlas.typesystem.IReferenceableInstance; -import org.apache.atlas.typesystem.ITypedReferenceableInstance; -import org.apache.atlas.typesystem.persistence.Id; -import org.apache.atlas.typesystem.persistence.MapIds; -import org.apache.atlas.typesystem.persistence.ReferenceableInstance; -import org.apache.atlas.typesystem.types.ClassType; -import org.apache.atlas.typesystem.types.DataTypes; -import org.apache.atlas.typesystem.types.HierarchicalType; -import org.apache.atlas.typesystem.types.HierarchicalTypeDependencySorter; -import org.apache.atlas.typesystem.types.Multiplicity; -import org.apache.atlas.typesystem.types.ObjectGraphWalker; -import org.apache.atlas.typesystem.types.TraitType; -import org.apache.atlas.typesystem.types.TypeSystem; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.concurrent.atomic.AtomicInteger; - -@Deprecated -public class MemRepository implements IRepository { - - final TypeSystem typeSystem; - /* - * A Store for each Class and Trait. - */ - final Map<String, HierarchicalTypeStore> typeStores; - final AtomicInteger ID_SEQ = new AtomicInteger(0); - - public MemRepository(TypeSystem typeSystem) { - this.typeSystem = typeSystem; - this.typeStores = new HashMap<>(); - } - - @Override - public Id newId(String typeName) { - return new Id("" + ID_SEQ.incrementAndGet(), 0, typeName); - } - - /** - * 1. traverse the Object Graph from i and create idToNewIdMap : Map[Id, Id], - * also create old Id to Instance Map: oldIdToInstance : Map[Id, IInstance] - * - traverse reference Attributes, List[ClassType], Maps where Key/value is ClassType - * - traverse Structs - * - traverse Traits. - * 1b. Ensure that every newId has an associated Instance. - * 2. Traverse oldIdToInstance map create newInstances : List[ITypedReferenceableInstance] - * - create a ITypedReferenceableInstance. - * replace any old References ( ids or object references) with new Ids. - * 3. Traverse over newInstances - * - ask ClassStore to assign a position to the Id. - * - for Instances with Traits, assign a position for each Trait - * - invoke store on the nwInstance. - * - * Recovery: - * - on each newInstance, invoke releaseId and delete on its ClassStore and Traits' Stores. - * - * @param i - * @return - * @throws org.apache.atlas.repository.RepositoryException - */ - public ITypedReferenceableInstance create(IReferenceableInstance i) throws RepositoryException { - - DiscoverInstances discoverInstances = new DiscoverInstances(this); - - /* - * Step 1: traverse the Object Graph from i and create idToNewIdMap : Map[Id, Id], - * also create old Id to Instance Map: oldIdToInstance : Map[Id, IInstance] - * - traverse reference Attributes, List[ClassType], Maps where Key/value is ClassType - * - traverse Structs - * - traverse Traits. - */ - try { - new ObjectGraphWalker(typeSystem, discoverInstances, i).walk(); - } catch (AtlasException me) { - throw new RepositoryException("TypeSystem error when walking the ObjectGraph", me); - } - - /* - * Step 1b: Ensure that every newId has an associated Instance. - */ - for (Id oldId : discoverInstances.idToNewIdMap.keySet()) { - if (!discoverInstances.idToInstanceMap.containsKey(oldId)) { - throw new RepositoryException(String.format("Invalid Object Graph: " - + "Encountered an unassignedId %s that is not associated with an Instance", oldId)); - } - } - - /* Step 2: Traverse oldIdToInstance map create newInstances : - List[ITypedReferenceableInstance] - * - create a ITypedReferenceableInstance. - * replace any old References ( ids or object references) with new Ids. - */ - List<ITypedReferenceableInstance> newInstances = new ArrayList<>(); - ITypedReferenceableInstance retInstance = null; - Set<ClassType> classTypes = new TreeSet<>(); - Set<TraitType> traitTypes = new TreeSet<>(); - for (IReferenceableInstance transientInstance : discoverInstances.idToInstanceMap.values()) { - try { - ClassType cT = typeSystem.getDataType(ClassType.class, transientInstance.getTypeName()); - ITypedReferenceableInstance newInstance = cT.convert(transientInstance, Multiplicity.REQUIRED); - newInstances.add(newInstance); - - classTypes.add(cT); - for (String traitName : newInstance.getTraits()) { - TraitType tT = typeSystem.getDataType(TraitType.class, traitName); - traitTypes.add(tT); - } - - if (newInstance.getId() == i.getId()) { - retInstance = newInstance; - } - - /* - * Now replace old references with new Ids - */ - MapIds mapIds = new MapIds(discoverInstances.idToNewIdMap); - new ObjectGraphWalker(typeSystem, mapIds, newInstances).walk(); - - } catch (AtlasException me) { - throw new RepositoryException( - String.format("Failed to create Instance(id = %s", transientInstance.getId()), me); - } - } - - /* - * 3. Acquire Class and Trait Storage locks. - * - acquire them in a stable order (super before subclass, classes before traits - */ - for (ClassType cT : classTypes) { - HierarchicalTypeStore st = typeStores.get(cT.getName()); - st.acquireWriteLock(); - } - - for (TraitType tT : traitTypes) { - HierarchicalTypeStore st = typeStores.get(tT.getName()); - st.acquireWriteLock(); - } - - - /* - * 4. Traverse over newInstances - * - ask ClassStore to assign a position to the Id. - * - for Instances with Traits, assign a position for each Trait - * - invoke store on the nwInstance. - */ - try { - for (ITypedReferenceableInstance instance : newInstances) { - HierarchicalTypeStore st = typeStores.get(instance.getTypeName()); - st.assignPosition(instance.getId()); - for (String traitName : instance.getTraits()) { - HierarchicalTypeStore tt = typeStores.get(traitName); - tt.assignPosition(instance.getId()); - } - } - - for (ITypedReferenceableInstance instance : newInstances) { - HierarchicalTypeStore st = typeStores.get(instance.getTypeName()); - st.store((ReferenceableInstance) instance); - for (String traitName : instance.getTraits()) { - HierarchicalTypeStore tt = typeStores.get(traitName); - tt.store((ReferenceableInstance) instance); - } - } - } catch (RepositoryException re) { - for (ITypedReferenceableInstance instance : newInstances) { - HierarchicalTypeStore st = typeStores.get(instance.getTypeName()); - st.releaseId(instance.getId()); - } - throw re; - } finally { - for (ClassType cT : classTypes) { - HierarchicalTypeStore st = typeStores.get(cT.getName()); - st.releaseWriteLock(); - } - - for (TraitType tT : traitTypes) { - HierarchicalTypeStore st = typeStores.get(tT.getName()); - st.releaseWriteLock(); - } - } - - return retInstance; - } - - public ITypedReferenceableInstance update(ITypedReferenceableInstance i) throws RepositoryException { - throw new RepositoryException("not implemented"); - } - - public void delete(ITypedReferenceableInstance i) throws RepositoryException { - throw new RepositoryException("not implemented"); - } - - public ITypedReferenceableInstance get(Id id) throws RepositoryException { - - try { - ReplaceIdWithInstance replacer = new ReplaceIdWithInstance(this); - ObjectGraphWalker walker = new ObjectGraphWalker(typeSystem, replacer); - replacer.setWalker(walker); - ITypedReferenceableInstance r = getDuringWalk(id, walker); - walker.walk(); - return r; - } catch (AtlasException me) { - throw new RepositoryException("TypeSystem error when walking the ObjectGraph", me); - } - } - - /* - * - Id must be valid; Class must be valid. - * - Ask ClassStore to createInstance. - * - Ask ClassStore to load instance. - * - load instance traits - * - add to GraphWalker - */ - ITypedReferenceableInstance getDuringWalk(Id id, ObjectGraphWalker walker) throws RepositoryException { - ClassStore cS = getClassStore(id.getTypeName()); - if (cS == null) { - throw new RepositoryException(String.format("Unknown Class %s", id.getTypeName())); - } - cS.validate(this, id); - ReferenceableInstance r = cS.createInstance(this, id); - cS.load(r); - for (String traitName : r.getTraits()) { - HierarchicalTypeStore tt = typeStores.get(traitName); - tt.load(r); - } - - walker.addRoot(r); - return r; - } - - HierarchicalTypeStore getStore(String typeName) { - return typeStores.get(typeName); - } - - ClassStore getClassStore(String typeName) { - return (ClassStore) getStore(typeName); - } - - public void defineClass(ClassType type) throws RepositoryException { - HierarchicalTypeStore s = new ClassStore(this, type); - typeStores.put(type.getName(), s); - } - - public void defineTrait(TraitType type) throws RepositoryException { - HierarchicalTypeStore s = new TraitStore(this, type); - typeStores.put(type.getName(), s); - } - - public void defineTypes(List<HierarchicalType> types) throws RepositoryException { - List<TraitType> tTypes = new ArrayList<>(); - List<ClassType> cTypes = new ArrayList<>(); - - for (HierarchicalType h : types) { - if (h.getTypeCategory() == DataTypes.TypeCategory.TRAIT) { - tTypes.add((TraitType) h); - } else { - cTypes.add((ClassType) h); - } - } - tTypes = HierarchicalTypeDependencySorter.sortTypes(tTypes); - cTypes = HierarchicalTypeDependencySorter.sortTypes(cTypes); - - for (TraitType tT : tTypes) { - defineTrait(tT); - } - - for (ClassType cT : cTypes) { - defineClass(cT); - } - } -}
http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/memory/ReplaceIdWithInstance.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/memory/ReplaceIdWithInstance.java b/repository/src/main/java/org/apache/atlas/repository/memory/ReplaceIdWithInstance.java deleted file mode 100755 index 6741eb8..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/memory/ReplaceIdWithInstance.java +++ /dev/null @@ -1,132 +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.memory; - -import com.google.common.collect.ImmutableCollection; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import org.apache.atlas.AtlasException; -import org.apache.atlas.typesystem.ITypedReferenceableInstance; -import org.apache.atlas.typesystem.persistence.Id; -import org.apache.atlas.typesystem.types.DataTypes; -import org.apache.atlas.typesystem.types.Multiplicity; -import org.apache.atlas.typesystem.types.ObjectGraphWalker; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -public class ReplaceIdWithInstance implements ObjectGraphWalker.NodeProcessor { - - public final Map<Id, ITypedReferenceableInstance> idToInstanceMap; - final MemRepository repository; - ObjectGraphWalker walker; - - public ReplaceIdWithInstance(MemRepository repository) { - this.repository = repository; - idToInstanceMap = new HashMap<>(); - } - - void setWalker(ObjectGraphWalker walker) { - this.walker = walker; - } - - @Override - public void processNode(ObjectGraphWalker.Node nd) throws AtlasException { - if (nd.attributeName != null) { - if (nd.aInfo.isComposite && nd.value != null) { - if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.CLASS) { - if (nd.value instanceof Id) { - Id id = (Id) nd.value; - ITypedReferenceableInstance r = getInstance(id); - nd.instance.set(nd.attributeName, r); - } - } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.ARRAY) { - DataTypes.ArrayType aT = (DataTypes.ArrayType) nd.aInfo.dataType(); - nd.instance.set(nd.attributeName, - convertToInstances((ImmutableCollection) nd.value, nd.aInfo.multiplicity, aT)); - } else if (nd.aInfo.dataType().getTypeCategory() == DataTypes.TypeCategory.MAP) { - DataTypes.MapType mT = (DataTypes.MapType) nd.aInfo.dataType(); - nd.instance.set(nd.attributeName, convertToInstances((ImmutableMap) nd.value, nd.aInfo.multiplicity, mT)); - } - } - } - } - - ImmutableCollection<?> convertToInstances(ImmutableCollection<?> val, Multiplicity m, DataTypes.ArrayType arrType) - throws AtlasException { - - if (val == null || arrType.getElemType().getTypeCategory() != DataTypes.TypeCategory.CLASS) { - return val; - } - - ImmutableCollection.Builder b = m.isUnique ? ImmutableSet.builder() : ImmutableList.builder(); - for (Object elem : val) { - if (elem instanceof Id) { - Id id = (Id) elem; - elem = getInstance(id); - } - - b.add(elem); - - } - return b.build(); - } - - ImmutableMap<?, ?> convertToInstances(ImmutableMap val, Multiplicity m, DataTypes.MapType mapType) - throws AtlasException { - - if (val == null || (mapType.getKeyType().getTypeCategory() != DataTypes.TypeCategory.CLASS - && mapType.getValueType().getTypeCategory() != DataTypes.TypeCategory.CLASS)) { - return val; - } - ImmutableMap.Builder b = ImmutableMap.builder(); - for (Map.Entry elem : (Iterable<Map.Entry>) val.entrySet()) { - Object oldKey = elem.getKey(); - Object oldValue = elem.getValue(); - Object newKey = oldKey; - Object newValue = oldValue; - - if (oldKey instanceof Id) { - Id id = (Id) elem; - ITypedReferenceableInstance r = getInstance(id); - } - - if (oldValue instanceof Id) { - Id id = (Id) elem; - ITypedReferenceableInstance r = getInstance(id); - } - - b.put(newKey, newValue); - } - return b.build(); - } - - ITypedReferenceableInstance getInstance(Id id) throws AtlasException { - - ITypedReferenceableInstance r = idToInstanceMap.get(id); - if (r == null) { - r = repository.get(id); - idToInstanceMap.put(id, r); - walker.addRoot(r); - } - return r; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/memory/StructStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/memory/StructStore.java b/repository/src/main/java/org/apache/atlas/repository/memory/StructStore.java deleted file mode 100755 index 69a18a5..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/memory/StructStore.java +++ /dev/null @@ -1,87 +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.memory; - -import com.google.common.collect.ImmutableBiMap; -import com.google.common.collect.ImmutableMap; -import org.apache.atlas.repository.RepositoryException; -import org.apache.atlas.typesystem.persistence.StructInstance; -import org.apache.atlas.typesystem.types.AttributeInfo; -import org.apache.atlas.typesystem.types.StructType; - -import java.util.Collection; -import java.util.Map; - -@Deprecated -public class StructStore extends AttributeStores.AbstractAttributeStore implements IAttributeStore { - - final StructType structType; - final ImmutableMap<AttributeInfo, IAttributeStore> attrStores; - - StructStore(AttributeInfo aInfo) throws RepositoryException { - super(aInfo); - this.structType = (StructType) aInfo.dataType(); - ImmutableMap.Builder<AttributeInfo, IAttributeStore> b = new ImmutableBiMap.Builder<>(); - Collection<AttributeInfo> l = structType.fieldMapping.fields.values(); - for (AttributeInfo i : l) { - b.put(i, AttributeStores.createStore(i)); - } - attrStores = b.build(); - - } - - @Override - protected void store(StructInstance instance, int colPos, int pos) throws RepositoryException { - StructInstance s = instance.structs[colPos]; - for (Map.Entry<AttributeInfo, IAttributeStore> e : attrStores.entrySet()) { - IAttributeStore attributeStore = e.getValue(); - attributeStore.store(pos, structType, s); - } - } - - @Override - protected void load(StructInstance instance, int colPos, int pos) throws RepositoryException { - StructInstance s = (StructInstance) structType.createInstance(); - instance.structs[colPos] = s; - for (Map.Entry<AttributeInfo, IAttributeStore> e : attrStores.entrySet()) { - IAttributeStore attributeStore = e.getValue(); - attributeStore.load(pos, structType, s); - } - } - - @Override - protected void store(StructInstance instance, int colPos, String attrName, Map<String, Object> m) { - m.put(attrName, instance.structs[colPos]); - } - - @Override - protected void load(StructInstance instance, int colPos, Object val) { - instance.structs[colPos] = (StructInstance) val; - } - - @Override - public void ensureCapacity(int pos) throws RepositoryException { - for (Map.Entry<AttributeInfo, IAttributeStore> e : attrStores.entrySet()) { - IAttributeStore attributeStore = e.getValue(); - attributeStore.ensureCapacity(pos); - } - nullList.size(pos + 1); - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/memory/TraitStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/memory/TraitStore.java b/repository/src/main/java/org/apache/atlas/repository/memory/TraitStore.java deleted file mode 100755 index 0cbb32d..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/memory/TraitStore.java +++ /dev/null @@ -1,57 +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.memory; - -import org.apache.atlas.repository.RepositoryException; -import org.apache.atlas.typesystem.persistence.ReferenceableInstance; -import org.apache.atlas.typesystem.persistence.StructInstance; -import org.apache.atlas.typesystem.types.TraitType; - -import java.util.ArrayList; - -@Deprecated -public class TraitStore extends HierarchicalTypeStore { - - final ArrayList<String> classNameStore; - - public TraitStore(MemRepository repository, TraitType hierarchicalType) throws RepositoryException { - super(repository, hierarchicalType); - classNameStore = new ArrayList<>(); - } - - void store(ReferenceableInstance i) throws RepositoryException { - int pos = idPosMap.get(i.getId()); - StructInstance s = (StructInstance) i.getTrait(hierarchicalType.getName()); - super.storeFields(pos, s); - classNameStore.set(pos, i.getTypeName()); - } - - void load(ReferenceableInstance i) throws RepositoryException { - int pos = idPosMap.get(i.getId()); - StructInstance s = (StructInstance) i.getTrait(hierarchicalType.getName()); - super.loadFields(pos, s); - } - - public void ensureCapacity(int pos) throws RepositoryException { - super.ensureCapacity(pos); - while (classNameStore.size() < pos + 1) { - classNameStore.add(null); - } - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java index 5a0b74e..0fe35b6 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/AtlasEntityStore.java @@ -32,6 +32,15 @@ import java.util.Map; * Persistence/Retrieval API for AtlasEntity */ public interface AtlasEntityStore { + + /** + * List all the entity guids for a given typename + * @param typename + * @return + * @throws AtlasBaseException + */ + List<String> getEntityGUIDS(String typename) throws AtlasBaseException; + /** * * Get entity definition by its guid http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java index 7b349c4..4c511c1 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityChangeNotifier.java @@ -26,13 +26,13 @@ import org.apache.atlas.model.instance.AtlasClassification; import org.apache.atlas.model.instance.AtlasEntityHeader; import org.apache.atlas.model.instance.EntityMutationResponse; import org.apache.atlas.model.instance.EntityMutations.EntityOperation; +import org.apache.atlas.v1.model.instance.Referenceable; +import org.apache.atlas.v1.model.instance.Struct; import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.converters.AtlasInstanceConverter; import org.apache.atlas.repository.graph.FullTextMapperV2; import org.apache.atlas.repository.graph.GraphHelper; import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.apache.atlas.typesystem.ITypedReferenceableInstance; -import org.apache.atlas.typesystem.ITypedStruct; import org.apache.atlas.util.AtlasRepositoryConfiguration; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -74,7 +74,7 @@ public class AtlasEntityChangeNotifier { List<AtlasEntityHeader> partiallyUpdatedEntities = entityMutationResponse.getPartialUpdatedEntities(); List<AtlasEntityHeader> deletedEntities = entityMutationResponse.getDeletedEntities(); - // complete full text mapping before calling toITypedReferenceable(), from notifyListners(), to + // complete full text mapping before calling toReferenceables(), from notifyListners(), to // include all vertex updates in the current graph-transaction doFullTextMapping(createdEntities); doFullTextMapping(updatedEntities); @@ -91,8 +91,8 @@ public class AtlasEntityChangeNotifier { // appended to the existing fullText updateFullTextMapping(entityId, classifications); - ITypedReferenceableInstance entity = toITypedReferenceable(entityId); - List<ITypedStruct> traits = toITypedStructs(classifications); + Referenceable entity = toReferenceable(entityId); + List<Struct> traits = toStruct(classifications); if (entity == null || CollectionUtils.isEmpty(traits)) { return; @@ -111,7 +111,7 @@ public class AtlasEntityChangeNotifier { // Since the entity has already been modified in the graph, we need to recursively remap the entity doFullTextMapping(entityId); - ITypedReferenceableInstance entity = toITypedReferenceable(entityId); + Referenceable entity = toReferenceable(entityId); if (entity == null || CollectionUtils.isEmpty(traitNames)) { return; @@ -130,8 +130,8 @@ public class AtlasEntityChangeNotifier { // Since the classification attributes are updated in the graph, we need to recursively remap the entityText doFullTextMapping(entityId); - ITypedReferenceableInstance entity = toITypedReferenceable(entityId); - List<ITypedStruct> traits = toITypedStructs(classifications); + Referenceable entity = toReferenceable(entityId); + List<Struct> traits = toStruct(classifications); if (entity == null || CollectionUtils.isEmpty(traits)) { return; @@ -155,7 +155,7 @@ public class AtlasEntityChangeNotifier { return; } - List<ITypedReferenceableInstance> typedRefInsts = toITypedReferenceable(entityHeaders); + List<Referenceable> typedRefInsts = toReferenceables(entityHeaders); for (EntityChangeListener listener : entityChangeListeners) { try { @@ -177,28 +177,28 @@ public class AtlasEntityChangeNotifier { } } - private List<ITypedReferenceableInstance> toITypedReferenceable(List<AtlasEntityHeader> entityHeaders) throws AtlasBaseException { - List<ITypedReferenceableInstance> ret = new ArrayList<>(entityHeaders.size()); + private List<Referenceable> toReferenceables(List<AtlasEntityHeader> entityHeaders) throws AtlasBaseException { + List<Referenceable> ret = new ArrayList<>(entityHeaders.size()); for (AtlasEntityHeader entityHeader : entityHeaders) { - ret.add(instanceConverter.getITypedReferenceable(entityHeader.getGuid())); + ret.add(toReferenceable(entityHeader.getGuid())); } return ret; } - private ITypedReferenceableInstance toITypedReferenceable(String entityId) throws AtlasBaseException { - ITypedReferenceableInstance ret = null; + private Referenceable toReferenceable(String entityId) throws AtlasBaseException { + Referenceable ret = null; if (StringUtils.isNotEmpty(entityId)) { - ret = instanceConverter.getITypedReferenceable(entityId); + ret = instanceConverter.getReferenceable(entityId); } return ret; } - private List<ITypedStruct> toITypedStructs(List<AtlasClassification> classifications) throws AtlasBaseException { - List<ITypedStruct> ret = null; + private List<Struct> toStruct(List<AtlasClassification> classifications) throws AtlasBaseException { + List<Struct> ret = null; if (classifications != null) { ret = new ArrayList<>(classifications.size()); http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java index a5db81b..89bf7dc 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1.java @@ -77,6 +77,26 @@ public class AtlasEntityStoreV1 implements AtlasEntityStore { @Override @GraphTransaction + public List<String> getEntityGUIDS(final String typename) throws AtlasBaseException { + if (LOG.isDebugEnabled()) { + LOG.debug("==> getEntityGUIDS({})", typename); + } + + if (StringUtils.isEmpty(typename)) { + throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME); + } + + List<String> ret = AtlasGraphUtilsV1.findEntityGUIDsByType(typename); + + if (LOG.isDebugEnabled()) { + LOG.debug("<== getEntityGUIDS({})", typename); + } + + return ret; + } + + @Override + @GraphTransaction public AtlasEntityWithExtInfo getById(String guid) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> getById({})", guid); http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java index 1eb4183..6a6ac60 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasGraphUtilsV1.java @@ -43,9 +43,12 @@ import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Set; @@ -325,6 +328,22 @@ public class AtlasGraphUtilsV1 { return vertex; } + public static List<String> findEntityGUIDsByType(String typename) { + AtlasGraphQuery query = AtlasGraphProvider.getGraphInstance().query() + .has(Constants.ENTITY_TYPE_PROPERTY_KEY, typename); + Iterator<AtlasVertex> results = query.vertices().iterator(); + if (!results.hasNext()) { + return Collections.emptyList(); + } + + ArrayList<String> entityList = new ArrayList<>(); + while (results.hasNext()) { + entityList.add(getIdFromVertex(results.next())); + } + + return entityList; + } + public static boolean relationshipTypeHasInstanceEdges(String typeName) throws AtlasBaseException { AtlasGraphQuery query = AtlasGraphProvider.getGraphInstance() .query() http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java index 86f1b88..f1d9031 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java @@ -23,6 +23,7 @@ import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.typedef.AtlasStructDef; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef; import org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef; +import org.apache.atlas.v1.model.typedef.AttributeDefinition; import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.graph.GraphHelper; import org.apache.atlas.repository.graphdb.AtlasVertex; @@ -31,12 +32,9 @@ import org.apache.atlas.type.AtlasStructType.AtlasAttribute; import org.apache.atlas.type.AtlasType; import org.apache.atlas.type.AtlasTypeRegistry; import org.apache.atlas.type.AtlasTypeUtil; -import org.apache.atlas.typesystem.types.AttributeDefinition; -import org.apache.atlas.typesystem.types.AttributeInfo; import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; -import org.codehaus.jettison.json.JSONException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -547,15 +545,9 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1<AtlasStructDe } public static AttributeDefinition toAttributeDefintion(AtlasAttribute attribute) { - AttributeDefinition ret = null; - String jsonString = toJsonFromAttribute(attribute); - try { - ret = AttributeInfo.fromJson(jsonString); - } catch (JSONException excp) { - LOG.error("failed in converting to AttributeDefinition: " + jsonString, excp); - } + AttributeDefinition ret = AtlasType.fromV1Json(jsonString, AttributeDefinition.class); return ret; } http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/typestore/GraphBackedTypeStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/typestore/GraphBackedTypeStore.java b/repository/src/main/java/org/apache/atlas/repository/typestore/GraphBackedTypeStore.java deleted file mode 100644 index 2dd339c..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/typestore/GraphBackedTypeStore.java +++ /dev/null @@ -1,394 +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.typestore; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; -import org.apache.atlas.AtlasException; -import org.apache.atlas.annotation.GraphTransaction; -import org.apache.atlas.repository.Constants; -import org.apache.atlas.repository.RepositoryException; -import org.apache.atlas.repository.graph.GraphHelper; -import org.apache.atlas.repository.graphdb.AtlasEdge; -import org.apache.atlas.repository.graphdb.AtlasEdgeDirection; -import org.apache.atlas.repository.graphdb.AtlasGraph; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.apache.atlas.typesystem.TypesDef; -import org.apache.atlas.typesystem.types.*; -import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; -import org.apache.atlas.typesystem.types.utils.TypesUtil; -import org.codehaus.jettison.json.JSONException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.apache.atlas.repository.graph.GraphHelper.setProperty; - -@Singleton -@Component -@Deprecated -public class GraphBackedTypeStore implements ITypeStore { - public static final String VERTEX_TYPE = "typeSystem"; - private static final String PROPERTY_PREFIX = Constants.INTERNAL_PROPERTY_KEY_PREFIX + "type."; - public static final String SUPERTYPE_EDGE_LABEL = PROPERTY_PREFIX + ".supertype"; - - private static Logger LOG = LoggerFactory.getLogger(GraphBackedTypeStore.class); - - private final AtlasGraph graph; - - private GraphHelper graphHelper = GraphHelper.getInstance(); - - @Inject - public GraphBackedTypeStore(AtlasGraph atlasGraph) { - this.graph = atlasGraph; - } - - @Override - @GraphTransaction - public void store(TypeSystem typeSystem, ImmutableList<String> typeNames) throws AtlasException { - - //Pre-create the vertices that are needed for the types. This allows us to execute - //one query to determine all of the vertices that already exist. - Map<String, AtlasVertex> typeVertices = getOrCreateTypeVertices(typeSystem, typeNames); - - //Complete the storage process by adding properties and edges to the vertices - //that were created. - TypePersistenceVisitor visitor = new TypePersistenceVisitor(this, typeVertices, typeSystem); - processTypes(typeNames, typeSystem, visitor); - } - - private void processTypes(ImmutableList<String> typeNames, TypeSystem typeSystem, TypeVisitor visitor) throws AtlasException { - for (String typeName : typeNames) { - IDataType dataType = typeSystem.getDataType(IDataType.class, typeName); - LOG.debug("Processing {}.{}.{} in type store", dataType.getTypeCategory(), dataType.getName(), dataType.getDescription()); - switch (dataType.getTypeCategory()) { - case ENUM: - visitor.visitEnumeration((EnumType)dataType); - break; - - case STRUCT: - StructType structType = (StructType) dataType; - processType(typeSystem, dataType.getTypeCategory(), dataType.getName(), dataType.getDescription(), - ImmutableList.copyOf(structType.infoToNameMap.keySet()), ImmutableSet.<String>of(), visitor); - break; - - case TRAIT: - case CLASS: - HierarchicalType type = (HierarchicalType) dataType; - processType(typeSystem, dataType.getTypeCategory(), dataType.getName(), type.getDescription(), type.immediateAttrs, - type.superTypes, visitor); - break; - - default: //Ignore primitive/collection types as they are covered under references - break; - } - } - } - - private Map<String, AtlasVertex> getOrCreateTypeVertices(TypeSystem typeSystem, ImmutableList<String> typeNames) throws AtlasException { - - //examine the types to determine what type vertices are needed - TypeVertexFinder vertexFinder = new TypeVertexFinder(typeSystem); - processTypes(typeNames, typeSystem, vertexFinder); - List<TypeVertexInfo> typeVerticesNeeded = vertexFinder.getVerticesToCreate(); - - //find or create the type vertices - List<AtlasVertex> vertices = createVertices(typeVerticesNeeded); - - //Create a type name->AtlasVertex map with the result - Map<String, AtlasVertex> result = new HashMap<>(typeVerticesNeeded.size()); - for(int i = 0 ; i < typeVerticesNeeded.size(); i++) { - TypeVertexInfo createdVertexInfo = typeVerticesNeeded.get(i); - AtlasVertex createdVertex = vertices.get(i); - result.put(createdVertexInfo.getTypeName(), createdVertex); - } - return result; - - } - - - static String getPropertyKey(String name) { - return PROPERTY_PREFIX + name; - } - - static String getPropertyKey(String parent, String child) { - return PROPERTY_PREFIX + parent + "." + child; - } - - static String getEdgeLabel(String parent, String child) { - return PROPERTY_PREFIX + "edge." + parent + "." + child; - } - - private void processType(TypeSystem typeSystem, DataTypes.TypeCategory category, String typeName, String typeDescription, - ImmutableList<AttributeInfo> attributes, ImmutableSet<String> superTypes, TypeVisitor visitor) throws AtlasException { - - visitor.visitDataType(category, typeName, typeDescription); - - List<String> attrNames = new ArrayList<>(); - if (attributes != null) { - for (AttributeInfo attribute : attributes) { - visitor.visitAttribute(typeName, attribute); - attrNames.add(attribute.name); - processsAttribute(typeSystem, typeName, attribute, visitor); - } - } - visitor.visitAttributeNames(typeName, attrNames); - - //Add edges for hierarchy - if (superTypes != null) { - for (String superTypeName : superTypes) { - visitor.visitSuperType(typeName, superTypeName); - } - } - } - - private void processsAttribute(TypeSystem typeSystem, String typeName, AttributeInfo attribute, TypeVisitor visitor) - throws AtlasException { - - ImmutableList<String> coreTypes = typeSystem.getCoreTypes(); - List<IDataType> attrDataTypes = new ArrayList<>(); - IDataType attrDataType = attribute.dataType(); - - - switch (attrDataType.getTypeCategory()) { - case ARRAY: - String attrType = TypeUtils.parseAsArrayType(attrDataType.getName()); - if(attrType != null) { - IDataType elementType = typeSystem.getDataType(IDataType.class, attrType); - attrDataTypes.add(elementType); - } - break; - - case MAP: - String[] attrTypes = TypeUtils.parseAsMapType(attrDataType.getName()); - if(attrTypes != null && attrTypes.length > 1) { - IDataType keyType = typeSystem.getDataType(IDataType.class, attrTypes[0]); - IDataType valueType = typeSystem.getDataType(IDataType.class, attrTypes[1]); - attrDataTypes.add(keyType); - attrDataTypes.add(valueType); - } - break; - - case ENUM: - case STRUCT: - case CLASS: - attrDataTypes.add(attrDataType); - break; - - case PRIMITIVE: //no vertex for primitive type, hence no edge required - break; - - default: - throw new IllegalArgumentException( - "Attribute cannot reference instances of type : " + attrDataType.getTypeCategory()); - } - - - for (IDataType attrType : attrDataTypes) { - if (!coreTypes.contains(attrType.getName())) { - visitor.visitAttributeDataType(typeName, attribute, attrType); - } - } - } - - @Override - @GraphTransaction - public TypesDef restore() throws AtlasException { - //Get all vertices for type system - Iterator vertices = - graph.query().has(Constants.VERTEX_TYPE_PROPERTY_KEY, VERTEX_TYPE).vertices().iterator(); - - return getTypesFromVertices(vertices); - } - - @Override - @GraphTransaction - public TypesDef restoreType(String typeName) throws AtlasException { - // Get AtlasVertex for the specified type name. - Iterator vertices = - graph.query().has(Constants.VERTEX_TYPE_PROPERTY_KEY, VERTEX_TYPE).has(Constants.TYPENAME_PROPERTY_KEY, typeName).vertices().iterator(); - - return getTypesFromVertices(vertices); - } - - private TypesDef getTypesFromVertices(Iterator<AtlasVertex> vertices) throws AtlasException { - ImmutableList.Builder<EnumTypeDefinition> enums = ImmutableList.builder(); - ImmutableList.Builder<StructTypeDefinition> structs = ImmutableList.builder(); - ImmutableList.Builder<HierarchicalTypeDefinition<ClassType>> classTypes = ImmutableList.builder(); - ImmutableList.Builder<HierarchicalTypeDefinition<TraitType>> traits = ImmutableList.builder(); - - while (vertices.hasNext()) { - AtlasVertex vertex = vertices.next(); - DataTypes.TypeCategory typeCategory = GraphHelper.getSingleValuedProperty(vertex, Constants.TYPE_CATEGORY_PROPERTY_KEY, TypeCategory.class); - String typeName = GraphHelper.getSingleValuedProperty(vertex, Constants.TYPENAME_PROPERTY_KEY, String.class); - String typeDescription = GraphHelper.getSingleValuedProperty(vertex, Constants.TYPEDESCRIPTION_PROPERTY_KEY, String.class); - LOG.info("Restoring type {}.{}.{}", typeCategory, typeName, typeDescription); - switch (typeCategory) { - case ENUM: - enums.add(getEnumType(vertex)); - break; - - case STRUCT: - AttributeDefinition[] attributes = getAttributes(vertex, typeName); - structs.add(new StructTypeDefinition(typeName, typeDescription, attributes)); - break; - - case CLASS: - ImmutableSet<String> superTypes = getSuperTypes(vertex); - attributes = getAttributes(vertex, typeName); - classTypes.add(new HierarchicalTypeDefinition(ClassType.class, typeName, typeDescription, superTypes, attributes)); - break; - - case TRAIT: - superTypes = getSuperTypes(vertex); - attributes = getAttributes(vertex, typeName); - traits.add(new HierarchicalTypeDefinition(TraitType.class, typeName, typeDescription, superTypes, attributes)); - break; - - case RELATIONSHIP: - // v1 typesystem is not notified on new relation type - break; - - default: - throw new IllegalArgumentException("Unhandled type category " + typeCategory); - } - } - return TypesUtil.getTypesDef(enums.build(), structs.build(), traits.build(), classTypes.build()); - } - - private EnumTypeDefinition getEnumType(AtlasVertex vertex) throws AtlasException { - String typeName = GraphHelper.getSingleValuedProperty(vertex, Constants.TYPENAME_PROPERTY_KEY, String.class); - String typeDescription = GraphHelper.getSingleValuedProperty(vertex, Constants.TYPEDESCRIPTION_PROPERTY_KEY, String.class); - List<EnumValue> enumValues = new ArrayList<>(); - List<String> values = GraphHelper.getListProperty(vertex, getPropertyKey(typeName)); - for (String value : values) { - String valueProperty = getPropertyKey(typeName, value); - enumValues.add(new EnumValue(value, GraphHelper.getSingleValuedProperty(vertex, valueProperty, Integer.class))); - } - return new EnumTypeDefinition(typeName, typeDescription, enumValues.toArray(new EnumValue[enumValues.size()])); - } - - private ImmutableSet<String> getSuperTypes(AtlasVertex vertex) { - Set<String> superTypes = new HashSet<>(); - for (AtlasEdge edge : (Iterable<AtlasEdge>) vertex.getEdges(AtlasEdgeDirection.OUT, SUPERTYPE_EDGE_LABEL)) { - superTypes.add(edge.getInVertex().getProperty(Constants.TYPENAME_PROPERTY_KEY, String.class)); - } - return ImmutableSet.copyOf(superTypes); - } - - private AttributeDefinition[] getAttributes(AtlasVertex vertex, String typeName) throws AtlasException { - List<AttributeDefinition> attributes = new ArrayList<>(); - List<String> attrNames = GraphHelper.getListProperty(vertex, getPropertyKey(typeName)); - if (attrNames != null) { - for (String attrName : attrNames) { - try { - String encodedPropertyKey = GraphHelper.encodePropertyKey(getPropertyKey(typeName, attrName)); - AttributeDefinition attrValue = AttributeInfo.fromJson((String) vertex.getJsonProperty(encodedPropertyKey)); - if (attrValue != null) - { - attributes.add(attrValue); - } - } catch (JSONException e) { - throw new AtlasException(e); - } - } - } - return attributes.toArray(new AttributeDefinition[attributes.size()]); - } - - /** - * Find vertex for the given type category and name, else create new vertex - * @param category - * @param typeName - * @return vertex - */ - AtlasVertex findVertex(DataTypes.TypeCategory category, String typeName) { - LOG.debug("Finding AtlasVertex for {}.{}", category, typeName); - - Iterator results = graph.query().has(Constants.TYPENAME_PROPERTY_KEY, typeName).vertices().iterator(); - AtlasVertex vertex = null; - if (results != null && results.hasNext()) { - //There should be just one AtlasVertex with the given typeName - vertex = (AtlasVertex) results.next(); - } - return vertex; - } - - //package-private for testing - Map<String, AtlasVertex> findVertices(List<String> typeNames) throws RepositoryException { - LOG.debug("Finding vertices for {}", typeNames.toString()); - Map<String, AtlasVertex> foundVertices = graphHelper.getVerticesForPropertyValues(Constants.TYPENAME_PROPERTY_KEY, typeNames); - return foundVertices; - - } - - - /** - * Finds or creates type vertices with the information specified. - * - * @param infoList - * @return list with the vertices corresponding to the types in the list. - * @throws AtlasException - */ - private List<AtlasVertex> createVertices(List<TypeVertexInfo> infoList) throws AtlasException { - - List<AtlasVertex> result = new ArrayList<>(infoList.size()); - List<String> typeNames = Lists.transform(infoList, new Function<TypeVertexInfo,String>() { - @Override - public String apply(TypeVertexInfo input) { - return input.getTypeName(); - } - }); - Map<String, AtlasVertex> vertices = findVertices(typeNames); - - for(TypeVertexInfo info : infoList) { - AtlasVertex vertex = vertices.get(info.getTypeName()); - if (! GraphHelper.elementExists(vertex)) { - LOG.debug("Adding vertex {}{}", PROPERTY_PREFIX, info.getTypeName()); - vertex = graph.addVertex(); - setProperty(vertex, Constants.VERTEX_TYPE_PROPERTY_KEY, VERTEX_TYPE); // Mark as type AtlasVertex - setProperty(vertex, Constants.TYPE_CATEGORY_PROPERTY_KEY, info.getCategory()); - setProperty(vertex, Constants.TYPENAME_PROPERTY_KEY, info.getTypeName()); - } - String newDescription = info.getTypeDescription(); - if (newDescription != null) { - String oldDescription = getPropertyKey(Constants.TYPEDESCRIPTION_PROPERTY_KEY); - if (!newDescription.equals(oldDescription)) { - setProperty(vertex, Constants.TYPEDESCRIPTION_PROPERTY_KEY, newDescription); - } - } else { - LOG.debug(" type description is null "); - } - result.add(vertex); - } - return result; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/typestore/ITypeStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/typestore/ITypeStore.java b/repository/src/main/java/org/apache/atlas/repository/typestore/ITypeStore.java deleted file mode 100755 index 84779f4..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/typestore/ITypeStore.java +++ /dev/null @@ -1,53 +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.typestore; - -import com.google.common.collect.ImmutableList; -import org.apache.atlas.AtlasException; -import org.apache.atlas.typesystem.TypesDef; -import org.apache.atlas.typesystem.types.TypeSystem; - -@Deprecated -public interface ITypeStore { - - /** - * Add types to the underlying type storage layer - * @param typeSystem {@link TypeSystem} object which contains existing types. To lookup newly added types, - * an instance of {@link TypeSystem.TransientTypeSystem} can be passed. - * @param types names of newly added types. - * @throws AtlasException - */ - void store(TypeSystem typeSystem, ImmutableList<String> types) throws AtlasException; - - /** - * Restore all type definitions - * @return List of persisted type definitions - * @throws AtlasException - */ - TypesDef restore() throws AtlasException; - - /** - * Restore the specified type definition - * - * @param typeName name of requested type - * @return persisted type definition - * @throws AtlasException - */ - TypesDef restoreType(String typeName) throws AtlasException; -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/typestore/StorageException.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/typestore/StorageException.java b/repository/src/main/java/org/apache/atlas/repository/typestore/StorageException.java deleted file mode 100755 index c4f64f8..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/typestore/StorageException.java +++ /dev/null @@ -1,35 +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.typestore; - -import org.apache.atlas.AtlasException; - -public class StorageException extends AtlasException { - public StorageException(String type) { - super("Failure in typesystem storage for type " + type); - } - - public StorageException(String type, Throwable cause) { - super("Failure in typesystem storage for type " + type, cause); - } - - public StorageException(Throwable cause) { - super("Failure in type system storage", cause); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/typestore/StoreBackedTypeCache.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/typestore/StoreBackedTypeCache.java b/repository/src/main/java/org/apache/atlas/repository/typestore/StoreBackedTypeCache.java deleted file mode 100644 index f472fa6..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/typestore/StoreBackedTypeCache.java +++ /dev/null @@ -1,239 +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.typestore; - -import com.google.common.collect.ImmutableList; -import org.apache.atlas.AtlasException; -import org.apache.atlas.annotation.ConditionalOnAtlasProperty; -import org.apache.atlas.typesystem.TypesDef; -import org.apache.atlas.typesystem.types.AttributeDefinition; -import org.apache.atlas.typesystem.types.ClassType; -import org.apache.atlas.typesystem.types.EnumTypeDefinition; -import org.apache.atlas.typesystem.types.HierarchicalTypeDefinition; -import org.apache.atlas.typesystem.types.IDataType; -import org.apache.atlas.typesystem.types.StructTypeDefinition; -import org.apache.atlas.typesystem.types.TraitType; -import org.apache.atlas.typesystem.types.TypeSystem; -import org.apache.atlas.typesystem.types.TypeSystem.TransientTypeSystem; -import org.apache.atlas.typesystem.types.TypeUtils; -import org.apache.atlas.typesystem.types.cache.DefaultTypeCache; -import org.apache.atlas.typesystem.types.utils.TypesUtil; -import org.springframework.stereotype.Component; - -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - - -/** - * An extension of {@link DefaultTypeCache} which loads - * the requested type from the type store if it is not found in the cache, - * and adds it to the cache if it's found in the store. - * Any attribute and super types that are required by the requested type - * are also loaded from the store if they are not already in the cache. - */ -@Singleton -@Component -@Deprecated -@ConditionalOnAtlasProperty(property = "atlas.TypeCache.impl") -public class StoreBackedTypeCache extends DefaultTypeCache { - - private ITypeStore typeStore; - - private ImmutableList<String> coreTypes; - private TypeSystem typeSystem; - - @Inject - public StoreBackedTypeCache(final ITypeStore typeStore) { - this.typeStore = typeStore; - typeSystem = TypeSystem.getInstance(); - coreTypes = typeSystem.getCoreTypes(); - } - - private static class Context { - ImmutableList.Builder<EnumTypeDefinition> enums = ImmutableList.builder(); - ImmutableList.Builder<StructTypeDefinition> structs = ImmutableList.builder(); - ImmutableList.Builder<HierarchicalTypeDefinition<ClassType>> classTypes = ImmutableList.builder(); - ImmutableList.Builder<HierarchicalTypeDefinition<TraitType>> traits = ImmutableList.builder(); - Set<String> loadedFromStore = new HashSet<>(); - - public void addTypesDefToLists(TypesDef typesDef) { - - List<EnumTypeDefinition> enumTypesAsJavaList = typesDef.enumTypesAsJavaList(); - enums.addAll(enumTypesAsJavaList); - for (EnumTypeDefinition etd : enumTypesAsJavaList) { - loadedFromStore.add(etd.name); - } - List<StructTypeDefinition> structTypesAsJavaList = typesDef.structTypesAsJavaList(); - structs.addAll(structTypesAsJavaList); - for (StructTypeDefinition std : structTypesAsJavaList) { - loadedFromStore.add(std.typeName); - } - List<HierarchicalTypeDefinition<ClassType>> classTypesAsJavaList = typesDef.classTypesAsJavaList(); - classTypes.addAll(classTypesAsJavaList); - for (HierarchicalTypeDefinition<ClassType> classTypeDef : classTypesAsJavaList) { - loadedFromStore.add(classTypeDef.typeName); - } - List<HierarchicalTypeDefinition<TraitType>> traitTypesAsJavaList = typesDef.traitTypesAsJavaList(); - traits.addAll(traitTypesAsJavaList); - for (HierarchicalTypeDefinition<TraitType> traitTypeDef : traitTypesAsJavaList) { - loadedFromStore.add(traitTypeDef.typeName); - } - } - - public boolean isLoadedFromStore(String typeName) { - return loadedFromStore.contains(typeName); - } - - public TypesDef getTypesDef() { - return TypesUtil.getTypesDef(enums.build(), structs.build(), traits.build(), classTypes.build()); - } - } - - /** - * Checks whether the specified type is cached in memory and does *not* - * access the type store. Used for testing. - * - * @param typeName - * @return - */ - public boolean isCachedInMemory(String typeName) throws AtlasException { - return super.has(typeName); - } - - /** - * Check the type store for the requested type. - * If found in the type store, the type and any required super and attribute types - * are loaded from the type store, and added to the cache. - */ - @Override - public IDataType onTypeFault(String typeName) throws AtlasException { - - // Type is not cached - check the type store. - // Any super and attribute types needed by the requested type - // which are not cached will also be loaded from the store. - Context context = new Context(); - TypesDef typesDef = getTypeFromStore(typeName, context); - if (typesDef.isEmpty()) { - // Type not found in the type store. - return null; - } - - // Add all types that were loaded from the store to the cache. - TransientTypeSystem transientTypeSystem = typeSystem.createTransientTypeSystem(context.getTypesDef(), false); - Map<String, IDataType> typesAdded = transientTypeSystem.getTypesAdded(); - putAll(typesAdded.values()); - return typesAdded.get(typeName); - } - - private void getTypeFromCacheOrStore(String typeName, Context context) - throws AtlasException { - - if (coreTypes.contains(typeName) || super.has(typeName)) { - return; - } - - if (context.isLoadedFromStore(typeName)) { - return; - } - - // Type not cached and hasn't been loaded during this operation, so check the store. - TypesDef typesDef = getTypeFromStore(typeName, context); - if (typesDef.isEmpty()) { - // Attribute type not found in cache or store. - throw new AtlasException(typeName + " not found in type store"); - } - } - - private TypesDef getTypeFromStore(String typeName, Context context) - throws AtlasException { - - TypesDef typesDef = typeStore.restoreType(typeName); - if (!typesDef.isEmpty()) { - // Type found in store, add it to lists. - context.addTypesDefToLists(typesDef); - - // Check the attribute and super types that are - // used by the requested type, and restore them - // as needed. - checkAttributeAndSuperTypes(typesDef, context); - } - return typesDef; - } - - private void checkAttributeAndSuperTypes(TypesDef typesDef, Context context) - throws AtlasException { - - // Check the cache and store for attribute types and super types. - for (HierarchicalTypeDefinition<ClassType> classTypeDef : typesDef.classTypesAsJavaList()) { - checkAttributeTypes(classTypeDef.attributeDefinitions, context); - for (String superTypeName : classTypeDef.superTypes) { - getTypeFromCacheOrStore(superTypeName, context); - } - } - for (HierarchicalTypeDefinition<TraitType> traitTypeDef : typesDef.traitTypesAsJavaList()) { - checkAttributeTypes(traitTypeDef.attributeDefinitions, context); - for (String superTypeName : traitTypeDef.superTypes) { - getTypeFromCacheOrStore(superTypeName, context); - } - } - for (StructTypeDefinition structTypeDef : typesDef.structTypesAsJavaList()) { - checkAttributeTypes(structTypeDef.attributeDefinitions, context); - } - } - - private void checkAttributeTypes(AttributeDefinition[] attributeDefinitions, - Context context) throws AtlasException { - - for (AttributeDefinition attrDef : attributeDefinitions) { - checkAttributeType(attrDef, context); - } - } - - private void checkAttributeType(AttributeDefinition attrDef, Context context) throws AtlasException { - - List<String> typeNamesToLookup = new ArrayList<>(2); - - // Get the attribute type(s). - String elementTypeName = TypeUtils.parseAsArrayType(attrDef.dataTypeName); - if (elementTypeName != null) { - // Array attribute, lookup the element type. - typeNamesToLookup.add(elementTypeName); - } - else { - String[] mapTypeNames = TypeUtils.parseAsMapType(attrDef.dataTypeName); - if (mapTypeNames != null) { - // Map attribute, lookup the key and value types. - typeNamesToLookup.addAll(Arrays.asList(mapTypeNames)); - } - else { - // Not an array or map, lookup the attribute type. - typeNamesToLookup.add(attrDef.dataTypeName); - } - } - - for (String typeName : typeNamesToLookup) { - getTypeFromCacheOrStore(typeName, context); - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/typestore/TypePersistenceVisitor.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/typestore/TypePersistenceVisitor.java b/repository/src/main/java/org/apache/atlas/repository/typestore/TypePersistenceVisitor.java deleted file mode 100644 index bfb1bfc..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/typestore/TypePersistenceVisitor.java +++ /dev/null @@ -1,116 +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.typestore; - -import static org.apache.atlas.repository.graph.GraphHelper.setProperty; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.apache.atlas.AtlasException; -import org.apache.atlas.repository.Constants; -import org.apache.atlas.repository.RepositoryException; -import org.apache.atlas.repository.graph.GraphHelper; -import org.apache.atlas.repository.graphdb.AtlasVertex; -import org.apache.atlas.typesystem.types.AttributeInfo; -import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; -import org.apache.atlas.typesystem.types.EnumType; -import org.apache.atlas.typesystem.types.EnumValue; -import org.apache.atlas.typesystem.types.HierarchicalType; -import org.apache.atlas.typesystem.types.IDataType; -import org.apache.atlas.typesystem.types.TypeSystem; -import org.codehaus.jettison.json.JSONException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * TypeVisitor implementation that completes the type storage process by - * adding the required properties and edges to the type vertices - * that were created. - */ -public class TypePersistenceVisitor implements TypeVisitor { - - private static final Logger LOG = LoggerFactory.getLogger(TypePersistenceVisitor.class); - private static final GraphHelper graphHelper = GraphHelper.getInstance(); - - private final GraphBackedTypeStore typeStore_; - private final Map<String,AtlasVertex> typeVertices; - private final TypeSystem typeSystem; - - /** - * @param graphBackedTypeStore - */ - public TypePersistenceVisitor(GraphBackedTypeStore graphBackedTypeStore, Map<String,AtlasVertex> typeVertices, TypeSystem typeSystem) { - typeStore_ = graphBackedTypeStore; - this.typeVertices = typeVertices; - this.typeSystem = typeSystem; - } - - @Override - public void visitEnumeration(EnumType dataType) throws AtlasException { - AtlasVertex vertex = typeVertices.get(dataType.getName()); - List<String> values = new ArrayList<>(dataType.values().size()); - for (EnumValue enumValue : dataType.values()) { - String key = GraphBackedTypeStore.getPropertyKey(dataType.getName(), enumValue.value); - setProperty(vertex, key, enumValue.ordinal); - values.add(enumValue.value); - } - setProperty(vertex, GraphBackedTypeStore.getPropertyKey(dataType.getName()), values); - - } - @Override - public void visitAttributeDataType(String typeName, AttributeInfo attribute, IDataType attrType) throws AtlasException { - AtlasVertex vertex = typeVertices.get(typeName); - String vertexTypeName = GraphHelper.getSingleValuedProperty(vertex, Constants.TYPENAME_PROPERTY_KEY, String.class); - AtlasVertex attrVertex = typeVertices.get(attrType.getName()); - String label = GraphBackedTypeStore.getEdgeLabel(vertexTypeName, attribute.name); - graphHelper.getOrCreateEdge(vertex, attrVertex, label); - } - @Override - public void visitSuperType(String typeName, String superTypeName) throws AtlasException { - AtlasVertex vertex = typeVertices.get(typeName); - HierarchicalType superType = typeSystem.getDataType(HierarchicalType.class, superTypeName); - AtlasVertex superVertex = typeVertices.get(superTypeName); - graphHelper.getOrCreateEdge(vertex, superVertex, GraphBackedTypeStore.SUPERTYPE_EDGE_LABEL); - } - - @Override - public void visitAttributeNames(String typeName, List<String> attrNames) throws AtlasException { - AtlasVertex vertex = typeVertices.get(typeName); - setProperty(vertex, GraphBackedTypeStore.getPropertyKey(typeName), attrNames); - - } - - @Override - public void visitAttribute(String typeName, AttributeInfo attribute) throws AtlasException { - AtlasVertex vertex = typeVertices.get(typeName); - String propertyKey = GraphBackedTypeStore.getPropertyKey(typeName, attribute.name); - try { - setProperty(vertex, propertyKey, attribute.toJson()); - } catch (JSONException e) { - throw new StorageException(typeName, e); - } - } - - @Override - public void visitDataType(TypeCategory category, String typeName, String typeDescription) { - //nothing to do - - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/typestore/TypeVertexFinder.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/typestore/TypeVertexFinder.java b/repository/src/main/java/org/apache/atlas/repository/typestore/TypeVertexFinder.java deleted file mode 100644 index 8b38152..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/typestore/TypeVertexFinder.java +++ /dev/null @@ -1,103 +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.typestore; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.apache.atlas.AtlasException; -import org.apache.atlas.typesystem.types.AttributeInfo; -import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; -import org.apache.atlas.typesystem.types.EnumType; -import org.apache.atlas.typesystem.types.HierarchicalType; -import org.apache.atlas.typesystem.types.IDataType; -import org.apache.atlas.typesystem.types.TypeSystem; - -/** - * TypeVisitor implementation that builds up a list of type vertices - * that need to be created for the types that are being stored. - * - */ -public class TypeVertexFinder implements TypeVisitor { - - private final List<TypeVertexInfo> toCreate = new ArrayList<TypeVertexInfo>(); - private final Set<String> typesIncluded = new HashSet<String>(); - private final TypeSystem typeSystem; - - public TypeVertexFinder(TypeSystem ts) { - typeSystem = ts; - } - - - @Override - public void visitEnumeration(EnumType dataType) { - visitDataType(dataType); - } - - private void addTypeIfNeeded(TypeVertexInfo info) { - if(! typesIncluded.contains(info.getTypeName())) { - toCreate.add(info); - typesIncluded.add(info.getTypeName()); - } - } - - @Override - public void visitAttributeDataType(String typeName, AttributeInfo sourceAttr, IDataType attrType) throws AtlasException { - visitDataType(attrType); - } - - @Override - public void visitSuperType(String typeName, String superTypeName) throws AtlasException { - HierarchicalType superType = typeSystem.getDataType(HierarchicalType.class, superTypeName); - visitDataType(superType); - } - - @Override - public void visitAttributeNames(String typeName, List<String> attrNames) throws AtlasException { - //nothing to do - - } - - @Override - public void visitAttribute(String typeName, AttributeInfo attribute) throws StorageException, AtlasException { - //nothing to do - } - - - private void visitDataType(IDataType dataType) { - TypeVertexInfo info = null; - info = new TypeVertexInfo(dataType.getTypeCategory(), dataType.getName(), dataType.getDescription()); - addTypeIfNeeded(info); - - } - - - public List<TypeVertexInfo> getVerticesToCreate() { - return toCreate; - } - - @Override - public void visitDataType(TypeCategory category, String typeName, String typeDescription) { - TypeVertexInfo info = new TypeVertexInfo(category, typeName, typeDescription); - addTypeIfNeeded(info); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/typestore/TypeVertexInfo.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/typestore/TypeVertexInfo.java b/repository/src/main/java/org/apache/atlas/repository/typestore/TypeVertexInfo.java deleted file mode 100644 index 32a9a19..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/typestore/TypeVertexInfo.java +++ /dev/null @@ -1,94 +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.typestore; - -import java.util.Objects; - -import org.apache.atlas.typesystem.types.DataTypes; -import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; - -/** - * Records the information needed to create a particular type vertex. - */ -public class TypeVertexInfo { - - private DataTypes.TypeCategory category; - private String typeName; - private String typeDescription; - - public TypeVertexInfo(TypeCategory category, String typeName, String typeDescription) { - super(); - this.category = category; - this.typeName = typeName; - this.typeDescription = typeDescription; - } - - public DataTypes.TypeCategory getCategory() { - return category; - } - - public void setCategory(DataTypes.TypeCategory category) { - this.category = category; - } - - public String getTypeName() { - return typeName; - } - - public void setTypeName(String typeName) { - this.typeName = typeName; - } - - public String getTypeDescription() { - return typeDescription; - } - - public void setTypeDescription(String typeDescription) { - this.typeDescription = typeDescription; - } - - @Override - public int hashCode() { - return Objects.hash(category, typeName); - } - - @Override - public boolean equals(Object obj) { - - if (this == obj) { - return true; - } - - if (getClass() != obj.getClass()) { - return false; - } - - TypeVertexInfo other = (TypeVertexInfo)obj; - if(! Objects.equals(category, other.category)) { - return false; - } - - if(! Objects.equals(typeName, other.typeName)) { - return false; - } - - return true; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/main/java/org/apache/atlas/repository/typestore/TypeVisitor.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/typestore/TypeVisitor.java b/repository/src/main/java/org/apache/atlas/repository/typestore/TypeVisitor.java deleted file mode 100644 index a6e353c..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/typestore/TypeVisitor.java +++ /dev/null @@ -1,96 +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.typestore; - -import java.util.List; - -import org.apache.atlas.AtlasException; -import org.apache.atlas.repository.RepositoryException; -import org.apache.atlas.typesystem.types.AttributeInfo; -import org.apache.atlas.typesystem.types.DataTypes.TypeCategory; -import org.apache.atlas.typesystem.types.EnumType; -import org.apache.atlas.typesystem.types.IDataType; - -/** - * Callback mechanism used when storing types. As {@link GraphBackedTypeStore} traverses - * through the types being persisted, these methods are called with the information that - * it finds. - */ -public interface TypeVisitor { - - /** - * Called when an enumeration type is found - * @param type - * @throws AtlasException - */ - void visitEnumeration(EnumType type) throws AtlasException; - - /** - * Called with a data type that is associated with a given attribute. There can - * be more than one. For example, map types have both a key and a value type. - * This is called once for each type. This is called once for each datatype - * associated with the given attribute. - * - * @param typeName The name of the type being processed. - * @param sourceAttr The attribute in that type that we are processing. - * @param attrType A dataType associated with that attribute. - * @throws AtlasException - */ - void visitAttributeDataType(String typeName, AttributeInfo sourceAttr, IDataType attrType) throws AtlasException; - - /** - * Called when a super type is found. It is called once for each superType. - * - * @param typeName The type being processed. - * @param superType The name of the super type that was found. - * @throws RepositoryException - * @throws AtlasException - */ - void visitSuperType(String typeName, String superType) throws RepositoryException, AtlasException; - - /** - * Called with the list of immediate attribute names that were found for the given type. It - * is called once per type. - * - * @param typeName The name of the type that is being processed. - * @param attrNames The names of all of the immediate attributes in the type. - * @throws AtlasException - */ - void visitAttributeNames(String typeName, List<String> attrNames) throws AtlasException; - - /** - * Called once for each immediate attribute in a type. - * @param typeName The name of the type that is being procesed - * @param attribute The immediate attribute that was found - * - * @throws StorageException - * @throws AtlasException - */ - void visitAttribute(String typeName, AttributeInfo attribute) throws StorageException, AtlasException; - - /** - * Called once for each struct, class, and trait type that was found. It is - * called when we start processing that type. - * - * @param category The category of the type - * @param typeName The name of the type - * @param typeDescription The description of the type. - */ - void visitDataType(TypeCategory category, String typeName, String typeDescription); -} \ No newline at end of file