Commit f4547da3 by Suma S

Merge pull request #89 from sumashivaprasad/BUG_36056

Bug 36056 Fixed
parents 4dbe5820 6a9193c7
...@@ -87,11 +87,11 @@ c. Using DGI ...@@ -87,11 +87,11 @@ c. Using DGI
{"Version":"v0.1"} {"Version":"v0.1"}
* List the types in the repository * List the types in the repository
curl -v http://localhost:21000/api/metadata/types/list curl -v http://localhost:21000/api/metadata/types
{"list":["biginteger","short","byte","int","string","bigdecimal","boolean","date","double","long","float"],"requestId":"902580786@qtp-1479771328-0"} {"list":["biginteger","short","byte","int","string","bigdecimal","boolean","date","double","long","float"],"requestId":"902580786@qtp-1479771328-0"}
* List the instances for a given type * List the instances for a given type
curl -v http://localhost:21000/api/metadata/entities/list/hive_table curl -v http://localhost:21000/api/metadata/entities?type=hive_table
{"requestId":"788558007@qtp-44808654-5","list":["cb9b5513-c672-42cb-8477-b8f3e537a162","ec985719-a794-4c98-b98f-0509bd23aac0","48998f81-f1d3-45a2-989a-223af5c1ed6e","a54b386e-c759-4651-8779-a099294244c4"]} {"requestId":"788558007@qtp-44808654-5","list":["cb9b5513-c672-42cb-8477-b8f3e537a162","ec985719-a794-4c98-b98f-0509bd23aac0","48998f81-f1d3-45a2-989a-223af5c1ed6e","a54b386e-c759-4651-8779-a099294244c4"]}
curl -v http://localhost:21000/api/metadata/entities/list/hive_db curl -v http://localhost:21000/api/metadata/entities/list/hive_db
......
...@@ -52,7 +52,11 @@ public class MetadataServiceClient { ...@@ -52,7 +52,11 @@ public class MetadataServiceClient {
public static final String REQUEST_ID = "requestId"; public static final String REQUEST_ID = "requestId";
public static final String RESULTS = "results"; public static final String RESULTS = "results";
public static final String TOTAL_SIZE = "totalSize"; public static final String TOTAL_SIZE = "totalSize";
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";
private WebResource service; private WebResource service;
...@@ -83,27 +87,27 @@ public class MetadataServiceClient { ...@@ -83,27 +87,27 @@ public class MetadataServiceClient {
static enum API { static enum API {
//Type operations //Type operations
CREATE_TYPE("api/metadata/types/submit", HttpMethod.POST), CREATE_TYPE(BASE_URI + URI_TYPES, HttpMethod.POST),
GET_TYPE("api/metadata/types/definition", HttpMethod.GET), GET_TYPE(BASE_URI + URI_TYPES, HttpMethod.GET),
LIST_TYPES("api/metadata/types/list", HttpMethod.GET), LIST_TYPES(BASE_URI + URI_TYPES, HttpMethod.GET),
LIST_TRAIT_TYPES("api/metadata/types/traits/list", HttpMethod.GET), LIST_TRAIT_TYPES(BASE_URI + URI_TYPES + "?type=trait", HttpMethod.GET),
//Entity operations //Entity operations
CREATE_ENTITY("api/metadata/entities/submit", HttpMethod.POST), CREATE_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.POST),
GET_ENTITY("api/metadata/entities/definition", HttpMethod.GET), GET_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.GET),
UPDATE_ENTITY("api/metadata/entities/update", HttpMethod.PUT), UPDATE_ENTITY(BASE_URI + URI_ENTITIES, HttpMethod.PUT),
LIST_ENTITY("api/metadata/entities/list", HttpMethod.GET), LIST_ENTITY(BASE_URI + URI_ENTITIES + "?type=", HttpMethod.GET),
//Trait operations //Trait operations
ADD_TRAITS("api/metadata/traits/add", HttpMethod.POST), ADD_TRAITS(BASE_URI + URI_TRAITS, HttpMethod.POST),
DELETE_TRAITS("api/metadata/traits/delete", HttpMethod.PUT), DELETE_TRAITS(BASE_URI + URI_TRAITS, HttpMethod.DELETE),
LIST_TRAITS("api/metadata/traits/list", HttpMethod.GET), LIST_TRAITS(BASE_URI + URI_TRAITS, HttpMethod.GET),
//Search operations //Search operations
SEARCH("api/metadata/discovery/search", HttpMethod.GET), SEARCH(BASE_URI + URI_SEARCH, HttpMethod.GET),
SEARCH_DSL("api/metadata/discovery/search/dsl", HttpMethod.GET), SEARCH_DSL(BASE_URI + URI_SEARCH + "/dsl", HttpMethod.GET),
SEARCH_GREMLIN("api/metadata/discovery/search/gremlin", HttpMethod.GET), SEARCH_GREMLIN(BASE_URI + URI_SEARCH + "/gremlin", HttpMethod.GET),
SEARCH_FULL_TEXT("api/metadata/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;
......
...@@ -34,11 +34,7 @@ import org.apache.hadoop.metadata.typesystem.TypesDef; ...@@ -34,11 +34,7 @@ import org.apache.hadoop.metadata.typesystem.TypesDef;
import org.apache.hadoop.metadata.typesystem.json.InstanceSerialization; import org.apache.hadoop.metadata.typesystem.json.InstanceSerialization;
import org.apache.hadoop.metadata.typesystem.json.Serialization$; import org.apache.hadoop.metadata.typesystem.json.Serialization$;
import org.apache.hadoop.metadata.typesystem.json.TypesSerialization; import org.apache.hadoop.metadata.typesystem.json.TypesSerialization;
import org.apache.hadoop.metadata.typesystem.types.ClassType; import org.apache.hadoop.metadata.typesystem.types.*;
import org.apache.hadoop.metadata.typesystem.types.IDataType;
import org.apache.hadoop.metadata.typesystem.types.Multiplicity;
import org.apache.hadoop.metadata.typesystem.types.TraitType;
import org.apache.hadoop.metadata.typesystem.types.TypeSystem;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -144,8 +140,8 @@ public class DefaultMetadataService implements MetadataService { ...@@ -144,8 +140,8 @@ public class DefaultMetadataService implements MetadataService {
* @return list of trait type names in the type system * @return list of trait type names in the type system
*/ */
@Override @Override
public List<String> getTraitNamesList() throws MetadataException { public List<String> getTypeNamesByCategory(DataTypes.TypeCategory typeCategory) throws MetadataException {
return typeSystem.getTraitsNames(); return typeSystem.getTypeNamesByCategory(typeCategory);
} }
/** /**
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.hadoop.metadata.services; package org.apache.hadoop.metadata.services;
import org.apache.hadoop.metadata.MetadataException; import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.typesystem.types.DataTypes;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import java.util.List; import java.util.List;
...@@ -57,7 +58,7 @@ public interface MetadataService { ...@@ -57,7 +58,7 @@ public interface MetadataService {
* *
* @return list of trait type names in the type system * @return list of trait type names in the type system
*/ */
List<String> getTraitNamesList() throws MetadataException; List<String> getTypeNamesByCategory(DataTypes.TypeCategory typeCategory) throws MetadataException;
/** /**
* Creates an entity, instance of the type. * Creates an entity, instance of the type.
......
...@@ -18,7 +18,9 @@ ...@@ -18,7 +18,9 @@
package org.apache.hadoop.metadata.typesystem.types; package org.apache.hadoop.metadata.typesystem.types;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Multimap;
import org.apache.hadoop.metadata.MetadataException; import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.classification.InterfaceAudience; import org.apache.hadoop.metadata.classification.InterfaceAudience;
import org.apache.hadoop.metadata.typesystem.TypesDef; import org.apache.hadoop.metadata.typesystem.TypesDef;
...@@ -55,9 +57,9 @@ public class TypeSystem { ...@@ -55,9 +57,9 @@ public class TypeSystem {
private IdType idType; private IdType idType;
/** /**
* An in-memory copy of list of traits for convenience. * An in-memory copy of type categories vs types for convenience.
*/ */
private List<String> traitTypes; private Multimap<DataTypes.TypeCategory, String> typeCategoriesToTypeNamesMap;
private ImmutableList<String> coreTypes; private ImmutableList<String> coreTypes;
...@@ -79,7 +81,7 @@ public class TypeSystem { ...@@ -79,7 +81,7 @@ public class TypeSystem {
private void initialize() { private void initialize() {
types = new ConcurrentHashMap<>(); types = new ConcurrentHashMap<>();
traitTypes = new ArrayList<>(); typeCategoriesToTypeNamesMap = ArrayListMultimap.create(DataTypes.TypeCategory.values().length, 10);
registerPrimitiveTypes(); registerPrimitiveTypes();
registerCoreTypes(); registerCoreTypes();
...@@ -94,12 +96,8 @@ public class TypeSystem { ...@@ -94,12 +96,8 @@ public class TypeSystem {
return ImmutableList.copyOf(types.keySet()); return ImmutableList.copyOf(types.keySet());
} }
public ImmutableList<String> getTraitsNames() { public ImmutableList<String> getTypeNamesByCategory(DataTypes.TypeCategory typeCategory) {
return ImmutableList.copyOf(traitTypes); return ImmutableList.copyOf(typeCategoriesToTypeNamesMap.get(typeCategory));
}
private void addTraitName(String traitName) {
traitTypes.add(traitName);
} }
private void registerPrimitiveTypes() { private void registerPrimitiveTypes() {
...@@ -114,6 +112,8 @@ public class TypeSystem { ...@@ -114,6 +112,8 @@ public class TypeSystem {
types.put(DataTypes.BIGDECIMAL_TYPE.getName(), DataTypes.BIGDECIMAL_TYPE); types.put(DataTypes.BIGDECIMAL_TYPE.getName(), DataTypes.BIGDECIMAL_TYPE);
types.put(DataTypes.DATE_TYPE.getName(), DataTypes.DATE_TYPE); types.put(DataTypes.DATE_TYPE.getName(), DataTypes.DATE_TYPE);
types.put(DataTypes.STRING_TYPE.getName(), DataTypes.STRING_TYPE); types.put(DataTypes.STRING_TYPE.getName(), DataTypes.STRING_TYPE);
typeCategoriesToTypeNamesMap.putAll(DataTypes.TypeCategory.PRIMITIVE, types.keySet());
} }
...@@ -267,6 +267,7 @@ public class TypeSystem { ...@@ -267,6 +267,7 @@ public class TypeSystem {
assert elemType != null; assert elemType != null;
DataTypes.ArrayType dT = new DataTypes.ArrayType(elemType); DataTypes.ArrayType dT = new DataTypes.ArrayType(elemType);
types.put(dT.getName(), dT); types.put(dT.getName(), dT);
typeCategoriesToTypeNamesMap.put(DataTypes.TypeCategory.ARRAY, dT.getName());
return dT; return dT;
} }
...@@ -276,6 +277,7 @@ public class TypeSystem { ...@@ -276,6 +277,7 @@ public class TypeSystem {
assert valueType != null; assert valueType != null;
DataTypes.MapType dT = new DataTypes.MapType(keyType, valueType); DataTypes.MapType dT = new DataTypes.MapType(keyType, valueType);
types.put(dT.getName(), dT); types.put(dT.getName(), dT);
typeCategoriesToTypeNamesMap.put(DataTypes.TypeCategory.MAP, dT.getName());
return dT; return dT;
} }
...@@ -291,6 +293,7 @@ public class TypeSystem { ...@@ -291,6 +293,7 @@ public class TypeSystem {
} }
EnumType eT = new EnumType(this, eDef.name, eDef.enumValues); EnumType eT = new EnumType(this, eDef.name, eDef.enumValues);
types.put(eDef.name, eT); types.put(eDef.name, eT);
typeCategoriesToTypeNamesMap.put(DataTypes.TypeCategory.ENUM, eDef.name);
return eT; return eT;
} }
...@@ -520,17 +523,19 @@ public class TypeSystem { ...@@ -520,17 +523,19 @@ public class TypeSystem {
for (StructTypeDefinition structDef : structDefs) { for (StructTypeDefinition structDef : structDefs) {
constructStructureType(structDef); constructStructureType(structDef);
typeCategoriesToTypeNamesMap.put(DataTypes.TypeCategory.CLASS, structDef.typeName);
} }
for (TraitType traitType : traitTypes) { for (TraitType traitType : traitTypes) {
constructHierarchicalType(TraitType.class, constructHierarchicalType(TraitType.class,
traitNameToDefMap.get(traitType.getName())); traitNameToDefMap.get(traitType.getName()));
addTraitName(traitType.getName()); typeCategoriesToTypeNamesMap.put(DataTypes.TypeCategory.TRAIT, traitType.getName());
} }
for (ClassType classType : classTypes) { for (ClassType classType : classTypes) {
constructHierarchicalType(ClassType.class, constructHierarchicalType(ClassType.class,
classNameToDefMap.get(classType.getName())); classNameToDefMap.get(classType.getName()));
typeCategoriesToTypeNamesMap.put(DataTypes.TypeCategory.CLASS, classType.getName());
} }
} }
......
...@@ -86,7 +86,7 @@ public class TypeSystemTest extends BaseTest { ...@@ -86,7 +86,7 @@ public class TypeSystemTest extends BaseTest {
soxTrait, secTrait, financeTrait), soxTrait, secTrait, financeTrait),
ImmutableList.<HierarchicalTypeDefinition<ClassType>>of()); ImmutableList.<HierarchicalTypeDefinition<ClassType>>of());
final ImmutableList<String> traitsNames = getTypeSystem().getTraitsNames(); final ImmutableList<String> traitsNames = getTypeSystem().getTypeNamesByCategory(DataTypes.TypeCategory.TRAIT);
Assert.assertEquals(traitsNames.size(), 7); Assert.assertEquals(traitsNames.size(), 7);
List traits = Arrays.asList(new String[]{ List traits = Arrays.asList(new String[]{
"Classification", "Classification",
......
...@@ -32,16 +32,7 @@ import org.slf4j.LoggerFactory; ...@@ -32,16 +32,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.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
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;
...@@ -80,7 +71,6 @@ public class EntityResource { ...@@ -80,7 +71,6 @@ public class EntityResource {
* Submits an entity definition (instance) corresponding to a given type. * Submits an entity definition (instance) corresponding to a given type.
*/ */
@POST @POST
@Path("submit")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response submit(@Context HttpServletRequest request) { public Response submit(@Context HttpServletRequest request) {
...@@ -111,7 +101,7 @@ public class EntityResource { ...@@ -111,7 +101,7 @@ public class EntityResource {
* @param guid GUID for the entity * @param guid GUID for the entity
*/ */
@GET @GET
@Path("definition/{guid}") @Path("{guid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response getEntityDefinition(@PathParam("guid") String guid) { public Response getEntityDefinition(@PathParam("guid") String guid) {
Preconditions.checkNotNull(guid, "Entity GUID cannot be null"); Preconditions.checkNotNull(guid, "Entity GUID cannot be null");
...@@ -157,9 +147,8 @@ public class EntityResource { ...@@ -157,9 +147,8 @@ public class EntityResource {
* @param resultsPerPage number of results for pagination * @param resultsPerPage number of results for pagination
*/ */
@GET @GET
@Path("list/{entityType}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response getEntityList(@PathParam("entityType") String entityType, public Response getEntityListByType(@QueryParam("type") String entityType,
@DefaultValue("0") @QueryParam("offset") Integer offset, @DefaultValue("0") @QueryParam("offset") Integer offset,
@QueryParam("numResults") Integer resultsPerPage) { @QueryParam("numResults") Integer resultsPerPage) {
Preconditions.checkNotNull(entityType, "Entity type cannot be null"); Preconditions.checkNotNull(entityType, "Entity type cannot be null");
...@@ -193,7 +182,7 @@ public class EntityResource { ...@@ -193,7 +182,7 @@ public class EntityResource {
* @return response payload as json * @return response payload as json
*/ */
@PUT @PUT
@Path("update/{guid}") @Path("{guid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response update(@PathParam("guid") String guid, public Response update(@PathParam("guid") String guid,
@QueryParam("property") String property, @QueryParam("property") String property,
...@@ -223,7 +212,7 @@ public class EntityResource { ...@@ -223,7 +212,7 @@ public class EntityResource {
* @return a list of trait names for the given entity guid * @return a list of trait names for the given entity guid
*/ */
@GET @GET
@Path("traits/list/{guid}") @Path("{guid}/traits")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response getTraitNames(@PathParam("guid") String guid) { public Response getTraitNames(@PathParam("guid") String guid) {
Preconditions.checkNotNull(guid, "Entity GUID cannot be null"); Preconditions.checkNotNull(guid, "Entity GUID cannot be null");
...@@ -256,7 +245,7 @@ public class EntityResource { ...@@ -256,7 +245,7 @@ public class EntityResource {
* @param guid globally unique identifier for the entity * @param guid globally unique identifier for the entity
*/ */
@POST @POST
@Path("traits/add/{guid}") @Path("{guid}/traits")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response addTrait(@Context HttpServletRequest request, public Response addTrait(@Context HttpServletRequest request,
...@@ -291,8 +280,8 @@ public class EntityResource { ...@@ -291,8 +280,8 @@ public class EntityResource {
* @param guid globally unique identifier for the entity * @param guid globally unique identifier for the entity
* @param traitName name of the trait * @param traitName name of the trait
*/ */
@PUT @DELETE
@Path("traits/delete/{guid}/{traitName}") @Path("{guid}/traits/{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,
...@@ -312,11 +301,11 @@ public class EntityResource { ...@@ -312,11 +301,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;
...@@ -69,7 +64,7 @@ public class HiveLineageResource { ...@@ -69,7 +64,7 @@ public class HiveLineageResource {
* @param tableName table name * @param tableName table name
*/ */
@GET @GET
@Path("inputs/{tableName}") @Path("table/{tableName}/inputs")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response inputs(@Context HttpServletRequest request, public Response inputs(@Context HttpServletRequest request,
...@@ -103,11 +98,12 @@ public class HiveLineageResource { ...@@ -103,11 +98,12 @@ public class HiveLineageResource {
* @param tableName table name * @param tableName table name
*/ */
@GET @GET
@Path("outputs/{tableName}") @Path("table/{tableName}/outputs")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@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);
...@@ -137,11 +133,12 @@ public class HiveLineageResource { ...@@ -137,11 +133,12 @@ public class HiveLineageResource {
* @param tableName table name * @param tableName table name
*/ */
@GET @GET
@Path("schema/{tableName}") @Path("table/{tableName}/schema")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@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);
......
...@@ -18,9 +18,11 @@ ...@@ -18,9 +18,11 @@
package org.apache.hadoop.metadata.web.resources; package org.apache.hadoop.metadata.web.resources;
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;
...@@ -31,13 +33,7 @@ import org.slf4j.LoggerFactory; ...@@ -31,13 +33,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.POST;
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;
...@@ -59,6 +55,8 @@ public class TypesResource { ...@@ -59,6 +55,8 @@ public class TypesResource {
private final MetadataService metadataService; private final MetadataService metadataService;
static final String TYPE_ALL = "all";
@Inject @Inject
public TypesResource(MetadataService metadataService) { public TypesResource(MetadataService metadataService) {
this.metadataService = metadataService; this.metadataService = metadataService;
...@@ -69,7 +67,6 @@ public class TypesResource { ...@@ -69,7 +67,6 @@ public class TypesResource {
* domain. Could represent things like Hive Database, Hive Table, etc. * domain. Could represent things like Hive Database, Hive Table, etc.
*/ */
@POST @POST
@Path("submit")
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response submit(@Context HttpServletRequest request) { public Response submit(@Context HttpServletRequest request) {
...@@ -97,7 +94,7 @@ public class TypesResource { ...@@ -97,7 +94,7 @@ public class TypesResource {
* @param typeName name of a type which is unique. * @param typeName name of a type which is unique.
*/ */
@GET @GET
@Path("definition/{typeName}") @Path("{typeName}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response getDefinition(@Context HttpServletRequest request, public Response getDefinition(@Context HttpServletRequest request,
@PathParam("typeName") String typeName) { @PathParam("typeName") String typeName) {
...@@ -122,44 +119,31 @@ public class TypesResource { ...@@ -122,44 +119,31 @@ public class TypesResource {
} }
/** /**
* Gets the list of type names registered in the type system.
*/
@GET
@Path("list")
@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
@Path("traits/list")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response getTraitNames(@Context HttpServletRequest request) { public Response getTypesByFilter(@Context HttpServletRequest request,
@DefaultValue(TYPE_ALL) @QueryParam("type") String type) {
try { try {
final List<String> traitNamesList = metadataService.getTraitNamesList(); List<String> result = null;
if (TYPE_ALL.equals(type)) {
result = metadataService.getTypeNamesList();
} else {
DataTypes.TypeCategory typeCategory = DataTypes.TypeCategory.valueOf(type);
result = metadataService.getTypeNamesByCategory(typeCategory);
}
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(MetadataServiceClient.RESULTS, new JSONArray(traitNamesList)); response.put(MetadataServiceClient.RESULTS, new JSONArray(result));
response.put(MetadataServiceClient.TOTAL_SIZE, traitNamesList.size()); response.put(MetadataServiceClient.TOTAL_SIZE, result.size());
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(
......
...@@ -70,7 +70,7 @@ public abstract class BaseResourceIT { ...@@ -70,7 +70,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)
......
...@@ -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;
...@@ -153,7 +155,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -153,7 +155,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
private ClientResponse addProperty(String guid, String property, String value) { private ClientResponse addProperty(String guid, String property, String value) {
WebResource resource = service WebResource resource = service
.path("api/metadata/entities/update") .path("api/metadata/entities")
.path(guid); .path(guid);
return resource.queryParam("property", property).queryParam("value", value) return resource.queryParam("property", property).queryParam("value", value)
...@@ -164,7 +166,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -164,7 +166,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
private ClientResponse getEntityDefinition(String guid) { private ClientResponse getEntityDefinition(String guid) {
WebResource resource = service WebResource resource = service
.path("api/metadata/entities/definition") .path("api/metadata/entities")
.path(guid); .path(guid);
return resource.accept(MediaType.APPLICATION_JSON) return resource.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
...@@ -183,7 +185,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -183,7 +185,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testGetInvalidEntityDefinition() throws Exception { public void testGetInvalidEntityDefinition() throws Exception {
WebResource resource = service WebResource resource = service
.path("api/metadata/entities/definition") .path("api/metadata/entities")
.path("blah"); .path("blah");
ClientResponse clientResponse = resource ClientResponse clientResponse = resource
...@@ -199,8 +201,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -199,8 +201,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test(dependsOnMethods = "testSubmitEntity") @Test(dependsOnMethods = "testSubmitEntity")
public void testGetEntityList() throws Exception { public void testGetEntityList() throws Exception {
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities/list/") .path("api/metadata/entities")
.path(TABLE_TYPE) .queryParam("type", TABLE_TYPE)
.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);
...@@ -220,7 +222,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -220,7 +222,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testGetEntityListForBadEntityType() throws Exception { public void testGetEntityListForBadEntityType() throws Exception {
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities/list/blah") .path("api/metadata/entities")
.queryParam("type", "blah")
.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);
...@@ -236,7 +239,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -236,7 +239,8 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
addNewType(); addNewType();
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities/list/test") .path("api/metadata/entities")
.queryParam("type", "test")
.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);
...@@ -267,8 +271,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -267,8 +271,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
public void testGetTraitNames() throws Exception { public void testGetTraitNames() throws Exception {
final String guid = tableId._getId(); final String guid = tableId._getId();
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities/traits/list") .path("api/metadata/entities")
.path(guid) .path(guid)
.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);
...@@ -300,8 +305,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -300,8 +305,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
final String guid = tableId._getId(); final String guid = tableId._getId();
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities/traits/add") .path("api/metadata/entities")
.path(guid) .path(guid)
.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);
...@@ -329,8 +335,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -329,8 +335,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON); LOG.debug("traitInstanceAsJSON = " + traitInstanceAsJSON);
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities/traits/add") .path("api/metadata/entities")
.path("random") .path("random")
.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);
...@@ -344,12 +351,13 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -344,12 +351,13 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
final String guid = tableId._getId(); final String guid = tableId._getId();
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities/traits/delete") .path("api/metadata/entities")
.path(guid) .path(guid)
.path(TRAITS)
.path(traitName) .path(traitName)
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
.method(HttpMethod.PUT, ClientResponse.class); .method(HttpMethod.DELETE, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
String responseAsString = clientResponse.getEntity(String.class); String responseAsString = clientResponse.getEntity(String.class);
...@@ -366,12 +374,13 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -366,12 +374,13 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
final String traitName = "blah_trait"; final String traitName = "blah_trait";
ClientResponse clientResponse = service ClientResponse clientResponse = service
.path("api/metadata/entities/traits/delete") .path("api/metadata/entities")
.path("random") .path("random")
.path(TRAITS)
.path(traitName) .path(traitName)
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
.method(HttpMethod.PUT, ClientResponse.class); .method(HttpMethod.DELETE, ClientResponse.class);
Assert.assertEquals(clientResponse.getStatus(), Assert.assertEquals(clientResponse.getStatus(),
Response.Status.BAD_REQUEST.getStatusCode()); Response.Status.BAD_REQUEST.getStatusCode());
} }
......
...@@ -53,6 +53,8 @@ import java.util.List; ...@@ -53,6 +53,8 @@ import java.util.List;
*/ */
public class HiveLineageJerseyResourceIT extends BaseResourceIT { public class HiveLineageJerseyResourceIT extends BaseResourceIT {
private static final String BASE_URI = "api/metadata/lineage/hive/table/";
@BeforeClass @BeforeClass
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
...@@ -64,8 +66,9 @@ public class HiveLineageJerseyResourceIT extends BaseResourceIT { ...@@ -64,8 +66,9 @@ public class HiveLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testInputs() throws Exception { public void testInputs() throws Exception {
WebResource resource = service WebResource resource = service
.path("api/metadata/lineage/hive/inputs") .path(BASE_URI)
.path("sales_fact_monthly_mv"); .path("sales_fact_monthly_mv")
.path("inputs");
ClientResponse clientResponse = resource ClientResponse clientResponse = resource
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
...@@ -94,8 +97,9 @@ public class HiveLineageJerseyResourceIT extends BaseResourceIT { ...@@ -94,8 +97,9 @@ public class HiveLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testOutputs() throws Exception { public void testOutputs() throws Exception {
WebResource resource = service WebResource resource = service
.path("api/metadata/lineage/hive/outputs") .path(BASE_URI)
.path("sales_fact"); .path("sales_fact")
.path("outputs");
ClientResponse clientResponse = resource ClientResponse clientResponse = resource
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
...@@ -124,8 +128,9 @@ public class HiveLineageJerseyResourceIT extends BaseResourceIT { ...@@ -124,8 +128,9 @@ public class HiveLineageJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testSchema() throws Exception { public void testSchema() throws Exception {
WebResource resource = service WebResource resource = service
.path("api/metadata/lineage/hive/schema") .path(BASE_URI)
.path("sales_fact"); .path("sales_fact")
.path("schema");
ClientResponse clientResponse = resource ClientResponse clientResponse = resource
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
......
...@@ -70,7 +70,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -70,7 +70,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
System.out.println("typesAsJSON = " + typesAsJSON); System.out.println("typesAsJSON = " + typesAsJSON);
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)
...@@ -93,7 +93,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -93,7 +93,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
System.out.println("typeName = " + typeDefinition.typeName); System.out.println("typeName = " + typeDefinition.typeName);
WebResource resource = service WebResource resource = service
.path("api/metadata/types/definition") .path("api/metadata/types")
.path(typeDefinition.typeName); .path(typeDefinition.typeName);
ClientResponse clientResponse = resource ClientResponse clientResponse = resource
...@@ -114,7 +114,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -114,7 +114,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
@Test @Test
public void testGetDefinitionForNonexistentType() throws Exception { public void testGetDefinitionForNonexistentType() throws Exception {
WebResource resource = service WebResource resource = service
.path("api/metadata/types/definition") .path("api/metadata/types")
.path("blah"); .path("blah");
ClientResponse clientResponse = resource ClientResponse clientResponse = resource
...@@ -127,7 +127,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -127,7 +127,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
@Test(dependsOnMethods = "testSubmit") @Test(dependsOnMethods = "testSubmit")
public void testGetTypeNames() throws Exception { public void testGetTypeNames() throws Exception {
WebResource resource = service WebResource resource = service
.path("api/metadata/types/list"); .path("api/metadata/types");
ClientResponse clientResponse = resource ClientResponse clientResponse = resource
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
...@@ -150,9 +150,10 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -150,9 +150,10 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
String[] traitsAdded = addTraits(); String[] traitsAdded = addTraits();
WebResource resource = service WebResource resource = service
.path("api/metadata/types/traits/list"); .path("api/metadata/types");
ClientResponse clientResponse = resource ClientResponse clientResponse = resource
.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