Skip to content

Commit 3333f3d

Browse files
committed
Handle status check prior to service creation
1 parent d47ab19 commit 3333f3d

File tree

2 files changed

+51
-59
lines changed

2 files changed

+51
-59
lines changed

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

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ static final class ReadHealthWithHttpClientStep extends Step {
8686

8787
public ReadHealthWithHttpClientStep(V1Service service, Step next) {
8888
super(next);
89-
if (service == null) {
90-
throw new IllegalArgumentException("service cannot be null");
91-
}
9289
this.service = service;
9390
}
9491

@@ -101,62 +98,63 @@ public NextAction apply(Packet packet) {
10198
Domain dom = info.getDomain();
10299

103100
String serviceURL = HttpClient.getServiceURL(service);
101+
if (serviceURL != null) {
102+
String jsonResult =
103+
httpClient
104+
.executePostUrlOnServiceClusterIP(
105+
getRetrieveHealthSearchUrl(),
106+
serviceURL,
107+
getRetrieveHealthSearchPayload(),
108+
true)
109+
.getResponse();
110+
111+
ObjectMapper mapper = new ObjectMapper();
112+
JsonNode root = mapper.readTree(jsonResult);
113+
114+
JsonNode state = null;
115+
JsonNode subsystemName = null;
116+
JsonNode symptoms = null;
117+
JsonNode overallHealthState = root.path("overallHealthState");
118+
if (overallHealthState != null) {
119+
state = overallHealthState.path("state");
120+
subsystemName = overallHealthState.path("subsystemName");
121+
symptoms = overallHealthState.path("symptoms");
122+
}
123+
JsonNode activationTime = root.path("activationTime");
124+
125+
List<String> sym = new ArrayList<>();
126+
if (symptoms != null) {
127+
Iterator<JsonNode> it = symptoms.elements();
128+
while (it.hasNext()) {
129+
sym.add(it.next().asText());
130+
}
131+
}
104132

105-
String jsonResult =
106-
httpClient
107-
.executePostUrlOnServiceClusterIP(
108-
getRetrieveHealthSearchUrl(),
109-
serviceURL,
110-
getRetrieveHealthSearchPayload(),
111-
true)
112-
.getResponse();
113-
114-
ObjectMapper mapper = new ObjectMapper();
115-
JsonNode root = mapper.readTree(jsonResult);
116-
117-
JsonNode state = null;
118-
JsonNode subsystemName = null;
119-
JsonNode symptoms = null;
120-
JsonNode overallHealthState = root.path("overallHealthState");
121-
if (overallHealthState != null) {
122-
state = overallHealthState.path("state");
123-
subsystemName = overallHealthState.path("subsystemName");
124-
symptoms = overallHealthState.path("symptoms");
125-
}
126-
JsonNode activationTime = root.path("activationTime");
127-
128-
List<String> sym = new ArrayList<>();
129-
if (symptoms != null) {
130-
Iterator<JsonNode> it = symptoms.elements();
131-
while (it.hasNext()) {
132-
sym.add(it.next().asText());
133+
String subName = null;
134+
if (subsystemName != null) {
135+
String s = subsystemName.asText();
136+
if (s != null && !"null".equals(s)) {
137+
subName = s;
138+
}
133139
}
134-
}
135140

136-
String subName = null;
137-
if (subsystemName != null) {
138-
String s = subsystemName.asText();
139-
if (s != null && !"null".equals(s)) {
140-
subName = s;
141+
ServerHealth health =
142+
new ServerHealth()
143+
.withOverallHealth(state != null ? state.asText() : null)
144+
.withActivationTime(
145+
activationTime != null ? new DateTime(activationTime.asLong()) : null);
146+
if (subName != null) {
147+
health
148+
.getSubsystems()
149+
.add(new SubsystemHealth().withSubsystemName(subName).withSymptoms(sym));
141150
}
142-
}
143151

144-
ServerHealth health =
145-
new ServerHealth()
146-
.withOverallHealth(state != null ? state.asText() : null)
147-
.withActivationTime(
148-
activationTime != null ? new DateTime(activationTime.asLong()) : null);
149-
if (subName != null) {
150-
health
151-
.getSubsystems()
152-
.add(new SubsystemHealth().withSubsystemName(subName).withSymptoms(sym));
152+
@SuppressWarnings("unchecked")
153+
ConcurrentMap<String, ServerHealth> serverHealthMap =
154+
(ConcurrentMap<String, ServerHealth>)
155+
packet.get(ProcessingConstants.SERVER_HEALTH_MAP);
156+
serverHealthMap.put((String) packet.get(ProcessingConstants.SERVER_NAME), health);
153157
}
154-
155-
@SuppressWarnings("unchecked")
156-
ConcurrentMap<String, ServerHealth> serverHealthMap =
157-
(ConcurrentMap<String, ServerHealth>) packet.get(ProcessingConstants.SERVER_HEALTH_MAP);
158-
serverHealthMap.put((String) packet.get(ProcessingConstants.SERVER_NAME), health);
159-
160158
return doNext(packet);
161159
} catch (Throwable t) {
162160
// do not retry for health check

operator/src/test/java/oracle/kubernetes/operator/steps/ReadHealthStepTest.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ public void withHttpClientStep_Health_logIfFailed() {
6464
assertThat(logRecords, containsFine(WLS_HEALTH_READ_FAILED, SERVER_NAME));
6565
}
6666

67-
@Test(expected = IllegalArgumentException.class)
68-
public void WithHttpClientStep_const_throws_with_null_service() {
69-
Step next = new MockStep(null);
70-
new ReadHealthWithHttpClientStep(null, next);
71-
}
72-
7367
abstract static class PacketStub extends Packet {
7468

7569
Integer retryCount;

0 commit comments

Comments
 (0)