HDFS-12031. Ozone: Rename OzoneClient to OzoneRestClient. Contributed by Nandakumar.

This commit is contained in:
Weiwei Yang 2017-06-28 23:57:34 +08:00 committed by Owen O'Malley
parent 7e834c839d
commit 8ef1163eca
25 changed files with 141 additions and 136 deletions

View File

@ -150,11 +150,11 @@ public class OzoneBucket {
*/
public void putKey(String keyName, String data) throws OzoneException {
if ((keyName == null) || keyName.isEmpty()) {
throw new OzoneClientException("Invalid key Name.");
throw new OzoneRestClientException("Invalid key Name.");
}
if (data == null) {
throw new OzoneClientException("Invalid data.");
throw new OzoneRestClientException("Invalid data.");
}
HttpPut putRequest = null;
@ -176,7 +176,7 @@ public class OzoneBucket {
}
executePutKey(putRequest, httpClient);
} catch (IOException | URISyntaxException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
IOUtils.closeStream(is);
OzoneClientUtils.releaseConnection(putRequest);
@ -192,7 +192,7 @@ public class OzoneBucket {
*/
public void putKey(File dataFile) throws OzoneException {
if (dataFile == null) {
throw new OzoneClientException("Invalid file object.");
throw new OzoneRestClientException("Invalid file object.");
}
String keyName = dataFile.getName();
putKey(keyName, dataFile);
@ -209,11 +209,11 @@ public class OzoneBucket {
throws OzoneException {
if ((keyName == null) || keyName.isEmpty()) {
throw new OzoneClientException("Invalid key Name");
throw new OzoneRestClientException("Invalid key Name");
}
if (file == null) {
throw new OzoneClientException("Invalid data stream");
throw new OzoneRestClientException("Invalid data stream");
}
HttpPut putRequest = null;
@ -234,7 +234,7 @@ public class OzoneBucket {
executePutKey(putRequest, httpClient);
} catch (IOException | URISyntaxException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
IOUtils.closeStream(fis);
OzoneClientUtils.releaseConnection(putRequest);
@ -262,7 +262,7 @@ public class OzoneBucket {
}
if (entity == null) {
throw new OzoneClientException("Unexpected null in http payload");
throw new OzoneRestClientException("Unexpected null in http payload");
}
throw OzoneException.parse(EntityUtils.toString(entity));
@ -283,11 +283,11 @@ public class OzoneBucket {
public void getKey(String keyName, Path downloadTo) throws OzoneException {
if ((keyName == null) || keyName.isEmpty()) {
throw new OzoneClientException("Invalid key Name");
throw new OzoneRestClientException("Invalid key Name");
}
if (downloadTo == null) {
throw new OzoneClientException("Invalid download path");
throw new OzoneRestClientException("Invalid download path");
}
FileOutputStream outPutFile = null;
@ -303,7 +303,7 @@ public class OzoneBucket {
executeGetKey(getRequest, httpClient, outPutFile);
outPutFile.flush();
} catch (IOException | URISyntaxException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
IOUtils.closeStream(outPutFile);
OzoneClientUtils.releaseConnection(getRequest);
@ -320,7 +320,7 @@ public class OzoneBucket {
public String getKey(String keyName) throws OzoneException {
if ((keyName == null) || keyName.isEmpty()) {
throw new OzoneClientException("Invalid key Name");
throw new OzoneRestClientException("Invalid key Name");
}
HttpGet getRequest = null;
@ -337,7 +337,7 @@ public class OzoneBucket {
executeGetKey(getRequest, httpClient, outPutStream);
return outPutStream.toString(ENCODING_NAME);
} catch (IOException | URISyntaxException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
IOUtils.closeStream(outPutStream);
OzoneClientUtils.releaseConnection(getRequest);
@ -371,7 +371,7 @@ public class OzoneBucket {
}
if (entity == null) {
throw new OzoneClientException("Unexpected null in http payload");
throw new OzoneRestClientException("Unexpected null in http payload");
}
throw OzoneException.parse(EntityUtils.toString(entity));
@ -391,7 +391,7 @@ public class OzoneBucket {
public void deleteKey(String keyName) throws OzoneException {
if ((keyName == null) || keyName.isEmpty()) {
throw new OzoneClientException("Invalid key Name");
throw new OzoneRestClientException("Invalid key Name");
}
HttpDelete deleteRequest = null;
@ -404,7 +404,7 @@ public class OzoneBucket {
.getClient().getHttpDelete(builder.toString());
executeDeleteKey(deleteRequest, httpClient);
} catch (IOException | URISyntaxException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
OzoneClientUtils.releaseConnection(deleteRequest);
}
@ -434,7 +434,7 @@ public class OzoneBucket {
}
if (entity == null) {
throw new OzoneClientException("Unexpected null in http payload");
throw new OzoneRestClientException("Unexpected null in http payload");
}
throw OzoneException.parse(EntityUtils.toString(entity));
@ -453,7 +453,7 @@ public class OzoneBucket {
public List<OzoneKey> listKeys() throws OzoneException {
HttpGet getRequest = null;
try (CloseableHttpClient httpClient = OzoneClientUtils.newHttpClient()) {
OzoneClient client = getVolume().getClient();
OzoneRestClient client = getVolume().getClient();
URIBuilder builder = new URIBuilder(volume.getClient().getEndPointURI());
builder.setPath("/" + getVolume().getVolumeName() + "/" + getBucketName())
.build();
@ -462,7 +462,7 @@ public class OzoneBucket {
return executeListKeys(getRequest, httpClient);
} catch (IOException | URISyntaxException e) {
throw new OzoneClientException(e.getMessage());
throw new OzoneRestClientException(e.getMessage());
} finally {
OzoneClientUtils.releaseConnection(getRequest);
}
@ -489,7 +489,7 @@ public class OzoneBucket {
entity = response.getEntity();
if (entity == null) {
throw new OzoneClientException("Unexpected null in http payload");
throw new OzoneRestClientException("Unexpected null in http payload");
}
if (errorCode == HTTP_OK) {
String temp = EntityUtils.toString(entity);

View File

@ -54,28 +54,28 @@ import static java.net.HttpURLConnection.HTTP_OK;
* Ozone client that connects to an Ozone server. Please note that this class is
* not thread safe.
*/
public class OzoneClient implements Closeable {
public class OzoneRestClient implements Closeable {
private URI endPointURI;
private String userAuth;
/**
* Constructor for OzoneClient.
* Constructor for OzoneRestClient.
*/
public OzoneClient() {
public OzoneRestClient() {
}
/**
* Constructor for OzoneClient.
* Constructor for OzoneRestClient.
*/
public OzoneClient(String ozoneURI)
public OzoneRestClient(String ozoneURI)
throws OzoneException, URISyntaxException {
setEndPoint(ozoneURI);
}
/**
* Constructor for OzoneClient.
* Constructor for OzoneRestClient.
*/
public OzoneClient(String ozoneURI, String userAuth)
public OzoneRestClient(String ozoneURI, String userAuth)
throws OzoneException, URISyntaxException {
setEndPoint(ozoneURI);
setUserAuth(userAuth);
@ -98,7 +98,7 @@ public class OzoneClient implements Closeable {
*/
public void setEndPointURI(URI endPointURI) throws OzoneException {
if ((endPointURI == null) || (endPointURI.toString().isEmpty())) {
throw new OzoneClientException("Invalid ozone URI");
throw new OzoneRestClientException("Invalid ozone URI");
}
this.endPointURI = endPointURI;
}
@ -138,7 +138,7 @@ public class OzoneClient implements Closeable {
* @param onBehalfOf - The user on behalf we are making the call for
* @param quota - Quota's are specified in a specific format. it is
* integer(MB|GB|TB), for example 100TB.
* @throws OzoneClientException
* @throws OzoneRestClientException
*/
public OzoneVolume createVolume(String volumeName, String onBehalfOf,
String quota) throws OzoneException {
@ -156,7 +156,7 @@ public class OzoneClient implements Closeable {
executeCreateVolume(httpPost, httpClient);
return getVolume(volumeName);
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
OzoneClientUtils.releaseConnection(httpPost);
}
@ -183,7 +183,7 @@ public class OzoneClient implements Closeable {
httpGet = getHttpGet(builder.toString());
return executeInfoVolume(httpGet, httpClient);
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
OzoneClientUtils.releaseConnection(httpGet);
}
@ -232,7 +232,7 @@ public class OzoneClient implements Closeable {
}
return executeListVolume(httpGet, httpClient);
} catch (IOException | URISyntaxException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
OzoneClientUtils.releaseConnection(httpGet);
}
@ -286,7 +286,7 @@ public class OzoneClient implements Closeable {
return executeListVolume(httpGet, httpClient);
} catch (IOException | URISyntaxException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
OzoneClientUtils.releaseConnection(httpGet);
}
@ -308,7 +308,7 @@ public class OzoneClient implements Closeable {
httpDelete = getHttpDelete(builder.toString());
executeDeleteVolume(httpDelete, httpClient);
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
OzoneClientUtils.releaseConnection(httpDelete);
}
@ -325,7 +325,7 @@ public class OzoneClient implements Closeable {
throws OzoneException {
HttpPut putRequest = null;
if (newOwner == null || newOwner.isEmpty()) {
throw new OzoneClientException("Invalid new owner name");
throw new OzoneRestClientException("Invalid new owner name");
}
try (CloseableHttpClient httpClient = newHttpClient()) {
OzoneUtils.verifyBucketName(volumeName);
@ -337,7 +337,7 @@ public class OzoneClient implements Closeable {
executePutVolume(putRequest, httpClient);
} catch (URISyntaxException | IllegalArgumentException | IOException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
OzoneClientUtils.releaseConnection(putRequest);
}
@ -356,7 +356,7 @@ public class OzoneClient implements Closeable {
public void setVolumeQuota(String volumeName, String quota)
throws OzoneException {
if (quota == null || quota.isEmpty()) {
throw new OzoneClientException("Invalid quota");
throw new OzoneRestClientException("Invalid quota");
}
HttpPut putRequest = null;
try (CloseableHttpClient httpClient = newHttpClient()) {
@ -370,7 +370,7 @@ public class OzoneClient implements Closeable {
executePutVolume(putRequest, httpClient);
} catch (URISyntaxException | IllegalArgumentException | IOException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
OzoneClientUtils.releaseConnection(putRequest);
}
@ -400,7 +400,7 @@ public class OzoneClient implements Closeable {
if (entity != null) {
throw OzoneException.parse(EntityUtils.toString(entity));
} else {
throw new OzoneClientException("Unexpected null in http payload");
throw new OzoneRestClientException("Unexpected null in http payload");
}
} finally {
if (entity != null) {
@ -427,7 +427,7 @@ public class OzoneClient implements Closeable {
entity = response.getEntity();
if (entity == null) {
throw new OzoneClientException("Unexpected null in http payload");
throw new OzoneRestClientException("Unexpected null in http payload");
}
if (errorCode == HTTP_OK) {
@ -488,7 +488,7 @@ public class OzoneClient implements Closeable {
entity = response.getEntity();
if (entity == null) {
throw new OzoneClientException("Unexpected null in http payload");
throw new OzoneRestClientException("Unexpected null in http payload");
}
String temp = EntityUtils.toString(entity);

View File

@ -22,13 +22,13 @@ import org.apache.hadoop.ozone.web.exceptions.OzoneException;
/**
* This exception is thrown by the Ozone Clients.
*/
public class OzoneClientException extends OzoneException {
public class OzoneRestClientException extends OzoneException {
/**
* Constructor that allows the shortMessage.
*
* @param shortMessage Short Message
*/
public OzoneClientException(String shortMessage) {
public OzoneRestClientException(String shortMessage) {
super(0, shortMessage, shortMessage);
}
@ -38,7 +38,7 @@ public class OzoneClientException extends OzoneException {
* @param shortMessage Short Message
* @param message long error message
*/
public OzoneClientException(String shortMessage, String message) {
public OzoneRestClientException(String shortMessage, String message) {
super(0, shortMessage, message);
}
}

View File

@ -55,12 +55,12 @@ import static java.net.HttpURLConnection.HTTP_OK;
public class OzoneVolume {
private VolumeInfo volumeInfo;
private Map<String, String> headerMap;
private final OzoneClient client;
private final OzoneRestClient client;
/**
* Constructor for OzoneVolume.
*/
public OzoneVolume(OzoneClient client) {
public OzoneVolume(OzoneRestClient client) {
this.client = client;
this.headerMap = new HashMap<>();
}
@ -71,7 +71,7 @@ public class OzoneVolume {
* @param volInfo - volume Info.
* @param client Client
*/
public OzoneVolume(VolumeInfo volInfo, OzoneClient client) {
public OzoneVolume(VolumeInfo volInfo, OzoneRestClient client) {
this.volumeInfo = volInfo;
this.client = client;
}
@ -145,7 +145,7 @@ public class OzoneVolume {
*
* @return - Ozone Client
*/
OzoneClient getClient() {
OzoneRestClient getClient() {
return client;
}
@ -184,7 +184,7 @@ public class OzoneVolume {
executeCreateBucket(httpPost, httpClient);
return getBucket(bucketName);
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
OzoneClientUtils.releaseConnection(httpPost);
}
@ -257,7 +257,7 @@ public class OzoneVolume {
if (entity != null) {
throw OzoneException.parse(EntityUtils.toString(entity));
} else {
throw new OzoneClientException("Unexpected null in http payload");
throw new OzoneRestClientException("Unexpected null in http payload");
}
} finally {
if (entity != null) {
@ -288,7 +288,7 @@ public class OzoneVolume {
}
executePutBucket(putRequest, httpClient);
} catch (URISyntaxException | IOException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
OzoneClientUtils.releaseConnection(putRequest);
}
@ -317,7 +317,7 @@ public class OzoneVolume {
}
executePutBucket(putRequest, httpClient);
} catch (URISyntaxException | IOException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
OzoneClientUtils.releaseConnection(putRequest);
}
@ -342,7 +342,7 @@ public class OzoneVolume {
return executeInfoBucket(getRequest, httpClient);
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
OzoneClientUtils.releaseConnection(getRequest);
}
@ -369,7 +369,7 @@ public class OzoneVolume {
int errorCode = response.getStatusLine().getStatusCode();
entity = response.getEntity();
if (entity == null) {
throw new OzoneClientException("Unexpected null in http payload");
throw new OzoneRestClientException("Unexpected null in http payload");
}
if ((errorCode == HTTP_OK) || (errorCode == HTTP_CREATED)) {
OzoneBucket bucket =
@ -413,7 +413,7 @@ public class OzoneVolume {
throw OzoneException.parse(EntityUtils.toString(entity));
}
throw new OzoneClientException("Unexpected null in http result");
throw new OzoneRestClientException("Unexpected null in http result");
} finally {
if (entity != null) {
EntityUtils.consumeQuietly(entity);
@ -438,7 +438,7 @@ public class OzoneVolume {
return executeListBuckets(getRequest, httpClient);
} catch (IOException | URISyntaxException e) {
throw new OzoneClientException(e.getMessage());
throw new OzoneRestClientException(e.getMessage());
} finally {
OzoneClientUtils.releaseConnection(getRequest);
}
@ -467,7 +467,7 @@ public class OzoneVolume {
entity = response.getEntity();
if (entity == null) {
throw new OzoneClientException("Unexpected null in http payload");
throw new OzoneRestClientException("Unexpected null in http payload");
}
if (errorCode == HTTP_OK) {
ListBuckets bucketList =
@ -506,7 +506,7 @@ public class OzoneVolume {
executeDeleteBucket(delRequest, httpClient);
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
throw new OzoneClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage());
} finally {
OzoneClientUtils.releaseConnection(delRequest);
}
@ -535,7 +535,7 @@ public class OzoneVolume {
}
if (entity == null) {
throw new OzoneClientException("Unexpected null in http payload.");
throw new OzoneRestClientException("Unexpected null in http payload.");
}
throw OzoneException.parse(EntityUtils.toString(entity));

View File

@ -19,8 +19,8 @@
package org.apache.hadoop.ozone.web.ozShell;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneClient;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClient;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.http.client.utils.URIBuilder;
@ -32,13 +32,13 @@ import java.net.URISyntaxException;
* Common interface for command handling.
*/
public abstract class Handler {
protected OzoneClient client;
protected OzoneRestClient client;
/**
* Constructs a client object.
*/
public Handler() {
client = new OzoneClient();
client = new OzoneRestClient();
}
/**
@ -63,7 +63,7 @@ public abstract class Handler {
protected URI verifyURI(String uri) throws URISyntaxException,
OzoneException {
if ((uri == null) || uri.isEmpty()) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Ozone URI is needed to execute this command.");
}
URIBuilder ozoneURI = new URIBuilder(uri);

View File

@ -19,7 +19,7 @@ package org.apache.hadoop.ozone.web.ozShell.bucket;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneBucket;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.client.OzoneVolume;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
@ -54,7 +54,7 @@ public class CreateBucketHandler extends Handler {
protected void execute(CommandLine cmd)
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.CREATE_BUCKET)) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Incorrect call : createBucket is missing");
}
@ -62,7 +62,7 @@ public class CreateBucketHandler extends Handler {
URI ozoneURI = verifyURI(ozoneURIString);
Path path = Paths.get(ozoneURI.getPath());
if (path.getNameCount() < 2) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"volume and bucket name required in createBucket");
}

View File

@ -19,7 +19,7 @@
package org.apache.hadoop.ozone.web.ozShell.bucket;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.client.OzoneVolume;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
@ -52,7 +52,7 @@ public class DeleteBucketHandler extends Handler {
protected void execute(CommandLine cmd)
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.DELETE_BUCKET)) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Incorrect call : deleteBucket is missing");
}
@ -60,7 +60,7 @@ public class DeleteBucketHandler extends Handler {
URI ozoneURI = verifyURI(ozoneURIString);
Path path = Paths.get(ozoneURI.getPath());
if (path.getNameCount() < 2) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"volume and bucket name required in delete Bucket");
}

View File

@ -20,7 +20,7 @@ package org.apache.hadoop.ozone.web.ozShell.bucket;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneBucket;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.client.OzoneVolume;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
@ -54,7 +54,7 @@ public class InfoBucketHandler extends Handler {
protected void execute(CommandLine cmd)
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.INFO_BUCKET)) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Incorrect call : infoBucket is missing");
}
@ -63,7 +63,7 @@ public class InfoBucketHandler extends Handler {
Path path = Paths.get(ozoneURI.getPath());
if (path.getNameCount() < 2) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"volume and bucket name required in info Bucket");
}

View File

@ -20,7 +20,7 @@ package org.apache.hadoop.ozone.web.ozShell.bucket;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneBucket;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.client.OzoneVolume;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
@ -54,14 +54,15 @@ public class ListBucketHandler extends Handler {
protected void execute(CommandLine cmd)
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.LIST_BUCKET)) {
throw new OzoneClientException("Incorrect call : listBucket is missing");
throw new OzoneRestClientException(
"Incorrect call : listBucket is missing");
}
String ozoneURIString = cmd.getOptionValue(Shell.LIST_BUCKET);
URI ozoneURI = verifyURI(ozoneURIString);
Path path = Paths.get(ozoneURI.getPath());
if (path.getNameCount() < 1) {
throw new OzoneClientException("volume is required in listBucket");
throw new OzoneRestClientException("volume is required in listBucket");
}
volumeName = path.getName(0).toString();

View File

@ -19,7 +19,7 @@ package org.apache.hadoop.ozone.web.ozShell.bucket;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneBucket;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.client.OzoneVolume;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
@ -44,7 +44,7 @@ public class UpdateBucketHandler extends Handler {
protected void execute(CommandLine cmd)
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.UPDATE_BUCKET)) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Incorrect call : updateBucket is missing");
}
@ -53,7 +53,7 @@ public class UpdateBucketHandler extends Handler {
Path path = Paths.get(ozoneURI.getPath());
if (path.getNameCount() < 2) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"volume and bucket name required in update bucket");
}

View File

@ -20,7 +20,7 @@ package org.apache.hadoop.ozone.web.ozShell.keys;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneBucket;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.client.OzoneVolume;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
@ -53,7 +53,8 @@ public class DeleteKeyHandler extends Handler {
protected void execute(CommandLine cmd)
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.DELETE_KEY)) {
throw new OzoneClientException("Incorrect call : deleteKey is missing");
throw new OzoneRestClientException(
"Incorrect call : deleteKey is missing");
}
@ -68,7 +69,7 @@ public class DeleteKeyHandler extends Handler {
URI ozoneURI = verifyURI(ozoneURIString);
Path path = Paths.get(ozoneURI.getPath());
if (path.getNameCount() < 3) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"volume/bucket/key name required in deleteKey");
}

View File

@ -21,7 +21,7 @@ package org.apache.hadoop.ozone.web.ozShell.keys;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.hadoop.ozone.web.client.OzoneBucket;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.client.OzoneVolume;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
@ -58,11 +58,11 @@ public class GetKeyHandler extends Handler {
protected void execute(CommandLine cmd)
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.GET_KEY)) {
throw new OzoneClientException("Incorrect call : getKey is missing");
throw new OzoneRestClientException("Incorrect call : getKey is missing");
}
if (!cmd.hasOption(Shell.FILE)) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"get key needs a file path to download to");
}
@ -77,7 +77,7 @@ public class GetKeyHandler extends Handler {
URI ozoneURI = verifyURI(ozoneURIString);
Path path = Paths.get(ozoneURI.getPath());
if (path.getNameCount() < 3) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"volume/bucket/key name required in putKey");
}
@ -99,7 +99,7 @@ public class GetKeyHandler extends Handler {
if (dataFile.exists()) {
throw new OzoneClientException(fileName +
throw new OzoneRestClientException(fileName +
"exists. Download will overwrite an " +
"existing file. Aborting.");
}

View File

@ -19,7 +19,7 @@
package org.apache.hadoop.ozone.web.ozShell.keys;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
import org.apache.hadoop.ozone.web.ozShell.Shell;
@ -51,7 +51,7 @@ public class InfoKeyHandler extends Handler {
protected void execute(CommandLine cmd)
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.INFO_KEY)) {
throw new OzoneClientException("Incorrect call : infoKey is missing");
throw new OzoneRestClientException("Incorrect call : infoKey is missing");
}
@ -66,7 +66,7 @@ public class InfoKeyHandler extends Handler {
URI ozoneURI = verifyURI(ozoneURIString);
Path path = Paths.get(ozoneURI.getPath());
if (path.getNameCount() < 3) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"volume/bucket/key name required in infoKey");
}
@ -88,6 +88,6 @@ public class InfoKeyHandler extends Handler {
// OzoneVolume vol = client.getVolume(volumeName);
// OzoneBucket bucket = vol.createBucket(bucketName);
throw new OzoneClientException("Not supported yet");
throw new OzoneRestClientException("Not supported yet");
}
}

View File

@ -20,7 +20,7 @@ package org.apache.hadoop.ozone.web.ozShell.keys;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneBucket;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.client.OzoneKey;
import org.apache.hadoop.ozone.web.client.OzoneVolume;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
@ -56,14 +56,16 @@ public class ListKeyHandler extends Handler {
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.LIST_KEY)) {
throw new OzoneClientException("Incorrect call : listKey is missing");
throw new OzoneRestClientException(
"Incorrect call : listKey is missing");
}
String ozoneURIString = cmd.getOptionValue(Shell.LIST_KEY);
URI ozoneURI = verifyURI(ozoneURIString);
Path path = Paths.get(ozoneURI.getPath());
if (path.getNameCount() < 2) {
throw new OzoneClientException("volume/bucket is required in listKey");
throw new OzoneRestClientException(
"volume/bucket is required in listKey");
}
volumeName = path.getName(0).toString();

View File

@ -21,7 +21,7 @@ package org.apache.hadoop.ozone.web.ozShell.keys;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.hadoop.ozone.web.client.OzoneBucket;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.client.OzoneVolume;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
@ -56,11 +56,11 @@ public class PutKeyHandler extends Handler {
protected void execute(CommandLine cmd)
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.PUT_KEY)) {
throw new OzoneClientException("Incorrect call : putKey is missing");
throw new OzoneRestClientException("Incorrect call : putKey is missing");
}
if (!cmd.hasOption(Shell.FILE)) {
throw new OzoneClientException("put key needs a file to put");
throw new OzoneRestClientException("put key needs a file to put");
}
if (cmd.hasOption(Shell.USER)) {
@ -73,7 +73,7 @@ public class PutKeyHandler extends Handler {
URI ozoneURI = verifyURI(ozoneURIString);
Path path = Paths.get(ozoneURI.getPath());
if (path.getNameCount() < 3) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"volume/bucket/key name required in putKey");
}

View File

@ -19,7 +19,7 @@
package org.apache.hadoop.ozone.web.ozShell.volume;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.client.OzoneVolume;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
@ -52,14 +52,14 @@ public class CreateVolumeHandler extends Handler {
protected void execute(CommandLine cmd)
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.CREATE_VOLUME)) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Incorrect call : createVolume is missing");
}
String ozoneURIString = cmd.getOptionValue(Shell.CREATE_VOLUME);
URI ozoneURI = verifyURI(ozoneURIString);
if (ozoneURI.getPath().isEmpty()) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Volume name is required to create a volume");
}
@ -77,7 +77,7 @@ public class CreateVolumeHandler extends Handler {
}
if (!cmd.hasOption(Shell.USER)) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"User name is needed in createVolume call.");
}

View File

@ -19,7 +19,7 @@
package org.apache.hadoop.ozone.web.ozShell.volume;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
import org.apache.hadoop.ozone.web.ozShell.Shell;
@ -49,14 +49,14 @@ public class DeleteVolumeHandler extends Handler {
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.DELETE_VOLUME)) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Incorrect call : deleteVolume call is missing");
}
String ozoneURIString = cmd.getOptionValue(Shell.DELETE_VOLUME);
URI ozoneURI = verifyURI(ozoneURIString);
if (ozoneURI.getPath().isEmpty()) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Volume name is required to delete a volume");
}

View File

@ -19,7 +19,7 @@
package org.apache.hadoop.ozone.web.ozShell.volume;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.client.OzoneVolume;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
@ -53,14 +53,14 @@ public class InfoVolumeHandler extends Handler{
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.INFO_VOLUME)) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Incorrect call : infoVolume is missing");
}
String ozoneURIString = cmd.getOptionValue(Shell.INFO_VOLUME);
URI ozoneURI = verifyURI(ozoneURIString);
if (ozoneURI.getPath().isEmpty()) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Volume name is required to get info of a volume");
}

View File

@ -19,7 +19,7 @@
package org.apache.hadoop.ozone.web.ozShell.volume;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.client.OzoneVolume;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
@ -51,7 +51,7 @@ public class ListVolumeHandler extends Handler {
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.LIST_VOLUME)) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Incorrect call : listVolume is missing");
}
@ -63,7 +63,7 @@ public class ListVolumeHandler extends Handler {
}
if (!cmd.hasOption(Shell.USER)) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"User name is needed in listVolume call.");
}

View File

@ -19,7 +19,7 @@
package org.apache.hadoop.ozone.web.ozShell.volume;
import org.apache.commons.cli.CommandLine;
import org.apache.hadoop.ozone.web.client.OzoneClientException;
import org.apache.hadoop.ozone.web.client.OzoneRestClientException;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.ozone.web.ozShell.Handler;
import org.apache.hadoop.ozone.web.ozShell.Shell;
@ -49,14 +49,14 @@ public class UpdateVolumeHandler extends Handler {
protected void execute(CommandLine cmd)
throws IOException, OzoneException, URISyntaxException {
if (!cmd.hasOption(Shell.UPDATE_VOLUME)) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Incorrect call : updateVolume is missing");
}
String ozoneURIString = cmd.getOptionValue(Shell.UPDATE_VOLUME);
URI ozoneURI = verifyURI(ozoneURIString);
if (ozoneURI.getPath().isEmpty()) {
throw new OzoneClientException(
throw new OzoneRestClientException(
"Volume name is required to update a volume");
}

View File

@ -30,13 +30,13 @@ import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.ozone.container.ContainerTestHelper;
import org.apache.hadoop.ozone.ksm.KSMConfigKeys;
import org.apache.hadoop.ozone.ksm.KeySpaceManager;
import org.apache.hadoop.ozone.web.client.OzoneRestClient;
import org.apache.hadoop.scm.ScmConfigKeys;
import org.apache.hadoop.scm.protocolPB
.StorageContainerLocationProtocolClientSideTranslatorPB;
import org.apache.hadoop.scm.protocolPB.StorageContainerLocationProtocolPB;
import org.apache.hadoop.ozone.scm.StorageContainerManager;
import org.apache.hadoop.ozone.scm.node.SCMNodeManager;
import org.apache.hadoop.ozone.web.client.OzoneClient;
import org.apache.hadoop.ozone.web.exceptions.OzoneException;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.test.GenericTestUtils;
@ -170,15 +170,15 @@ public final class MiniOzoneCluster extends MiniDFSCluster
}
/**
* Creates an {@link OzoneClient} connected to this cluster's REST service.
* Callers take ownership of the client and must close it when done.
* Creates an {@link OzoneRestClient} connected to this cluster's REST
* service. Callers take ownership of the client and must close it when done.
*
* @return OzoneClient connected to this cluster's REST service
* @return OzoneRestClient connected to this cluster's REST service
* @throws OzoneException if Ozone encounters an error creating the client
*/
public OzoneClient createOzoneClient() throws OzoneException {
public OzoneRestClient createOzoneRestClient() throws OzoneException {
Preconditions.checkState(!getDataNodes().isEmpty(),
"Cannot create OzoneClient if the cluster has no DataNodes.");
"Cannot create OzoneRestClient if the cluster has no DataNodes.");
// An Ozone request may originate at any DataNode, so pick one at random.
int dnIndex = new Random().nextInt(getDataNodes().size());
String uri = String.format("http://127.0.0.1:%d",
@ -186,7 +186,7 @@ public final class MiniOzoneCluster extends MiniDFSCluster
LOG.info("Creating Ozone client to DataNode {} with URI {} and user {}",
dnIndex, uri, USER_AUTH);
try {
return new OzoneClient(uri, USER_AUTH);
return new OzoneRestClient(uri, USER_AUTH);
} catch (URISyntaxException e) {
// We control the REST service URI, so it should never be invalid.
throw new IllegalStateException("Unexpected URISyntaxException", e);

View File

@ -25,6 +25,7 @@ import static org.junit.Assert.*;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.hadoop.ozone.OzoneConsts;
import org.apache.hadoop.ozone.web.client.OzoneRestClient;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
@ -35,7 +36,6 @@ import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.ozone.MiniOzoneCluster;
import org.apache.hadoop.ozone.OzoneConfiguration;
import org.apache.hadoop.ozone.web.client.OzoneBucket;
import org.apache.hadoop.ozone.web.client.OzoneClient;
import org.apache.hadoop.ozone.web.client.OzoneVolume;
import org.apache.hadoop.ozone.web.request.OzoneQuota;
import org.junit.rules.Timeout;
@ -52,7 +52,7 @@ public class TestOzoneRestWithMiniCluster {
private static MiniOzoneCluster cluster;
private static OzoneConfiguration conf;
private static OzoneClient ozoneClient;
private static OzoneRestClient ozoneClient;
@Rule
public ExpectedException exception = ExpectedException.none();
@ -63,7 +63,7 @@ public class TestOzoneRestWithMiniCluster {
cluster = new MiniOzoneCluster.Builder(conf).numDataNodes(1)
.setHandlerType(OzoneConsts.OZONE_HANDLER_DISTRIBUTED).build();
cluster.waitOzoneReady();
ozoneClient = cluster.createOzoneClient();
ozoneClient = cluster.createOzoneRestClient();
}
@AfterClass

View File

@ -49,7 +49,7 @@ public class TestBuckets {
public Timeout testTimeout = new Timeout(300000);
private static MiniOzoneCluster cluster = null;
private static OzoneClient client = null;
private static OzoneRestClient client = null;
/**
* Create a MiniDFSCluster for testing.
@ -75,7 +75,7 @@ public class TestBuckets {
.setHandlerType(OzoneConsts.OZONE_HANDLER_LOCAL).build();
DataNode dataNode = cluster.getDataNodes().get(0);
final int port = dataNode.getInfoPort();
client = new OzoneClient(String.format("http://localhost:%d", port));
client = new OzoneRestClient(String.format("http://localhost:%d", port));
}
/**

View File

@ -60,7 +60,7 @@ public class TestKeys {
private static MiniOzoneCluster cluster = null;
static private String path;
private static OzoneClient client = null;
private static OzoneRestClient client = null;
/**
* Create a MiniDFSCluster for testing.
@ -85,7 +85,7 @@ public class TestKeys {
.setHandlerType(OzoneConsts.OZONE_HANDLER_LOCAL).build();
DataNode dataNode = cluster.getDataNodes().get(0);
final int port = dataNode.getInfoPort();
client = new OzoneClient(String.format("http://localhost:%d", port));
client = new OzoneRestClient(String.format("http://localhost:%d", port));
}
/**

View File

@ -55,7 +55,7 @@ import static org.mockito.Mockito.verify;
public class TestVolume {
private static MiniOzoneCluster cluster = null;
private static OzoneClient client = null;
private static OzoneRestClient client = null;
/**
* Create a MiniDFSCluster for testing.
@ -84,7 +84,7 @@ public class TestVolume {
DataNode dataNode = cluster.getDataNodes().get(0);
final int port = dataNode.getInfoPort();
client = new OzoneClient(String.format("http://localhost:%d", port));
client = new OzoneRestClient(String.format("http://localhost:%d", port));
}
/**
@ -102,7 +102,7 @@ public class TestVolume {
String volumeName = OzoneUtils.getRequestID().toLowerCase();
client.setUserAuth(OzoneConsts.OZONE_SIMPLE_HDFS_USER);
OzoneClient mockClient = Mockito.spy(client);
OzoneRestClient mockClient = Mockito.spy(client);
List<CloseableHttpClient> mockedClients = mockHttpClients(mockClient);
OzoneVolume vol = mockClient.createVolume(volumeName, "bilbo", "100TB");
// Verify http clients are properly closed.
@ -227,16 +227,17 @@ public class TestVolume {
/**
* Returns a list of mocked {@link CloseableHttpClient} used for testing.
* The mocked client replaces the actual calls in
* {@link OzoneClient#newHttpClient()}, it is used to verify
* {@link OzoneRestClient#newHttpClient()}, it is used to verify
* if the invocation of this client is expected. <b>Note</b>, the output
* of this method is always used as the input of
* {@link TestVolume#verifyHttpConnectionClosed(List)}.
*
* @param ozoneClient mocked ozone client.
* @param ozoneRestClient mocked ozone client.
* @return a list of mocked {@link CloseableHttpClient}.
* @throws IOException
*/
private List<CloseableHttpClient> mockHttpClients(OzoneClient ozoneClient)
private List<CloseableHttpClient> mockHttpClients(
OzoneRestClient ozoneRestClient)
throws IOException {
List<CloseableHttpClient> spyHttpClients = new ArrayList<>();
for (int i = 0; i < 5; i++) {
@ -247,7 +248,7 @@ public class TestVolume {
List<CloseableHttpClient> nextReturns =
new ArrayList<>(spyHttpClients.subList(1, spyHttpClients.size()));
Mockito.when(ozoneClient.newHttpClient()).thenReturn(
Mockito.when(ozoneRestClient.newHttpClient()).thenReturn(
spyHttpClients.get(0),
nextReturns.toArray(new CloseableHttpClient[nextReturns.size()]));
return spyHttpClients;
@ -255,7 +256,7 @@ public class TestVolume {
/**
* This method is used together with
* {@link TestVolume#mockHttpClients(OzoneClient)} to verify
* {@link TestVolume#mockHttpClients(OzoneRestClient)} to verify
* if the http client is properly closed. It verifies that as long as
* a client calls {@link CloseableHttpClient#execute(HttpUriRequest)} to
* send request, then it must calls {@link CloseableHttpClient#close()}