Skip to content

Commit a4ff79f

Browse files
committed
provide ServerHealth when HTTP response code for Read Health Step is 5xx
1 parent 452d052 commit a4ff79f

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

operator/src/main/java/oracle/kubernetes/operator/http/HttpClient.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ public class HttpClient {
3636
private static final String HTTP_PROTOCOL = "http://";
3737
private static final String HTTPS_PROTOCOL = "https://";
3838

39-
// for debugging
40-
private static final String SERVICE_URL =
41-
System.getProperty("oracle.kubernetes.operator.http.HttpClient.SERVICE_URL");
42-
4339
// Please use one of the factory methods to get an instance of HttpClient.
4440
// Constructor is package access for unit testing
4541
HttpClient(Client httpClient, String encodedCredentials) {

operator/src/main/java/oracle/kubernetes/operator/http/Result.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ public boolean isSuccessful() {
3737
return successful;
3838
}
3939

40+
/**
41+
* @return true if the HTTP status code from the REST request indicates a server error, ie in the
42+
* 5xx range
43+
*/
44+
public boolean isServerError() {
45+
return status >= 500 && status <= 599;
46+
}
47+
4048
@Override
4149
public String toString() {
4250
return "Result{"

operator/src/main/java/oracle/kubernetes/operator/steps/ReadHealthStep.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import java.util.concurrent.atomic.AtomicInteger;
2020
import oracle.kubernetes.operator.ProcessingConstants;
2121
import oracle.kubernetes.operator.helpers.DomainPresenceInfo;
22+
import oracle.kubernetes.operator.http.HTTPException;
2223
import oracle.kubernetes.operator.http.HttpClient;
24+
import oracle.kubernetes.operator.http.Result;
2325
import oracle.kubernetes.operator.logging.LoggingFacade;
2426
import oracle.kubernetes.operator.logging.LoggingFactory;
2527
import oracle.kubernetes.operator.logging.LoggingFilter;
@@ -96,6 +98,7 @@ private static String getRetrieveHealthSearchPayload() {
9698
static final class ReadHealthWithHttpClientStep extends Step {
9799
private final V1Service service;
98100
private final V1Pod pod;
101+
static final String OVERALL_HEALTH_FOR_SERVER_ERROR = "Not available";
99102

100103
ReadHealthWithHttpClientStep(V1Service service, V1Pod pod, Step next) {
101104
super(next);
@@ -138,16 +141,14 @@ public NextAction apply(Packet packet) {
138141
serverConfig.getAdminProtocolChannelName(),
139142
serverConfig.getListenPort());
140143
if (serviceURL != null) {
141-
String jsonResult =
142-
httpClient
143-
.executePostUrlOnServiceClusterIP(
144-
getRetrieveHealthSearchUrl(),
145-
serviceURL,
146-
getRetrieveHealthSearchPayload(),
147-
true)
148-
.getResponse();
144+
Result result =
145+
httpClient.executePostUrlOnServiceClusterIP(
146+
getRetrieveHealthSearchUrl(),
147+
serviceURL,
148+
getRetrieveHealthSearchPayload(),
149+
false);
149150

150-
ServerHealth health = parseServerHealthJson(jsonResult);
151+
ServerHealth health = createServerHealthFromResult(result);
151152

152153
@SuppressWarnings("unchecked")
153154
ConcurrentMap<String, ServerHealth> serverHealthMap =
@@ -171,6 +172,17 @@ public NextAction apply(Packet packet) {
171172
}
172173
}
173174

175+
private ServerHealth createServerHealthFromResult(Result restResult)
176+
throws IOException, HTTPException {
177+
if (restResult.isSuccessful()) {
178+
return parseServerHealthJson(restResult.getResponse());
179+
}
180+
if (restResult.isServerError()) {
181+
return new ServerHealth().withOverallHealth(OVERALL_HEALTH_FOR_SERVER_ERROR);
182+
}
183+
throw new HTTPException(restResult.getStatus());
184+
}
185+
174186
private ServerHealth parseServerHealthJson(String jsonResult) throws IOException {
175187
if (jsonResult == null) return null;
176188

0 commit comments

Comments
 (0)