@@ -333,7 +333,8 @@ private static void addConfigForCluster(
333
333
Status .INTERNAL .withDescription ("Logical DNS in dependency manager unsupported" )));
334
334
break ;
335
335
default :
336
- throw new IllegalStateException ("Unexpected value: " + cdsUpdate .clusterType ());
336
+ child = new EndpointConfig (StatusOr .fromStatus (Status .UNAVAILABLE .withDescription (
337
+ "Unknown type in cluster " + clusterName + " " + cdsUpdate .clusterType ())));
337
338
}
338
339
if (clusters .containsKey (clusterName )) {
339
340
// If a cycle is detected, we'll have detected it while recursing, so now there will be a key
@@ -520,7 +521,7 @@ public void onError(Status error) {
520
521
}
521
522
// Don't update configuration on error, if we've already received configuration
522
523
if (!hasDataValue ()) {
523
- setDataAsStatus (Status .UNAVAILABLE .withDescription (
524
+ this . data = StatusOr . fromStatus (Status .UNAVAILABLE .withDescription (
524
525
String .format ("Error retrieving %s: %s: %s" ,
525
526
toContextString (), error .getCode (), error .getDescription ())));
526
527
maybePublishConfig ();
@@ -534,11 +535,25 @@ public void onResourceDoesNotExist(String resourceName) {
534
535
}
535
536
536
537
checkArgument (this .resourceName .equals (resourceName ), "Resource name does not match" );
537
- setDataAsStatus (Status .UNAVAILABLE .withDescription (
538
+ this . data = StatusOr . fromStatus (Status .UNAVAILABLE .withDescription (
538
539
toContextString () + " does not exist" + nodeInfo ()));
539
540
maybePublishConfig ();
540
541
}
541
542
543
+ @ Override
544
+ public void onChanged (T update ) {
545
+ checkNotNull (update , "update" );
546
+ if (cancelled ) {
547
+ return ;
548
+ }
549
+
550
+ this .data = StatusOr .fromValue (update );
551
+ subscribeToChildren (update );
552
+ maybePublishConfig ();
553
+ }
554
+
555
+ protected abstract void subscribeToChildren (T update );
556
+
542
557
public void close () {
543
558
cancelled = true ;
544
559
xdsClient .cancelXdsResourceWatch (type , resourceName , this );
@@ -557,20 +572,6 @@ boolean hasDataValue() {
557
572
return data != null && data .hasValue ();
558
573
}
559
574
560
- String resourceName () {
561
- return resourceName ;
562
- }
563
-
564
- protected void setData (T data ) {
565
- checkNotNull (data , "data" );
566
- this .data = StatusOr .fromValue (data );
567
- }
568
-
569
- protected void setDataAsStatus (Status status ) {
570
- checkNotNull (status , "status" );
571
- this .data = StatusOr .fromStatus (status );
572
- }
573
-
574
575
public String toContextString () {
575
576
return toContextStr (type .typeName (), resourceName );
576
577
}
@@ -588,12 +589,7 @@ private LdsWatcher(String resourceName) {
588
589
}
589
590
590
591
@ Override
591
- public void onChanged (XdsListenerResource .LdsUpdate update ) {
592
- checkNotNull (update , "update" );
593
- if (cancelled ) {
594
- return ;
595
- }
596
-
592
+ public void subscribeToChildren (XdsListenerResource .LdsUpdate update ) {
597
593
HttpConnectionManager httpConnectionManager = update .httpConnectionManager ();
598
594
List <VirtualHost > virtualHosts ;
599
595
if (httpConnectionManager == null ) {
@@ -610,9 +606,6 @@ public void onChanged(XdsListenerResource.LdsUpdate update) {
610
606
if (rdsName != null ) {
611
607
addRdsWatcher (rdsName );
612
608
}
613
-
614
- setData (update );
615
- maybePublishConfig ();
616
609
}
617
610
618
611
private String getRdsName (XdsListenerResource .LdsUpdate update ) {
@@ -680,14 +673,8 @@ public RdsWatcher(String resourceName) {
680
673
}
681
674
682
675
@ Override
683
- public void onChanged (RdsUpdate update ) {
684
- checkNotNull (update , "update" );
685
- if (cancelled ) {
686
- return ;
687
- }
688
- setData (update );
676
+ public void subscribeToChildren (RdsUpdate update ) {
689
677
updateRoutes (update .virtualHosts );
690
- maybePublishConfig ();
691
678
}
692
679
693
680
@ Override
@@ -705,31 +692,20 @@ private class CdsWatcher extends XdsWatcherBase<XdsClusterResource.CdsUpdate> {
705
692
}
706
693
707
694
@ Override
708
- public void onChanged (XdsClusterResource .CdsUpdate update ) {
709
- checkNotNull (update , "update" );
710
- if (cancelled ) {
711
- return ;
712
- }
695
+ public void subscribeToChildren (XdsClusterResource .CdsUpdate update ) {
713
696
switch (update .clusterType ()) {
714
697
case EDS :
715
- setData (update );
716
698
addEdsWatcher (getEdsServiceName ());
717
699
break ;
718
700
case LOGICAL_DNS :
719
- setData (update );
720
701
// no eds needed
721
702
break ;
722
703
case AGGREGATE :
723
- setData (update );
724
704
update .prioritizedClusterNames ()
725
705
.forEach (name -> addClusterWatcher (name ));
726
706
break ;
727
707
default :
728
- Status error = Status .UNAVAILABLE .withDescription (
729
- "unknown cluster type in " + resourceName () + " " + update .clusterType ());
730
- setDataAsStatus (error );
731
708
}
732
- maybePublishConfig ();
733
709
}
734
710
735
711
public String getEdsServiceName () {
@@ -749,12 +725,6 @@ private EdsWatcher(String resourceName) {
749
725
}
750
726
751
727
@ Override
752
- public void onChanged (XdsEndpointResource .EdsUpdate update ) {
753
- if (cancelled ) {
754
- return ;
755
- }
756
- setData (checkNotNull (update , "update" ));
757
- maybePublishConfig ();
758
- }
728
+ public void subscribeToChildren (XdsEndpointResource .EdsUpdate update ) {}
759
729
}
760
730
}
0 commit comments