Search in sources :

Example 1 with RetrySettings

use of com.google.api.gax.retrying.RetrySettings in project toolkit by googleapis.

the class RetryDefinitionsTransformer method createRetrySettingsDefinition.

public static ImmutableMap<String, RetrySettings> createRetrySettingsDefinition(DiagCollector diagCollector, InterfaceConfigProto interfaceConfigProto) {
    ImmutableMap.Builder<String, RetrySettings> builder = ImmutableMap.builder();
    for (RetryParamsDefinitionProto retryDef : interfaceConfigProto.getRetryParamsDefList()) {
        try {
            RetrySettings settings = RetrySettings.newBuilder().setInitialRetryDelay(Duration.ofMillis(retryDef.getInitialRetryDelayMillis())).setRetryDelayMultiplier(retryDef.getRetryDelayMultiplier()).setMaxRetryDelay(Duration.ofMillis(retryDef.getMaxRetryDelayMillis())).setInitialRpcTimeout(Duration.ofMillis(retryDef.getInitialRpcTimeoutMillis())).setRpcTimeoutMultiplier(retryDef.getRpcTimeoutMultiplier()).setMaxRpcTimeout(Duration.ofMillis(retryDef.getMaxRpcTimeoutMillis())).setTotalTimeout(Duration.ofMillis(retryDef.getTotalTimeoutMillis())).build();
            builder.put(retryDef.getName(), settings);
        } catch (IllegalStateException | NullPointerException e) {
            diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "error while creating retry params: %s (in interface %s)", e, interfaceConfigProto.getName()));
        }
    }
    if (diagCollector.getErrorCount() > 0) {
        return null;
    }
    return builder.build();
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) RetryParamsDefinitionProto(com.google.api.codegen.RetryParamsDefinitionProto) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with RetrySettings

use of com.google.api.gax.retrying.RetrySettings in project toolkit by googleapis.

the class DiscoGapicInterfaceConfig method createInterfaceConfig.

