Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
53574720
Commit
53574720
authored
Apr 25, 2016
by
Shwetha GS
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-543 Entity Instance requests should not require ID element for new…
ATLAS-543 Entity Instance requests should not require ID element for new Entities (harishjp via shwethags)
parent
2e90ff1f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
8 deletions
+111
-8
release-log.txt
release-log.txt
+1
-0
InstanceSerialization.scala
.../apache/atlas/typesystem/json/InstanceSerialization.scala
+12
-8
InstanceSerializationTest.scala
...che/atlas/typesystem/json/InstanceSerializationTest.scala
+98
-0
No files found.
release-log.txt
View file @
53574720
...
...
@@ -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)
...
...
typesystem/src/main/scala/org/apache/atlas/typesystem/json/InstanceSerialization.scala
View file @
53574720
...
...
@@ -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
]])
...
...
typesystem/src/test/scala/org/apache/atlas/typesystem/json/InstanceSerializationTest.scala
0 → 100644
View file @
53574720
/*
* 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"
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment