use of io.grpc.xds.XdsClient.ResourceMetadata in project grpc-java by grpc.
the class ClientXdsClientTestBase method verifyResourceMetadata.
private ResourceMetadata verifyResourceMetadata(ResourceType type, String resourceName, Any rawResource, ResourceMetadataStatus status, String versionInfo, long updateTimeNanos, boolean hasErrorState) {
ResourceMetadata metadata = awaitSubscribedResourcesMetadata().get(type).get(resourceName);
assertThat(metadata).isNotNull();
String name = type.toString() + " resource '" + resourceName + "' metadata field ";
assertWithMessage(name + "status").that(metadata.getStatus()).isEqualTo(status);
assertWithMessage(name + "version").that(metadata.getVersion()).isEqualTo(versionInfo);
assertWithMessage(name + "rawResource").that(metadata.getRawResource()).isEqualTo(rawResource);
assertWithMessage(name + "updateTimeNanos").that(metadata.getUpdateTimeNanos()).isEqualTo(updateTimeNanos);
if (hasErrorState) {
assertWithMessage(name + "errorState").that(metadata.getErrorState()).isNotNull();
} else {
assertWithMessage(name + "errorState").that(metadata.getErrorState()).isNull();
}
return metadata;
}
use of io.grpc.xds.XdsClient.ResourceMetadata in project grpc-java by grpc.
the class ClientXdsClientTestBase method verifyResourceMetadataNacked.
/**
* Verify the resource to be nacked, and every i-th line of error details to begin with
* corresponding i-th element of {@code List<String> failedDetails}.
*/
private void verifyResourceMetadataNacked(ResourceType type, String resourceName, Any rawResource, String versionInfo, long updateTime, String failedVersion, long failedUpdateTimeNanos, List<String> failedDetails) {
ResourceMetadata resourceMetadata = verifyResourceMetadata(type, resourceName, rawResource, ResourceMetadataStatus.NACKED, versionInfo, updateTime, true);
UpdateFailureState errorState = resourceMetadata.getErrorState();
assertThat(errorState).isNotNull();
String name = type.toString() + " resource '" + resourceName + "' metadata error ";
assertWithMessage(name + "failedVersion").that(errorState.getFailedVersion()).isEqualTo(failedVersion);
assertWithMessage(name + "failedUpdateTimeNanos").that(errorState.getFailedUpdateTimeNanos()).isEqualTo(failedUpdateTimeNanos);
List<String> errors = Splitter.on('\n').splitToList(errorState.getFailedDetails());
for (int i = 0; i < errors.size(); i++) {
assertWithMessage(name + "failedDetails line " + i).that(errors.get(i)).startsWith(failedDetails.get(i));
}
}
use of io.grpc.xds.XdsClient.ResourceMetadata in project grpc-java by grpc.
the class CsdsService method getClientConfigForXdsClient.
@VisibleForTesting
static ClientConfig getClientConfigForXdsClient(XdsClient xdsClient) throws InterruptedException {
ClientConfig.Builder builder = ClientConfig.newBuilder().setNode(xdsClient.getBootstrapInfo().node().toEnvoyProtoNode());
Map<ResourceType, Map<String, ResourceMetadata>> metadataByType = awaitSubscribedResourcesMetadata(xdsClient.getSubscribedResourcesMetadataSnapshot());
for (Map.Entry<ResourceType, Map<String, ResourceMetadata>> metadataByTypeEntry : metadataByType.entrySet()) {
ResourceType type = metadataByTypeEntry.getKey();
Map<String, ResourceMetadata> metadataByResourceName = metadataByTypeEntry.getValue();
for (Map.Entry<String, ResourceMetadata> metadataEntry : metadataByResourceName.entrySet()) {
String resourceName = metadataEntry.getKey();
ResourceMetadata metadata = metadataEntry.getValue();
GenericXdsConfig.Builder genericXdsConfigBuilder = GenericXdsConfig.newBuilder().setTypeUrl(type.typeUrl()).setName(resourceName).setClientStatus(metadataStatusToClientStatus(metadata.getStatus()));
if (metadata.getRawResource() != null) {
genericXdsConfigBuilder.setVersionInfo(metadata.getVersion()).setLastUpdated(Timestamps.fromNanos(metadata.getUpdateTimeNanos())).setXdsConfig(metadata.getRawResource());
}
if (metadata.getStatus() == ResourceMetadataStatus.NACKED) {
verifyNotNull(metadata.getErrorState(), "resource %s getErrorState", resourceName);
genericXdsConfigBuilder.setErrorState(metadataUpdateFailureStateToProto(metadata.getErrorState()));
}
builder.addGenericXdsConfigs(genericXdsConfigBuilder);
}
}
return builder.build();
}
Aggregations