|
| 1 | +/* |
| 2 | + * Copyright 2016 Google Inc. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | + * in compliance with the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | + * or implied. See the License for the specific language governing permissions and limitations under |
| 12 | + * the License. |
| 13 | + */ |
| 14 | + |
| 15 | +/* |
| 16 | + * EDITING INSTRUCTIONS |
| 17 | + * This file was generated from the file |
| 18 | + * https://github.com/google/googleapis/blob/master/google/logging/v2/logging_config.proto |
| 19 | + * and updates to that file get reflected here through a refresh process. |
| 20 | + * For the short term, the refresh process will only be runnable by Google engineers. |
| 21 | + * Manual additions are allowed because the refresh process performs |
| 22 | + * a 3-way merge in order to preserve those manual additions. In order to not |
| 23 | + * break the refresh process, only certain types of modifications are |
| 24 | + * allowed. |
| 25 | + * |
| 26 | + * Allowed modifications - currently these are the only types allowed: |
| 27 | + * 1. New methods (these should be added to the end of the class) |
| 28 | + * 2. New imports |
| 29 | + * 3. Additional documentation between "manual edit" demarcations |
| 30 | + * |
| 31 | + * Happy editing! |
| 32 | + */ |
| 33 | + |
| 34 | +package com.google.gcloud.logging.spi.v2; |
| 35 | + |
| 36 | +import com.google.api.gax.core.BackoffParams; |
| 37 | +import com.google.api.gax.core.ConnectionSettings; |
| 38 | +import com.google.api.gax.core.RetryParams; |
| 39 | +import com.google.api.gax.grpc.ApiCallSettings; |
| 40 | +import com.google.api.gax.grpc.ApiCallable.ApiCallableBuilder; |
| 41 | +import com.google.api.gax.grpc.ApiCallable.PageStreamingApiCallableBuilder; |
| 42 | +import com.google.api.gax.grpc.PageDescriptor; |
| 43 | +import com.google.api.gax.grpc.ServiceApiSettings; |
| 44 | +import com.google.common.collect.ImmutableList; |
| 45 | +import com.google.common.collect.ImmutableMap; |
| 46 | +import com.google.common.collect.ImmutableSet; |
| 47 | +import com.google.common.collect.Lists; |
| 48 | +import com.google.common.collect.Sets; |
| 49 | +import com.google.logging.v2.ConfigServiceV2Grpc; |
| 50 | +import com.google.logging.v2.CreateSinkRequest; |
| 51 | +import com.google.logging.v2.DeleteSinkRequest; |
| 52 | +import com.google.logging.v2.GetSinkRequest; |
| 53 | +import com.google.logging.v2.ListSinksRequest; |
| 54 | +import com.google.logging.v2.ListSinksResponse; |
| 55 | +import com.google.logging.v2.LogSink; |
| 56 | +import com.google.logging.v2.UpdateSinkRequest; |
| 57 | +import com.google.protobuf.Empty; |
| 58 | +import io.grpc.Status; |
| 59 | + |
| 60 | +// Manually-added imports: add custom (non-generated) imports after this point. |
| 61 | + |
| 62 | +// AUTO-GENERATED DOCUMENTATION AND CLASS - see instructions at the top of the file for editing. |
| 63 | +@javax.annotation.Generated("by GAPIC") |
| 64 | +public class ConfigServiceV2Settings extends ServiceApiSettings { |
| 65 | + |
| 66 | + // ========= |
| 67 | + // Constants |
| 68 | + // ========= |
| 69 | + |
| 70 | + /** |
| 71 | + * The default address of the service. |
| 72 | + * |
| 73 | + * <!-- manual edit --> |
| 74 | + * <!-- end manual edit --> |
| 75 | + */ |
| 76 | + public static final String DEFAULT_SERVICE_ADDRESS = "logging.googleapis.com"; |
| 77 | + |
| 78 | + /** |
| 79 | + * The default port of the service. |
| 80 | + * |
| 81 | + * <!-- manual edit --> |
| 82 | + * <!-- end manual edit --> |
| 83 | + */ |
| 84 | + public static final int DEFAULT_SERVICE_PORT = 443; |
| 85 | + |
| 86 | + /** |
| 87 | + * The default scopes of the service. |
| 88 | + */ |
| 89 | + public static final ImmutableList<String> DEFAULT_SERVICE_SCOPES = |
| 90 | + ImmutableList.<String>builder() |
| 91 | + .add("https://www.googleapis.com/auth/logging.write") |
| 92 | + .add("https://www.googleapis.com/auth/logging.admin") |
| 93 | + .add("https://www.googleapis.com/auth/logging.read") |
| 94 | + .add("https://www.googleapis.com/auth/cloud-platform.read-only") |
| 95 | + .add("https://www.googleapis.com/auth/cloud-platform") |
| 96 | + .build(); |
| 97 | + |
| 98 | + private static final ImmutableMap<String, ImmutableSet<Status.Code>> RETRYABLE_CODE_DEFINITIONS; |
| 99 | + |
| 100 | + static { |
| 101 | + ImmutableMap.Builder<String, ImmutableSet<Status.Code>> definitions = ImmutableMap.builder(); |
| 102 | + definitions.put( |
| 103 | + "idempotent", |
| 104 | + Sets.immutableEnumSet( |
| 105 | + Lists.<Status.Code>newArrayList( |
| 106 | + Status.Code.DEADLINE_EXCEEDED, Status.Code.UNAVAILABLE))); |
| 107 | + definitions.put("non_idempotent", Sets.immutableEnumSet(Lists.<Status.Code>newArrayList())); |
| 108 | + RETRYABLE_CODE_DEFINITIONS = definitions.build(); |
| 109 | + } |
| 110 | + |
| 111 | + private static final ImmutableMap<String, RetryParams> RETRY_PARAM_DEFINITIONS; |
| 112 | + |
| 113 | + static { |
| 114 | + ImmutableMap.Builder<String, RetryParams> definitions = ImmutableMap.builder(); |
| 115 | + RetryParams params = null; |
| 116 | + params = |
| 117 | + RetryParams.newBuilder() |
| 118 | + .setRetryBackoff( |
| 119 | + BackoffParams.newBuilder() |
| 120 | + .setInitialDelayMillis(100L) |
| 121 | + .setDelayMultiplier(1.2) |
| 122 | + .setMaxDelayMillis(1000L) |
| 123 | + .build()) |
| 124 | + .setTimeoutBackoff( |
| 125 | + BackoffParams.newBuilder() |
| 126 | + .setInitialDelayMillis(300L) |
| 127 | + .setDelayMultiplier(1.3) |
| 128 | + .setMaxDelayMillis(3000L) |
| 129 | + .build()) |
| 130 | + .setTotalTimeout(30000L) |
| 131 | + .build(); |
| 132 | + definitions.put("default", params); |
| 133 | + RETRY_PARAM_DEFINITIONS = definitions.build(); |
| 134 | + } |
| 135 | + |
| 136 | + private static class MethodBuilders { |
| 137 | + private final PageStreamingApiCallableBuilder<ListSinksRequest, ListSinksResponse, LogSink> |
| 138 | + listSinksMethod; |
| 139 | + private final ApiCallableBuilder<GetSinkRequest, LogSink> getSinkMethod; |
| 140 | + private final ApiCallableBuilder<CreateSinkRequest, LogSink> createSinkMethod; |
| 141 | + private final ApiCallableBuilder<UpdateSinkRequest, LogSink> updateSinkMethod; |
| 142 | + private final ApiCallableBuilder<DeleteSinkRequest, Empty> deleteSinkMethod; |
| 143 | + private final ImmutableList<? extends ApiCallSettings> allMethods; |
| 144 | + |
| 145 | + public MethodBuilders() { |
| 146 | + listSinksMethod = |
| 147 | + new PageStreamingApiCallableBuilder<>( |
| 148 | + ConfigServiceV2Grpc.METHOD_LIST_SINKS, LIST_SINKS_PAGE_STR_DESC); |
| 149 | + listSinksMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); |
| 150 | + listSinksMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); |
| 151 | + |
| 152 | + getSinkMethod = new ApiCallableBuilder<>(ConfigServiceV2Grpc.METHOD_GET_SINK); |
| 153 | + getSinkMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); |
| 154 | + getSinkMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); |
| 155 | + |
| 156 | + createSinkMethod = new ApiCallableBuilder<>(ConfigServiceV2Grpc.METHOD_CREATE_SINK); |
| 157 | + createSinkMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); |
| 158 | + createSinkMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); |
| 159 | + |
| 160 | + updateSinkMethod = new ApiCallableBuilder<>(ConfigServiceV2Grpc.METHOD_UPDATE_SINK); |
| 161 | + updateSinkMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("non_idempotent")); |
| 162 | + updateSinkMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); |
| 163 | + |
| 164 | + deleteSinkMethod = new ApiCallableBuilder<>(ConfigServiceV2Grpc.METHOD_DELETE_SINK); |
| 165 | + deleteSinkMethod.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("idempotent")); |
| 166 | + deleteSinkMethod.setRetryParams(RETRY_PARAM_DEFINITIONS.get("default")); |
| 167 | + |
| 168 | + allMethods = |
| 169 | + ImmutableList.<ApiCallSettings>builder() |
| 170 | + .add( |
| 171 | + listSinksMethod, |
| 172 | + getSinkMethod, |
| 173 | + createSinkMethod, |
| 174 | + updateSinkMethod, |
| 175 | + deleteSinkMethod) |
| 176 | + .build(); |
| 177 | + } |
| 178 | + } |
| 179 | + |
| 180 | + private final MethodBuilders methods; |
| 181 | + |
| 182 | + // =============== |
| 183 | + // Factory Methods |
| 184 | + // =============== |
| 185 | + |
| 186 | + /** |
| 187 | + * Constructs an instance of ConfigServiceV2Settings with default settings. |
| 188 | + * |
| 189 | + * <!-- manual edit --> |
| 190 | + * <!-- end manual edit --> |
| 191 | + */ |
| 192 | + public static ConfigServiceV2Settings create() { |
| 193 | + ConfigServiceV2Settings settings = new ConfigServiceV2Settings(new MethodBuilders()); |
| 194 | + settings.provideChannelWith( |
| 195 | + ConnectionSettings.builder() |
| 196 | + .setServiceAddress(DEFAULT_SERVICE_ADDRESS) |
| 197 | + .setPort(DEFAULT_SERVICE_PORT) |
| 198 | + .provideCredentialsWith(DEFAULT_SERVICE_SCOPES) |
| 199 | + .build()); |
| 200 | + return settings; |
| 201 | + } |
| 202 | + |
| 203 | + /** |
| 204 | + * Constructs an instance of ConfigServiceV2Settings with default settings. This is protected so |
| 205 | + * that it easy to make a subclass, but otherwise, the static factory methods should be preferred. |
| 206 | + * |
| 207 | + * <!-- manual edit --> |
| 208 | + * <!-- end manual edit --> |
| 209 | + */ |
| 210 | + protected ConfigServiceV2Settings(MethodBuilders methods) { |
| 211 | + super(methods.allMethods); |
| 212 | + this.methods = methods; |
| 213 | + } |
| 214 | + |
| 215 | + /** |
| 216 | + * Returns the PageStreamingApiCallableBuilder for the API method listSinks. |
| 217 | + * |
| 218 | + * <!-- manual edit --> |
| 219 | + * <!-- end manual edit --> |
| 220 | + */ |
| 221 | + public PageStreamingApiCallableBuilder<ListSinksRequest, ListSinksResponse, LogSink> |
| 222 | + listSinksMethod() { |
| 223 | + return methods.listSinksMethod; |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * Returns the ApiCallableBuilder for the API method getSink. |
| 228 | + * |
| 229 | + * <!-- manual edit --> |
| 230 | + * <!-- end manual edit --> |
| 231 | + */ |
| 232 | + public ApiCallableBuilder<GetSinkRequest, LogSink> getSinkMethod() { |
| 233 | + return methods.getSinkMethod; |
| 234 | + } |
| 235 | + |
| 236 | + /** |
| 237 | + * Returns the ApiCallableBuilder for the API method createSink. |
| 238 | + * |
| 239 | + * <!-- manual edit --> |
| 240 | + * <!-- end manual edit --> |
| 241 | + */ |
| 242 | + public ApiCallableBuilder<CreateSinkRequest, LogSink> createSinkMethod() { |
| 243 | + return methods.createSinkMethod; |
| 244 | + } |
| 245 | + |
| 246 | + /** |
| 247 | + * Returns the ApiCallableBuilder for the API method updateSink. |
| 248 | + * |
| 249 | + * <!-- manual edit --> |
| 250 | + * <!-- end manual edit --> |
| 251 | + */ |
| 252 | + public ApiCallableBuilder<UpdateSinkRequest, LogSink> updateSinkMethod() { |
| 253 | + return methods.updateSinkMethod; |
| 254 | + } |
| 255 | + |
| 256 | + /** |
| 257 | + * Returns the ApiCallableBuilder for the API method deleteSink. |
| 258 | + * |
| 259 | + * <!-- manual edit --> |
| 260 | + * <!-- end manual edit --> |
| 261 | + */ |
| 262 | + public ApiCallableBuilder<DeleteSinkRequest, Empty> deleteSinkMethod() { |
| 263 | + return methods.deleteSinkMethod; |
| 264 | + } |
| 265 | + |
| 266 | + private static PageDescriptor<ListSinksRequest, ListSinksResponse, LogSink> |
| 267 | + LIST_SINKS_PAGE_STR_DESC = |
| 268 | + new PageDescriptor<ListSinksRequest, ListSinksResponse, LogSink>() { |
| 269 | + @Override |
| 270 | + public Object emptyToken() { |
| 271 | + return ""; |
| 272 | + } |
| 273 | + |
| 274 | + @Override |
| 275 | + public ListSinksRequest injectToken(ListSinksRequest payload, Object token) { |
| 276 | + return ListSinksRequest.newBuilder(payload).setPageToken((String) token).build(); |
| 277 | + } |
| 278 | + |
| 279 | + @Override |
| 280 | + public Object extractNextToken(ListSinksResponse payload) { |
| 281 | + return payload.getNextPageToken(); |
| 282 | + } |
| 283 | + |
| 284 | + @Override |
| 285 | + public Iterable<LogSink> extractResources(ListSinksResponse payload) { |
| 286 | + return payload.getSinksList(); |
| 287 | + } |
| 288 | + }; |
| 289 | +} |
0 commit comments