Skip to content

Commit c59f9ff

Browse files
committed
Status update refactoring
1 parent 32c3f2a commit c59f9ff

File tree

2 files changed

+212
-6
lines changed

2 files changed

+212
-6
lines changed

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

Lines changed: 208 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ public class DomainStatusUpdater {
4545
public static final String INSPECTING_DOMAIN_PROGRESS_REASON = "InspectingDomainPrescence";
4646
public static final String ADMIN_SERVER_STARTING_PROGRESS_REASON = "AdminServerStarting";
4747
public static final String MANAGED_SERVERS_STARTING_PROGRESS_REASON = "ManagedServersStarting";
48-
48+
49+
public static final String SERVERS_READY_AVAILABLE_REASON = "ServersReady";
50+
public static final String ALL_STOPPED_AVAILABLE_REASON = "AllServersStopped";
51+
4952
private static final String AVAILABLE_TYPE = "Available";
5053
private static final String PROGRESSING_TYPE = "Progressing";
5154
private static final String FAILED_TYPE = "Failed";
@@ -96,7 +99,6 @@ public NextAction apply(Packet packet) {
9699
}
97100

98101
V1ObjectMeta metadata = pod.getMetadata();
99-
String domainUID = metadata.getLabels().get(LabelConstants.DOMAINUID_LABEL);
100102
String serverName = metadata.getLabels().get(LabelConstants.SERVERNAME_LABEL);
101103
String clusterName = metadata.getLabels().get(LabelConstants.CLUSTERNAME_LABEL);
102104

@@ -488,6 +490,203 @@ public NextAction onSuccess(Packet packet, Domain result, int statusCode,
488490
}
489491
}
490492

