16
16
import java .util .ArrayList ;
17
17
import java .util .List ;
18
18
import java .util .Map ;
19
+ import java .util .Optional ;
19
20
import java .util .concurrent .ConcurrentHashMap ;
20
21
import java .util .concurrent .ConcurrentMap ;
21
22
import java .util .concurrent .ScheduledFuture ;
31
32
import oracle .kubernetes .operator .helpers .KubernetesUtils ;
32
33
import oracle .kubernetes .operator .helpers .PodHelper ;
33
34
import oracle .kubernetes .operator .helpers .ResponseStep ;
34
- import oracle .kubernetes .operator .helpers .ServerKubernetesObjects ;
35
35
import oracle .kubernetes .operator .helpers .ServiceHelper ;
36
36
import oracle .kubernetes .operator .logging .LoggingFacade ;
37
37
import oracle .kubernetes .operator .logging .LoggingFactory ;
@@ -135,66 +135,22 @@ public void stopNamespace(String ns) {
135
135
}
136
136
137
137
public void dispatchPodWatch (Watch .Response <V1Pod > item ) {
138
- V1Pod p = item .object ;
139
- if (p != null ) {
140
- V1ObjectMeta metadata = p .getMetadata ();
138
+ V1Pod pod = item .object ;
139
+ if (pod != null ) {
140
+ V1ObjectMeta metadata = pod .getMetadata ();
141
141
String domainUID = metadata .getLabels ().get (LabelConstants .DOMAINUID_LABEL );
142
142
String serverName = metadata .getLabels ().get (LabelConstants .SERVERNAME_LABEL );
143
143
if (domainUID != null && serverName != null ) {
144
144
DomainPresenceInfo info = getExistingDomainPresenceInfo (metadata .getNamespace (), domainUID );
145
145
if (info != null ) {
146
- ServerKubernetesObjects sko =
147
- info .getServers ().computeIfAbsent (serverName , k -> new ServerKubernetesObjects ());
148
146
switch (item .type ) {
149
147
case "ADDED" :
150
- sko .getPod ()
151
- .accumulateAndGet (
152
- p ,
153
- (current , ob ) -> {
154
- if (current != null ) {
155
- if (KubernetesUtils .isFirstNewer (current .getMetadata (), metadata )) {
156
- return current ;
157
- }
158
- }
159
- return ob ;
160
- });
161
- break ;
162
148
case "MODIFIED" :
163
- if (PodWatcher .isReady (p )) {
164
- sko .getLastKnownStatus ().set (WebLogicConstants .RUNNING_STATE );
165
- } else {
166
- sko .getLastKnownStatus ().compareAndSet (WebLogicConstants .RUNNING_STATE , null );
167
- }
168
- sko .getPod ()
169
- .accumulateAndGet (
170
- p ,
171
- (current , ob ) -> {
172
- if (current != null ) {
173
- if (!KubernetesUtils .isFirstNewer (current .getMetadata (), metadata )) {
174
- return ob ;
175
- }
176
- }
177
- // If the skoPod is null then the operator deleted this pod
178
- // and modifications are to the terminating pod
179
- return current ;
180
- });
149
+ info .setServerPodFromEvent (serverName , pod );
181
150
break ;
182
151
case "DELETED" :
183
- V1Pod oldPod =
184
- sko .getPod ()
185
- .getAndAccumulate (
186
- p ,
187
- (current , ob ) -> {
188
- if (current != null ) {
189
- if (!KubernetesUtils .isFirstNewer (current .getMetadata (), metadata )) {
190
- sko .getLastKnownStatus ().set (WebLogicConstants .SHUTDOWN_STATE );
191
- return null ;
192
- }
193
- }
194
- return current ;
195
- });
196
- if (oldPod != null && info .isNotDeleting ()) {
197
- // Pod was deleted, but sko still contained a non-null entry
152
+ boolean removed = info .deleteServerPodFromEvent (serverName , pod );
153
+ if (removed && info .isNotDeleting ()) {
198
154
LOGGER .info (
199
155
MessageKeys .POD_DELETED , domainUID , metadata .getNamespace (), serverName );
200
156
makeRightDomainPresence (info , true , false , true );
@@ -209,6 +165,14 @@ public void dispatchPodWatch(Watch.Response<V1Pod> item) {
209
165
}
210
166
}
211
167
168
+ private V1Pod getNewerPod (V1Pod first , V1Pod second ) {
169
+ return KubernetesUtils .isFirstNewer (getMetadata (first ), getMetadata (second )) ? first : second ;
170
+ }
171
+
172
+ private V1ObjectMeta getMetadata (V1Pod pod ) {
173
+ return pod == null ? null : pod .getMetadata ();
174
+ }
175
+
212
176
public void dispatchServiceWatch (Watch .Response <V1Service > item ) {
213
177
V1Service service = item .object ;
214
178
String domainUID = ServiceHelper .getServiceDomainUID (service );
@@ -265,30 +229,24 @@ public void dispatchEventWatch(Watch.Response<V1Event> item) {
265
229
266
230
private static void onEvent (V1Event event ) {
267
231
V1ObjectReference ref = event .getInvolvedObject ();
268
- if (ref != null ) {
269
- String name = ref .getName ();
270
- String message = event .getMessage ();
271
- if (message != null ) {
272
- if (message .contains (WebLogicConstants .READINESS_PROBE_NOT_READY_STATE )) {
273
- String ns = event .getMetadata ().getNamespace ();
274
- Map <String , DomainPresenceInfo > map = DOMAINS .get (ns );
275
- if (map != null ) {
276
- for (DomainPresenceInfo d : map .values ()) {
277
- String domainUIDPlusDash = d .getDomainUID () + "-" ;
278
- if (name .startsWith (domainUIDPlusDash )) {
279
- String serverName = name .substring (domainUIDPlusDash .length ());
280
- ServerKubernetesObjects sko = d .getServers ().get (serverName );
281
- if (sko != null ) {
282
- int idx = message .lastIndexOf (':' );
283
- sko .getLastKnownStatus ().set (message .substring (idx + 1 ).trim ());
284
- break ;
285
- }
286
- }
287
- }
288
- }
289
- }
290
- }
291
- }
232
+ if (ref == null ) return ;
233
+
234
+ String [] domainAndServer = ref .getName ().split ("-" );
235
+ String domainUid = domainAndServer [0 ];
236
+ String serverName = domainAndServer [1 ];
237
+ String status = getReadinessStatus (event );
238
+ if (status == null ) return ;
239
+
240
+ Optional .ofNullable (DOMAINS .get (event .getMetadata ().getNamespace ()))
241
+ .map (m -> m .get (domainUid ))
242
+ .ifPresent (info -> info .setLastKnownServerStatus (serverName , status ));
243
+ }
244
+
245
+ private static String getReadinessStatus (V1Event event ) {
246
+ return Optional .ofNullable (event .getMessage ())
247
+ .filter (m -> m .contains (WebLogicConstants .READINESS_PROBE_NOT_READY_STATE ))
248
+ .map (m -> m .substring (m .lastIndexOf (':' ) + 1 ).trim ())
249
+ .orElse (null );
292
250
}
293
251
294
252
/**
@@ -542,11 +500,9 @@ public NextAction onSuccess(Packet packet, CallResponse<V1PodList> callResponse)
542
500
V1PodList result = callResponse .getResult ();
543
501
if (result != null ) {
544
502
for (V1Pod pod : result .getItems ()) {
545
- String serverName = PodWatcher .getPodServerName (pod );
503
+ String serverName = PodHelper .getPodServerName (pod );
546
504
if (serverName != null ) {
547
- ServerKubernetesObjects sko =
548
- info .getServers ().computeIfAbsent (serverName , k -> new ServerKubernetesObjects ());
549
- sko .getPod ().set (pod );
505
+ info .setServerPod (serverName , pod );
550
506
}
551
507
}
552
508
}
0 commit comments