Skip to content

Commit 650b0af

Browse files
committed
Server health check
1 parent 978349a commit 650b0af

File tree

17 files changed

+223
-111
lines changed

17 files changed

+223
-111
lines changed

src-generated-swagger/main/java/oracle/kubernetes/weblogic/domain/v1/ServerHealth.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public class ServerHealth {
2424
* RFC 3339 date and time at which the server started.
2525
*
2626
*/
27-
@SerializedName("startTime")
27+
@SerializedName("activationTime")
2828
@Expose
29-
private DateTime startTime;
29+
private DateTime activationTime;
3030
/**
3131
* Server health of this WebLogic server.
3232
*
@@ -54,25 +54,25 @@ public class ServerHealth {
5454
* RFC 3339 date and time at which the server started.
5555
* @return start time
5656
*/
57-
public DateTime getStartTime() {
58-
return startTime;
57+
public DateTime getActivationTime() {
58+
return activationTime;
5959
}
6060

6161
/**
6262
* RFC 3339 date and time at which the server started.
63-
* @param startTime start time
63+
* @param activationTime start time
6464
*/
65-
public void setStartTime(DateTime startTime) {
66-
this.startTime = startTime;
65+
public void setActivationTime(DateTime activationTime) {
66+
this.activationTime = activationTime;
6767
}
6868

6969
/**
7070
* RFC 3339 date and time at which the server started.
7171
* @param startTime start time
7272
* @return this
7373
*/
74-
public ServerHealth withStartTime(DateTime startTime) {
75-
this.startTime = startTime;
74+
public ServerHealth withActivationTime(DateTime activationTime) {
75+
this.activationTime = activationTime;
7676
return this;
7777
}
7878

@@ -156,12 +156,12 @@ public ServerHealth withSymptoms(List<String> symptoms) {
156156

157157
@Override
158158
public String toString() {
159-
return new ToStringBuilder(this).append("startTime", startTime).append("health", health).append("subsystemName", subsystemName).append("symptoms", symptoms).toString();
159+
return new ToStringBuilder(this).append("activationTime", activationTime).append("health", health).append("subsystemName", subsystemName).append("symptoms", symptoms).toString();
160160
}
161161

162162
@Override
163163
public int hashCode() {
164-
return new HashCodeBuilder().append(symptoms).append(health).append(startTime).append(subsystemName).toHashCode();
164+
return new HashCodeBuilder().append(symptoms).append(health).append(activationTime).append(subsystemName).toHashCode();
165165
}
166166

167167
@Override
@@ -173,7 +173,7 @@ public boolean equals(Object other) {
173173
return false;
174174
}
175175
ServerHealth rhs = ((ServerHealth) other);
176-
return new EqualsBuilder().append(symptoms, rhs.symptoms).append(health, rhs.health).append(startTime, rhs.startTime).append(subsystemName, rhs.subsystemName).isEquals();
176+
return new EqualsBuilder().append(symptoms, rhs.symptoms).append(health, rhs.health).append(activationTime, rhs.activationTime).append(subsystemName, rhs.subsystemName).isEquals();
177177
}
178178

179179
}

src/main/java/oracle/kubernetes/operator/DomainStatusUpdater.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,19 @@ public NextAction apply(Packet packet) {
120120
// Acquire current state
121121
@SuppressWarnings("unchecked")
122122
ConcurrentMap<String, String> serverState = (ConcurrentMap<String, String>) packet.get(ProcessingConstants.SERVER_STATE_MAP);
123-
123+
124+
@SuppressWarnings("unchecked")
125+
ConcurrentMap<String, ServerHealth> serverHealth = (ConcurrentMap<String, ServerHealth>) packet.get(ProcessingConstants.SERVER_HEALTH_MAP);
126+
124127
Map<String, ServerStatus> serverStatuses = new LinkedHashMap<>();
125128
WlsDomainConfig scan = info.getScan();
126129
if (scan != null) {
127130
for (Map.Entry<String, WlsServerConfig> entry : scan.getServerConfigs().entrySet()) {
128131
String serverName = entry.getKey();
129-
ServerHealth health = new ServerHealth();
130132
ServerStatus ss = new ServerStatus()
131133
.withState(serverState.getOrDefault(serverName, "SHUTDOWN"))
132134
.withServerName(serverName)
133-
.withHealth(health);
135+
.withHealth(serverHealth.get(serverName));
134136
outer:
135137
for (Map.Entry<String, WlsClusterConfig> cluster : scan.getClusterConfigs().entrySet()) {
136138
for (WlsServerConfig sic : cluster.getValue().getServerConfigs()) {
@@ -145,12 +147,8 @@ public NextAction apply(Packet packet) {
145147
V1Pod pod = sko.getPod().get();
146148
if (pod != null) {
147149
ss.setNodeName(pod.getSpec().getNodeName());
148-
health.setStartTime(pod.getMetadata().getCreationTimestamp());
149150
}
150151
}
151-
// TODO
152-
//ss.setSubsystemName(subsystemName);
153-
//ss.setSymptoms(symptoms);
154152
serverStatuses.put(serverName, ss);
155153
}
156154
}
@@ -159,17 +157,12 @@ public NextAction apply(Packet packet) {
159157
if (!serverStatuses.containsKey(serverName)) {
160158
V1Pod pod = entry.getValue().getPod().get();
161159
if (pod != null) {
162-
ServerHealth health = new ServerHealth()
163-
.withStartTime(pod.getMetadata().getCreationTimestamp());
164160
ServerStatus ss = new ServerStatus()
165161
.withState(serverState.getOrDefault(serverName, "SHUTDOWN"))
166162
.withClusterName(pod.getMetadata().getLabels().get(LabelConstants.CLUSTERNAME_LABEL))
167163
.withNodeName(pod.getSpec().getNodeName())
168164
.withServerName(serverName)
169-
.withHealth(health);
170-
// TODO
171-
//ss.setSubsystemName(subsystemName);
172-
//ss.setSymptoms(symptoms);
165+
.withHealth(serverHealth.get(serverName));
173166
serverStatuses.put(serverName, ss);
174167
}
175168
}

src/main/java/oracle/kubernetes/operator/Main.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
import oracle.kubernetes.operator.rest.RestServer;
6464
import oracle.kubernetes.operator.wlsconfig.NetworkAccessPoint;
6565
import oracle.kubernetes.operator.wlsconfig.WlsClusterConfig;
66-
import oracle.kubernetes.operator.wlsconfig.WlsConfigRetriever;
66+
import oracle.kubernetes.operator.wlsconfig.WlsRetriever;
6767
import oracle.kubernetes.operator.wlsconfig.WlsDomainConfig;
6868
import oracle.kubernetes.operator.wlsconfig.WlsServerConfig;
6969
import oracle.kubernetes.operator.work.Component;
@@ -763,7 +763,7 @@ public NextAction apply(Packet packet) {
763763
}
764764

765765
private static Step connectToAdminAndInspectDomain(Step next) {
766-
return new WatchPodReadyAdminStep(WlsConfigRetriever.readConfigStep(
766+
return new WatchPodReadyAdminStep(WlsRetriever.readConfigStep(
767767
new ExternalAdminChannelsStep(next)));
768768
}
769769

src/main/java/oracle/kubernetes/operator/ProcessingConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public interface ProcessingConstants {
3030

3131
public static final String SCRIPT_CONFIG_MAP = "scriptConfigMap";
3232
public static final String SERVER_STATE_MAP = "serverStateMap";
33+
public static final String SERVER_HEALTH_MAP = "serverHealthMap";
3334

3435
public static final String STATUS_UNCHANGED = "statusUnchanged";
3536

src/main/java/oracle/kubernetes/operator/ServerStatusReader.java

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import java.io.Reader;
1010
import java.util.ArrayList;
1111
import java.util.Collection;
12+
import java.util.HashSet;
1213
import java.util.Map;
14+
import java.util.Set;
1315
import java.util.concurrent.ConcurrentHashMap;
1416
import java.util.concurrent.ConcurrentMap;
1517
import java.util.concurrent.TimeUnit;
@@ -29,11 +31,13 @@
2931
import oracle.kubernetes.operator.logging.LoggingFacade;
3032
import oracle.kubernetes.operator.logging.LoggingFactory;
3133
import oracle.kubernetes.operator.logging.MessageKeys;
34+
import oracle.kubernetes.operator.wlsconfig.WlsRetriever;
3235
import oracle.kubernetes.operator.work.NextAction;
3336
import oracle.kubernetes.operator.work.Packet;
3437
import oracle.kubernetes.operator.work.Step;
3538
import oracle.kubernetes.weblogic.domain.v1.Domain;
3639
import oracle.kubernetes.weblogic.domain.v1.DomainSpec;
40+
import oracle.kubernetes.weblogic.domain.v1.ServerHealth;
3741

3842
/**
3943
* Creates an asynchronous step to read the WebLogic server state from a particular pod
@@ -63,7 +67,10 @@ public DomainStatusReaderStep(DomainPresenceInfo info, long timeoutSeconds, Step
6367
public NextAction apply(Packet packet) {
6468
ConcurrentMap<String, String> serverStateMap = new ConcurrentHashMap<>();
6569
packet.put(ProcessingConstants.SERVER_STATE_MAP, serverStateMap);
66-
70+
71+
ConcurrentMap<String, ServerHealth> serverHealthMap = new ConcurrentHashMap<>();
72+
packet.put(ProcessingConstants.SERVER_HEALTH_MAP, serverHealthMap);
73+
6774
Domain domain = info.getDomain();
6875
V1ObjectMeta meta = domain.getMetadata();
6976
DomainSpec spec = domain.getSpec();
@@ -107,7 +114,8 @@ public NextAction apply(Packet packet) {
107114
*/
108115
public static Step createServerStatusReaderStep(String namespace, String domainUID,
109116
String serverName, long timeoutSeconds, Step next) {
110-
return new ServerStatusReaderStep(namespace, domainUID, serverName, timeoutSeconds, next);
117+
return new ServerStatusReaderStep(namespace, domainUID, serverName, timeoutSeconds,
118+
new ServerHealthStep(serverName, timeoutSeconds, next));
111119
}
112120

113121
private static class ServerStatusReaderStep extends Step {
@@ -181,4 +189,40 @@ private static String parseState(String state) {
181189

182190
return s;
183191
}
192+
193+
private static final Set<String> statesSupportingREST = new HashSet<>();
194+
static {
195+
statesSupportingREST.add("STANDBY");
196+
statesSupportingREST.add("ADMIN");
197+
statesSupportingREST.add("RESUMING");
198+
statesSupportingREST.add("RUNNING");
199+
statesSupportingREST.add("SUSPENDING");
200+
statesSupportingREST.add("FORCE_SUSPENDING");
201+
}
202+
203+
private static class ServerHealthStep extends Step {
204+
private final String serverName;
205+
private final long timeoutSeconds; // FIXME
206+
207+
public ServerHealthStep(String serverName, long timeoutSeconds, Step next) {
208+
super(next);
209+
this.serverName = serverName;
210+
this.timeoutSeconds = timeoutSeconds;
211+
}
212+
213+
@Override
214+
public NextAction apply(Packet packet) {
215+
@SuppressWarnings("unchecked")
216+
ConcurrentMap<String, String> serverStateMap = (ConcurrentMap<String, String>) packet
217+
.get(ProcessingConstants.SERVER_STATE_MAP);
218+
String state = serverStateMap.get(serverName);
219+
if (statesSupportingREST.contains(state)) {
220+
packet.put(ProcessingConstants.SERVER_NAME, serverName);
221+
return doNext(WlsRetriever.readHealthStep(next), packet);
222+
}
223+
224+
return doNext(packet);
225+
}
226+
227+
}
184228
}

src/main/java/oracle/kubernetes/operator/helpers/SecretHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class SecretHelper {
4343
private final String namespace;
4444

4545
public enum SecretType {
46-
AdminServerCredentials
46+
AdminCredentials
4747
}
4848

4949
// Admin Server Credentials Type Secret
@@ -75,7 +75,7 @@ public Map<String, byte[]> getSecretData(SecretType secretType, String secretNam
7575
LOGGER.entering();
7676

7777
try {
78-
if (secretType != SecretType.AdminServerCredentials) {
78+
if (secretType != SecretType.AdminCredentials) {
7979
throw new IllegalArgumentException("Invalid secret type");
8080
} else if (secretName == null) {
8181
throw new IllegalArgumentException("Invalid secret name");
@@ -125,7 +125,7 @@ public SecretDataStep(SecretType secretType, String secretName, String namespace
125125

126126
@Override
127127
public NextAction apply(Packet packet) {
128-
if (secretType != SecretType.AdminServerCredentials) {
128+
if (secretType != SecretType.AdminCredentials) {
129129
throw new IllegalArgumentException("Invalid secret type");
130130
} else if (secretName == null) {
131131
throw new IllegalArgumentException("Invalid secret name");

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ public String executeGetOnServiceClusterIP(String requestUrl, ClientHolder clien
6666

6767
public String executePostUrlOnServiceClusterIP(String requestUrl, ClientHolder client, String serviceName, String namespace, String payload) {
6868
String serviceURL = SERVICE_URL == null ? getServiceURL(client, principal, serviceName, namespace) : SERVICE_URL;
69-
return executePostUrlOnServiceClusterIP(requestUrl, serviceURL, serviceName, namespace, payload);
69+
return executePostUrlOnServiceClusterIP(requestUrl, serviceURL, namespace, payload);
7070
}
7171

72-
public String executePostUrlOnServiceClusterIP(String requestUrl, String serviceURL, String serviceName, String namespace, String payload) {
72+
public String executePostUrlOnServiceClusterIP(String requestUrl, String serviceURL, String namespace, String payload) {
7373
String url = serviceURL + requestUrl;
7474
WebTarget target = httpClient.target(url);
7575
Invocation.Builder invocationBuilder = target.request().accept("application/json")
@@ -88,30 +88,30 @@ public String executePostUrlOnServiceClusterIP(String requestUrl, String service
8888
}
8989

9090
/**
91-
* Asynchronous {@link Step} for creating an authenticated HTTP client targeted at an admin server
91+
* Asynchronous {@link Step} for creating an authenticated HTTP client targeted at a server instance
9292
* @param principal Principal
9393
* @param namespace Namespace
9494
* @param adminSecretName Admin secret name
9595
* @param next Next processing step
9696
* @return step to create client
9797
*/
98-
public static Step createAuthenticatedClientForAdminServer(String principal, String namespace, String adminSecretName, Step next) {
99-
return new AuthenticatedClientForAdminServerStep(namespace, adminSecretName, new WithSecretDataStep(principal, next));
98+
public static Step createAuthenticatedClientForServer(String principal, String namespace, String adminSecretName, Step next) {
99+
return new AuthenticatedClientForServerStep(namespace, adminSecretName, new WithSecretDataStep(principal, next));
100100
}
101101

102-
private static class AuthenticatedClientForAdminServerStep extends Step {
102+
private static class AuthenticatedClientForServerStep extends Step {
103103
private final String namespace;
104104
private final String adminSecretName;
105105

106-
public AuthenticatedClientForAdminServerStep(String namespace, String adminSecretName, Step next) {
106+
public AuthenticatedClientForServerStep(String namespace, String adminSecretName, Step next) {
107107
super(next);
108108
this.namespace = namespace;
109109
this.adminSecretName = adminSecretName;
110110
}
111111

112112
@Override
113113
public NextAction apply(Packet packet) {
114-
Step readSecret = SecretHelper.getSecretData(SecretHelper.SecretType.AdminServerCredentials, adminSecretName, namespace, next);
114+
Step readSecret = SecretHelper.getSecretData(SecretHelper.SecretType.AdminCredentials, adminSecretName, namespace, next);
115115
return doNext(readSecret, packet);
116116
}
117117
}
@@ -150,10 +150,10 @@ public NextAction apply(Packet packet) {
150150
* @param adminSecretName Admin secret name
151151
* @return authenticated client
152152
*/
153-
public static HttpClient createAuthenticatedClientForAdminServer(ClientHolder client, String principal, String namespace, String adminSecretName) {
153+
public static HttpClient createAuthenticatedClientForServer(ClientHolder client, String principal, String namespace, String adminSecretName) {
154154
SecretHelper secretHelper = new SecretHelper(client, namespace);
155155
Map<String, byte[]> secretData =
156-
secretHelper.getSecretData(SecretHelper.SecretType.AdminServerCredentials, adminSecretName);
156+
secretHelper.getSecretData(SecretHelper.SecretType.AdminCredentials, adminSecretName);
157157

158158
byte[] username = null;
159159
byte[] password = null;

src/main/java/oracle/kubernetes/operator/rest/RestBackendImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import oracle.kubernetes.operator.logging.MessageKeys;
2424
import oracle.kubernetes.operator.rest.backend.RestBackend;
2525
import oracle.kubernetes.operator.wlsconfig.WlsClusterConfig;
26-
import oracle.kubernetes.operator.wlsconfig.WlsConfigRetriever;
26+
import oracle.kubernetes.operator.wlsconfig.WlsRetriever;
2727
import oracle.kubernetes.operator.wlsconfig.WlsDomainConfig;
2828

2929
import javax.ws.rs.WebApplicationException;
@@ -400,14 +400,14 @@ private ClusterStartup getClusterStartup(Domain domain, String cluster) {
400400
}
401401

402402
private int getWLSConfiguredClusterSize(ClientHolder client, String adminServerServiceName, String cluster, String namespace, String adminSecretName) {
403-
WlsConfigRetriever wlsConfigRetriever = WlsConfigRetriever.create(client.getHelper(), namespace, adminServerServiceName, adminSecretName);
403+
WlsRetriever wlsConfigRetriever = WlsRetriever.create(client.getHelper(), namespace, adminServerServiceName, adminSecretName);
404404
WlsDomainConfig wlsDomainConfig = wlsConfigRetriever.readConfig(principal);
405405
WlsClusterConfig wlsClusterConfig = wlsDomainConfig.getClusterConfig(cluster);
406406
return wlsClusterConfig.getClusterSize();
407407
}
408408

409409
private Map<String, WlsClusterConfig> getWLSConfiguredClusters(ClientHolder client, String namespace, String adminServerServiceName, String adminSecretName) {
410-
WlsConfigRetriever wlsConfigRetriever = WlsConfigRetriever.create(client.getHelper(), namespace, adminServerServiceName, adminSecretName);
410+
WlsRetriever wlsConfigRetriever = WlsRetriever.create(client.getHelper(), namespace, adminServerServiceName, adminSecretName);
411411
WlsDomainConfig wlsDomainConfig = wlsConfigRetriever.readConfig(principal);
412412
return wlsDomainConfig.getClusterConfigs();
413413
}

src/main/java/oracle/kubernetes/operator/wlsconfig/NetworkAccessPoint.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator.wlsconfig;
@@ -7,7 +7,6 @@
77

88
/**
99
* Contains configuration for a Network Access Point
10-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
1110
*/
1211
public class NetworkAccessPoint {
1312

src/main/java/oracle/kubernetes/operator/wlsconfig/WlsClusterConfig.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2017, Oracle Corporation and/or its affiliates. All rights reserved.
1+
// Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
22
// Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
33

44
package oracle.kubernetes.operator.wlsconfig;
@@ -13,8 +13,6 @@
1313

1414
/**
1515
* Contains configuration of a WLS cluster
16-
* <p>
17-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
1816
*/
1917
public class WlsClusterConfig {
2018
private static final LoggingFacade LOGGER = LoggingFactory.getLogger("Operator", "Operator");

0 commit comments

Comments
 (0)