Skip to content

Commit 2ebd13b

Browse files
committed
Restore per-managed server service lifetime
1 parent a014a43 commit 2ebd13b

File tree

2 files changed

+66
-72
lines changed

2 files changed

+66
-72
lines changed

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

Lines changed: 16 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ else if (StartupControlConstants.AUTO_STARTUPCONTROL.equals(sc)) {
903903
info.setServerStartupInfo(ssic);
904904
LOGGER.exiting();
905905
return doNext(scaleDownIfNecessary(info, servers,
906-
checkServerServices(info, new ManagedServerUpIteratorStep(ssic, next))),
906+
new ClusterServicesStep(info, new ManagedServerUpIteratorStep(ssic, next))),
907907
packet);
908908
case StartupControlConstants.ADMIN_STARTUPCONTROL:
909909
case StartupControlConstants.NONE_STARTUPCONTROL:
@@ -912,7 +912,7 @@ else if (StartupControlConstants.AUTO_STARTUPCONTROL.equals(sc)) {
912912
info.setServerStartupInfo(null);
913913
LOGGER.exiting();
914914
return doNext(scaleDownIfNecessary(info, servers,
915-
checkServerServices(info, next)),
915+
new ClusterServicesStep(info, next)),
916916
packet);
917917
}
918918
}
@@ -949,84 +949,18 @@ private static List<V1EnvVar> startInAdminMode(List<V1EnvVar> env) {
949949
return env;
950950
}
951951

