Return-Path: X-Original-To: apmail-atlas-commits-archive@minotaur.apache.org Delivered-To: apmail-atlas-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D44E718FEB for ; Fri, 12 Jun 2015 20:40:47 +0000 (UTC) Received: (qmail 98472 invoked by uid 500); 12 Jun 2015 20:40:47 -0000 Delivered-To: apmail-atlas-commits-archive@atlas.apache.org Received: (qmail 98452 invoked by uid 500); 12 Jun 2015 20:40:47 -0000 Mailing-List: contact commits-help@atlas.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@atlas.incubator.apache.org Delivered-To: mailing list commits@atlas.incubator.apache.org Received: (qmail 98439 invoked by uid 99); 12 Jun 2015 20:40:47 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Jun 2015 20:40:47 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 12 Jun 2015 20:36:36 +0000 Received: (qmail 94288 invoked by uid 99); 12 Jun 2015 20:38:22 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Jun 2015 20:38:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 22AABE180E; Fri, 12 Jun 2015 20:38:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: venkatesh@apache.org To: commits@atlas.incubator.apache.org Date: Fri, 12 Jun 2015 20:38:33 -0000 Message-Id: <47c319a1f13a4ac99501f424fdecc8ff@git.apache.org> In-Reply-To: <229524f4b62b4addac63bc5dde2ad83b@git.apache.org> References: <229524f4b62b4addac63bc5dde2ad83b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [13/50] [abbrv] incubator-atlas git commit: IDE java code reformat X-Virus-Checked: Checked by ClamAV on apache.org http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java index 02036f4..d617bd2 100755 --- a/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java +++ b/repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java @@ -45,11 +45,10 @@ public final class GraphHelper { private GraphHelper() { } - public static Vertex createVertexWithIdentity(Graph graph, - ITypedReferenceableInstance typedInstance, - Set superTypeNames) { - final Vertex vertexWithIdentity = createVertexWithoutIdentity( - graph, typedInstance.getTypeName(), typedInstance.getId(), superTypeNames); + public static Vertex createVertexWithIdentity(Graph graph, ITypedReferenceableInstance typedInstance, + Set superTypeNames) { + final Vertex vertexWithIdentity = + createVertexWithoutIdentity(graph, typedInstance.getTypeName(), typedInstance.getId(), superTypeNames); // add identity final String guid = UUID.randomUUID().toString(); @@ -58,10 +57,8 @@ public final class GraphHelper { return vertexWithIdentity; } - public static Vertex createVertexWithoutIdentity(Graph graph, - String typeName, - Id typedInstanceId, - Set superTypeNames) { + public static Vertex createVertexWithoutIdentity(Graph graph, String typeName, Id typedInstanceId, + Set superTypeNames) { final Vertex vertexWithoutIdentity = graph.addVertex(null); // add type information @@ -69,34 +66,28 @@ public final class GraphHelper { // add super types for (String superTypeName : superTypeNames) { - ((TitanVertex) vertexWithoutIdentity).addProperty( - Constants.SUPER_TYPES_PROPERTY_KEY, superTypeName); + ((TitanVertex) vertexWithoutIdentity).addProperty(Constants.SUPER_TYPES_PROPERTY_KEY, superTypeName); } // add version information vertexWithoutIdentity.setProperty(Constants.VERSION_PROPERTY_KEY, typedInstanceId.version); // add timestamp information - vertexWithoutIdentity.setProperty( - Constants.TIMESTAMP_PROPERTY_KEY, System.currentTimeMillis()); + vertexWithoutIdentity.setProperty(Constants.TIMESTAMP_PROPERTY_KEY, System.currentTimeMillis()); return vertexWithoutIdentity; } - public static Edge addEdge(TitanGraph titanGraph, Vertex fromVertex, Vertex toVertex, - String edgeLabel) { - LOG.debug("Adding edge for {} -> label {} -> {}", - fromVertex, edgeLabel, toVertex); + public static Edge addEdge(TitanGraph titanGraph, Vertex fromVertex, Vertex toVertex, String edgeLabel) { + LOG.debug("Adding edge for {} -> label {} -> {}", fromVertex, edgeLabel, toVertex); return titanGraph.addEdge(null, fromVertex, toVertex, edgeLabel); } - public static Vertex findVertexByGUID(TitanGraph titanGraph, - String value) { + public static Vertex findVertexByGUID(TitanGraph titanGraph, String value) { LOG.debug("Finding vertex for key={}, value={}", Constants.GUID_PROPERTY_KEY, value); - GraphQuery query = titanGraph.query() - .has(Constants.GUID_PROPERTY_KEY, value); + GraphQuery query = titanGraph.query().has(Constants.GUID_PROPERTY_KEY, value); Iterator results = query.vertices().iterator(); // returning one since guid should be unique return results.hasNext() ? results.next() : null; @@ -105,20 +96,15 @@ public final class GraphHelper { public static String vertexString(final Vertex vertex) { StringBuilder properties = new StringBuilder(); for (String propertyKey : vertex.getPropertyKeys()) { - properties.append(propertyKey) - .append("=").append(vertex.getProperty(propertyKey)) - .append(", "); + properties.append(propertyKey).append("=").append(vertex.getProperty(propertyKey)).append(", "); } return "v[" + vertex.getId() + "], Properties[" + properties + "]"; } public static String edgeString(final Edge edge) { - return "e[" + edge.getLabel() + "], [" - + edge.getVertex(Direction.OUT) - + " -> " + edge.getLabel() + " -> " - + edge.getVertex(Direction.IN) - + "]"; + return "e[" + edge.getLabel() + "], [" + edge.getVertex(Direction.OUT) + " -> " + edge.getLabel() + " -> " + + edge.getVertex(Direction.IN) + "]"; } /* http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/repository/src/main/java/org/apache/atlas/repository/memory/AttributeStores.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/memory/AttributeStores.java b/repository/src/main/java/org/apache/atlas/repository/memory/AttributeStores.java index 59cf67d..2a6969b 100755 --- a/repository/src/main/java/org/apache/atlas/repository/memory/AttributeStores.java +++ b/repository/src/main/java/org/apache/atlas/repository/memory/AttributeStores.java @@ -49,48 +49,46 @@ public class AttributeStores { static IAttributeStore createStore(AttributeInfo i) throws RepositoryException { switch (i.dataType().getTypeCategory()) { - case PRIMITIVE: - if (i.dataType() == DataTypes.BOOLEAN_TYPE) { - return new BooleanAttributeStore(i); - } else if (i.dataType() == DataTypes.BYTE_TYPE) { - return new ByteAttributeStore(i); - } else if (i.dataType() == DataTypes.SHORT_TYPE) { - new ShortAttributeStore(i); - } else if (i.dataType() == DataTypes.INT_TYPE) { - return new IntAttributeStore(i); - } else if (i.dataType() == DataTypes.LONG_TYPE) { - return new LongAttributeStore(i); - } else if (i.dataType() == DataTypes.FLOAT_TYPE) { - return new FloatAttributeStore(i); - } else if (i.dataType() == DataTypes.DOUBLE_TYPE) { - return new DoubleAttributeStore(i); - } else if (i.dataType() == DataTypes.BIGINTEGER_TYPE) { - return new BigIntStore(i); - } else if (i.dataType() == DataTypes.BIGDECIMAL_TYPE) { - return new BigDecimalStore(i); - } else if (i.dataType() == DataTypes.DATE_TYPE) { - return new DateStore(i); - } else if (i.dataType() == DataTypes.STRING_TYPE) { - return new StringStore(i); - } else if (i.dataType() == DataTypes.STRING_TYPE) { - return new StringStore(i); - } else { - throw new RepositoryException( - String.format("Unknown datatype %s", i.dataType())); - } - case ENUM: + case PRIMITIVE: + if (i.dataType() == DataTypes.BOOLEAN_TYPE) { + return new BooleanAttributeStore(i); + } else if (i.dataType() == DataTypes.BYTE_TYPE) { + return new ByteAttributeStore(i); + } else if (i.dataType() == DataTypes.SHORT_TYPE) { + new ShortAttributeStore(i); + } else if (i.dataType() == DataTypes.INT_TYPE) { return new IntAttributeStore(i); - case ARRAY: - return new ImmutableListStore(i); - case MAP: - return new ImmutableMapStore(i); - case STRUCT: - return new StructStore(i); - case CLASS: - return new IdStore(i); - default: - throw new RepositoryException( - String.format("Unknown Category for datatype %s", i.dataType())); + } else if (i.dataType() == DataTypes.LONG_TYPE) { + return new LongAttributeStore(i); + } else if (i.dataType() == DataTypes.FLOAT_TYPE) { + return new FloatAttributeStore(i); + } else if (i.dataType() == DataTypes.DOUBLE_TYPE) { + return new DoubleAttributeStore(i); + } else if (i.dataType() == DataTypes.BIGINTEGER_TYPE) { + return new BigIntStore(i); + } else if (i.dataType() == DataTypes.BIGDECIMAL_TYPE) { + return new BigDecimalStore(i); + } else if (i.dataType() == DataTypes.DATE_TYPE) { + return new DateStore(i); + } else if (i.dataType() == DataTypes.STRING_TYPE) { + return new StringStore(i); + } else if (i.dataType() == DataTypes.STRING_TYPE) { + return new StringStore(i); + } else { + throw new RepositoryException(String.format("Unknown datatype %s", i.dataType())); + } + case ENUM: + return new IntAttributeStore(i); + case ARRAY: + return new ImmutableListStore(i); + case MAP: + return new ImmutableMapStore(i); + case STRUCT: + return new StructStore(i); + case CLASS: + return new IdStore(i); + default: + throw new RepositoryException(String.format("Unknown Category for datatype %s", i.dataType())); } } @@ -113,8 +111,7 @@ public class AttributeStores { return nullList.get(pos); } - void storeHiddenVals(int pos, IConstructableType type, StructInstance instance) - throws RepositoryException { + void storeHiddenVals(int pos, IConstructableType type, StructInstance instance) throws RepositoryException { List attrNames = type.getNames(attrInfo); Map m = hiddenVals.get(pos); if (m == null) { @@ -134,8 +131,7 @@ public class AttributeStores { } } - void loadHiddenVals(int pos, IConstructableType type, StructInstance instance) - throws RepositoryException { + void loadHiddenVals(int pos, IConstructableType type, StructInstance instance) throws RepositoryException { List attrNames = type.getNames(attrInfo); Map m = hiddenVals.get(pos); for (int i = 2; i < attrNames.size(); i++) { @@ -153,8 +149,7 @@ public class AttributeStores { } @Override - public void store(int pos, IConstructableType type, StructInstance instance) - throws RepositoryException { + public void store(int pos, IConstructableType type, StructInstance instance) throws RepositoryException { List attrNames = type.getNames(attrInfo); String attrName = attrNames.get(0); int nullPos = instance.fieldMapping().fieldNullPos.get(attrName); @@ -175,8 +170,7 @@ public class AttributeStores { } @Override - public void load(int pos, IConstructableType type, StructInstance instance) - throws RepositoryException { + public void load(int pos, IConstructableType type, StructInstance instance) throws RepositoryException { List attrNames = type.getNames(attrInfo); String attrName = attrNames.get(0); int nullPos = instance.fieldMapping().fieldNullPos.get(attrName); @@ -197,20 +191,17 @@ public class AttributeStores { /* * store the value from colPos in instance into the list. */ - protected abstract void store(StructInstance instance, int colPos, int pos) - throws RepositoryException; + protected abstract void store(StructInstance instance, int colPos, int pos) throws RepositoryException; /* * load the value from pos in list into colPos in instance. */ - protected abstract void load(StructInstance instance, int colPos, int pos) - throws RepositoryException; + protected abstract void load(StructInstance instance, int colPos, int pos) throws RepositoryException; /* * store the value from colPos in map as attrName */ - protected abstract void store(StructInstance instance, int colPos, String attrName, - Map m); + protected abstract void store(StructInstance instance, int colPos, String attrName, Map m); /* * load the val into colPos in instance. @@ -219,8 +210,7 @@ public class AttributeStores { } - static abstract class PrimitiveAttributeStore extends AbstractAttributeStore - implements IAttributeStore { + static abstract class PrimitiveAttributeStore extends AbstractAttributeStore implements IAttributeStore { public PrimitiveAttributeStore(AttributeInfo attrInfo) { @@ -246,8 +236,7 @@ public class AttributeStores { instance.bools[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.bools[colPos]); } @@ -279,8 +268,7 @@ public class AttributeStores { instance.bytes[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.bytes[colPos]); } @@ -312,8 +300,7 @@ public class AttributeStores { instance.shorts[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.shorts[colPos]); } @@ -345,8 +332,7 @@ public class AttributeStores { instance.ints[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.ints[colPos]); } @@ -378,8 +364,7 @@ public class AttributeStores { instance.longs[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.longs[colPos]); } @@ -411,8 +396,7 @@ public class AttributeStores { instance.floats[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.floats[colPos]); } @@ -444,8 +428,7 @@ public class AttributeStores { instance.doubles[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.doubles[colPos]); } @@ -492,8 +475,7 @@ public class AttributeStores { instance.bigIntegers[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.bigIntegers[colPos]); } @@ -517,8 +499,7 @@ public class AttributeStores { instance.bigDecimals[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.bigDecimals[colPos]); } @@ -542,8 +523,7 @@ public class AttributeStores { instance.dates[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.dates[colPos]); } @@ -567,8 +547,7 @@ public class AttributeStores { instance.strings[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.strings[colPos]); } @@ -592,8 +571,7 @@ public class AttributeStores { instance.ids[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.ids[colPos]); } @@ -617,8 +595,7 @@ public class AttributeStores { instance.arrays[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.arrays[colPos]); } @@ -642,8 +619,7 @@ public class AttributeStores { instance.maps[colPos] = list.get(pos); } - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.maps[colPos]); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/repository/src/main/java/org/apache/atlas/repository/memory/ClassStore.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/repository/memory/ClassStore.java b/repository/src/main/java/org/apache/atlas/repository/memory/ClassStore.java index b6b787b..7fcfffe 100755 --- a/repository/src/main/java/org/apache/atlas/repository/memory/ClassStore.java +++ b/repository/src/main/java/org/apache/atlas/repository/memory/ClassStore.java @@ -32,8 +32,7 @@ public class ClassStore extends HierarchicalTypeStore { final ArrayList> traitNamesStore; final ClassType classType; - public ClassStore(MemRepository repository, ClassType hierarchicalType) - throws RepositoryException { + public ClassStore(MemRepository repository, ClassType hierarchicalType) throws RepositoryException { super(repository, hierarchicalType); classType = hierarchicalType; traitNamesStore = new ArrayList>(); @@ -64,8 +63,7 @@ public class ClassStore extends HierarchicalTypeStore { String typeName = typeNameList.get(pos); if (typeName != hierarchicalType.getName()) { throw new RepositoryException( - String.format("Invalid Id (incorrect typeName, type is %s) : %s", - typeName, id)); + String.format("Invalid Id (incorrect typeName, type is %s) : %s", typeName, id)); } return true; http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/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 index c9e245b..d7acf97 100755 --- a/repository/src/main/java/org/apache/atlas/repository/memory/HierarchicalTypeStore.java +++ b/repository/src/main/java/org/apache/atlas/repository/memory/HierarchicalTypeStore.java @@ -60,13 +60,11 @@ public abstract class HierarchicalTypeStore { */ ReentrantReadWriteLock lock; - HierarchicalTypeStore(MemRepository repository, HierarchicalType hierarchicalType) - throws RepositoryException { + HierarchicalTypeStore(MemRepository repository, HierarchicalType hierarchicalType) throws RepositoryException { this.hierarchicalType = (IConstructableType) hierarchicalType; this.repository = repository; - ImmutableMap.Builder b - = new ImmutableBiMap.Builder(); + ImmutableMap.Builder b = + new ImmutableBiMap.Builder(); typeNameList = Lists.newArrayList((String) null); ImmutableList l = hierarchicalType.immediateAttrs; for (AttributeInfo i : l) { @@ -74,8 +72,7 @@ public abstract class HierarchicalTypeStore { } attrStores = b.build(); - ImmutableList.Builder b1 - = new ImmutableList.Builder(); + ImmutableList.Builder b1 = new ImmutableList.Builder(); Set allSuperTypeNames = hierarchicalType.getAllSuperTypeNames(); for (String s : allSuperTypeNames) { b1.add(repository.getStore(s)); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/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 index cce239b..3ceac01 100755 --- a/repository/src/main/java/org/apache/atlas/repository/memory/IAttributeStore.java +++ b/repository/src/main/java/org/apache/atlas/repository/memory/IAttributeStore.java @@ -29,8 +29,7 @@ public interface IAttributeStore { * @param instance * @throws RepositoryException */ - void store(int pos, IConstructableType type, StructInstance 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. http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/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 index c7981e0..4cf0a72 100755 --- a/repository/src/main/java/org/apache/atlas/repository/memory/MemRepository.java +++ b/repository/src/main/java/org/apache/atlas/repository/memory/MemRepository.java @@ -129,9 +129,8 @@ public class MemRepository implements IRepository { */ 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)); + throw new RepositoryException(String.format("Invalid Object Graph: " + + "Encountered an unassignedId %s that is not associated with an Instance", oldId)); } } @@ -140,18 +139,14 @@ public class MemRepository implements IRepository { * - create a ITypedReferenceableInstance. * replace any old References ( ids or object references) with new Ids. */ - List newInstances - = new ArrayList(); + List newInstances = new ArrayList(); ITypedReferenceableInstance retInstance = null; Set classTypes = new TreeSet(); Set traitTypes = new TreeSet(); - for (IReferenceableInstance transientInstance : discoverInstances.idToInstanceMap - .values()) { + for (IReferenceableInstance transientInstance : discoverInstances.idToInstanceMap.values()) { try { - ClassType cT = typeSystem - .getDataType(ClassType.class, transientInstance.getTypeName()); - ITypedReferenceableInstance newInstance = cT - .convert(transientInstance, Multiplicity.REQUIRED); + ClassType cT = typeSystem.getDataType(ClassType.class, transientInstance.getTypeName()); + ITypedReferenceableInstance newInstance = cT.convert(transientInstance, Multiplicity.REQUIRED); newInstances.add(newInstance); classTypes.add(cT); @@ -172,8 +167,7 @@ public class MemRepository implements IRepository { } catch (AtlasException me) { throw new RepositoryException( - String.format("Failed to create Instance(id = %s", - transientInstance.getId()), me); + String.format("Failed to create Instance(id = %s", transientInstance.getId()), me); } } @@ -237,8 +231,7 @@ public class MemRepository implements IRepository { return retInstance; } - public ITypedReferenceableInstance update(ITypedReferenceableInstance i) - throws RepositoryException { + public ITypedReferenceableInstance update(ITypedReferenceableInstance i) throws RepositoryException { throw new RepositoryException("not implemented"); } @@ -267,8 +260,7 @@ public class MemRepository implements IRepository { * - load instance traits * - add to GraphWalker */ - ITypedReferenceableInstance getDuringWalk(Id id, ObjectGraphWalker walker) - throws RepositoryException { + 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())); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/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 index b53b971..86141e2 100755 --- a/repository/src/main/java/org/apache/atlas/repository/memory/ReplaceIdWithInstance.java +++ b/repository/src/main/java/org/apache/atlas/repository/memory/ReplaceIdWithInstance.java @@ -67,22 +67,18 @@ public class ReplaceIdWithInstance implements ObjectGraphWalker.NodeProcessor { 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)); + nd.instance.set(nd.attributeName, convertToInstances((ImmutableMap) nd.value, nd.aInfo.multiplicity, mT)); } } - ImmutableCollection convertToInstances(ImmutableCollection val, - Multiplicity m, DataTypes.ArrayType arrType) + ImmutableCollection convertToInstances(ImmutableCollection val, Multiplicity m, DataTypes.ArrayType arrType) throws AtlasException { - if (val == null || - arrType.getElemType().getTypeCategory() != DataTypes.TypeCategory.CLASS) { + if (val == null || arrType.getElemType().getTypeCategory() != DataTypes.TypeCategory.CLASS) { return val; } - ImmutableCollection.Builder b = m.isUnique ? ImmutableSet.builder() - : ImmutableList.builder(); + ImmutableCollection.Builder b = m.isUnique ? ImmutableSet.builder() : ImmutableList.builder(); Iterator it = val.iterator(); while (it.hasNext()) { Object elem = it.next(); @@ -97,13 +93,11 @@ public class ReplaceIdWithInstance implements ObjectGraphWalker.NodeProcessor { return b.build(); } - ImmutableMap convertToInstances(ImmutableMap val, Multiplicity m, - DataTypes.MapType mapType) + 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)) { + if (val == null || (mapType.getKeyType().getTypeCategory() != DataTypes.TypeCategory.CLASS + && mapType.getValueType().getTypeCategory() != DataTypes.TypeCategory.CLASS)) { return val; } ImmutableMap.Builder b = ImmutableMap.builder(); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/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 index fb84e13..f0331d9 100755 --- a/repository/src/main/java/org/apache/atlas/repository/memory/StructStore.java +++ b/repository/src/main/java/org/apache/atlas/repository/memory/StructStore.java @@ -65,8 +65,7 @@ public class StructStore extends AttributeStores.AbstractAttributeStore implemen } @Override - protected void store(StructInstance instance, int colPos, String attrName, - Map m) { + protected void store(StructInstance instance, int colPos, String attrName, Map m) { m.put(attrName, instance.structs[colPos]); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/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 index cd9c8ee..9d73cc9 100755 --- a/repository/src/main/java/org/apache/atlas/repository/memory/TraitStore.java +++ b/repository/src/main/java/org/apache/atlas/repository/memory/TraitStore.java @@ -29,8 +29,7 @@ public class TraitStore extends HierarchicalTypeStore { final ArrayList classNameStore; - public TraitStore(MemRepository repository, TraitType hierarchicalType) - throws RepositoryException { + public TraitStore(MemRepository repository, TraitType hierarchicalType) throws RepositoryException { super(repository, hierarchicalType); classNameStore = new ArrayList<>(); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/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 index 92fc315..eed297f 100755 --- a/repository/src/main/java/org/apache/atlas/repository/typestore/GraphBackedTypeStore.java +++ b/repository/src/main/java/org/apache/atlas/repository/typestore/GraphBackedTypeStore.java @@ -25,8 +25,8 @@ import com.thinkaurelius.titan.core.TitanGraph; import com.tinkerpop.blueprints.Direction; import com.tinkerpop.blueprints.Edge; import com.tinkerpop.blueprints.Vertex; -import org.apache.atlas.GraphTransaction; import org.apache.atlas.AtlasException; +import org.apache.atlas.GraphTransaction; import org.apache.atlas.repository.Constants; import org.apache.atlas.repository.graph.GraphProvider; import org.apache.atlas.typesystem.TypesDef; @@ -80,25 +80,25 @@ public class GraphBackedTypeStore implements ITypeStore { IDataType dataType = typeSystem.getDataType(IDataType.class, typeName); LOG.debug("Processing {}.{} in type store", dataType.getTypeCategory(), dataType.getName()); switch (dataType.getTypeCategory()) { - case ENUM: - storeInGraph((EnumType)dataType); - break; - - case STRUCT: - StructType structType = (StructType) dataType; - storeInGraph(typeSystem, dataType.getTypeCategory(), dataType.getName(), - ImmutableList.copyOf(structType.infoToNameMap.keySet()), ImmutableList.of()); - break; - - case TRAIT: - case CLASS: - HierarchicalType type = (HierarchicalType) dataType; - storeInGraph(typeSystem, dataType.getTypeCategory(), dataType.getName(), - type.immediateAttrs, type.superTypes); - break; - - default: //Ignore primitive/collection types as they are covered under references - break; + case ENUM: + storeInGraph((EnumType) dataType); + break; + + case STRUCT: + StructType structType = (StructType) dataType; + storeInGraph(typeSystem, dataType.getTypeCategory(), dataType.getName(), + ImmutableList.copyOf(structType.infoToNameMap.keySet()), ImmutableList.of()); + break; + + case TRAIT: + case CLASS: + HierarchicalType type = (HierarchicalType) dataType; + storeInGraph(typeSystem, dataType.getTypeCategory(), dataType.getName(), type.immediateAttrs, + type.superTypes); + break; + + default: //Ignore primitive/collection types as they are covered under references + break; } } } @@ -132,8 +132,7 @@ public class GraphBackedTypeStore implements ITypeStore { } private void storeInGraph(TypeSystem typeSystem, DataTypes.TypeCategory category, String typeName, - ImmutableList attributes, ImmutableList superTypes) throws - AtlasException { + ImmutableList attributes, ImmutableList superTypes) throws AtlasException { Vertex vertex = createVertex(category, typeName); List attrNames = new ArrayList<>(); if (attributes != null) { @@ -161,39 +160,40 @@ public class GraphBackedTypeStore implements ITypeStore { } //Add edges for complex attributes - private void addReferencesForAttribute(TypeSystem typeSystem, Vertex vertex, AttributeInfo attribute) throws - AtlasException { + private void addReferencesForAttribute(TypeSystem typeSystem, Vertex vertex, AttributeInfo attribute) + throws AtlasException { ImmutableList coreTypes = typeSystem.getCoreTypes(); List attrDataTypes = new ArrayList<>(); IDataType attrDataType = attribute.dataType(); String vertexTypeName = vertex.getProperty(Constants.TYPENAME_PROPERTY_KEY); switch (attrDataType.getTypeCategory()) { - case ARRAY: - String attrType = TypeUtils.parseAsArrayType(attrDataType.getName()); - IDataType elementType = typeSystem.getDataType(IDataType.class, attrType); - attrDataTypes.add(elementType); - break; - - case MAP: - String[] attrTypes = TypeUtils.parseAsMapType(attrDataType.getName()); - 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()); + case ARRAY: + String attrType = TypeUtils.parseAsArrayType(attrDataType.getName()); + IDataType elementType = typeSystem.getDataType(IDataType.class, attrType); + attrDataTypes.add(elementType); + break; + + case MAP: + String[] attrTypes = TypeUtils.parseAsMapType(attrDataType.getName()); + 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) { http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java b/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java index 46968da..f494a4a 100755 --- a/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java +++ b/repository/src/main/java/org/apache/atlas/services/DefaultMetadataService.java @@ -21,12 +21,11 @@ package org.apache.atlas.services; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.inject.Provider; -import org.apache.atlas.AtlasException; import org.apache.atlas.AtlasClient; +import org.apache.atlas.AtlasException; import org.apache.atlas.ParamChecker; import org.apache.atlas.TypeNotFoundException; import org.apache.atlas.classification.InterfaceAudience; -import org.apache.atlas.discovery.SearchIndexer; import org.apache.atlas.listener.EntityChangeListener; import org.apache.atlas.listener.TypesChangeListener; import org.apache.atlas.repository.IndexCreationException; @@ -55,17 +54,14 @@ import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import scala.actors.threadpool.Arrays; import javax.inject.Inject; import javax.inject.Singleton; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Set; /** * Simple wrapper over TypeSystem and MetadataRepository services with hooks @@ -74,11 +70,9 @@ import java.util.Set; @Singleton public class DefaultMetadataService implements MetadataService { - private static final Logger LOG = - LoggerFactory.getLogger(DefaultMetadataService.class); + private static final Logger LOG = LoggerFactory.getLogger(DefaultMetadataService.class); - private final Collection entityChangeListeners - = new LinkedHashSet<>(); + private final Collection entityChangeListeners = new LinkedHashSet<>(); private final TypeSystem typeSystem; private final MetadataRepository repository; @@ -87,7 +81,7 @@ public class DefaultMetadataService implements MetadataService { @Inject DefaultMetadataService(final MetadataRepository repository, final ITypeStore typeStore, - final Collection> typeChangeListeners) throws AtlasException { + final Collection> typeChangeListeners) throws AtlasException { this.typeStore = typeStore; this.typeSystem = TypeSystem.getInstance(); this.repository = repository; @@ -122,22 +116,20 @@ public class DefaultMetadataService implements MetadataService { return; // this is already registered } - HierarchicalTypeDefinition infraType = - TypesUtil.createClassTypeDef(AtlasClient.INFRASTRUCTURE_SUPER_TYPE, - ImmutableList.of(), NAME_ATTRIBUTE, DESCRIPTION_ATTRIBUTE); + HierarchicalTypeDefinition infraType = TypesUtil + .createClassTypeDef(AtlasClient.INFRASTRUCTURE_SUPER_TYPE, ImmutableList.of(), NAME_ATTRIBUTE, + DESCRIPTION_ATTRIBUTE); HierarchicalTypeDefinition datasetType = TypesUtil - .createClassTypeDef(AtlasClient.DATA_SET_SUPER_TYPE, - ImmutableList.of(), - NAME_ATTRIBUTE, DESCRIPTION_ATTRIBUTE); + .createClassTypeDef(AtlasClient.DATA_SET_SUPER_TYPE, ImmutableList.of(), NAME_ATTRIBUTE, + DESCRIPTION_ATTRIBUTE); HierarchicalTypeDefinition processType = TypesUtil - .createClassTypeDef(AtlasClient.PROCESS_SUPER_TYPE, ImmutableList.of(), - NAME_ATTRIBUTE, DESCRIPTION_ATTRIBUTE, new AttributeDefinition("inputs", - DataTypes.arrayTypeName(AtlasClient.DATA_SET_SUPER_TYPE), + .createClassTypeDef(AtlasClient.PROCESS_SUPER_TYPE, ImmutableList.of(), NAME_ATTRIBUTE, + DESCRIPTION_ATTRIBUTE, + new AttributeDefinition("inputs", DataTypes.arrayTypeName(AtlasClient.DATA_SET_SUPER_TYPE), Multiplicity.OPTIONAL, false, null), - new AttributeDefinition("outputs", - DataTypes.arrayTypeName(AtlasClient.DATA_SET_SUPER_TYPE), + new AttributeDefinition("outputs", DataTypes.arrayTypeName(AtlasClient.DATA_SET_SUPER_TYPE), Multiplicity.OPTIONAL, false, null)); TypesDef typesDef = TypeUtils @@ -234,8 +226,7 @@ public class DefaultMetadataService implements MetadataService { public String createEntity(String entityInstanceDefinition) throws AtlasException { ParamChecker.notEmpty(entityInstanceDefinition, "Entity instance definition cannot be empty"); - ITypedReferenceableInstance entityTypedInstance = - deserializeClassInstance(entityInstanceDefinition); + ITypedReferenceableInstance entityTypedInstance = deserializeClassInstance(entityInstanceDefinition); final String guid = repository.createEntity(entityTypedInstance); @@ -243,13 +234,12 @@ public class DefaultMetadataService implements MetadataService { return guid; } - private ITypedReferenceableInstance deserializeClassInstance( - String entityInstanceDefinition) throws AtlasException { + private ITypedReferenceableInstance deserializeClassInstance(String entityInstanceDefinition) + throws AtlasException { final Referenceable entityInstance; try { - entityInstance = InstanceSerialization.fromJsonReferenceable( - entityInstanceDefinition, true); + entityInstance = InstanceSerialization.fromJsonReferenceable(entityInstanceDefinition, true); } catch (Exception e) { // exception from deserializer LOG.error("Unable to deserialize json={}", entityInstanceDefinition, e); throw new IllegalArgumentException("Unable to deserialize json"); @@ -327,8 +317,7 @@ public class DefaultMetadataService implements MetadataService { * @throws AtlasException */ @Override - public void addTrait(String guid, - String traitInstanceDefinition) throws AtlasException { + public void addTrait(String guid, String traitInstanceDefinition) throws AtlasException { ParamChecker.notEmpty(guid, "entity GUID cannot be null"); ParamChecker.notEmpty(traitInstanceDefinition, "Trait instance cannot be null"); @@ -336,34 +325,32 @@ public class DefaultMetadataService implements MetadataService { final String traitName = traitInstance.getTypeName(); // ensure trait type is already registered with the TS - if ( !typeSystem.isRegistered(traitName) ) { + if (!typeSystem.isRegistered(traitName)) { String msg = String.format("trait=%s should be defined in type system before it can be added", traitName); LOG.error(msg); throw new TypeNotFoundException(msg); } // ensure trait is not already defined - Preconditions.checkArgument(!getTraitNames(guid).contains(traitName), - "trait=%s is already defined for entity=%s", traitName, guid); + Preconditions + .checkArgument(!getTraitNames(guid).contains(traitName), "trait=%s is already defined for entity=%s", + traitName, guid); repository.addTrait(guid, traitInstance); onTraitAddedToEntity(guid, traitName); } - private ITypedStruct deserializeTraitInstance(String traitInstanceDefinition) - throws AtlasException { + private ITypedStruct deserializeTraitInstance(String traitInstanceDefinition) throws AtlasException { try { - Struct traitInstance = InstanceSerialization.fromJsonStruct( - traitInstanceDefinition, true); + Struct traitInstance = InstanceSerialization.fromJsonStruct(traitInstanceDefinition, true); final String entityTypeName = traitInstance.getTypeName(); ParamChecker.notEmpty(entityTypeName, "entity type cannot be null"); TraitType traitType = typeSystem.getDataType(TraitType.class, entityTypeName); - return traitType.convert( - traitInstance, Multiplicity.REQUIRED); - } catch ( TypeNotFoundException e ) { + return traitType.convert(traitInstance, Multiplicity.REQUIRED); + } catch (TypeNotFoundException e) { throw e; } catch (Exception e) { throw new AtlasException("Error deserializing trait instance", e); @@ -378,13 +365,12 @@ public class DefaultMetadataService implements MetadataService { * @throws AtlasException */ @Override - public void deleteTrait(String guid, - String traitNameToBeDeleted) throws AtlasException { + public void deleteTrait(String guid, String traitNameToBeDeleted) throws AtlasException { ParamChecker.notEmpty(guid, "entity GUID cannot be null"); ParamChecker.notEmpty(traitNameToBeDeleted, "Trait name cannot be null"); // ensure trait type is already registered with the TS - if ( !typeSystem.isRegistered(traitNameToBeDeleted)) { + if (!typeSystem.isRegistered(traitNameToBeDeleted)) { final String msg = String.format("trait=%s should be defined in type system before it can be deleted", traitNameToBeDeleted); LOG.error(msg); @@ -398,7 +384,7 @@ public class DefaultMetadataService implements MetadataService { private void onTypesAdded(Map typesAdded) throws AtlasException { Map caughtExceptions = new HashMap<>(); - for(Provider indexerProvider : typeChangeListeners) { + for (Provider indexerProvider : typeChangeListeners) { final TypesChangeListener listener = indexerProvider.get(); try { listener.onAdd(typesAdded.values()); @@ -409,27 +395,24 @@ public class DefaultMetadataService implements MetadataService { } if (caughtExceptions.size() > 0) { - throw new IndexCreationException("Index creation failed for types " + typesAdded.keySet() + ". Aborting"); + throw new IndexCreationException("Index creation failed for types " + typesAdded.keySet() + ". Aborting"); } } - private void onEntityAddedToRepo(ITypedReferenceableInstance typedInstance) - throws AtlasException { + private void onEntityAddedToRepo(ITypedReferenceableInstance typedInstance) throws AtlasException { for (EntityChangeListener listener : entityChangeListeners) { listener.onEntityAdded(typedInstance); } } - private void onTraitAddedToEntity(String typeName, - String traitName) throws AtlasException { + private void onTraitAddedToEntity(String typeName, String traitName) throws AtlasException { for (EntityChangeListener listener : entityChangeListeners) { listener.onTraitAdded(typeName, traitName); } } - private void onTraitDeletedFromEntity(String typeName, - String traitName) throws AtlasException { + private void onTraitDeletedFromEntity(String typeName, String traitName) throws AtlasException { for (EntityChangeListener listener : entityChangeListeners) { listener.onTraitDeleted(typeName, traitName); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/repository/src/main/java/org/apache/atlas/services/MetadataService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/services/MetadataService.java b/repository/src/main/java/org/apache/atlas/services/MetadataService.java index 8728ab6..8f82f88 100755 --- a/repository/src/main/java/org/apache/atlas/services/MetadataService.java +++ b/repository/src/main/java/org/apache/atlas/services/MetadataService.java @@ -94,6 +94,7 @@ public interface MetadataService { void updateEntity(String guid, String property, String value) throws AtlasException; // Trait management functions + /** * Gets the list of trait names for a given entity represented by a guid. * @@ -110,8 +111,7 @@ public interface MetadataService { * @param traitInstanceDefinition trait instance that needs to be added to entity * @throws AtlasException */ - void addTrait(String guid, - String traitInstanceDefinition) throws AtlasException; + void addTrait(String guid, String traitInstanceDefinition) throws AtlasException; /** * Deletes a given trait from an existing entity represented by a guid. @@ -120,6 +120,5 @@ public interface MetadataService { * @param traitNameToBeDeleted name of the trait * @throws AtlasException */ - void deleteTrait(String guid, - String traitNameToBeDeleted) throws AtlasException; + void deleteTrait(String guid, String traitNameToBeDeleted) throws AtlasException; } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/repository/src/test/java/org/apache/atlas/TestUtils.java ---------------------------------------------------------------------- diff --git a/repository/src/test/java/org/apache/atlas/TestUtils.java b/repository/src/test/java/org/apache/atlas/TestUtils.java index a734a06..de41793 100755 --- a/repository/src/test/java/org/apache/atlas/TestUtils.java +++ b/repository/src/test/java/org/apache/atlas/TestUtils.java @@ -94,44 +94,31 @@ public final class TestUtils { new EnumTypeDefinition("OrgLevel", new EnumValue("L1", 1), new EnumValue("L2", 2)); ts.defineEnumType(orgLevelEnum); - StructTypeDefinition addressDetails = createStructTypeDef("Address", - createRequiredAttrDef("street", DataTypes.STRING_TYPE), - createRequiredAttrDef("city", DataTypes.STRING_TYPE)); - - HierarchicalTypeDefinition deptTypeDef = - createClassTypeDef("Department", ImmutableList.of(), - createRequiredAttrDef("name", DataTypes.STRING_TYPE), - new AttributeDefinition("employees", - String.format("array<%s>", "Person"), Multiplicity.COLLECTION, true, - "department") - ); - - HierarchicalTypeDefinition personTypeDef = createClassTypeDef("Person", - ImmutableList.of(), + StructTypeDefinition addressDetails = + createStructTypeDef("Address", createRequiredAttrDef("street", DataTypes.STRING_TYPE), + createRequiredAttrDef("city", DataTypes.STRING_TYPE)); + + HierarchicalTypeDefinition deptTypeDef = createClassTypeDef("Department", ImmutableList.of(), + createRequiredAttrDef("name", DataTypes.STRING_TYPE), + new AttributeDefinition("employees", String.format("array<%s>", "Person"), Multiplicity.COLLECTION, + true, "department")); + + HierarchicalTypeDefinition personTypeDef = createClassTypeDef("Person", ImmutableList.of(), createRequiredAttrDef("name", DataTypes.STRING_TYPE), createOptionalAttrDef("orgLevel", ts.getDataType(EnumType.class, "OrgLevel")), createOptionalAttrDef("address", "Address"), - new AttributeDefinition("department", - "Department", Multiplicity.REQUIRED, false, "employees"), - new AttributeDefinition("manager", - "Manager", Multiplicity.OPTIONAL, false, "subordinates") - ); - - HierarchicalTypeDefinition managerTypeDef = createClassTypeDef("Manager", - ImmutableList.of("Person"), - new AttributeDefinition("subordinates", - String.format("array<%s>", "Person"), Multiplicity.COLLECTION, false, - "manager") - ); - - HierarchicalTypeDefinition securityClearanceTypeDef = createTraitTypeDef( - "SecurityClearance", - ImmutableList.of(), - createRequiredAttrDef("level", DataTypes.INT_TYPE) - ); - - ts.defineTypes(ImmutableList.of(addressDetails), - ImmutableList.of(securityClearanceTypeDef), + new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"), + new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates")); + + HierarchicalTypeDefinition managerTypeDef = createClassTypeDef("Manager", ImmutableList.of("Person"), + new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), Multiplicity.COLLECTION, + false, "manager")); + + HierarchicalTypeDefinition securityClearanceTypeDef = + createTraitTypeDef("SecurityClearance", ImmutableList.of(), + createRequiredAttrDef("level", DataTypes.INT_TYPE)); + + ts.defineTypes(ImmutableList.of(addressDetails), ImmutableList.of(securityClearanceTypeDef), ImmutableList.of(deptTypeDef, personTypeDef, managerTypeDef)); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/fef50cee/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java ---------------------------------------------------------------------- diff --git a/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java b/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java index 4d12ccd..fc07010 100755 --- a/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java +++ b/repository/src/test/java/org/apache/atlas/discovery/GraphBackedDiscoveryServiceTest.java @@ -95,8 +95,7 @@ public class GraphBackedDiscoveryServiceTest { Bindings bindings = engine.createBindings(); bindings.put("g", titanGraph); - String hiveGraphFile = FileUtils.getTempDirectory().getPath() - + File.separator + System.nanoTime() + ".gson"; + String hiveGraphFile = FileUtils.getTempDirectory().getPath() + File.separator + System.nanoTime() + ".gson"; System.out.println("hiveGraphFile = " + hiveGraphFile); HiveTitanSample.writeGson(hiveGraphFile); bindings.put("hiveGraphFile", hiveGraphFile); @@ -164,71 +163,56 @@ public class GraphBackedDiscoveryServiceTest { System.out.println("search result = " + r); // Property Query: list all Person names - r = discoveryService - .searchByGremlin("g.V.filter{it.typeName == 'Person'}.'Person.name'.toList()"); + r = discoveryService.searchByGremlin("g.V.filter{it.typeName == 'Person'}.'Person.name'.toList()"); System.out.println("search result = " + r); } @DataProvider(name = "dslQueriesProvider") private Object[][] createDSLQueries() { - return new String[][] { - {"from DB"}, - {"DB"}, - {"DB where DB.name=\"Reporting\""}, - {"DB DB.name = \"Reporting\""}, - {"DB where DB.name=\"Reporting\" select name, owner"}, - {"DB has name"}, - {"DB, Table"}, - {"DB is JdbcAccess"}, + return new String[][]{{"from DB"}, {"DB"}, {"DB where DB.name=\"Reporting\""}, {"DB DB.name = \"Reporting\""}, + {"DB where DB.name=\"Reporting\" select name, owner"}, {"DB has name"}, {"DB, Table"}, + {"DB is JdbcAccess"}, /* {"DB, LoadProcess has name"}, {"DB as db1, Table where db1.name = \"Reporting\""}, {"DB where DB.name=\"Reporting\" and DB.createTime < " + System.currentTimeMillis()}, */ - {"from Table"}, - {"Table"}, - {"Table is Dimension"}, - {"Column where Column isa PII"}, - {"View is Dimension"}, + {"from Table"}, {"Table"}, {"Table is Dimension"}, {"Column where Column isa PII"}, + {"View is Dimension"}, /*{"Column where Column isa PII select Column.name"},*/ - {"Column select Column.name"}, - {"Column select name"}, - {"Column where Column.name=\"customer_id\""}, - {"from Table select Table.name"}, - {"DB where (name = \"Reporting\")"}, - {"DB where (name = \"Reporting\") select name as _col_0, owner as _col_1"}, - {"DB where DB is JdbcAccess"}, - {"DB where DB has name"}, - {"DB Table"}, - {"DB where DB has name"}, - {"DB as db1 Table where (db1.name = \"Reporting\")"}, - {"DB where (name = \"Reporting\") select name as _col_0, (createTime + 1) as _col_1 "}, + {"Column select Column.name"}, {"Column select name"}, {"Column where Column.name=\"customer_id\""}, + {"from Table select Table.name"}, {"DB where (name = \"Reporting\")"}, + {"DB where (name = \"Reporting\") select name as _col_0, owner as _col_1"}, + {"DB where DB is JdbcAccess"}, {"DB where DB has name"}, {"DB Table"}, {"DB where DB has name"}, + {"DB as db1 Table where (db1.name = \"Reporting\")"}, + {"DB where (name = \"Reporting\") select name as _col_0, (createTime + 1) as _col_1 "}, /* todo: does not work {"DB where (name = \"Reporting\") and ((createTime + 1) > 0)"}, - {"DB as db1 Table as tab where ((db1.createTime + 1) > 0) and (db1.name = \"Reporting\") select db1.name as dbName, tab.name as tabName"}, - {"DB as db1 Table as tab where ((db1.createTime + 1) > 0) or (db1.name = \"Reporting\") select db1.name as dbName, tab.name as tabName"}, - {"DB as db1 Table as tab where ((db1.createTime + 1) > 0) and (db1.name = \"Reporting\") or db1 has owner select db1.name as dbName, tab.name as tabName"}, - {"DB as db1 Table as tab where ((db1.createTime + 1) > 0) and (db1.name = \"Reporting\") or db1 has owner select db1.name as dbName, tab.name as tabName"}, + {"DB as db1 Table as tab where ((db1.createTime + 1) > 0) and (db1.name = \"Reporting\") select db1.name + as dbName, tab.name as tabName"}, + {"DB as db1 Table as tab where ((db1.createTime + 1) > 0) or (db1.name = \"Reporting\") select db1.name + as dbName, tab.name as tabName"}, + {"DB as db1 Table as tab where ((db1.createTime + 1) > 0) and (db1.name = \"Reporting\") or db1 has owner + select db1.name as dbName, tab.name as tabName"}, + {"DB as db1 Table as tab where ((db1.createTime + 1) > 0) and (db1.name = \"Reporting\") or db1 has owner + select db1.name as dbName, tab.name as tabName"}, */ - // trait searches - {"Dimension"}, + // trait searches + {"Dimension"}, /*{"Fact"}, - todo: does not work*/ - {"JdbcAccess"}, - {"ETL"}, - {"Metric"}, - {"PII"}, - // Lineage - {"Table LoadProcess outputTable"}, - {"Table loop (LoadProcess outputTable)"}, - {"Table as _loop0 loop (LoadProcess outputTable) withPath"}, - {"Table as src loop (LoadProcess outputTable) as dest select src.name as srcTable, dest.name as destTable withPath"}, - {"Table as t, sd, Column as c where t.name=\"sales_fact\" select c.name as colName, c.dataType as colType"}, - {"Table where name='sales_fact', db where name='Reporting'"} - }; + {"JdbcAccess"}, {"ETL"}, {"Metric"}, {"PII"}, + // Lineage + {"Table LoadProcess outputTable"}, {"Table loop (LoadProcess outputTable)"}, + {"Table as _loop0 loop (LoadProcess outputTable) withPath"}, + {"Table as src loop (LoadProcess outputTable) as dest select src.name as srcTable, dest.name as " + + "destTable withPath"}, + {"Table as t, sd, Column as c where t.name=\"sales_fact\" select c.name as colName, c.dataType as " + + "colType"}, + {"Table where name='sales_fact', db where name='Reporting'"}}; } - @Test (dataProvider = "dslQueriesProvider") + @Test(dataProvider = "dslQueriesProvider") public void testSearchByDSLQueries(String dslQuery) throws Exception { System.out.println("Executing dslQuery = " + dslQuery); String jsonResults = discoveryService.searchByDSL(dslQuery); @@ -254,14 +238,10 @@ public class GraphBackedDiscoveryServiceTest { @DataProvider(name = "invalidDslQueriesProvider") private Object[][] createInvalidDSLQueries() { - return new String[][] { - {"from Unknown"}, - {"Unknown"}, - {"Unknown is Blah"}, - }; + return new String[][]{{"from Unknown"}, {"Unknown"}, {"Unknown is Blah"},}; } - @Test (dataProvider = "invalidDslQueriesProvider", expectedExceptions = DiscoveryException.class) + @Test(dataProvider = "invalidDslQueriesProvider", expectedExceptions = DiscoveryException.class) public void testSearchByDSLInvalidQueries(String dslQuery) throws Exception { System.out.println("Executing dslQuery = " + dslQuery); discoveryService.searchByDSL(dslQuery); @@ -289,17 +269,16 @@ public class GraphBackedDiscoveryServiceTest { * D(d) extends C */ private void createTypesWithMultiLevelInheritance() throws Exception { - HierarchicalTypeDefinition A = createClassTypeDef("A", null, - createRequiredAttrDef("a", DataTypes.INT_TYPE)); + HierarchicalTypeDefinition A = createClassTypeDef("A", null, createRequiredAttrDef("a", DataTypes.INT_TYPE)); - HierarchicalTypeDefinition B = createClassTypeDef("B", ImmutableList.of("A"), - createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); + HierarchicalTypeDefinition B = + createClassTypeDef("B", ImmutableList.of("A"), createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)); - HierarchicalTypeDefinition C = createClassTypeDef("C", ImmutableList.of("B"), - createOptionalAttrDef("c", DataTypes.BYTE_TYPE)); + HierarchicalTypeDefinition C = + createClassTypeDef("C", ImmutableList.of("B"), createOptionalAttrDef("c", DataTypes.BYTE_TYPE)); - HierarchicalTypeDefinition D = createClassTypeDef("D", ImmutableList.of("C"), - createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); + HierarchicalTypeDefinition D = + createClassTypeDef("D", ImmutableList.of("C"), createOptionalAttrDef("d", DataTypes.SHORT_TYPE)); TypeSystem.getInstance().defineClassTypes(A, B, C, D); } @@ -312,8 +291,7 @@ public class GraphBackedDiscoveryServiceTest { instance.set("a", 1); ClassType deptType = TypeSystem.getInstance().getDataType(ClassType.class, "D"); - ITypedReferenceableInstance typedInstance = - deptType.convert(instance, Multiplicity.REQUIRED); + ITypedReferenceableInstance typedInstance = deptType.convert(instance, Multiplicity.REQUIRED); repositoryService.createEntity(typedInstance); }