Commit e013e656 by Suma Shivaprasad

Fixed all review comments

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