From e9d09c209ed015b53e0a654d5c643aca238e5330 Mon Sep 17 00:00:00 2001 From: Weiwei Yang Date: Thu, 18 May 2017 14:02:52 +0800 Subject: [PATCH] HDFS-11824. Ozone: Fix javac warnings. Contributed by Yiqun Lin. --- .../apache/hadoop/ozone/OzoneClientUtils.java | 2 +- .../hadoop/ozone/web/client/OzoneBucket.java | 28 ++++++++----------- .../hadoop/ozone/web/client/OzoneClient.java | 27 +++++++++--------- .../hadoop/ozone/web/client/OzoneVolume.java | 25 +++++++++-------- .../hadoop/ozone/web/TestOzoneHelper.java | 4 +-- .../hadoop/ozone/web/TestOzoneWebAccess.java | 8 +++--- 6 files changed, 46 insertions(+), 48 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/OzoneClientUtils.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/OzoneClientUtils.java index 79275ebd0eb..9476ef5c778 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/OzoneClientUtils.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/OzoneClientUtils.java @@ -281,7 +281,7 @@ public final class OzoneClientUtils { if ((value == null) || value.isEmpty()) { return Optional.absent(); } - return Optional.of(HostAndPort.fromString(value).getHostText()); + return Optional.of(HostAndPort.fromString(value).getHost()); } /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/client/OzoneBucket.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/client/OzoneBucket.java index 86b3d7c98cd..d12b6ddc43f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/client/OzoneBucket.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/client/OzoneBucket.java @@ -36,10 +36,10 @@ import org.apache.http.client.utils.URIBuilder; import org.apache.http.entity.ContentType; import org.apache.http.entity.FileEntity; import org.apache.http.entity.InputStreamEntity; -import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; -import javax.ws.rs.core.HttpHeaders; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -159,7 +159,7 @@ public class OzoneBucket { try { OzoneClient client = getVolume().getClient(); - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(volume.getClient().getEndPointURI()); builder.setPath("/" + getVolume().getVolumeName() + "/" + getBucketName() @@ -219,7 +219,7 @@ public class OzoneBucket { try { OzoneClient client = getVolume().getClient(); - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(volume.getClient().getEndPointURI()); builder.setPath("/" + getVolume().getVolumeName() + "/" + getBucketName() + "/" + keyName).build(); @@ -234,10 +234,6 @@ public class OzoneBucket { FileInputStream fis = new FileInputStream(file); putRequest.setHeader(Header.CONTENT_MD5, DigestUtils.md5Hex(fis)); fis.close(); - putRequest.setHeader(HttpHeaders.CONTENT_LENGTH, Long.toString(file - .length())); - httpClient.removeRequestInterceptorByClass( - org.apache.http.protocol.RequestContent.class); executePutKey(putRequest, httpClient); } catch (IOException | URISyntaxException ex) { @@ -253,7 +249,7 @@ public class OzoneBucket { * @throws OzoneException * @throws IOException */ - private void executePutKey(HttpPut putRequest, DefaultHttpClient httpClient) + private void executePutKey(HttpPut putRequest, CloseableHttpClient httpClient) throws OzoneException, IOException { HttpEntity entity = null; try { @@ -298,7 +294,7 @@ public class OzoneBucket { try { OzoneClient client = getVolume().getClient(); - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); FileOutputStream outPutFile = new FileOutputStream(downloadTo.toFile()); URIBuilder builder = new URIBuilder(volume.getClient().getEndPointURI()); @@ -332,7 +328,7 @@ public class OzoneBucket { OzoneClient client = getVolume().getClient(); ByteArrayOutputStream outPutStream = new ByteArrayOutputStream(); - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(volume.getClient().getEndPointURI()); builder.setPath("/" + getVolume().getVolumeName() + "/" + getBucketName() @@ -357,7 +353,7 @@ public class OzoneBucket { * @throws IOException * @throws OzoneException */ - private void executeGetKey(HttpGet getRequest, DefaultHttpClient httpClient, + private void executeGetKey(HttpGet getRequest, CloseableHttpClient httpClient, OutputStream stream) throws IOException, OzoneException { @@ -399,7 +395,7 @@ public class OzoneBucket { try { OzoneClient client = getVolume().getClient(); - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(volume.getClient().getEndPointURI()); builder.setPath("/" + getVolume().getVolumeName() + "/" + getBucketName() @@ -422,7 +418,7 @@ public class OzoneBucket { * @throws OzoneException */ private void executeDeleteKey(HttpDelete deleteRequest, - DefaultHttpClient httpClient) + CloseableHttpClient httpClient) throws IOException, OzoneException { HttpEntity entity = null; @@ -456,7 +452,7 @@ public class OzoneBucket { public List listKeys() throws OzoneException { try { OzoneClient client = getVolume().getClient(); - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(volume.getClient().getEndPointURI()); builder.setPath("/" + getVolume().getVolumeName() + "/" + getBucketName()) .build(); @@ -479,7 +475,7 @@ public class OzoneBucket { * @throws OzoneException */ private List executeListKeys(HttpGet getRequest, - DefaultHttpClient httpClient) + CloseableHttpClient httpClient) throws IOException, OzoneException { HttpEntity entity = null; List ozoneKeyList = new LinkedList(); diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/client/OzoneClient.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/client/OzoneClient.java index c150b45e31c..0fba35eba09 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/client/OzoneClient.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/client/OzoneClient.java @@ -31,7 +31,8 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.utils.URIBuilder; -import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import javax.ws.rs.core.HttpHeaders; @@ -142,7 +143,7 @@ public class OzoneClient implements Closeable { public OzoneVolume createVolume(String volumeName, String onBehalfOf, String quota) throws OzoneException { try { - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); OzoneUtils.verifyBucketName(volumeName); URIBuilder builder = new URIBuilder(endPointURI); @@ -169,7 +170,7 @@ public class OzoneClient implements Closeable { */ public OzoneVolume getVolume(String volumeName) throws OzoneException { try { - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); OzoneUtils.verifyBucketName(volumeName); URIBuilder builder = new URIBuilder(endPointURI); @@ -205,7 +206,7 @@ public class OzoneClient implements Closeable { public List listVolumes(String onBehalfOf, String prefix, int maxKeys, OzoneVolume prevKey) throws OzoneException { try { - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(endPointURI); if (prefix != null) { @@ -261,7 +262,7 @@ public class OzoneClient implements Closeable { public List listAllVolumes(String prefix, int maxKeys, OzoneVolume prevKey) throws OzoneException { try { - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(endPointURI); if (prefix != null) { @@ -296,7 +297,7 @@ public class OzoneClient implements Closeable { */ public void deleteVolume(String volumeName) throws OzoneException { try { - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); OzoneUtils.verifyBucketName(volumeName); URIBuilder builder = new URIBuilder(endPointURI); @@ -323,7 +324,7 @@ public class OzoneClient implements Closeable { throw new OzoneClientException("Invalid new owner name"); } try { - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); OzoneUtils.verifyBucketName(volumeName); URIBuilder builder = new URIBuilder(endPointURI); @@ -354,7 +355,7 @@ public class OzoneClient implements Closeable { throw new OzoneClientException("Invalid quota"); } try { - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); OzoneUtils.verifyBucketName(volumeName); URIBuilder builder = new URIBuilder(endPointURI); @@ -379,7 +380,7 @@ public class OzoneClient implements Closeable { * @throws OzoneException */ private void executeCreateVolume(HttpPost httppost, - DefaultHttpClient httpClient) + CloseableHttpClient httpClient) throws IOException, OzoneException { HttpEntity entity = null; try { @@ -412,7 +413,7 @@ public class OzoneClient implements Closeable { * @throws OzoneException */ private OzoneVolume executeInfoVolume(HttpGet httpGet, - DefaultHttpClient httpClient) + CloseableHttpClient httpClient) throws IOException, OzoneException { HttpEntity entity = null; try { @@ -446,7 +447,7 @@ public class OzoneClient implements Closeable { * @throws OzoneException */ private void executePutVolume(HttpPut putRequest, - DefaultHttpClient httpClient) + CloseableHttpClient httpClient) throws IOException, OzoneException { HttpEntity entity = null; try { @@ -472,7 +473,7 @@ public class OzoneClient implements Closeable { * @throws OzoneException */ private List executeListVolume(HttpGet httpGet, - DefaultHttpClient httpClient) + CloseableHttpClient httpClient) throws IOException, OzoneException { HttpEntity entity = null; List volList = new LinkedList<>(); @@ -513,7 +514,7 @@ public class OzoneClient implements Closeable { * @throws OzoneException */ private void executeDeleteVolume(HttpDelete httpDelete, - DefaultHttpClient httpClient) + CloseableHttpClient httpClient) throws IOException, OzoneException { HttpEntity entity = null; try { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/client/OzoneVolume.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/client/OzoneVolume.java index fd96c5ad864..c5284cd3984 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/client/OzoneVolume.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/ozone/web/client/OzoneVolume.java @@ -34,7 +34,8 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.utils.URIBuilder; -import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import java.io.IOException; @@ -165,7 +166,7 @@ public class OzoneVolume { try { OzoneUtils.verifyBucketName(bucketName); - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(getClient().getEndPointURI()); builder.setPath("/" + getVolumeName() + "/" + bucketName).build(); @@ -240,7 +241,7 @@ public class OzoneVolume { * @throws OzoneException */ private void executeCreateBucket(HttpPost httppost, - DefaultHttpClient httpClient) + CloseableHttpClient httpClient) throws IOException, OzoneException { HttpEntity entity = null; try { @@ -275,7 +276,7 @@ public class OzoneVolume { try { OzoneUtils.verifyBucketName(bucketName); - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(getClient().getEndPointURI()); builder.setPath("/" + getVolumeName() + "/" + bucketName).build(); HttpPut putRequest = client.getHttpPut(builder.toString()); @@ -302,7 +303,7 @@ public class OzoneVolume { throws OzoneException { try { OzoneUtils.verifyBucketName(bucketName); - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(getClient().getEndPointURI()); builder.setPath("/" + getVolumeName() + "/" + bucketName).build(); HttpPut putRequest = client.getHttpPut(builder.toString()); @@ -327,7 +328,7 @@ public class OzoneVolume { public OzoneBucket getBucket(String bucketName) throws OzoneException { try { OzoneUtils.verifyBucketName(bucketName); - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(getClient().getEndPointURI()); builder.setPath("/" + getVolumeName() + "/" + bucketName) .setParameter(Header.OZONE_LIST_QUERY_TAG, @@ -353,7 +354,7 @@ public class OzoneVolume { * @throws OzoneException */ private OzoneBucket executeInfoBucket(HttpGet getRequest, - DefaultHttpClient httpClient) + CloseableHttpClient httpClient) throws IOException, OzoneException { HttpEntity entity = null; try { @@ -389,7 +390,7 @@ public class OzoneVolume { * @throws OzoneException */ private void executePutBucket(HttpPut putRequest, - DefaultHttpClient httpClient) + CloseableHttpClient httpClient) throws IOException, OzoneException { HttpEntity entity = null; try { @@ -422,7 +423,7 @@ public class OzoneVolume { */ public List listBuckets() throws OzoneException { try { - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(getClient().getEndPointURI()); builder.setPath("/" + getVolumeName()).build(); @@ -447,7 +448,7 @@ public class OzoneVolume { * @throws OzoneException */ private List executeListBuckets(HttpGet getRequest, - DefaultHttpClient httpClient) + CloseableHttpClient httpClient) throws IOException, OzoneException { HttpEntity entity = null; List ozoneBucketList = new LinkedList(); @@ -489,7 +490,7 @@ public class OzoneVolume { public void deleteBucket(String bucketName) throws OzoneException { try { OzoneUtils.verifyBucketName(bucketName); - DefaultHttpClient httpClient = new DefaultHttpClient(); + CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(getClient().getEndPointURI()); builder.setPath("/" + getVolumeName() + "/" + bucketName).build(); @@ -511,7 +512,7 @@ public class OzoneVolume { * @throws OzoneException */ private void executeDeleteBucket(HttpDelete delRequest, - DefaultHttpClient httpClient) + CloseableHttpClient httpClient) throws IOException, OzoneException { HttpEntity entity = null; try { diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestOzoneHelper.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestOzoneHelper.java index 73955969064..791504e3fb2 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestOzoneHelper.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestOzoneHelper.java @@ -26,7 +26,7 @@ import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; import javax.ws.rs.core.HttpHeaders; import java.io.IOException; @@ -44,7 +44,7 @@ import static org.junit.Assert.assertEquals; public class TestOzoneHelper { public CloseableHttpClient createHttpClient() { - return HttpClientBuilder.create().build(); + return HttpClients.createDefault(); } /** * Creates Volumes on Ozone Store. diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestOzoneWebAccess.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestOzoneWebAccess.java index 639c80cc9a3..f7e54c77de9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestOzoneWebAccess.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/ozone/web/TestOzoneWebAccess.java @@ -27,9 +27,9 @@ import org.apache.hadoop.ozone.web.headers.Header; import org.apache.hadoop.test.GenericTestUtils; import org.apache.hadoop.util.Time; import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; -import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; @@ -98,7 +98,7 @@ public class TestOzoneWebAccess { public void testOzoneRequest() throws IOException { SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ZZZ", Locale.US); - HttpClient client = new DefaultHttpClient(); + CloseableHttpClient client = HttpClients.createDefault(); String volumeName = getRequestID().toLowerCase(Locale.US); try { HttpPost httppost = new HttpPost( @@ -117,7 +117,7 @@ public class TestOzoneWebAccess { assertEquals(response.toString(), HTTP_CREATED, response.getStatusLine().getStatusCode()); } finally { - client.getConnectionManager().shutdown(); + client.close(); } } }