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
4f928a8d
Commit
4f928a8d
authored
Mar 23, 2015
by
Venkatesh Seetharam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove type name from create type API
parent
a86f0f3e
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
21 additions
and
47 deletions
+21
-47
MetadataServiceClient.java
...ava/org/apache/hadoop/metadata/MetadataServiceClient.java
+2
-3
DefaultMetadataService.java
...ache/hadoop/metadata/services/DefaultMetadataService.java
+6
-20
MetadataService.java
.../org/apache/hadoop/metadata/services/MetadataService.java
+1
-3
TypesResource.java
...g/apache/hadoop/metadata/web/resources/TypesResource.java
+5
-9
BaseResourceIT.java
.../apache/hadoop/metadata/web/resources/BaseResourceIT.java
+3
-5
EntityJerseyResourceIT.java
...hadoop/metadata/web/resources/EntityJerseyResourceIT.java
+2
-2
TypesJerseyResourceIT.java
.../hadoop/metadata/web/resources/TypesJerseyResourceIT.java
+2
-5
No files found.
client/src/main/java/org/apache/hadoop/metadata/MetadataServiceClient.java
View file @
4f928a8d
...
...
@@ -87,9 +87,8 @@ public class MetadataServiceClient {
}
}
public
JSONObject
createType
(
String
typeName
,
String
typeAsJson
)
throws
MetadataServiceException
{
return
callAPI
(
API
.
CREATE_TYPE
,
typeAsJson
,
typeName
);
public
JSONObject
createType
(
String
typeAsJson
)
throws
MetadataServiceException
{
return
callAPI
(
API
.
CREATE_TYPE
,
typeAsJson
);
}
public
List
<
String
>
listTypes
()
throws
MetadataServiceException
{
...
...
repository/src/main/java/org/apache/hadoop/metadata/services/DefaultMetadataService.java
View file @
4f928a8d
...
...
@@ -81,15 +81,13 @@ public class DefaultMetadataService implements MetadataService {
* Creates a new type based on the type system to enable adding
* entities (instances for types).
*
* @param typeName name for this type, must be unique
* @param typeDefinition definition as json
* @return a unique id for this type
*/
@Override
public
JSONObject
createType
(
String
typeName
,
String
typeDefinition
)
throws
MetadataException
{
public
JSONObject
createType
(
String
typeDefinition
)
throws
MetadataException
{
try
{
validateTypeDoesNotExist
(
typeName
,
typeDefinition
);
Preconditions
.
checkNotNull
(
typeDefinition
,
"type definition cannot be null"
);
TypesDef
typesDef
=
TypesSerialization
.
fromJson
(
typeDefinition
);
Map
<
String
,
IDataType
>
typesAdded
=
typeSystem
.
defineTypes
(
typesDef
);
...
...
@@ -105,20 +103,8 @@ public class DefaultMetadataService implements MetadataService {
return
response
;
}
catch
(
JSONException
e
)
{
LOG
.
error
(
"Unable to persist type {}"
,
typeName
,
e
);
throw
new
MetadataException
(
"Unable to create response for: "
+
typeName
);
}
}
private
void
validateTypeDoesNotExist
(
String
typeName
,
String
typeDefinition
)
throws
MetadataException
{
Preconditions
.
checkNotNull
(
typeName
,
"type name cannot be null"
);
Preconditions
.
checkNotNull
(
typeDefinition
,
"type definition cannot be null"
);
// verify if the type already exists
if
(
typeSystem
.
isRegistered
(
typeName
))
{
LOG
.
error
(
"type is already defined for {}"
,
typeName
);
throw
new
MetadataException
(
"type is already defined for : "
+
typeName
);
LOG
.
error
(
"Unable to create response for types={}"
,
typeDefinition
,
e
);
throw
new
MetadataException
(
"Unable to create response"
);
}
}
...
...
@@ -186,7 +172,7 @@ public class DefaultMetadataService implements MetadataService {
ClassType
entityType
=
typeSystem
.
getDataType
(
ClassType
.
class
,
entityTypeName
);
return
entityType
.
convert
(
entityInstance
,
Multiplicity
.
REQUIRED
);
}
catch
(
Exception
e
)
{
throw
new
MetadataException
(
"Error deserializing
trait instance"
);
throw
new
MetadataException
(
"Error deserializing
class instance"
,
e
);
}
}
...
...
@@ -286,7 +272,7 @@ public class DefaultMetadataService implements MetadataService {
return
traitType
.
convert
(
traitInstance
,
Multiplicity
.
REQUIRED
);
}
catch
(
Exception
e
)
{
throw
new
MetadataException
(
"Error deserializing trait instance"
);
throw
new
MetadataException
(
"Error deserializing trait instance"
,
e
);
}
}
...
...
repository/src/main/java/org/apache/hadoop/metadata/services/MetadataService.java
View file @
4f928a8d
...
...
@@ -32,12 +32,10 @@ public interface MetadataService {
* Creates a new type based on the type system to enable adding
* entities (instances for types).
*
* @param typeName name for this type, must be unique
* @param typeDefinition definition as json
* @return a unique id for this type
*/
JSONObject
createType
(
String
typeName
,
String
typeDefinition
)
throws
MetadataException
;
JSONObject
createType
(
String
typeDefinition
)
throws
MetadataException
;
/**
* Return the definition for the given type.
...
...
webapp/src/main/java/org/apache/hadoop/metadata/web/resources/TypesResource.java
View file @
4f928a8d
...
...
@@ -67,29 +67,25 @@ public class TypesResource {
/**
* Submits a type definition corresponding to a given type representing a meta model of a
* domain. Could represent things like Hive Database, Hive Table, etc.
*
* @param typeName name of a type, should be unique.
*/
@POST
@Path
(
"submit
/{typeName}
"
)
@Path
(
"submit"
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Response
submit
(
@Context
HttpServletRequest
request
,
@PathParam
(
"typeName"
)
String
typeName
)
{
public
Response
submit
(
@Context
HttpServletRequest
request
)
{
try
{
final
String
typeDefinition
=
Servlets
.
getRequestPayload
(
request
);
LOG
.
debug
(
"creating type
{} with definition {} "
,
typeName
,
typeDefinition
);
LOG
.
debug
(
"creating type
with definition {} "
,
typeDefinition
);
JSONObject
typesAdded
=
metadataService
.
createType
(
type
Name
,
type
Definition
);
JSONObject
typesAdded
=
metadataService
.
createType
(
typeDefinition
);
JSONObject
response
=
new
JSONObject
();
response
.
put
(
"typeName"
,
typeName
);
response
.
put
(
"types"
,
typesAdded
);
response
.
put
(
MetadataServiceClient
.
REQUEST_ID
,
Servlets
.
getRequestId
());
return
Response
.
ok
(
response
).
build
();
}
catch
(
Exception
e
)
{
LOG
.
error
(
"Unable to persist type
{}"
,
typeName
,
e
);
LOG
.
error
(
"Unable to persist type
s"
,
e
);
throw
new
WebApplicationException
(
Servlets
.
getErrorResponse
(
e
,
Response
.
Status
.
BAD_REQUEST
));
}
...
...
webapp/src/test/java/org/apache/hadoop/metadata/web/resources/BaseResourceIT.java
View file @
4f928a8d
...
...
@@ -57,13 +57,12 @@ public abstract class BaseResourceIT {
protected
void
createType
(
TypesDef
typesDef
)
throws
Exception
{
String
typesAsJSON
=
TypesSerialization
.
toJson
(
typesDef
);
createType
(
typesAsJSON
,
"removeme"
);
createType
(
typesAsJSON
);
}
protected
void
createType
(
String
typesAsJSON
,
String
typeName
)
throws
Exception
{
protected
void
createType
(
String
typesAsJSON
)
throws
Exception
{
WebResource
resource
=
service
.
path
(
"api/metadata/types/submit"
)
.
path
(
typeName
);
.
path
(
"api/metadata/types/submit"
);
ClientResponse
clientResponse
=
resource
.
accept
(
MediaType
.
APPLICATION_JSON
)
...
...
@@ -75,7 +74,6 @@ public abstract class BaseResourceIT {
Assert
.
assertNotNull
(
responseAsString
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertEquals
(
response
.
get
(
"typeName"
),
typeName
);
Assert
.
assertNotNull
(
response
.
get
(
"types"
));
Assert
.
assertNotNull
(
response
.
get
(
MetadataServiceClient
.
REQUEST_ID
));
}
...
...
webapp/src/test/java/org/apache/hadoop/metadata/web/resources/EntityJerseyResourceIT.java
View file @
4f928a8d
...
...
@@ -269,7 +269,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
TypesUtil
.
createRequiredAttrDef
(
"description"
,
DataTypes
.
STRING_TYPE
));
String
typesAsJSON
=
TypesSerialization
.
toJson
(
testTypeDefinition
);
createType
(
typesAsJSON
,
"test"
);
createType
(
typesAsJSON
);
}
@Test
(
dependsOnMethods
=
"testSubmitEntity"
)
...
...
@@ -301,7 +301,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
TypesUtil
.
createTraitTypeDef
(
traitName
,
ImmutableList
.<
String
>
of
());
String
traitDefinitionAsJSON
=
TypesSerialization
$
.
MODULE
$
.
toJson
(
piiTrait
,
true
);
LOG
.
debug
(
"traitDefinitionAsJSON = "
+
traitDefinitionAsJSON
);
createType
(
traitDefinitionAsJSON
,
traitName
);
createType
(
traitDefinitionAsJSON
);
Struct
traitInstance
=
new
Struct
(
traitName
);
String
traitInstanceAsJSON
=
InstanceSerialization
.
toJson
(
traitInstance
,
true
);
...
...
webapp/src/test/java/org/apache/hadoop/metadata/web/resources/TypesJerseyResourceIT.java
View file @
4f928a8d
...
...
@@ -70,8 +70,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
System
.
out
.
println
(
"typesAsJSON = "
+
typesAsJSON
);
WebResource
resource
=
service
.
path
(
"api/metadata/types/submit"
)
.
path
(
typeDefinition
.
typeName
);
.
path
(
"api/metadata/types/submit"
);
ClientResponse
clientResponse
=
resource
.
accept
(
MediaType
.
APPLICATION_JSON
)
...
...
@@ -83,7 +82,6 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
Assert
.
assertNotNull
(
responseAsString
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertEquals
(
response
.
get
(
"typeName"
),
typeDefinition
.
typeName
);
Assert
.
assertNotNull
(
response
.
get
(
"types"
));
Assert
.
assertNotNull
(
response
.
get
(
MetadataServiceClient
.
REQUEST_ID
));
}
...
...
@@ -108,7 +106,6 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
Assert
.
assertNotNull
(
responseAsString
);
JSONObject
response
=
new
JSONObject
(
responseAsString
);
Assert
.
assertEquals
(
response
.
get
(
"typeName"
),
typeDefinition
.
typeName
);
Assert
.
assertNotNull
(
response
.
get
(
"definition"
));
Assert
.
assertNotNull
(
response
.
get
(
MetadataServiceClient
.
REQUEST_ID
));
}
...
...
@@ -186,7 +183,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
HierarchicalTypeDefinition
<
TraitType
>
traitTypeDef
=
TypesUtil
.
createTraitTypeDef
(
traitName
,
ImmutableList
.<
String
>
of
());
String
json
=
TypesSerialization
$
.
MODULE
$
.
toJson
(
traitTypeDef
,
true
);
createType
(
json
,
traitName
);
createType
(
json
);
}
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