Commit 7d929407 by Suma Shivaprasad

Fixed all issues in ITs

parent cb5f3d40
...@@ -53,30 +53,34 @@ public class MetadataServiceClient { ...@@ -53,30 +53,34 @@ public class MetadataServiceClient {
} }
private static final String BASE_URI = "api/metadata/"; private static final String BASE_URI = "api/metadata/";
private static final String URI_TYPES = "types";
private static final String URI_ENTITIES = "entities";
private static final String URI_TRAITS = "traits";
private static final String URI_SEARCH = "discovery/search";
static enum API { static enum API {
//Type operations //Type operations
CREATE_TYPE(BASE_URI + "types", HttpMethod.POST), CREATE_TYPE(BASE_URI + URI_TYPES, HttpMethod.POST),
GET_TYPE(BASE_URI + "types", HttpMethod.GET), GET_TYPE(BASE_URI + URI_TYPES, HttpMethod.GET),
LIST_TYPES(BASE_URI + "types", HttpMethod.GET), LIST_TYPES(BASE_URI + URI_TYPES, HttpMethod.GET),
LIST_TRAIT_TYPES(BASE_URI + "types?type=trait", HttpMethod.GET), LIST_TRAIT_TYPES(BASE_URI + URI_TYPES + "?type=trait", HttpMethod.GET),
//Entity operations //Entity operations
CREATE_ENTITY(BASE_URI + "entities", HttpMethod.POST), CREATE_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.POST),
GET_ENTITY(BASE_URI + "entities", HttpMethod.GET), GET_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.GET),
UPDATE_ENTITY(BASE_URI + "entities", HttpMethod.PUT), UPDATE_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.PUT),
LIST_ENTITY(BASE_URI + "entities", HttpMethod.GET), LIST_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.GET),
//Trait operations //Trait operations
ADD_TRAITS(BASE_URI + "traits", HttpMethod.POST), ADD_TRAITS(BASE_URI + URI_TRAITS, HttpMethod.POST),
DELETE_TRAITS(BASE_URI + "traits", HttpMethod.DELETE), DELETE_TRAITS(BASE_URI + URI_TRAITS, HttpMethod.DELETE),
LIST_TRAITS(BASE_URI + "traits", HttpMethod.GET), LIST_TRAITS(BASE_URI + URI_TRAITS, HttpMethod.GET),
//Search operations //Search operations
SEARCH(BASE_URI + "discovery/search", HttpMethod.GET), SEARCH(BASE_URI + URI_SEARCH, HttpMethod.GET),
SEARCH_DSL(BASE_URI + "discovery/search/dsl", HttpMethod.GET), SEARCH_DSL(BASE_URI + URI_SEARCH + "/dsl", HttpMethod.GET),
SEARCH_GREMLIN(BASE_URI + "discovery/search/gremlin", HttpMethod.GET), SEARCH_GREMLIN(BASE_URI + URI_SEARCH + "/gremlin", HttpMethod.GET),
SEARCH_FULL_TEXT(BASE_URI + "discovery/search/fulltext", HttpMethod.GET); SEARCH_FULL_TEXT(BASE_URI + URI_SEARCH + "/fulltext", HttpMethod.GET);
private final String method; private final String method;
private final String path; private final String path;
......
...@@ -22,6 +22,7 @@ import com.google.common.base.Preconditions; ...@@ -22,6 +22,7 @@ import com.google.common.base.Preconditions;
import org.apache.hadoop.metadata.MetadataException; import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.MetadataServiceClient; import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.services.MetadataService; import org.apache.hadoop.metadata.services.MetadataService;
import org.apache.hadoop.metadata.typesystem.types.DataTypes;
import org.apache.hadoop.metadata.web.util.Servlets; 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.JSONException; import org.codehaus.jettison.json.JSONException;
...@@ -55,9 +56,6 @@ public class TypesResource { ...@@ -55,9 +56,6 @@ public class TypesResource {
private final MetadataService metadataService; private final MetadataService metadataService;
static final String TYPE_ALL = "all"; static final String TYPE_ALL = "all";
static final String TYPE_TRAIT = "trait";
static final String TYPE_CLASS = "class";
static final String TYPE_STRUCT = "struct";
@Inject @Inject
public TypesResource(MetadataService metadataService) { public TypesResource(MetadataService metadataService) {
...@@ -129,20 +127,11 @@ public class TypesResource { ...@@ -129,20 +127,11 @@ public class TypesResource {
@DefaultValue(TYPE_ALL) @QueryParam("type") String type) { @DefaultValue(TYPE_ALL) @QueryParam("type") String type) {
try { try {
List<String> result = null; List<String> result = null;
switch(type) { if (TYPE_ALL.equals(type)) {
case TYPE_ALL :
result = metadataService.getTypeNamesList(); result = metadataService.getTypeNamesList();
break; } else {
case TYPE_TRAIT : DataTypes.TypeCategory typeCategory = DataTypes.TypeCategory.valueOf(type);
result = metadataService.getTraitNamesList(); result = metadataService.getTypeNamesByCategory(typeCategory);
break;
case TYPE_STRUCT :
case TYPE_CLASS :
//TODO for ÇLASS, STRUCT
default:
LOG.error("Unsupported typeName while retrieving type list {}", type);
throw new WebApplicationException(
Servlets.getErrorResponse("Unsupported type " + type, Response.Status.BAD_REQUEST));
} }
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
...@@ -151,6 +140,10 @@ public class TypesResource { ...@@ -151,6 +140,10 @@ public class TypesResource {
response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
return Response.ok(response).build(); return Response.ok(response).build();
} catch(IllegalArgumentException ie) {
LOG.error("Unsupported typeName while retrieving type list {}", type);
throw new WebApplicationException(
Servlets.getErrorResponse("Unsupported type " + type, Response.Status.BAD_REQUEST));
} catch (Exception e) { } catch (Exception e) {
LOG.error("Unable to get types list", e); LOG.error("Unable to get types list", e);
throw new WebApplicationException( throw new WebApplicationException(
......
...@@ -66,6 +66,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -66,6 +66,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
private static final String DATABASE_NAME = "foo"; private static final String DATABASE_NAME = "foo";
private static final String TABLE_TYPE = "hive_table_type"; private static final String TABLE_TYPE = "hive_table_type";
private static final String TABLE_NAME = "bar"; private static final String TABLE_NAME = "bar";
private static final String TRAITS = "traits";
private static final String TRAIT = "trait";
private Referenceable tableInstance; private Referenceable tableInstance;
private Id tableId; private Id tableId;
...@@ -270,7 +272,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -270,7 +272,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities") .path("api/metadata/entities")
.path(guid) .path(guid)
.path(EntityResource.TRAITS) .path(TRAITS)
.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);
...@@ -304,7 +306,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -304,7 +306,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities") .path("api/metadata/entities")
.path(guid) .path(guid)
.path(EntityResource.TRAITS) .path(TRAITS)
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
.method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON); .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
...@@ -334,7 +336,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -334,7 +336,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities") .path("api/metadata/entities")
.path("random") .path("random")
.path(EntityResource.TRAITS) .path(TRAITS)
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
.method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON); .method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
...@@ -350,7 +352,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -350,7 +352,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities") .path("api/metadata/entities")
.path(guid) .path(guid)
.path(EntityResource.TRAIT) .path(TRAIT)
.path(traitName) .path(traitName)
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
...@@ -373,7 +375,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -373,7 +375,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities") .path("api/metadata/entities")
.path("random") .path("random")
.path(EntityResource.TRAIT) .path(TRAIT)
.path(traitName) .path(traitName)
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
......
...@@ -153,7 +153,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -153,7 +153,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
.path("api/metadata/types"); .path("api/metadata/types");
ClientResponse clientResponse = resource ClientResponse clientResponse = resource
.queryParam("type", TypesResource.TYPE_TRAIT) .queryParam("type", DataTypes.TypeCategory.TRAIT.name())
.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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment