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
4de5cfd0
Commit
4de5cfd0
authored
May 29, 2015
by
Venkatesh Seetharam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
BUG-37893 Add a trait with an attribute and its value shows up as null in the get entity call
parent
7843e2ae
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
19 deletions
+103
-19
GraphBackedMetadataRepository.java
...adata/repository/graph/GraphBackedMetadataRepository.java
+13
-9
GraphBackedMetadataRepositoryTest.java
...a/repository/graph/GraphBackedMetadataRepositoryTest.java
+39
-7
EntityJerseyResourceIT.java
...hadoop/metadata/web/resources/EntityJerseyResourceIT.java
+51
-3
No files found.
repository/src/main/java/org/apache/hadoop/metadata/repository/graph/GraphBackedMetadataRepository.java
View file @
4de5cfd0
...
...
@@ -41,7 +41,6 @@ import org.apache.hadoop.metadata.typesystem.persistence.MapIds;
import
org.apache.hadoop.metadata.typesystem.types.AttributeInfo
;
import
org.apache.hadoop.metadata.typesystem.types.ClassType
;
import
org.apache.hadoop.metadata.typesystem.types.DataTypes
;
import
org.apache.hadoop.metadata.typesystem.types.EnumType
;
import
org.apache.hadoop.metadata.typesystem.types.EnumValue
;
import
org.apache.hadoop.metadata.typesystem.types.HierarchicalType
;
import
org.apache.hadoop.metadata.typesystem.types.IDataType
;
...
...
@@ -57,7 +56,13 @@ import javax.inject.Inject;
import
javax.inject.Singleton
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.atomic.AtomicInteger
;
/**
...
...
@@ -142,8 +147,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
public
String
createEntity
(
IReferenceableInstance
typedInstance
)
throws
RepositoryException
{
LOG
.
info
(
"adding entity={}"
,
typedInstance
);
try
{
final
String
guid
=
instanceToGraphMapper
.
mapTypedInstanceToGraph
(
typedInstance
);
return
guid
;
return
instanceToGraphMapper
.
mapTypedInstanceToGraph
(
typedInstance
);
}
catch
(
MetadataException
e
)
{
throw
new
RepositoryException
(
e
);
}
...
...
@@ -240,7 +244,8 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
// add the trait instance as a new vertex
final
String
typeName
=
getTypeName
(
instanceVertex
);
instanceToGraphMapper
.
mapTraitInstanceToVertex
(
traitInstance
,
getIdFromVertex
(
typeName
,
instanceVertex
),
instanceToGraphMapper
.
mapTraitInstanceToVertex
(
traitInstance
,
getIdFromVertex
(
typeName
,
instanceVertex
),
typeName
,
instanceVertex
,
Collections
.<
Id
,
Vertex
>
emptyMap
());
// update the traits in entity once adding trait instance is successful
...
...
@@ -732,7 +737,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
String
propertyName
=
getQualifiedName
(
typedInstance
,
attributeInfo
);
IDataType
elementType
=
((
DataTypes
.
ArrayType
)
attributeInfo
.
dataType
()).
getElemType
();
List
<
String
>
values
=
new
ArrayList
(
list
.
size
());
List
<
String
>
values
=
new
ArrayList
<>
(
list
.
size
());
for
(
int
index
=
0
;
index
<
list
.
size
();
index
++)
{
String
entryId
=
mapCollectionEntryToVertex
(
id
,
instanceVertex
,
attributeInfo
,
idToVertexMap
,
elementType
,
list
.
get
(
index
),
propertyName
);
...
...
@@ -1108,7 +1113,6 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
return
;
}
DataTypes
.
MapType
mapType
=
(
DataTypes
.
MapType
)
attributeInfo
.
dataType
();
final
IDataType
keyType
=
mapType
.
getKeyType
();
final
IDataType
valueType
=
mapType
.
getValueType
();
HashMap
values
=
new
HashMap
();
...
...
@@ -1219,10 +1223,10 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
traitName
,
traitType
,
traitInstance
);
}
public
void
mapVertexToTraitInstance
(
Vertex
instanceVertex
,
String
typeName
,
public
void
mapVertexToTraitInstance
(
Vertex
instanceVertex
,
String
type
dInstanceType
Name
,
String
traitName
,
TraitType
traitType
,
ITypedStruct
traitInstance
)
throws
MetadataException
{
String
relationshipLabel
=
typeName
+
"."
+
traitName
;
String
relationshipLabel
=
getEdgeLabel
(
typedInstanceTypeName
,
traitName
)
;
LOG
.
debug
(
"Finding edge for {} -> label {} "
,
instanceVertex
,
relationshipLabel
);
for
(
Edge
edge
:
instanceVertex
.
getEdges
(
Direction
.
OUT
,
relationshipLabel
))
{
final
Vertex
traitInstanceVertex
=
edge
.
getVertex
(
Direction
.
IN
);
...
...
repository/src/test/java/org/apache/hadoop/metadata/repository/graph/GraphBackedMetadataRepositoryTest.java
View file @
4de5cfd0
...
...
@@ -30,6 +30,7 @@ import org.apache.hadoop.metadata.discovery.graph.GraphBackedDiscoveryService;
import
org.apache.hadoop.metadata.repository.BaseTest
;
import
org.apache.hadoop.metadata.repository.Constants
;
import
org.apache.hadoop.metadata.repository.RepositoryException
;
import
org.apache.hadoop.metadata.typesystem.IStruct
;
import
org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance
;
import
org.apache.hadoop.metadata.typesystem.ITypedStruct
;
import
org.apache.hadoop.metadata.typesystem.Referenceable
;
...
...
@@ -55,10 +56,12 @@ import org.testng.annotations.Test;
import
scala.actors.threadpool.Arrays
;
import
javax.inject.Inject
;
import
java.util.*
;
import
static
org
.
apache
.
hadoop
.
metadata
.
typesystem
.
types
.
utils
.
TypesUtil
.
createRequiredAttrDef
;
import
static
org
.
apache
.
hadoop
.
metadata
.
typesystem
.
types
.
utils
.
TypesUtil
.
createStructTypeDef
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.UUID
;
/**
* GraphBackedMetadataRepository test
...
...
@@ -146,7 +149,8 @@ public class GraphBackedMetadataRepositoryTest {
@Test
(
dependsOnMethods
=
"testSubmitEntity"
)
public
void
testGetTraitLabel
()
throws
Exception
{
Assert
.
assertEquals
(
repositoryService
.
getTraitLabel
(
typeSystem
.
getDataType
(
ClassType
.
class
,
TABLE_TYPE
),
Assert
.
assertEquals
(
repositoryService
.
getTraitLabel
(
typeSystem
.
getDataType
(
ClassType
.
class
,
TABLE_TYPE
),
CLASSIFICATION
),
TABLE_TYPE
+
"."
+
CLASSIFICATION
);
}
...
...
@@ -253,6 +257,33 @@ public class GraphBackedMetadataRepositoryTest {
Assert
.
assertTrue
(
traitNames
.
contains
(
CLASSIFICATION
));
}
@Test
(
dependsOnMethods
=
"testAddTrait"
)
public
void
testAddTraitWithAttribute
()
throws
Exception
{
final
String
aGUID
=
getGUID
();
final
String
traitName
=
"P_I_I"
;
HierarchicalTypeDefinition
<
TraitType
>
piiTrait
=
TypesUtil
.
createTraitTypeDef
(
traitName
,
ImmutableList
.<
String
>
of
(),
TypesUtil
.
createRequiredAttrDef
(
"type"
,
DataTypes
.
STRING_TYPE
));
TraitType
traitType
=
typeSystem
.
defineTraitType
(
piiTrait
);
ITypedStruct
traitInstance
=
traitType
.
createInstance
();
traitInstance
.
set
(
"type"
,
"SSN"
);
repositoryService
.
addTrait
(
aGUID
,
traitInstance
);
TestUtils
.
dumpGraph
(
graphProvider
.
get
());
// refresh trait names
List
<
String
>
traitNames
=
repositoryService
.
getTraitNames
(
aGUID
);
Assert
.
assertEquals
(
traitNames
.
size
(),
3
);
Assert
.
assertTrue
(
traitNames
.
contains
(
traitName
));
ITypedReferenceableInstance
instance
=
repositoryService
.
getEntityDefinition
(
aGUID
);
IStruct
traitInstanceRef
=
instance
.
getTrait
(
traitName
);
String
type
=
(
String
)
traitInstanceRef
.
get
(
"type"
);
Assert
.
assertEquals
(
type
,
"SSN"
);
}
@Test
(
expectedExceptions
=
NullPointerException
.
class
)
public
void
testAddTraitWithNullInstance
()
throws
Exception
{
repositoryService
.
addTrait
(
getGUID
(),
null
);
...
...
@@ -273,15 +304,16 @@ public class GraphBackedMetadataRepositoryTest {
final
String
aGUID
=
getGUID
();
List
<
String
>
traitNames
=
repositoryService
.
getTraitNames
(
aGUID
);
Assert
.
assertEquals
(
traitNames
.
size
(),
2
);
Assert
.
assertEquals
(
traitNames
.
size
(),
3
);
Assert
.
assertTrue
(
traitNames
.
contains
(
PII
));
Assert
.
assertTrue
(
traitNames
.
contains
(
CLASSIFICATION
));
Assert
.
assertTrue
(
traitNames
.
contains
(
"P_I_I"
));
repositoryService
.
deleteTrait
(
aGUID
,
PII
);
// refresh trait names
traitNames
=
repositoryService
.
getTraitNames
(
aGUID
);
Assert
.
assertEquals
(
traitNames
.
size
(),
1
);
Assert
.
assertEquals
(
traitNames
.
size
(),
2
);
Assert
.
assertTrue
(
traitNames
.
contains
(
CLASSIFICATION
));
Assert
.
assertFalse
(
traitNames
.
contains
(
PII
));
}
...
...
webapp/src/test/java/org/apache/hadoop/metadata/web/resources/EntityJerseyResourceIT.java
View file @
4de5cfd0
...
...
@@ -24,6 +24,7 @@ import com.sun.jersey.api.client.WebResource;
import
org.apache.commons.lang.RandomStringUtils
;
import
org.apache.hadoop.metadata.MetadataServiceClient
;
import
org.apache.hadoop.metadata.MetadataServiceException
;
import
org.apache.hadoop.metadata.typesystem.IStruct
;
import
org.apache.hadoop.metadata.typesystem.Referenceable
;
import
org.apache.hadoop.metadata.typesystem.Struct
;
import
org.apache.hadoop.metadata.typesystem.TypesDef
;
...
...
@@ -60,7 +61,6 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
private
static
final
String
TABLE_TYPE
=
"hive_table_type"
;
private
static
final
String
TABLE_NAME
=
"bar"
;
private
static
final
String
TRAITS
=
"traits"
;
private
static
final
String
TRAIT
=
"trait"
;
private
Referenceable
tableInstance
;
private
Id
tableId
;
...
...
@@ -120,7 +120,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
tableId
=
createInstance
(
tableInstance
);
Assert
.
fail
(
"Was expecting an exception here "
);
}
catch
(
MetadataServiceException
e
)
{
Assert
.
assertTrue
(
e
.
getMessage
().
contains
(
"\"error\":\"Cannot convert value '2014-07-11' to datatype date\""
));
Assert
.
assertTrue
(
e
.
getMessage
()
.
contains
(
"\"error\":\"Cannot convert value '2014-07-11' to datatype date\""
));
}
}
...
...
@@ -359,7 +360,54 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertNotNull
(
response
.
get
(
MetadataServiceClient
.
REQUEST_ID
));
Assert
.
assertNotNull
(
response
.
get
(
MetadataServiceClient
.
GUID
));
Assert
.
assertNotNull
(
response
.
get
(
MetadataServiceClient
.
DEFINITION
));
}
@Test
(
dependsOnMethods
=
"testGetTraitNames"
)
public
void
testAddTraitWithAttribute
()
throws
Exception
{
final
String
traitName
=
"P_I_I"
;
HierarchicalTypeDefinition
<
TraitType
>
piiTrait
=
TypesUtil
.
createTraitTypeDef
(
traitName
,
ImmutableList
.<
String
>
of
(),
TypesUtil
.
createRequiredAttrDef
(
"type"
,
DataTypes
.
STRING_TYPE
));
String
traitDefinitionAsJSON
=
TypesSerialization
$
.
MODULE
$
.
toJson
(
piiTrait
,
true
);
LOG
.
debug
(
"traitDefinitionAsJSON = "
+
traitDefinitionAsJSON
);
createType
(
traitDefinitionAsJSON
);
Struct
traitInstance
=
new
Struct
(
traitName
);
traitInstance
.
set
(
"type"
,
"SSN"
);
String
traitInstanceAsJSON
=
InstanceSerialization
.
toJson
(
traitInstance
,
true
);
LOG
.
debug
(
"traitInstanceAsJSON = "
+
traitInstanceAsJSON
);
final
String
guid
=
tableId
.
_getId
();
ClientResponse
clientResponse
=
service
.
path
(
"api/metadata/entities"
)
.
path
(
guid
)
.
path
(
TRAITS
)
.
accept
(
MediaType
.
APPLICATION_JSON
)
.
type
(
MediaType
.
APPLICATION_JSON
)
.
method
(
HttpMethod
.
POST
,
ClientResponse
.
class
,
traitInstanceAsJSON
);
Assert
.
assertEquals
(
clientResponse
.
getStatus
(),
Response
.
Status
.
CREATED
.
getStatusCode
());
String
responseAsString
=
clientResponse
.
getEntity
(
String
.
class
);
Assert
.
assertNotNull
(
responseAsString
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertNotNull
(
response
.
get
(
MetadataServiceClient
.
REQUEST_ID
));
Assert
.
assertNotNull
(
response
.
get
(
MetadataServiceClient
.
GUID
));
// verify the response
clientResponse
=
getEntityDefinition
(
guid
);
Assert
.
assertEquals
(
clientResponse
.
getStatus
(),
Response
.
Status
.
OK
.
getStatusCode
());
responseAsString
=
clientResponse
.
getEntity
(
String
.
class
);
Assert
.
assertNotNull
(
responseAsString
);
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertNotNull
(
response
.
get
(
MetadataServiceClient
.
REQUEST_ID
));
final
String
definition
=
response
.
getString
(
MetadataServiceClient
.
DEFINITION
);
Assert
.
assertNotNull
(
definition
);
Referenceable
entityRef
=
InstanceSerialization
.
fromJsonReferenceable
(
definition
,
true
);
IStruct
traitRef
=
entityRef
.
getTrait
(
traitName
);
String
type
=
(
String
)
traitRef
.
get
(
"type"
);
Assert
.
assertEquals
(
type
,
"SSN"
);
}
@Test
...
...
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