Commit bbc46662 by Suma Shivaprasad

BUG_36056 - Fixed first set of issues in ITs

parent d7807410
......@@ -53,6 +53,8 @@ public class EntityResource {
private static final String GUID = "GUID";
private static final String TRAIT_NAME = "traitName";
static final String TRAITS = "traits";
static final String TRAIT = "trait";
private final MetadataService metadataService;
......@@ -281,7 +283,7 @@ public class EntityResource {
* @param traitName name of the trait
*/
@DELETE
@Path("{guid}/traits/{traitName}")
@Path("{guid}/trait/{traitName}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response deleteTrait(@Context HttpServletRequest request,
......@@ -301,11 +303,11 @@ public class EntityResource {
return Response.ok(response).build();
} catch (MetadataException | IllegalArgumentException e) {
LOG.error("Unable to add trait name={} for entity={}", traitName, guid, e);
LOG.error("Unable to delete trait name={} for entity={}", traitName, guid, e);
throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
} catch (JSONException e) {
LOG.error("Unable to add trait name={} for entity={}", traitName, guid, e);
LOG.error("Unable to delete trait name={} for entity={}", traitName, guid, e);
throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
}
......
......@@ -31,12 +31,7 @@ import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
......@@ -108,6 +103,7 @@ public class HiveLineageResource {
@Produces(MediaType.APPLICATION_JSON)
public Response outputs(@Context HttpServletRequest request,
@PathParam("tableName") String tableName) {
Preconditions.checkNotNull(tableName, "table name cannot be null");
LOG.info("Fetching lineage outputs for tableName={}", tableName);
......@@ -142,6 +138,7 @@ public class HiveLineageResource {
@Produces(MediaType.APPLICATION_JSON)
public Response schema(@Context HttpServletRequest request,
@PathParam("tableName") String tableName) {
Preconditions.checkNotNull(tableName, "table name cannot be null");
LOG.info("Fetching schema for tableName={}", tableName);
......
......@@ -54,9 +54,10 @@ public class TypesResource {
private final MetadataService metadataService;
static final String TRAIT = "trait";
static final String CLASS = "class";
static final String STRUCT = "struct";
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) {
......@@ -120,44 +121,28 @@ public class TypesResource {
}
/**
* Gets the list of type names registered in the type system.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getTypeNames(@Context HttpServletRequest request) {
try {
final List<String> typeNamesList = metadataService.getTypeNamesList();
JSONObject response = new JSONObject();
response.put(MetadataServiceClient.RESULTS, new JSONArray(typeNamesList));
response.put(MetadataServiceClient.TOTAL_SIZE, typeNamesList.size());
response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
return Response.ok(response).build();
} catch (Exception e) {
LOG.error("Unable to get types list", e);
throw new WebApplicationException(
Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
}
}
/**
* Gets the list of trait type names registered in the type system.
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getTypesByFilter(@Context HttpServletRequest request,
@DefaultValue(TRAIT) @QueryParam("type") String type) {
@DefaultValue(TYPE_ALL) @QueryParam("type") String type) {
try {
Preconditions.checkNotNull(type, "type cannot be null");
List<String> result = null;
switch(type) {
case TRAIT :
case TYPE_ALL :
result = metadataService.getTypeNamesList();
break;
case TYPE_TRAIT :
result = metadataService.getTraitNamesList();
case STRUCT :
case CLASS :
//TBD for ÇLASS, STRUCT
throw new UnsupportedOperationException("Unsupported operation on " + type);
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();
......
......@@ -65,7 +65,7 @@ public abstract class BaseResourceIT {
protected void createType(String typesAsJSON) throws Exception {
WebResource resource = service
.path("api/metadata/types/submit");
.path("api/metadata/types");
ClientResponse clientResponse = resource
.accept(MediaType.APPLICATION_JSON)
......
......@@ -268,7 +268,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service
.path("api/metadata/entities")
.path(guid)
.path("traits")
.path(EntityResource.TRAITS)
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(HttpMethod.GET, ClientResponse.class);
......@@ -302,7 +302,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service
.path("api/metadata/entities")
.path(guid)
.path("traits")
.path(EntityResource.TRAITS)
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
......@@ -332,7 +332,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service
.path("api/metadata/entities")
.path("random")
.path("traits")
.path(EntityResource.TRAITS)
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(HttpMethod.POST, ClientResponse.class, traitInstanceAsJSON);
......@@ -348,7 +348,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service
.path("api/metadata/entities")
.path(guid)
.path("traits")
.path(EntityResource.TRAIT)
.path(traitName)
.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
......@@ -371,7 +371,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClientResponse clientResponse = service
.path("api/metadata/entities")
.path("random")
.path("traits")
.path(EntityResource.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.TRAIT)
.queryParam("type", TypesResource.TYPE_TRAIT)
.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