HDFS-12489. Ozone: OzoneRestClientException swallows exceptions which makes client hard to debug failures. Contributed by Weiwei Yang.
This commit is contained in:
parent
68f7cc6206
commit
14e184a283
|
@ -190,7 +190,7 @@ public class OzoneBucket {
|
||||||
}
|
}
|
||||||
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 class OzoneBucket {
|
||||||
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 class OzoneBucket {
|
||||||
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 class OzoneBucket {
|
||||||
.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 class OzoneBucket {
|
||||||
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 class OzoneBucket {
|
||||||
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 class OzoneRestClient implements Closeable {
|
||||||
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 class OzoneRestClient implements Closeable {
|
||||||
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 class OzoneRestClient implements Closeable {
|
||||||
}
|
}
|
||||||
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 class OzoneRestClient implements Closeable {
|
||||||
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 class OzoneRestClient implements Closeable {
|
||||||
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 class OzoneRestClient implements Closeable {
|
||||||
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 class OzoneRestClient implements Closeable {
|
||||||
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 class OzoneRestClient implements Closeable {
|
||||||
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 class OzoneRestClient implements Closeable {
|
||||||
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 class OzoneRestClient implements Closeable {
|
||||||
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 class OzoneRestClientException extends OzoneException {
|
||||||
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 class OzoneVolume {
|
||||||
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 class OzoneVolume {
|
||||||
}
|
}
|
||||||
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 class OzoneVolume {
|
||||||
}
|
}
|
||||||
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 class OzoneVolume {
|
||||||
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 class OzoneVolume {
|
||||||
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 class OzoneVolume {
|
||||||
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 @@ import com.fasterxml.jackson.databind.ObjectReader;
|
||||||
*/
|
*/
|
||||||
@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 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
|
* @return String
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -402,6 +402,7 @@ public class Shell extends Configured implements Tool {
|
||||||
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