952-
private static Step checkServerServices(DomainPresenceInfo info, Step next) {
953-
Collection<String> allServers = new ArrayList<>();
954-
Collection<ServerStartupInfo> ssic = new ArrayList<>();
955-
956-
WlsDomainConfig scan = info.getScan();
957-
958-
// Iterate all servers
959-
for (WlsClusterConfig wlsClusterConfig : scan.getClusterConfigs().values()) {
960-
for (WlsServerConfig wlsServerConfig : wlsClusterConfig.getServerConfigs()) {
961-
String serverName = wlsServerConfig.getListenAddress();
962-
if (!allServers.contains(serverName)) {
963-
allServers.add(serverName);
964-
ssic.add(new ServerStartupInfo(wlsServerConfig, wlsClusterConfig, null, null));
965-
}
966-
}
967-
}
968-
for (Map.Entry<String, WlsServerConfig> wlsServerConfig : scan.getServerConfigs().entrySet()) {
969-
String serverName = wlsServerConfig.getKey();
970-
if (!allServers.contains(serverName)) {
971-
allServers.add(serverName);
972-
ssic.add(new ServerStartupInfo(wlsServerConfig.getValue(), null, null, null));
973-
}
974-
}
975-
976-
return new ManagedServerServicesStep(info, ssic, next);
977-
}
978-
979-
private static class ManagedServerServicesStep extends Step {
952+
private static class ClusterServicesStep extends Step {
980953
private final DomainPresenceInfo info;
981-
private final Collection<ServerStartupInfo> ssic;
982954

983-
public ManagedServerServicesStep(DomainPresenceInfo info, Collection<ServerStartupInfo> ssic, Step next) {
955+
public ClusterServicesStep(DomainPresenceInfo info, Step next) {
984956
super(next);
985957
this.info = info;
986-
this.ssic = ssic;
987958
}
988959

989960
@Override
990961
public NextAction apply(Packet packet) {
991962
Collection<StepAndPacket> startDetails = new ArrayList<>();
992963

993-
for (ServerStartupInfo ssi : ssic) {
994-
Packet p = packet.clone();
995-
WlsServerConfig serverConfig = ssi.serverConfig;
996-
ServerStartup serverStartup = ssi.serverStartup;
997-
String serverName = serverConfig.getName();
998-
p.put(ProcessingConstants.SERVER_SCAN, serverConfig);
999-
p.put(ProcessingConstants.CLUSTER_SCAN, ssi.clusterConfig);
1000-
p.put(ProcessingConstants.ENVVARS, ssi.envVars);
1001-
1002-
DomainSpec spec = info.getDomain().getSpec();
1003-
Integer nodePort = null;
1004-
if (serverStartup == null) {
1005-
List<ServerStartup> ssl = spec.getServerStartup();
1006-
if (ssl != null) {
1007-
for (ServerStartup ss : ssl) {
1008-
if (serverName.equals(ss.getServerName())) {
1009-
serverStartup = ss;
1010-
break;
1011-
}
1012-
}
1013-
}
1014-
}
1015-
1016-
if (serverStartup != null) {
1017-
nodePort = serverStartup.getNodePort();
1018-
}
1019-
1020-
p.put(ProcessingConstants.SERVER_NAME, serverName);
1021-
if (ssi.clusterConfig != null) {
1022-
p.put(ProcessingConstants.CLUSTER_NAME, ssi.clusterConfig.getClusterName());
1023-
}
1024-
p.put(ProcessingConstants.PORT, serverConfig.getListenPort());
1025-
p.put(ProcessingConstants.NODE_PORT, nodePort);
1026-
1027-
startDetails.add(new StepAndPacket(ServiceHelper.createForServerStep(null), p));
1028-
}
1029-
1030964
// Add cluster services
1031965
WlsDomainConfig scan = info.getScan();
1032966
if (scan != null) {
@@ -1100,6 +1034,13 @@ public NextAction apply(Packet packet) {
11001034
p.put(ProcessingConstants.CLUSTER_SCAN, ssi.clusterConfig);
11011035
p.put(ProcessingConstants.ENVVARS, ssi.envVars);
11021036

1037+
p.put(ProcessingConstants.SERVER_NAME, ssi.serverConfig.getName());
1038+
p.put(ProcessingConstants.PORT, ssi.serverConfig.getListenPort());
1039+
ServerStartup ss = ssi.serverStartup;
1040+
if (ss != null) {
1041+
p.put(ProcessingConstants.NODE_PORT, ss.getNodePort());
1042+
}
1043+
11031044
startDetails.add(new StepAndPacket(bringManagedServerUp(ssi, null), p));
11041045
}
11051046

@@ -1202,7 +1143,9 @@ public ServerDownStep(String serverName, ServerKubernetesObjects sko, Step next)
12021143

12031144
@Override
12041145
public NextAction apply(Packet packet) {
1205-
return doNext(PodHelper.deletePodStep(sko, new ServerDownFinalizeStep(serverName, next)), packet);
1146+
return doNext(PodHelper.deletePodStep(sko,
1147+
ServiceHelper.deleteServiceStep(sko,
1148+
new ServerDownFinalizeStep(serverName, next))), packet);
12061149
}
12071150
}
12081151

@@ -1228,7 +1171,8 @@ public NextAction apply(Packet packet) {
12281171
// "clusterScan"
12291172
// "envVars"
12301173
private static Step bringManagedServerUp(ServerStartupInfo ssi, Step next) {
1231-
return PodHelper.createManagedPodStep(next);
1174+
return PodHelper.createManagedPodStep(
1175+
ServiceHelper.createForServerStep(next));
12321176
}
12331177

12341178
private static void deleteDomainPresence(Domain dom) {

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,56 @@ public NextAction onSuccess(Packet packet, V1Service result, int statusCode,
161161
}
162162
}
163163

164+
/**
165+
* Factory for {@link Step} that deletes per-managed server service
166+
* @param sko Server Kubernetes Objects
167+
* @param next Next processing step
168+
* @return Step for deleting per-managed server service
169+
*/
170+
public static Step deleteServiceStep(ServerKubernetesObjects sko, Step next) {
171+
return new DeleteServiceStep(sko, next);
172+
}
173+
174+
private static class DeleteServiceStep extends Step {
175+
private final ServerKubernetesObjects sko;
176+
177+
public DeleteServiceStep(ServerKubernetesObjects sko, Step next) {
178+
super(next);
179+
this.sko = sko;
180+
}
181+
182+
@Override
183+
public NextAction apply(Packet packet) {
184+
DomainPresenceInfo info = packet.getSPI(DomainPresenceInfo.class);
185+
186+
Domain dom = info.getDomain();
187+
V1ObjectMeta meta = dom.getMetadata();
188+
String namespace = meta.getNamespace();
189+
190+
// Set service to null so that watcher doesn't try to recreate service
191+
V1Service oldService = sko.getService().getAndSet(null);
192+
if (oldService != null) {
193+
return doNext(CallBuilder.create().deleteServiceAsync(oldService.getMetadata().getName(), namespace, new ResponseStep<V1Status>(next) {
194+
@Override
195+
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
196+
Map<String, List<String>> responseHeaders) {
197+
if (statusCode == CallBuilder.NOT_FOUND) {
198+
return onSuccess(packet, null, statusCode, responseHeaders);
199+
}
200+
return super.onFailure(packet, e, statusCode, responseHeaders);
201+
}
202+
203+
@Override
204+
public NextAction onSuccess(Packet packet, V1Status result, int statusCode,
205+
Map<String, List<String>> responseHeaders) {
206+
return doNext(next, packet);
207+
}
208+
}), packet);
209+
}
210+
return doNext(packet);
211+
}
212+
}
213+
164214
/**
165215
* Create asynchronous step for internal cluster service
166216
* @param next Next processing step

0 commit comments

Comments
 (0)