16
16
17
17
package io .grpc .xds ;
18
18
19
- import static com .google .common .base .Preconditions .checkNotNull ;
20
-
19
+ import com .google .auto .value .AutoValue ;
21
20
import com .google .common .annotations .VisibleForTesting ;
21
+ import com .google .common .collect .ImmutableList ;
22
+ import com .google .common .collect .ImmutableMap ;
22
23
import io .grpc .ChannelCredentials ;
23
24
import io .grpc .Internal ;
24
25
import io .grpc .xds .EnvoyProtoData .Node ;
25
- import java .util .Collections ;
26
26
import java .util .List ;
27
27
import java .util .Map ;
28
28
import javax .annotation .Nullable ;
@@ -49,101 +49,77 @@ BootstrapInfo bootstrap(Map<String, ?> rawData) throws XdsInitializationExceptio
49
49
* Data class containing xDS server information, such as server URI and channel credentials
50
50
* to be used for communication.
51
51
*/
52
+ @ AutoValue
52
53
@ Internal
53
- static class ServerInfo {
54
- private final String target ;
55
- private final ChannelCredentials channelCredentials ;
56
- private final boolean useProtocolV3 ;
54
+ abstract static class ServerInfo {
55
+ abstract String target ();
57
56
58
- @ VisibleForTesting
59
- ServerInfo (String target , ChannelCredentials channelCredentials , boolean useProtocolV3 ) {
60
- this .target = checkNotNull (target , "target" );
61
- this .channelCredentials = checkNotNull (channelCredentials , "channelCredentials" );
62
- this .useProtocolV3 = useProtocolV3 ;
63
- }
57
+ abstract ChannelCredentials channelCredentials ();
64
58
65
- String getTarget () {
66
- return target ;
67
- }
59
+ abstract boolean useProtocolV3 ();
68
60
69
- ChannelCredentials getChannelCredentials () {
70
- return channelCredentials ;
71
- }
72
-
73
- boolean isUseProtocolV3 () {
74
- return useProtocolV3 ;
61
+ @ VisibleForTesting
62
+ static ServerInfo create (
63
+ String target , ChannelCredentials channelCredentials , boolean useProtocolV3 ) {
64
+ return new AutoValue_Bootstrapper_ServerInfo (target , channelCredentials , useProtocolV3 );
75
65
}
76
66
}
77
67
78
68
/**
79
69
* Data class containing Certificate provider information: the plugin-name and an opaque
80
70
* Map that represents the config for that plugin.
81
71
*/
72
+ @ AutoValue
82
73
@ Internal
83
- public static class CertificateProviderInfo {
84
- private final String pluginName ;
85
- private final Map <String , ?> config ;
74
+ public abstract static class CertificateProviderInfo {
75
+ public abstract String pluginName ();
86
76
87
- @ VisibleForTesting
88
- public CertificateProviderInfo (String pluginName , Map <String , ?> config ) {
89
- this .pluginName = checkNotNull (pluginName , "pluginName" );
90
- this .config = checkNotNull (config , "config" );
91
- }
92
-
93
- public String getPluginName () {
94
- return pluginName ;
95
- }
77
+ public abstract ImmutableMap <String , ?> config ();
96
78
97
- public Map <String , ?> getConfig () {
98
- return config ;
79
+ @ VisibleForTesting
80
+ public static CertificateProviderInfo create (String pluginName , Map <String , ?> config ) {
81
+ return new AutoValue_Bootstrapper_CertificateProviderInfo (
82
+ pluginName , ImmutableMap .copyOf (config ));
99
83
}
100
84
}
101
85
102
86
/**
103
87
* Data class containing the results of reading bootstrap.
104
88
*/
89
+ @ AutoValue
105
90
@ Internal
106
- public static class BootstrapInfo {
107
- private List <ServerInfo > servers ;
108
- private final Node node ;
109
- @ Nullable private final Map <String , CertificateProviderInfo > certProviders ;
110
- @ Nullable private final String serverListenerResourceNameTemplate ;
91
+ public abstract static class BootstrapInfo {
92
+ /** Returns the list of xDS servers to be connected to. */
93
+ abstract ImmutableList <ServerInfo > servers ();
94
+
95
+ /** Returns the node identifier to be included in xDS requests. */
96
+ public abstract Node node ();
97
+
98
+ /** Returns the cert-providers config map. */
99
+ @ Nullable
100
+ public abstract ImmutableMap <String , CertificateProviderInfo > certProviders ();
101
+
102
+ @ Nullable
103
+ public abstract String serverListenerResourceNameTemplate ();
111
104
112
105
@ VisibleForTesting
113
- BootstrapInfo (
114
- List <ServerInfo > servers ,
115
- Node node ,
116
- Map <String , CertificateProviderInfo > certProviders ,
117
- String serverListenerResourceNameTemplate ) {
118
- this .servers = servers ;
119
- this .node = node ;
120
- this .certProviders = certProviders ;
121
- this .serverListenerResourceNameTemplate = serverListenerResourceNameTemplate ;
106
+ static Builder builder () {
107
+ return new AutoValue_Bootstrapper_BootstrapInfo .Builder ();
122
108
}
123
109
124
- /**
125
- * Returns the list of xDS servers to be connected to.
126
- */
127
- List <ServerInfo > getServers () {
128
- return Collections .unmodifiableList (servers );
129
- }
110
+ @ AutoValue .Builder
111
+ @ VisibleForTesting
112
+ abstract static class Builder {
113
+ abstract Builder servers (List <ServerInfo > servers );
130
114
131
- /**
132
- * Returns the node identifier to be included in xDS requests.
133
- */
134
- public Node getNode () {
135
- return node ;
136
- }
115
+ abstract Builder node (Node node );
137
116
138
- /** Returns the cert-providers config map. */
139
- @ Nullable
140
- public Map <String , CertificateProviderInfo > getCertProviders () {
141
- return certProviders == null ? null : Collections .unmodifiableMap (certProviders );
142
- }
117
+ abstract Builder certProviders (@ Nullable Map <String , CertificateProviderInfo > certProviders );
143
118
144
- @ Nullable
145
- public String getServerListenerResourceNameTemplate () {
146
- return serverListenerResourceNameTemplate ;
119
+ abstract Builder serverListenerResourceNameTemplate (
120
+ @ Nullable String serverListenerResourceNameTemplate );
121
+
122
+ abstract BootstrapInfo build ();
147
123
}
148
124
}
149
125
}
0 commit comments