HDFS-12489. Ozone: OzoneRestClientException swallows exceptions which makes client hard to debug failures. Contributed by Weiwei Yang.

This commit is contained in:
Weiwei Yang 2017-09-20 10:42:58 +08:00 committed by Owen O'Malley
parent c329d3b4b4
commit 8ddf75da17
6 changed files with 51 additions and 23 deletions

View File

@ -190,7 +190,7 @@ public void putKey(String keyName, String data) throws OzoneException {
}
executePutKey(putRequest, httpClient);
} catch (IOException | URISyntaxException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
IOUtils.closeStream(is);
OzoneClientUtils.releaseConnection(putRequest);
@ -321,7 +321,7 @@ public void getKey(String keyName, Path downloadTo) throws OzoneException {
executeGetKey(getRequest, httpClient, outPutFile);
outPutFile.flush();
} catch (IOException | URISyntaxException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
IOUtils.closeStream(outPutFile);
OzoneClientUtils.releaseConnection(getRequest);
@ -355,7 +355,7 @@ public String getKey(String keyName) throws OzoneException {
executeGetKey(getRequest, httpClient, outPutStream);
return outPutStream.toString(ENCODING_NAME);
} catch (IOException | URISyntaxException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
IOUtils.closeStream(outPutStream);
OzoneClientUtils.releaseConnection(getRequest);
@ -422,7 +422,7 @@ public void deleteKey(String keyName) throws OzoneException {
.getClient().getHttpDelete(builder.toString());
executeDeleteKey(deleteRequest, httpClient);
} catch (IOException | URISyntaxException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
OzoneClientUtils.releaseConnection(deleteRequest);
}
@ -500,7 +500,7 @@ public List<OzoneKey> listKeys(String resultLength, String previousKey,
return executeListKeys(getRequest, httpClient);
} catch (IOException | URISyntaxException e) {
throw new OzoneRestClientException(e.getMessage());
throw new OzoneRestClientException(e.getMessage(), e);
} finally {
OzoneClientUtils.releaseConnection(getRequest);
}
@ -570,7 +570,7 @@ public OzoneKey getKeyInfo(String keyName) throws OzoneException {
getRequest = client.getHttpGet(builder.toString());
return executeGetKeyInfo(getRequest, httpClient);
} catch (IOException | URISyntaxException e) {
throw new OzoneRestClientException(e.getMessage());
throw new OzoneRestClientException(e.getMessage(), e);
} finally {
OzoneClientUtils.releaseConnection(getRequest);
}

View File

@ -167,7 +167,7 @@ public OzoneVolume createVolume(String volumeName, String onBehalfOf,
executeCreateVolume(httpPost, httpClient);
return getVolume(volumeName);
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
OzoneClientUtils.releaseConnection(httpPost);
}
@ -194,7 +194,7 @@ public OzoneVolume getVolume(String volumeName) throws OzoneException {
httpGet = getHttpGet(builder.toString());
return executeInfoVolume(httpGet, httpClient);
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
OzoneClientUtils.releaseConnection(httpGet);
}
@ -245,7 +245,7 @@ public List<OzoneVolume> listVolumes(String onBehalfOf, String prefix,
}
return executeListVolume(httpGet, httpClient);
} catch (IOException | URISyntaxException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
OzoneClientUtils.releaseConnection(httpGet);
}
@ -327,7 +327,7 @@ public List<OzoneVolume> listAllVolumes(String prefix, int maxKeys,
return executeListVolume(httpGet, httpClient);
} catch (IOException | URISyntaxException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
OzoneClientUtils.releaseConnection(httpGet);
}
@ -349,7 +349,7 @@ public void deleteVolume(String volumeName) throws OzoneException {
httpDelete = getHttpDelete(builder.toString());
executeDeleteVolume(httpDelete, httpClient);
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
OzoneClientUtils.releaseConnection(httpDelete);
}
@ -378,7 +378,7 @@ public void setVolumeOwner(String volumeName, String newOwner)
executePutVolume(putRequest, httpClient);
} catch (URISyntaxException | IllegalArgumentException | IOException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
OzoneClientUtils.releaseConnection(putRequest);
}
@ -411,7 +411,7 @@ public void setVolumeQuota(String volumeName, String quota)
executePutVolume(putRequest, httpClient);
} catch (URISyntaxException | IllegalArgumentException | IOException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
OzoneClientUtils.releaseConnection(putRequest);
}
@ -617,7 +617,7 @@ public void putKey(String volumeName, String bucketName, String keyName,
putRequest.setHeader(Header.CONTENT_MD5, DigestUtils.md5Hex(fis));
OzoneBucket.executePutKey(putRequest, httpClient);
} catch (IOException | URISyntaxException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
IOUtils.closeStream(fis);
OzoneClientUtils.releaseConnection(putRequest);
@ -659,7 +659,7 @@ public void getKey(String volumeName, String bucketName, String keyName,
OzoneBucket.executeGetKey(getRequest, httpClient, outPutFile);
outPutFile.flush();
} catch (IOException | URISyntaxException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
IOUtils.closeStream(outPutFile);
OzoneClientUtils.releaseConnection(getRequest);
@ -704,7 +704,7 @@ public List<OzoneKey> listKeys(String volumeName, String bucketName,
getRequest = getHttpGet(builder.toString());
return OzoneBucket.executeListKeys(getRequest, httpClient);
} catch (IOException | URISyntaxException e) {
throw new OzoneRestClientException(e.getMessage());
throw new OzoneRestClientException(e.getMessage(), e);
} finally {
OzoneClientUtils.releaseConnection(getRequest);
}

View File

@ -32,6 +32,16 @@ public OzoneRestClientException(String 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.
*

View File

@ -201,7 +201,7 @@ public OzoneBucket createBucket(String bucketName, String[] acls,
executeCreateBucket(httpPost, httpClient);
return getBucket(bucketName);
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
OzoneClientUtils.releaseConnection(httpPost);
}
@ -305,7 +305,7 @@ public void addAcls(String bucketName, String[] acls) throws OzoneException {
}
executePutBucket(putRequest, httpClient);
} catch (URISyntaxException | IOException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
OzoneClientUtils.releaseConnection(putRequest);
}
@ -334,7 +334,7 @@ public void removeAcls(String bucketName, String[] acls)
}
executePutBucket(putRequest, httpClient);
} catch (URISyntaxException | IOException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
OzoneClientUtils.releaseConnection(putRequest);
}
@ -359,7 +359,7 @@ public OzoneBucket getBucket(String bucketName) throws OzoneException {
return executeInfoBucket(getRequest, httpClient);
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
OzoneClientUtils.releaseConnection(getRequest);
}
@ -465,7 +465,7 @@ public List<OzoneBucket> listBuckets(String resultLength,
return executeListBuckets(getRequest, httpClient);
} catch (IOException | URISyntaxException e) {
throw new OzoneRestClientException(e.getMessage());
throw new OzoneRestClientException(e.getMessage(), e);
} finally {
OzoneClientUtils.releaseConnection(getRequest);
}
@ -533,7 +533,7 @@ public void deleteBucket(String bucketName) throws OzoneException {
executeDeleteBucket(delRequest, httpClient);
} catch (IOException | URISyntaxException | IllegalArgumentException ex) {
throw new OzoneRestClientException(ex.getMessage());
throw new OzoneRestClientException(ex.getMessage(), ex);
} finally {
OzoneClientUtils.releaseConnection(delRequest);
}

View File

@ -34,6 +34,7 @@
*/
@InterfaceAudience.Private
public class OzoneException extends Exception {
private static final ObjectReader READER =
new ObjectMapper().readerFor(OzoneException.class);
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
*/

View File

@ -402,6 +402,7 @@ private int dispatch(CommandLine cmd, Options opts)
System.err.printf("Command Failed : %s%n", ex.getMessage());
} catch (OzoneException ex) {
System.err.printf("Command Failed : %s%n", ex.toJsonString());
ex.printStackTrace(System.err);
} catch (IllegalArgumentException ex) {
System.err.printf("Illegal argument: %s%n", ex.getMessage());
}