static DiscoGapicInterfaceConfig createInterfaceConfig(DiscoApiModel model, String language, InterfaceConfigProto interfaceConfigProto, String interfaceNameOverride, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs) {
    ImmutableMap<String, ImmutableSet<String>> retryCodesDefinition = RetryDefinitionsTransformer.createRetryCodesDefinition(model.getDiagCollector(), interfaceConfigProto);
    ImmutableMap<String, RetrySettings> retrySettingsDefinition = RetryDefinitionsTransformer.createRetrySettingsDefinition(model.getDiagCollector(), interfaceConfigProto);
    List<DiscoGapicMethodConfig> methodConfigs = null;
    ImmutableMap<String, DiscoGapicMethodConfig> methodConfigMap = null;
    if (retryCodesDefinition != null && retrySettingsDefinition != null) {
        methodConfigMap = createMethodConfigMap(model, language, interfaceConfigProto, messageConfigs, resourceNameConfigs, retryCodesDefinition.keySet(), retrySettingsDefinition.keySet());
        methodConfigs = GapicInterfaceConfig.createMethodConfigs(methodConfigMap, interfaceConfigProto);
    }
    // TODO(andrealin)  Make non-null smokeTestConfig.
    SmokeTestConfig smokeTestConfig = null;
    // TODO(andrealin) IAM permissions configs.
    ImmutableList<String> requiredConstructorParams = ImmutableList.copyOf(interfaceConfigProto.getRequiredConstructorParamsList());
    for (String param : interfaceConfigProto.getRequiredConstructorParamsList()) {
        if (!CONSTRUCTOR_PARAMS.contains(param)) {
            model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unsupported constructor param: %s", param));
        }
    }
    ImmutableList.Builder<SingleResourceNameConfig> resourcesBuilder = ImmutableList.builder();
    for (CollectionConfigProto collectionConfigProto : interfaceConfigProto.getCollectionsList()) {
        String entityName = collectionConfigProto.getEntityName();
        ResourceNameConfig resourceName = resourceNameConfigs.get(entityName);
        if (resourceName == null || !(resourceName instanceof SingleResourceNameConfig)) {
            model.getDiagCollector().addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Inconsistent configuration - single resource name %s specified for interface, " + " but was not found in GapicProductConfig configuration.", entityName));
            return null;
        }
        resourcesBuilder.add((SingleResourceNameConfig) resourceName);
    }
    ImmutableList<SingleResourceNameConfig> singleResourceNames = resourcesBuilder.build();
    ImmutableMap.Builder<MethodConfig, SingleResourceNameConfig> methodToSingleResourceNameMap = ImmutableMap.builder();
    if (methodConfigs != null) {
        for (MethodConfig methodConfig : methodConfigs) {
            Method method = ((DiscoveryMethodModel) methodConfig.getMethodModel()).getDiscoMethod();
            String canonicalMethodPath = DiscoGapicParser.getCanonicalPath(method);
            for (SingleResourceNameConfig nameConfig : singleResourceNames) {
                if (nameConfig.getNamePattern().equals(canonicalMethodPath)) {
                    methodToSingleResourceNameMap.put(methodConfig, nameConfig);
                }
            }
        }
    }
    String manualDoc = Strings.nullToEmpty(interfaceConfigProto.getLangDoc().get(language)).trim();
    String interfaceName = interfaceNameOverride != null ? interfaceNameOverride : DiscoGapicParser.getInterfaceName(interfaceConfigProto.getName()).toUpperCamel();
    if (model.getDiagCollector().hasErrors()) {
        return null;
    } else {
        return new AutoValue_DiscoGapicInterfaceConfig(methodConfigs, retryCodesDefinition, retrySettingsDefinition, requiredConstructorParams, manualDoc, interfaceNameOverride, new DiscoInterfaceModel(interfaceName, model), smokeTestConfig, methodToSingleResourceNameMap.build(), methodConfigMap, singleResourceNames);
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Method(com.google.api.codegen.discovery.Method) ImmutableMap(com.google.common.collect.ImmutableMap) RetrySettings(com.google.api.gax.retrying.RetrySettings) ImmutableSet(com.google.common.collect.ImmutableSet) CollectionConfigProto(com.google.api.codegen.CollectionConfigProto)

Example 3 with RetrySettings

use of com.google.api.gax.retrying.RetrySettings in project toolkit by googleapis.

the class GapicInterfaceConfig method createInterfaceConfig.

/**
 * Creates an instance of GapicInterfaceConfig based on ConfigProto, linking up method
 * configurations with specified methods in methodConfigMap. On errors, null will be returned, and
 * diagnostics are reported to the model.
 */
@Nullable
static GapicInterfaceConfig createInterfaceConfig(DiagCollector diagCollector, String language, InterfaceConfigProto interfaceConfigProto, Interface apiInterface, String interfaceNameOverride, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs) {
    ImmutableMap<String, ImmutableSet<String>> retryCodesDefinition = RetryDefinitionsTransformer.createRetryCodesDefinition(diagCollector, interfaceConfigProto);
    ImmutableMap<String, RetrySettings> retrySettingsDefinition = RetryDefinitionsTransformer.createRetrySettingsDefinition(diagCollector, interfaceConfigProto);
    List<GapicMethodConfig> methodConfigs = null;
    ImmutableMap<String, GapicMethodConfig> methodConfigMap = null;
    if (retryCodesDefinition != null && retrySettingsDefinition != null) {
        methodConfigMap = createMethodConfigMap(diagCollector, language, interfaceConfigProto, apiInterface, messageConfigs, resourceNameConfigs, retryCodesDefinition.keySet(), retrySettingsDefinition.keySet());
        methodConfigs = createMethodConfigs(methodConfigMap, interfaceConfigProto);
    }
    SmokeTestConfig smokeTestConfig = createSmokeTestConfig(diagCollector, apiInterface, interfaceConfigProto);
    ImmutableList<FieldModel> iamResources = createIamResources(apiInterface.getModel(), interfaceConfigProto.getExperimentalFeatures().getIamResourcesList());
    ImmutableList<String> requiredConstructorParams = ImmutableList.<String>copyOf(interfaceConfigProto.getRequiredConstructorParamsList());
    for (String param : interfaceConfigProto.getRequiredConstructorParamsList()) {
        if (!CONSTRUCTOR_PARAMS.contains(param)) {
            diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Unsupported constructor param: %s", param));
        }
    }
    ImmutableList.Builder<SingleResourceNameConfig> resourcesBuilder = ImmutableList.builder();
    for (CollectionConfigProto collectionConfigProto : interfaceConfigProto.getCollectionsList()) {
        String entityName = collectionConfigProto.getEntityName();
        ResourceNameConfig resourceName = resourceNameConfigs.get(entityName);
        if (resourceName == null || !(resourceName instanceof SingleResourceNameConfig)) {
            diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Inconsistent configuration - single resource name %s specified for interface, " + " but was not found in GapicProductConfig configuration.", entityName));
            return null;
        }
        resourcesBuilder.add((SingleResourceNameConfig) resourceName);
    }
    ImmutableList<SingleResourceNameConfig> singleResourceNames = resourcesBuilder.build();
    String manualDoc = Strings.nullToEmpty(interfaceConfigProto.getLangDoc().get(language)).trim();
    if (diagCollector.hasErrors()) {
        return null;
    } else {
        return new AutoValue_GapicInterfaceConfig(interfaceNameOverride, new ProtoInterfaceModel(apiInterface), methodConfigs, smokeTestConfig, methodConfigMap, retryCodesDefinition, retrySettingsDefinition, iamResources, requiredConstructorParams, singleResourceNames, manualDoc);
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) RetrySettings(com.google.api.gax.retrying.RetrySettings) ImmutableSet(com.google.common.collect.ImmutableSet) CollectionConfigProto(com.google.api.codegen.CollectionConfigProto) Nullable(javax.annotation.Nullable)

Example 4 with RetrySettings

use of com.google.api.gax.retrying.RetrySettings in project divolte-collector by divolte.

the class GoogleCloudPubSubSinkConfiguration method getFactory.

@Override
public SinkFactory getFactory() {
    final RetrySettings retrySettings = this.retrySettings.createRetrySettings();
    final BatchingSettings batchingSettings = this.batchingSettings.createBatchingSettings();
    final Optional<String> emulator = Optional.ofNullable(System.getenv("PUBSUB_EMULATOR_HOST"));
    return emulator.map(hostport -> createFlushingPool(retrySettings, batchingSettings, hostport)).orElseGet(() -> createFlushingPool(retrySettings, batchingSettings));
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Topic(com.google.pubsub.v1.Topic) GoogleCloudPubSubFlushingPool(io.divolte.server.topicsinks.pubsub.GoogleCloudPubSubFlushingPool) ParametersAreNullableByDefault(javax.annotation.ParametersAreNullableByDefault) ManagedChannel(io.grpc.ManagedChannel) LoggerFactory(org.slf4j.LoggerFactory) NoCredentialsProvider(com.google.api.gax.core.NoCredentialsProvider) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) RetrySettings(com.google.api.gax.retrying.RetrySettings) Valid(javax.validation.Valid) FixedTransportChannelProvider(com.google.api.gax.rpc.FixedTransportChannelProvider) Duration(java.time.Duration) ProjectTopicName(com.google.pubsub.v1.ProjectTopicName) Logger(org.slf4j.Logger) BatchingSettings(com.google.api.gax.batching.BatchingSettings) MoreObjects(com.google.common.base.MoreObjects) IOException(java.io.IOException) Streams(com.google.common.collect.Streams) UncheckedIOException(java.io.UncheckedIOException) GrpcTransportChannel(com.google.api.gax.grpc.GrpcTransportChannel) ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) TransportChannelProvider(com.google.api.gax.rpc.TransportChannelProvider) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) IOExceptions(io.divolte.server.IOExceptions) Optional(java.util.Optional) com.google.cloud.pubsub.v1(com.google.cloud.pubsub.v1) ProjectName(com.google.pubsub.v1.ProjectName) RetrySettings(com.google.api.gax.retrying.RetrySettings) BatchingSettings(com.google.api.gax.batching.BatchingSettings)

Example 5 with RetrySettings

use of com.google.api.gax.retrying.RetrySettings in project google-cloud-java by GoogleCloudPlatform.

the class PublisherSnippets method getPublisherWithCustomRetrySettings.

public Publisher getPublisherWithCustomRetrySettings(TopicName topicName) throws Exception {
    // [START pubsub_publisher_retry_settings]
    // Retry settings control how the publisher handles retryable failures
    // default : 1 ms
    Duration retryDelay = Duration.ofMillis(100);
    // back off for repeated failures
    double retryDelayMultiplier = 2.0;
    // default : 10 seconds
    Duration maxRetryDelay = Duration.ofSeconds(5);
    RetrySettings retrySettings = RetrySettings.newBuilder().setInitialRetryDelay(retryDelay).setRetryDelayMultiplier(retryDelayMultiplier).setMaxRetryDelay(maxRetryDelay).build();
    Publisher publisher = Publisher.defaultBuilder(topicName).setRetrySettings(retrySettings).build();
    // [END pubsub_publisher_retry_settings]
    return publisher;
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) Duration(org.threeten.bp.Duration) Publisher(com.google.cloud.pubsub.spi.v1.Publisher)

Aggregations

RetrySettings (com.google.api.gax.retrying.RetrySettings)9 ImmutableSet (com.google.common.collect.ImmutableSet)3 CollectionConfigProto (com.google.api.codegen.CollectionConfigProto)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)1 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)1 RetryParamsDefinitionProto (com.google.api.codegen.RetryParamsDefinitionProto)1 MethodConfig (com.google.api.codegen.config.MethodConfig)1 MethodModel (com.google.api.codegen.config.MethodModel)1 Method (com.google.api.codegen.discovery.Method)1 RetryConfigDefinitionView (com.google.api.codegen.viewmodel.RetryConfigDefinitionView)1 RetryParamsDefinitionView (com.google.api.codegen.viewmodel.RetryParamsDefinitionView)1 BatchingSettings (com.google.api.gax.batching.BatchingSettings)1 NoCredentialsProvider (com.google.api.gax.core.NoCredentialsProvider)1 GrpcTransportChannel (com.google.api.gax.grpc.GrpcTransportChannel)1 FixedTransportChannelProvider (com.google.api.gax.rpc.FixedTransportChannelProvider)1 TransportChannelProvider (com.google.api.gax.rpc.TransportChannelProvider)1