You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by sh...@apache.org on 2016/04/25 06:15:14 UTC
incubator-atlas git commit: ATLAS-543 Entity Instance requests should
not require ID element for new Entities (harishjp via shwethags)
Repository: incubator-atlas
Updated Branches:
refs/heads/master 2e90ff1f6 -> 53574720c
ATLAS-543 Entity Instance requests should not require ID element for new Entities (harishjp via shwethags)
Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/53574720
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/53574720
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/53574720
Branch: refs/heads/master
Commit: 53574720c79cc99dddf5d3dbbe5cae61748eeee4
Parents: 2e90ff1
Author: Shwetha GS <ss...@hortonworks.com>
Authored: Mon Apr 25 09:44:59 2016 +0530
Committer: Shwetha GS <ss...@hortonworks.com>
Committed: Mon Apr 25 09:44:59 2016 +0530
----------------------------------------------------------------------
release-log.txt | 1 +
.../typesystem/json/InstanceSerialization.scala | 20 ++--
.../json/InstanceSerializationTest.scala | 98 ++++++++++++++++++++
3 files changed, 111 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/53574720/release-log.txt
----------------------------------------------------------------------
diff --git a/release-log.txt b/release-log.txt
index 86605b1..10cf434 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -17,6 +17,7 @@ ATLAS-409 Atlas will not import avro tables with schema read from a file (dosset
ATLAS-379 Create sqoop and falcon metadata addons (venkatnrangan,bvellanki,sowmyaramesh via shwethags)
ALL CHANGES:
+ATLAS-543 Entity Instance requests should not require ID element for new Entities (harishjp via shwethags)
ATLAS-681 update committer/ppmc members in the pom.xml (sneethiraj via shwethags)
ATLAS-616 Resolve OOM - Zookeeper throws exceptions when trying to fire DSL queries at Atlas at large scale. (yhemanth via sumasai)
ATLAS-530 Add table information to column class (sumasai)
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/53574720/typesystem/src/main/scala/org/apache/atlas/typesystem/json/InstanceSerialization.scala
----------------------------------------------------------------------
diff --git a/typesystem/src/main/scala/org/apache/atlas/typesystem/json/InstanceSerialization.scala b/typesystem/src/main/scala/org/apache/atlas/typesystem/json/InstanceSerialization.scala
index 836d9f8..a8389bd 100755
--- a/typesystem/src/main/scala/org/apache/atlas/typesystem/json/InstanceSerialization.scala
+++ b/typesystem/src/main/scala/org/apache/atlas/typesystem/json/InstanceSerialization.scala
@@ -31,9 +31,9 @@ import scala.collection.JavaConverters._
object InstanceSerialization {
- case class _Id(id : String, version : Int, typeName : String, state : String)
+ case class _Id(id : String, version : Int, typeName : String, state : Option[String])
case class _Struct(typeName : String, values : Map[String, AnyRef])
- case class _Reference(id : _Id,
+ case class _Reference(id : Option[_Id],
typeName : String,
values : Map[String, AnyRef],
traitNames : List[String],
@@ -106,7 +106,7 @@ object InstanceSerialization {
i <- id
s <- state
v <- version
- } yield _Id(i, v, typNm, s)
+ } yield _Id(i, v, typNm, Some(s))
}
/**
@@ -233,7 +233,7 @@ object InstanceSerialization {
values <- valuesMap
traitNms <- traitNames
ts <- traits
- } yield _Reference(i, typNm, values, traitNms.toList, ts)
+ } yield _Reference(Some(i), typNm, values, traitNms.toList, ts)
}
/**
@@ -258,10 +258,14 @@ object InstanceSerialization {
}
def asJava(v : Any)(implicit format: Formats) : Any = v match {
- case i : _Id => new Id(i.id, i.version, i.typeName, i.state)
+ case i : _Id => new Id(i.id, i.version, i.typeName, i.state.orNull)
case s : _Struct => new Struct(s.typeName, asJava(s.values).asInstanceOf[java.util.Map[String, Object]])
case r : _Reference => {
- new Referenceable(new Id(r.id.id, r.id.version, r.id.typeName, r.id.state),
+ val id = r.id match {
+ case Some(i) => new Id(i.id, i.version, i.typeName, i.state.orNull)
+ case None => new Id(r.typeName)
+ }
+ new Referenceable(id,
r.typeName,
asJava(r.values).asInstanceOf[java.util.Map[String, Object]],
asJava(r.traitNames).asInstanceOf[java.util.List[String]],
@@ -280,13 +284,13 @@ object InstanceSerialization {
}
def asScala(v : Any) : Any = v match {
- case i : Id => _Id(i._getId(), i.getVersion, i.getClassName, i.getStateAsString)
+ case i : Id => _Id(i._getId(), i.getVersion, i.getClassName, Some(i.getStateAsString))
case r : IReferenceableInstance => {
val traits = r.getTraits.map { tName =>
val t = r.getTrait(tName).asInstanceOf[IStruct]
(tName -> _Struct(t.getTypeName, asScala(t.getValuesMap).asInstanceOf[Map[String, AnyRef]]))
}.toMap
- _Reference(asScala(r.getId).asInstanceOf[_Id],
+ _Reference(Some(asScala(r.getId).asInstanceOf[_Id]),
r.getTypeName, asScala(r.getValuesMap).asInstanceOf[Map[String, AnyRef]],
asScala(r.getTraits).asInstanceOf[List[String]],
traits.asInstanceOf[Map[String, _Struct]])
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/53574720/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
new file mode 100644
index 0000000..98a9739
--- /dev/null
+++ b/typesystem/src/test/scala/org/apache/atlas/typesystem/json/InstanceSerializationTest.scala
@@ -0,0 +1,98 @@
+/*
+ * 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.ImmutableSet
+import org.apache.atlas.typesystem.Referenceable
+import org.apache.atlas.typesystem.types.{DataTypes, TypeSystem}
+import org.apache.atlas.typesystem.types.utils.TypesUtil
+import org.testng.Assert._
+import org.testng.annotations.{BeforeClass, Test}
+
+import scala.util.Random
+
+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 testMissingStateInId: Unit = {
+ val entity: Referenceable = new Referenceable(typeName)
+ val json: String = InstanceSerialization.toJson(entity, true)
+ val staticJson: String = "{\n" +
+ " \"jsonClass\":\"org.apache.atlas.typesystem.json.InstanceSerialization$_Reference\",\n" +
+ " \"id\":{\n" +
+ " \"jsonClass\":\"org.apache.atlas.typesystem.json.InstanceSerialization$_Id\",\n" +
+ " \"id\":\"" + entity.getId.id + "\",\n" +
+ " \"version\":0,\n" +
+ " \"typeName\":\"" + entity.getTypeName + "\",\n" +
+ " },\n" +
+ " \"typeName\":\"" + entity.getTypeName + "\",\n" +
+ " \"values\":{}\n" +
+ " \"traitNames\":[]\n" +
+ " \"traits\":{}\n" +
+ "}"
+ 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 json: String = InstanceSerialization.toJson(entity, true)
+ val staticJson: String = "{\n" +
+ " \"jsonClass\":\"org.apache.atlas.typesystem.json.InstanceSerialization$_Reference\",\n" +
+ " \"typeName\":\"" + entity.getTypeName + "\",\n" +
+ " \"values\":{}\n" +
+ " \"traitNames\":[],\n" +
+ " \"traits\":{}\n" +
+ "}"
+ 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")
+ }
+}