All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.cloud.osconfig.v1.spring.OsConfigServiceSpringAutoConfiguration Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2024 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.cloud.osconfig.v1.spring;

import com.google.api.core.BetaApi;
import com.google.api.gax.core.CredentialsProvider;
import com.google.api.gax.core.ExecutorProvider;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.rpc.HeaderProvider;
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.cloud.osconfig.v1.OsConfigServiceClient;
import com.google.cloud.osconfig.v1.OsConfigServiceSettings;
import com.google.cloud.spring.autoconfigure.core.GcpContextAutoConfiguration;
import com.google.cloud.spring.core.DefaultCredentialsProvider;
import com.google.cloud.spring.core.Retry;
import com.google.cloud.spring.core.util.RetryUtil;
import java.io.IOException;
import java.util.Collections;
import javax.annotation.Generated;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
 * Auto-configuration for {@link OsConfigServiceClient}.
 *
 * 

Provides auto-configuration for Spring Boot * *

The default instance has everything set to sensible defaults: * *

    *
  • The default transport provider is used. *
  • Credentials are acquired automatically through Application Default Credentials. *
  • Retries are configured for idempotent methods but not for non-idempotent methods. *
*/ @Generated("by google-cloud-spring-generator") @BetaApi("Autogenerated Spring autoconfiguration is not yet stable") @AutoConfiguration @AutoConfigureAfter(GcpContextAutoConfiguration.class) @ConditionalOnClass(OsConfigServiceClient.class) @ConditionalOnProperty( value = "com.google.cloud.osconfig.v1.os-config-service.enabled", matchIfMissing = true) @EnableConfigurationProperties(OsConfigServiceSpringProperties.class) public class OsConfigServiceSpringAutoConfiguration { private final OsConfigServiceSpringProperties clientProperties; private final CredentialsProvider credentialsProvider; private static final Log LOGGER = LogFactory.getLog(OsConfigServiceSpringAutoConfiguration.class); protected OsConfigServiceSpringAutoConfiguration( OsConfigServiceSpringProperties clientProperties, CredentialsProvider credentialsProvider) throws IOException { this.clientProperties = clientProperties; if (this.clientProperties.getCredentials().hasKey()) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Using credentials from OsConfigService-specific configuration"); } this.credentialsProvider = ((CredentialsProvider) new DefaultCredentialsProvider(this.clientProperties)); } else { this.credentialsProvider = credentialsProvider; } } /** * Provides a default transport channel provider bean, corresponding to the client library's * default transport channel provider. If the library supports both GRPC and REST transport, and * the useRest property is configured, the HTTP/JSON transport provider will be used instead of * GRPC. * * @return a default transport channel provider. */ @Bean @ConditionalOnMissingBean(name = "defaultOsConfigServiceTransportChannelProvider") public TransportChannelProvider defaultOsConfigServiceTransportChannelProvider() { if (this.clientProperties.getUseRest()) { return OsConfigServiceSettings.defaultHttpJsonTransportProviderBuilder().build(); } return OsConfigServiceSettings.defaultTransportChannelProvider(); } /** * Provides a OsConfigServiceSettings bean configured to use a DefaultCredentialsProvider and the * client library's default transport channel provider * (defaultOsConfigServiceTransportChannelProvider()). It also configures the quota project ID and * executor thread count, if provided through properties. * *

Retry settings are also configured from service-level and method-level properties specified * in OsConfigServiceSpringProperties. Method-level properties will take precedence over * service-level properties if available, and client library defaults will be used if neither are * specified. * * @param defaultTransportChannelProvider TransportChannelProvider to use in the settings. * @return a {@link OsConfigServiceSettings} bean configured with {@link TransportChannelProvider} * bean. */ @Bean @ConditionalOnMissingBean public OsConfigServiceSettings osConfigServiceSettings( @Qualifier("defaultOsConfigServiceTransportChannelProvider") TransportChannelProvider defaultTransportChannelProvider) throws IOException { OsConfigServiceSettings.Builder clientSettingsBuilder; if (this.clientProperties.getUseRest()) { clientSettingsBuilder = OsConfigServiceSettings.newHttpJsonBuilder(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Using REST (HTTP/JSON) transport."); } } else { clientSettingsBuilder = OsConfigServiceSettings.newBuilder(); } clientSettingsBuilder .setCredentialsProvider(this.credentialsProvider) .setTransportChannelProvider(defaultTransportChannelProvider) .setEndpoint(OsConfigServiceSettings.getDefaultEndpoint()) .setHeaderProvider(this.userAgentHeaderProvider()); if (this.clientProperties.getQuotaProjectId() != null) { clientSettingsBuilder.setQuotaProjectId(this.clientProperties.getQuotaProjectId()); if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Quota project id set to " + this.clientProperties.getQuotaProjectId() + ", this overrides project id from credentials."); } } if (this.clientProperties.getExecutorThreadCount() != null) { ExecutorProvider executorProvider = OsConfigServiceSettings.defaultExecutorProviderBuilder() .setExecutorThreadCount(this.clientProperties.getExecutorThreadCount()) .build(); clientSettingsBuilder.setBackgroundExecutorProvider(executorProvider); if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Background executor thread count is " + this.clientProperties.getExecutorThreadCount()); } } Retry serviceRetry = clientProperties.getRetry(); if (serviceRetry != null) { RetrySettings executePatchJobRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.executePatchJobSettings().getRetrySettings(), serviceRetry); clientSettingsBuilder .executePatchJobSettings() .setRetrySettings(executePatchJobRetrySettings); RetrySettings getPatchJobRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.getPatchJobSettings().getRetrySettings(), serviceRetry); clientSettingsBuilder.getPatchJobSettings().setRetrySettings(getPatchJobRetrySettings); RetrySettings cancelPatchJobRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.cancelPatchJobSettings().getRetrySettings(), serviceRetry); clientSettingsBuilder.cancelPatchJobSettings().setRetrySettings(cancelPatchJobRetrySettings); RetrySettings listPatchJobsRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.listPatchJobsSettings().getRetrySettings(), serviceRetry); clientSettingsBuilder.listPatchJobsSettings().setRetrySettings(listPatchJobsRetrySettings); RetrySettings listPatchJobInstanceDetailsRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.listPatchJobInstanceDetailsSettings().getRetrySettings(), serviceRetry); clientSettingsBuilder .listPatchJobInstanceDetailsSettings() .setRetrySettings(listPatchJobInstanceDetailsRetrySettings); RetrySettings createPatchDeploymentRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.createPatchDeploymentSettings().getRetrySettings(), serviceRetry); clientSettingsBuilder .createPatchDeploymentSettings() .setRetrySettings(createPatchDeploymentRetrySettings); RetrySettings getPatchDeploymentRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.getPatchDeploymentSettings().getRetrySettings(), serviceRetry); clientSettingsBuilder .getPatchDeploymentSettings() .setRetrySettings(getPatchDeploymentRetrySettings); RetrySettings listPatchDeploymentsRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.listPatchDeploymentsSettings().getRetrySettings(), serviceRetry); clientSettingsBuilder .listPatchDeploymentsSettings() .setRetrySettings(listPatchDeploymentsRetrySettings); RetrySettings deletePatchDeploymentRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.deletePatchDeploymentSettings().getRetrySettings(), serviceRetry); clientSettingsBuilder .deletePatchDeploymentSettings() .setRetrySettings(deletePatchDeploymentRetrySettings); RetrySettings updatePatchDeploymentRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.updatePatchDeploymentSettings().getRetrySettings(), serviceRetry); clientSettingsBuilder .updatePatchDeploymentSettings() .setRetrySettings(updatePatchDeploymentRetrySettings); RetrySettings pausePatchDeploymentRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.pausePatchDeploymentSettings().getRetrySettings(), serviceRetry); clientSettingsBuilder .pausePatchDeploymentSettings() .setRetrySettings(pausePatchDeploymentRetrySettings); RetrySettings resumePatchDeploymentRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.resumePatchDeploymentSettings().getRetrySettings(), serviceRetry); clientSettingsBuilder .resumePatchDeploymentSettings() .setRetrySettings(resumePatchDeploymentRetrySettings); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Configured service-level retry settings from properties."); } } Retry executePatchJobRetry = clientProperties.getExecutePatchJobRetry(); if (executePatchJobRetry != null) { RetrySettings executePatchJobRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.executePatchJobSettings().getRetrySettings(), executePatchJobRetry); clientSettingsBuilder .executePatchJobSettings() .setRetrySettings(executePatchJobRetrySettings); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Configured method-level retry settings for executePatchJob from properties."); } } Retry getPatchJobRetry = clientProperties.getGetPatchJobRetry(); if (getPatchJobRetry != null) { RetrySettings getPatchJobRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.getPatchJobSettings().getRetrySettings(), getPatchJobRetry); clientSettingsBuilder.getPatchJobSettings().setRetrySettings(getPatchJobRetrySettings); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Configured method-level retry settings for getPatchJob from properties."); } } Retry cancelPatchJobRetry = clientProperties.getCancelPatchJobRetry(); if (cancelPatchJobRetry != null) { RetrySettings cancelPatchJobRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.cancelPatchJobSettings().getRetrySettings(), cancelPatchJobRetry); clientSettingsBuilder.cancelPatchJobSettings().setRetrySettings(cancelPatchJobRetrySettings); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Configured method-level retry settings for cancelPatchJob from properties."); } } Retry listPatchJobsRetry = clientProperties.getListPatchJobsRetry(); if (listPatchJobsRetry != null) { RetrySettings listPatchJobsRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.listPatchJobsSettings().getRetrySettings(), listPatchJobsRetry); clientSettingsBuilder.listPatchJobsSettings().setRetrySettings(listPatchJobsRetrySettings); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Configured method-level retry settings for listPatchJobs from properties."); } } Retry listPatchJobInstanceDetailsRetry = clientProperties.getListPatchJobInstanceDetailsRetry(); if (listPatchJobInstanceDetailsRetry != null) { RetrySettings listPatchJobInstanceDetailsRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.listPatchJobInstanceDetailsSettings().getRetrySettings(), listPatchJobInstanceDetailsRetry); clientSettingsBuilder .listPatchJobInstanceDetailsSettings() .setRetrySettings(listPatchJobInstanceDetailsRetrySettings); if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Configured method-level retry settings for listPatchJobInstanceDetails from properties."); } } Retry createPatchDeploymentRetry = clientProperties.getCreatePatchDeploymentRetry(); if (createPatchDeploymentRetry != null) { RetrySettings createPatchDeploymentRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.createPatchDeploymentSettings().getRetrySettings(), createPatchDeploymentRetry); clientSettingsBuilder .createPatchDeploymentSettings() .setRetrySettings(createPatchDeploymentRetrySettings); if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Configured method-level retry settings for createPatchDeployment from properties."); } } Retry getPatchDeploymentRetry = clientProperties.getGetPatchDeploymentRetry(); if (getPatchDeploymentRetry != null) { RetrySettings getPatchDeploymentRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.getPatchDeploymentSettings().getRetrySettings(), getPatchDeploymentRetry); clientSettingsBuilder .getPatchDeploymentSettings() .setRetrySettings(getPatchDeploymentRetrySettings); if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Configured method-level retry settings for getPatchDeployment from properties."); } } Retry listPatchDeploymentsRetry = clientProperties.getListPatchDeploymentsRetry(); if (listPatchDeploymentsRetry != null) { RetrySettings listPatchDeploymentsRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.listPatchDeploymentsSettings().getRetrySettings(), listPatchDeploymentsRetry); clientSettingsBuilder .listPatchDeploymentsSettings() .setRetrySettings(listPatchDeploymentsRetrySettings); if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Configured method-level retry settings for listPatchDeployments from properties."); } } Retry deletePatchDeploymentRetry = clientProperties.getDeletePatchDeploymentRetry(); if (deletePatchDeploymentRetry != null) { RetrySettings deletePatchDeploymentRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.deletePatchDeploymentSettings().getRetrySettings(), deletePatchDeploymentRetry); clientSettingsBuilder .deletePatchDeploymentSettings() .setRetrySettings(deletePatchDeploymentRetrySettings); if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Configured method-level retry settings for deletePatchDeployment from properties."); } } Retry updatePatchDeploymentRetry = clientProperties.getUpdatePatchDeploymentRetry(); if (updatePatchDeploymentRetry != null) { RetrySettings updatePatchDeploymentRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.updatePatchDeploymentSettings().getRetrySettings(), updatePatchDeploymentRetry); clientSettingsBuilder .updatePatchDeploymentSettings() .setRetrySettings(updatePatchDeploymentRetrySettings); if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Configured method-level retry settings for updatePatchDeployment from properties."); } } Retry pausePatchDeploymentRetry = clientProperties.getPausePatchDeploymentRetry(); if (pausePatchDeploymentRetry != null) { RetrySettings pausePatchDeploymentRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.pausePatchDeploymentSettings().getRetrySettings(), pausePatchDeploymentRetry); clientSettingsBuilder .pausePatchDeploymentSettings() .setRetrySettings(pausePatchDeploymentRetrySettings); if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Configured method-level retry settings for pausePatchDeployment from properties."); } } Retry resumePatchDeploymentRetry = clientProperties.getResumePatchDeploymentRetry(); if (resumePatchDeploymentRetry != null) { RetrySettings resumePatchDeploymentRetrySettings = RetryUtil.updateRetrySettings( clientSettingsBuilder.resumePatchDeploymentSettings().getRetrySettings(), resumePatchDeploymentRetry); clientSettingsBuilder .resumePatchDeploymentSettings() .setRetrySettings(resumePatchDeploymentRetrySettings); if (LOGGER.isTraceEnabled()) { LOGGER.trace( "Configured method-level retry settings for resumePatchDeployment from properties."); } } return clientSettingsBuilder.build(); } /** * Provides a OsConfigServiceClient bean configured with OsConfigServiceSettings. * * @param osConfigServiceSettings settings to configure an instance of client bean. * @return a {@link OsConfigServiceClient} bean configured with {@link OsConfigServiceSettings} */ @Bean @ConditionalOnMissingBean public OsConfigServiceClient osConfigServiceClient( OsConfigServiceSettings osConfigServiceSettings) throws IOException { return OsConfigServiceClient.create(osConfigServiceSettings); } private HeaderProvider userAgentHeaderProvider() { String springLibrary = "spring-autogen-os-config-service"; String version = this.getClass().getPackage().getImplementationVersion(); return () -> Collections.singletonMap("user-agent", springLibrary + "/" + version); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy