Search in sources :

Example 1 with ClientConfig

use of io.envoyproxy.envoy.service.status.v3.ClientConfig 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 ClientConfig

use of io.envoyproxy.envoy.service.status.v3.ClientConfig in project aws-doc-sdk-examples by awsdocs.

the class DaxAsyncClientDemo method main.

public static void main(String[] args) throws Exception {
    ClientConfig daxConfig = new ClientConfig().withCredentialsProvider(new ProfileCredentialsProvider()).withEndpoints("mydaxcluster.2cmrwl.clustercfg.dax.use1.cache.amazonaws.com:8111");
    AmazonDynamoDBAsync client = new ClusterDaxAsyncClient(daxConfig);
    HashMap<String, AttributeValue> key = new HashMap<String, AttributeValue>();
    key.put("Artist", new AttributeValue().withS("No One You Know"));
    key.put("SongTitle", new AttributeValue().withS("Scared of My Shadow"));
    GetItemRequest request = new GetItemRequest().withTableName("Music").withKey(key);
    // Java Futures
    Future<GetItemResult> call = client.getItemAsync(request);
    while (!call.isDone()) {
        // Do other processing while you're waiting for the response
        System.out.println("Doing something else for a few seconds...");
        Thread.sleep(3000);
    }
    try {
        call.get();
    } catch (ExecutionException ee) {
        // Futures always wrap errors as an ExecutionException.
        // The *real* exception is stored as the cause of the
        // ExecutionException
        Throwable exception = ee.getCause();
        System.out.println("Error getting item: " + exception.getMessage());
    }
    // Async callbacks
    call = client.getItemAsync(request, new AsyncHandler<GetItemRequest, GetItemResult>() {

        @Override
        public void onSuccess(GetItemRequest request, GetItemResult getItemResult) {
            System.out.println("Result: " + getItemResult);
        }

        @Override
        public void onError(Exception e) {
            System.out.println("Unable to read item");
            System.err.println(e.getMessage());
        // Callers can also test if exception is an instance of
        // AmazonServiceException or AmazonClientException and cast
        // it to get additional information
        }
    });
    call.get();
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) AsyncHandler(com.amazonaws.handlers.AsyncHandler) HashMap(java.util.HashMap) ClusterDaxAsyncClient(com.amazon.dax.client.dynamodbv2.ClusterDaxAsyncClient) ExecutionException(java.util.concurrent.ExecutionException) GetItemResult(com.amazonaws.services.dynamodbv2.model.GetItemResult) AmazonDynamoDBAsync(com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync) ProfileCredentialsProvider(com.amazonaws.auth.profile.ProfileCredentialsProvider) ClientConfig(com.amazon.dax.client.dynamodbv2.ClientConfig) ExecutionException(java.util.concurrent.ExecutionException) GetItemRequest(com.amazonaws.services.dynamodbv2.model.GetItemRequest)

Example 3 with ClientConfig

use of io.envoyproxy.envoy.service.status.v3.ClientConfig 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 ClientConfig (com.amazon.dax.client.dynamodbv2.ClientConfig)1 ClusterDaxAsyncClient (com.amazon.dax.client.dynamodbv2.ClusterDaxAsyncClient)1 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)1 AsyncHandler (com.amazonaws.handlers.AsyncHandler)1 AmazonDynamoDBAsync (com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync)1 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)1 GetItemRequest (com.amazonaws.services.dynamodbv2.model.GetItemRequest)1 GetItemResult (com.amazonaws.services.dynamodbv2.model.GetItemResult)1 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 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1