Commit a2e16bb9 by Shwetha GS

renamed addProperty API to update, first version of service client

parent 6d369328
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>metadata-governance</artifactId>
<groupId>org.apache.hadoop.metadata</groupId>
<version>0.1-incubating-SNAPSHOT</version>
</parent>
<artifactId>metadata-client</artifactId>
<description>Apache Metadata Client</description>
<name>Apache Metadata Client</name>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.apache.hadoop.metadata</groupId>
<artifactId>metadata-typesystem</artifactId>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
</dependencies>
</project>
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.metadata;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
public class MetadataServiceClient {
public static final String REQUEST_ID = "requestId";
public static final String RESULTS = "results";
public static final String TOTAL_SIZE = "totalSize";
private final WebResource service;
public MetadataServiceClient(String baseUrl) {
DefaultClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
client.resource(UriBuilder.fromUri(baseUrl).build());
service = client.resource(UriBuilder.fromUri(baseUrl).build());
}
static enum API {
//Type operations
CREATE_TYPE("api/metadata/types/submit", HttpMethod.POST),
GET_TYPE("api/metadata/types/definition", HttpMethod.GET),
LIST_TYPE("api/metadata/types/list", HttpMethod.GET),
LIST_TRAIT_TYPE("api/metadata/types/traits/list", HttpMethod.GET),
//Entity operations
CREATE_ENTITY("api/metadata/entities/submit", HttpMethod.POST),
GET_ENTITY("api/metadata/entities/definition", HttpMethod.GET),
UPDATE_ENTITY("api/metadata/entities/update", HttpMethod.PUT),
LIST_ENTITY("api/metadata/entities/list", HttpMethod.GET),
//Trait operations
ADD_TRAITS("api/metadata/traits/add", HttpMethod.POST),
DELETE_TRAITS("api/metadata/traits/delete", HttpMethod.PUT),
LIST_TRAITS("api/metadata/traits/list", HttpMethod.GET);
private final String method;
private final String path;
API(String path, String method) {
this.path = path;
this.method = method;
}
public String getMethod() {
return method;
}
public String getPath() {
return path;
}
}
public JSONObject createEntity(String typeName, String entityAsJson) throws MetadataServiceException {
return callAPI(API.CREATE_ENTITY, entityAsJson, typeName);
}
public String getRequestId(JSONObject json) throws MetadataServiceException {
try {
return json.getString(REQUEST_ID);
} catch (JSONException e) {
throw new MetadataServiceException(e);
}
}
private JSONObject callAPI(API api, Object requestObject, String... pathParams) throws MetadataServiceException {
WebResource resource = service.path(api.getPath());
if (pathParams != null) {
for (String pathParam : pathParams) {
resource = resource.path(pathParam);
}
}
ClientResponse clientResponse = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON)
.method(api.getMethod(), ClientResponse.class, requestObject);
if (clientResponse.getStatus() == Response.Status.OK.getStatusCode()) {
String responseAsString = clientResponse.getEntity(String.class);
try {
return new JSONObject(responseAsString);
} catch (JSONException e) {
throw new MetadataServiceException(api, e);
}
}
throw new MetadataServiceException(api, clientResponse.getClientResponseStatus());
}
}
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.metadata;
import com.sun.jersey.api.client.ClientResponse;
public class MetadataServiceException extends Exception {
public MetadataServiceException(MetadataServiceClient.API api, Exception e) {
super("Metadata service API " + api + " failed", e);
}
public MetadataServiceException(MetadataServiceClient.API api, ClientResponse.Status status) {
super("Metadata service API " + api + " failed with status " + status.getStatusCode()
+ "(" + status.getReasonPhrase() + ")");
}
public MetadataServiceException(Exception e) {
super(e);
}
}
...@@ -200,6 +200,7 @@ ...@@ -200,6 +200,7 @@
<modules> <modules>
<module>typesystem</module> <module>typesystem</module>
<module>client</module>
<module>repository</module> <module>repository</module>
<module>webapp</module> <module>webapp</module>
<module>docs</module> <module>docs</module>
...@@ -514,6 +515,12 @@ ...@@ -514,6 +515,12 @@
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.hadoop.metadata</groupId>
<artifactId>metadata-client</artifactId>
<version>${project.version}</version>
</dependency>
<!--Scala dependencies--> <!--Scala dependencies-->
<dependency> <dependency>
<groupId>org.scala-lang</groupId> <groupId>org.scala-lang</groupId>
......
...@@ -163,5 +163,5 @@ public interface MetadataRepository { ...@@ -163,5 +163,5 @@ public interface MetadataRepository {
* @param property * @param property
* @param value * @param value
*/ */
void addProperty(String guid, String property, String value) throws RepositoryException; void updateEntity(String guid, String property, String value) throws RepositoryException;
} }
...@@ -298,7 +298,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository { ...@@ -298,7 +298,7 @@ public class GraphBackedMetadataRepository implements MetadataRepository {
} }
@Override @Override
public void addProperty(String guid, String property, String value) throws RepositoryException { public void updateEntity(String guid, String property, String value) throws RepositoryException {
LOG.info("Adding property {} for entity guid {}", property, guid); LOG.info("Adding property {} for entity guid {}", property, guid);
try { try {
......
...@@ -197,12 +197,12 @@ public class DefaultMetadataService implements MetadataService { ...@@ -197,12 +197,12 @@ public class DefaultMetadataService implements MetadataService {
} }
@Override @Override
public void addProperty(String guid, String property, String value) throws MetadataException { public void updateEntity(String guid, String property, String value) throws MetadataException {
Preconditions.checkNotNull(guid, "guid cannot be null"); Preconditions.checkNotNull(guid, "guid cannot be null");
Preconditions.checkNotNull(property, "property cannot be null"); Preconditions.checkNotNull(property, "property cannot be null");
Preconditions.checkNotNull(value, "property value cannot be null"); Preconditions.checkNotNull(value, "property value cannot be null");
repository.addProperty(guid, property, value); repository.updateEntity(guid, property, value);
} }
private void validateTypeExists(String entityType) throws MetadataException { private void validateTypeExists(String entityType) throws MetadataException {
......
...@@ -92,7 +92,7 @@ public interface MetadataService { ...@@ -92,7 +92,7 @@ public interface MetadataService {
* @param property * @param property
* @param value * @param value
*/ */
void addProperty(String guid, String property, String value) throws MetadataException; void updateEntity(String guid, String property, String value) throws MetadataException;
// Trait management functions // Trait management functions
/** /**
......
...@@ -49,6 +49,11 @@ ...@@ -49,6 +49,11 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.hadoop.metadata</groupId>
<artifactId>metadata-client</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId> <groupId>joda-time</groupId>
<artifactId>joda-time</artifactId> <artifactId>joda-time</artifactId>
</dependency> </dependency>
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.hadoop.metadata.web.filters; package org.apache.hadoop.metadata.web.filters;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.web.util.DateTimeHelper; import org.apache.hadoop.metadata.web.util.DateTimeHelper;
import org.apache.hadoop.metadata.web.util.Servlets; import org.apache.hadoop.metadata.web.util.Servlets;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -67,7 +68,7 @@ public class AuditFilter implements Filter { ...@@ -67,7 +68,7 @@ public class AuditFilter implements Filter {
filterChain.doFilter(request, response); filterChain.doFilter(request, response);
} finally { } finally {
// put the request id into the response so users can trace logs for this request // put the request id into the response so users can trace logs for this request
((HttpServletResponse) response).setHeader(Servlets.REQUEST_ID, requestId); ((HttpServletResponse) response).setHeader(MetadataServiceClient.REQUEST_ID, requestId);
currentThread.setName(oldName); currentThread.setName(oldName);
} }
} }
......
...@@ -20,6 +20,7 @@ package org.apache.hadoop.metadata.web.resources; ...@@ -20,6 +20,7 @@ package org.apache.hadoop.metadata.web.resources;
import com.google.common.base.Preconditions; 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.services.MetadataService; import org.apache.hadoop.metadata.services.MetadataService;
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;
...@@ -92,8 +93,8 @@ public class EntityResource { ...@@ -92,8 +93,8 @@ public class EntityResource {
final String guid = metadataService.createEntity(typeName, entity); final String guid = metadataService.createEntity(typeName, entity);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put(Servlets.RESULTS, guid); response.put(MetadataServiceClient.RESULTS, guid);
return Response.ok(response).build(); return Response.ok(response).build();
} catch (MetadataException | IOException | IllegalArgumentException e) { } catch (MetadataException | IOException | IllegalArgumentException e) {
...@@ -123,12 +124,12 @@ public class EntityResource { ...@@ -123,12 +124,12 @@ public class EntityResource {
final String entityDefinition = metadataService.getEntityDefinition(guid); final String entityDefinition = metadataService.getEntityDefinition(guid);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put(GUID, guid); response.put(GUID, guid);
Response.Status status = Response.Status.NOT_FOUND; Response.Status status = Response.Status.NOT_FOUND;
if (entityDefinition != null) { if (entityDefinition != null) {
response.put(Servlets.RESULTS, entityDefinition); response.put(MetadataServiceClient.RESULTS, entityDefinition);
status = Response.Status.OK; status = Response.Status.OK;
} }
...@@ -170,10 +171,10 @@ public class EntityResource { ...@@ -170,10 +171,10 @@ public class EntityResource {
final List<String> entityList = metadataService.getEntityList(entityType); final List<String> entityList = metadataService.getEntityList(entityType);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put("type", entityType); response.put("type", entityType);
response.put(Servlets.RESULTS, new JSONArray(entityList)); response.put(MetadataServiceClient.RESULTS, new JSONArray(entityList));
response.put(Servlets.TOTAL_SIZE, entityList.size()); response.put(MetadataServiceClient.TOTAL_SIZE, entityList.size());
return Response.ok(response).build(); return Response.ok(response).build();
} catch (MetadataException | IllegalArgumentException e) { } catch (MetadataException | IllegalArgumentException e) {
...@@ -195,12 +196,12 @@ public class EntityResource { ...@@ -195,12 +196,12 @@ public class EntityResource {
* @return * @return
*/ */
@PUT @PUT
@Path("addProperty/{guid}") @Path("update/{guid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public Response addProperty(@PathParam("guid") String guid, @QueryParam("property") String property, public Response update(@PathParam("guid") String guid, @QueryParam("property") String property,
@QueryParam("value") String value) { @QueryParam("value") String value) {
try { try {
metadataService.addProperty(guid, property, value); metadataService.updateEntity(guid, property, value);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put("requestId", Thread.currentThread().getName()); response.put("requestId", Thread.currentThread().getName());
...@@ -234,10 +235,10 @@ public class EntityResource { ...@@ -234,10 +235,10 @@ public class EntityResource {
final List<String> traitNames = metadataService.getTraitNames(guid); final List<String> traitNames = metadataService.getTraitNames(guid);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put(GUID, guid); response.put(GUID, guid);
response.put(Servlets.RESULTS, new JSONArray(traitNames)); response.put(MetadataServiceClient.RESULTS, new JSONArray(traitNames));
response.put(Servlets.TOTAL_SIZE, traitNames.size()); response.put(MetadataServiceClient.TOTAL_SIZE, traitNames.size());
return Response.ok(response).build(); return Response.ok(response).build();
} catch (MetadataException | IllegalArgumentException e) { } catch (MetadataException | IllegalArgumentException e) {
...@@ -270,7 +271,7 @@ public class EntityResource { ...@@ -270,7 +271,7 @@ public class EntityResource {
metadataService.addTrait(guid, traitDefinition); metadataService.addTrait(guid, traitDefinition);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put(GUID, guid); response.put(GUID, guid);
response.put("traitInstance", traitDefinition); response.put("traitInstance", traitDefinition);
...@@ -307,7 +308,7 @@ public class EntityResource { ...@@ -307,7 +308,7 @@ public class EntityResource {
metadataService.deleteTrait(guid, traitName); metadataService.deleteTrait(guid, traitName);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put(GUID, guid); response.put(GUID, guid);
response.put(TRAIT_NAME, traitName); response.put(TRAIT_NAME, traitName);
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.hadoop.metadata.web.resources; package org.apache.hadoop.metadata.web.resources;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.discovery.DiscoveryException; import org.apache.hadoop.metadata.discovery.DiscoveryException;
import org.apache.hadoop.metadata.discovery.DiscoveryService; import org.apache.hadoop.metadata.discovery.DiscoveryService;
import org.apache.hadoop.metadata.web.util.Servlets; import org.apache.hadoop.metadata.web.util.Servlets;
...@@ -89,20 +90,20 @@ public class MetadataDiscoveryResource { ...@@ -89,20 +90,20 @@ public class MetadataDiscoveryResource {
try { try {
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put("query", query); response.put("query", query);
try { // fall back to dsl try { // fall back to dsl
final String jsonResult = discoveryService.searchByDSL(query); final String jsonResult = discoveryService.searchByDSL(query);
response.put("queryType", "dsl"); response.put("queryType", "dsl");
response.put(Servlets.RESULTS, new JSONObject(jsonResult)); response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult));
} catch (Throwable throwable) { } catch (Throwable throwable) {
LOG.error("Unable to get entity list for query {} using dsl", query, throwable); LOG.error("Unable to get entity list for query {} using dsl", query, throwable);
// todo: fall back to full text search // todo: fall back to full text search
response.put("queryType", "full-text"); response.put("queryType", "full-text");
response.put(Servlets.RESULTS, new JSONObject()); response.put(MetadataServiceClient.RESULTS, new JSONObject());
} }
return Response.ok(response).build(); return Response.ok(response).build();
...@@ -129,10 +130,10 @@ public class MetadataDiscoveryResource { ...@@ -129,10 +130,10 @@ public class MetadataDiscoveryResource {
final String jsonResult = discoveryService.searchByDSL(dslQuery); final String jsonResult = discoveryService.searchByDSL(dslQuery);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put("query", dslQuery); response.put("query", dslQuery);
response.put("queryType", "dsl"); response.put("queryType", "dsl");
response.put(Servlets.RESULTS, new JSONObject(jsonResult)); response.put(MetadataServiceClient.RESULTS, new JSONObject(jsonResult));
return Response.ok(response).build(); return Response.ok(response).build();
} catch (DiscoveryException e) { } catch (DiscoveryException e) {
...@@ -163,7 +164,7 @@ public class MetadataDiscoveryResource { ...@@ -163,7 +164,7 @@ public class MetadataDiscoveryResource {
.searchByGremlin(gremlinQuery); .searchByGremlin(gremlinQuery);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
response.put("query", gremlinQuery); response.put("query", gremlinQuery);
response.put("queryType", "gremlin"); response.put("queryType", "gremlin");
...@@ -171,8 +172,8 @@ public class MetadataDiscoveryResource { ...@@ -171,8 +172,8 @@ public class MetadataDiscoveryResource {
for (Map<String, String> result : results) { for (Map<String, String> result : results) {
list.put(new JSONObject(result)); list.put(new JSONObject(result));
} }
response.put(Servlets.RESULTS, list); response.put(MetadataServiceClient.RESULTS, list);
response.put(Servlets.TOTAL_SIZE, list.length()); response.put(MetadataServiceClient.TOTAL_SIZE, list.length());
return Response.ok(response).build(); return Response.ok(response).build();
} catch (DiscoveryException e) { } catch (DiscoveryException e) {
...@@ -213,7 +214,7 @@ public class MetadataDiscoveryResource { ...@@ -213,7 +214,7 @@ public class MetadataDiscoveryResource {
.relationshipWalk(guid, depth, edgesToFollow); .relationshipWalk(guid, depth, edgesToFollow);
try { try {
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
if (resultMap.containsKey("vertices")) { if (resultMap.containsKey("vertices")) {
response.put("vertices", new JSONObject(resultMap.get("vertices"))); response.put("vertices", new JSONObject(resultMap.get("vertices")));
} }
...@@ -259,7 +260,7 @@ public class MetadataDiscoveryResource { ...@@ -259,7 +260,7 @@ public class MetadataDiscoveryResource {
searchText, depth, prop); searchText, depth, prop);
try { try {
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
if (resultMap.containsKey("vertices")) { if (resultMap.containsKey("vertices")) {
response.put("vertices", resultMap.get("vertices")); response.put("vertices", resultMap.get("vertices"));
} }
......
...@@ -27,6 +27,7 @@ import com.tinkerpop.blueprints.VertexQuery; ...@@ -27,6 +27,7 @@ import com.tinkerpop.blueprints.VertexQuery;
import com.tinkerpop.blueprints.util.io.graphson.GraphSONMode; import com.tinkerpop.blueprints.util.io.graphson.GraphSONMode;
import com.tinkerpop.blueprints.util.io.graphson.GraphSONUtility; import com.tinkerpop.blueprints.util.io.graphson.GraphSONUtility;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.repository.graph.GraphService; import org.apache.hadoop.metadata.repository.graph.GraphService;
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;
...@@ -120,7 +121,7 @@ public class RexsterGraphResource { ...@@ -120,7 +121,7 @@ public class RexsterGraphResource {
Vertex vertex = findVertex(vertexId); Vertex vertex = findVertex(vertexId);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.RESULTS, GraphSONUtility.jsonFromElement( response.put(MetadataServiceClient.RESULTS, GraphSONUtility.jsonFromElement(
vertex, getVertexIndexedKeys(), GraphSONMode.NORMAL)); vertex, getVertexIndexedKeys(), GraphSONMode.NORMAL));
return Response.ok(response).build(); return Response.ok(response).build();
} catch (JSONException e) { } catch (JSONException e) {
...@@ -161,8 +162,8 @@ public class RexsterGraphResource { ...@@ -161,8 +162,8 @@ public class RexsterGraphResource {
Map<String, String> vertexProperties = getVertexProperties(vertex); Map<String, String> vertexProperties = getVertexProperties(vertex);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.RESULTS, new JSONObject(vertexProperties)); response.put(MetadataServiceClient.RESULTS, new JSONObject(vertexProperties));
response.put(Servlets.TOTAL_SIZE, vertexProperties.size()); response.put(MetadataServiceClient.TOTAL_SIZE, vertexProperties.size());
return Response.ok(response).build(); return Response.ok(response).build();
} catch (JSONException e) { } catch (JSONException e) {
throw new WebApplicationException( throw new WebApplicationException(
...@@ -271,9 +272,9 @@ public class RexsterGraphResource { ...@@ -271,9 +272,9 @@ public class RexsterGraphResource {
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
if (!countOnly) { if (!countOnly) {
response.put(Servlets.RESULTS, elementArray); response.put(MetadataServiceClient.RESULTS, elementArray);
} }
response.put(Servlets.TOTAL_SIZE, counter); response.put(MetadataServiceClient.TOTAL_SIZE, counter);
return Response.ok(response).build(); return Response.ok(response).build();
} }
...@@ -299,7 +300,7 @@ public class RexsterGraphResource { ...@@ -299,7 +300,7 @@ public class RexsterGraphResource {
} }
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.RESULTS, GraphSONUtility.jsonFromElement( response.put(MetadataServiceClient.RESULTS, GraphSONUtility.jsonFromElement(
edge, getEdgeIndexedKeys(), GraphSONMode.NORMAL)); edge, getEdgeIndexedKeys(), GraphSONMode.NORMAL));
return Response.ok(response).build(); return Response.ok(response).build();
} catch (JSONException e) { } catch (JSONException e) {
...@@ -319,8 +320,8 @@ public class RexsterGraphResource { ...@@ -319,8 +320,8 @@ public class RexsterGraphResource {
} }
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.RESULTS, vertexArray); response.put(MetadataServiceClient.RESULTS, vertexArray);
response.put(Servlets.TOTAL_SIZE, counter); response.put(MetadataServiceClient.TOTAL_SIZE, counter);
return response; return response;
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.apache.hadoop.metadata.web.resources; package org.apache.hadoop.metadata.web.resources;
import org.apache.hadoop.metadata.MetadataException; import org.apache.hadoop.metadata.MetadataException;
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.web.util.Servlets; import org.apache.hadoop.metadata.web.util.Servlets;
import org.codehaus.jettison.json.JSONArray; import org.codehaus.jettison.json.JSONArray;
...@@ -84,7 +85,7 @@ public class TypesResource { ...@@ -84,7 +85,7 @@ public class TypesResource {
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put("typeName", typeName); response.put("typeName", typeName);
response.put("types", typesAdded); response.put("types", typesAdded);
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
return Response.ok(response).build(); return Response.ok(response).build();
} catch (Exception e) { } catch (Exception e) {
...@@ -110,7 +111,7 @@ public class TypesResource { ...@@ -110,7 +111,7 @@ public class TypesResource {
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put("typeName", typeName); response.put("typeName", typeName);
response.put("definition", typeDefinition); response.put("definition", typeDefinition);
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
return Response.ok(response).build(); return Response.ok(response).build();
} catch (MetadataException e) { } catch (MetadataException e) {
...@@ -135,9 +136,9 @@ public class TypesResource { ...@@ -135,9 +136,9 @@ public class TypesResource {
final List<String> typeNamesList = metadataService.getTypeNamesList(); final List<String> typeNamesList = metadataService.getTypeNamesList();
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.RESULTS, new JSONArray(typeNamesList)); response.put(MetadataServiceClient.RESULTS, new JSONArray(typeNamesList));
response.put(Servlets.TOTAL_SIZE, typeNamesList.size()); response.put(MetadataServiceClient.TOTAL_SIZE, typeNamesList.size());
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
return Response.ok(response).build(); return Response.ok(response).build();
} catch (Exception e) { } catch (Exception e) {
...@@ -158,9 +159,9 @@ public class TypesResource { ...@@ -158,9 +159,9 @@ public class TypesResource {
final List<String> traitNamesList = metadataService.getTraitNamesList(); final List<String> traitNamesList = metadataService.getTraitNamesList();
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put(Servlets.RESULTS, new JSONArray(traitNamesList)); response.put(MetadataServiceClient.RESULTS, new JSONArray(traitNamesList));
response.put(Servlets.TOTAL_SIZE, traitNamesList.size()); response.put(MetadataServiceClient.TOTAL_SIZE, traitNamesList.size());
response.put(Servlets.REQUEST_ID, Servlets.getRequestId()); response.put(MetadataServiceClient.REQUEST_ID, Servlets.getRequestId());
return Response.ok(response).build(); return Response.ok(response).build();
} catch (Exception e) { } catch (Exception e) {
......
...@@ -33,10 +33,6 @@ import java.io.StringWriter; ...@@ -33,10 +33,6 @@ import java.io.StringWriter;
*/ */
public final class Servlets { public final class Servlets {
public static final String REQUEST_ID = "requestId";
public static final String RESULTS = "results";
public static final String TOTAL_SIZE = "totalSize";
private Servlets() { private Servlets() {
/* singleton */ /* singleton */
} }
......
...@@ -22,6 +22,7 @@ import com.sun.jersey.api.client.Client; ...@@ -22,6 +22,7 @@ import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.DefaultClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig;
import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.typesystem.types.TypeSystem; import org.apache.hadoop.metadata.typesystem.types.TypeSystem;
import org.apache.hadoop.metadata.web.util.Servlets; import org.apache.hadoop.metadata.web.util.Servlets;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
...@@ -37,6 +38,7 @@ public abstract class BaseResourceIT { ...@@ -37,6 +38,7 @@ public abstract class BaseResourceIT {
protected TypeSystem typeSystem; protected TypeSystem typeSystem;
protected WebResource service; protected WebResource service;
protected MetadataServiceClient serviceClient;
public void setUp() throws Exception { public void setUp() throws Exception {
typeSystem = TypeSystem.getInstance(); typeSystem = TypeSystem.getInstance();
...@@ -49,6 +51,7 @@ public abstract class BaseResourceIT { ...@@ -49,6 +51,7 @@ public abstract class BaseResourceIT {
client.resource(UriBuilder.fromUri(baseUrl).build()); client.resource(UriBuilder.fromUri(baseUrl).build());
service = client.resource(UriBuilder.fromUri(baseUrl).build()); service = client.resource(UriBuilder.fromUri(baseUrl).build());
serviceClient = new MetadataServiceClient(baseUrl);
} }
protected void sumbitType(String typesAsJSON, String type) throws Exception { protected void sumbitType(String typesAsJSON, String type) throws Exception {
...@@ -68,6 +71,6 @@ public abstract class BaseResourceIT { ...@@ -68,6 +71,6 @@ public abstract class BaseResourceIT {
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertEquals(response.get("typeName"), type); Assert.assertEquals(response.get("typeName"), type);
Assert.assertNotNull(response.get("types")); Assert.assertNotNull(response.get("types"));
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
} }
} }
...@@ -21,6 +21,8 @@ package org.apache.hadoop.metadata.web.resources; ...@@ -21,6 +21,8 @@ package org.apache.hadoop.metadata.web.resources;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.MetadataServiceException;
import org.apache.hadoop.metadata.typesystem.ITypedInstance; import org.apache.hadoop.metadata.typesystem.ITypedInstance;
import org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance; import org.apache.hadoop.metadata.typesystem.ITypedReferenceableInstance;
import org.apache.hadoop.metadata.typesystem.ITypedStruct; import org.apache.hadoop.metadata.typesystem.ITypedStruct;
...@@ -81,40 +83,28 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -81,40 +83,28 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
submitTypes(); submitTypes();
} }
private ClientResponse submit(ITypedReferenceableInstance instance) { private JSONObject submit(ITypedReferenceableInstance instance) throws MetadataServiceException {
String instanceAsJSON = Serialization$.MODULE$.toJson(instance); String instanceAsJSON = Serialization$.MODULE$.toJson(instance);
LOG.debug("instanceAsJSON = " + instanceAsJSON); return serviceClient.createEntity(instance.getTypeName(), instanceAsJSON);
WebResource resource = service
.path("api/metadata/entities/submit")
.path(instance.getTypeName());
return resource.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.method(HttpMethod.POST, ClientResponse.class, instanceAsJSON);
} }
@Test @Test
public void testSubmitEntity() throws Exception { public void testSubmitEntity() throws Exception {
tableInstance = createHiveTableInstance(); tableInstance = createHiveTableInstance();
ClientResponse clientResponse = submit(tableInstance); JSONObject clientResponse = submit(tableInstance);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
guid = getGuid(clientResponse); guid = getGuid(clientResponse);
try { try {
Assert.assertNotNull(UUID.fromString(guid)); Assert.assertNotNull(UUID.fromString(guid));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Assert.fail("Response is not a guid, " + clientResponse.getEntity(String.class)); Assert.fail("Response is not a guid, " + guid);
} }
} }
private String getGuid(ClientResponse clientResponse) throws JSONException { private String getGuid(JSONObject response) throws JSONException {
String responseAsString = clientResponse.getEntity(String.class); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); String guid = response.get(MetadataServiceClient.RESULTS).toString();
Assert.assertNotNull(response.get(Servlets.REQUEST_ID));
String guid = response.get(Servlets.RESULTS).toString();
Assert.assertNotNull(guid); Assert.assertNotNull(guid);
return guid; return guid;
} }
...@@ -151,12 +141,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -151,12 +141,11 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
ClassType classType = typeSystem.getDataType(ClassType.class, DATABASE_TYPE); ClassType classType = typeSystem.getDataType(ClassType.class, DATABASE_TYPE);
ITypedReferenceableInstance dbInstance = classType.convert(databaseInstance, Multiplicity.REQUIRED); ITypedReferenceableInstance dbInstance = classType.convert(databaseInstance, Multiplicity.REQUIRED);
ClientResponse clientResponse = submit(dbInstance); JSONObject json = submit(dbInstance);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); String dbId = getGuid(json);
String dbId = getGuid(clientResponse);
//Add reference property //Add reference property
clientResponse = addProperty(guid, "database", dbId); ClientResponse clientResponse = addProperty(guid, "database", dbId);
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
} }
...@@ -169,9 +158,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -169,9 +158,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
final String definition = response.getString(Servlets.RESULTS); final String definition = response.getString(MetadataServiceClient.RESULTS);
Assert.assertNotNull(definition); Assert.assertNotNull(definition);
LOG.debug("tableInstanceAfterGet = " + definition); LOG.debug("tableInstanceAfterGet = " + definition);
...@@ -183,7 +172,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -183,7 +172,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/addProperty") .path("api/metadata/entities/update")
.path(guid); .path(guid);
return resource.queryParam("property", property).queryParam("value", value) return resource.queryParam("property", property).queryParam("value", value)
...@@ -204,7 +193,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -204,7 +193,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
private ITypedReferenceableInstance getEntityDefinition(ClientResponse clientResponse) throws Exception { private ITypedReferenceableInstance getEntityDefinition(ClientResponse clientResponse) throws Exception {
Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode()); Assert.assertEquals(clientResponse.getStatus(), Response.Status.OK.getStatusCode());
JSONObject response = new JSONObject(clientResponse.getEntity(String.class)); JSONObject response = new JSONObject(clientResponse.getEntity(String.class));
final String definition = response.getString(Servlets.RESULTS); final String definition = response.getString(MetadataServiceClient.RESULTS);
Assert.assertNotNull(definition); Assert.assertNotNull(definition);
return Serialization.fromJson(definition); return Serialization.fromJson(definition);
} }
...@@ -263,9 +252,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -263,9 +252,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(Servlets.RESULTS); final JSONArray list = response.getJSONArray(MetadataServiceClient.RESULTS);
Assert.assertNotNull(list); Assert.assertNotNull(list);
Assert.assertEquals(list.length(), 1); Assert.assertEquals(list.length(), 1);
} }
...@@ -299,9 +288,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -299,9 +288,9 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(Servlets.RESULTS); final JSONArray list = response.getJSONArray(MetadataServiceClient.RESULTS);
Assert.assertEquals(list.length(), 0); Assert.assertEquals(list.length(), 0);
} }
...@@ -330,10 +319,10 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -330,10 +319,10 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
Assert.assertNotNull(response.get("GUID")); Assert.assertNotNull(response.get("GUID"));
final JSONArray list = response.getJSONArray(Servlets.RESULTS); final JSONArray list = response.getJSONArray(MetadataServiceClient.RESULTS);
Assert.assertEquals(list.length(), 7); Assert.assertEquals(list.length(), 7);
} }
...@@ -365,7 +354,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -365,7 +354,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
Assert.assertNotNull(response.get("GUID")); Assert.assertNotNull(response.get("GUID"));
Assert.assertNotNull(response.get("traitInstance")); Assert.assertNotNull(response.get("traitInstance"));
} }
...@@ -412,7 +401,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT { ...@@ -412,7 +401,7 @@ public class EntityJerseyResourceIT extends BaseResourceIT {
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
Assert.assertNotNull(response.get("GUID")); Assert.assertNotNull(response.get("GUID"));
Assert.assertNotNull(response.get("traitName")); Assert.assertNotNull(response.get("traitName"));
} }
......
...@@ -21,6 +21,7 @@ package org.apache.hadoop.metadata.web.resources; ...@@ -21,6 +21,7 @@ package org.apache.hadoop.metadata.web.resources;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.typesystem.Struct; import org.apache.hadoop.metadata.typesystem.Struct;
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;
...@@ -78,12 +79,12 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT { ...@@ -78,12 +79,12 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT {
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
Assert.assertEquals(response.getString("query"), dslQuery); Assert.assertEquals(response.getString("query"), dslQuery);
Assert.assertEquals(response.getString("queryType"), "dsl"); Assert.assertEquals(response.getString("queryType"), "dsl");
JSONObject results = response.getJSONObject(Servlets.RESULTS); JSONObject results = response.getJSONObject(MetadataServiceClient.RESULTS);
Assert.assertNotNull(results); Assert.assertNotNull(results);
JSONArray rows = results.getJSONArray("rows"); JSONArray rows = results.getJSONArray("rows");
...@@ -122,7 +123,7 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT { ...@@ -122,7 +123,7 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT {
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
Assert.assertEquals(response.getString("query"), query); Assert.assertEquals(response.getString("query"), query);
Assert.assertEquals(response.getString("queryType"), "gremlin"); Assert.assertEquals(response.getString("queryType"), "gremlin");
...@@ -145,7 +146,7 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT { ...@@ -145,7 +146,7 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT {
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
Assert.assertEquals(response.getString("query"), query); Assert.assertEquals(response.getString("query"), query);
Assert.assertEquals(response.getString("queryType"), "dsl"); Assert.assertEquals(response.getString("queryType"), "dsl");
...@@ -253,9 +254,9 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT { ...@@ -253,9 +254,9 @@ public class MetadataDiscoveryResourceIT extends BaseResourceIT {
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
String guid = response.get(Servlets.RESULTS).toString(); String guid = response.get(MetadataServiceClient.RESULTS).toString();
Assert.assertNotNull(guid); Assert.assertNotNull(guid);
} }
......
...@@ -21,6 +21,7 @@ package org.apache.hadoop.metadata.web.resources; ...@@ -21,6 +21,7 @@ package org.apache.hadoop.metadata.web.resources;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.WebResource;
import org.apache.hadoop.metadata.MetadataServiceClient;
import org.apache.hadoop.metadata.typesystem.json.TypesSerialization; import org.apache.hadoop.metadata.typesystem.json.TypesSerialization;
import org.apache.hadoop.metadata.typesystem.json.TypesSerialization$; import org.apache.hadoop.metadata.typesystem.json.TypesSerialization$;
import org.apache.hadoop.metadata.typesystem.types.AttributeDefinition; import org.apache.hadoop.metadata.typesystem.types.AttributeDefinition;
...@@ -85,7 +86,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -85,7 +86,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertEquals(response.get("typeName"), typeDefinition.typeName); Assert.assertEquals(response.get("typeName"), typeDefinition.typeName);
Assert.assertNotNull(response.get("types")); Assert.assertNotNull(response.get("types"));
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
} }
} }
...@@ -110,7 +111,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -110,7 +111,7 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertEquals(response.get("typeName"), typeDefinition.typeName); Assert.assertEquals(response.get("typeName"), typeDefinition.typeName);
Assert.assertNotNull(response.get("definition")); Assert.assertNotNull(response.get("definition"));
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
} }
} }
...@@ -142,9 +143,9 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -142,9 +143,9 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(Servlets.RESULTS); final JSONArray list = response.getJSONArray(MetadataServiceClient.RESULTS);
Assert.assertNotNull(list); Assert.assertNotNull(list);
} }
...@@ -165,9 +166,9 @@ public class TypesJerseyResourceIT extends BaseResourceIT { ...@@ -165,9 +166,9 @@ public class TypesJerseyResourceIT extends BaseResourceIT {
Assert.assertNotNull(responseAsString); Assert.assertNotNull(responseAsString);
JSONObject response = new JSONObject(responseAsString); JSONObject response = new JSONObject(responseAsString);
Assert.assertNotNull(response.get(Servlets.REQUEST_ID)); Assert.assertNotNull(response.get(MetadataServiceClient.REQUEST_ID));
final JSONArray list = response.getJSONArray(Servlets.RESULTS); final JSONArray list = response.getJSONArray(MetadataServiceClient.RESULTS);
Assert.assertNotNull(list); Assert.assertNotNull(list);
Assert.assertTrue(list.length() >= traitsAdded.length); Assert.assertTrue(list.length() >= traitsAdded.length);
} }
......
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