@@ -45,7 +45,10 @@ public class DomainStatusUpdater {
45
45
public static final String INSPECTING_DOMAIN_PROGRESS_REASON = "InspectingDomainPrescence" ;
46
46
public static final String ADMIN_SERVER_STARTING_PROGRESS_REASON = "AdminServerStarting" ;
47
47
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
+
49
52
private static final String AVAILABLE_TYPE = "Available" ;
50
53
private static final String PROGRESSING_TYPE = "Progressing" ;
51
54
private static final String FAILED_TYPE = "Failed" ;
@@ -96,7 +99,6 @@ public NextAction apply(Packet packet) {
96
99
}
97
100
98
101
V1ObjectMeta metadata = pod .getMetadata ();
99
- String domainUID = metadata .getLabels ().get (LabelConstants .DOMAINUID_LABEL );
100
102
String serverName = metadata .getLabels ().get (LabelConstants .SERVERNAME_LABEL );
101
103
String clusterName = metadata .getLabels ().get (LabelConstants .CLUSTERNAME_LABEL );
102
104
@@ -488,6 +490,203 @@ public NextAction onSuccess(Packet packet, Domain result, int statusCode,
488
490
}
489
491
}
490
492
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
+
491
690
/**
492
691
* Asynchronous step to set Domain condition to Failed
493
692
* @param throwable Throwable that caused failure
@@ -570,8 +769,14 @@ public NextAction apply(Packet packet) {
570
769
dc .setLastTransitionTime (now );
571
770
}
572
771
break ;
573
- case AVAILABLE_TYPE :
574
772
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 ;
575
780
default :
576
781
it .remove ();
577
782
}
0 commit comments