com.google.api.gax.rpc.FixedHeaderProvider Java Examples
The following examples show how to use
com.google.api.gax.rpc.FixedHeaderProvider.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BigQueryConnectorModule.java From presto with Apache License 2.0 | 4 votes |
@Provides @Singleton public static HeaderProvider createHeaderProvider(NodeManager nodeManager) { return FixedHeaderProvider.create("user-agent", "prestosql/" + nodeManager.getCurrentNode().getVersion()); }
Example #2
Source File: ExposedSpannerAccessor.java From DataflowTemplates with Apache License 2.0 | 4 votes |
public static ExposedSpannerAccessor create(SpannerConfig spannerConfig) { SpannerOptions.Builder builder = SpannerOptions.newBuilder(); ValueProvider<Duration> commitDeadline = spannerConfig.getCommitDeadline(); if (commitDeadline != null && commitDeadline.get().getMillis() > 0) { // In Spanner API version 1.21 or above, we can set the deadline / total Timeout on an API // call using the following code: // // UnaryCallSettings.Builder commitSettings = // builder.getSpannerStubSettingsBuilder().commitSettings(); // RetrySettings.Builder commitRetrySettings = commitSettings.getRetrySettings().toBuilder() // commitSettings.setRetrySettings( // commitRetrySettings.setTotalTimeout( // Duration.ofMillis(getCommitDeadlineMillis().get())) // .build()); // // However, at time of this commit, the Spanner API is at only at v1.6.0, where the only // method to set a deadline is with GRPC Interceptors, so we have to use that... SpannerInterceptorProvider interceptorProvider = SpannerInterceptorProvider.createDefault() .with(new CommitDeadlineSettingInterceptor(commitDeadline.get())); builder.setInterceptorProvider(interceptorProvider); } ValueProvider<String> projectId = spannerConfig.getProjectId(); if (projectId != null) { builder.setProjectId(projectId.get()); } ServiceFactory<Spanner, SpannerOptions> serviceFactory = spannerConfig.getServiceFactory(); if (serviceFactory != null) { builder.setServiceFactory(serviceFactory); } ValueProvider<String> host = spannerConfig.getHost(); if (host != null) { builder.setHost(host.get()); } String userAgentString = USER_AGENT_PREFIX + "/" + ReleaseInfo.getReleaseInfo().getVersion(); builder.setHeaderProvider(FixedHeaderProvider.create("user-agent", userAgentString)); SessionPoolOptions.Builder sessionPoolOptions = SessionPoolOptions.newBuilder(); sessionPoolOptions.setMinSessions(1); sessionPoolOptions.setMaxSessions(3); builder.setSessionPoolOption(sessionPoolOptions.build()); SpannerOptions options = builder.build(); Spanner spanner = options.getService(); String instanceId = spannerConfig.getInstanceId().get(); String databaseId = spannerConfig.getDatabaseId().get(); DatabaseClient databaseClient = spanner.getDatabaseClient(DatabaseId.of(options.getProjectId(), instanceId, databaseId)); BatchClient batchClient = spanner.getBatchClient(DatabaseId.of(options.getProjectId(), instanceId, databaseId)); DatabaseAdminClient databaseAdminClient = spanner.getDatabaseAdminClient(); return new ExposedSpannerAccessor(spanner, databaseClient, databaseAdminClient, batchClient); }
Example #3
Source File: SpannerAccessor.java From beam with Apache License 2.0 | 4 votes |
private static SpannerAccessor createAndConnect(SpannerConfig spannerConfig) { SpannerOptions.Builder builder = SpannerOptions.newBuilder(); ValueProvider<Duration> commitDeadline = spannerConfig.getCommitDeadline(); if (commitDeadline != null && commitDeadline.get().getMillis() > 0) { // Set the GRPC deadline on the Commit API call. UnaryCallSettings.Builder commitSettings = builder.getSpannerStubSettingsBuilder().commitSettings(); RetrySettings.Builder commitRetrySettings = commitSettings.getRetrySettings().toBuilder(); commitSettings.setRetrySettings( commitRetrySettings .setTotalTimeout(org.threeten.bp.Duration.ofMillis(commitDeadline.get().getMillis())) .setMaxRpcTimeout(org.threeten.bp.Duration.ofMillis(commitDeadline.get().getMillis())) .setInitialRpcTimeout( org.threeten.bp.Duration.ofMillis(commitDeadline.get().getMillis())) .build()); } ValueProvider<String> projectId = spannerConfig.getProjectId(); if (projectId != null) { builder.setProjectId(projectId.get()); } ServiceFactory<Spanner, SpannerOptions> serviceFactory = spannerConfig.getServiceFactory(); if (serviceFactory != null) { builder.setServiceFactory(serviceFactory); } ValueProvider<String> host = spannerConfig.getHost(); if (host != null) { builder.setHost(host.get()); } String userAgentString = USER_AGENT_PREFIX + "/" + ReleaseInfo.getReleaseInfo().getVersion(); builder.setHeaderProvider(FixedHeaderProvider.create("user-agent", userAgentString)); SpannerOptions options = builder.build(); Spanner spanner = options.getService(); String instanceId = spannerConfig.getInstanceId().get(); String databaseId = spannerConfig.getDatabaseId().get(); DatabaseClient databaseClient = spanner.getDatabaseClient(DatabaseId.of(options.getProjectId(), instanceId, databaseId)); BatchClient batchClient = spanner.getBatchClient(DatabaseId.of(options.getProjectId(), instanceId, databaseId)); DatabaseAdminClient databaseAdminClient = spanner.getDatabaseAdminClient(); return new SpannerAccessor( spanner, databaseClient, databaseAdminClient, batchClient, spannerConfig); }