@@ -323,7 +323,8 @@ private static void addConfigForCluster(
323
323
Status .INTERNAL .withDescription ("Logical DNS in dependency manager unsupported" )));
324
324
break ;
325
325
default :
326
- throw new IllegalStateException ("Unexpected value: " + cdsUpdate .clusterType ());
326
+ child = new EndpointConfig (StatusOr .fromStatus (Status .UNAVAILABLE .withDescription (
327
+ "Unknown type in cluster " + clusterName + " " + cdsUpdate .clusterType ())));
327
328
}
328
329
clusters .put (clusterName , StatusOr .fromValue (
329
330
new XdsConfig .XdsClusterConfig (clusterName , cdsUpdate , child )));
@@ -505,7 +506,7 @@ public void onError(Status error) {
505
506
}
506
507
// Don't update configuration on error, if we've already received configuration
507
508
if (!hasDataValue ()) {
508
- setDataAsStatus (Status .UNAVAILABLE .withDescription (
509
+ this . data = StatusOr . fromStatus (Status .UNAVAILABLE .withDescription (
509
510
String .format ("Error retrieving %s: %s: %s" ,
510
511
toContextString (), error .getCode (), error .getDescription ())));
511
512
maybePublishConfig ();
@@ -519,11 +520,25 @@ public void onResourceDoesNotExist(String resourceName) {
519
520
}
520
521
521
522
checkArgument (this .resourceName .equals (resourceName ), "Resource name does not match" );
522
- setDataAsStatus (Status .UNAVAILABLE .withDescription (
523
+ this . data = StatusOr . fromStatus (Status .UNAVAILABLE .withDescription (
523
524
toContextString () + " does not exist" + nodeInfo ()));
524
525
maybePublishConfig ();
525
526
}
526
527
528
+ @ Override
529
+ public void onChanged (T update ) {
530
+ checkNotNull (update , "update" );
531
+ if (cancelled ) {
532
+ return ;
533
+ }
534
+
535
+ this .data = StatusOr .fromValue (update );
536
+ subscribeToChildren (update );
537
+ maybePublishConfig ();
538
+ }
539
+
540
+ protected abstract void subscribeToChildren (T update );
541
+
527
542
public void close () {
528
543
cancelled = true ;
529
544
xdsClient .cancelXdsResourceWatch (type , resourceName , this );
@@ -542,20 +557,6 @@ boolean hasDataValue() {
542
557
return data != null && data .hasValue ();
543
558
}
544
559
545
- String resourceName () {
546
- return resourceName ;
547
- }
548
-
549
- protected void setData (T data ) {
550
- checkNotNull (data , "data" );
551
- this .data = StatusOr .fromValue (data );
552
- }
553
-
554
- protected void setDataAsStatus (Status status ) {
555
- checkNotNull (status , "status" );
556
- this .data = StatusOr .fromStatus (status );
557
- }
558
-
559
560
public String toContextString () {
560
561
return toContextStr (type .typeName (), resourceName );
561
562
}
@@ -573,12 +574,7 @@ private LdsWatcher(String resourceName) {
573
574
}
574
575
575
576
@ Override
576
- public void onChanged (XdsListenerResource .LdsUpdate update ) {
577
- checkNotNull (update , "update" );
578
- if (cancelled ) {
579
- return ;
580
- }
581
-
577
+ public void subscribeToChildren (XdsListenerResource .LdsUpdate update ) {
582
578
HttpConnectionManager httpConnectionManager = update .httpConnectionManager ();
583
579
List <VirtualHost > virtualHosts ;
584
580
if (httpConnectionManager == null ) {
@@ -595,9 +591,6 @@ public void onChanged(XdsListenerResource.LdsUpdate update) {
595
591
if (rdsName != null ) {
596
592
addRdsWatcher (rdsName );
597
593
}
598
-
599
- setData (update );
600
- maybePublishConfig ();
601
594
}
602
595
603
596
private String getRdsName (XdsListenerResource .LdsUpdate update ) {
@@ -665,14 +658,8 @@ public RdsWatcher(String resourceName) {
665
658
}
666
659
667
660
@ Override
668
- public void onChanged (RdsUpdate update ) {
669
- checkNotNull (update , "update" );
670
- if (cancelled ) {
671
- return ;
672
- }
673
- setData (update );
661
+ public void subscribeToChildren (RdsUpdate update ) {
674
662
updateRoutes (update .virtualHosts );
675
- maybePublishConfig ();
676
663
}
677
664
678
665
@ Override
@@ -690,31 +677,20 @@ private class CdsWatcher extends XdsWatcherBase<XdsClusterResource.CdsUpdate> {
690
677
}
691
678
692
679
@ Override
693
- public void onChanged (XdsClusterResource .CdsUpdate update ) {
694
- checkNotNull (update , "update" );
695
- if (cancelled ) {
696
- return ;
697
- }
680
+ public void subscribeToChildren (XdsClusterResource .CdsUpdate update ) {
698
681
switch (update .clusterType ()) {
699
682
case EDS :
700
- setData (update );
701
683
addEdsWatcher (getEdsServiceName ());
702
684
break ;
703
685
case LOGICAL_DNS :
704
- setData (update );
705
686
// no eds needed
706
687
break ;
707
688
case AGGREGATE :
708
- setData (update );
709
689
update .prioritizedClusterNames ()
710
690
.forEach (name -> addClusterWatcher (name ));
711
691
break ;
712
692
default :
713
- Status error = Status .UNAVAILABLE .withDescription (
714
- "unknown cluster type in " + resourceName () + " " + update .clusterType ());
715
- setDataAsStatus (error );
716
693
}
717
- maybePublishConfig ();
718
694
}
719
695
720
696
public String getEdsServiceName () {
@@ -734,12 +710,6 @@ private EdsWatcher(String resourceName) {
734
710
}
735
711
736
712
@ Override
737
- public void onChanged (XdsEndpointResource .EdsUpdate update ) {
738
- if (cancelled ) {
739
- return ;
740
- }
741
- setData (checkNotNull (update , "update" ));
742
- maybePublishConfig ();
743
- }
713
+ public void subscribeToChildren (XdsEndpointResource .EdsUpdate update ) {}
744
714
}
745
715
}
0 commit comments