Skip to content

Commit c21dea3

Browse files
committed
Use constants
1 parent 0d07ad3 commit c21dea3

File tree

7 files changed

+47
-34
lines changed

7 files changed

+47
-34
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public NextAction apply(Packet packet) {
134134
for (Map.Entry<String, WlsServerConfig> entry : scan.getServerConfigs().entrySet()) {
135135
String serverName = entry.getKey();
136136
ServerStatus ss = new ServerStatus()
137-
.withState(serverState.getOrDefault(serverName, "SHUTDOWN"))
137+
.withState(serverState.getOrDefault(serverName, WebLogicConstants.SHUTDOWN_STATE))
138138
.withServerName(serverName)
139139
.withHealth(serverHealth.get(serverName));
140140
outer:
@@ -162,7 +162,7 @@ public NextAction apply(Packet packet) {
162162
V1Pod pod = entry.getValue().getPod().get();
163163
if (pod != null) {
164164
ServerStatus ss = new ServerStatus()
165-
.withState(serverState.getOrDefault(serverName, "SHUTDOWN"))
165+
.withState(serverState.getOrDefault(serverName, WebLogicConstants.SHUTDOWN_STATE))
166166
.withClusterName(pod.getMetadata().getLabels().get(LabelConstants.CLUSTERNAME_LABEL))
167167
.withNodeName(pod.getSpec().getNodeName())
168168
.withServerName(serverName)
@@ -215,7 +215,7 @@ public NextAction apply(Packet packet) {
215215
String serverName = entry.getKey();
216216
if (serversIntendedToRunning.contains(serverName)) {
217217
ServerStatus ss = serverStatuses.get(serverName);
218-
if (ss == null || !"RUNNING".equals(ss.getState())) {
218+
if (ss == null || !WebLogicConstants.RUNNING_STATE.equals(ss.getState())) {
219219
allIntendedPodsToRunning = false;
220220
}
221221
}

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@
8888
*/
8989
public class Main {
9090

91-
private static final String RUNNING_STATE = "RUNNING";
92-
private static final String ADMIN_STATE = "ADMIN";
93-
9491
private static final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
9592
private static final ThreadFactory factory = (r) -> {
9693
Thread t = defaultFactory.newThread(r);
@@ -420,7 +417,7 @@ private static void normalizeDomainSpec(DomainSpec spec) {
420417
} else {
421418
for (ServerStartup ss : spec.getServerStartup()) {
422419
if (ss.getDesiredState() == null) {
423-
ss.setDesiredState(RUNNING_STATE);
420+
ss.setDesiredState(WebLogicConstants.RUNNING_STATE);
424421
}
425422
if (ss.getEnv() == null) {
426423
ss.setEnv(new ArrayList<V1EnvVar>());
@@ -432,7 +429,7 @@ private static void normalizeDomainSpec(DomainSpec spec) {
432429
} else {
433430
for (ClusterStartup cs : spec.getClusterStartup()) {
434431
if (cs.getDesiredState() == null) {
435-
cs.setDesiredState(RUNNING_STATE);
432+
cs.setDesiredState(WebLogicConstants.RUNNING_STATE);
436433
}
437434
if (cs.getEnv() == null) {
438435
cs.setEnv(new ArrayList<V1EnvVar>());
@@ -916,7 +913,7 @@ public NextAction apply(Packet packet) {
916913
}
917914
}
918915
List<V1EnvVar> env = ss.getEnv();
919-
if (ADMIN_STATE.equals(ss.getDesiredState())) {
916+
if (WebLogicConstants.ADMIN_STATE.equals(ss.getDesiredState())) {
920917
env = startInAdminMode(env);
921918
}
922919
ssic.add(new ServerStartupInfo(wlsServerConfig, cc, env, ss));
@@ -955,7 +952,7 @@ public NextAction apply(Packet packet) {
955952
}
956953
// start server
957954
servers.add(serverName);
958-
if (ADMIN_STATE.equals(cs.getDesiredState())) {
955+
if (WebLogicConstants.ADMIN_STATE.equals(cs.getDesiredState())) {
959956
env = startInAdminMode(env);
960957
}
961958
ssic.add(new ServerStartupInfo(wlsServerConfig, wlsClusterConfig, env, ssi));
@@ -1550,11 +1547,11 @@ private static void dispatchEventWatch(Watch.Response<V1Event> item) {
15501547
String name = ref.getName();
15511548
String message = e.getMessage();
15521549
if (message != null) {
1553-
int idx = message.indexOf("Not ready: Server state=");
1550+
int idx = message.indexOf(WebLogicConstants.READINESS_PROBE_NOT_READY_STATE);
15541551
if (idx > 0) {
15551552
ServerKubernetesObjects sko = servers.get(name);
15561553
if (sko != null) {
1557-
sko.getLastKnownStatus().set(message.substring(idx + 24));
1554+
sko.getLastKnownStatus().set(message.substring(idx + WebLogicConstants.READINESS_PROBE_NOT_READY_STATE.length()));
15581555
}
15591556
}
15601557
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void receivedResponse(Watch.Response<V1Pod> item) {
8989
ServerKubernetesObjectsFactory skoFactory = c.getSPI(ServerKubernetesObjectsFactory.class);
9090
ServerKubernetesObjects sko = skoFactory.lookup(podName);
9191
if (sko != null) {
92-
sko.getLastKnownStatus().set("RUNNING");
92+
sko.getLastKnownStatus().set(WebLogicConstants.RUNNING_STATE);
9393
}
9494

9595
OnReady ready = readyCallbackRegistrations.remove(podName);

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

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
import java.io.Reader;
1010
import java.util.ArrayList;
1111
import java.util.Collection;
12-
import java.util.HashSet;
1312
import java.util.Map;
14-
import java.util.Set;
1513
import java.util.concurrent.ConcurrentHashMap;
1614
import java.util.concurrent.ConcurrentMap;
1715
import java.util.concurrent.TimeUnit;
@@ -128,7 +126,7 @@ public NextAction apply(Packet packet) {
128126
serverStateMap.put(serverName, lastKnownState);
129127
return doNext(packet);
130128
} else if (PodWatcher.isReady(pod, true)) {
131-
serverStateMap.put(serverName, "RUNNING");
129+
serverStateMap.put(serverName, WebLogicConstants.RUNNING_STATE);
132130
return doNext(packet);
133131
}
134132

@@ -162,22 +160,12 @@ public NextAction apply(Packet packet) {
162160
}
163161
}
164162

165-
serverStateMap.put(serverName, state != null ? state : "UNKNOWN");
163+
serverStateMap.put(serverName, state != null ? state : WebLogicConstants.UNKNOWN_STATE);
166164
fiber.resume(packet);
167165
});
168166
}
169167
}
170168

171-
private static final Set<String> statesSupportingREST = new HashSet<>();
172-
static {
173-
statesSupportingREST.add("STANDBY");
174-
statesSupportingREST.add("ADMIN");
175-
statesSupportingREST.add("RESUMING");
176-
statesSupportingREST.add("RUNNING");
177-
statesSupportingREST.add("SUSPENDING");
178-
statesSupportingREST.add("FORCE_SUSPENDING");
179-
}
180-
181169
private static class ServerHealthStep extends Step {
182170
private final String serverName;
183171

@@ -193,7 +181,7 @@ public NextAction apply(Packet packet) {
193181
.get(ProcessingConstants.SERVER_STATE_MAP);
194182
String state = serverStateMap.get(serverName);
195183

196-
if (statesSupportingREST.contains(state)) {
184+
if (WebLogicConstants.STATES_SUPPORTING_REST.contains(state)) {
197185
packet.put(ProcessingConstants.SERVER_NAME, serverName);
198186
return doNext(WlsRetriever.readHealthStep(next), packet);
199187
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved.
2+
// Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
3+
4+
package oracle.kubernetes.operator;
5+
6+
import java.util.Arrays;
7+
import java.util.HashSet;
8+
import java.util.Set;
9+
10+
public interface WebLogicConstants {
11+
public static final String UNKNOWN_STATE = "UNKNOWN";
12+
public static final String SHUTDOWN_STATE = "SHUTDOWN";
13+
public static final String STANDBY_STATE = "STANDBY";
14+
public static final String ADMIN_STATE = "ADMIN";
15+
public static final String RESUMING_STATE = "RESUMING";
16+
public static final String RUNNING_STATE = "RUNNING";
17+
public static final String SUSPENDING_STATE = "SUSPENDING";
18+
public static final String FORCE_SUSPENDING_STATE = "FORCE_SUSPENDING";
19+
public static final String FAILED_NOT_RESTARTABLE_STATE = "FAILED_NOT_RESTARTABLE";
20+
21+
public static final Set<String> STATES_SUPPORTING_REST = new HashSet<>(Arrays.asList(
22+
STANDBY_STATE, ADMIN_STATE, RESUMING_STATE, RUNNING_STATE, SUSPENDING_STATE, FORCE_SUSPENDING_STATE));
23+
24+
public static final String READINESS_PROBE_NOT_READY_STATE = "Not ready: WebLogic Server state: ";
25+
26+
}

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import oracle.kubernetes.operator.KubernetesConstants;
1414
import oracle.kubernetes.operator.LabelConstants;
1515
import oracle.kubernetes.operator.ProcessingConstants;
16+
import oracle.kubernetes.operator.WebLogicConstants;
1617
import oracle.kubernetes.operator.logging.LoggingFacade;
1718
import oracle.kubernetes.operator.logging.LoggingFactory;
1819
import oracle.kubernetes.operator.logging.MessageKeys;
@@ -75,8 +76,8 @@ public NextAction apply(Packet packet) {
7576
" echo \"Error: WebLogic NodeManager process not found.\"\n" +
7677
" exit 1\n" +
7778
"fi\n" +
78-
"if [ -f ${STATEFILE} ] && [ `grep -c \"FAILED_NOT_RESTARTABLE\" ${STATEFILE}` -eq 1 ]; then\n" +
79-
" echo \"Error: WebLogic Server state is FAILED_NOT_RESTARTABLE.\"\n" +
79+
"if [ -f ${STATEFILE} ] && [ `grep -c \"" + WebLogicConstants.FAILED_NOT_RESTARTABLE_STATE + "\" ${STATEFILE}` -eq 1 ]; then\n" +
80+
" echo \"Error: WebLogic Server state is " + WebLogicConstants.FAILED_NOT_RESTARTABLE_STATE + ".\"\n" +
8081
" exit 1\n" +
8182
"fi\n" +
8283
"exit 0");
@@ -103,8 +104,8 @@ public NextAction apply(Packet packet) {
103104
"fi\n" +
104105
"\n" +
105106
"state=$(cat ${STATEFILE} | cut -f 1 -d ':')\n" +
106-
"if [ \"$state\" != \"RUNNING\" ]; then\n" +
107-
" echo \"Not ready: WebLogic Server state: ${state}\"\n" +
107+
"if [ \"$state\" != \"" + WebLogicConstants.RUNNING_STATE + "\" ]; then\n" +
108+
" echo \"" + WebLogicConstants.READINESS_PROBE_NOT_READY_STATE + "${state}\"\n" +
108109
" exit 3\n" +
109110
"fi\n" +
110111
"exit 0");

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.Map;
1212

1313
import oracle.kubernetes.operator.ProcessingConstants;
14+
import oracle.kubernetes.operator.WebLogicConstants;
1415
import oracle.kubernetes.weblogic.domain.v1.Domain;
1516
import oracle.kubernetes.weblogic.domain.v1.DomainStatus;
1617
import oracle.kubernetes.weblogic.domain.v1.ServerStatus;
@@ -70,7 +71,7 @@ public NextAction apply(Packet packet) {
7071
List<ServerStatus> ss = status.getServers();
7172
if (ss != null) {
7273
for (ServerStatus s : ss) {
73-
if ("RUNNING".equals(s.getState())) {
74+
if (WebLogicConstants.RUNNING_STATE.equals(s.getState())) {
7475
availableServers.add(s.getServerName());
7576
}
7677
}
@@ -168,7 +169,7 @@ public NextAction apply(Packet packet) {
168169
List<ServerStatus> ss = status.getServers();
169170
if (ss != null) {
170171
for (ServerStatus s : ss) {
171-
if ("RUNNING".equals(s.getState())) {
172+
if (WebLogicConstants.RUNNING_STATE.equals(s.getState())) {
172173
availableServers.add(s.getServerName());
173174
}
174175
}

0 commit comments

Comments
 (0)