|
39 | 39 | import io.grpc.xds.client.XdsClient.ResourceMetadata.ResourceMetadataStatus; |
40 | 40 | import io.grpc.xds.client.XdsClient.ResourceMetadata.UpdateFailureState; |
41 | 41 | import io.grpc.xds.client.XdsResourceType; |
| 42 | +import java.util.ArrayList; |
| 43 | +import java.util.List; |
42 | 44 | import java.util.Map; |
43 | 45 | import java.util.concurrent.ExecutionException; |
44 | 46 | import java.util.concurrent.TimeUnit; |
@@ -117,53 +119,77 @@ public void onCompleted() { |
117 | 119 |
|
118 | 120 | private boolean handleRequest( |
119 | 121 | ClientStatusRequest request, StreamObserver<ClientStatusResponse> responseObserver) { |
120 | | - StatusException error; |
121 | | - try { |
122 | | - responseObserver.onNext(getConfigDumpForRequest(request)); |
123 | | - return true; |
124 | | - } catch (StatusException e) { |
125 | | - error = e; |
126 | | - } catch (InterruptedException e) { |
127 | | - Thread.currentThread().interrupt(); |
128 | | - logger.log(Level.FINE, "Server interrupted while building CSDS config dump", e); |
129 | | - error = Status.ABORTED.withDescription("Thread interrupted").withCause(e).asException(); |
130 | | - } catch (RuntimeException e) { |
131 | | - logger.log(Level.WARNING, "Unexpected error while building CSDS config dump", e); |
132 | | - error = |
133 | | - Status.INTERNAL.withDescription("Unexpected internal error").withCause(e).asException(); |
134 | | - } |
135 | | - responseObserver.onError(error); |
136 | | - return false; |
137 | | - } |
| 122 | + StatusException error = null; |
138 | 123 |
|
139 | | - private ClientStatusResponse getConfigDumpForRequest(ClientStatusRequest request) |
140 | | - throws StatusException, InterruptedException { |
141 | 124 | if (request.getNodeMatchersCount() > 0) { |
142 | | - throw new StatusException( |
| 125 | + error = new StatusException( |
143 | 126 | Status.INVALID_ARGUMENT.withDescription("node_matchers not supported")); |
| 127 | + } else { |
| 128 | + List<String> targets = xdsClientPoolFactory.getTargets(); |
| 129 | + List<ClientConfig> clientConfigs = new ArrayList<>(targets.size()); |
| 130 | + |
| 131 | + for (int i = 0; i < targets.size() && error == null; i++) { |
| 132 | + try { |
| 133 | + ClientConfig clientConfig = getConfigForRequest(targets.get(i)); |
| 134 | + if (clientConfig != null) { |
| 135 | + clientConfigs.add(clientConfig); |
| 136 | + } |
| 137 | + } catch (InterruptedException e) { |
| 138 | + Thread.currentThread().interrupt(); |
| 139 | + logger.log(Level.FINE, "Server interrupted while building CSDS config dump", e); |
| 140 | + error = Status.ABORTED.withDescription("Thread interrupted").withCause(e).asException(); |
| 141 | + } catch (RuntimeException e) { |
| 142 | + logger.log(Level.WARNING, "Unexpected error while building CSDS config dump", e); |
| 143 | + error = Status.INTERNAL.withDescription("Unexpected internal error").withCause(e) |
| 144 | + .asException(); |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + try { |
| 149 | + responseObserver.onNext(getStatusResponse(clientConfigs)); |
| 150 | + } catch (RuntimeException e) { |
| 151 | + logger.log(Level.WARNING, "Unexpected error while processing CSDS config dump", e); |
| 152 | + error = Status.INTERNAL.withDescription("Unexpected internal error").withCause(e) |
| 153 | + .asException(); |
| 154 | + } |
144 | 155 | } |
145 | 156 |
|
146 | | - ObjectPool<XdsClient> xdsClientPool = xdsClientPoolFactory.get(); |
| 157 | + if (error == null) { |
| 158 | + return true; // All clients reported without error |
| 159 | + } |
| 160 | + responseObserver.onError(error); |
| 161 | + return false; |
| 162 | + } |
| 163 | + |
| 164 | + private ClientConfig getConfigForRequest(String target) throws InterruptedException { |
| 165 | + ObjectPool<XdsClient> xdsClientPool = xdsClientPoolFactory.get(target); |
147 | 166 | if (xdsClientPool == null) { |
148 | | - return ClientStatusResponse.getDefaultInstance(); |
| 167 | + return null; |
149 | 168 | } |
150 | 169 |
|
151 | 170 | XdsClient xdsClient = null; |
152 | 171 | try { |
153 | 172 | xdsClient = xdsClientPool.getObject(); |
154 | | - return ClientStatusResponse.newBuilder() |
155 | | - .addConfig(getClientConfigForXdsClient(xdsClient)) |
156 | | - .build(); |
| 173 | + return getClientConfigForXdsClient(xdsClient, target); |
157 | 174 | } finally { |
158 | 175 | if (xdsClient != null) { |
159 | 176 | xdsClientPool.returnObject(xdsClient); |
160 | 177 | } |
161 | 178 | } |
162 | 179 | } |
163 | 180 |
|
| 181 | + private ClientStatusResponse getStatusResponse(List<ClientConfig> clientConfigs) { |
| 182 | + if (clientConfigs.isEmpty()) { |
| 183 | + return ClientStatusResponse.getDefaultInstance(); |
| 184 | + } |
| 185 | + return ClientStatusResponse.newBuilder().addAllConfig(clientConfigs).build(); |
| 186 | + } |
| 187 | + |
164 | 188 | @VisibleForTesting |
165 | | - static ClientConfig getClientConfigForXdsClient(XdsClient xdsClient) throws InterruptedException { |
| 189 | + static ClientConfig getClientConfigForXdsClient(XdsClient xdsClient, String target) |
| 190 | + throws InterruptedException { |
166 | 191 | ClientConfig.Builder builder = ClientConfig.newBuilder() |
| 192 | + .setClientScope(target) |
167 | 193 | .setNode(xdsClient.getBootstrapInfo().node().toEnvoyProtoNode()); |
168 | 194 |
|
169 | 195 | Map<XdsResourceType<?>, Map<String, ResourceMetadata>> metadataByType = |
|
0 commit comments