Commit bbc46662 by Suma Shivaprasad

BUG_36056 - Fixed first set of issues in ITs

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