Search in sources :

Example 1 with ResourceMetadata

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;
}
Also used : ResourceMetadata(io.grpc.xds.XdsClient.ResourceMetadata)

Example 2 with ResourceMetadata

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));
    }
}
Also used : UpdateFailureState(io.grpc.xds.XdsClient.ResourceMetadata.UpdateFailureState) ResourceMetadata(io.grpc.xds.XdsClient.ResourceMetadata) LbEndpoint(io.grpc.xds.Endpoints.LbEndpoint)

Example 3 with ResourceMetadata

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();
}
Also used : GenericXdsConfig(io.envoyproxy.envoy.service.status.v3.ClientConfig.GenericXdsConfig) ResourceType(io.grpc.xds.AbstractXdsClient.ResourceType) ClientConfig(io.envoyproxy.envoy.service.status.v3.ClientConfig) ResourceMetadata(io.grpc.xds.XdsClient.ResourceMetadata) Map(java.util.Map) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ResourceMetadata (io.grpc.xds.XdsClient.ResourceMetadata)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ClientConfig (io.envoyproxy.envoy.service.status.v3.ClientConfig)1 GenericXdsConfig (io.envoyproxy.envoy.service.status.v3.ClientConfig.GenericXdsConfig)1 ResourceType (io.grpc.xds.AbstractXdsClient.ResourceType)1 LbEndpoint (io.grpc.xds.Endpoints.LbEndpoint)1 UpdateFailureState (io.grpc.xds.XdsClient.ResourceMetadata.UpdateFailureState)1 Map (java.util.Map)1