HBASE-18518 Remove jersey1* dependencies form project and jersey1* jars from lib dir.

This patch removes jersey1 dependencies form hbase REST project also
removes dead code in hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ResourceConfig.java and prevents jersey1 jars in lib dir. RESTApiClusterManager.java is modified to use jersey2.

Signed-off-by: Michael Stack <stack@apache.org>
This commit is contained in:
Samir Ahmic 2017-08-06 16:16:18 +02:00 committed by Michael Stack
parent 2af2b4c040
commit 7fee03ed65
5 changed files with 23 additions and 52 deletions

View File

@ -59,6 +59,8 @@
<dependencySet> <dependencySet>
<excludes> <excludes>
<exclude>org.jruby:jruby-complete</exclude> <exclude>org.jruby:jruby-complete</exclude>
<exclude>com.sun.jersey:*</exclude>
<exclude>com.sun.jersey.contribs:*</exclude>
</excludes> </excludes>
</dependencySet> </dependencySet>
</dependencySets> </dependencySets>

View File

@ -18,10 +18,6 @@
package org.apache.hadoop.hbase; package org.apache.hadoop.hbase;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
@ -29,7 +25,12 @@ import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.util.ReflectionUtils; import org.apache.hadoop.util.ReflectionUtils;
import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.ObjectMapper;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
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;
@ -91,7 +92,7 @@ public class RESTApiClusterManager extends Configured implements ClusterManager
private static final String API_VERSION = "v6"; private static final String API_VERSION = "v6";
// Client instances are expensive, so use the same one for all our REST queries. // Client instances are expensive, so use the same one for all our REST queries.
private Client client = Client.create(); private Client client = ClientBuilder.newClient();
// An instance of HBaseClusterManager is used for methods like the kill, resume, and suspend // An instance of HBaseClusterManager is used for methods like the kill, resume, and suspend
// because cluster managers don't tend to implement these operations. // because cluster managers don't tend to implement these operations.
@ -117,7 +118,7 @@ public class RESTApiClusterManager extends Configured implements ClusterManager
clusterName = conf.get(REST_API_CLUSTER_MANAGER_CLUSTER_NAME, DEFAULT_CLUSTER_NAME); clusterName = conf.get(REST_API_CLUSTER_MANAGER_CLUSTER_NAME, DEFAULT_CLUSTER_NAME);
// Add filter to Client instance to enable server authentication. // Add filter to Client instance to enable server authentication.
client.addFilter(new HTTPBasicAuthFilter(serverUsername, serverPassword)); client.register(HttpAuthenticationFeature.basic(serverUsername, serverPassword));
} }
@Override @Override
@ -193,10 +194,9 @@ public class RESTApiClusterManager extends Configured implements ClusterManager
.build(); .build();
String body = "{ \"items\": [ \"" + roleName + "\" ] }"; String body = "{ \"items\": [ \"" + roleName + "\" ] }";
LOG.info("Executing POST against " + uri + " with body " + body + "..."); LOG.info("Executing POST against " + uri + " with body " + body + "...");
ClientResponse response = client.resource(uri) WebTarget webTarget = client.target(uri);
.type(MediaType.APPLICATION_JSON) Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
.post(ClientResponse.class, body); Response response = invocationBuilder.post(Entity.json(body));
int statusCode = response.getStatus(); int statusCode = response.getStatus();
if (statusCode != Response.Status.OK.getStatusCode()) { if (statusCode != Response.Status.OK.getStatusCode()) {
throw new HTTPException(statusCode); throw new HTTPException(statusCode);
@ -237,16 +237,16 @@ public class RESTApiClusterManager extends Configured implements ClusterManager
// Execute GET against URI, returning a JsonNode object to be traversed. // Execute GET against URI, returning a JsonNode object to be traversed.
private JsonNode getJsonNodeFromURIGet(URI uri) throws IOException { private JsonNode getJsonNodeFromURIGet(URI uri) throws IOException {
LOG.info("Executing GET against " + uri + "..."); LOG.info("Executing GET against " + uri + "...");
ClientResponse response = client.resource(uri) WebTarget webTarget = client.target(uri);
.accept(MediaType.APPLICATION_JSON_TYPE) Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON);
.get(ClientResponse.class); Response response = invocationBuilder.get();
int statusCode = response.getStatus(); int statusCode = response.getStatus();
if (statusCode != Response.Status.OK.getStatusCode()) { if (statusCode != Response.Status.OK.getStatusCode()) {
throw new HTTPException(statusCode); throw new HTTPException(statusCode);
} }
// This API folds information as the value to an "items" attribute. // This API folds information as the value to an "items" attribute.
return new ObjectMapper().readTree(response.getEntity(String.class)).get("items"); return new ObjectMapper().readTree(response.readEntity(String.class)).get("items");
} }
// This API assigns a unique role name to each host's instance of a role. // This API assigns a unique role name to each host's instance of a role.

View File

@ -1,31 +0,0 @@
/*
*
* 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.hbase.rest;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import com.sun.jersey.api.core.PackagesResourceConfig;
@InterfaceAudience.Private
public class ResourceConfig extends PackagesResourceConfig {
public ResourceConfig() {
super("org.apache.hadoop.hbase.rest");
}
}

View File

@ -31,8 +31,8 @@ import org.apache.hadoop.hbase.rest.ProtobufMessageHandler;
import org.apache.hadoop.hbase.rest.RESTServlet; import org.apache.hadoop.hbase.rest.RESTServlet;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil; import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.rest.protobuf.generated.VersionMessage.Version; import org.apache.hadoop.hbase.rest.protobuf.generated.VersionMessage.Version;
import org.glassfish.jersey.servlet.ServletContainer;
import com.sun.jersey.spi.container.servlet.ServletContainer;
/** /**
* A representation of the collection of versions of the REST gateway software * A representation of the collection of versions of the REST gateway software
@ -75,7 +75,7 @@ public class VersionModel implements Serializable, ProtobufMessageHandler {
System.getProperty("os.version") + ' ' + System.getProperty("os.version") + ' ' +
System.getProperty("os.arch"); System.getProperty("os.arch");
serverVersion = context.getServerInfo(); serverVersion = context.getServerInfo();
jerseyVersion = ServletContainer.class.getPackage() jerseyVersion = ServletContainer.class.getClass().getPackage()
.getImplementationVersion(); .getImplementationVersion();
} }

View File

@ -35,6 +35,7 @@ import org.apache.hadoop.hbase.rest.model.VersionModel;
import org.apache.hadoop.hbase.testclassification.MediumTests; import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.testclassification.RestTests; import org.apache.hadoop.hbase.testclassification.RestTests;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.glassfish.jersey.servlet.ServletContainer;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -42,7 +43,6 @@ import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import com.sun.jersey.spi.container.servlet.ServletContainer;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
@Category({RestTests.class, MediumTests.class}) @Category({RestTests.class, MediumTests.class})
@ -89,7 +89,7 @@ public class TestVersionResource {
assertNotNull(model.getServerVersion()); assertNotNull(model.getServerVersion());
String jerseyVersion = model.getJerseyVersion(); String jerseyVersion = model.getJerseyVersion();
assertNotNull(jerseyVersion); assertNotNull(jerseyVersion);
assertEquals(jerseyVersion, ServletContainer.class.getPackage() assertEquals(jerseyVersion, ServletContainer.class.getClass().getPackage()
.getImplementationVersion()); .getImplementationVersion());
} }
@ -107,7 +107,7 @@ public class TestVersionResource {
assertTrue(body.contains(System.getProperty("os.name"))); assertTrue(body.contains(System.getProperty("os.name")));
assertTrue(body.contains(System.getProperty("os.version"))); assertTrue(body.contains(System.getProperty("os.version")));
assertTrue(body.contains(System.getProperty("os.arch"))); assertTrue(body.contains(System.getProperty("os.arch")));
assertTrue(body.contains(ServletContainer.class.getPackage() assertTrue(body.contains(ServletContainer.class.getClass().getPackage()
.getImplementationVersion())); .getImplementationVersion()));
} }