http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/MultiplicityTest.scala ---------------------------------------------------------------------- diff --git a/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/MultiplicityTest.scala b/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/MultiplicityTest.scala deleted file mode 100644 index 91e72c7..0000000 --- a/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/MultiplicityTest.scala +++ /dev/null @@ -1,124 +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.typesystem.builders - -import org.apache.atlas.AtlasException -import org.apache.atlas.typesystem.types.{ClassType, Multiplicity, TypeSystem} -import org.testng.annotations.{BeforeMethod,Test} - -class MultiplicityTest { - - @BeforeMethod - def beforeAll { - TypeSystem.getInstance().reset() - - val b = new TypesBuilder - import b._ - - val tDef = types { - - _trait("Dimension") {} - _trait("PII") {} - _trait("Metric") {} - _trait("ETL") {} - _trait("JdbcAccess") {} - - _class("DB") { - "name" ~ (string, required, indexed, unique) - "owner" ~ (string) - "createTime" ~ (int) - } - - _class("StorageDesc") { - "inputFormat" ~ (string, required) - "outputFormat" ~ (string, required) - } - - _class("Column") { - "name" ~ (string, required) - "dataType" ~ (string, required) - "sd" ~ ("StorageDesc", required) - } - - _class("Table", List()) { - "name" ~ (string, required, indexed) - "db" ~ ("DB", required) - "sd" ~ ("StorageDesc", required) - } - - _class("LoadProcess") { - "name" ~ (string, required) - "inputTables" ~ (array("Table"), collection) - "outputTable" ~ ("Table", required) - - } - - _class("View") { - "name" ~ (string, required) - "inputTables" ~ (array("Table"), collection) - } - - _class("AT") { - "name" ~ (string, required) - "stringSet" ~ (array("string"), multiplicty(0, Int.MaxValue, true)) - } - } - - TypeSystem.getInstance().defineTypes(tDef) - } - - @Test - def test1 { - - val b = new InstanceBuilder - import b._ - - val instances = b create { - val a = instance("AT") { // use instance to create Referenceables. use closure to - // set attributes of instance - 'name ~ "A1" // use '~' to set attributes. Use a Symbol (names starting with ') for - 'stringSet ~ Seq("a", "a") - } - } - - val ts = TypeSystem.getInstance() - import scala.collection.JavaConversions._ - val typedInstances = instances.map { i => - val iTyp = ts.getDataType(classOf[ClassType], i.getTypeName) - iTyp.convert(i, Multiplicity.REQUIRED) - } - - typedInstances.foreach { i => - println(i) - } - } - - @Test(expectedExceptions = Array(classOf[AtlasException]) , expectedExceptionsMessageRegExp = "A multiplicty of more than one requires a collection type for attribute 'stringSet'") - def WrongMultiplicity { - val b = new TypesBuilder - import b._ - val tDef = types { - _class("Wrong") { - "name" ~ (string, required) - "stringSet" ~ (string, multiplicty(0, Int.MaxValue, true)) - } - } - TypeSystem.getInstance().defineTypes(tDef) - } -}
http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/TypesBuilderTest.scala ---------------------------------------------------------------------- diff --git a/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/TypesBuilderTest.scala b/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/TypesBuilderTest.scala deleted file mode 100644 index d01adb4..0000000 --- a/typesystem/src/test/scala/org/apache/atlas/typesystem/builders/TypesBuilderTest.scala +++ /dev/null @@ -1,33 +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.typesystem.builders - -import org.apache.atlas.typesystem.json.TypesSerialization -import org.apache.atlas.typesystem.types.TypeSystem -import org.testng.annotations.Test - -class TypesBuilderTest extends BuilderTest { - - - @Test def test1 { - TypeSystem.getInstance().defineTypes(tDef) - - println(TypesSerialization.toJson(TypeSystem.getInstance(), x => true)) - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/typesystem/src/test/scala/org/apache/atlas/typesystem/json/InstanceSerializationTest.scala ---------------------------------------------------------------------- diff --git a/typesystem/src/test/scala/org/apache/atlas/typesystem/json/InstanceSerializationTest.scala b/typesystem/src/test/scala/org/apache/atlas/typesystem/json/InstanceSerializationTest.scala deleted file mode 100644 index 9e656a5..0000000 --- a/typesystem/src/test/scala/org/apache/atlas/typesystem/json/InstanceSerializationTest.scala +++ /dev/null @@ -1,164 +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.typesystem.json - -import scala.util.Random - -import org.apache.atlas.typesystem.Referenceable -import org.apache.atlas.typesystem.persistence.Id -import org.apache.atlas.typesystem.types.DataTypes -import org.apache.atlas.typesystem.types.TypeSystem -import org.apache.atlas.typesystem.types.utils.TypesUtil -import org.testng.Assert.assertEquals -import org.testng.Assert.assertNotNull -import org.testng.Assert.assertTrue -import org.testng.annotations.BeforeClass -import org.testng.annotations.Test - -import com.google.common.collect.ImmutableSet - -class InstanceSerializationTest { - private var typeName: String = null - - @BeforeClass def setup { - typeName = "Random_" + Math.abs(Random.nextInt()) - val clsType = TypesUtil.createClassTypeDef(typeName, "Random-description", ImmutableSet.of[String](), - TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE)) - TypeSystem.getInstance().defineClassType(clsType) - } - - @Test def testIdentity { - val entity: Referenceable = new Referenceable(typeName) - val json: String = InstanceSerialization.toJson(entity, true) - val entity2: Referenceable = InstanceSerialization.fromJsonReferenceable(json, true) - assertNotNull(entity2) - assertEquals(entity2.getId, entity.getId, "Simple conversion failed") - assertEquals(entity2.getTraits, entity.getTraits, "Traits mismatch") - } - - @Test def testReferenceArrayWithNoState { - val staticJson = s"""{ - "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Reference", - "id": { - "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id", - "version": 0, - "typeName": "LoadProcess" - }, - "typeName": "LoadProcess", - "values": { - "inputTables": [{ - "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id", - "id": "bacfa996-e88e-4d7e-9630-68c9829b10b4", - "version": 0, - "typeName": "Table" - }, { - "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id", - "id": "6da06805-3f56-446f-8831-672a65ac2199", - "version": 0, - "typeName": "Table" - }, { - "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Reference", - "typeName": "$typeName", - "values": {} - "traitNames": [] - "traits": {} - } - ], - "outputTable": { - "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id", - "id": "d5c3d6d0-aa10-44c1-b05d-ed9400d2a5ac", - "version": 0, - "typeName": "Table" - }, - "name": "loadSalesDaily" - }, - "traitNames": [ - "ETL" - ], - "traits": { - "ETL": { - "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Struct", - "typeName": "ETL", - "values": { - } - } - } - } - """; - - val entity: Referenceable = InstanceSerialization.fromJsonReferenceable(staticJson, true) - val outputTable = entity.getValuesMap.get("outputTable") - val inputTables : java.util.List[_] = entity.getValuesMap().get("inputTables").asInstanceOf[java.util.List[_]] - - assertTrue(entity.getId.isInstanceOf[Id]); - assertTrue(outputTable.isInstanceOf[Id]); - import scala.collection.JavaConversions._ - assertTrue(inputTables(0).isInstanceOf[Id]); - assertTrue(inputTables(1).isInstanceOf[Id]); - assertTrue(inputTables(2).isInstanceOf[Referenceable]); - } - - @Test def testMissingStateInId: Unit = { - val entity: Referenceable = new Referenceable(typeName) - val staticJson: String = s"""{ - "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Reference", - "id": { - "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Id", - "id": "${entity.getId.id}", - "version":0, - "typeName": "${entity.getTypeName}", - }, - "typeName": "${entity.getTypeName}", - "values": {} - "traitNames": [] - "traits": {} - }""" - val entity2: Referenceable = InstanceSerialization.fromJsonReferenceable(staticJson, true) - assertNotNull(entity2) - assertNotNull(entity2.getId) - assertNotNull(entity2.getId.id) // This creates a new id so the values will not match. - assertEquals(entity2.getId.typeName, entity.getId.typeName) - assertEquals(entity2.getId.version, entity.getId.version) - assertEquals(entity2.getId.state, entity.getId.state) - assertEquals(entity2.getTypeName, entity.getTypeName, "Type name mismatch") - assertEquals(entity2.getValuesMap, entity.getValuesMap, "Values mismatch") - assertEquals(entity2.getTraits, entity.getTraits, "Traits mismatch") - } - - @Test def testMissingId: Unit = { - val entity: Referenceable = new Referenceable(typeName) - val staticJson: String = s"""{ - "jsonClass": "org.apache.atlas.typesystem.json.InstanceSerialization$$_Reference", - "typeName": "${entity.getTypeName}", - "values": {} - "traitNames": [] - "traits": {} - }""" - val entity2: Referenceable = InstanceSerialization.fromJsonReferenceable(staticJson, true) - assertNotNull(entity2) - assertNotNull(entity2.getId) - assertNotNull(entity2.getId.id) // This creates a new id so the values will not match. - assertEquals(entity2.getId.typeName, entity.getId.typeName) - assertEquals(entity2.getId.version, entity.getId.version) - assertEquals(entity2.getId.state, entity.getId.state) - assertEquals(entity2.getTypeName, entity.getTypeName, "Type name mismatch") - assertEquals(entity2.getValuesMap, entity.getValuesMap, "Values mismatch") - assertEquals(entity2.getTraits, entity.getTraits, "Traits mismatch") - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/typesystem/src/test/scala/org/apache/atlas/typesystem/json/SerializationTest.scala ---------------------------------------------------------------------- diff --git a/typesystem/src/test/scala/org/apache/atlas/typesystem/json/SerializationTest.scala b/typesystem/src/test/scala/org/apache/atlas/typesystem/json/SerializationTest.scala deleted file mode 100755 index 931773d..0000000 --- a/typesystem/src/test/scala/org/apache/atlas/typesystem/json/SerializationTest.scala +++ /dev/null @@ -1,263 +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.typesystem.json - -import com.google.common.collect.ImmutableList -import org.apache.atlas.typesystem.persistence.Id.EntityState -import org.apache.atlas.typesystem.persistence.{Id, ReferenceableInstance, StructInstance} -import org.apache.atlas.typesystem.types._ -import org.apache.atlas.typesystem.types.utils.TypesUtil -import org.apache.atlas.typesystem.{ITypedReferenceableInstance, ITypedStruct, Referenceable, Struct} -import org.json4s.native.JsonMethods._ -import org.json4s.native.Serialization.{write => swrite, _} -import org.json4s.{NoTypeHints, _} -import org.testng.Assert -import org.testng.annotations.{BeforeMethod,Test} -import com.google.common.collect.ImmutableSet -import org.testng.Assert.assertEquals - -class SerializationTest extends BaseTest { - - private[atlas] var structType: StructType = null - private[atlas] var recursiveStructType: StructType = null - - @BeforeMethod - override def setup { - super.setup - structType = getTypeSystem.getDataType(classOf[StructType], BaseTest.STRUCT_TYPE_1).asInstanceOf[StructType] - recursiveStructType = getTypeSystem.getDataType(classOf[StructType], BaseTest.STRUCT_TYPE_2).asInstanceOf[StructType] - } - - @Test def test1 { - val s: Struct = BaseTest.createStruct() - val ts: ITypedStruct = structType.convert(s, Multiplicity.REQUIRED) - - Assert.assertEquals(ts.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \t" + BaseTest.TEST_DATE + "\n\tm : \t[1, 1]\n\tn : \t[1.1, 1.1]\n\to : \t{a=1.0, b=2.0}\n\tp : \t\n\tq : \t<null>\n\tr : \t{a=}\n}") - - implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer + - new BigDecimalSerializer + new BigIntegerSerializer - - //Json representation - val ser = swrite(ts) - val ser1 = swrite(ts.toString) - Assert.assertEquals(ser1, "\"{\\n\\ta : \\t1\\n\\tb : \\ttrue\\n\\tc : \\t1\\n\\td : \\t2\\n\\te : \\t1\\n\\tf : \\t1\\n\\tg : \\t1\\n\\th : \\t1.0\\n\\ti : \\t1.0\\n\\tj : \\t1\\n\\tk : \\t1\\n\\tl : \\t" + BaseTest.TEST_DATE + "\\n\\tm : \\t[1, 1]\\n\\tn : \\t[1.1, 1.1]\\n\\to : \\t{a=1.0, b=2.0}\\n\\tp : \\t\\n\\tq : \\t<null>\\n\\tr : \\t{a=}\\n}\""); - // Typed Struct read back - val ts1 = read[StructInstance](ser) - Assert.assertEquals(ts1.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \t" + BaseTest.TEST_DATE + "\n\tm : \t[1, 1]\n\tn : \t[1.100000000000000088817841970012523233890533447265625, 1.100000000000000088817841970012523233890533447265625]\n\to : \t{a=1.0, b=2.0}\n\tp : \t\n\tq : \t<null>\n\tr : \t{a=}\n}") - } - - @Test def test2 { - val s: Struct = BaseTest.createStruct() - val ts: ITypedStruct = structType.convert(s, Multiplicity.REQUIRED) - - implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer + - new BigDecimalSerializer + new BigIntegerSerializer - - val ts1 = read[StructInstance]( - """ - {"$typeName$":"t1","e":1,"n":[1.1,1.1],"h":1.0,"b":true,"k":1,"j":1,"d":2,"m":[1,1],"g":1,"a":1,"i":1.0, - "c":1,"l":"2014-12-03T19:38:55.053Z","f":1,"o":{"a":1.0,"b":2.0}}""") - // Typed Struct read from string - Assert.assertEquals(ts1.toString, "{\n\ta : \t1\n\tb : \ttrue\n\tc : \t1\n\td : \t2\n\te : \t1\n\tf : \t1\n\tg : \t1\n\th : \t1.0\n\ti : \t1.0\n\tj : \t1\n\tk : \t1\n\tl : \t2014-12-03T19:38:55.053Z\n\tm : \t[1, 1]\n\tn : \t[1.100000000000000088817841970012523233890533447265625, 1.100000000000000088817841970012523233890533447265625]\n\to : \t{a=1.0, b=2.0}\n\tp : \t<null>\n\tq : \t<null>\n\tr : \t<null>\n}") - } - - @Test def testTrait { - val A: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef("A", null, - TypesUtil.createRequiredAttrDef("a", DataTypes.INT_TYPE), - TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE), - TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE), - TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE)) - val B: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef( - "B", ImmutableSet.of[String]("A"), - TypesUtil.createOptionalAttrDef("b", DataTypes.BOOLEAN_TYPE)) - val C: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef( - "C", ImmutableSet.of[String]("A"), - TypesUtil.createOptionalAttrDef("c", DataTypes.BYTE_TYPE)) - val D: HierarchicalTypeDefinition[TraitType] = TypesUtil.createTraitTypeDef( - "D", ImmutableSet.of[String]("B", "C"), - TypesUtil.createOptionalAttrDef("d", DataTypes.SHORT_TYPE)) - - defineTraits(A, B, C, D) - - val DType: TraitType = getTypeSystem.getDataType(classOf[TraitType], "D").asInstanceOf[TraitType] - val s1: Struct = new Struct("D") - s1.set("d", 1) - s1.set("c", 1) - s1.set("b", true) - s1.set("a", 1) - s1.set("A.B.D.b", true) - s1.set("A.B.D.c", 2) - s1.set("A.B.D.d", 2) - s1.set("A.C.D.a", 3) - s1.set("A.C.D.b", false) - s1.set("A.C.D.c", 3) - s1.set("A.C.D.d", 3) - - val s: Struct = BaseTest.createStruct() - val ts: ITypedStruct = DType.convert(s1, Multiplicity.REQUIRED) - - implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer + - new BigDecimalSerializer + new BigIntegerSerializer - - // Typed Struct : - Assert.assertEquals(ts.toString, "{\n\td : \t1\n\tb : \ttrue\n\tc : \t1\n\ta : \t1\n\tA.B.D.b : \ttrue\n\tA.B.D.c : \t2\n\tA.B.D.d : \t2\n\tA.C.D.a : \t3\n\tA.C.D.b : \tfalse\n\tA.C.D.c : \t3\n\tA.C.D.d : \t3\n}") - - // Json representation : - val ser = swrite(ts) - Assert.assertEquals(ser, "{\"$typeName$\":\"D\",\"A.C.D.d\":3,\"A.B.D.c\":2,\"b\":true,\"A.C.D.c\":3,\"d\":1,\"A.B.D.b\":true,\"a\":1,\"A.C.D.b\":false,\"A.B.D.d\":2,\"c\":1,\"A.C.D.a\":3}") - - val ts1 = read[StructInstance]( - """ - {"$typeName$":"D","A.C.D.d":3,"A.B.D.c":2,"b":true,"A.C.D.c":3,"d":1, - "A.B.D.b":true,"a":1,"A.C.D.b":false,"A.B.D.d":2,"c":1,"A.C.D.a":3}""") - // Typed Struct read from string: - Assert.assertEquals(ts1.toString, "{\n\td : \t1\n\tb : \ttrue\n\tc : \t1\n\ta : \t1\n\tA.B.D.b : \ttrue\n\tA.B.D.c : \t2\n\tA.B.D.d : \t2\n\tA.C.D.a : \t3\n\tA.C.D.b : \tfalse\n\tA.C.D.c : \t3\n\tA.C.D.d : \t3\n}") - } - - def defineHRTypes(ts: TypeSystem) : Unit = { - val deptTypeDef: HierarchicalTypeDefinition[ClassType] = TypesUtil.createClassTypeDef( - "Department", - ImmutableSet.of[String], - TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), - new AttributeDefinition("employees", String.format("array<%s>", "Person"), - Multiplicity.COLLECTION, true, "department")) - val personTypeDef: HierarchicalTypeDefinition[ClassType] = TypesUtil.createClassTypeDef( - "Person", ImmutableSet.of[String], - TypesUtil.createRequiredAttrDef("name", DataTypes.STRING_TYPE), - new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"), - new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates")) - val managerTypeDef: HierarchicalTypeDefinition[ClassType] = TypesUtil.createClassTypeDef( - "Manager", ImmutableSet.of[String]("Person"), - new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), - Multiplicity.COLLECTION, false, "manager")) - val securityClearanceTypeDef: HierarchicalTypeDefinition[TraitType] = - TypesUtil.createTraitTypeDef("SecurityClearance", ImmutableSet.of[String], - TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE)) - - ts.defineTypes(ImmutableList.of[EnumTypeDefinition], ImmutableList.of[StructTypeDefinition], - ImmutableList.of[HierarchicalTypeDefinition[TraitType]](securityClearanceTypeDef), - ImmutableList.of[HierarchicalTypeDefinition[ClassType]](deptTypeDef, personTypeDef, managerTypeDef) - ) - - } - - def defineHRDept() : Referenceable = { - val hrDept: Referenceable = new Referenceable("Department") - val john: Referenceable = new Referenceable("Person") - val jane: Referenceable = new Referenceable("Manager", "SecurityClearance") - hrDept.set("name", "hr") - john.set("name", "John") - john.set("department", hrDept.getId) - jane.set("name", "Jane") - jane.set("department", hrDept.getId) - john.set("manager", jane.getId) - hrDept.set("employees", ImmutableList.of[Referenceable](john, jane)) - jane.set("subordinates", ImmutableList.of[Id](john.getId)) - jane.getTrait("SecurityClearance").set("level", 1) - hrDept - } - - @Test def testClass { - - val ts: TypeSystem = getTypeSystem - defineHRTypes(ts) - val hrDept: Referenceable = defineHRDept() - - val deptType: ClassType = ts.getDataType(classOf[ClassType], "Department") - val hrDept2: ITypedReferenceableInstance = deptType.convert(hrDept, Multiplicity.REQUIRED) - - println(s"HR Dept Object Graph:\n${hrDept2}\n") - - implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer + - new TypedReferenceableInstanceSerializer + new BigDecimalSerializer + new BigIntegerSerializer - - val ser = swrite(hrDept2) - println(s"HR Dept JSON:\n${pretty(render(parse(ser)))}\n") - - println(s"HR Dept Object Graph read from JSON:${read[ReferenceableInstance](ser)}\n") - } - - @Test def testReference { - - val ts: TypeSystem = getTypeSystem - defineHRTypes(ts) - val hrDept: Referenceable = defineHRDept() - - - val jsonStr = InstanceSerialization.toJson(hrDept) - val hrDept2 = InstanceSerialization.fromJsonReferenceable(jsonStr) - - val deptType: ClassType = ts.getDataType(classOf[ClassType], "Department") - val hrDept3: ITypedReferenceableInstance = deptType.convert(hrDept2, Multiplicity.REQUIRED) - - println(s"HR Dept Object Graph:\n${hrDept3}\n") - - implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer + - new TypedReferenceableInstanceSerializer + new BigDecimalSerializer + new BigIntegerSerializer - - val ser = swrite(hrDept3) - println(s"HR Dept JSON:\n${pretty(render(parse(ser)))}\n") - - println(s"HR Dept Object Graph read from JSON:${read[ReferenceableInstance](ser)}\n") - } - - @Test def testReference2 { - - val ts: TypeSystem = getTypeSystem - defineHRTypes(ts) - val hrDept: Referenceable = defineHRDept() - - val deptType: ClassType = ts.getDataType(classOf[ClassType], "Department") - val hrDept2: ITypedReferenceableInstance = deptType.convert(hrDept, Multiplicity.REQUIRED) - - val jsonStr = InstanceSerialization.toJson(hrDept2) - val hrDept3 = InstanceSerialization.fromJsonReferenceable(jsonStr) - - val hrDept4: ITypedReferenceableInstance = deptType.convert(hrDept2, Multiplicity.REQUIRED) - - println(s"HR Dept Object Graph:\n${hrDept4}\n") - - implicit val formats = org.json4s.native.Serialization.formats(NoTypeHints) + new TypedStructSerializer + - new TypedReferenceableInstanceSerializer + new BigDecimalSerializer + new BigIntegerSerializer - - val ser = swrite(hrDept4) - println(s"HR Dept JSON:\n${pretty(render(parse(ser)))}\n") - - println(s"HR Dept Object Graph read from JSON:${read[ReferenceableInstance](ser)}\n") - - } - - @Test def testIdSerde: Unit = { - - val ts: TypeSystem = getTypeSystem - defineHRTypes(ts) - val hrDept: Referenceable = defineHRDept() - //default state is actiev by default - assertEquals(hrDept.getId.getState, EntityState.ACTIVE) - - val deptType: ClassType = ts.getDataType(classOf[ClassType], "Department") - val hrDept2: ITypedReferenceableInstance = deptType.convert(hrDept, Multiplicity.REQUIRED) - hrDept2.getId.state = EntityState.DELETED - - //updated state should be maintained correctly after serialisation-deserialisation - val deptJson: String = InstanceSerialization.toJson(hrDept2, true) - val deserDept: Referenceable = InstanceSerialization.fromJsonReferenceable(deptJson, true) - assertEquals(deserDept.getId.getState, EntityState.DELETED) - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/typesystem/src/test/scala/org/apache/atlas/typesystem/json/TypesSerializationTest.scala ---------------------------------------------------------------------- diff --git a/typesystem/src/test/scala/org/apache/atlas/typesystem/json/TypesSerializationTest.scala b/typesystem/src/test/scala/org/apache/atlas/typesystem/json/TypesSerializationTest.scala deleted file mode 100755 index cfd4bdb..0000000 --- a/typesystem/src/test/scala/org/apache/atlas/typesystem/json/TypesSerializationTest.scala +++ /dev/null @@ -1,342 +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.typesystem.json - -import com.google.common.collect.ImmutableList -import org.apache.atlas.typesystem.types._ -import org.testng.Assert -import org.testng.annotations.Test - -class TypesSerializationTest extends BaseTest with TypeHelpers { - - @Test def test1: Unit = { - - val ts = getTypeSystem - - val sDef = structDef("ts1", requiredAttr("a", DataTypes.INT_TYPE), - optionalAttr("b", DataTypes.BOOLEAN_TYPE), - optionalAttr("c", DataTypes.BYTE_TYPE), - optionalAttr("d", DataTypes.SHORT_TYPE), - optionalAttr("e", DataTypes.INT_TYPE), - optionalAttr("f", DataTypes.INT_TYPE), - optionalAttr("g", DataTypes.LONG_TYPE), - optionalAttr("h", DataTypes.FLOAT_TYPE), - optionalAttr("i", DataTypes.DOUBLE_TYPE), - optionalAttr("j", DataTypes.BIGINTEGER_TYPE), - optionalAttr("k", DataTypes.BIGDECIMAL_TYPE), - optionalAttr("l", DataTypes.DATE_TYPE), - optionalAttr("m", DataTypes.arrayTypeName(DataTypes.INT_TYPE)), - optionalAttr("n", DataTypes.arrayTypeName(DataTypes.BIGDECIMAL_TYPE)), - optionalAttr("o", DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE))) - - - ts.defineTypes(ImmutableList.of[EnumTypeDefinition], ImmutableList.of[StructTypeDefinition](sDef), - ImmutableList.of[HierarchicalTypeDefinition[TraitType]], - ImmutableList.of[HierarchicalTypeDefinition[ClassType]] - ) - - val A: HierarchicalTypeDefinition[TraitType] = createTraitTypeDef("A", List(), - requiredAttr("a", DataTypes.INT_TYPE), - optionalAttr("b", DataTypes.BOOLEAN_TYPE), - optionalAttr("c", DataTypes.BYTE_TYPE), - optionalAttr("d", DataTypes.SHORT_TYPE)) - val B: HierarchicalTypeDefinition[TraitType] = - createTraitTypeDef("B", Seq("A"), optionalAttr("b", DataTypes.BOOLEAN_TYPE)) - val C: HierarchicalTypeDefinition[TraitType] = - createTraitTypeDef("C", Seq("A"), optionalAttr("c", DataTypes.BYTE_TYPE)) - val D: HierarchicalTypeDefinition[TraitType] = - createTraitTypeDef("D", Seq("B", "C"), optionalAttr("d", DataTypes.SHORT_TYPE)) - - defineTraits(ts, A, B, C, D) - - ts.defineEnumType("HiveObjectType", - new EnumValue("GLOBAL", 1), - new EnumValue("DATABASE", 2), - new EnumValue("TABLE", 3), - new EnumValue("PARTITION", 4), - new EnumValue("COLUMN", 5)) - - ts.defineEnumType("PrincipalType", - new EnumValue("USER", 1), - new EnumValue("ROLE", 2), - new EnumValue("GROUP", 3)) - - ts.defineEnumType("TxnState", - new EnumValue("COMMITTED", 1), - new EnumValue("ABORTED", 2), - new EnumValue("OPEN", 3)) - - ts.defineEnumType("LockLevel", - new EnumValue("DB", 1), - new EnumValue("TABLE", 2), - new EnumValue("PARTITION", 3)) - - ts.defineEnumType("TestType", "TestType-description", - new EnumValue("A", 1), - new EnumValue("B", 2), - new EnumValue("C", 3)) - - defineClassType(ts, createClassTypeDef("t4", List(), - requiredAttr("a", DataTypes.INT_TYPE), - optionalAttr("b", DataTypes.BOOLEAN_TYPE), - optionalAttr("c", DataTypes.BYTE_TYPE), - optionalAttr("d", DataTypes.SHORT_TYPE), - optionalAttr("enum1", ts.getDataType(classOf[EnumType], "HiveObjectType")), - optionalAttr("e", DataTypes.INT_TYPE), - optionalAttr("f", DataTypes.INT_TYPE), - optionalAttr("g", DataTypes.LONG_TYPE), - optionalAttr("enum2", ts.getDataType(classOf[EnumType], "PrincipalType")), - optionalAttr("h", DataTypes.FLOAT_TYPE), - optionalAttr("i", DataTypes.DOUBLE_TYPE), - optionalAttr("j", DataTypes.BIGINTEGER_TYPE), - optionalAttr("k", DataTypes.BIGDECIMAL_TYPE), - optionalAttr("enum3", ts.getDataType(classOf[EnumType], "TxnState")), - optionalAttr("l", DataTypes.DATE_TYPE), - optionalAttr("m", ts.defineArrayType(DataTypes.INT_TYPE)), - optionalAttr("n", ts.defineArrayType(DataTypes.BIGDECIMAL_TYPE)), - optionalAttr("o", ts.defineMapType(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)), - optionalAttr("enum4", ts.getDataType(classOf[EnumType], "LockLevel")))) - - val deptTypeDef: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Department", List(), - requiredAttr("name", DataTypes.STRING_TYPE), - new AttributeDefinition("employees", String.format("array<%s>", "Person"), - Multiplicity.COLLECTION, true, "department")) - val personTypeDef: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Person", List(), - requiredAttr("name", DataTypes.STRING_TYPE), - new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"), - new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates") - ) - val managerTypeDef: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Manager", List("Person"), - new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), - Multiplicity.COLLECTION, false, "manager") - ) - val securityClearanceTypeDef: HierarchicalTypeDefinition[TraitType] = createTraitTypeDef("SecurityClearance", List(), - requiredAttr("level", DataTypes.INT_TYPE) - ) - - val securityClearanceTypeDefWithDesc: HierarchicalTypeDefinition[TraitType] = createTraitTypeDef("SecurityClearance2", Some("SecurityClearance-Description"), List(), - requiredAttr("level", DataTypes.INT_TYPE) - ) - ts.defineTypes(ImmutableList.of[EnumTypeDefinition], ImmutableList.of[StructTypeDefinition], - ImmutableList.of[HierarchicalTypeDefinition[TraitType]](securityClearanceTypeDef, securityClearanceTypeDefWithDesc), - ImmutableList.of[HierarchicalTypeDefinition[ClassType]](deptTypeDef, personTypeDef, managerTypeDef)) - - val ser = TypesSerialization.toJson(ts, _ => true) - - val typesDef1 = TypesSerialization.fromJson(ser) - - val ts1 = TypeSystem.getInstance() - ts1.reset() - - typesDef1.enumTypes.foreach(ts1.defineEnumType(_)) - - ts1.defineTypes(ImmutableList.of[EnumTypeDefinition], ImmutableList.copyOf(typesDef1.structTypes.toArray), - ImmutableList.copyOf(typesDef1.traitTypes.toArray), - ImmutableList.copyOf(typesDef1.classTypes.toArray) - ) - val ser2 = TypesSerialization.toJson(ts1, _ => true) - val typesDef2 = TypesSerialization.fromJson(ser2) - - Assert.assertEquals(typesDef1, typesDef2) - } - - @Test def test2: Unit = { - - val sDef = structDef("ts1", requiredAttr("a", DataTypes.INT_TYPE), - optionalAttr("b", DataTypes.BOOLEAN_TYPE), - optionalAttr("c", DataTypes.BYTE_TYPE), - optionalAttr("d", DataTypes.SHORT_TYPE), - optionalAttr("e", DataTypes.INT_TYPE), - optionalAttr("f", DataTypes.INT_TYPE), - optionalAttr("g", DataTypes.LONG_TYPE), - optionalAttr("h", DataTypes.FLOAT_TYPE), - optionalAttr("i", DataTypes.DOUBLE_TYPE), - optionalAttr("j", DataTypes.BIGINTEGER_TYPE), - optionalAttr("k", DataTypes.BIGDECIMAL_TYPE), - optionalAttr("l", DataTypes.DATE_TYPE), - optionalAttr("m", DataTypes.arrayTypeName(DataTypes.INT_TYPE)), - optionalAttr("n", DataTypes.arrayTypeName(DataTypes.BIGDECIMAL_TYPE)), - optionalAttr("o", DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE))) - - - - val ser2 = TypesSerialization.toJson(sDef) - val typesDef2 = TypesSerialization.fromJson(ser2) - - Assert.assertEquals(sDef, typesDef2.structTypes(0)) - } - - @Test def test3: Unit = { - - val sDef = structDef("ts1", requiredAttr("a", DataTypes.INT_TYPE), - optionalAttr("b", DataTypes.BOOLEAN_TYPE), - optionalAttr("c", DataTypes.BYTE_TYPE), - optionalAttr("d", DataTypes.SHORT_TYPE), - optionalAttr("e", DataTypes.INT_TYPE), - optionalAttr("f", DataTypes.INT_TYPE), - optionalAttr("g", DataTypes.LONG_TYPE), - optionalAttr("h", DataTypes.FLOAT_TYPE), - optionalAttr("i", DataTypes.DOUBLE_TYPE), - optionalAttr("j", DataTypes.BIGINTEGER_TYPE), - optionalAttr("k", DataTypes.BIGDECIMAL_TYPE), - optionalAttr("l", DataTypes.DATE_TYPE), - optionalAttr("m", DataTypes.arrayTypeName(DataTypes.INT_TYPE)), - optionalAttr("n", DataTypes.arrayTypeName(DataTypes.BIGDECIMAL_TYPE)), - optionalAttr("o", DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE))) - - val ser = TypesSerialization.toJson(sDef) - val typesDef2 = TypesSerialization.fromJson(ser) - - Assert.assertEquals(sDef, typesDef2.structTypes(0)) - - //Now with description - val sDef2 = structDef("ts1", Some("ts1-description"), requiredAttr("a", DataTypes.INT_TYPE), - optionalAttr("b", DataTypes.BOOLEAN_TYPE), - optionalAttr("c", DataTypes.BYTE_TYPE), - optionalAttr("d", DataTypes.SHORT_TYPE), - optionalAttr("e", DataTypes.INT_TYPE), - optionalAttr("f", DataTypes.INT_TYPE), - optionalAttr("g", DataTypes.LONG_TYPE), - optionalAttr("h", DataTypes.FLOAT_TYPE), - optionalAttr("i", DataTypes.DOUBLE_TYPE), - optionalAttr("j", DataTypes.BIGINTEGER_TYPE), - optionalAttr("k", DataTypes.BIGDECIMAL_TYPE), - optionalAttr("l", DataTypes.DATE_TYPE), - optionalAttr("m", DataTypes.arrayTypeName(DataTypes.INT_TYPE)), - optionalAttr("n", DataTypes.arrayTypeName(DataTypes.BIGDECIMAL_TYPE)), - optionalAttr("o", DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE))) - - val ser2 = TypesSerialization.toJson(sDef) - val typesDef3 = TypesSerialization.fromJson(ser2) - Assert.assertEquals(sDef, typesDef3.structTypes(0)) - - } - - @Test def test4 : Unit = { - - val A: HierarchicalTypeDefinition[TraitType] = createTraitTypeDef("A", List(), - requiredAttr("a", DataTypes.INT_TYPE), - optionalAttr("b", DataTypes.BOOLEAN_TYPE), - optionalAttr("c", DataTypes.BYTE_TYPE), - optionalAttr("d", DataTypes.SHORT_TYPE)) - val B: HierarchicalTypeDefinition[TraitType] = - createTraitTypeDef("B", Seq("A"), optionalAttr("b", DataTypes.BOOLEAN_TYPE)) - val C: HierarchicalTypeDefinition[TraitType] = - createTraitTypeDef("C", Seq("A"), optionalAttr("c", DataTypes.BYTE_TYPE)) - val D: HierarchicalTypeDefinition[TraitType] = - createTraitTypeDef("D", Seq("B", "C"), optionalAttr("d", DataTypes.SHORT_TYPE)) - val E: HierarchicalTypeDefinition[TraitType] = - createTraitTypeDef("E", Some("E-description"), Seq("B", "C"), optionalAttr("d", DataTypes.SHORT_TYPE)) - val typDefs = Seq(A,B,C,D,E) - typDefs.foreach { tDef => - val ser2 = TypesSerialization.toJson(tDef, true) - val typesDef2 = TypesSerialization.fromJson(ser2) - Assert.assertEquals(tDef, typesDef2.traitTypes(0)) - - } - } - - @Test def test5 : Unit = { - val e1 = new EnumTypeDefinition("HiveObjectType", - new EnumValue("GLOBAL", 1), - new EnumValue("DATABASE", 2), - new EnumValue("TABLE", 3), - new EnumValue("PARTITION", 4), - new EnumValue("COLUMN", 5)) - - val e2 = new EnumTypeDefinition("PrincipalType", - new EnumValue("USER", 1), - new EnumValue("ROLE", 2), - new EnumValue("GROUP", 3)) - - val e3 = new EnumTypeDefinition("TxnState", - new EnumValue("COMMITTED", 1), - new EnumValue("ABORTED", 2), - new EnumValue("OPEN", 3)) - - val e4 = new EnumTypeDefinition("LockLevel", - new EnumValue("DB", 1), - new EnumValue("TABLE", 2), - new EnumValue("PARTITION", 3)) - - val e5 = new EnumTypeDefinition("LockLevel", "LockLevel-description", - new EnumValue("DB", 1), - new EnumValue("TABLE", 2), - new EnumValue("PARTITION", 3)) - - val typDefs = Seq(e1,e2,e3,e4,e5) - typDefs.foreach { tDef => - val ser2 = TypesSerialization.toJson(tDef) - val typesDef2 = TypesSerialization.fromJson(ser2) - Assert.assertEquals(tDef, typesDef2.enumTypes(0)) - - } - } - - @Test def test6 : Unit = { - val typDef = createClassTypeDef("t4", List(), - requiredAttr("a", DataTypes.INT_TYPE), - optionalAttr("b", DataTypes.BOOLEAN_TYPE), - optionalAttr("c", DataTypes.BYTE_TYPE), - optionalAttr("d", DataTypes.SHORT_TYPE), - optionalAttr("enum1", "HiveObjectType"), - optionalAttr("e", DataTypes.INT_TYPE), - optionalAttr("f", DataTypes.INT_TYPE), - optionalAttr("g", DataTypes.LONG_TYPE), - optionalAttr("enum2", "PrincipalType"), - optionalAttr("h", DataTypes.FLOAT_TYPE), - optionalAttr("i", DataTypes.DOUBLE_TYPE), - optionalAttr("j", DataTypes.BIGINTEGER_TYPE), - optionalAttr("k", DataTypes.BIGDECIMAL_TYPE), - optionalAttr("enum3", "TxnState"), - optionalAttr("l", DataTypes.DATE_TYPE), - optionalAttr("m", DataTypes.INT_TYPE), - optionalAttr("n", DataTypes.BIGDECIMAL_TYPE), - optionalAttr("o", DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.DOUBLE_TYPE)), - optionalAttr("enum4", "LockLevel")) - - val deptTypeDef: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Department", List(), - requiredAttr("name", DataTypes.STRING_TYPE), - new AttributeDefinition("employees", String.format("array<%s>", "Person"), - Multiplicity.COLLECTION, true, "department")) - val personTypeDef: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Person", List(), - requiredAttr("name", DataTypes.STRING_TYPE), - new AttributeDefinition("department", "Department", Multiplicity.REQUIRED, false, "employees"), - new AttributeDefinition("manager", "Manager", Multiplicity.OPTIONAL, false, "subordinates") - ) - val managerTypeDef: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Manager", List("Person"), - new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), - Multiplicity.COLLECTION, false, "manager") - ) - - val managerTypeDefWithDesc: HierarchicalTypeDefinition[ClassType] = createClassTypeDef("Manager", Some("Manager-description"), List("Person"), - new AttributeDefinition("subordinates", String.format("array<%s>", "Person"), - Multiplicity.COLLECTION, false, "manager") - ) - - val typDefs = Seq(typDef, deptTypeDef, personTypeDef, managerTypeDef, managerTypeDefWithDesc) - typDefs.foreach { tDef => - val ser2 = TypesSerialization.toJson(tDef, false) - val typesDef2 = TypesSerialization.fromJson(ser2) - Assert.assertEquals(tDef, typesDef2.classTypes(0)) - - } - - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/webapp/pom.xml ---------------------------------------------------------------------- diff --git a/webapp/pom.xml b/webapp/pom.xml index 782c280..569e06f 100755 --- a/webapp/pom.xml +++ b/webapp/pom.xml @@ -88,11 +88,6 @@ <dependency> <groupId>org.apache.atlas</groupId> - <artifactId>atlas-typesystem</artifactId> - </dependency> - - <dependency> - <groupId>org.apache.atlas</groupId> <artifactId>atlas-repository</artifactId> </dependency> @@ -262,11 +257,6 @@ </dependency> <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - </dependency> - - <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-jsp</artifactId> </dependency> @@ -390,13 +380,6 @@ <dependency> <groupId>org.apache.atlas</groupId> - <artifactId>atlas-typesystem</artifactId> - <classifier>tests</classifier> - <scope>test</scope> - </dependency> - - <dependency> - <groupId>org.apache.atlas</groupId> <artifactId>atlas-intg</artifactId> <classifier>tests</classifier> <scope>test</scope> @@ -638,7 +621,7 @@ </systemProperty> <systemProperty> <key>atlas.conf</key> - <value>${project.build.directory}/../../typesystem/target/test-classes</value> + <value>${project.build.directory}/../../intg/target/test-classes</value> </systemProperty> </systemProperties> <stopKey>atlas-stop</stopKey> @@ -665,11 +648,6 @@ </execution> </executions> </plugin> - <plugin> - <groupId>net.alchim31.maven</groupId> - <artifactId>scala-maven-plugin</artifactId> - <version>3.2.0</version> - </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/webapp/src/main/java/org/apache/atlas/classification/InterfaceAudience.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/classification/InterfaceAudience.java b/webapp/src/main/java/org/apache/atlas/classification/InterfaceAudience.java new file mode 100755 index 0000000..ae162ac --- /dev/null +++ b/webapp/src/main/java/org/apache/atlas/classification/InterfaceAudience.java @@ -0,0 +1,48 @@ +/** + * 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.classification; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * Annotation to mark methods for consumption. + */ +@InterfaceAudience.Public +public class InterfaceAudience { + private InterfaceAudience() { + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + public @interface Private { + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + public @interface LimitedPrivate { + String[] value(); + } + + @Documented + @Retention(RetentionPolicy.RUNTIME) + public @interface Public { + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java b/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java index 91ba111..0e2d32d 100755 --- a/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java +++ b/webapp/src/main/java/org/apache/atlas/examples/QuickStart.java @@ -20,31 +20,23 @@ package org.apache.atlas.examples; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import org.apache.atlas.ApplicationProperties; import org.apache.atlas.AtlasClient; import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasException; import org.apache.atlas.exception.AtlasBaseException; -import org.apache.atlas.typesystem.Referenceable; -import org.apache.atlas.typesystem.TypesDef; -import org.apache.atlas.typesystem.json.InstanceSerialization; -import org.apache.atlas.typesystem.json.TypesSerialization; -import org.apache.atlas.typesystem.persistence.Id; -import org.apache.atlas.typesystem.types.AttributeDefinition; -import org.apache.atlas.typesystem.types.ClassType; -import org.apache.atlas.typesystem.types.DataTypes; -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.Multiplicity; -import org.apache.atlas.typesystem.types.StructTypeDefinition; -import org.apache.atlas.typesystem.types.TraitType; -import org.apache.atlas.typesystem.types.utils.TypesUtil; +import org.apache.atlas.model.typedef.AtlasBaseTypeDef; +import org.apache.atlas.v1.model.instance.Id; +import org.apache.atlas.v1.model.instance.Referenceable; +import org.apache.atlas.v1.model.typedef.*; +import org.apache.atlas.type.AtlasType; +import org.apache.atlas.v1.typesystem.types.utils.TypesUtil; import org.apache.atlas.utils.AuthenticationUtil; import org.apache.commons.configuration.Configuration; import org.codehaus.jettison.json.JSONArray; + +import java.util.Arrays; +import java.util.Collections; import java.util.List; /** @@ -142,7 +134,7 @@ public class QuickStart { void createTypes() throws Exception { TypesDef typesDef = createTypeDefinitions(); - String typesAsJSON = TypesSerialization.toJson(typesDef); + String typesAsJSON = AtlasType.toV1Json(typesDef); System.out.println("typesAsJSON = " + typesAsJSON); metadataServiceClient.createType(typesAsJSON); @@ -151,80 +143,80 @@ public class QuickStart { } TypesDef createTypeDefinitions() throws Exception { - HierarchicalTypeDefinition<ClassType> dbClsDef = TypesUtil + ClassTypeDefinition dbClsDef = TypesUtil .createClassTypeDef(DATABASE_TYPE, DATABASE_TYPE, null, - TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), - attrDef("description", DataTypes.STRING_TYPE), attrDef("locationUri", DataTypes.STRING_TYPE), - attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE)); + TypesUtil.createUniqueRequiredAttrDef("name", AtlasBaseTypeDef.ATLAS_TYPE_STRING), + attrDef("description", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("locationUri", AtlasBaseTypeDef.ATLAS_TYPE_STRING), + attrDef("owner", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("createTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG)); - HierarchicalTypeDefinition<ClassType> storageDescClsDef = TypesUtil - .createClassTypeDef(STORAGE_DESC_TYPE, STORAGE_DESC_TYPE, null, attrDef("location", DataTypes.STRING_TYPE), - attrDef("inputFormat", DataTypes.STRING_TYPE), attrDef("outputFormat", DataTypes.STRING_TYPE), - attrDef("compressed", DataTypes.STRING_TYPE, Multiplicity.REQUIRED, false, null)); + ClassTypeDefinition storageDescClsDef = TypesUtil + .createClassTypeDef(STORAGE_DESC_TYPE, STORAGE_DESC_TYPE, null, attrDef("location", AtlasBaseTypeDef.ATLAS_TYPE_STRING), + attrDef("inputFormat", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("outputFormat", AtlasBaseTypeDef.ATLAS_TYPE_STRING), + attrDef("compressed", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED, false, null)); - HierarchicalTypeDefinition<ClassType> columnClsDef = TypesUtil - .createClassTypeDef(COLUMN_TYPE, COLUMN_TYPE, null, attrDef("name", DataTypes.STRING_TYPE), - attrDef("dataType", DataTypes.STRING_TYPE), attrDef("comment", DataTypes.STRING_TYPE)); + ClassTypeDefinition columnClsDef = TypesUtil + .createClassTypeDef(COLUMN_TYPE, COLUMN_TYPE, null, attrDef("name", AtlasBaseTypeDef.ATLAS_TYPE_STRING), + attrDef("dataType", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("comment", AtlasBaseTypeDef.ATLAS_TYPE_STRING)); - HierarchicalTypeDefinition<ClassType> tblClsDef = TypesUtil - .createClassTypeDef(TABLE_TYPE, TABLE_TYPE, ImmutableSet.of("DataSet"), + ClassTypeDefinition tblClsDef = TypesUtil + .createClassTypeDef(TABLE_TYPE, TABLE_TYPE, Collections.singleton("DataSet"), new AttributeDefinition(DB_ATTRIBUTE, DATABASE_TYPE, Multiplicity.REQUIRED, false, null), new AttributeDefinition("sd", STORAGE_DESC_TYPE, Multiplicity.REQUIRED, true, null), - attrDef("owner", DataTypes.STRING_TYPE), attrDef("createTime", DataTypes.LONG_TYPE), - attrDef("lastAccessTime", DataTypes.LONG_TYPE), attrDef("retention", DataTypes.LONG_TYPE), - attrDef("viewOriginalText", DataTypes.STRING_TYPE), - attrDef("viewExpandedText", DataTypes.STRING_TYPE), attrDef("tableType", DataTypes.STRING_TYPE), - attrDef("temporary", DataTypes.BOOLEAN_TYPE), - new AttributeDefinition(COLUMNS_ATTRIBUTE, DataTypes.arrayTypeName(COLUMN_TYPE), + attrDef("owner", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("createTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG), + attrDef("lastAccessTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG), attrDef("retention", AtlasBaseTypeDef.ATLAS_TYPE_LONG), + attrDef("viewOriginalText", AtlasBaseTypeDef.ATLAS_TYPE_STRING), + attrDef("viewExpandedText", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("tableType", AtlasBaseTypeDef.ATLAS_TYPE_STRING), + attrDef("temporary", AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN), + new AttributeDefinition(COLUMNS_ATTRIBUTE, AtlasBaseTypeDef.getArrayTypeName(COLUMN_TYPE), Multiplicity.COLLECTION, true, null)); - HierarchicalTypeDefinition<ClassType> loadProcessClsDef = TypesUtil - .createClassTypeDef(LOAD_PROCESS_TYPE, LOAD_PROCESS_TYPE, ImmutableSet.of("Process"), - attrDef("userName", DataTypes.STRING_TYPE), attrDef("startTime", DataTypes.LONG_TYPE), - attrDef("endTime", DataTypes.LONG_TYPE), - attrDef("queryText", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), - attrDef("queryPlan", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), - attrDef("queryId", DataTypes.STRING_TYPE, Multiplicity.REQUIRED), - attrDef("queryGraph", DataTypes.STRING_TYPE, Multiplicity.REQUIRED)); - - HierarchicalTypeDefinition<ClassType> viewClsDef = TypesUtil - .createClassTypeDef(VIEW_TYPE, VIEW_TYPE, ImmutableSet.of("DataSet"), + ClassTypeDefinition loadProcessClsDef = TypesUtil + .createClassTypeDef(LOAD_PROCESS_TYPE, LOAD_PROCESS_TYPE, Collections.singleton("Process"), + attrDef("userName", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("startTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG), + attrDef("endTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG), + attrDef("queryText", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED), + attrDef("queryPlan", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED), + attrDef("queryId", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED), + attrDef("queryGraph", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED)); + + ClassTypeDefinition viewClsDef = TypesUtil + .createClassTypeDef(VIEW_TYPE, VIEW_TYPE, Collections.singleton("DataSet"), new AttributeDefinition("db", DATABASE_TYPE, Multiplicity.REQUIRED, false, null), - new AttributeDefinition("inputTables", DataTypes.arrayTypeName(TABLE_TYPE), + new AttributeDefinition("inputTables", AtlasBaseTypeDef.getArrayTypeName(TABLE_TYPE), Multiplicity.COLLECTION, false, null)); - HierarchicalTypeDefinition<TraitType> dimTraitDef = TypesUtil.createTraitTypeDef("Dimension_v1", "Dimension Trait", null); + TraitTypeDefinition dimTraitDef = TypesUtil.createTraitTypeDef("Dimension_v1", "Dimension Trait", null); - HierarchicalTypeDefinition<TraitType> factTraitDef = TypesUtil.createTraitTypeDef("Fact_v1", "Fact Trait", null); + TraitTypeDefinition factTraitDef = TypesUtil.createTraitTypeDef("Fact_v1", "Fact Trait", null); - HierarchicalTypeDefinition<TraitType> piiTraitDef = TypesUtil.createTraitTypeDef("PII_v1", "PII Trait", null); + TraitTypeDefinition piiTraitDef = TypesUtil.createTraitTypeDef("PII_v1", "PII Trait", null); - HierarchicalTypeDefinition<TraitType> metricTraitDef = TypesUtil.createTraitTypeDef("Metric_v1", "Metric Trait", null); + TraitTypeDefinition metricTraitDef = TypesUtil.createTraitTypeDef("Metric_v1", "Metric Trait", null); - HierarchicalTypeDefinition<TraitType> etlTraitDef = TypesUtil.createTraitTypeDef("ETL_v1", "ETL Trait", null); + TraitTypeDefinition etlTraitDef = TypesUtil.createTraitTypeDef("ETL_v1", "ETL Trait", null); - HierarchicalTypeDefinition<TraitType> jdbcTraitDef = TypesUtil.createTraitTypeDef("JdbcAccess_v1", "JdbcAccess Trait", null); + TraitTypeDefinition jdbcTraitDef = TypesUtil.createTraitTypeDef("JdbcAccess_v1", "JdbcAccess Trait", null); - HierarchicalTypeDefinition<TraitType> logTraitDef = TypesUtil.createTraitTypeDef("Log Data_v1", "LogData Trait", null); + TraitTypeDefinition logTraitDef = TypesUtil.createTraitTypeDef("Log Data_v1", "LogData Trait", null); - return TypesUtil.getTypesDef(ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), - ImmutableList.of(dimTraitDef, factTraitDef, piiTraitDef, metricTraitDef, etlTraitDef, jdbcTraitDef, logTraitDef), - ImmutableList.of(dbClsDef, storageDescClsDef, columnClsDef, tblClsDef, loadProcessClsDef, viewClsDef)); + return new TypesDef(Collections.<EnumTypeDefinition>emptyList(), Collections.<StructTypeDefinition>emptyList(), + Arrays.asList(dimTraitDef, factTraitDef, piiTraitDef, metricTraitDef, etlTraitDef, jdbcTraitDef, logTraitDef), + Arrays.asList(dbClsDef, storageDescClsDef, columnClsDef, tblClsDef, loadProcessClsDef, viewClsDef)); } - AttributeDefinition attrDef(String name, IDataType dT) { + AttributeDefinition attrDef(String name, String dT) { return attrDef(name, dT, Multiplicity.OPTIONAL, false, null); } - AttributeDefinition attrDef(String name, IDataType dT, Multiplicity m) { + AttributeDefinition attrDef(String name, String dT, Multiplicity m) { return attrDef(name, dT, m, false, null); } - AttributeDefinition attrDef(String name, IDataType dT, Multiplicity m, boolean isComposite, + AttributeDefinition attrDef(String name, String dT, Multiplicity m, boolean isComposite, String reverseAttributeName) { Preconditions.checkNotNull(name); Preconditions.checkNotNull(dT); - return new AttributeDefinition(name, dT.getName(), m, isComposite, reverseAttributeName); + return new AttributeDefinition(name, dT, m, isComposite, reverseAttributeName); } void createEntities() throws Exception { @@ -235,35 +227,31 @@ public class QuickStart { rawStorageDescriptor("hdfs://host:8000/apps/warehouse/sales", "TextInputFormat", "TextOutputFormat", true); - List<Referenceable> salesFactColumns = ImmutableList - .of(rawColumn(TIME_ID_COLUMN, "int", "time id"), rawColumn("product_id", "int", "product id"), + List<Referenceable> salesFactColumns = Arrays.asList(rawColumn(TIME_ID_COLUMN, "int", "time id"), rawColumn("product_id", "int", "product id"), rawColumn("customer_id", "int", "customer id", "PII_v1"), rawColumn("sales", "double", "product id", "Metric_v1")); - List<Referenceable> logFactColumns = ImmutableList - .of(rawColumn("time_id", "int", "time id"), rawColumn("app_id", "int", "app id"), + List<Referenceable> logFactColumns = Arrays.asList(rawColumn("time_id", "int", "time id"), rawColumn("app_id", "int", "app id"), rawColumn("machine_id", "int", "machine id"), rawColumn("log", "string", "log data", "Log Data_v1")); Id salesFact = table(SALES_FACT_TABLE, SALES_FACT_TABLE_DESCRIPTION, salesDB, sd, "Joe", "Managed", salesFactColumns, FACT_TRAIT); - List<Referenceable> productDimColumns = ImmutableList - .of(rawColumn("product_id", "int", "product id"), rawColumn("product_name", "string", "product name"), + List<Referenceable> productDimColumns = Arrays.asList(rawColumn("product_id", "int", "product id"), rawColumn("product_name", "string", "product name"), rawColumn("brand_name", "int", "brand name")); Id productDim = table(PRODUCT_DIM_TABLE, "product dimension table", salesDB, sd, "John Doe", "Managed", productDimColumns, "Dimension_v1"); - List<Referenceable> timeDimColumns = ImmutableList - .of(rawColumn("time_id", "int", "time id"), rawColumn("dayOfYear", "int", "day Of Year"), + List<Referenceable> timeDimColumns = Arrays.asList(rawColumn("time_id", "int", "time id"), rawColumn("dayOfYear", "int", "day Of Year"), rawColumn("weekDay", "int", "week Day")); Id timeDim = table(TIME_DIM_TABLE, "time dimension table", salesDB, sd, "John Doe", "External", timeDimColumns, "Dimension_v1"); - List<Referenceable> customerDimColumns = ImmutableList.of(rawColumn("customer_id", "int", "customer id", "PII_v1"), + List<Referenceable> customerDimColumns = Arrays.asList(rawColumn("customer_id", "int", "customer id", "PII_v1"), rawColumn("name", "string", "customer name", "PII_v1"), rawColumn("address", "string", "customer address", "PII_v1")); @@ -286,32 +274,32 @@ public class QuickStart { logFactColumns, "Log Data_v1"); loadProcess(LOAD_SALES_DAILY_PROCESS, LOAD_SALES_DAILY_PROCESS_DESCRIPTION, "John ETL", - ImmutableList.of(salesFact, timeDim), - ImmutableList.of(salesFactDaily), "create table as select ", "plan", "id", "graph", "ETL_v1"); + Arrays.asList(salesFact, timeDim), + Collections.singletonList(salesFactDaily), "create table as select ", "plan", "id", "graph", "ETL_v1"); - view(PRODUCT_DIM_VIEW, reportingDB, ImmutableList.of(productDim), "Dimension_v1", "JdbcAccess_v1"); + view(PRODUCT_DIM_VIEW, reportingDB, Collections.singletonList(productDim), "Dimension_v1", "JdbcAccess_v1"); - view("customer_dim_view", reportingDB, ImmutableList.of(customerDim), "Dimension_v1", "JdbcAccess_v1"); + view("customer_dim_view", reportingDB, Collections.singletonList(customerDim), "Dimension_v1", "JdbcAccess_v1"); Id salesFactMonthly = table("sales_fact_monthly_mv", "sales fact monthly materialized view", reportingDB, sd, "Jane BI", "Managed", salesFactColumns, "Metric_v1"); - loadProcess("loadSalesMonthly", "hive query for monthly summary", "John ETL", ImmutableList.of(salesFactDaily), - ImmutableList.of(salesFactMonthly), "create table as select ", "plan", "id", "graph", "ETL_v1"); + loadProcess("loadSalesMonthly", "hive query for monthly summary", "John ETL", Collections.singletonList(salesFactDaily), + Collections.singletonList(salesFactMonthly), "create table as select ", "plan", "id", "graph", "ETL_v1"); Id loggingFactMonthly = table("logging_fact_monthly_mv", "logging fact monthly materialized view", logDB, sd, "Tim ETL", "Managed", logFactColumns, "Log Data_v1"); - loadProcess("loadLogsMonthly", "hive query for monthly summary", "Tim ETL", ImmutableList.of(loggingFactDaily), - ImmutableList.of(loggingFactMonthly), "create table as select ", "plan", "id", "graph", "ETL_v1"); + loadProcess("loadLogsMonthly", "hive query for monthly summary", "Tim ETL", Collections.singletonList(loggingFactDaily), + Collections.singletonList(loggingFactMonthly), "create table as select ", "plan", "id", "graph", "ETL_v1"); } private Id createInstance(Referenceable referenceable) throws Exception { String typeName = referenceable.getTypeName(); - String entityJSON = InstanceSerialization.toJson(referenceable, true); + String entityJSON = AtlasType.toV1Json(referenceable); System.out.println("Submitting new entity= " + entityJSON); List<String> guids = metadataServiceClient.createEntity(entityJSON); System.out.println("created instance for type " + typeName + ", guid: " + guids); http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/webapp/src/main/java/org/apache/atlas/examples/QuickStartV2.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/examples/QuickStartV2.java b/webapp/src/main/java/org/apache/atlas/examples/QuickStartV2.java index a95fac3..a338ae2 100755 --- a/webapp/src/main/java/org/apache/atlas/examples/QuickStartV2.java +++ b/webapp/src/main/java/org/apache/atlas/examples/QuickStartV2.java @@ -19,8 +19,6 @@ package org.apache.atlas.examples; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import com.sun.jersey.core.util.MultivaluedMapImpl; import org.apache.atlas.ApplicationProperties; import org.apache.atlas.AtlasClient; @@ -53,11 +51,7 @@ import org.apache.commons.configuration.Configuration; import org.apache.commons.lang.ArrayUtils; import javax.ws.rs.core.MultivaluedMap; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_PARAM_ATTRIBUTE; import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.CONSTRAINT_TYPE_INVERSE_REF; @@ -218,7 +212,7 @@ public class QuickStartV2 { colType.setOptions(new HashMap<String, String>() {{ put("schemaAttributes", "[\"name\", \"description\", \"owner\", \"type\", \"comment\", \"position\"]"); }}); - AtlasEntityDef tblType = AtlasTypeUtil.createClassTypeDef(TABLE_TYPE, TABLE_TYPE, "1.0", ImmutableSet.of("DataSet"), + AtlasEntityDef tblType = AtlasTypeUtil.createClassTypeDef(TABLE_TYPE, TABLE_TYPE, "1.0", Collections.singleton("DataSet"), AtlasTypeUtil.createRequiredAttrDef("db", DATABASE_TYPE), AtlasTypeUtil.createRequiredAttrDefWithConstraint("sd", STORAGE_DESC_TYPE, CONSTRAINT_TYPE_OWNED_REF, null), AtlasTypeUtil.createOptionalAttrDef("owner", "string"), @@ -234,7 +228,7 @@ public class QuickStartV2 { tblType.setOptions(new HashMap<String, String>() {{ put("schemaElementsAttribute", "columns"); }}); - AtlasEntityDef procType = AtlasTypeUtil.createClassTypeDef(LOAD_PROCESS_TYPE, LOAD_PROCESS_TYPE, "1.0", ImmutableSet.of("Process"), + AtlasEntityDef procType = AtlasTypeUtil.createClassTypeDef(LOAD_PROCESS_TYPE, LOAD_PROCESS_TYPE, "1.0", Collections.singleton("Process"), AtlasTypeUtil.createOptionalAttrDef("userName", "string"), AtlasTypeUtil.createOptionalAttrDef("startTime", "long"), AtlasTypeUtil.createOptionalAttrDef("endTime", "long"), @@ -243,22 +237,22 @@ public class QuickStartV2 { AtlasTypeUtil.createRequiredAttrDef("queryId", "string"), AtlasTypeUtil.createRequiredAttrDef("queryGraph", "string")); - AtlasEntityDef viewType = AtlasTypeUtil.createClassTypeDef(VIEW_TYPE, VIEW_TYPE, "1.0", ImmutableSet.of("DataSet"), + AtlasEntityDef viewType = AtlasTypeUtil.createClassTypeDef(VIEW_TYPE, VIEW_TYPE, "1.0", Collections.singleton("DataSet"), AtlasTypeUtil.createRequiredAttrDef("db", DATABASE_TYPE), AtlasTypeUtil.createOptionalListAttrDef("inputTables", AtlasBaseTypeDef.getArrayTypeName(TABLE_TYPE))); - AtlasClassificationDef dimClassifDef = AtlasTypeUtil.createTraitTypeDef(DIMENSION_CLASSIFICATION, "Dimension Classification", "1.0", ImmutableSet.<String>of()); - AtlasClassificationDef factClassifDef = AtlasTypeUtil.createTraitTypeDef(FACT_CLASSIFICATION, "Fact Classification", "1.0", ImmutableSet.<String>of()); - AtlasClassificationDef piiClassifDef = AtlasTypeUtil.createTraitTypeDef(PII_CLASSIFICATION, "PII Classification", "1.0", ImmutableSet.<String>of()); - AtlasClassificationDef metricClassifDef = AtlasTypeUtil.createTraitTypeDef(METRIC_CLASSIFICATION, "Metric Classification", "1.0", ImmutableSet.<String>of()); - AtlasClassificationDef etlClassifDef = AtlasTypeUtil.createTraitTypeDef(ETL_CLASSIFICATION, "ETL Classification", "1.0", ImmutableSet.<String>of()); - AtlasClassificationDef jdbcClassifDef = AtlasTypeUtil.createTraitTypeDef(JDBC_CLASSIFICATION, "JdbcAccess Classification", "1.0", ImmutableSet.<String>of()); - AtlasClassificationDef logClassifDef = AtlasTypeUtil.createTraitTypeDef(LOGDATA_CLASSIFICATION, "LogData Classification", "1.0", ImmutableSet.<String>of()); - - return AtlasTypeUtil.getTypesDef(ImmutableList.<AtlasEnumDef>of(), - ImmutableList.<AtlasStructDef>of(), - ImmutableList.of(dimClassifDef, factClassifDef, piiClassifDef, metricClassifDef, etlClassifDef, jdbcClassifDef, logClassifDef), - ImmutableList.of(dbType, sdType, colType, tblType, procType, viewType)); + AtlasClassificationDef dimClassifDef = AtlasTypeUtil.createTraitTypeDef(DIMENSION_CLASSIFICATION, "Dimension Classification", "1.0", Collections.<String>emptySet()); + AtlasClassificationDef factClassifDef = AtlasTypeUtil.createTraitTypeDef(FACT_CLASSIFICATION, "Fact Classification", "1.0", Collections.<String>emptySet()); + AtlasClassificationDef piiClassifDef = AtlasTypeUtil.createTraitTypeDef(PII_CLASSIFICATION, "PII Classification", "1.0", Collections.<String>emptySet()); + AtlasClassificationDef metricClassifDef = AtlasTypeUtil.createTraitTypeDef(METRIC_CLASSIFICATION, "Metric Classification", "1.0", Collections.<String>emptySet()); + AtlasClassificationDef etlClassifDef = AtlasTypeUtil.createTraitTypeDef(ETL_CLASSIFICATION, "ETL Classification", "1.0", Collections.<String>emptySet()); + AtlasClassificationDef jdbcClassifDef = AtlasTypeUtil.createTraitTypeDef(JDBC_CLASSIFICATION, "JdbcAccess Classification", "1.0", Collections.<String>emptySet()); + AtlasClassificationDef logClassifDef = AtlasTypeUtil.createTraitTypeDef(LOGDATA_CLASSIFICATION, "LogData Classification", "1.0", Collections.<String>emptySet()); + + return AtlasTypeUtil.getTypesDef(Collections.<AtlasEnumDef>emptyList(), + Collections.<AtlasStructDef>emptyList(), + Arrays.asList(dimClassifDef, factClassifDef, piiClassifDef, metricClassifDef, etlClassifDef, jdbcClassifDef, logClassifDef), + Arrays.asList(dbType, sdType, colType, tblType, procType, viewType)); } void createEntities() throws Exception { @@ -273,25 +267,25 @@ public class QuickStartV2 { AtlasEntity storageDesc = createStorageDescriptor("hdfs://host:8000/apps/warehouse/sales", "TextInputFormat", "TextOutputFormat", true); // Column entities - List<AtlasEntity> salesFactColumns = ImmutableList.of(createColumn(TIME_ID_COLUMN, "int", "time id"), + List<AtlasEntity> salesFactColumns = Arrays.asList(createColumn(TIME_ID_COLUMN, "int", "time id"), createColumn(PRODUCT_ID_COLUMN, "int", "product id"), createColumn(CUSTOMER_ID_COLUMN, "int", "customer id", PII_CLASSIFICATION), createColumn(SALES_COLUMN, "double", "product id", METRIC_CLASSIFICATION)); - List<AtlasEntity> logFactColumns = ImmutableList.of(createColumn(TIME_ID_COLUMN, "int", "time id"), + List<AtlasEntity> logFactColumns = Arrays.asList(createColumn(TIME_ID_COLUMN, "int", "time id"), createColumn(APP_ID_COLUMN, "int", "app id"), createColumn(MACHINE_ID_COLUMN, "int", "machine id"), createColumn(LOG_COLUMN, "string", "log data", LOGDATA_CLASSIFICATION)); - List<AtlasEntity> productDimColumns = ImmutableList.of(createColumn(PRODUCT_ID_COLUMN, "int", "product id"), + List<AtlasEntity> productDimColumns = Arrays.asList(createColumn(PRODUCT_ID_COLUMN, "int", "product id"), createColumn(PRODUCT_NAME_COLUMN, "string", "product name"), createColumn(BRAND_NAME_COLUMN, "int", "brand name")); - List<AtlasEntity> timeDimColumns = ImmutableList.of(createColumn(TIME_ID_COLUMN, "int", "time id"), + List<AtlasEntity> timeDimColumns = Arrays.asList(createColumn(TIME_ID_COLUMN, "int", "time id"), createColumn(DAY_OF_YEAR_COLUMN, "int", "day Of Year"), createColumn(WEEKDAY_COLUMN, "int", "week Day")); - List<AtlasEntity> customerDimColumns = ImmutableList.of(createColumn(CUSTOMER_ID_COLUMN, "int", "customer id", PII_CLASSIFICATION), + List<AtlasEntity> customerDimColumns = Arrays.asList(createColumn(CUSTOMER_ID_COLUMN, "int", "customer id", PII_CLASSIFICATION), createColumn(NAME_COLUMN, "string", "customer name", PII_CLASSIFICATION), createColumn(ADDRESS_COLUMN, "string", "customer address", PII_CLASSIFICATION)); @@ -314,23 +308,23 @@ public class QuickStartV2 { storageDesc, "Jane BI", "Managed", salesFactColumns, METRIC_CLASSIFICATION); // View entities - createView(PRODUCT_DIM_VIEW, reportingDB, ImmutableList.of(productDim), DIMENSION_CLASSIFICATION, JDBC_CLASSIFICATION); - createView(CUSTOMER_DIM_VIEW, reportingDB, ImmutableList.of(customerDim), DIMENSION_CLASSIFICATION, JDBC_CLASSIFICATION); + createView(PRODUCT_DIM_VIEW, reportingDB, Collections.singletonList(productDim), DIMENSION_CLASSIFICATION, JDBC_CLASSIFICATION); + createView(CUSTOMER_DIM_VIEW, reportingDB, Collections.singletonList(customerDim), DIMENSION_CLASSIFICATION, JDBC_CLASSIFICATION); // Process entities createProcess(LOAD_SALES_DAILY_PROCESS, "hive query for daily summary", "John ETL", - ImmutableList.of(salesFact, timeDim), - ImmutableList.of(salesFactDaily), + Arrays.asList(salesFact, timeDim), + Collections.singletonList(salesFactDaily), "create table as select ", "plan", "id", "graph", ETL_CLASSIFICATION); createProcess(LOAD_SALES_MONTHLY_PROCESS, "hive query for monthly summary", "John ETL", - ImmutableList.of(salesFactDaily), - ImmutableList.of(salesFactMonthly), + Collections.singletonList(salesFactDaily), + Collections.singletonList(salesFactMonthly), "create table as select ", "plan", "id", "graph", ETL_CLASSIFICATION); createProcess(LOAD_LOGS_MONTHLY_PROCESS, "hive query for monthly summary", "Tim ETL", - ImmutableList.of(loggingFactDaily), - ImmutableList.of(loggingFactMonthly), + Collections.singletonList(loggingFactDaily), + Collections.singletonList(loggingFactMonthly), "create table as select ", "plan", "id", "graph", ETL_CLASSIFICATION); } @@ -364,7 +358,7 @@ public class QuickStartV2 { private List<AtlasClassification> toAtlasClassifications(String[] traitNames) { List<AtlasClassification> ret = new ArrayList<>(); - ImmutableList<String> traits = ImmutableList.copyOf(traitNames); + List<String> traits = Arrays.asList(traitNames); if (CollectionUtils.isNotEmpty(traits)) { for (String trait : traits) {