Commit e013e656 by Suma Shivaprasad

Fixed all review comments

parent 1a536c2a
...@@ -29,6 +29,7 @@ import org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance; ...@@ -29,6 +29,7 @@ import org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance;
import org.apache.hadoop.metadata.typesystem.Referenceable; import org.apache.hadoop.metadata.typesystem.Referenceable;
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.http.protocol.HTTP;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
...@@ -36,6 +37,7 @@ import org.slf4j.Logger; ...@@ -36,6 +37,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import javax.ws.rs.HttpMethod; import javax.ws.rs.HttpMethod;
import javax.ws.rs.POST;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriBuilder;
...@@ -50,7 +52,6 @@ import static org.apache.hadoop.metadata.security.SecurityProperties.TLS_ENABLED ...@@ -50,7 +52,6 @@ import static org.apache.hadoop.metadata.security.SecurityProperties.TLS_ENABLED
public class MetadataServiceClient { public class MetadataServiceClient {
private static final Logger LOG = LoggerFactory.getLogger(MetadataServiceClient.class); private static final Logger LOG = LoggerFactory.getLogger(MetadataServiceClient.class);
public static final String NAME = "name"; public static final String NAME = "name";
public static final String URI = "id";
public static final String GUID = "GUID"; public static final String GUID = "GUID";
public static final String DEFINITION = "definition"; public static final String DEFINITION = "definition";
public static final String ERROR = "error"; public static final String ERROR = "error";
...@@ -61,7 +62,7 @@ public class MetadataServiceClient { ...@@ -61,7 +62,7 @@ public class MetadataServiceClient {
public static final String URI_TYPES = "types"; public static final String URI_TYPES = "types";
public static final String URI_ENTITIES = "entities"; public static final String URI_ENTITIES = "entities";
public static final String URI_TRAITS = "traits"; public static final String URI_TRAITS = "traits";
private static final String URI_SEARCH = "discovery/search"; public static final String URI_SEARCH = "discovery/search";
private WebResource service; private WebResource service;
...@@ -169,7 +170,7 @@ public class MetadataServiceClient { ...@@ -169,7 +170,7 @@ public class MetadataServiceClient {
* @throws MetadataServiceException * @throws MetadataServiceException
*/ */
public JSONObject createType(String typeAsJson) throws MetadataServiceException { public JSONObject createType(String typeAsJson) throws MetadataServiceException {
return callAPI(API.CREATE_TYPE, typeAsJson, Response.Status.CREATED); return callAPI(API.CREATE_TYPE, typeAsJson);
} }
/** /**
...@@ -179,7 +180,7 @@ public class MetadataServiceClient { ...@@ -179,7 +180,7 @@ public class MetadataServiceClient {
* @throws MetadataServiceException * @throws MetadataServiceException
*/ */
public JSONObject createEntity(String entityAsJson) throws MetadataServiceException { public JSONObject createEntity(String entityAsJson) throws MetadataServiceException {
return callAPI(API.CREATE_ENTITY, entityAsJson, Response.Status.CREATED); return callAPI(API.CREATE_ENTITY, entityAsJson);
} }
/** /**
...@@ -189,7 +190,7 @@ public class MetadataServiceClient { ...@@ -189,7 +190,7 @@ public class MetadataServiceClient {
* @throws MetadataServiceException * @throws MetadataServiceException
*/ */
public Referenceable getEntity(String guid) throws MetadataServiceException { public Referenceable getEntity(String guid) throws MetadataServiceException {
JSONObject jsonResponse = callAPI(API.GET_ENTITY, null, Response.Status.OK, guid); JSONObject jsonResponse = callAPI(API.GET_ENTITY, null, guid);
try { try {
String entityInstanceDefinition = jsonResponse.getString(MetadataServiceClient.GUID); String entityInstanceDefinition = jsonResponse.getString(MetadataServiceClient.GUID);
return InstanceSerialization.fromJsonReferenceable(entityInstanceDefinition, true); return InstanceSerialization.fromJsonReferenceable(entityInstanceDefinition, true);
...@@ -281,17 +282,19 @@ public class MetadataServiceClient { ...@@ -281,17 +282,19 @@ public class MetadataServiceClient {
return resource; return resource;
} }
private JSONObject callAPIWithResource(API api, WebResource resource, Response.Status expectedStatus) throws MetadataServiceException { private JSONObject callAPIWithResource(API api, WebResource resource) throws MetadataServiceException {
return callAPIWithResource(api, resource, null, expectedStatus); return callAPIWithResource(api, resource, null);
} }
private JSONObject callAPIWithResource(API api, WebResource resource, Object requestObject, Response.Status expectedStatus) private JSONObject callAPIWithResource(API api, WebResource resource, Object requestObject)
throws MetadataServiceException { throws MetadataServiceException {
ClientResponse clientResponse = resource ClientResponse clientResponse = resource
.accept(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON)
.method(api.getMethod(), ClientResponse.class, requestObject); .method(api.getMethod(), ClientResponse.class, requestObject);
Response.Status expectedStatus = (api.getMethod() == HttpMethod.POST)
? Response.Status.CREATED : Response.Status.OK;
if (clientResponse.getStatus() == expectedStatus.getStatusCode()) { if (clientResponse.getStatus() == expectedStatus.getStatusCode()) {
String responseAsString = clientResponse.getEntity(String.class); String responseAsString = clientResponse.getEntity(String.class);
System.out.println("response : " + responseAsString); System.out.println("response : " + responseAsString);
...@@ -306,8 +309,8 @@ public class MetadataServiceClient { ...@@ -306,8 +309,8 @@ public class MetadataServiceClient {
} }
private JSONObject callAPI(API api, Object requestObject, private JSONObject callAPI(API api, Object requestObject,
Response.Status expectedStatus, String... pathParams) throws MetadataServiceException { String... pathParams) throws MetadataServiceException {
WebResource resource = getResource(api, pathParams); WebResource resource = getResource(api, pathParams);
return callAPIWithResource(api, resource, requestObject, expectedStatus); return callAPIWithResource(api, resource, requestObject);
} }
} }
...@@ -21,6 +21,7 @@ package org.apache.hadoop.metadata.services; ...@@ -21,6 +21,7 @@ package org.apache.hadoop.metadata.services;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.apache.hadoop.metadata.MetadataException; import org.apache.hadoop.metadata.MetadataException;
import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.discovery.SearchIndexer; import org.apache.hadoop.metadata.discovery.SearchIndexer;
import org.apache.hadoop.metadata.listener.EntityChangeListener; import org.apache.hadoop.metadata.listener.EntityChangeListener;
import org.apache.hadoop.metadata.listener.TypesChangeListener; import org.apache.hadoop.metadata.listener.TypesChangeListener;
...@@ -100,7 +101,7 @@ public class DefaultMetadataService implements MetadataService { ...@@ -100,7 +101,7 @@ public class DefaultMetadataService implements MetadataService {
onTypesAddedToRepo(typesAdded); onTypesAddedToRepo(typesAdded);
JSONObject response = new JSONObject() {{ JSONObject response = new JSONObject() {{
put("types", typesAdded.keySet()); put(MetadataServiceClient.URI_TYPES, typesAdded.keySet());
}}; }};
return response; return response;
} catch (JSONException e) { } catch (JSONException e) {
......
...@@ -36,10 +36,8 @@ import javax.ws.rs.*; ...@@ -36,10 +36,8 @@ import javax.ws.rs.*;
import javax.ws.rs.core.*; import javax.ws.rs.core.*;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* Entity management operations as REST API. * Entity management operations as REST API.
...@@ -89,7 +87,6 @@ public class EntityResource { ...@@ -89,7 +87,6 @@ public class EntityResource {
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put(MetadataServiceClient.GUID, guid); response.put(MetadataServiceClient.GUID, guid);
response.put(MetadataServiceClient.URI, locationURI.toURL().toExternalForm());
response.put(MetadataServiceClient.DEFINITION, entity); response.put(MetadataServiceClient.DEFINITION, entity);
return Response.created(locationURI).entity(response).build(); return Response.created(locationURI).entity(response).build();
...@@ -268,7 +265,6 @@ public class EntityResource { ...@@ -268,7 +265,6 @@ public class EntityResource {
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put(MetadataServiceClient.GUID, guid); response.put(MetadataServiceClient.GUID, guid);
response.put(MetadataServiceClient.URI, locationURI.toURL().toExternalForm());
response.put(MetadataServiceClient.DEFINITION, traitDefinition); response.put(MetadataServiceClient.DEFINITION, traitDefinition);
return Response.created(locationURI).entity(response).build(); return Response.created(locationURI).entity(response).build();
......
...@@ -95,7 +95,6 @@ public class TypesResource { ...@@ -95,7 +95,6 @@ public class TypesResource {
typesAddedList.add( typesAddedList.add(
new HashMap<String, String>() {{ new HashMap<String, String>() {{
put(MetadataServiceClient.NAME, name); put(MetadataServiceClient.NAME, name);
put(MetadataServiceClient.URI, locationUri.toURL().toExternalForm());
}}); }});
} }
......
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