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
e747e2ae
Commit
e747e2ae
authored
Mar 23, 2015
by
Venkatesh Seetharam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tests to rid using TypeSystem in client
parent
35adfb8e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
134 additions
and
80 deletions
+134
-80
MetadataServiceClient.java
...ava/org/apache/hadoop/metadata/MetadataServiceClient.java
+33
-5
EntityChangeListener.java
...apache/hadoop/metadata/listener/EntityChangeListener.java
+1
-3
MetadataRepository.java
...apache/hadoop/metadata/repository/MetadataRepository.java
+3
-16
GraphBackedMetadataRepository.java
...adata/repository/graph/GraphBackedMetadataRepository.java
+2
-3
DefaultMetadataService.java
...ache/hadoop/metadata/services/DefaultMetadataService.java
+41
-14
MetadataService.java
.../org/apache/hadoop/metadata/services/MetadataService.java
+5
-5
GraphBackedDiscoveryServiceTest.java
...p/metadata/discovery/GraphBackedDiscoveryServiceTest.java
+5
-7
GraphBackedMetadataRepositoryTest.java
...a/repository/graph/GraphBackedMetadataRepositoryTest.java
+3
-3
GraphRepoMapperScaleTest.java
...p/metadata/repository/graph/GraphRepoMapperScaleTest.java
+2
-2
EntityResource.java
.../apache/hadoop/metadata/web/resources/EntityResource.java
+8
-10
BaseResourceIT.java
.../apache/hadoop/metadata/web/resources/BaseResourceIT.java
+30
-10
EntityJerseyResourceIT.java
...hadoop/metadata/web/resources/EntityJerseyResourceIT.java
+0
-0
MetadataDiscoveryJerseyResourceIT.java
...data/web/resources/MetadataDiscoveryJerseyResourceIT.java
+0
-0
TypesJerseyResourceIT.java
.../hadoop/metadata/web/resources/TypesJerseyResourceIT.java
+1
-2
No files found.
client/src/main/java/org/apache/hadoop/metadata/MetadataServiceClient.java
View file @
e747e2ae
...
@@ -22,6 +22,7 @@ import com.sun.jersey.api.client.Client;
...
@@ -22,6 +22,7 @@ import com.sun.jersey.api.client.Client;
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
com.sun.jersey.api.client.config.DefaultClientConfig
;
import
com.sun.jersey.api.client.config.DefaultClientConfig
;
import
org.codehaus.jettison.json.JSONArray
;
import
org.codehaus.jettison.json.JSONException
;
import
org.codehaus.jettison.json.JSONException
;
import
org.codehaus.jettison.json.JSONObject
;
import
org.codehaus.jettison.json.JSONObject
;
...
@@ -29,7 +30,12 @@ import javax.ws.rs.HttpMethod;
...
@@ -29,7 +30,12 @@ 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
javax.ws.rs.core.UriBuilder
;
import
javax.ws.rs.core.UriBuilder
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Client for metadata.
*/
public
class
MetadataServiceClient
{
public
class
MetadataServiceClient
{
public
static
final
String
REQUEST_ID
=
"requestId"
;
public
static
final
String
REQUEST_ID
=
"requestId"
;
public
static
final
String
RESULTS
=
"results"
;
public
static
final
String
RESULTS
=
"results"
;
...
@@ -50,8 +56,8 @@ public class MetadataServiceClient {
...
@@ -50,8 +56,8 @@ public class MetadataServiceClient {
//Type operations
//Type operations
CREATE_TYPE
(
"api/metadata/types/submit"
,
HttpMethod
.
POST
),
CREATE_TYPE
(
"api/metadata/types/submit"
,
HttpMethod
.
POST
),
GET_TYPE
(
"api/metadata/types/definition"
,
HttpMethod
.
GET
),
GET_TYPE
(
"api/metadata/types/definition"
,
HttpMethod
.
GET
),
LIST_TYPE
(
"api/metadata/types/list"
,
HttpMethod
.
GET
),
LIST_TYPE
S
(
"api/metadata/types/list"
,
HttpMethod
.
GET
),
LIST_TRAIT_TYPE
(
"api/metadata/types/traits/list"
,
HttpMethod
.
GET
),
LIST_TRAIT_TYPE
S
(
"api/metadata/types/traits/list"
,
HttpMethod
.
GET
),
//Entity operations
//Entity operations
CREATE_ENTITY
(
"api/metadata/entities/submit"
,
HttpMethod
.
POST
),
CREATE_ENTITY
(
"api/metadata/entities/submit"
,
HttpMethod
.
POST
),
...
@@ -81,8 +87,28 @@ public class MetadataServiceClient {
...
@@ -81,8 +87,28 @@ public class MetadataServiceClient {
}
}
}
}
public
JSONObject
createEntity
(
String
typeName
,
String
entityAsJson
)
throws
MetadataServiceException
{
public
JSONObject
createType
(
String
typeName
,
return
callAPI
(
API
.
CREATE_ENTITY
,
entityAsJson
,
typeName
);
String
typeAsJson
)
throws
MetadataServiceException
{
return
callAPI
(
API
.
CREATE_TYPE
,
typeAsJson
,
typeName
);
}
public
List
<
String
>
listTypes
()
throws
MetadataServiceException
{
try
{
final
JSONObject
jsonObject
=
callAPI
(
API
.
LIST_TYPES
,
null
);
final
JSONArray
list
=
jsonObject
.
getJSONArray
(
MetadataServiceClient
.
RESULTS
);
ArrayList
<
String
>
types
=
new
ArrayList
<>();
for
(
int
index
=
0
;
index
<
list
.
length
();
index
++)
{
types
.
add
(
list
.
getString
(
index
));
}
return
types
;
}
catch
(
JSONException
e
)
{
throw
new
MetadataServiceException
(
API
.
LIST_TYPES
,
e
);
}
}
public
JSONObject
createEntity
(
String
entityAsJson
)
throws
MetadataServiceException
{
return
callAPI
(
API
.
CREATE_ENTITY
,
entityAsJson
);
}
}
public
String
getRequestId
(
JSONObject
json
)
throws
MetadataServiceException
{
public
String
getRequestId
(
JSONObject
json
)
throws
MetadataServiceException
{
...
@@ -101,7 +127,9 @@ public class MetadataServiceClient {
...
@@ -101,7 +127,9 @@ public class MetadataServiceClient {
}
}
}
}
ClientResponse
clientResponse
=
resource
.
accept
(
MediaType
.
APPLICATION_JSON
).
type
(
MediaType
.
APPLICATION_JSON
)
ClientResponse
clientResponse
=
resource
.
accept
(
MediaType
.
APPLICATION_JSON
)
.
type
(
MediaType
.
APPLICATION_JSON
)
.
method
(
api
.
getMethod
(),
ClientResponse
.
class
,
requestObject
);
.
method
(
api
.
getMethod
(),
ClientResponse
.
class
,
requestObject
);
if
(
clientResponse
.
getStatus
()
==
Response
.
Status
.
OK
.
getStatusCode
())
{
if
(
clientResponse
.
getStatus
()
==
Response
.
Status
.
OK
.
getStatusCode
())
{
...
...
repository/src/main/java/org/apache/hadoop/metadata/listener/EntityChangeListener.java
View file @
e747e2ae
...
@@ -29,12 +29,10 @@ public interface EntityChangeListener {
...
@@ -29,12 +29,10 @@ public interface EntityChangeListener {
/**
/**
* This is upon adding a new typed instance to the repository.
* This is upon adding a new typed instance to the repository.
*
*
* @param typeName type name
* @param typedInstance a typed instance
* @param typedInstance a typed instance
* @throws org.apache.hadoop.metadata.MetadataException
* @throws org.apache.hadoop.metadata.MetadataException
*/
*/
void
onEntityAdded
(
String
typeName
,
void
onEntityAdded
(
ITypedReferenceableInstance
typedInstance
)
throws
MetadataException
;
ITypedReferenceableInstance
typedInstance
)
throws
MetadataException
;
/**
/**
* This is upon adding a new trait to a typed instance.
* This is upon adding a new trait to a typed instance.
...
...
repository/src/main/java/org/apache/hadoop/metadata/repository/MetadataRepository.java
View file @
e747e2ae
...
@@ -69,12 +69,10 @@ public interface MetadataRepository {
...
@@ -69,12 +69,10 @@ public interface MetadataRepository {
* Creates an entity definition (instance) corresponding to a given type.
* Creates an entity definition (instance) corresponding to a given type.
*
*
* @param entity entity (typed instance)
* @param entity entity (typed instance)
* @param entityType entity type name
* @return a globally unique identifier
* @return a globally unique identifier
* @throws RepositoryException
* @throws RepositoryException
*/
*/
String
createEntity
(
IReferenceableInstance
entity
,
String
createEntity
(
IReferenceableInstance
entity
)
throws
RepositoryException
;
String
entityType
)
throws
RepositoryException
;
/**
/**
* Fetch the complete definition of an entity given its GUID.
* Fetch the complete definition of an entity given its GUID.
...
@@ -137,17 +135,6 @@ public interface MetadataRepository {
...
@@ -137,17 +135,6 @@ public interface MetadataRepository {
ITypedStruct
traitInstance
)
throws
RepositoryException
;
ITypedStruct
traitInstance
)
throws
RepositoryException
;
/**
/**
* Adds a list of traits to an existing entity represented by a guid.
*
* @param guid globally unique identifier for the entity
* @param traitInstances list of trait instances that needs to be added to entity
* @return an entity instance with updated traits
* @throws RepositoryException
*/
// ITypedReferenceableInstance addTraits(String guid, Map<String, ITypedStruct> traitInstances)
// throws RepositoryException;
/**
* Deletes a given trait from an existing entity represented by a guid.
* Deletes a given trait from an existing entity represented by a guid.
*
*
* @param guid globally unique identifier for the entity
* @param guid globally unique identifier for the entity
...
@@ -160,8 +147,8 @@ public interface MetadataRepository {
...
@@ -160,8 +147,8 @@ public interface MetadataRepository {
/**
/**
* Adds the property to the entity that corresponds to the GUID
* Adds the property to the entity that corresponds to the GUID
* @param guid entity id
* @param guid entity id
* @param property
* @param property
property name
* @param value
* @param value
property value
*/
*/
void
updateEntity
(
String
guid
,
String
property
,
String
value
)
throws
RepositoryException
;
void
updateEntity
(
String
guid
,
String
property
,
String
value
)
throws
RepositoryException
;
}
}
repository/src/main/java/org/apache/hadoop/metadata/repository/graph/GraphBackedMetadataRepository.java
View file @
e747e2ae
...
@@ -116,9 +116,8 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
...
@@ -116,9 +116,8 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
}
}
@Override
@Override
public
String
createEntity
(
IReferenceableInstance
typedInstance
,
public
String
createEntity
(
IReferenceableInstance
typedInstance
)
throws
RepositoryException
{
String
typeName
)
throws
RepositoryException
{
LOG
.
info
(
"adding entity={}"
,
typedInstance
);
LOG
.
info
(
"adding entity={} type={}"
,
typedInstance
,
typeName
);
try
{
try
{
titanGraph
.
rollback
();
titanGraph
.
rollback
();
...
...
repository/src/main/java/org/apache/hadoop/metadata/services/DefaultMetadataService.java
View file @
e747e2ae
...
@@ -28,10 +28,16 @@ import org.apache.hadoop.metadata.repository.MetadataRepository;
...
@@ -28,10 +28,16 @@ import org.apache.hadoop.metadata.repository.MetadataRepository;
import
org.apache.hadoop.metadata.repository.typestore.ITypeStore
;
import
org.apache.hadoop.metadata.repository.typestore.ITypeStore
;
import
org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance
;
import
org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance
;
import
org.apache.hadoop.metadata.typesystem.ITypedStruct
;
import
org.apache.hadoop.metadata.typesystem.ITypedStruct
;
import
org.apache.hadoop.metadata.typesystem.Referenceable
;
import
org.apache.hadoop.metadata.typesystem.Struct
;
import
org.apache.hadoop.metadata.typesystem.TypesDef
;
import
org.apache.hadoop.metadata.typesystem.TypesDef
;
import
org.apache.hadoop.metadata.typesystem.json.InstanceSerialization
;
import
org.apache.hadoop.metadata.typesystem.json.Serialization
$
;
import
org.apache.hadoop.metadata.typesystem.json.Serialization
$
;
import
org.apache.hadoop.metadata.typesystem.json.TypesSerialization
;
import
org.apache.hadoop.metadata.typesystem.json.TypesSerialization
;
import
org.apache.hadoop.metadata.typesystem.types.ClassType
;
import
org.apache.hadoop.metadata.typesystem.types.IDataType
;
import
org.apache.hadoop.metadata.typesystem.types.IDataType
;
import
org.apache.hadoop.metadata.typesystem.types.Multiplicity
;
import
org.apache.hadoop.metadata.typesystem.types.TraitType
;
import
org.apache.hadoop.metadata.typesystem.types.TypeSystem
;
import
org.apache.hadoop.metadata.typesystem.types.TypeSystem
;
import
org.codehaus.jettison.json.JSONException
;
import
org.codehaus.jettison.json.JSONException
;
import
org.codehaus.jettison.json.JSONObject
;
import
org.codehaus.jettison.json.JSONObject
;
...
@@ -151,24 +157,39 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -151,24 +157,39 @@ public class DefaultMetadataService implements MetadataService {
/**
/**
* Creates an entity, instance of the type.
* Creates an entity, instance of the type.
*
*
* @param entityType type
* @param entityInstanceDefinition definition
* @param entityDefinition definition
* @return guid
* @return guid
*/
*/
@Override
@Override
public
String
createEntity
(
String
entityType
,
public
String
createEntity
(
String
entityInstanceDefinition
)
throws
MetadataException
{
String
entityDefinition
)
throws
MetadataException
{
Preconditions
.
checkNotNull
(
entityInstanceDefinition
,
Preconditions
.
checkNotNull
(
entityDefinition
,
"entity cannot be null"
);
"entity instance definition cannot be null"
);
Preconditions
.
checkNotNull
(
entityType
,
"entity type cannot be null"
);
ITypedReferenceableInstance
entityTypedInstance
=
deserializeClassInstance
(
entityInstanceDefinition
);
ITypedReferenceableInstance
entityInstance
=
final
String
guid
=
repository
.
createEntity
(
entityTypedInstance
);
Serialization
$
.
MODULE
$
.
fromJson
(
entityDefinition
);
final
String
guid
=
repository
.
createEntity
(
entityInstance
,
entityType
);
onEntityAddedToRepo
(
entityType
,
entity
Instance
);
onEntityAddedToRepo
(
entityType
d
Instance
);
return
guid
;
return
guid
;
}
}
private
ITypedReferenceableInstance
deserializeClassInstance
(
String
entityInstanceDefinition
)
throws
MetadataException
{
try
{
final
Referenceable
entityInstance
=
InstanceSerialization
.
fromJsonReferenceable
(
entityInstanceDefinition
,
true
);
final
String
entityTypeName
=
entityInstance
.
getTypeName
();
Preconditions
.
checkNotNull
(
entityTypeName
,
"entity type cannot be null"
);
ClassType
entityType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
entityTypeName
);
return
entityType
.
convert
(
entityInstance
,
Multiplicity
.
REQUIRED
);
}
catch
(
Exception
e
)
{
throw
new
MetadataException
(
"Error deserializing trait instance"
);
}
}
/**
/**
* Return the definition for the given guid.
* Return the definition for the given guid.
*
*
...
@@ -256,7 +277,14 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -256,7 +277,14 @@ public class DefaultMetadataService implements MetadataService {
throws
MetadataException
{
throws
MetadataException
{
try
{
try
{
return
(
ITypedStruct
)
Serialization
$
.
MODULE
$
.
traitFromJson
(
traitInstanceDefinition
);
Struct
traitInstance
=
InstanceSerialization
.
fromJsonStruct
(
traitInstanceDefinition
,
true
);
final
String
entityTypeName
=
traitInstance
.
getTypeName
();
Preconditions
.
checkNotNull
(
entityTypeName
,
"entity type cannot be null"
);
TraitType
traitType
=
typeSystem
.
getDataType
(
TraitType
.
class
,
entityTypeName
);
return
traitType
.
convert
(
traitInstance
,
Multiplicity
.
REQUIRED
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
MetadataException
(
"Error deserializing trait instance"
);
throw
new
MetadataException
(
"Error deserializing trait instance"
);
}
}
...
@@ -301,12 +329,11 @@ public class DefaultMetadataService implements MetadataService {
...
@@ -301,12 +329,11 @@ public class DefaultMetadataService implements MetadataService {
typesChangeListeners
.
remove
(
listener
);
typesChangeListeners
.
remove
(
listener
);
}
}
private
void
onEntityAddedToRepo
(
String
typeName
,
private
void
onEntityAddedToRepo
(
ITypedReferenceableInstance
typedInstance
)
ITypedReferenceableInstance
typedInstance
)
throws
MetadataException
{
throws
MetadataException
{
for
(
EntityChangeListener
listener
:
entityChangeListeners
)
{
for
(
EntityChangeListener
listener
:
entityChangeListeners
)
{
listener
.
onEntityAdded
(
type
Name
,
type
dInstance
);
listener
.
onEntityAdded
(
typedInstance
);
}
}
}
}
...
...
repository/src/main/java/org/apache/hadoop/metadata/services/MetadataService.java
View file @
e747e2ae
...
@@ -64,11 +64,10 @@ public interface MetadataService {
...
@@ -64,11 +64,10 @@ public interface MetadataService {
/**
/**
* Creates an entity, instance of the type.
* Creates an entity, instance of the type.
*
*
* @param entityType type
* @param entityDefinition definition
* @param entityDefinition definition
* @return guid
* @return guid
*/
*/
String
createEntity
(
String
entity
Type
,
String
entity
Definition
)
throws
MetadataException
;
String
createEntity
(
String
entityDefinition
)
throws
MetadataException
;
/**
/**
* Return the definition for the given guid.
* Return the definition for the given guid.
...
@@ -87,10 +86,11 @@ public interface MetadataService {
...
@@ -87,10 +86,11 @@ public interface MetadataService {
List
<
String
>
getEntityList
(
String
entityType
)
throws
MetadataException
;
List
<
String
>
getEntityList
(
String
entityType
)
throws
MetadataException
;
/**
/**
* Adds the property to the given entity id(guid)
* Adds the property to the given entity id(guid).
*
* @param guid entity id
* @param guid entity id
* @param property
* @param property
property name
* @param value
* @param value
property value
*/
*/
void
updateEntity
(
String
guid
,
String
property
,
String
value
)
throws
MetadataException
;
void
updateEntity
(
String
guid
,
String
property
,
String
value
)
throws
MetadataException
;
...
...
repository/src/test/java/org/apache/hadoop/metadata/discovery/GraphBackedDiscoveryServiceTest.java
View file @
e747e2ae
...
@@ -78,7 +78,7 @@ public class GraphBackedDiscoveryServiceTest {
...
@@ -78,7 +78,7 @@ public class GraphBackedDiscoveryServiceTest {
ClassType
deptType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
"Department"
);
ClassType
deptType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
"Department"
);
ITypedReferenceableInstance
hrDept2
=
deptType
.
convert
(
hrDept
,
Multiplicity
.
REQUIRED
);
ITypedReferenceableInstance
hrDept2
=
deptType
.
convert
(
hrDept
,
Multiplicity
.
REQUIRED
);
repositoryService
.
createEntity
(
hrDept2
,
"Department"
);
repositoryService
.
createEntity
(
hrDept2
);
}
}
private
void
setupSampleData
()
throws
ScriptException
{
private
void
setupSampleData
()
throws
ScriptException
{
...
@@ -173,12 +173,10 @@ public class GraphBackedDiscoveryServiceTest {
...
@@ -173,12 +173,10 @@ public class GraphBackedDiscoveryServiceTest {
{
"DB, Table"
},
{
"DB, Table"
},
/*{"DB as db1 Table where db1.name = \"Reporting\""},*/
/*{"DB as db1 Table where db1.name = \"Reporting\""},*/
{
"DB name = \"Reporting\""
},
{
"DB name = \"Reporting\""
},
/*
{
"Column where Column isa PII"
},
{"Column where is PII"},
{
"Table is Dimension"
},
{"Table where is Dimension"},
{
"View is Dimension"
},
{"View where is Dimension"},
/*{"Column where Column isa PII select Column.name"},*/
{"Column where is PII select Column.name"},
*/
{
"Column select Column.name"
},
{
"Column select Column.name"
},
{
"from Table select Table.name"
},
{
"from Table select Table.name"
},
};
};
...
...
repository/src/test/java/org/apache/hadoop/metadata/repository/graph/GraphBackedMetadataRepositoryTest.java
View file @
e747e2ae
...
@@ -106,7 +106,7 @@ public class GraphBackedMetadataRepositoryTest {
...
@@ -106,7 +106,7 @@ public class GraphBackedMetadataRepositoryTest {
ClassType
deptType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
"Department"
);
ClassType
deptType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
"Department"
);
ITypedReferenceableInstance
hrDept2
=
deptType
.
convert
(
hrDept
,
Multiplicity
.
REQUIRED
);
ITypedReferenceableInstance
hrDept2
=
deptType
.
convert
(
hrDept
,
Multiplicity
.
REQUIRED
);
guid
=
repositoryService
.
createEntity
(
hrDept2
,
ENTITY_TYPE
);
guid
=
repositoryService
.
createEntity
(
hrDept2
);
Assert
.
assertNotNull
(
guid
);
Assert
.
assertNotNull
(
guid
);
}
}
...
@@ -154,14 +154,14 @@ public class GraphBackedMetadataRepositoryTest {
...
@@ -154,14 +154,14 @@ public class GraphBackedMetadataRepositoryTest {
ITypedReferenceableInstance
db
=
dbType
.
convert
(
databaseInstance
,
Multiplicity
.
REQUIRED
);
ITypedReferenceableInstance
db
=
dbType
.
convert
(
databaseInstance
,
Multiplicity
.
REQUIRED
);
System
.
out
.
println
(
"db = "
+
db
);
System
.
out
.
println
(
"db = "
+
db
);
String
dbGUID
=
repositoryService
.
createEntity
(
db
,
DATABASE_TYPE
);
String
dbGUID
=
repositoryService
.
createEntity
(
db
);
System
.
out
.
println
(
"added db = "
+
dbGUID
);
System
.
out
.
println
(
"added db = "
+
dbGUID
);
Referenceable
dbInstance
=
new
Referenceable
(
Referenceable
dbInstance
=
new
Referenceable
(
dbGUID
,
DATABASE_TYPE
,
databaseInstance
.
getValuesMap
());
dbGUID
,
DATABASE_TYPE
,
databaseInstance
.
getValuesMap
());
ITypedReferenceableInstance
table
=
createHiveTableInstance
(
dbInstance
);
ITypedReferenceableInstance
table
=
createHiveTableInstance
(
dbInstance
);
String
tableGUID
=
repositoryService
.
createEntity
(
table
,
TABLE_TYPE
);
String
tableGUID
=
repositoryService
.
createEntity
(
table
);
System
.
out
.
println
(
"added table = "
+
tableGUID
);
System
.
out
.
println
(
"added table = "
+
tableGUID
);
}
}
...
...
repository/src/test/java/org/apache/hadoop/metadata/repository/graph/GraphRepoMapperScaleTest.java
View file @
e747e2ae
...
@@ -89,14 +89,14 @@ public class GraphRepoMapperScaleTest {
...
@@ -89,14 +89,14 @@ public class GraphRepoMapperScaleTest {
ClassType
dbType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
DATABASE_TYPE
);
ClassType
dbType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
DATABASE_TYPE
);
ITypedReferenceableInstance
db
=
dbType
.
convert
(
databaseInstance
,
Multiplicity
.
REQUIRED
);
ITypedReferenceableInstance
db
=
dbType
.
convert
(
databaseInstance
,
Multiplicity
.
REQUIRED
);
dbGUID
=
repositoryService
.
createEntity
(
db
,
DATABASE_TYPE
);
dbGUID
=
repositoryService
.
createEntity
(
db
);
Referenceable
dbInstance
=
new
Referenceable
(
Referenceable
dbInstance
=
new
Referenceable
(
dbGUID
,
DATABASE_TYPE
,
databaseInstance
.
getValuesMap
());
dbGUID
,
DATABASE_TYPE
,
databaseInstance
.
getValuesMap
());
for
(
int
index
=
0
;
index
<
1000
;
index
++)
{
for
(
int
index
=
0
;
index
<
1000
;
index
++)
{
ITypedReferenceableInstance
table
=
createHiveTableInstance
(
dbInstance
,
index
);
ITypedReferenceableInstance
table
=
createHiveTableInstance
(
dbInstance
,
index
);
repositoryService
.
createEntity
(
table
,
TABLE_TYPE
);
repositoryService
.
createEntity
(
table
);
}
}
}
}
...
...
webapp/src/main/java/org/apache/hadoop/metadata/web/resources/EntityResource.java
View file @
e747e2ae
...
@@ -78,31 +78,28 @@ public class EntityResource {
...
@@ -78,31 +78,28 @@ public class EntityResource {
/**
/**
* Submits an entity definition (instance) corresponding to a given type.
* Submits an entity definition (instance) corresponding to a given type.
*
* @param typeName name of a type which is unique.
*/
*/
@POST
@POST
@Path
(
"submit
/{typeName}
"
)
@Path
(
"submit"
)
@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
(
"typeName"
)
final
String
typeName
)
{
try
{
try
{
final
String
entity
=
Servlets
.
getRequestPayload
(
request
);
final
String
entity
=
Servlets
.
getRequestPayload
(
request
);
LOG
.
debug
(
"submitting entity {} "
,
entity
);
LOG
.
debug
(
"submitting entity {} "
,
entity
);
final
String
guid
=
metadataService
.
createEntity
(
typeName
,
entity
);
final
String
guid
=
metadataService
.
createEntity
(
entity
);
JSONObject
response
=
new
JSONObject
();
JSONObject
response
=
new
JSONObject
();
response
.
put
(
MetadataServiceClient
.
REQUEST_ID
,
Servlets
.
getRequestId
());
response
.
put
(
MetadataServiceClient
.
REQUEST_ID
,
Servlets
.
getRequestId
());
response
.
put
(
MetadataServiceClient
.
RESULTS
,
guid
);
response
.
put
(
MetadataServiceClient
.
RESULTS
,
guid
);
return
Response
.
ok
(
response
).
build
();
return
Response
.
ok
(
response
).
build
();
}
catch
(
MetadataException
|
IOException
|
IllegalArgumentException
e
)
{
}
catch
(
MetadataException
|
IOException
|
IllegalArgumentException
e
)
{
LOG
.
error
(
"Unable to persist
instance for type {}"
,
typeName
,
e
);
LOG
.
error
(
"Unable to persist
entity instance"
,
e
);
throw
new
WebApplicationException
(
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
BAD_REQUEST
));
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
BAD_REQUEST
));
}
catch
(
JSONException
e
)
{
}
catch
(
JSONException
e
)
{
LOG
.
error
(
"Unable to persist
instance for type {}"
,
typeName
,
e
);
LOG
.
error
(
"Unable to persist
entity instance"
,
e
);
throw
new
WebApplicationException
(
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
INTERNAL_SERVER_ERROR
));
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
INTERNAL_SERVER_ERROR
));
}
}
...
@@ -193,12 +190,13 @@ public class EntityResource {
...
@@ -193,12 +190,13 @@ public class EntityResource {
* @param guid entity id
* @param guid entity id
* @param property property to add
* @param property property to add
* @param value property's value
* @param value property's value
* @return
* @return
response payload as json
*/
*/
@PUT
@PUT
@Path
(
"update/{guid}"
)
@Path
(
"update/{guid}"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Response
update
(
@PathParam
(
"guid"
)
String
guid
,
@QueryParam
(
"property"
)
String
property
,
public
Response
update
(
@PathParam
(
"guid"
)
String
guid
,
@QueryParam
(
"property"
)
String
property
,
@QueryParam
(
"value"
)
String
value
)
{
@QueryParam
(
"value"
)
String
value
)
{
try
{
try
{
metadataService
.
updateEntity
(
guid
,
property
,
value
);
metadataService
.
updateEntity
(
guid
,
property
,
value
);
...
...
webapp/src/test/java/org/apache/hadoop/metadata/web/resources/BaseResourceIT.java
View file @
e747e2ae
...
@@ -23,27 +23,28 @@ import com.sun.jersey.api.client.ClientResponse;
...
@@ -23,27 +23,28 @@ import com.sun.jersey.api.client.ClientResponse;
import
com.sun.jersey.api.client.WebResource
;
import
com.sun.jersey.api.client.WebResource
;
import
com.sun.jersey.api.client.config.DefaultClientConfig
;
import
com.sun.jersey.api.client.config.DefaultClientConfig
;
import
org.apache.hadoop.metadata.MetadataServiceClient
;
import
org.apache.hadoop.metadata.MetadataServiceClient
;
import
org.apache.hadoop.metadata.typesystem.types.TypeSystem
;
import
org.apache.hadoop.metadata.typesystem.Referenceable
;
import
org.apache.hadoop.metadata.web.util.Servlets
;
import
org.apache.hadoop.metadata.typesystem.TypesDef
;
import
org.apache.hadoop.metadata.typesystem.json.InstanceSerialization
;
import
org.apache.hadoop.metadata.typesystem.json.TypesSerialization
;
import
org.codehaus.jettison.json.JSONObject
;
import
org.codehaus.jettison.json.JSONObject
;
import
org.testng.Assert
;
import
org.testng.Assert
;
import
org.testng.annotations.BeforeClass
;
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
javax.ws.rs.core.UriBuilder
;
import
javax.ws.rs.core.UriBuilder
;
/**
* Base class for integration tests.
* Sets up the web resource and has helper methods to create type and entity.
*/
public
abstract
class
BaseResourceIT
{
public
abstract
class
BaseResourceIT
{
protected
TypeSystem
typeSystem
;
protected
WebResource
service
;
protected
WebResource
service
;
protected
MetadataServiceClient
serviceClient
;
protected
MetadataServiceClient
serviceClient
;
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
();
...
@@ -54,10 +55,15 @@ public abstract class BaseResourceIT {
...
@@ -54,10 +55,15 @@ public abstract class BaseResourceIT {
serviceClient
=
new
MetadataServiceClient
(
baseUrl
);
serviceClient
=
new
MetadataServiceClient
(
baseUrl
);
}
}
protected
void
sumbitType
(
String
typesAsJSON
,
String
type
)
throws
Exception
{
protected
void
createType
(
TypesDef
typesDef
)
throws
Exception
{
String
typesAsJSON
=
TypesSerialization
.
toJson
(
typesDef
);
createType
(
typesAsJSON
,
"removeme"
);
}
protected
void
createType
(
String
typesAsJSON
,
String
typeName
)
throws
Exception
{
WebResource
resource
=
service
WebResource
resource
=
service
.
path
(
"api/metadata/types/submit"
)
.
path
(
"api/metadata/types/submit"
)
.
path
(
type
);
.
path
(
type
Name
);
ClientResponse
clientResponse
=
resource
ClientResponse
clientResponse
=
resource
.
accept
(
MediaType
.
APPLICATION_JSON
)
.
accept
(
MediaType
.
APPLICATION_JSON
)
...
@@ -69,8 +75,22 @@ public abstract class BaseResourceIT {
...
@@ -69,8 +75,22 @@ public abstract class BaseResourceIT {
Assert
.
assertNotNull
(
responseAsString
);
Assert
.
assertNotNull
(
responseAsString
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertEquals
(
response
.
get
(
"typeName"
),
type
);
Assert
.
assertEquals
(
response
.
get
(
"typeName"
),
type
Name
);
Assert
.
assertNotNull
(
response
.
get
(
"types"
));
Assert
.
assertNotNull
(
response
.
get
(
"types"
));
Assert
.
assertNotNull
(
response
.
get
(
MetadataServiceClient
.
REQUEST_ID
));
Assert
.
assertNotNull
(
response
.
get
(
MetadataServiceClient
.
REQUEST_ID
));
}
}
protected
Referenceable
createInstance
(
Referenceable
referenceable
)
throws
Exception
{
String
typeName
=
referenceable
.
getTypeName
();
System
.
out
.
println
(
"creating instance of type "
+
typeName
);
String
entityJSON
=
InstanceSerialization
.
toJson
(
referenceable
,
true
);
System
.
out
.
println
(
"Submitting new entity= "
+
entityJSON
);
JSONObject
jsonObject
=
serviceClient
.
createEntity
(
entityJSON
);
String
guid
=
jsonObject
.
getString
(
MetadataServiceClient
.
RESULTS
);
System
.
out
.
println
(
"created instance for type "
+
typeName
+
", guid: "
+
guid
);
// return the reference to created instance with guid
return
new
Referenceable
(
guid
,
referenceable
.
getTypeName
(),
referenceable
.
getValuesMap
());
}
}
}
webapp/src/test/java/org/apache/hadoop/metadata/web/resources/EntityJerseyResourceIT.java
View file @
e747e2ae
This diff is collapsed.
Click to expand it.
webapp/src/test/java/org/apache/hadoop/metadata/web/resources/MetadataDiscoveryResourceIT.java
→
webapp/src/test/java/org/apache/hadoop/metadata/web/resources/MetadataDiscovery
Jersey
ResourceIT.java
View file @
e747e2ae
This diff is collapsed.
Click to expand it.
webapp/src/test/java/org/apache/hadoop/metadata/web/resources/TypesJerseyResourceIT.java
View file @
e747e2ae
...
@@ -31,7 +31,6 @@ import org.apache.hadoop.metadata.typesystem.types.HierarchicalTypeDefinition;
...
@@ -31,7 +31,6 @@ import org.apache.hadoop.metadata.typesystem.types.HierarchicalTypeDefinition;
import
org.apache.hadoop.metadata.typesystem.types.Multiplicity
;
import
org.apache.hadoop.metadata.typesystem.types.Multiplicity
;
import
org.apache.hadoop.metadata.typesystem.types.TraitType
;
import
org.apache.hadoop.metadata.typesystem.types.TraitType
;
import
org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil
;
import
org.apache.hadoop.metadata.typesystem.types.utils.TypesUtil
;
import
org.apache.hadoop.metadata.web.util.Servlets
;
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
;
...
@@ -187,7 +186,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
...
@@ -187,7 +186,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
HierarchicalTypeDefinition
<
TraitType
>
traitTypeDef
=
HierarchicalTypeDefinition
<
TraitType
>
traitTypeDef
=
TypesUtil
.
createTraitTypeDef
(
traitName
,
ImmutableList
.<
String
>
of
());
TypesUtil
.
createTraitTypeDef
(
traitName
,
ImmutableList
.<
String
>
of
());
String
json
=
TypesSerialization
$
.
MODULE
$
.
toJson
(
traitTypeDef
,
true
);
String
json
=
TypesSerialization
$
.
MODULE
$
.
toJson
(
traitTypeDef
,
true
);
sumbit
Type
(
json
,
traitName
);
create
Type
(
json
,
traitName
);
}
}
return
traitNames
;
return
traitNames
;
...
...
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