http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/repository/src/main/java/org/apache/atlas/repository/memory/HierarchicalTypeStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/memory/HierarchicalTypeStore.java b/repository/src/main/java/org/apache/atlas/repository/memory/HierarchicalTypeStore.java deleted file mode 100755 index 429730c..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/memory/HierarchicalTypeStore.java +++ /dev/null @@ -1,207 +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.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import org.apache.atlas.repository.RepositoryException; -import org.apache.atlas.typesystem.persistence.Id; -import org.apache.atlas.typesystem.persistence.ReferenceableInstance; -import org.apache.atlas.typesystem.persistence.StructInstance; -import org.apache.atlas.typesystem.types.AttributeInfo; -import org.apache.atlas.typesystem.types.HierarchicalType; -import org.apache.atlas.typesystem.types.IConstructableType; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -@Deprecated -public abstract class HierarchicalTypeStore { - - final MemRepository repository; - final IConstructableType hierarchicalType; - final ArrayList<String> typeNameList; - final ImmutableMap<AttributeInfo, IAttributeStore> attrStores; - final ImmutableList<HierarchicalTypeStore> superTypeStores; - - - /** - * Map Id to position in storage lists. - */ - Map<Id, Integer> idPosMap; - - List<Integer> freePositions; - - int nextPos; - - /** - * Lock for each Class/Trait. - */ - ReentrantReadWriteLock lock; - - HierarchicalTypeStore(MemRepository repository, HierarchicalType hierarchicalType) throws RepositoryException { - this.hierarchicalType = (IConstructableType) hierarchicalType; - this.repository = repository; - ImmutableMap.Builder<AttributeInfo, IAttributeStore> b = - new ImmutableBiMap.Builder<>(); - typeNameList = Lists.newArrayList((String) null); - ImmutableList<AttributeInfo> l = hierarchicalType.immediateAttrs; - for (AttributeInfo i : l) { - b.put(i, AttributeStores.createStore(i)); - } - attrStores = b.build(); - - ImmutableList.Builder<HierarchicalTypeStore> b1 = new ImmutableList.Builder<>(); - Set<String> allSuperTypeNames = hierarchicalType.getAllSuperTypeNames(); - for (String s : allSuperTypeNames) { - b1.add(repository.getStore(s)); - } - superTypeStores = b1.build(); - - nextPos = 0; - idPosMap = new HashMap<>(); - freePositions = new ArrayList<>(); - - lock = new ReentrantReadWriteLock(); - } - - /** - * Assign a storage position to an Id. - * - try to assign from freePositions - * - ensure storage capacity. - * - add entry in idPosMap. - * @param id - * @return - * @throws RepositoryException - */ - int assignPosition(Id id) throws RepositoryException { - - int pos = -1; - if (!freePositions.isEmpty()) { - pos = freePositions.remove(0); - } else { - pos = nextPos++; - ensureCapacity(pos); - } - - idPosMap.put(id, pos); - - for (HierarchicalTypeStore s : superTypeStores) { - s.assignPosition(id); - } - - return pos; - } - - /** - * - remove from idPosMap - * - add to freePositions. - * @throws RepositoryException - */ - void releaseId(Id id) { - - Integer pos = idPosMap.get(id); - if (pos != null) { - idPosMap.remove(id); - freePositions.add(pos); - - for (HierarchicalTypeStore s : superTypeStores) { - s.releaseId(id); - } - } - } - - void acquireReadLock() { - lock.readLock().lock(); - } - - void acquireWriteLock() { - lock.writeLock().lock(); - } - - void releaseReadLock() { - lock.readLock().unlock(); - } - - void releaseWriteLock() { - lock.writeLock().unlock(); - } - - protected void storeFields(int pos, StructInstance s) throws RepositoryException { - for (Map.Entry<AttributeInfo, IAttributeStore> e : attrStores.entrySet()) { - IAttributeStore attributeStore = e.getValue(); - attributeStore.store(pos, hierarchicalType, s); - } - } - - protected void loadFields(int pos, StructInstance s) throws RepositoryException { - for (Map.Entry<AttributeInfo, IAttributeStore> e : attrStores.entrySet()) { - IAttributeStore attributeStore = e.getValue(); - attributeStore.load(pos, hierarchicalType, s); - } - } - - /** - * - store the typeName - * - store the immediate attributes in the respective IAttributeStore - * - call store on each SuperType. - * @param i - * @throws RepositoryException - */ - void store(ReferenceableInstance i) throws RepositoryException { - int pos = idPosMap.get(i.getId()); - typeNameList.set(pos, i.getTypeName()); - storeFields(pos, i); - - for (HierarchicalTypeStore s : superTypeStores) { - s.store(i); - } - } - - /** - * - copy over the immediate attribute values from the respective IAttributeStore - * - call load on each SuperType. - * @param i - * @throws RepositoryException - */ - void load(ReferenceableInstance i) throws RepositoryException { - int pos = idPosMap.get(i.getId()); - loadFields(pos, i); - - for (HierarchicalTypeStore s : superTypeStores) { - s.load(i); - } - } - - public void ensureCapacity(int pos) throws RepositoryException { - while (typeNameList.size() < pos + 1) { - typeNameList.add(null); - } - for (Map.Entry<AttributeInfo, IAttributeStore> e : attrStores.entrySet()) { - IAttributeStore attributeStore = e.getValue(); - attributeStore.ensureCapacity(pos); - } - } -}
http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/repository/src/main/java/org/apache/atlas/repository/memory/IAttributeStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/memory/IAttributeStore.java b/repository/src/main/java/org/apache/atlas/repository/memory/IAttributeStore.java deleted file mode 100755 index b8cbe05..0000000 --- a/repository/src/main/java/org/apache/atlas/repository/memory/IAttributeStore.java +++ /dev/null @@ -1,49 +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.StructInstance; -import org.apache.atlas.typesystem.types.IConstructableType; - -@Deprecated -public interface IAttributeStore { - /** - * Store the attribute's value from the 'instance' into this store. - * @param pos - * @param instance - * @throws RepositoryException - */ - void store(int pos, IConstructableType type, StructInstance instance) throws RepositoryException; - - /** - * load the Instance with the value from position 'pos' for the attribute. - * @param pos - * @param instance - * @throws RepositoryException - */ - void load(int pos, IConstructableType type, StructInstance instance) throws RepositoryException; - - /** - * Ensure store have space for the given pos. - * @param pos - * @throws RepositoryException - */ - void ensureCapacity(int pos) throws RepositoryException; -} http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/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/0877e47c/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/0877e47c/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/0877e47c/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/0877e47c/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..88b76cc 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.model.v1.instance.Referenceable; +import org.apache.atlas.model.v1.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,13 +91,14 @@ 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; } + /* TODO: for (EntityChangeListener listener : entityChangeListeners) { try { listener.onTraitsAdded(entity, traits); @@ -105,18 +106,20 @@ public class AtlasEntityChangeNotifier { throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitAdd"); } } + */ } public void onClassificationDeletedFromEntity(String entityId, List<String> traitNames) throws AtlasBaseException { // 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; } + /* TODO: for (EntityChangeListener listener : entityChangeListeners) { try { listener.onTraitsDeleted(entity, traitNames); @@ -124,19 +127,21 @@ public class AtlasEntityChangeNotifier { throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitDelete"); } } + */ } public void onClassificationUpdatedToEntity(String entityId, List<AtlasClassification> classifications) throws AtlasBaseException { // 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; } + /* TODO: for (EntityChangeListener listener : entityChangeListeners) { try { listener.onTraitsUpdated(entity, traits); @@ -144,6 +149,7 @@ public class AtlasEntityChangeNotifier { throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), "TraitUpdate"); } } + */ } private String getListenerName(EntityChangeListener listener) { @@ -155,8 +161,9 @@ public class AtlasEntityChangeNotifier { return; } - List<ITypedReferenceableInstance> typedRefInsts = toITypedReferenceable(entityHeaders); + List<Referenceable> typedRefInsts = toReferenceables(entityHeaders); + /* TODO: for (EntityChangeListener listener : entityChangeListeners) { try { switch (operation) { @@ -175,30 +182,33 @@ public class AtlasEntityChangeNotifier { throw new AtlasBaseException(AtlasErrorCode.NOTIFICATION_FAILED, e, getListenerName(listener), operation.toString()); } } + */ } - 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; + /* TODO: 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/0877e47c/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..583fc6f 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 @@ -58,7 +58,7 @@ public class AtlasGraphUtilsV1 { public static final String PROPERTY_PREFIX = Constants.INTERNAL_PROPERTY_KEY_PREFIX + "type."; public static final String SUPERTYPE_EDGE_LABEL = PROPERTY_PREFIX + ".supertype"; public static final String ENTITYTYPE_EDGE_LABEL = PROPERTY_PREFIX + ".entitytype"; - public static final String VERTEX_TYPE = "typeSystem"; + public static final String VERTEX_TYPE = "typeRegistry"; public static final String RELATIONSHIPTYPE_EDGE_LABEL = PROPERTY_PREFIX + ".relationshipType"; private static boolean USE_INDEX_QUERY_TO_FIND_ENTITY_BY_UNIQUE_ATTRIBUTES = false; http://git-wip-us.apache.org/repos/asf/atlas/blob/0877e47c/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..ad6c255 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.model.v1.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/0877e47c/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/0877e47c/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/0877e47c/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/0877e47c/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/0877e47c/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/0877e47c/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