493+
/**
494+
* Asynchronous step to set Domain condition end Progressing and set Available, if needed
495+
* @param next Next step
496+
* @return Step
497+
*/
498+
public static Step createEndProgressingStep(Step next) {
499+
return new EndProgressingStep(next);
500+
}
501+
502+
private static class EndProgressingStep extends Step {
503+
504+
public EndProgressingStep(Step next) {
505+
super(next);
506+
}
507+
508+
@Override
509+
public NextAction apply(Packet packet) {
510+
LOGGER.entering();
511+
512+
DateTime now = DateTime.now();
513+
DomainPresenceInfo info = packet.getSPI(DomainPresenceInfo.class);
514+
515+
Domain dom = info.getDomain();
516+
V1ObjectMeta meta = dom.getMetadata();
517+
DomainStatus status = dom.getStatus();
518+
if (status == null) {
519+
status = new DomainStatus();
520+
status.setStartTime(now);
521+
dom.setStatus(status);
522+
}
523+
524+
List<DomainCondition> conditions = status.getConditions();
525+
if (conditions == null) {
526+
conditions = new ArrayList<>();
527+
status.setConditions(conditions);
528+
}
529+
530+
ListIterator<DomainCondition> it = conditions.listIterator();
531+
while (it.hasNext()) {
532+
DomainCondition dc = it.next();
533+
switch (dc.getType()) {
534+
case PROGRESSING_TYPE:
535+
if (TRUE.equals(dc.getStatus())) {
536+
it.remove();
537+
}
538+
break;
539+
case AVAILABLE_TYPE:
540+
case FAILED_TYPE:
541+
break;
542+
default:
543+
it.remove();
544+
}
545+
}
546+
547+
LOGGER.info(MessageKeys.DOMAIN_STATUS, dom.getSpec().getDomainUID(), status.getAvailableServers(), status.getAvailableClusters(), status.getUnavailableServers(), status.getUnavailableClusters(), conditions);
548+
LOGGER.exiting();
549+
550+
return doNext(CallBuilder.create().replaceDomainAsync(meta.getName(), meta.getNamespace(), dom, new ResponseStep<Domain>(next) {
551+
@Override
552+
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
553+
Map<String, List<String>> responseHeaders) {
554+
if (statusCode == CallBuilder.NOT_FOUND) {
555+
return doNext(packet); // Just ignore update
556+
}
557+
return super.onFailure(next, packet, e, statusCode, responseHeaders);
558+
}
559+
560+
@Override
561+
public NextAction onSuccess(Packet packet, Domain result, int statusCode,
562+
Map<String, List<String>> responseHeaders) {
563+
info.setDomain(result);
564+
return doNext(packet);
565+
}
566+
}), packet);
567+
}
568+
}
569+
570+
/**
571+
* Asynchronous step to set Domain condition to Available
572+
* @param reason Available reason
573+
* @param next Next step
574+
* @return Step
575+
*/
576+
public static Step createAvailableStep(String reason, Step next) {
577+
return new AvailableHookStep(reason, next);
578+
}
579+
580+
private static class AvailableHookStep extends Step {
581+
private final String reason;
582+
583+
private AvailableHookStep(String reason, Step next) {
584+
super(next);
585+
this.reason = reason;
586+
}
587+
588+
@Override
589+
public NextAction apply(Packet packet) {
590+
Fiber f = Fiber.current().createChildFiber();
591+
Packet p = new Packet();
592+
p.getComponents().putAll(packet.getComponents());
593+
f.start(new AvailableStep(reason), p, new CompletionCallback() {
594+
@Override
595+
public void onCompletion(Packet packet) {
596+
}
597+
598+
@Override
599+
public void onThrowable(Packet packet, Throwable throwable) {
600+
LOGGER.severe(MessageKeys.EXCEPTION, throwable);
601+
}
602+
});
603+
604+
return doNext(packet);
605+
}
606+
}
607+
608+
private static class AvailableStep extends Step {
609+
private final String reason;
610+
611+
private AvailableStep(String reason) {
612+
super(null);
613+
this.reason = reason;
614+
}
615+
616+
@Override
617+
public NextAction apply(Packet packet) {
618+
LOGGER.entering();
619+
620+
DateTime now = DateTime.now();
621+
DomainPresenceInfo info = packet.getSPI(DomainPresenceInfo.class);
622+
623+
Domain dom = info.getDomain();
624+
V1ObjectMeta meta = dom.getMetadata();
625+
DomainStatus status = dom.getStatus();
626+
if (status == null) {
627+
status = new DomainStatus();
628+
status.setStartTime(now);
629+
dom.setStatus(status);
630+
}
631+
632+
List<DomainCondition> conditions = status.getConditions();
633+
if (conditions == null) {
634+
conditions = new ArrayList<>();
635+
status.setConditions(conditions);
636+
}
637+
638+
ListIterator<DomainCondition> it = conditions.listIterator();
639+
boolean foundAvailable = false;
640+
while (it.hasNext()) {
641+
DomainCondition dc = it.next();
642+
switch (dc.getType()) {
643+
case AVAILABLE_TYPE:
644+
foundAvailable = true;
645+
if (!TRUE.equals(dc.getStatus())) {
646+
dc.setStatus(TRUE);
647+
dc.setLastTransitionTime(now);
648+
}
649+
dc.setReason(reason);
650+
break;
651+
case PROGRESSING_TYPE:
652+
break;
653+
case FAILED_TYPE:
654+
default:
655+
it.remove();
656+
}
657+
}
658+
if (!foundAvailable) {
659+
DomainCondition dc = new DomainCondition();
660+
dc.setType(AVAILABLE_TYPE);
661+
dc.setStatus(TRUE);
662+
dc.setLastTransitionTime(now);
663+
dc.setReason(reason);
664+
conditions.add(dc);
665+
}
666+
667+
LOGGER.info(MessageKeys.DOMAIN_STATUS, dom.getSpec().getDomainUID(), status.getAvailableServers(), status.getAvailableClusters(), status.getUnavailableServers(), status.getUnavailableClusters(), conditions);
668+
LOGGER.exiting();
669+
670+
return doNext(CallBuilder.create().replaceDomainAsync(meta.getName(), meta.getNamespace(), dom, new ResponseStep<Domain>(next) {
671+
@Override
672+
public NextAction onFailure(Packet packet, ApiException e, int statusCode,
673+
Map<String, List<String>> responseHeaders) {
674+
if (statusCode == CallBuilder.NOT_FOUND) {
675+
return doNext(packet); // Just ignore update
676+
}
677+
return super.onFailure(next, packet, e, statusCode, responseHeaders);
678+
}
679+
680+
@Override
681+
public NextAction onSuccess(Packet packet, Domain result, int statusCode,
682+
Map<String, List<String>> responseHeaders) {
683+
info.setDomain(result);
684+
return doNext(packet);
685+
}
686+
}), packet);
687+
}
688+
}
689+
491690
/**
492691
* Asynchronous step to set Domain condition to Failed
493692
* @param throwable Throwable that caused failure
@@ -570,8 +769,14 @@ public NextAction apply(Packet packet) {
570769
dc.setLastTransitionTime(now);
571770
}
572771
break;
573-
case AVAILABLE_TYPE:
574772
case PROGRESSING_TYPE:
773+
if (!FALSE.equals(dc.getStatus())) {
774+
dc.setStatus(FALSE);
775+
dc.setLastTransitionTime(now);
776+
}
777+
break;
778+
case AVAILABLE_TYPE:
779+
break;
575780
default:
576781
it.remove();
577782
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ private static void doCheckAndCreateDomainPresence(
415415

416416
LOGGER.info(MessageKeys.PROCESSING_DOMAIN, domainUID);
417417

418-
Step managedServerStrategy = bringManagedServersUp(null);
418+
Step managedServerStrategy = bringManagedServersUp(
419+
DomainStatusUpdater.createEndProgressingStep(null));
419420
Step adminServerStrategy = bringAdminServerUp(
420421
connectToAdminAndInspectDomain(
421422
managedServerStrategy));
@@ -508,9 +509,8 @@ public NextAction apply(Packet packet) {
508509
return doNext(packet);
509510
}
510511

511-
// none flow
512-
// TODO: stop admin pod
513512
LOGGER.exiting();
513+
// admin server will be stopped as part of scale down flow
514514
return doNext(managedServerStep, packet);
515515
}
516516
}
@@ -850,6 +850,7 @@ private static Step scaleDownIfNecessary(DomainPresenceInfo info, Collection<Str
850850
String sc = spec.getStartupControl();
851851
if (sc != null && StartupControlConstants.NONE_STARTUPCONTROL.equals(sc.toUpperCase())) {
852852
shouldStopAdmin = true;
853+
next = DomainStatusUpdater.createAvailableStep(DomainStatusUpdater.ALL_STOPPED_AVAILABLE_REASON, next);
853854
}
854855

855856
String adminName = spec.getAsName();

0 commit comments

Comments
 (0)