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
parent 68f7cc6206
commit 14e184a283
6 changed files with 51 additions and 23 deletions

View File

@ -190,7 +190,7 @@ public class OzoneBucket {
}
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 class 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);
@ -355,7 +355,7 @@ public class OzoneBucket {
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 class OzoneBucket {
.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 class OzoneBucket {
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 class OzoneBucket {
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 class OzoneRestClient implements Closeable {
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 class OzoneRestClient implements Closeable {
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 class OzoneRestClient implements Closeable {
}
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 class OzoneRestClient implements Closeable {
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 class OzoneRestClient implements Closeable {
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 class OzoneRestClient implements Closeable {
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 class OzoneRestClient implements Closeable {
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 class OzoneRestClient implements Closeable {
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 class OzoneRestClient implements Closeable {
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 class OzoneRestClient implements Closeable {
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 class OzoneRestClientException extends OzoneException {
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 class OzoneVolume {
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 class OzoneVolume {
}
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 class OzoneVolume {
}
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 class OzoneVolume {
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 class OzoneVolume {
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 class OzoneVolume {
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 @@ import com.fasterxml.jackson.databind.ObjectReader;
*/
@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 class OzoneException extends Exception {
}
/**
* 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 @@ public class Shell extends Configured implements Tool {
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());
}