http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/test/scala/org/apache/atlas/query/LineageQueryTest.scala ---------------------------------------------------------------------- diff --git a/repository/src/test/scala/org/apache/atlas/query/LineageQueryTest.scala b/repository/src/test/scala/org/apache/atlas/query/LineageQueryTest.scala deleted file mode 100755 index b01cbf8..0000000 --- a/repository/src/test/scala/org/apache/atlas/query/LineageQueryTest.scala +++ /dev/null @@ -1,541 +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.query - -import org.apache.atlas.{DBSandboxer, TestUtils} -import org.apache.atlas.discovery.graph.DefaultGraphPersistenceStrategy -import org.apache.atlas.query.Expressions._class -import org.apache.atlas.query.Expressions.id -import org.apache.atlas.query.Expressions.int -import org.apache.atlas.repository.graph.AtlasGraphProvider -import org.apache.atlas.repository.graph.GraphBackedMetadataRepository -import org.apache.atlas.repository.graphdb.AtlasGraph -import org.apache.atlas.typesystem.types.TypeSystem -import org.testng.annotations._ - -class LineageQueryTest extends BaseGremlinTest { - - var g: AtlasGraph[_,_] = null - var gp:GraphPersistenceStrategies = null; - - @BeforeMethod - def resetRequestContext() { - TestUtils.resetRequestContext() - } - - - @BeforeClass - def beforeAll() { - TypeSystem.getInstance().reset() - var repo = new GraphBackedMetadataRepository(null, new AtlasGraphProvider().get()); - TestUtils.setupGraphProvider(repo); - //force graph to be initialized first - AtlasGraphProvider.getGraphInstance(); - - //create types and indices up front. Without this, some of the property keys (particularly __traitNames and __superTypes) - //get ended up created implicitly with some graph backends with the wrong multiplicity. This also makes the queries - //we execute perform better :-) - QueryTestsUtils.setupTypesAndIndices() - - gp = new DefaultGraphPersistenceStrategy(repo); - g = QueryTestsUtils.setupTestGraph(repo) - } - - @AfterClass - def afterAll() { - AtlasGraphProvider.cleanup() - } - - val PREFIX_SPACES_REGEX = ("\\n\\s*").r - - @Test def testInputTables { - val r = QueryProcessor.evaluate(_class("LoadProcess").field("inputTables"), g, gp) - val x = r.toJson - validateJson(r,"""{ - | "query":"LoadProcess inputTables", - | "dataType":{ - | "superTypes":[ - | - | ], - | "hierarchicalMetaTypeName":"org.apache.atlas.typesystem.types.ClassType", - | "typeName":"Table", - | "attributeDefinitions":[ - | { - | "name":"name", - | "dataTypeName":"string", - | "multiplicity":{ - | "lower":0, - | "upper":1, - | "isUnique":false - | }, - | "isComposite":false, - | "isUnique":false, - | "isIndexable":false, - | "reverseAttributeName":null - | }, - | { - | "name":"db", - | "dataTypeName":"DB", - | "multiplicity":{ - | "lower":1, - | "upper":1, - | "isUnique":false - | }, - | "isComposite":false, - | "isUnique":false, - | "isIndexable":false, - | "reverseAttributeName":null - | }, - | { - | "name":"sd", - | "dataTypeName":"StorageDescriptor", - | "multiplicity":{ - | "lower":1, - | "upper":1, - | "isUnique":false - | }, - | "isComposite":false, - | "isUnique":false, - | "isIndexable":false, - | "reverseAttributeName":null - | }, - | { - | "name":"created", - | "dataTypeName":"date", - | "multiplicity":{ - | "lower":0, - | "upper":1, - | "isUnique":false - | }, - | "isComposite":false, - | "isUnique":false, - | "isIndexable":false, - | "reverseAttributeName":null - | } - | ] - | }, - | "rows":[ - | { - | "$typeName$":"Table", - | "$id$":{ - | "$typeName$":"Table", - | "version":0 - | }, - | "created":"2014-12-11T02:35:58.440Z", - | "sd":{ - | "$typeName$":"StorageDescriptor", - | "version":0 - | }, - | "db":{ - | "$typeName$":"DB", - | "version":0 - | }, - | "name":"sales_fact" - | }, - | { - | "$typeName$":"Table", - | "$id$":{ - | "$typeName$":"Table", - | "version":0 - | }, - | "created":"2014-12-11T02:35:58.440Z", - | "sd":{ - | "$typeName$":"StorageDescriptor", - | "version":0 - | }, - | "db":{ - | "$typeName$":"DB", - | "version":0 - | }, - | "name":"time_dim", - | "$traits$":{ - | "Dimension":{ - | "$typeName$":"Dimension" - | } - | } - | }, - | { - | "$typeName$":"Table", - | "$id$":{ - | "$typeName$":"Table", - | "version":0 - | }, - | "created":"2014-12-11T02:35:58.440Z", - | "sd":{ - | "$typeName$":"StorageDescriptor", - | "version":0 - | }, - | "db":{ - | "$typeName$":"DB", - | "version":0 - | }, - | "name":"sales_fact_daily_mv" - | } - | ] - |} - """.stripMargin) - } - - @Test def testLoadProcessOut { - val r = QueryProcessor.evaluate(_class("Table").field("LoadProcess").field("outputTable"), g, gp) - validateJson(r, null) - } - - @Test def testLineageAll { - val r = QueryProcessor.evaluate(_class("Table").loop(id("LoadProcess").field("outputTable")), g, gp) - validateJson(r, """{ - | "query":"Table as _loop0 loop (LoadProcess outputTable)", - | "dataType":{ - | "superTypes":[ - | - | ], - | "hierarchicalMetaTypeName":"org.apache.atlas.typesystem.types.ClassType", - | "typeName":"Table", - | "attributeDefinitions":[ - | { - | "name":"name", - | "dataTypeName":"string", - | "multiplicity":{ - | "lower":0, - | "upper":1, - | "isUnique":false - | }, - | "isComposite":false, - | "isUnique":false, - | "isIndexable":false, - | "reverseAttributeName":null - | }, - | { - | "name":"db", - | "dataTypeName":"DB", - | "multiplicity":{ - | "lower":1, - | "upper":1, - | "isUnique":false - | }, - | "isComposite":false, - | "isUnique":false, - | "isIndexable":false, - | "reverseAttributeName":null - | }, - | { - | "name":"sd", - | "dataTypeName":"StorageDescriptor", - | "multiplicity":{ - | "lower":1, - | "upper":1, - | "isUnique":false - | }, - | "isComposite":false, - | "isUnique":false, - | "isIndexable":false, - | "reverseAttributeName":null - | }, - | { - | "name":"created", - | "dataTypeName":"date", - | "multiplicity":{ - | "lower":0, - | "upper":1, - | "isUnique":false - | }, - | "isComposite":false, - | "isUnique":false, - | "isIndexable":false, - | "reverseAttributeName":null - | } - | ] - | }, - | "rows":[ - | { - | "$typeName$":"Table", - | "$id$":{ - | "$typeName$":"Table", - | "version":0 - | }, - | "created":"2014-12-11T02:35:58.440Z", - | "sd":{ - | "$typeName$":"StorageDescriptor", - | "version":0 - | }, - | "db":{ - | "$typeName$":"DB", - | "version":0 - | }, - | "name":"sales_fact_daily_mv" - | }, - | { - | "$typeName$":"Table", - | "$id$":{ - | "$typeName$":"Table", - | "version":0 - | }, - | "created":"2014-12-11T02:35:58.440Z", - | "sd":{ - | "$typeName$":"StorageDescriptor", - | "version":0 - | }, - | "db":{ - | "$typeName$":"DB", - | "version":0 - | }, - | "name":"sales_fact_monthly_mv" - | }, - | { - | "$typeName$":"Table", - | "$id$":{ - | "$typeName$":"Table", - | "version":0 - | }, - | "created":"2014-12-11T02:35:58.440Z", - | "sd":{ - | "$typeName$":"StorageDescriptor", - | "version":0 - | }, - | "db":{ - | "$typeName$":"DB", - | "version":0 - | }, - | "name":"sales_fact_daily_mv" - | }, - | { - | "$typeName$":"Table", - | "$id$":{ - | "$typeName$":"Table", - | "version":0 - | }, - | "created":"2014-12-11T02:35:58.440Z", - | "sd":{ - | "$typeName$":"StorageDescriptor", - | "version":0 - | }, - | "db":{ - | "$typeName$":"DB", - | "version":0 - | }, - | "name":"sales_fact_monthly_mv" - | }, - | { - | "$typeName$":"Table", - | "$id$":{ - | "$typeName$":"Table", - | "version":0 - | }, - | "created":"2014-12-11T02:35:58.440Z", - | "sd":{ - | "$typeName$":"StorageDescriptor", - | "version":0 - | }, - | "db":{ - | "$typeName$":"DB", - | "version":0 - | }, - | "name":"sales_fact_monthly_mv" - | } - | ] - |}""".stripMargin) - } - - @Test def testLineageAllSelect { - val r = QueryProcessor.evaluate(_class("Table").as("src").loop(id("LoadProcess").field("outputTable")).as("dest"). - select(id("src").field("name").as("srcTable"), id("dest").field("name").as("destTable")), g, gp) - validateJson(r, """{ - "query":"Table as src loop (LoadProcess outputTable) as dest select src.name as srcTable, dest.name as destTable", - "dataType":{ - "typeName":"__tempQueryResultStruct2", - "attributeDefinitions":[ - { - "name":"srcTable", - "dataTypeName":"string", - "multiplicity":{ - "lower":0, - "upper":1, - "isUnique":false - }, - "isComposite":false, - "isUnique":false, - "isIndexable":false, - "reverseAttributeName":null - }, - { - "name":"destTable", - "dataTypeName":"string", - "multiplicity":{ - "lower":0, - "upper":1, - "isUnique":false - }, - "isComposite":false, - "isUnique":false, - "isIndexable":false, - "reverseAttributeName":null - } - ] - }, - "rows":[ - { - "$typeName$":"__tempQueryResultStruct2", - "srcTable":"sales_fact", - "destTable":"sales_fact_daily_mv" - }, - { - "$typeName$":"__tempQueryResultStruct2", - "srcTable":"sales_fact", - "destTable":"sales_fact_monthly_mv" - }, - { - "$typeName$":"__tempQueryResultStruct2", - "srcTable":"time_dim", - "destTable":"sales_fact_daily_mv" - }, - { - "$typeName$":"__tempQueryResultStruct2", - "srcTable":"time_dim", - "destTable":"sales_fact_monthly_mv" - }, - { - "$typeName$":"__tempQueryResultStruct2", - "srcTable":"sales_fact_daily_mv", - "destTable":"sales_fact_monthly_mv" - } - ] -}""".stripMargin) - } - - @Test def testLineageFixedDepth { - val r = QueryProcessor.evaluate(_class("Table").loop(id("LoadProcess").field("outputTable"), int(1)), g, gp) - validateJson(r, """{ - | "query":"Table as _loop0 loop (LoadProcess outputTable) times 1", - | "dataType":{ - | "superTypes":[ - | - | ], - | "hierarchicalMetaTypeName":"org.apache.atlas.typesystem.types.ClassType", - | "typeName":"Table", - | "attributeDefinitions":[ - | { - | "name":"name", - | "dataTypeName":"string", - | "multiplicity":{ - | "lower":0, - | "upper":1, - | "isUnique":false - | }, - | "isComposite":false, - | "isUnique":false, - | "isIndexable":false, - | "reverseAttributeName":null - | }, - | { - | "name":"db", - | "dataTypeName":"DB", - | "multiplicity":{ - | "lower":1, - | "upper":1, - | "isUnique":false - | }, - | "isComposite":false, - | "isUnique":false, - | "isIndexable":false, - | "reverseAttributeName":null - | }, - | { - | "name":"sd", - | "dataTypeName":"StorageDescriptor", - | "multiplicity":{ - | "lower":1, - | "upper":1, - | "isUnique":false - | }, - | "isComposite":false, - | "isUnique":false, - | "isIndexable":false, - | "reverseAttributeName":null - | }, - | { - | "name":"created", - | "dataTypeName":"date", - | "multiplicity":{ - | "lower":0, - | "upper":1, - | "isUnique":false - | }, - | "isComposite":false, - | "isUnique":false, - | "isIndexable":false, - | "reverseAttributeName":null - | } - | ] - | }, - | "rows":[ - | { - | "$typeName$":"Table", - | "$id$":{ - | "$typeName$":"Table", - | "version":0 - | }, - | "created":"2014-12-11T02:35:58.440Z", - | "sd":{ - | "$typeName$":"StorageDescriptor", - | "version":0 - | }, - | "db":{ - | "$typeName$":"DB", - | "version":0 - | }, - | "name":"sales_fact_daily_mv" - | }, - | { - | "$typeName$":"Table", - | "$id$":{ - | "$typeName$":"Table", - | "version":0 - | }, - | "created":"2014-12-11T02:35:58.440Z", - | "sd":{ - | "$typeName$":"StorageDescriptor", - | "version":0 - | }, - | "db":{ - | "$typeName$":"DB", - | "version":0 - | }, - | "name":"sales_fact_daily_mv" - | }, - | { - | "$typeName$":"Table", - | "$id$":{ - | "$typeName$":"Table", - | "version":0 - | }, - | "created":"2014-12-11T02:35:58.440Z", - | "sd":{ - | "$typeName$":"StorageDescriptor", - | "version":0 - | }, - | "db":{ - | "$typeName$":"DB", - | "version":0 - | }, - | "name":"sales_fact_monthly_mv" - | } - | ] - |}""".stripMargin) - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/test/scala/org/apache/atlas/query/ParserTest.scala ---------------------------------------------------------------------- diff --git a/repository/src/test/scala/org/apache/atlas/query/ParserTest.scala b/repository/src/test/scala/org/apache/atlas/query/ParserTest.scala deleted file mode 100755 index de5d879..0000000 --- a/repository/src/test/scala/org/apache/atlas/query/ParserTest.scala +++ /dev/null @@ -1,100 +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.query - -import org.apache.atlas.DBSandboxer -import org.apache.atlas.repository.BaseTest -import org.testng.annotations.{BeforeMethod, Listeners, Test} - - -class ParserTest extends BaseTest { - - @BeforeMethod - override def setup { - super.setup - QueryTestsUtils.setupTypes - } - - @Test def testFrom: Unit = { - println(QueryParser.apply("from DB").right.get.toString) - } - - @Test def testFrom2: Unit = { - println(QueryParser.apply("DB").right.get.toString) - } - - @Test def testJoin1: Unit = { - println(QueryParser.apply("DB, Table").right.get.toString) - } - - @Test def testWhere1: Unit = { - println(QueryParser.apply("DB as db1 Table where db1.name ").right.get.toString) - } - - @Test def testWhere2: Unit = { - println(QueryParser.apply("DB name = \"Reporting\"").right.get.toString) - } - - @Test def testIsTrait: Unit = { - println(QueryParser.apply("Table isa Dimension").right.get.toString) - println(QueryParser.apply("Table is Dimension").right.get.toString) - } - - @Test def test4: Unit = { - println(QueryParser.apply("DB where (name = \"Reporting\") select name as _col_0, (createTime + 1) as _col_1").right.get.toString) - } - - @Test def testJoin2: Unit = { - println(QueryParser.apply("DB as db1 where (createTime + 1) > 0 and (db1.name = \"Reporting\") or DB has owner Table as tab " + - " select db1.name as dbName, tab.name as tabName").right.get.toString) - } - - @Test def testLoop: Unit = { - println(QueryParser.apply("Table loop (LoadProcess outputTable)").right.get.toString) - } - - @Test def testNegInvalidateType: Unit = { - val x = QueryParser.apply("from blah") - println(QueryParser.apply("from blah").left) - } - - @Test def testPath1: Unit = { - println(QueryParser.apply("Table loop (LoadProcess outputTable) withPath").right.get.toString) - } - - @Test def testPath2: Unit = { - println(QueryParser.apply( - "Table as src loop (LoadProcess outputTable) as dest " + - "select src.name as srcTable, dest.name as destTable withPath").right.get.toString - ) - } - - @Test def testList: Unit = { - println(QueryParser.apply( - "Partition as p where values = ['2015-01-01']," + - " table where name = 'tableoq8ty'," + - " db where name = 'default' and clusterName = 'test'").right.get.toString - ) - } - - @Test def testorder_by: Unit = { - println(QueryParser.apply("from DB order by columnA").right.get.toString) - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/repository/src/test/scala/org/apache/atlas/query/QueryTestsUtils.scala ---------------------------------------------------------------------- diff --git a/repository/src/test/scala/org/apache/atlas/query/QueryTestsUtils.scala b/repository/src/test/scala/org/apache/atlas/query/QueryTestsUtils.scala deleted file mode 100755 index f26f98e..0000000 --- a/repository/src/test/scala/org/apache/atlas/query/QueryTestsUtils.scala +++ /dev/null @@ -1,206 +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.query - -import java.io.File -import javax.script.{Bindings, ScriptEngine, ScriptEngineManager} - -import com.google.common.collect.ImmutableList -import org.apache.atlas.repository.graphdb.AtlasVertex -import com.typesafe.config.{Config, ConfigFactory} -import org.apache.atlas.typesystem.types._ -import org.apache.commons.configuration.{Configuration, ConfigurationException, MapConfiguration} -import org.apache.commons.io.FileUtils -import org.apache.commons.lang.RandomStringUtils -import org.json.JSONObject -import org.skyscreamer.jsonassert.JSONAssert - -import scala.util.Random -import org.apache.atlas.repository.MetadataRepository -import org.apache.atlas.repository.graphdb.AtlasGraph -import org.apache.atlas.repository.graph.AtlasGraphProvider -import java.net.URL - -import org.apache.atlas.`type`.AtlasTypeRegistry -import org.apache.atlas.repository.graph.GraphBackedSearchIndexer -import org.apache.atlas.typesystem.TypesDef -import org.apache.atlas.typesystem.ITypedReferenceableInstance - - -trait GraphUtils { - - import scala.collection.JavaConversions._ - - def getConfiguration(config: Config): Configuration = { - val keys = config.entrySet().map { - _.getKey - } - val gConfig: java.util.Map[String, String] = new java.util.HashMap[String, String]() - keys.foreach { k => - gConfig.put(k, config.getString(k)) - } - return new MapConfiguration(gConfig) - } - - - def graph(conf: Configuration) = { - try { - val g = AtlasGraphProvider.getGraphInstance - val mgmt = g.getManagementSystem - val typname = mgmt.makePropertyKey("typeName", classOf[String], null); - mgmt.createExactMatchIndex("byTypeName", false, List(typname)); - mgmt.commit() - g - } catch { - case e: ConfigurationException => throw new RuntimeException(e) - } - } -} - -object QueryTestsUtils extends GraphUtils { - - def setupTypesAndIndices() : Unit = { - val indexer = new GraphBackedSearchIndexer(new AtlasTypeRegistry()); - val typesDef : TypesDef = defineTypes; - val newTypes = TypeSystem.getInstance.defineTypes(typesDef); - indexer.onAdd(newTypes.values()); - } - - def setupTypes: Unit = { - - val types : TypesDef = defineTypes; - TypeSystem.getInstance.defineTypes(types); - } - - - def defineTypes: TypesDef = { - def attrDef(name: String, dT: IDataType[_], - m: Multiplicity = Multiplicity.OPTIONAL, - isComposite: Boolean = false, - reverseAttributeName: String = null) = { - require(name != null) - require(dT != null) - new AttributeDefinition(name, dT.getName, m, isComposite, reverseAttributeName) - } - - def dbClsDef = new HierarchicalTypeDefinition[ClassType](classOf[ClassType], "DB", null, null, - Array( - attrDef("name", DataTypes.STRING_TYPE), - attrDef("owner", DataTypes.STRING_TYPE), - attrDef("createTime", DataTypes.INT_TYPE), - attrDef("clusterName", DataTypes.STRING_TYPE) - )) - - def hiveOrderDef = new StructTypeDefinition("HiveOrder", - Array( - attrDef("col", DataTypes.STRING_TYPE), - attrDef("order", DataTypes.INT_TYPE) - )) - - def storageDescClsDef = new HierarchicalTypeDefinition[ClassType](classOf[ClassType], "StorageDescriptor", null, null, - Array( - attrDef("inputFormat", DataTypes.STRING_TYPE), - attrDef("outputFormat", DataTypes.STRING_TYPE), - new AttributeDefinition("sortCols", DataTypes.arrayTypeName("HiveOrder"), Multiplicity.REQUIRED, false, null) - )) - - def columnClsDef = new HierarchicalTypeDefinition[ClassType](classOf[ClassType], "Column", null, null, - Array( - attrDef("name", DataTypes.STRING_TYPE), - attrDef("dataType", DataTypes.STRING_TYPE), - new AttributeDefinition("sd", "StorageDescriptor", Multiplicity.REQUIRED, false, null) - )) - - def tblClsDef = new HierarchicalTypeDefinition[ClassType](classOf[ClassType], "Table", null, null, - Array( - attrDef("name", DataTypes.STRING_TYPE), - new AttributeDefinition("db", "DB", Multiplicity.REQUIRED, false, null), - new AttributeDefinition("sd", "StorageDescriptor", Multiplicity.REQUIRED, false, null), - attrDef("created", DataTypes.DATE_TYPE) - )) - - def partitionClsDef = new HierarchicalTypeDefinition[ClassType](classOf[ClassType], "Partition", null, null, - Array( - new AttributeDefinition("values", DataTypes.arrayTypeName(DataTypes.STRING_TYPE.getName), Multiplicity.REQUIRED, false, null), - new AttributeDefinition("table", "Table", Multiplicity.REQUIRED, false, null) - )) - - def loadProcessClsDef = new HierarchicalTypeDefinition[ClassType](classOf[ClassType], "LoadProcess", null, null, - Array( - attrDef("name", DataTypes.STRING_TYPE), - new AttributeDefinition("inputTables", DataTypes.arrayTypeName("Table"), Multiplicity.COLLECTION, false, null), - new AttributeDefinition("outputTable", "Table", Multiplicity.REQUIRED, false, null) - )) - - def viewClsDef = new HierarchicalTypeDefinition[ClassType](classOf[ClassType], "View", null, null, - Array( - attrDef("name", DataTypes.STRING_TYPE), - new AttributeDefinition("inputTables", DataTypes.arrayTypeName("Table"), Multiplicity.COLLECTION, false, null) - )) - - def dimTraitDef = new HierarchicalTypeDefinition[TraitType](classOf[TraitType], "Dimension", null, null, - Array[AttributeDefinition]()) - def piiTraitDef = new HierarchicalTypeDefinition[TraitType](classOf[TraitType], "PII", null, null, - Array[AttributeDefinition]()) - def metricTraitDef = new HierarchicalTypeDefinition[TraitType](classOf[TraitType], "Metric", null, null, - Array[AttributeDefinition]()) - def etlTraitDef = new HierarchicalTypeDefinition[TraitType](classOf[TraitType], "ETL", null, null, - Array[AttributeDefinition]()) - def jdbcTraitDef = new HierarchicalTypeDefinition[TraitType](classOf[TraitType], "JdbcAccess", null, null, - Array[AttributeDefinition]()) - - TypesDef(Seq[EnumTypeDefinition](), - Seq[StructTypeDefinition](hiveOrderDef), - Seq[HierarchicalTypeDefinition[TraitType]](dimTraitDef, piiTraitDef, - metricTraitDef, etlTraitDef, jdbcTraitDef), - Seq[HierarchicalTypeDefinition[ClassType]](dbClsDef, storageDescClsDef, columnClsDef, tblClsDef, - partitionClsDef, loadProcessClsDef, viewClsDef)) - } - - def setupTestGraph(repo : MetadataRepository): AtlasGraph[_,_] = { - - val g = AtlasGraphProvider.getGraphInstance(); - val entities = HiveTitanSample.getEntitiesToCreate(); - repo.createEntities(entities:_*) - g.commit(); - g - } - - - -} - - - -trait BaseGremlinTest { - val STRUCT_NAME_REGEX = (TypeUtils.TEMP_STRUCT_NAME_PREFIX + "\\d+").r - def validateJson(r: GremlinQueryResult, expected: String = null): Unit = { - val rJ = r.toJson - if (expected != null) { - val a = STRUCT_NAME_REGEX.replaceAllIn(rJ, "") - val b = STRUCT_NAME_REGEX.replaceAllIn(expected, "") - val actualjsonObj = new JSONObject(a) - val expectedjsonObj = new JSONObject(b) - JSONAssert.assertEquals(expectedjsonObj, actualjsonObj, false) - } else { - println(rJ) - } - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/pom.xml ---------------------------------------------------------------------- diff --git a/server-api/pom.xml b/server-api/pom.xml index 6e99ca3..6919dcd 100644 --- a/server-api/pom.xml +++ b/server-api/pom.xml @@ -37,11 +37,6 @@ </dependency> <dependency> - <groupId>org.apache.atlas</groupId> - <artifactId>atlas-typesystem</artifactId> - </dependency> - - <dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-common</artifactId> </dependency> http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/RequestContext.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/RequestContext.java b/server-api/src/main/java/org/apache/atlas/RequestContext.java deleted file mode 100644 index 3e729b5..0000000 --- a/server-api/src/main/java/org/apache/atlas/RequestContext.java +++ /dev/null @@ -1,197 +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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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; - -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; - -import org.apache.atlas.metrics.Metrics; -import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; -import org.apache.atlas.typesystem.ITypedReferenceableInstance; -import org.apache.atlas.typesystem.persistence.Id; -import org.apache.atlas.typesystem.types.ClassType; -import org.apache.atlas.typesystem.types.TypeSystem; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Deprecated -public class RequestContext { - private static final Logger LOG = LoggerFactory.getLogger(RequestContext.class); - - private static final ThreadLocal<RequestContext> CURRENT_CONTEXT = new ThreadLocal<>(); - - private Set<String> createdEntityIds = new LinkedHashSet<>(); - private Set<String> updatedEntityIds = new LinkedHashSet<>(); - private Set<String> deletedEntityIds = new LinkedHashSet<>(); - private List<ITypedReferenceableInstance> deletedEntities = new ArrayList<>(); - private Map<String,ITypedReferenceableInstance> entityCacheV1 = new HashMap<>(); - private Map<String,AtlasEntityWithExtInfo> entityCacheV2 = new HashMap<>(); - - private String user; - private long requestTime; - - private TypeSystem typeSystem = TypeSystem.getInstance(); - private Metrics metrics = new Metrics(); - - private RequestContext() { - } - - //To handle gets from background threads where createContext() is not called - //createContext called for every request in the filter - public static RequestContext get() { - if (CURRENT_CONTEXT.get() == null) { - synchronized (RequestContext.class) { - if (CURRENT_CONTEXT.get() == null) { - createContext(); - } - } - } - - // ensure that RequestContextV1 is also initialized for this request - RequestContextV1.get(); - - return CURRENT_CONTEXT.get(); - } - - public static RequestContext createContext() { - RequestContext context = new RequestContext(); - context.requestTime = System.currentTimeMillis(); - CURRENT_CONTEXT.set(context); - return context; - } - - /** - * Adds the specified instance to the cache - * - */ - public void cache(ITypedReferenceableInstance instance) { - entityCacheV1.put(instance.getId()._getId(), instance); - } - - /** - * Adds the specified instance to the cache - * - */ - public void cache(AtlasEntityWithExtInfo entity) { - if (entity != null && entity.getEntity() != null && entity.getEntity().getGuid() != null) { - entityCacheV2.put(entity.getEntity().getGuid(), entity); - } - } - - /** - * Checks if an instance with the given guid is in the cache for this request. Either returns the instance - * or null if it is not in the cache. - * - * @param guid the guid to find - * @return Either the instance or null if it is not in the cache. - */ - public ITypedReferenceableInstance getInstanceV1(String guid) { - return entityCacheV1.get(guid); - } - - /** - * Checks if an instance with the given guid is in the cache for this request. Either returns the instance - * or null if it is not in the cache. - * - * @param guid the guid to find - * @return Either the instance or null if it is not in the cache. - */ - public AtlasEntityWithExtInfo getInstanceV2(String guid) { - return entityCacheV2.get(guid); - } - - public static void clear() { - RequestContext instance = CURRENT_CONTEXT.get(); - - if (instance != null) { - if (instance.entityCacheV1 != null) { - instance.entityCacheV1.clear(); - } - - if (instance.entityCacheV2 != null) { - instance.entityCacheV2.clear(); - } - } - - CURRENT_CONTEXT.remove(); - } - - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - - RequestContextV1.get().setUser(user); - } - - public void recordEntityCreate(Collection<String> createdEntityIds) { - this.createdEntityIds.addAll(createdEntityIds); - } - - public void recordEntityUpdate(Collection<String> updatedEntityIds) { - this.updatedEntityIds.addAll(updatedEntityIds); - } - - public void recordEntityUpdate(String entityId) { - this.updatedEntityIds.add(entityId); - } - - public void recordEntityDelete(String entityId, String typeName) throws AtlasException { - ClassType type = typeSystem.getDataType(ClassType.class, typeName); - ITypedReferenceableInstance entity = type.createInstance(new Id(entityId, 0, typeName)); - if (deletedEntityIds.add(entityId)) { - deletedEntities.add(entity); - } - } - - public List<String> getCreatedEntityIds() { - return new ArrayList<>(createdEntityIds); - } - - public List<String> getUpdatedEntityIds() { - return new ArrayList<>(updatedEntityIds); - } - - public List<String> getDeletedEntityIds() { - return new ArrayList<>(deletedEntityIds); - } - - public List<ITypedReferenceableInstance> getDeletedEntities() { - return deletedEntities; - } - - public long getRequestTime() { - return requestTime; - } - - public boolean isDeletedEntity(String entityGuid) { - return deletedEntityIds.contains(entityGuid); - } - - public static Metrics getMetrics() { - return get().metrics; - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/RequestContextV1.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/RequestContextV1.java b/server-api/src/main/java/org/apache/atlas/RequestContextV1.java index 08aa960..27fe3d2 100644 --- a/server-api/src/main/java/org/apache/atlas/RequestContextV1.java +++ b/server-api/src/main/java/org/apache/atlas/RequestContextV1.java @@ -19,14 +19,12 @@ package org.apache.atlas; import org.apache.atlas.metrics.Metrics; +import org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo; import org.apache.atlas.model.instance.AtlasObjectId; -import org.apache.atlas.typesystem.types.TypeSystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.Set; +import java.util.*; public class RequestContextV1 { private static final Logger LOG = LoggerFactory.getLogger(RequestContextV1.class); @@ -36,11 +34,11 @@ public class RequestContextV1 { private Set<AtlasObjectId> createdEntityIds = new LinkedHashSet<>(); private Set<AtlasObjectId> updatedEntityIds = new LinkedHashSet<>(); private Set<AtlasObjectId> deletedEntityIds = new LinkedHashSet<>(); + private Map<String, AtlasEntityWithExtInfo> entityCacheV2 = new HashMap<>(); private String user; private final long requestTime; - TypeSystem typeSystem = TypeSystem.getInstance(); private Metrics metrics = new Metrics(); private RequestContextV1() { @@ -59,7 +57,16 @@ public class RequestContextV1 { return ret; } + public static void clear() { + RequestContextV1 instance = CURRENT_CONTEXT.get(); + + if (instance != null) { + if (instance.entityCacheV2 != null) { + instance.entityCacheV2.clear(); + } + } + CURRENT_CONTEXT.remove(); } @@ -91,6 +98,16 @@ public class RequestContextV1 { deletedEntityIds.add(entityId); } + /** + * Adds the specified instance to the cache + * + */ + public void cache(AtlasEntityWithExtInfo entity) { + if (entity != null && entity.getEntity() != null && entity.getEntity().getGuid() != null) { + entityCacheV2.put(entity.getEntity().getGuid(), entity); + } + } + public Collection<AtlasObjectId> getCreatedEntityIds() { return createdEntityIds; } @@ -103,6 +120,17 @@ public class RequestContextV1 { return deletedEntityIds; } + /** + * Checks if an instance with the given guid is in the cache for this request. Either returns the instance + * or null if it is not in the cache. + * + * @param guid the guid to find + * @return Either the instance or null if it is not in the cache. + */ + public AtlasEntityWithExtInfo getInstanceV2(String guid) { + return entityCacheV2.get(guid); + } + public long getRequestTime() { return requestTime; } http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/discovery/LineageService.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/discovery/LineageService.java b/server-api/src/main/java/org/apache/atlas/discovery/LineageService.java deleted file mode 100644 index 5aab355..0000000 --- a/server-api/src/main/java/org/apache/atlas/discovery/LineageService.java +++ /dev/null @@ -1,75 +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.discovery; - -import org.apache.atlas.AtlasException; - -/** - * Lineage service interface. - */ -public interface LineageService { - - /** - * Return the lineage outputs graph for the given datasetName. - * - * @param datasetName datasetName - * @return Outputs Graph as JSON - */ - String getOutputsGraph(String datasetName) throws AtlasException; - - /** - * Return the lineage inputs graph for the given datasetName. - * - * @param datasetName datasetName - * @return Inputs Graph as JSON - */ - String getInputsGraph(String datasetName) throws AtlasException; - - /** - * Return the lineage inputs graph for the given entity id. - * - * @param guid entity id - * @return Inputs Graph as JSON - */ - String getInputsGraphForEntity(String guid) throws AtlasException; - - /** - * Return the lineage inputs graph for the given entity id. - * - * @param guid entity id - * @return Inputs Graph as JSON - */ - String getOutputsGraphForEntity(String guid) throws AtlasException; - - /** - * Return the schema for the given datasetName. - * - * @param datasetName datasetName - * @return Schema as JSON - */ - String getSchema(String datasetName) throws AtlasException; - - /** - * Return the schema for the given entity id. - * - * @param guid tableName - * @return Schema as JSON - */ - String getSchemaForEntity(String guid) throws AtlasException; -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/exception/EntityNotFoundException.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/exception/EntityNotFoundException.java b/server-api/src/main/java/org/apache/atlas/exception/EntityNotFoundException.java new file mode 100644 index 0000000..14be3ed --- /dev/null +++ b/server-api/src/main/java/org/apache/atlas/exception/EntityNotFoundException.java @@ -0,0 +1,44 @@ +/** + * 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.exception; + +/** + * A simple wrapper for 404. + */ +public class EntityNotFoundException extends NotFoundException { + public EntityNotFoundException() { + } + + public EntityNotFoundException(String message) { + super(message); + } + + public EntityNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public EntityNotFoundException(Throwable cause) { + super(cause); + } + + public EntityNotFoundException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/exception/NotFoundException.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/exception/NotFoundException.java b/server-api/src/main/java/org/apache/atlas/exception/NotFoundException.java new file mode 100644 index 0000000..c24789d --- /dev/null +++ b/server-api/src/main/java/org/apache/atlas/exception/NotFoundException.java @@ -0,0 +1,46 @@ +/** + * 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.exception; + +import org.apache.atlas.AtlasException; + +/** + * A simple wrapper for 404. + */ +public class NotFoundException extends AtlasException { + public NotFoundException() { + } + + public NotFoundException(String message) { + super(message); + } + + public NotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public NotFoundException(Throwable cause) { + super(cause); + } + + public NotFoundException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/exception/SchemaNotFoundException.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/exception/SchemaNotFoundException.java b/server-api/src/main/java/org/apache/atlas/exception/SchemaNotFoundException.java new file mode 100644 index 0000000..981ef2a --- /dev/null +++ b/server-api/src/main/java/org/apache/atlas/exception/SchemaNotFoundException.java @@ -0,0 +1,40 @@ +/** + * 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.exception; + +public class SchemaNotFoundException extends NotFoundException { + public SchemaNotFoundException() { + } + + public SchemaNotFoundException(String message) { + super(message); + } + + public SchemaNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public SchemaNotFoundException(Throwable cause) { + super(cause); + } + + public SchemaNotFoundException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/exception/TraitNotFoundException.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/exception/TraitNotFoundException.java b/server-api/src/main/java/org/apache/atlas/exception/TraitNotFoundException.java new file mode 100644 index 0000000..ba46a2e --- /dev/null +++ b/server-api/src/main/java/org/apache/atlas/exception/TraitNotFoundException.java @@ -0,0 +1,45 @@ +/** + * 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.exception; + +/** + * A simple wrapper for 404. + * Thrown when a requested trait can not be found. + */ +public class TraitNotFoundException extends NotFoundException { + public TraitNotFoundException() { + } + + public TraitNotFoundException(String message) { + super(message); + } + + public TraitNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public TraitNotFoundException(Throwable cause) { + super(cause); + } + + public TraitNotFoundException(String message, Throwable cause, boolean enableSuppression, + boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/listener/EntityChangeListener.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/listener/EntityChangeListener.java b/server-api/src/main/java/org/apache/atlas/listener/EntityChangeListener.java index e05a775..19fae4f 100644 --- a/server-api/src/main/java/org/apache/atlas/listener/EntityChangeListener.java +++ b/server-api/src/main/java/org/apache/atlas/listener/EntityChangeListener.java @@ -19,8 +19,8 @@ package org.apache.atlas.listener; import org.apache.atlas.AtlasException; -import org.apache.atlas.typesystem.IStruct; -import org.apache.atlas.typesystem.ITypedReferenceableInstance; +import org.apache.atlas.v1.model.instance.Referenceable; +import org.apache.atlas.v1.model.instance.Struct; import java.util.Collection; @@ -36,7 +36,7 @@ public interface EntityChangeListener { * @param isImport * @throws AtlasException if the listener notification fails */ - void onEntitiesAdded(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException; + void onEntitiesAdded(Collection<Referenceable> entities, boolean isImport) throws AtlasException; /** * This is upon updating an entity. @@ -46,7 +46,7 @@ public interface EntityChangeListener { * @param isImport * @throws AtlasException if the listener notification fails */ - void onEntitiesUpdated(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException; + void onEntitiesUpdated(Collection<Referenceable> entities, boolean isImport) throws AtlasException; /** * This is upon adding a new trait to a typed instance. @@ -56,7 +56,7 @@ public interface EntityChangeListener { * * @throws AtlasException if the listener notification fails */ - void onTraitsAdded(ITypedReferenceableInstance entity, Collection<? extends IStruct> traits) throws AtlasException; + void onTraitsAdded(Referenceable entity, Collection<? extends Struct> traits) throws AtlasException; /** * This is upon deleting a trait from a typed instance. @@ -66,7 +66,7 @@ public interface EntityChangeListener { * * @throws AtlasException if the listener notification fails */ - void onTraitsDeleted(ITypedReferenceableInstance entity, Collection<String> traitNames) throws AtlasException; + void onTraitsDeleted(Referenceable entity, Collection<String> traitNames) throws AtlasException; /** * This is upon updating a trait from a typed instance. @@ -76,7 +76,7 @@ public interface EntityChangeListener { * * @throws AtlasException if the listener notification fails */ - void onTraitsUpdated(ITypedReferenceableInstance entity, Collection<? extends IStruct> traits) throws AtlasException; + void onTraitsUpdated(Referenceable entity, Collection<? extends Struct> traits) throws AtlasException; /** * This is upon deleting entities from the repository. @@ -85,5 +85,5 @@ public interface EntityChangeListener { * @param isImport * @throws AtlasException */ - void onEntitiesDeleted(Collection<ITypedReferenceableInstance> entities, boolean isImport) throws AtlasException; + void onEntitiesDeleted(Collection<Referenceable> entities, boolean isImport) throws AtlasException; } http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/listener/TypesChangeListener.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/listener/TypesChangeListener.java b/server-api/src/main/java/org/apache/atlas/listener/TypesChangeListener.java index 5ff6d4a..0fcec50 100644 --- a/server-api/src/main/java/org/apache/atlas/listener/TypesChangeListener.java +++ b/server-api/src/main/java/org/apache/atlas/listener/TypesChangeListener.java @@ -19,7 +19,7 @@ package org.apache.atlas.listener; import org.apache.atlas.AtlasException; -import org.apache.atlas.typesystem.types.IDataType; +import org.apache.atlas.type.AtlasType; import java.util.Collection; @@ -31,19 +31,19 @@ public interface TypesChangeListener { /** * This is upon adding new type(s) to Store. * - * @param dataTypes data type + * @param dataTypes the data types * @throws AtlasException */ - void onAdd(Collection<? extends IDataType> dataTypes) throws AtlasException; + void onAdd(Collection<? extends AtlasType> dataTypes) throws AtlasException; /** * This is upon removing an existing type from the Store. * - * @param typeName type name + * @param dataTypes the data types * @throws AtlasException */ // void onRemove(String typeName) throws MetadataException; //This is upon updating an existing type to the store - void onChange(Collection<? extends IDataType> dataTypes) throws AtlasException; + void onChange(Collection<? extends AtlasType> dataTypes) throws AtlasException; } http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/services/MetadataService.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/services/MetadataService.java b/server-api/src/main/java/org/apache/atlas/services/MetadataService.java deleted file mode 100644 index d2aa457..0000000 --- a/server-api/src/main/java/org/apache/atlas/services/MetadataService.java +++ /dev/null @@ -1,317 +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.services; - -import org.apache.atlas.AtlasException; -import org.apache.atlas.CreateUpdateEntitiesResult; -import org.apache.atlas.EntityAuditEvent; -import org.apache.atlas.listener.EntityChangeListener; -import org.apache.atlas.model.legacy.EntityResult; -import org.apache.atlas.typesystem.IReferenceableInstance; -import org.apache.atlas.typesystem.IStruct; -import org.apache.atlas.typesystem.ITypedReferenceableInstance; -import org.apache.atlas.typesystem.ITypedStruct; -import org.apache.atlas.typesystem.Referenceable; -import org.apache.atlas.typesystem.Struct; -import org.apache.atlas.typesystem.types.cache.TypeCache; -import org.codehaus.jettison.json.JSONObject; - -import java.util.List; -import java.util.Map; - -/** - * Metadata service. - */ -@Deprecated -public interface MetadataService { - - /** - * Creates a new type based on the type system to enable adding - * entities (instances for types). - * - * @param typeDefinition definition as json - * @return a unique id for this type - */ - JSONObject createType(String typeDefinition) throws AtlasException; - - /**z - * Updates the given types in the type definition - * @param typeDefinition - * @return - * @throws AtlasException - */ - JSONObject updateType(String typeDefinition) throws AtlasException; - - /** - * Return the definition for the given type. - * - * @param typeName name for this type, must be unique - * @return type definition as JSON - */ - String getTypeDefinition(String typeName) throws AtlasException; - - /** - * Return the list of type names in the type system which match the specified filter. - * - * @return list of type names - * @param filterMap - Map of filter for type names. Valid keys are CATEGORY, SUPERTYPE, NOT_SUPERTYPE - * For example, CATEGORY = TRAIT && SUPERTYPE contains 'X' && SUPERTYPE !contains 'Y' - * If there is no filter, all the types are returned - */ - List<String> getTypeNames(Map<TypeCache.TYPE_FILTER, String> filterMap) throws AtlasException; - - /** - * Creates an entity, instance of the type. - * - * @param entityDefinition definition - * @return CreateUpdateEntitiesResult with the guids of the entities created - */ - CreateUpdateEntitiesResult createEntities(String entityDefinition) throws AtlasException; - - /** - * Get a typed entity instance. - * - * @param entity entity - * @return typed entity instance - * - * @throws AtlasException if any failure occurs - */ - ITypedReferenceableInstance getTypedReferenceableInstance(Referenceable entity) throws AtlasException; - - /** - * Create entity instances. - * - * @param typedInstances instance to create - * @return CreateUpdateEntitiesResult with the guids of the entities created - * - * @throws AtlasException if unable to create the entities - */ - CreateUpdateEntitiesResult createEntities(ITypedReferenceableInstance[] typedInstances) throws AtlasException; - - - /** - * Return the definition for the given guid. - * - * @param guid guid - * @return entity definition as JSON - */ - String getEntityDefinitionJson(String guid) throws AtlasException; - - ITypedReferenceableInstance getEntityDefinition(String guid) throws AtlasException; - - - /** - * Return the definition given type and attribute. The attribute has to be unique attribute for the type - * @param entityType - type name - * @param attribute - attribute name - * @param value - attribute value - * @return - * @throws AtlasException - */ - ITypedReferenceableInstance getEntityDefinitionReference(String entityType, String attribute, String value) throws AtlasException; - - /** - * Return the definition given type and attribute. The attribute has to be unique attribute for the type - * @param entityType - type name - * @param attribute - attribute name - * @param value - attribute value - * @return - * @throws AtlasException - */ - String getEntityDefinition(String entityType, String attribute, String value) throws AtlasException; - - /** - * Return the list of entity names for the given type in the repository. - * - * @param entityType type - * @return list of entity names for the given type in the repository - */ - List<String> getEntityList(String entityType) throws AtlasException; - - /** - * Adds the property to the given entity id(guid). - * Currently supports updates only on PRIMITIVE, CLASS attribute types - * @param guid entity id - * @param attribute property name - * @param value property value - * @return {@link CreateUpdateEntitiesResult} with the guids of the entities that were created/updated - */ - CreateUpdateEntitiesResult updateEntityAttributeByGuid(String guid, String attribute, String value) throws AtlasException; - - /** - * Supports Partial updates of an entity. Users can update a subset of attributes for an entity identified by its guid - * Note however that it cannot be used to set attribute values to null or delete attrbute values - * @param guid entity id - * @param entity - * @return {@link CreateUpdateEntitiesResult} with the guids of the entities that were created/updated - * @throws AtlasException - */ - CreateUpdateEntitiesResult updateEntityPartialByGuid(String guid, Referenceable entity) throws AtlasException; - - /** - * Batch API - Adds/Updates the given entity id(guid). - * - * @param entityJson entity json - * @return {@link CreateUpdateEntitiesResult} with the guids of the entities that were created/updated - */ - CreateUpdateEntitiesResult updateEntities(String entityJson) throws AtlasException; - - - /** - * Batch API - Adds/Updates the given entity id(guid). - * - * @param entityJson entity json - * @return {@link CreateUpdateEntitiesResult} with the guids of the entities that were created/updated - */ - CreateUpdateEntitiesResult updateEntities(ITypedReferenceableInstance[] iTypedReferenceableInstances) throws AtlasException; - - // Trait management functions - - /** - * Updates entity identified by a qualified name - * - * @param typeName - * @param uniqueAttributeName - * @param attrValue - * @param updatedEntity - * @return Guid of updated entity - * @throws AtlasException - */ - CreateUpdateEntitiesResult updateEntityByUniqueAttribute(String typeName, String uniqueAttributeName, - String attrValue, - Referenceable updatedEntity) throws AtlasException; - - /** - * Gets the list of trait names for a given entity represented by a guid. - * - * @param guid globally unique identifier for the entity - * @return a list of trait names for the given entity guid - * @throws AtlasException - */ - List<String> getTraitNames(String guid) throws AtlasException; - - /** - * Adds a new trait to an existing entity represented by a guid. - * - * @param guid globally unique identifier for the entity - * @param traitInstanceDefinition trait instance that needs to be added to entity - * @throws AtlasException - */ - void addTrait(String guid, String traitInstanceDefinition) throws AtlasException; - - /** - * Adds a new trait to an existing entity represented by a guid. - * - * @param guid globally unique identifier for the entity - * @param traitInstance trait instance to add * - * @throws AtlasException if unable to add the trait instance - */ - void addTrait(String guid, ITypedStruct traitInstance) throws AtlasException; - - - /** - * Adds a new trait to a list of existing entities represented by their respective guids - * @param entityGuids list of guids of entities - * @param traitInstance trait instance json that needs to be added to entities - * @throws AtlasException - */ - void addTrait(List<String> entityGuids, ITypedStruct traitInstance) throws AtlasException; - - /** - * Create a typed trait instance. - * - * @param traitInstance trait instance - * @return a typed trait instance - * @throws AtlasException if unable to create the typed trait instance - */ - ITypedStruct createTraitInstance(Struct traitInstance) throws AtlasException; - - /** - * Return trait definition of a single trait for a given entity - * @param guid - Guid of the entity to which the trait is tagged - * @param traitName - Name of the trait - * @return - * @throws AtlasException - */ - IStruct getTraitDefinition(String guid, String traitName) throws AtlasException; - - /** - * Deletes a given trait from an existing entity represented by a guid. - * - * @param guid globally unique identifier for the entity - * @param traitNameToBeDeleted name of the trait - * @throws AtlasException - */ - void deleteTrait(String guid, String traitNameToBeDeleted) throws AtlasException; - - /** - * Delete the specified entities from the repository - * - * @param guids entity guids to be deleted - * @return List of guids for deleted entities - * @throws AtlasException - */ - EntityResult deleteEntities(List<String> guids) throws AtlasException; - - /** - * Register a listener for entity change. - * - * @param listener the listener to register - */ - void registerListener(EntityChangeListener listener); - - /** - * Unregister an entity change listener. - * - * @param listener the listener to unregister - */ - void unregisterListener(EntityChangeListener listener); - - /** - * Delete the specified entity from the repository identified by its unique attribute (including its composite references) - * - * @param typeName The entity's type - * @param uniqueAttributeName attribute name by which the entity could be identified uniquely - * @param attrValue attribute value by which the entity could be identified uniquely - * @return List of guids for deleted entities (including their composite references) - * @throws AtlasException - */ - EntityResult deleteEntityByUniqueAttribute(String typeName, String uniqueAttributeName, - String attrValue) throws AtlasException; - - /** - * Returns entity audit events for entity id in the decreasing order of timestamp - * @param guid entity id - * @param startKey key for the first event, used for pagination - * @param count number of events to be returned - * @return - */ - List<EntityAuditEvent> getAuditEvents(String guid, String startKey, short count) throws AtlasException; - - /** - * Deserializes entity instances into ITypedReferenceableInstance array. - * @param entityInstanceDefinition - * @return ITypedReferenceableInstance[] - * @throws AtlasException - */ - ITypedReferenceableInstance[] deserializeClassInstances(String entityInstanceDefinition) throws AtlasException; - - ITypedReferenceableInstance validateAndConvertToTypedInstance(IReferenceableInstance updatedEntity, String typeName) - throws AtlasException; -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/typesystem/exception/EntityExistsException.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/typesystem/exception/EntityExistsException.java b/server-api/src/main/java/org/apache/atlas/typesystem/exception/EntityExistsException.java deleted file mode 100644 index b16cfa9..0000000 --- a/server-api/src/main/java/org/apache/atlas/typesystem/exception/EntityExistsException.java +++ /dev/null @@ -1,32 +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 - * <p/> - * http://www.apache.org/licenses/LICENSE-2.0 - * <p/> - * 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.exception; - -import org.apache.atlas.AtlasException; -import org.apache.atlas.typesystem.IReferenceableInstance; - -public class EntityExistsException extends AtlasException { - public EntityExistsException(IReferenceableInstance typedInstance, Exception e) { - super("Model violation for type "+ typedInstance.getTypeName(), e); - } - - public EntityExistsException(IReferenceableInstance typedInstance) { - super("Model violation for type "+ typedInstance.getTypeName()); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/typesystem/exception/EntityNotFoundException.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/typesystem/exception/EntityNotFoundException.java b/server-api/src/main/java/org/apache/atlas/typesystem/exception/EntityNotFoundException.java deleted file mode 100644 index 7579b80..0000000 --- a/server-api/src/main/java/org/apache/atlas/typesystem/exception/EntityNotFoundException.java +++ /dev/null @@ -1,44 +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.exception; - -/** - * A simple wrapper for 404. - */ -public class EntityNotFoundException extends NotFoundException { - public EntityNotFoundException() { - } - - public EntityNotFoundException(String message) { - super(message); - } - - public EntityNotFoundException(String message, Throwable cause) { - super(message, cause); - } - - public EntityNotFoundException(Throwable cause) { - super(cause); - } - - public EntityNotFoundException(String message, Throwable cause, boolean enableSuppression, - boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/typesystem/exception/NotFoundException.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/typesystem/exception/NotFoundException.java b/server-api/src/main/java/org/apache/atlas/typesystem/exception/NotFoundException.java deleted file mode 100644 index b45b970..0000000 --- a/server-api/src/main/java/org/apache/atlas/typesystem/exception/NotFoundException.java +++ /dev/null @@ -1,46 +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.exception; - -import org.apache.atlas.AtlasException; - -/** - * A simple wrapper for 404. - */ -public class NotFoundException extends AtlasException { - public NotFoundException() { - } - - public NotFoundException(String message) { - super(message); - } - - public NotFoundException(String message, Throwable cause) { - super(message, cause); - } - - public NotFoundException(Throwable cause) { - super(cause); - } - - public NotFoundException(String message, Throwable cause, boolean enableSuppression, - boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/typesystem/exception/NullRequiredAttributeException.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/typesystem/exception/NullRequiredAttributeException.java b/server-api/src/main/java/org/apache/atlas/typesystem/exception/NullRequiredAttributeException.java deleted file mode 100644 index db4b054..0000000 --- a/server-api/src/main/java/org/apache/atlas/typesystem/exception/NullRequiredAttributeException.java +++ /dev/null @@ -1,59 +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.exception; - -import org.apache.atlas.AtlasException; -import org.apache.atlas.typesystem.types.Multiplicity; - - -/** - * Thrown when a repository operation attempts to - * unset an attribute that is defined as required in the - * type system. A required attribute has a non-zero - * lower bound in its multiplicity. - * - * @see Multiplicity#REQUIRED - * @see Multiplicity#COLLECTION - * @see Multiplicity#SET - * - */ -public class NullRequiredAttributeException extends AtlasException { - - private static final long serialVersionUID = 4023597038462910948L; - - public NullRequiredAttributeException() { - super(); - } - - public NullRequiredAttributeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } - - public NullRequiredAttributeException(String message, Throwable cause) { - super(message, cause); - } - - public NullRequiredAttributeException(String message) { - super(message); - } - - public NullRequiredAttributeException(Throwable cause) { - super(cause); - } - -} http://git-wip-us.apache.org/repos/asf/atlas/blob/435fe3fb/server-api/src/main/java/org/apache/atlas/typesystem/exception/SchemaNotFoundException.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/typesystem/exception/SchemaNotFoundException.java b/server-api/src/main/java/org/apache/atlas/typesystem/exception/SchemaNotFoundException.java deleted file mode 100644 index 55b4088..0000000 --- a/server-api/src/main/java/org/apache/atlas/typesystem/exception/SchemaNotFoundException.java +++ /dev/null @@ -1,40 +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.exception; - -public class SchemaNotFoundException extends NotFoundException { - public SchemaNotFoundException() { - } - - public SchemaNotFoundException(String message) { - super(message); - } - - public SchemaNotFoundException(String message, Throwable cause) { - super(message, cause); - } - - public SchemaNotFoundException(Throwable cause) { - super(cause); - } - - public SchemaNotFoundException(String message, Throwable cause, boolean enableSuppression, - boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -}