Search in sources :

Example 1 with ResourceType

use of io.grpc.xds.AbstractXdsClient.ResourceType in project grpc-java by grpc.

the class CsdsServiceTest method mapConfigDumps.

private static EnumMap<ResourceType, GenericXdsConfig> mapConfigDumps(ClientConfig config) {
    EnumMap<ResourceType, GenericXdsConfig> xdsConfigMap = new EnumMap<>(ResourceType.class);
    List<GenericXdsConfig> xdsConfigList = config.getGenericXdsConfigsList();
    for (GenericXdsConfig genericXdsConfig : xdsConfigList) {
        ResourceType type = ResourceType.fromTypeUrl(genericXdsConfig.getTypeUrl());
        assertThat(type).isNotEqualTo(ResourceType.UNKNOWN);
        assertThat(xdsConfigMap).doesNotContainKey(type);
        xdsConfigMap.put(type, genericXdsConfig);
    }
    return xdsConfigMap;
}
Also used : GenericXdsConfig(io.envoyproxy.envoy.service.status.v3.ClientConfig.GenericXdsConfig) ResourceType(io.grpc.xds.AbstractXdsClient.ResourceType) EnumMap(java.util.EnumMap)

Example 2 with ResourceType

use of io.grpc.xds.AbstractXdsClient.ResourceType 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

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