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
386d8d38
Commit
386d8d38
authored
Jan 16, 2015
by
Venkatesh Seetharam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ISSUE-35 Add typed instance put/get end to end. Contributed by Venkatesh Seetharam
parent
8285e3b9
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
192 additions
and
80 deletions
+192
-80
DefaultMetadataService.java
...ache/hadoop/metadata/services/DefaultMetadataService.java
+9
-16
GraphBackedMetadataRepository.java
...doop/metadata/services/GraphBackedMetadataRepository.java
+0
-0
MetadataService.java
.../org/apache/hadoop/metadata/services/MetadataService.java
+0
-9
GraphUtils.java
...main/java/org/apache/hadoop/metadata/util/GraphUtils.java
+36
-0
EntityResource.java
.../apache/hadoop/metadata/web/resources/EntityResource.java
+6
-6
BaseResourceIT.java
.../apache/hadoop/metadata/web/resources/BaseResourceIT.java
+6
-1
EntityJerseyResourceIT.java
...hadoop/metadata/web/resources/EntityJerseyResourceIT.java
+132
-42
TypesJerseyResourceIT.java
.../hadoop/metadata/web/resources/TypesJerseyResourceIT.java
+3
-6
No files found.
repository/src/main/java/org/apache/hadoop/metadata/services/DefaultMetadataService.java
View file @
386d8d38
...
@@ -83,8 +83,10 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -83,8 +83,10 @@ public class DefaultMetadataService implements MetadataService {
return
response
;
return
response
;
}
catch
(
ParseException
e
)
{
}
catch
(
ParseException
e
)
{
LOG
.
error
(
"Unable to parse JSON for type {}"
,
typeName
,
e
);
throw
new
MetadataException
(
"validation failed for: "
+
typeName
);
throw
new
MetadataException
(
"validation failed for: "
+
typeName
);
}
catch
(
JSONException
e
)
{
}
catch
(
JSONException
e
)
{
LOG
.
error
(
"Unable to persist type {}"
,
typeName
,
e
);
throw
new
MetadataException
(
"Unable to create response for: "
+
typeName
);
throw
new
MetadataException
(
"Unable to create response for: "
+
typeName
);
}
}
}
}
...
@@ -147,6 +149,7 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -147,6 +149,7 @@ public class DefaultMetadataService implements MetadataService {
Serialization
$
.
MODULE
$
.
fromJson
(
entityDefinition
);
Serialization
$
.
MODULE
$
.
fromJson
(
entityDefinition
);
return
repository
.
createEntity
(
entityInstance
,
entityType
);
return
repository
.
createEntity
(
entityInstance
,
entityType
);
}
catch
(
ParseException
e
)
{
}
catch
(
ParseException
e
)
{
LOG
.
error
(
"Unable to parse JSON {} for type {}"
,
entityDefinition
,
entityType
,
e
);
throw
new
MetadataException
(
"validation failed for: "
+
entityType
);
throw
new
MetadataException
(
"validation failed for: "
+
entityType
);
}
}
}
}
...
@@ -154,7 +157,9 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -154,7 +157,9 @@ public class DefaultMetadataService implements MetadataService {
private
void
validateEntity
(
String
entity
,
String
entityType
)
throws
ParseException
{
private
void
validateEntity
(
String
entity
,
String
entityType
)
throws
ParseException
{
Preconditions
.
checkNotNull
(
entity
,
"entity cannot be null"
);
Preconditions
.
checkNotNull
(
entity
,
"entity cannot be null"
);
Preconditions
.
checkNotNull
(
entityType
,
"entity type cannot be null"
);
Preconditions
.
checkNotNull
(
entityType
,
"entity type cannot be null"
);
JSONValue
.
parseWithException
(
entity
);
// todo: this is failing for instances but not types
// JSONValue.parseWithException(entity);
}
}
/**
/**
...
@@ -167,21 +172,9 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -167,21 +172,9 @@ public class DefaultMetadataService implements MetadataService {
public
String
getEntityDefinition
(
String
guid
)
throws
MetadataException
{
public
String
getEntityDefinition
(
String
guid
)
throws
MetadataException
{
final
ITypedReferenceableInstance
instance
=
final
ITypedReferenceableInstance
instance
=
repository
.
getEntityDefinition
(
guid
);
repository
.
getEntityDefinition
(
guid
);
return
Serialization
$
.
MODULE
$
.
toJson
(
instance
);
return
instance
==
null
}
?
null
:
Serialization
$
.
MODULE
$
.
toJson
(
instance
);
/**
* Return the definition for the given entity name and type.
*
* @param entityName name
* @param entityType type
* @return entity definition as JSON
*/
@Override
public
String
getEntityDefinition
(
String
entityName
,
String
entityType
)
throws
MetadataException
{
throw
new
UnsupportedOperationException
();
}
}
/**
/**
...
...
repository/src/main/java/org/apache/hadoop/metadata/services/GraphBackedMetadataRepository.java
View file @
386d8d38
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/hadoop/metadata/services/MetadataService.java
View file @
386d8d38
...
@@ -73,15 +73,6 @@ public interface MetadataService extends Service {
...
@@ -73,15 +73,6 @@ public interface MetadataService extends Service {
String
getEntityDefinition
(
String
guid
)
throws
MetadataException
;
String
getEntityDefinition
(
String
guid
)
throws
MetadataException
;
/**
/**
* Return the definition for the given entity name and type.
*
* @param entityName name
* @param entityType type
* @return entity definition as JSON
*/
String
getEntityDefinition
(
String
entityName
,
String
entityType
)
throws
MetadataException
;
/**
* Return the list of entity names for the given type in the repository.
* Return the list of entity names for the given type in the repository.
*
*
* @param entityType type
* @param entityType type
...
...
repository/src/main/java/org/apache/hadoop/metadata/util/GraphUtils.java
View file @
386d8d38
...
@@ -23,9 +23,45 @@ public final class GraphUtils {
...
@@ -23,9 +23,45 @@ public final class GraphUtils {
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
GraphUtils
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
GraphUtils
.
class
);
private
static
final
String
GUID_PROPERTY_KEY
=
"guid"
;
private
static
final
String
TIMESTAMP_PROPERTY_KEY
=
"timestamp"
;
private
GraphUtils
()
{
private
GraphUtils
()
{
}
}
public
static
Edge
addEdge
(
Vertex
fromVertex
,
Vertex
toVertex
,
String
edgeLabel
)
{
return
addEdge
(
fromVertex
,
toVertex
,
edgeLabel
,
null
);
}
public
static
Edge
addEdge
(
Vertex
fromVertex
,
Vertex
toVertex
,
String
edgeLabel
,
String
timestamp
)
{
Edge
edge
=
findEdge
(
fromVertex
,
toVertex
,
edgeLabel
);
Edge
edgeToVertex
=
edge
!=
null
?
edge
:
fromVertex
.
addEdge
(
edgeLabel
,
toVertex
);
if
(
timestamp
!=
null
)
{
edgeToVertex
.
setProperty
(
TIMESTAMP_PROPERTY_KEY
,
timestamp
);
}
return
edgeToVertex
;
}
public
static
Edge
findEdge
(
Vertex
fromVertex
,
Vertex
toVertex
,
String
edgeLabel
)
{
return
findEdge
(
fromVertex
,
toVertex
.
getProperty
(
GUID_PROPERTY_KEY
),
edgeLabel
);
}
public
static
Edge
findEdge
(
Vertex
fromVertex
,
Object
toVertexName
,
String
edgeLabel
)
{
Edge
edgeToFind
=
null
;
for
(
Edge
edge
:
fromVertex
.
getEdges
(
Direction
.
OUT
,
edgeLabel
))
{
if
(
edge
.
getVertex
(
Direction
.
IN
).
getProperty
(
GUID_PROPERTY_KEY
).
equals
(
toVertexName
))
{
edgeToFind
=
edge
;
break
;
}
}
return
edgeToFind
;
}
public
static
Vertex
findVertex
(
Graph
blueprintsGraph
,
public
static
Vertex
findVertex
(
Graph
blueprintsGraph
,
String
guid
)
{
String
guid
)
{
LOG
.
debug
(
"Finding vertex for: guid={}"
,
guid
);
LOG
.
debug
(
"Finding vertex for: guid={}"
,
guid
);
...
...
webapp/src/main/java/org/apache/hadoop/metadata/web/resources/EntityResource.java
View file @
386d8d38
...
@@ -67,22 +67,23 @@ public class EntityResource {
...
@@ -67,22 +67,23 @@ public class EntityResource {
}
}
@POST
@POST
@Path
(
"submit/{
entityTyp
e}"
)
@Path
(
"submit/{
typeNam
e}"
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Response
submit
(
@Context
HttpServletRequest
request
,
public
Response
submit
(
@Context
HttpServletRequest
request
,
@PathParam
(
"
entityType"
)
final
String
entityTyp
e
)
{
@PathParam
(
"
typeName"
)
final
String
typeNam
e
)
{
try
{
try
{
final
String
entity
=
Servlets
.
getRequestPayload
(
request
);
final
String
entity
=
Servlets
.
getRequestPayload
(
request
);
System
.
out
.
println
(
"entity = "
+
entity
);
LOG
.
debug
(
"submitting entity {} "
,
entity
);
final
String
guid
=
metadataService
.
createEntity
(
entity
,
entityType
);
final
String
guid
=
metadataService
.
createEntity
(
typeName
,
entity
);
JSONObject
response
=
new
JSONObject
();
JSONObject
response
=
new
JSONObject
();
response
.
put
(
"GUID"
,
guid
);
response
.
put
(
"GUID"
,
guid
);
response
.
put
(
"requestId"
,
Thread
.
currentThread
().
getName
());
response
.
put
(
"requestId"
,
Thread
.
currentThread
().
getName
());
return
Response
.
ok
(
response
).
build
();
return
Response
.
ok
(
response
).
build
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Unable to persist instance for type {}"
,
typeName
,
e
);
throw
new
WebApplicationException
(
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
BAD_REQUEST
));
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
BAD_REQUEST
));
}
}
...
@@ -109,8 +110,7 @@ public class EntityResource {
...
@@ -109,8 +110,7 @@ public class EntityResource {
return
Response
.
status
(
status
).
entity
(
response
).
build
();
return
Response
.
status
(
status
).
entity
(
response
).
build
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Action failed: {}\nError: {}"
,
LOG
.
error
(
"Unable to get instance definition for GUID {}"
,
guid
,
e
);
Response
.
Status
.
INTERNAL_SERVER_ERROR
,
e
.
getMessage
());
throw
new
WebApplicationException
(
e
,
Response
throw
new
WebApplicationException
(
e
,
Response
.
status
(
Response
.
Status
.
INTERNAL_SERVER_ERROR
)
.
status
(
Response
.
Status
.
INTERNAL_SERVER_ERROR
)
.
entity
(
e
.
getMessage
())
.
entity
(
e
.
getMessage
())
...
...
webapp/src/test/java/org/apache/hadoop/metadata/web/resources/BaseResourceIT.java
View file @
386d8d38
...
@@ -10,16 +10,21 @@ import org.apache.hadoop.metadata.types.HierarchicalTypeDefinition;
...
@@ -10,16 +10,21 @@ import org.apache.hadoop.metadata.types.HierarchicalTypeDefinition;
import
org.apache.hadoop.metadata.types.IDataType
;
import
org.apache.hadoop.metadata.types.IDataType
;
import
org.apache.hadoop.metadata.types.Multiplicity
;
import
org.apache.hadoop.metadata.types.Multiplicity
;
import
org.apache.hadoop.metadata.types.TraitType
;
import
org.apache.hadoop.metadata.types.TraitType
;
import
org.apache.hadoop.metadata.types.TypeSystem
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.BeforeClass
;
import
javax.ws.rs.core.UriBuilder
;
import
javax.ws.rs.core.UriBuilder
;
public
class
BaseResourceIT
{
public
abstract
class
BaseResourceIT
{
protected
TypeSystem
typeSystem
;
protected
WebResource
service
;
protected
WebResource
service
;
@BeforeClass
@BeforeClass
public
void
setUp
()
throws
Exception
{
public
void
setUp
()
throws
Exception
{
typeSystem
=
TypeSystem
.
getInstance
();
typeSystem
.
reset
();
String
baseUrl
=
"http://localhost:21000/"
;
String
baseUrl
=
"http://localhost:21000/"
;
DefaultClientConfig
config
=
new
DefaultClientConfig
();
DefaultClientConfig
config
=
new
DefaultClientConfig
();
...
...
webapp/src/test/java/org/apache/hadoop/metadata/web/resources/EntityJerseyResourceIT.java
View file @
386d8d38
...
@@ -18,54 +18,78 @@
...
@@ -18,54 +18,78 @@
package
org
.
apache
.
hadoop
.
metadata
.
web
.
resources
;
package
org
.
apache
.
hadoop
.
metadata
.
web
.
resources
;
import
java.util.HashMap
;
import
com.google.common.collect.ImmutableList
;
import
java.util.Map
;
import
com.sun.jersey.api.client.ClientResponse
;
import
java.util.UUID
;
import
com.sun.jersey.api.client.WebResource
;
import
org.apache.hadoop.metadata.ITypedReferenceableInstance
;
import
org.apache.hadoop.metadata.Referenceable
;
import
org.apache.hadoop.metadata.Struct
;
import
org.apache.hadoop.metadata.json.Serialization
$
;
import
org.apache.hadoop.metadata.json.TypesSerialization
;
import
org.apache.hadoop.metadata.types.AttributeDefinition
;
import
org.apache.hadoop.metadata.types.ClassType
;
import
org.apache.hadoop.metadata.types.DataTypes
;
import
org.apache.hadoop.metadata.types.HierarchicalTypeDefinition
;
import
org.apache.hadoop.metadata.types.Multiplicity
;
import
org.apache.hadoop.metadata.types.StructTypeDefinition
;
import
org.apache.hadoop.metadata.types.TraitType
;
import
org.codehaus.jettison.json.JSONObject
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.Test
;
import
javax.ws.rs.HttpMethod
;
import
javax.ws.rs.HttpMethod
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response
;
import
java.util.ArrayList
;
import
org.json.simple.JSONValue
;
import
java.util.List
;
import
org.testng.Assert
;
import
java.util.UUID
;
import
org.testng.annotations.Test
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonParser
;
import
com.sun.jersey.api.client.ClientResponse
;
import
com.sun.jersey.api.client.WebResource
;
/**
/**
* Integration tests for Entity Jersey Resource.
* Integration tests for Entity Jersey Resource.
*/
*/
@Test
(
enabled
=
false
)
public
class
EntityJerseyResourceIT
extends
BaseResourceIT
{
public
class
EntityJerseyResourceIT
extends
BaseResourceIT
{
private
static
final
String
ENTITY_NAME
=
"clicks-table"
;
private
static
final
String
DATABASE_TYPE
=
"hive_database"
;
private
static
final
String
ENTITY_TYPE
=
"hive-table"
;
private
static
final
String
DATABASE_NAME
=
"foo"
;
private
static
final
String
DATABASE_NAME
=
"ads"
;
private
static
final
String
TABLE_TYPE
=
"hive_table"
;
private
static
final
String
TABLE_NAME
=
"clicks-table"
;
private
static
final
String
TABLE_NAME
=
"bar"
;
private
static
final
String
TRAIT_TYPE
=
"hive_fetl"
;
private
String
guid
;
@BeforeClass
public
void
setUp
()
throws
Exception
{
super
.
setUp
();
List
<
HierarchicalTypeDefinition
>
typeDefinitions
=
createHiveTypes
();
submitTypes
(
typeDefinitions
);
}
@Test
public
void
testSubmitEntity
()
throws
Exception
{
ITypedReferenceableInstance
tableInstance
=
createHiveTableInstance
();
@Test
(
enabled
=
false
)
String
instanceAsJSON
=
Serialization
$
.
MODULE
$
.
toJson
(
tableInstance
);
public
void
testSubmitEntity
()
{
String
entityStream
=
getTestEntityJSON
();
JsonParser
parser
=
new
JsonParser
();
WebResource
resource
=
service
WebResource
resource
=
service
.
path
(
"api/metadata/entities/submit"
)
.
path
(
"api/metadata/entities/submit"
)
.
path
(
ENTITY
_TYPE
);
.
path
(
TABLE
_TYPE
);
ClientResponse
clientResponse
=
resource
ClientResponse
clientResponse
=
resource
.
accept
(
MediaType
.
APPLICATION_JSON
)
.
accept
(
MediaType
.
APPLICATION_JSON
)
.
type
(
MediaType
.
APPLICATION_JSON
)
.
type
(
MediaType
.
APPLICATION_JSON
)
.
method
(
HttpMethod
.
POST
,
ClientResponse
.
class
,
entityStream
);
.
method
(
HttpMethod
.
POST
,
ClientResponse
.
class
,
instanceAsJSON
);
Assert
.
assertEquals
(
clientResponse
.
getStatus
(),
Response
.
Status
.
OK
.
getStatusCode
());
Assert
.
assertEquals
(
clientResponse
.
getStatus
(),
Response
.
Status
.
OK
.
getStatusCode
());
String
response
=
clientResponse
.
getEntity
(
String
.
class
);
String
responseAsString
=
clientResponse
.
getEntity
(
String
.
class
);
Assert
.
assertNotNull
(
response
);
Assert
.
assertNotNull
(
responseAsString
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertNotNull
(
response
.
get
(
"requestId"
));
JsonElement
elem
=
parser
.
parse
(
response
);
guid
=
response
.
get
(
"GUID"
).
toString
(
);
String
guid
=
elem
.
getAsJsonObject
().
get
(
"GUID"
).
getAsString
(
);
Assert
.
assertNotNull
(
guid
);
try
{
try
{
Assert
.
assertNotNull
(
UUID
.
fromString
(
guid
));
Assert
.
assertNotNull
(
UUID
.
fromString
(
guid
));
...
@@ -74,12 +98,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
...
@@ -74,12 +98,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
}
}
}
}
@Test
(
dependsOnMethods
=
"testSubmitEntity"
,
enabled
=
false
)
@Test
(
dependsOnMethods
=
"testSubmitEntity"
)
public
void
testGetEntityDefinition
()
{
public
void
testGetEntityDefinition
()
{
WebResource
resource
=
service
WebResource
resource
=
service
.
path
(
"api/metadata/entities/definition"
)
.
path
(
"api/metadata/entities/definition"
)
.
path
(
ENTITY_TYPE
)
.
path
(
guid
);
.
path
(
ENTITY_NAME
);
ClientResponse
clientResponse
=
resource
ClientResponse
clientResponse
=
resource
.
accept
(
MediaType
.
APPLICATION_JSON
)
.
accept
(
MediaType
.
APPLICATION_JSON
)
...
@@ -90,20 +113,10 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
...
@@ -90,20 +113,10 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
System
.
out
.
println
(
"response = "
+
response
);
System
.
out
.
println
(
"response = "
+
response
);
}
}
private
static
String
getTestEntityJSON
()
{
@Test
Map
<
String
,
String
>
props
=
new
HashMap
<>();
props
.
put
(
"entityName"
,
ENTITY_NAME
);
props
.
put
(
"entityType"
,
ENTITY_TYPE
);
props
.
put
(
"database"
,
DATABASE_NAME
);
props
.
put
(
"table"
,
TABLE_NAME
);
return
JSONValue
.
toJSONString
(
props
);
}
@Test
(
enabled
=
false
)
public
void
testGetInvalidEntityDefinition
()
{
public
void
testGetInvalidEntityDefinition
()
{
WebResource
resource
=
service
WebResource
resource
=
service
.
path
(
"api/metadata/entities/definition"
)
.
path
(
"api/metadata/entities/definition"
)
.
path
(
ENTITY_TYPE
)
.
path
(
"blah"
);
.
path
(
"blah"
);
ClientResponse
clientResponse
=
resource
ClientResponse
clientResponse
=
resource
...
@@ -119,7 +132,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
...
@@ -119,7 +132,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
public
void
testGetEntityList
()
{
public
void
testGetEntityList
()
{
ClientResponse
clientResponse
=
service
ClientResponse
clientResponse
=
service
.
path
(
"api/metadata/entities/list/"
)
.
path
(
"api/metadata/entities/list/"
)
.
path
(
ENTITY
_TYPE
)
.
path
(
TABLE
_TYPE
)
.
accept
(
MediaType
.
APPLICATION_JSON
)
.
accept
(
MediaType
.
APPLICATION_JSON
)
.
type
(
MediaType
.
APPLICATION_JSON
)
.
type
(
MediaType
.
APPLICATION_JSON
)
.
method
(
HttpMethod
.
GET
,
ClientResponse
.
class
);
.
method
(
HttpMethod
.
GET
,
ClientResponse
.
class
);
...
@@ -139,4 +152,81 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
...
@@ -139,4 +152,81 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
String
response
=
clientResponse
.
getEntity
(
String
.
class
);
String
response
=
clientResponse
.
getEntity
(
String
.
class
);
System
.
out
.
println
(
"response = "
+
response
);
System
.
out
.
println
(
"response = "
+
response
);
}
}
private
List
<
HierarchicalTypeDefinition
>
createHiveTypes
()
throws
Exception
{
ArrayList
<
HierarchicalTypeDefinition
>
typeDefinitions
=
new
ArrayList
<>();
HierarchicalTypeDefinition
<
ClassType
>
databaseTypeDefinition
=
createClassTypeDef
(
DATABASE_TYPE
,
ImmutableList
.<
String
>
of
(),
createRequiredAttrDef
(
"name"
,
DataTypes
.
STRING_TYPE
),
createRequiredAttrDef
(
"description"
,
DataTypes
.
STRING_TYPE
));
typeDefinitions
.
add
(
databaseTypeDefinition
);
HierarchicalTypeDefinition
<
ClassType
>
tableTypeDefinition
=
createClassTypeDef
(
TABLE_TYPE
,
ImmutableList
.<
String
>
of
(),
createRequiredAttrDef
(
"name"
,
DataTypes
.
STRING_TYPE
),
createRequiredAttrDef
(
"description"
,
DataTypes
.
STRING_TYPE
),
createRequiredAttrDef
(
"type"
,
DataTypes
.
STRING_TYPE
),
new
AttributeDefinition
(
DATABASE_TYPE
,
DATABASE_TYPE
,
Multiplicity
.
REQUIRED
,
true
,
DATABASE_TYPE
));
typeDefinitions
.
add
(
tableTypeDefinition
);
HierarchicalTypeDefinition
<
TraitType
>
fetlTypeDefinition
=
createTraitTypeDef
(
TRAIT_TYPE
,
ImmutableList
.<
String
>
of
(),
createRequiredAttrDef
(
"level"
,
DataTypes
.
INT_TYPE
));
typeDefinitions
.
add
(
fetlTypeDefinition
);
typeSystem
.
defineTypes
(
ImmutableList
.<
StructTypeDefinition
>
of
(),
ImmutableList
.
of
(
fetlTypeDefinition
),
ImmutableList
.
of
(
databaseTypeDefinition
,
tableTypeDefinition
));
return
typeDefinitions
;
}
private
void
submitTypes
(
List
<
HierarchicalTypeDefinition
>
typeDefinitions
)
throws
Exception
{
for
(
HierarchicalTypeDefinition
typeDefinition
:
typeDefinitions
)
{
String
typesAsJSON
=
TypesSerialization
.
toJson
(
typeSystem
,
typeDefinition
.
typeName
);
WebResource
resource
=
service
.
path
(
"api/metadata/types/submit"
)
.
path
(
typeDefinition
.
typeName
);
ClientResponse
clientResponse
=
resource
.
accept
(
MediaType
.
APPLICATION_JSON
)
.
type
(
MediaType
.
APPLICATION_JSON
)
.
method
(
HttpMethod
.
POST
,
ClientResponse
.
class
,
typesAsJSON
);
Assert
.
assertEquals
(
clientResponse
.
getStatus
(),
Response
.
Status
.
OK
.
getStatusCode
());
String
responseAsString
=
clientResponse
.
getEntity
(
String
.
class
);
Assert
.
assertNotNull
(
responseAsString
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertEquals
(
response
.
get
(
"typeName"
),
typeDefinition
.
typeName
);
Assert
.
assertNotNull
(
response
.
get
(
"types"
));
Assert
.
assertNotNull
(
response
.
get
(
"requestId"
));
}
}
protected
ITypedReferenceableInstance
createHiveTableInstance
()
throws
Exception
{
Referenceable
databaseInstance
=
new
Referenceable
(
DATABASE_TYPE
);
databaseInstance
.
set
(
"name"
,
DATABASE_NAME
);
databaseInstance
.
set
(
"description"
,
"foo database"
);
Referenceable
tableInstance
=
new
Referenceable
(
TABLE_TYPE
,
TRAIT_TYPE
);
tableInstance
.
set
(
"name"
,
TABLE_NAME
);
tableInstance
.
set
(
"description"
,
"bar table"
);
tableInstance
.
set
(
"type"
,
"managed"
);
tableInstance
.
set
(
DATABASE_TYPE
,
databaseInstance
);
Struct
traitInstance
=
(
Struct
)
tableInstance
.
getTrait
(
TRAIT_TYPE
);
traitInstance
.
set
(
"level"
,
1
);
ClassType
tableType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
TABLE_TYPE
);
return
tableType
.
convert
(
tableInstance
,
Multiplicity
.
REQUIRED
);
}
}
}
webapp/src/test/java/org/apache/hadoop/metadata/web/resources/TypesJerseyResourceIT.java
View file @
386d8d38
...
@@ -21,7 +21,6 @@ package org.apache.hadoop.metadata.web.resources;
...
@@ -21,7 +21,6 @@ package org.apache.hadoop.metadata.web.resources;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableList
;
import
com.sun.jersey.api.client.ClientResponse
;
import
com.sun.jersey.api.client.ClientResponse
;
import
com.sun.jersey.api.client.WebResource
;
import
com.sun.jersey.api.client.WebResource
;
import
org.apache.hadoop.metadata.MetadataException
;
import
org.apache.hadoop.metadata.json.TypesSerialization
;
import
org.apache.hadoop.metadata.json.TypesSerialization
;
import
org.apache.hadoop.metadata.types.AttributeDefinition
;
import
org.apache.hadoop.metadata.types.AttributeDefinition
;
import
org.apache.hadoop.metadata.types.ClassType
;
import
org.apache.hadoop.metadata.types.ClassType
;
...
@@ -30,7 +29,6 @@ import org.apache.hadoop.metadata.types.HierarchicalTypeDefinition;
...
@@ -30,7 +29,6 @@ import org.apache.hadoop.metadata.types.HierarchicalTypeDefinition;
import
org.apache.hadoop.metadata.types.Multiplicity
;
import
org.apache.hadoop.metadata.types.Multiplicity
;
import
org.apache.hadoop.metadata.types.StructTypeDefinition
;
import
org.apache.hadoop.metadata.types.StructTypeDefinition
;
import
org.apache.hadoop.metadata.types.TraitType
;
import
org.apache.hadoop.metadata.types.TraitType
;
import
org.apache.hadoop.metadata.types.TypeSystem
;
import
org.codehaus.jettison.json.JSONArray
;
import
org.codehaus.jettison.json.JSONArray
;
import
org.codehaus.jettison.json.JSONObject
;
import
org.codehaus.jettison.json.JSONObject
;
import
org.testng.Assert
;
import
org.testng.Assert
;
...
@@ -49,14 +47,12 @@ import java.util.List;
...
@@ -49,14 +47,12 @@ import java.util.List;
*/
*/
public
class
TypesJerseyResourceIT
extends
BaseResourceIT
{
public
class
TypesJerseyResourceIT
extends
BaseResourceIT
{
private
TypeSystem
typeSystem
;
private
List
<
HierarchicalTypeDefinition
>
typeDefinitions
;
private
List
<
HierarchicalTypeDefinition
>
typeDefinitions
;
@BeforeClass
@BeforeClass
public
void
setUp
()
throws
Exception
{
public
void
setUp
()
throws
Exception
{
super
.
setUp
();
super
.
setUp
();
typeSystem
=
TypeSystem
.
getInstance
();
typeDefinitions
=
createHiveTypes
();
typeDefinitions
=
createHiveTypes
();
}
}
...
@@ -151,11 +147,12 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
...
@@ -151,11 +147,12 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
Assert
.
assertNotNull
(
list
);
Assert
.
assertNotNull
(
list
);
}
}
private
List
<
HierarchicalTypeDefinition
>
createHiveTypes
()
throws
Metadata
Exception
{
private
List
<
HierarchicalTypeDefinition
>
createHiveTypes
()
throws
Exception
{
ArrayList
<
HierarchicalTypeDefinition
>
typeDefinitions
=
new
ArrayList
<>();
ArrayList
<
HierarchicalTypeDefinition
>
typeDefinitions
=
new
ArrayList
<>();
HierarchicalTypeDefinition
<
ClassType
>
databaseTypeDefinition
=
HierarchicalTypeDefinition
<
ClassType
>
databaseTypeDefinition
=
createClassTypeDef
(
"database"
,
ImmutableList
.<
String
>
of
(),
createClassTypeDef
(
"database"
,
ImmutableList
.<
String
>
of
(),
createRequiredAttrDef
(
"name"
,
DataTypes
.
STRING_TYPE
),
createRequiredAttrDef
(
"name"
,
DataTypes
.
STRING_TYPE
),
createRequiredAttrDef
(
"description"
,
DataTypes
.
STRING_TYPE
));
createRequiredAttrDef
(
"description"
,
DataTypes
.
STRING_TYPE
));
typeDefinitions
.
add
(
databaseTypeDefinition
);
typeDefinitions
.
add
(
databaseTypeDefinition
);
...
...
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