From 7fee03ed65af53618d206aed159ab4f2ccb464e1 Mon Sep 17 00:00:00 2001 From: Samir Ahmic Date: Sun, 6 Aug 2017 16:16:18 +0200 Subject: [PATCH] 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 --- .../src/main/assembly/hadoop-two-compat.xml | 2 ++ .../hadoop/hbase/RESTApiClusterManager.java | 32 +++++++++---------- .../hadoop/hbase/rest/ResourceConfig.java | 31 ------------------ .../hadoop/hbase/rest/model/VersionModel.java | 4 +-- .../hbase/rest/TestVersionResource.java | 6 ++-- 5 files changed, 23 insertions(+), 52 deletions(-) delete mode 100644 hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ResourceConfig.java diff --git a/hbase-assembly/src/main/assembly/hadoop-two-compat.xml b/hbase-assembly/src/main/assembly/hadoop-two-compat.xml index 3b8908c7756..8039c4d3681 100644 --- a/hbase-assembly/src/main/assembly/hadoop-two-compat.xml +++ b/hbase-assembly/src/main/assembly/hadoop-two-compat.xml @@ -59,6 +59,8 @@ org.jruby:jruby-complete + com.sun.jersey:* + com.sun.jersey.contribs:* diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/RESTApiClusterManager.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/RESTApiClusterManager.java index 03ba4606d95..055b58a0818 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/RESTApiClusterManager.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/RESTApiClusterManager.java @@ -18,10 +18,6 @@ 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.LogFactory; import org.apache.hadoop.conf.Configuration; @@ -29,7 +25,12 @@ import org.apache.hadoop.conf.Configured; import org.apache.hadoop.util.ReflectionUtils; import org.codehaus.jackson.JsonNode; 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.Response; import javax.ws.rs.core.UriBuilder; @@ -91,7 +92,7 @@ public class RESTApiClusterManager extends Configured implements ClusterManager private static final String API_VERSION = "v6"; // 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 // 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); // Add filter to Client instance to enable server authentication. - client.addFilter(new HTTPBasicAuthFilter(serverUsername, serverPassword)); + client.register(HttpAuthenticationFeature.basic(serverUsername, serverPassword)); } @Override @@ -193,10 +194,9 @@ public class RESTApiClusterManager extends Configured implements ClusterManager .build(); String body = "{ \"items\": [ \"" + roleName + "\" ] }"; LOG.info("Executing POST against " + uri + " with body " + body + "..."); - ClientResponse response = client.resource(uri) - .type(MediaType.APPLICATION_JSON) - .post(ClientResponse.class, body); - + WebTarget webTarget = client.target(uri); + Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON); + Response response = invocationBuilder.post(Entity.json(body)); int statusCode = response.getStatus(); if (statusCode != Response.Status.OK.getStatusCode()) { 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. private JsonNode getJsonNodeFromURIGet(URI uri) throws IOException { LOG.info("Executing GET against " + uri + "..."); - ClientResponse response = client.resource(uri) - .accept(MediaType.APPLICATION_JSON_TYPE) - .get(ClientResponse.class); - + WebTarget webTarget = client.target(uri); + Invocation.Builder invocationBuilder = webTarget.request(MediaType.APPLICATION_JSON); + Response response = invocationBuilder.get(); int statusCode = response.getStatus(); if (statusCode != Response.Status.OK.getStatusCode()) { throw new HTTPException(statusCode); } // 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. diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ResourceConfig.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ResourceConfig.java deleted file mode 100644 index d3973991b3c..00000000000 --- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ResourceConfig.java +++ /dev/null @@ -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"); - } -} diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/model/VersionModel.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/model/VersionModel.java index a82bb93205c..177e06a0dc0 100644 --- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/model/VersionModel.java +++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/model/VersionModel.java @@ -31,8 +31,8 @@ import org.apache.hadoop.hbase.rest.ProtobufMessageHandler; import org.apache.hadoop.hbase.rest.RESTServlet; import org.apache.hadoop.hbase.protobuf.ProtobufUtil; 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 @@ -75,7 +75,7 @@ public class VersionModel implements Serializable, ProtobufMessageHandler { System.getProperty("os.version") + ' ' + System.getProperty("os.arch"); serverVersion = context.getServerInfo(); - jerseyVersion = ServletContainer.class.getPackage() + jerseyVersion = ServletContainer.class.getClass().getPackage() .getImplementationVersion(); } diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestVersionResource.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestVersionResource.java index 34973c2c026..b96a5d5a2a7 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestVersionResource.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestVersionResource.java @@ -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.RestTests; import org.apache.hadoop.hbase.util.Bytes; +import org.glassfish.jersey.servlet.ServletContainer; import static org.junit.Assert.*; @@ -42,7 +43,6 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import com.sun.jersey.spi.container.servlet.ServletContainer; import org.junit.experimental.categories.Category; @Category({RestTests.class, MediumTests.class}) @@ -89,7 +89,7 @@ public class TestVersionResource { assertNotNull(model.getServerVersion()); String jerseyVersion = model.getJerseyVersion(); assertNotNull(jerseyVersion); - assertEquals(jerseyVersion, ServletContainer.class.getPackage() + assertEquals(jerseyVersion, ServletContainer.class.getClass().getPackage() .getImplementationVersion()); } @@ -107,7 +107,7 @@ public class TestVersionResource { assertTrue(body.contains(System.getProperty("os.name"))); assertTrue(body.contains(System.getProperty("os.version"))); assertTrue(body.contains(System.getProperty("os.arch"))); - assertTrue(body.contains(ServletContainer.class.getPackage() + assertTrue(body.contains(ServletContainer.class.getClass().getPackage() .getImplementationVersion())); }