From a5ccbf290a8e4c6774b0d7c7b1b78d49eae8e035 Mon Sep 17 00:00:00 2001 From: Billy_Yuan Date: Fri, 12 Aug 2022 13:37:49 +0800 Subject: [PATCH 1/3] [SDK-610] add a new exception type to escape 4xx errors from server cooldowns --- .../emc/rest/smart/SmartClientException.java | 29 +++++++++++++++++++ .../emc/rest/smart/jersey/SmartFilter.java | 9 ++++-- 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java diff --git a/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java b/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java new file mode 100644 index 0000000..c4ee659 --- /dev/null +++ b/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java @@ -0,0 +1,29 @@ +package com.emc.rest.smart; + +public class SmartClientException extends RuntimeException { + + public SmartClientException(String message) { + super(message); + } + + public SmartClientException(String message, Throwable cause) { + super(message, cause); + } + + public enum ErrorType { + Client, // 4xx + Service, // 5xx + Unknown + } + + public ErrorType getErrorType() { + return errorType; + } + + public void setErrorType(ErrorType errorType) { + this.errorType = errorType; + } + + private ErrorType errorType = ErrorType.Unknown; + +} diff --git a/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartFilter.java b/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartFilter.java index 87a391b..3b8ed7e 100644 --- a/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartFilter.java +++ b/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartFilter.java @@ -16,6 +16,7 @@ package com.emc.rest.smart.jersey; import com.emc.rest.smart.Host; +import com.emc.rest.smart.SmartClientException; import com.emc.rest.smart.SmartConfig; import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.ClientRequest; @@ -75,9 +76,11 @@ public ClientResponse handle(ClientRequest request) throws ClientHandlerExceptio return response; } catch (RuntimeException e) { - // capture requests stats (error) - host.callComplete(true); - host.connectionClosed(); + if (e instanceof SmartClientException && !((SmartClientException)e).getErrorType().equals(SmartClientException.ErrorType.Client)) { + // capture requests stats (error) + host.callComplete(true); + host.connectionClosed(); + } throw e; } From 71434dc48c70df0aef113f81811bd07531bb14ca Mon Sep 17 00:00:00 2001 From: Billy_Yuan Date: Mon, 22 Aug 2022 17:06:36 +0800 Subject: [PATCH 2/3] fix callcomplete: reset consecutiveErrors when 4xx --- .../emc/rest/smart/SmartClientException.java | 19 +++++++++++-------- .../emc/rest/smart/jersey/SmartFilter.java | 10 ++++------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java b/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java index c4ee659..6cfa293 100644 --- a/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java +++ b/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java @@ -2,6 +2,8 @@ public class SmartClientException extends RuntimeException { + private ErrorType errorType = ErrorType.Unknown; + public SmartClientException(String message) { super(message); } @@ -9,13 +11,6 @@ public SmartClientException(String message) { public SmartClientException(String message, Throwable cause) { super(message, cause); } - - public enum ErrorType { - Client, // 4xx - Service, // 5xx - Unknown - } - public ErrorType getErrorType() { return errorType; } @@ -24,6 +19,14 @@ public void setErrorType(ErrorType errorType) { this.errorType = errorType; } - private ErrorType errorType = ErrorType.Unknown; + public enum ErrorType { + Client, // 4xx + Service, // 5xx + Unknown + } + + public boolean isServerError() { + return this.getErrorType().equals(SmartClientException.ErrorType.Service); + } } diff --git a/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartFilter.java b/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartFilter.java index 3b8ed7e..eb85e4b 100644 --- a/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartFilter.java +++ b/smart-client-jersey/src/main/java/com/emc/rest/smart/jersey/SmartFilter.java @@ -75,12 +75,10 @@ public ClientResponse handle(ClientRequest request) throws ClientHandlerExceptio return response; } catch (RuntimeException e) { - - if (e instanceof SmartClientException && !((SmartClientException)e).getErrorType().equals(SmartClientException.ErrorType.Client)) { - // capture requests stats (error) - host.callComplete(true); - host.connectionClosed(); - } + // capture requests stats (error) + boolean isServerError = e instanceof SmartClientException && ((SmartClientException) e).isServerError(); + host.callComplete(isServerError); + host.connectionClosed(); throw e; } From 44108728690790de59ef5c6a0983608a924deb71 Mon Sep 17 00:00:00 2001 From: Billy Yuan <97728850+dunedodo@users.noreply.github.com> Date: Wed, 21 Sep 2022 15:25:03 +0800 Subject: [PATCH 3/3] Update SmartClientException.java --- .../java/com/emc/rest/smart/SmartClientException.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java b/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java index 6cfa293..539db1e 100644 --- a/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java +++ b/smart-client-core/src/main/java/com/emc/rest/smart/SmartClientException.java @@ -19,14 +19,14 @@ public void setErrorType(ErrorType errorType) { this.errorType = errorType; } + public boolean isServerError() { + return this.getErrorType().equals(SmartClientException.ErrorType.Service); + } + public enum ErrorType { Client, // 4xx Service, // 5xx Unknown } - public boolean isServerError() { - return this.getErrorType().equals(SmartClientException.ErrorType.Service); - } - }