1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.cloud.asset.v1p7beta1; 18 19 import com.google.api.core.BetaApi; 20 import com.google.api.gax.core.BackgroundResource; 21 import com.google.api.gax.longrunning.OperationFuture; 22 import com.google.api.gax.rpc.OperationCallable; 23 import com.google.api.gax.rpc.UnaryCallable; 24 import com.google.cloud.asset.v1p7beta1.stub.AssetServiceStub; 25 import com.google.cloud.asset.v1p7beta1.stub.AssetServiceStubSettings; 26 import com.google.longrunning.Operation; 27 import com.google.longrunning.OperationsClient; 28 import java.io.IOException; 29 import java.util.concurrent.TimeUnit; 30 import javax.annotation.Generated; 31 32 // AUTO-GENERATED DOCUMENTATION AND CLASS. 33 /** 34 * Service Description: Asset service definition. 35 * 36 * <p>This class provides the ability to make remote calls to the backing service through method 37 * calls that map to API methods. Sample code to get started: 38 * 39 * <pre>{@code 40 * // This snippet has been automatically generated and should be regarded as a code template only. 41 * // It will require modifications to work: 42 * // - It may require correct/in-range values for request initialization. 43 * // - It may require specifying regional endpoints when creating the service client as shown in 44 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 45 * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { 46 * ExportAssetsRequest request = 47 * ExportAssetsRequest.newBuilder() 48 * .setParent("ExportAssetsRequest-846449128".toString()) 49 * .setReadTime(Timestamp.newBuilder().build()) 50 * .addAllAssetTypes(new ArrayList<String>()) 51 * .setContentType(ContentType.forNumber(0)) 52 * .setOutputConfig(OutputConfig.newBuilder().build()) 53 * .addAllRelationshipTypes(new ArrayList<String>()) 54 * .build(); 55 * ExportAssetsResponse response = assetServiceClient.exportAssetsAsync(request).get(); 56 * } 57 * }</pre> 58 * 59 * <p>Note: close() needs to be called on the AssetServiceClient object to clean up resources such 60 * as threads. In the example above, try-with-resources is used, which automatically calls close(). 61 * 62 * <p>The surface of this class includes several types of Java methods for each of the API's 63 * methods: 64 * 65 * <ol> 66 * <li>A "flattened" method. With this type of method, the fields of the request type have been 67 * converted into function parameters. It may be the case that not all fields are available as 68 * parameters, and not every API method will have a flattened method entry point. 69 * <li>A "request object" method. This type of method only takes one parameter, a request object, 70 * which must be constructed before the call. Not every API method will have a request object 71 * method. 72 * <li>A "callable" method. This type of method takes no parameters and returns an immutable API 73 * callable object, which can be used to initiate calls to the service. 74 * </ol> 75 * 76 * <p>See the individual methods for example code. 77 * 78 * <p>Many parameters require resource names to be formatted in a particular way. To assist with 79 * these names, this class includes a format method for each type of name, and additionally a parse 80 * method to extract the individual identifiers contained within names that are returned. 81 * 82 * <p>This class can be customized by passing in a custom instance of AssetServiceSettings to 83 * create(). For example: 84 * 85 * <p>To customize credentials: 86 * 87 * <pre>{@code 88 * // This snippet has been automatically generated and should be regarded as a code template only. 89 * // It will require modifications to work: 90 * // - It may require correct/in-range values for request initialization. 91 * // - It may require specifying regional endpoints when creating the service client as shown in 92 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 93 * AssetServiceSettings assetServiceSettings = 94 * AssetServiceSettings.newBuilder() 95 * .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) 96 * .build(); 97 * AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); 98 * }</pre> 99 * 100 * <p>To customize the endpoint: 101 * 102 * <pre>{@code 103 * // This snippet has been automatically generated and should be regarded as a code template only. 104 * // It will require modifications to work: 105 * // - It may require correct/in-range values for request initialization. 106 * // - It may require specifying regional endpoints when creating the service client as shown in 107 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 108 * AssetServiceSettings assetServiceSettings = 109 * AssetServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); 110 * AssetServiceClient assetServiceClient = AssetServiceClient.create(assetServiceSettings); 111 * }</pre> 112 * 113 * <p>Please refer to the GitHub repository's samples for more quickstart code snippets. 114 */ 115 @BetaApi 116 @Generated("by gapic-generator-java") 117 public class AssetServiceClient implements BackgroundResource { 118 private final AssetServiceSettings settings; 119 private final AssetServiceStub stub; 120 private final OperationsClient operationsClient; 121 122 /** Constructs an instance of AssetServiceClient with default settings. */ create()123 public static final AssetServiceClient create() throws IOException { 124 return create(AssetServiceSettings.newBuilder().build()); 125 } 126 127 /** 128 * Constructs an instance of AssetServiceClient, using the given settings. The channels are 129 * created based on the settings passed in, or defaults for any settings that are not set. 130 */ create(AssetServiceSettings settings)131 public static final AssetServiceClient create(AssetServiceSettings settings) throws IOException { 132 return new AssetServiceClient(settings); 133 } 134 135 /** 136 * Constructs an instance of AssetServiceClient, using the given stub for making calls. This is 137 * for advanced usage - prefer using create(AssetServiceSettings). 138 */ create(AssetServiceStub stub)139 public static final AssetServiceClient create(AssetServiceStub stub) { 140 return new AssetServiceClient(stub); 141 } 142 143 /** 144 * Constructs an instance of AssetServiceClient, using the given settings. This is protected so 145 * that it is easy to make a subclass, but otherwise, the static factory methods should be 146 * preferred. 147 */ AssetServiceClient(AssetServiceSettings settings)148 protected AssetServiceClient(AssetServiceSettings settings) throws IOException { 149 this.settings = settings; 150 this.stub = ((AssetServiceStubSettings) settings.getStubSettings()).createStub(); 151 this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); 152 } 153 AssetServiceClient(AssetServiceStub stub)154 protected AssetServiceClient(AssetServiceStub stub) { 155 this.settings = null; 156 this.stub = stub; 157 this.operationsClient = OperationsClient.create(this.stub.getOperationsStub()); 158 } 159 getSettings()160 public final AssetServiceSettings getSettings() { 161 return settings; 162 } 163 getStub()164 public AssetServiceStub getStub() { 165 return stub; 166 } 167 168 /** 169 * Returns the OperationsClient that can be used to query the status of a long-running operation 170 * returned by another API method call. 171 */ getOperationsClient()172 public final OperationsClient getOperationsClient() { 173 return operationsClient; 174 } 175 176 // AUTO-GENERATED DOCUMENTATION AND METHOD. 177 /** 178 * Exports assets with time and resource types to a given Cloud Storage location/BigQuery table. 179 * For Cloud Storage location destinations, the output format is newline-delimited JSON. Each line 180 * represents a [google.cloud.asset.v1p7beta1.Asset][google.cloud.asset.v1p7beta1.Asset] in the 181 * JSON format; for BigQuery table destinations, the output table stores the fields in asset proto 182 * as columns. This API implements the 183 * [google.longrunning.Operation][google.longrunning.Operation] API , which allows you to keep 184 * track of the export. We recommend intervals of at least 2 seconds with exponential retry to 185 * poll the export operation result. For regular-size resource parent, the export operation 186 * usually finishes within 5 minutes. 187 * 188 * <p>Sample code: 189 * 190 * <pre>{@code 191 * // This snippet has been automatically generated and should be regarded as a code template only. 192 * // It will require modifications to work: 193 * // - It may require correct/in-range values for request initialization. 194 * // - It may require specifying regional endpoints when creating the service client as shown in 195 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 196 * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { 197 * ExportAssetsRequest request = 198 * ExportAssetsRequest.newBuilder() 199 * .setParent("ExportAssetsRequest-846449128".toString()) 200 * .setReadTime(Timestamp.newBuilder().build()) 201 * .addAllAssetTypes(new ArrayList<String>()) 202 * .setContentType(ContentType.forNumber(0)) 203 * .setOutputConfig(OutputConfig.newBuilder().build()) 204 * .addAllRelationshipTypes(new ArrayList<String>()) 205 * .build(); 206 * ExportAssetsResponse response = assetServiceClient.exportAssetsAsync(request).get(); 207 * } 208 * }</pre> 209 * 210 * @param request The request object containing all of the parameters for the API call. 211 * @throws com.google.api.gax.rpc.ApiException if the remote call fails 212 */ exportAssetsAsync( ExportAssetsRequest request)213 public final OperationFuture<ExportAssetsResponse, ExportAssetsRequest> exportAssetsAsync( 214 ExportAssetsRequest request) { 215 return exportAssetsOperationCallable().futureCall(request); 216 } 217 218 // AUTO-GENERATED DOCUMENTATION AND METHOD. 219 /** 220 * Exports assets with time and resource types to a given Cloud Storage location/BigQuery table. 221 * For Cloud Storage location destinations, the output format is newline-delimited JSON. Each line 222 * represents a [google.cloud.asset.v1p7beta1.Asset][google.cloud.asset.v1p7beta1.Asset] in the 223 * JSON format; for BigQuery table destinations, the output table stores the fields in asset proto 224 * as columns. This API implements the 225 * [google.longrunning.Operation][google.longrunning.Operation] API , which allows you to keep 226 * track of the export. We recommend intervals of at least 2 seconds with exponential retry to 227 * poll the export operation result. For regular-size resource parent, the export operation 228 * usually finishes within 5 minutes. 229 * 230 * <p>Sample code: 231 * 232 * <pre>{@code 233 * // This snippet has been automatically generated and should be regarded as a code template only. 234 * // It will require modifications to work: 235 * // - It may require correct/in-range values for request initialization. 236 * // - It may require specifying regional endpoints when creating the service client as shown in 237 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 238 * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { 239 * ExportAssetsRequest request = 240 * ExportAssetsRequest.newBuilder() 241 * .setParent("ExportAssetsRequest-846449128".toString()) 242 * .setReadTime(Timestamp.newBuilder().build()) 243 * .addAllAssetTypes(new ArrayList<String>()) 244 * .setContentType(ContentType.forNumber(0)) 245 * .setOutputConfig(OutputConfig.newBuilder().build()) 246 * .addAllRelationshipTypes(new ArrayList<String>()) 247 * .build(); 248 * OperationFuture<ExportAssetsResponse, ExportAssetsRequest> future = 249 * assetServiceClient.exportAssetsOperationCallable().futureCall(request); 250 * // Do something. 251 * ExportAssetsResponse response = future.get(); 252 * } 253 * }</pre> 254 */ 255 public final OperationCallable<ExportAssetsRequest, ExportAssetsResponse, ExportAssetsRequest> exportAssetsOperationCallable()256 exportAssetsOperationCallable() { 257 return stub.exportAssetsOperationCallable(); 258 } 259 260 // AUTO-GENERATED DOCUMENTATION AND METHOD. 261 /** 262 * Exports assets with time and resource types to a given Cloud Storage location/BigQuery table. 263 * For Cloud Storage location destinations, the output format is newline-delimited JSON. Each line 264 * represents a [google.cloud.asset.v1p7beta1.Asset][google.cloud.asset.v1p7beta1.Asset] in the 265 * JSON format; for BigQuery table destinations, the output table stores the fields in asset proto 266 * as columns. This API implements the 267 * [google.longrunning.Operation][google.longrunning.Operation] API , which allows you to keep 268 * track of the export. We recommend intervals of at least 2 seconds with exponential retry to 269 * poll the export operation result. For regular-size resource parent, the export operation 270 * usually finishes within 5 minutes. 271 * 272 * <p>Sample code: 273 * 274 * <pre>{@code 275 * // This snippet has been automatically generated and should be regarded as a code template only. 276 * // It will require modifications to work: 277 * // - It may require correct/in-range values for request initialization. 278 * // - It may require specifying regional endpoints when creating the service client as shown in 279 * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library 280 * try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) { 281 * ExportAssetsRequest request = 282 * ExportAssetsRequest.newBuilder() 283 * .setParent("ExportAssetsRequest-846449128".toString()) 284 * .setReadTime(Timestamp.newBuilder().build()) 285 * .addAllAssetTypes(new ArrayList<String>()) 286 * .setContentType(ContentType.forNumber(0)) 287 * .setOutputConfig(OutputConfig.newBuilder().build()) 288 * .addAllRelationshipTypes(new ArrayList<String>()) 289 * .build(); 290 * ApiFuture<Operation> future = assetServiceClient.exportAssetsCallable().futureCall(request); 291 * // Do something. 292 * Operation response = future.get(); 293 * } 294 * }</pre> 295 */ exportAssetsCallable()296 public final UnaryCallable<ExportAssetsRequest, Operation> exportAssetsCallable() { 297 return stub.exportAssetsCallable(); 298 } 299 300 @Override close()301 public final void close() { 302 stub.close(); 303 } 304 305 @Override shutdown()306 public void shutdown() { 307 stub.shutdown(); 308 } 309 310 @Override isShutdown()311 public boolean isShutdown() { 312 return stub.isShutdown(); 313 } 314 315 @Override isTerminated()316 public boolean isTerminated() { 317 return stub.isTerminated(); 318 } 319 320 @Override shutdownNow()321 public void shutdownNow() { 322 stub.shutdownNow(); 323 } 324 325 @Override awaitTermination(long duration, TimeUnit unit)326 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 327 return stub.awaitTermination(duration, unit); 328 } 329 } 330