HDFS-12489. Ozone: OzoneRestClientException swallows exceptions which makes client hard to debug failures. Contributed by Weiwei Yang.
This commit is contained in:
parent
c329d3b4b4
commit
8ddf75da17
@ -190,7 +190,7 @@ public void putKey(String keyName, String data) throws OzoneException {
|
|||||||
}
|
}
|
||||||
executePutKey(putRequest, httpClient);
|
executePutKey(putRequest, httpClient);
|
||||||
} catch (IOException | URISyntaxException ex) {
|
} catch (IOException | URISyntaxException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeStream(is);
|
IOUtils.closeStream(is);
|
||||||
OzoneClientUtils.releaseConnection(putRequest);
|
OzoneClientUtils.releaseConnection(putRequest);
|
||||||
@ -321,7 +321,7 @@ public void getKey(String keyName, Path downloadTo) throws OzoneException {
|
|||||||
executeGetKey(getRequest, httpClient, outPutFile);
|
executeGetKey(getRequest, httpClient, outPutFile);
|
||||||
outPutFile.flush();
|
outPutFile.flush();
|
||||||
} catch (IOException | URISyntaxException ex) {
|
} catch (IOException | URISyntaxException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeStream(outPutFile);
|
IOUtils.closeStream(outPutFile);
|
||||||
OzoneClientUtils.releaseConnection(getRequest);
|
OzoneClientUtils.releaseConnection(getRequest);
|
||||||
@ -355,7 +355,7 @@ public String getKey(String keyName) throws OzoneException {
|
|||||||
executeGetKey(getRequest, httpClient, outPutStream);
|
executeGetKey(getRequest, httpClient, outPutStream);
|
||||||
return outPutStream.toString(ENCODING_NAME);
|
return outPutStream.toString(ENCODING_NAME);
|
||||||
} catch (IOException | URISyntaxException ex) {
|
} catch (IOException | URISyntaxException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeStream(outPutStream);
|
IOUtils.closeStream(outPutStream);
|
||||||
OzoneClientUtils.releaseConnection(getRequest);
|
OzoneClientUtils.releaseConnection(getRequest);
|
||||||
@ -422,7 +422,7 @@ public void deleteKey(String keyName) throws OzoneException {
|
|||||||
.getClient().getHttpDelete(builder.toString());
|
.getClient().getHttpDelete(builder.toString());
|
||||||
executeDeleteKey(deleteRequest, httpClient);
|
executeDeleteKey(deleteRequest, httpClient);
|
||||||
} catch (IOException | URISyntaxException ex) {
|
} catch (IOException | URISyntaxException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(deleteRequest);
|
OzoneClientUtils.releaseConnection(deleteRequest);
|
||||||
}
|
}
|
||||||
@ -500,7 +500,7 @@ public List<OzoneKey> listKeys(String resultLength, String previousKey,
|
|||||||
return executeListKeys(getRequest, httpClient);
|
return executeListKeys(getRequest, httpClient);
|
||||||
|
|
||||||
} catch (IOException | URISyntaxException e) {
|
} catch (IOException | URISyntaxException e) {
|
||||||
throw new OzoneRestClientException(e.getMessage());
|
throw new OzoneRestClientException(e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(getRequest);
|
OzoneClientUtils.releaseConnection(getRequest);
|
||||||
}
|
}
|
||||||
@ -570,7 +570,7 @@ public OzoneKey getKeyInfo(String keyName) throws OzoneException {
|
|||||||
getRequest = client.getHttpGet(builder.toString());
|
getRequest = client.getHttpGet(builder.toString());
|
||||||
return executeGetKeyInfo(getRequest, httpClient);
|
return executeGetKeyInfo(getRequest, httpClient);
|
||||||
} catch (IOException | URISyntaxException e) {
|
} catch (IOException | URISyntaxException e) {
|
||||||
throw new OzoneRestClientException(e.getMessage());
|
throw new OzoneRestClientException(e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(getRequest);
|
OzoneClientUtils.releaseConnection(getRequest);
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ public OzoneVolume createVolume(String volumeName, String onBehalfOf,
|
|||||||
executeCreateVolume(httpPost, httpClient);
|
executeCreateVolume(httpPost, httpClient);
|
||||||
return getVolume(volumeName);
|
return getVolume(volumeName);
|
||||||
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
|
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(httpPost);
|
OzoneClientUtils.releaseConnection(httpPost);
|
||||||
}
|
}
|
||||||
@ -194,7 +194,7 @@ public OzoneVolume getVolume(String volumeName) throws OzoneException {
|
|||||||
httpGet = getHttpGet(builder.toString());
|
httpGet = getHttpGet(builder.toString());
|
||||||
return executeInfoVolume(httpGet, httpClient);
|
return executeInfoVolume(httpGet, httpClient);
|
||||||
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
|
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(httpGet);
|
OzoneClientUtils.releaseConnection(httpGet);
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ public List<OzoneVolume> listVolumes(String onBehalfOf, String prefix,
|
|||||||
}
|
}
|
||||||
return executeListVolume(httpGet, httpClient);
|
return executeListVolume(httpGet, httpClient);
|
||||||
} catch (IOException | URISyntaxException ex) {
|
} catch (IOException | URISyntaxException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(httpGet);
|
OzoneClientUtils.releaseConnection(httpGet);
|
||||||
}
|
}
|
||||||
@ -327,7 +327,7 @@ public List<OzoneVolume> listAllVolumes(String prefix, int maxKeys,
|
|||||||
return executeListVolume(httpGet, httpClient);
|
return executeListVolume(httpGet, httpClient);
|
||||||
|
|
||||||
} catch (IOException | URISyntaxException ex) {
|
} catch (IOException | URISyntaxException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(httpGet);
|
OzoneClientUtils.releaseConnection(httpGet);
|
||||||
}
|
}
|
||||||
@ -349,7 +349,7 @@ public void deleteVolume(String volumeName) throws OzoneException {
|
|||||||
httpDelete = getHttpDelete(builder.toString());
|
httpDelete = getHttpDelete(builder.toString());
|
||||||
executeDeleteVolume(httpDelete, httpClient);
|
executeDeleteVolume(httpDelete, httpClient);
|
||||||
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
|
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(httpDelete);
|
OzoneClientUtils.releaseConnection(httpDelete);
|
||||||
}
|
}
|
||||||
@ -378,7 +378,7 @@ public void setVolumeOwner(String volumeName, String newOwner)
|
|||||||
executePutVolume(putRequest, httpClient);
|
executePutVolume(putRequest, httpClient);
|
||||||
|
|
||||||
} catch (URISyntaxException | IllegalArgumentException | IOException ex) {
|
} catch (URISyntaxException | IllegalArgumentException | IOException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(putRequest);
|
OzoneClientUtils.releaseConnection(putRequest);
|
||||||
}
|
}
|
||||||
@ -411,7 +411,7 @@ public void setVolumeQuota(String volumeName, String quota)
|
|||||||
executePutVolume(putRequest, httpClient);
|
executePutVolume(putRequest, httpClient);
|
||||||
|
|
||||||
} catch (URISyntaxException | IllegalArgumentException | IOException ex) {
|
} catch (URISyntaxException | IllegalArgumentException | IOException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(putRequest);
|
OzoneClientUtils.releaseConnection(putRequest);
|
||||||
}
|
}
|
||||||
@ -617,7 +617,7 @@ public void putKey(String volumeName, String bucketName, String keyName,
|
|||||||
putRequest.setHeader(Header.CONTENT_MD5, DigestUtils.md5Hex(fis));
|
putRequest.setHeader(Header.CONTENT_MD5, DigestUtils.md5Hex(fis));
|
||||||
OzoneBucket.executePutKey(putRequest, httpClient);
|
OzoneBucket.executePutKey(putRequest, httpClient);
|
||||||
} catch (IOException | URISyntaxException ex) {
|
} catch (IOException | URISyntaxException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeStream(fis);
|
IOUtils.closeStream(fis);
|
||||||
OzoneClientUtils.releaseConnection(putRequest);
|
OzoneClientUtils.releaseConnection(putRequest);
|
||||||
@ -659,7 +659,7 @@ public void getKey(String volumeName, String bucketName, String keyName,
|
|||||||
OzoneBucket.executeGetKey(getRequest, httpClient, outPutFile);
|
OzoneBucket.executeGetKey(getRequest, httpClient, outPutFile);
|
||||||
outPutFile.flush();
|
outPutFile.flush();
|
||||||
} catch (IOException | URISyntaxException ex) {
|
} catch (IOException | URISyntaxException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
IOUtils.closeStream(outPutFile);
|
IOUtils.closeStream(outPutFile);
|
||||||
OzoneClientUtils.releaseConnection(getRequest);
|
OzoneClientUtils.releaseConnection(getRequest);
|
||||||
@ -704,7 +704,7 @@ public List<OzoneKey> listKeys(String volumeName, String bucketName,
|
|||||||
getRequest = getHttpGet(builder.toString());
|
getRequest = getHttpGet(builder.toString());
|
||||||
return OzoneBucket.executeListKeys(getRequest, httpClient);
|
return OzoneBucket.executeListKeys(getRequest, httpClient);
|
||||||
} catch (IOException | URISyntaxException e) {
|
} catch (IOException | URISyntaxException e) {
|
||||||
throw new OzoneRestClientException(e.getMessage());
|
throw new OzoneRestClientException(e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(getRequest);
|
OzoneClientUtils.releaseConnection(getRequest);
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,16 @@ public OzoneRestClientException(String shortMessage) {
|
|||||||
super(0, shortMessage, shortMessage);
|
super(0, shortMessage, shortMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor that allows a shortMessage and an exception.
|
||||||
|
*
|
||||||
|
* @param shortMessage short message
|
||||||
|
* @param ex exception
|
||||||
|
*/
|
||||||
|
public OzoneRestClientException(String shortMessage, Exception ex) {
|
||||||
|
super(0, shortMessage, shortMessage, ex);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor that allows the shortMessage and a longer message.
|
* Constructor that allows the shortMessage and a longer message.
|
||||||
*
|
*
|
||||||
|
@ -201,7 +201,7 @@ public OzoneBucket createBucket(String bucketName, String[] acls,
|
|||||||
executeCreateBucket(httpPost, httpClient);
|
executeCreateBucket(httpPost, httpClient);
|
||||||
return getBucket(bucketName);
|
return getBucket(bucketName);
|
||||||
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
|
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(httpPost);
|
OzoneClientUtils.releaseConnection(httpPost);
|
||||||
}
|
}
|
||||||
@ -305,7 +305,7 @@ public void addAcls(String bucketName, String[] acls) throws OzoneException {
|
|||||||
}
|
}
|
||||||
executePutBucket(putRequest, httpClient);
|
executePutBucket(putRequest, httpClient);
|
||||||
} catch (URISyntaxException | IOException ex) {
|
} catch (URISyntaxException | IOException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(putRequest);
|
OzoneClientUtils.releaseConnection(putRequest);
|
||||||
}
|
}
|
||||||
@ -334,7 +334,7 @@ public void removeAcls(String bucketName, String[] acls)
|
|||||||
}
|
}
|
||||||
executePutBucket(putRequest, httpClient);
|
executePutBucket(putRequest, httpClient);
|
||||||
} catch (URISyntaxException | IOException ex) {
|
} catch (URISyntaxException | IOException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(putRequest);
|
OzoneClientUtils.releaseConnection(putRequest);
|
||||||
}
|
}
|
||||||
@ -359,7 +359,7 @@ public OzoneBucket getBucket(String bucketName) throws OzoneException {
|
|||||||
return executeInfoBucket(getRequest, httpClient);
|
return executeInfoBucket(getRequest, httpClient);
|
||||||
|
|
||||||
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
|
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(getRequest);
|
OzoneClientUtils.releaseConnection(getRequest);
|
||||||
}
|
}
|
||||||
@ -465,7 +465,7 @@ public List<OzoneBucket> listBuckets(String resultLength,
|
|||||||
return executeListBuckets(getRequest, httpClient);
|
return executeListBuckets(getRequest, httpClient);
|
||||||
|
|
||||||
} catch (IOException | URISyntaxException e) {
|
} catch (IOException | URISyntaxException e) {
|
||||||
throw new OzoneRestClientException(e.getMessage());
|
throw new OzoneRestClientException(e.getMessage(), e);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(getRequest);
|
OzoneClientUtils.releaseConnection(getRequest);
|
||||||
}
|
}
|
||||||
@ -533,7 +533,7 @@ public void deleteBucket(String bucketName) throws OzoneException {
|
|||||||
executeDeleteBucket(delRequest, httpClient);
|
executeDeleteBucket(delRequest, httpClient);
|
||||||
|
|
||||||
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
|
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
|
||||||
throw new OzoneRestClientException(ex.getMessage());
|
throw new OzoneRestClientException(ex.getMessage(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
OzoneClientUtils.releaseConnection(delRequest);
|
OzoneClientUtils.releaseConnection(delRequest);
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
*/
|
*/
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
public class OzoneException extends Exception {
|
public class OzoneException extends Exception {
|
||||||
|
|
||||||
private static final ObjectReader READER =
|
private static final ObjectReader READER =
|
||||||
new ObjectMapper().readerFor(OzoneException.class);
|
new ObjectMapper().readerFor(OzoneException.class);
|
||||||
private static final ObjectMapper MAPPER;
|
private static final ObjectMapper MAPPER;
|
||||||
@ -113,7 +114,23 @@ public OzoneException(long httpCode, String shortMessage, String message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Resource that was involved in the exception.
|
* Constructor that allows a shortMessage, a long message and an exception.
|
||||||
|
*
|
||||||
|
* @param httpCode Error code
|
||||||
|
* @param shortMessage Short message
|
||||||
|
* @param message Long error message
|
||||||
|
* @param ex Exception
|
||||||
|
*/
|
||||||
|
public OzoneException(long httpCode, String shortMessage,
|
||||||
|
String message, Exception ex) {
|
||||||
|
super(ex);
|
||||||
|
this.shortMessage = shortMessage;
|
||||||
|
this.message = message;
|
||||||
|
this.httpCode = httpCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Resource that was involved in the stackTraceString.
|
||||||
*
|
*
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
|
@ -402,6 +402,7 @@ private int dispatch(CommandLine cmd, Options opts)
|
|||||||
System.err.printf("Command Failed : %s%n", ex.getMessage());
|
System.err.printf("Command Failed : %s%n", ex.getMessage());
|
||||||
} catch (OzoneException ex) {
|
} catch (OzoneException ex) {
|
||||||
System.err.printf("Command Failed : %s%n", ex.toJsonString());
|
System.err.printf("Command Failed : %s%n", ex.toJsonString());
|
||||||
|
ex.printStackTrace(System.err);
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
System.err.printf("Illegal argument: %s%n", ex.getMessage());
|
System.err.printf("Illegal argument: %s%n", ex.getMessage());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user