Commit 7d929407 by Suma Shivaprasad

Fixed all issues in ITs

parent cb5f3d40
......@@ -53,30 +53,34 @@ public class MetadataServiceClient {
}
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 {
//Type operations
CREATE_TYPE(BASE_URI + "types", HttpMethod.POST),
GET_TYPE(BASE_URI + "types", HttpMethod.GET),
LIST_TYPES(BASE_URI + "types", HttpMethod.GET),
LIST_TRAIT_TYPES(BASE_URI + "types?type=trait", HttpMethod.GET),
CREATE_TYPE(BASE_URI + URI_TYPES, HttpMethod.POST),
GET_TYPE(BASE_URI + URI_TYPES, HttpMethod.GET),
LIST_TYPES(BASE_URI + URI_TYPES, HttpMethod.GET),
LIST_TRAIT_TYPES(BASE_URI + URI_TYPES + "?type=trait", HttpMethod.GET),
//Entity operations
CREATE_ENTITY(BASE_URI + "entities", HttpMethod.POST),
GET_ENTITY(BASE_URI + "entities", HttpMethod.GET),
UPDATE_ENTITY(BASE_URI + "entities", HttpMethod.PUT),
LIST_ENTITY(BASE_URI + "entities", HttpMethod.GET),
CREATE_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.POST),
GET_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.GET),
UPDATE_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.PUT),
LIST_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.GET),
//Trait operations
ADD_TRAITS(BASE_URI + "traits", HttpMethod.POST),
DELETE_TRAITS(BASE_URI + "traits", HttpMethod.DELETE),
LIST_TRAITS(BASE_URI + "traits", HttpMethod.GET),
ADD_TRAITS(BASE_URI + URI_TRAITS, HttpMethod.POST),
DELETE_TRAITS(BASE_URI + URI_TRAITS, HttpMethod.DELETE),
LIST_TRAITS(BASE_URI + URI_TRAITS, HttpMethod.GET),
//Search operations
SEARCH(BASE_URI + "discovery/search", HttpMethod.GET),
SEARCH_DSL(BASE_URI + "discovery/search/dsl", HttpMethod.GET),
SEARCH_GREMLIN(BASE_URI + "discovery/search/gremlin", HttpMethod.GET),
SEARCH_FULL_TEXT(BASE_URI + "discovery/search/fulltext", HttpMethod.GET);
SEARCH(BASE_URI + URI_SEARCH, HttpMethod.GET),
SEARCH_DSL(BASE_URI + URI_SEARCH + "/dsl", HttpMethod.GET),
SEARCH_GREMLIN(BASE_URI + URI_SEARCH + "/gremlin", HttpMethod.GET),
SEARCH_FULL_TEXT(BASE_URI + URI_SEARCH + "/fulltext", HttpMethod.GET);
private final String method;
private final String path;
......
......@@ -22,6 +22,7 @@ import com.google.common.base.Preconditions;
import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.MetadataServiceClient;
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.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
......@@ -55,9 +56,6 @@ public class TypesResource {
private final MetadataService metadataService;
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
public TypesResource(MetadataService metadataService) {
......@@ -129,20 +127,11 @@ public class TypesResource {
@DefaultValue(TYPE_ALL) @QueryParam("type") String type) {
try {
List<String> result = null;
switch(type) {
case TYPE_ALL :
result = metadataService.getTypeNamesList();
break;
case TYPE_TRAIT :
result = metadataService.getTraitNamesList();
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));
if (TYPE_ALL.equals(type)) {
result = metadataService.getTypeNamesList();
} else {
DataTypes.TypeCategory typeCategory = DataTypes.TypeCategory.valueOf(type);
result = metadataService.getTypeNamesByCategory(typeCategory);
}
JSONObject response = new JSONObject();
......@@ -151,6 +140,10 @@ public class TypesResource {
response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
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) {
LOG.error("Unable to get types list", e);
throw new WebApplicationException(
......
......@@ -66,6 +66,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
private static final String DATABASE_NAME = "foo";
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;
......@@ -270,7 +272,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service
.path("api/metadata/entities")
.path(guid)
.path(EntityResource.TRAITS)
.path(TRAITS)
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(HttpMethod.GET, ClientResponse.class);
......@@ -304,7 +306,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service
.path("api/metadata/entities")
.path(guid)
.path(EntityResource.TRAITS)
.path(TRAITS)
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
......@@ -334,7 +336,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service
.path("api/metadata/entities")
.path("random")
.path(EntityResource.TRAITS)
.path(TRAITS)
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
......@@ -350,7 +352,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service
.path("api/metadata/entities")
.path(guid)
.path(EntityResource.TRAIT)
.path(TRAIT)
.path(traitName)
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
......@@ -373,7 +375,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service
.path("api/metadata/entities")
.path("random")
.path(EntityResource.TRAIT)
.path(TRAIT)
.path(traitName)
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
......
......@@ -153,7 +153,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
.path("api/metadata/types");
ClientResponse clientResponse = resource
.queryParam("type", TypesResource.TYPE_TRAIT)
.queryParam("type", DataTypes.TypeCategory.TRAIT.name())
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.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