From 7f5dbe7670b42fa6688410aa73bf0941b7409491 Mon Sep 17 00:00:00 2001 From: aaronlichen-hp <75718017+aaronlichen-hp@users.noreply.github.com> Date: Tue, 10 Aug 2021 16:36:20 -0700 Subject: [PATCH] samples: Refactor the sample test to avoid direct reference the AnalyzeIamPolicyLongrunning metadata field (#829) * Refactor to remove the direct reference to the metadata field of AnalyzeIamPolicyLongrunning operation. * Refactor to remove the direct reference to the metadata field of AnalyzeIamPolicyLongrunning operation for Bigquery, also reformat the file. --- .../asset/AnalyzeIamPolicyLongrunningBigqueryExample.java | 8 +++----- .../asset/AnalyzeIamPolicyLongrunningGcsExample.java | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/asset/src/main/java/com/example/asset/AnalyzeIamPolicyLongrunningBigqueryExample.java b/asset/src/main/java/com/example/asset/AnalyzeIamPolicyLongrunningBigqueryExample.java index 1876d1bfd6c..a5387e0a46c 100644 --- a/asset/src/main/java/com/example/asset/AnalyzeIamPolicyLongrunningBigqueryExample.java +++ b/asset/src/main/java/com/example/asset/AnalyzeIamPolicyLongrunningBigqueryExample.java @@ -17,10 +17,8 @@ package com.example.asset; // [START asset_quickstart_analyze_iam_policy_longrunning_bigquery] -import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.rpc.ApiException; import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest; -import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningResponse; import com.google.cloud.asset.v1.AssetServiceClient; import com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig; import com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig.BigQueryDestination; @@ -71,9 +69,9 @@ public static void analyzeIamPolicyLongrunning( // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. try (AssetServiceClient client = AssetServiceClient.create()) { - OperationFuture - future = client.analyzeIamPolicyLongrunningAsync(request); - System.out.println("Analyze completed successfully:\n" + future.getMetadata().get()); + System.out.println( + "Analyze completed successfully:\n" + + client.analyzeIamPolicyLongrunningAsync(request).getMetadata().get()); } catch (IOException e) { System.out.println("Failed to create client:\n" + e.toString()); } catch (InterruptedException e) { diff --git a/asset/src/main/java/com/example/asset/AnalyzeIamPolicyLongrunningGcsExample.java b/asset/src/main/java/com/example/asset/AnalyzeIamPolicyLongrunningGcsExample.java index 955b5fad6a2..0784685077d 100644 --- a/asset/src/main/java/com/example/asset/AnalyzeIamPolicyLongrunningGcsExample.java +++ b/asset/src/main/java/com/example/asset/AnalyzeIamPolicyLongrunningGcsExample.java @@ -17,10 +17,8 @@ package com.example.asset; // [START asset_quickstart_analyze_iam_policy_longrunning_gcs] -import com.google.api.gax.longrunning.OperationFuture; import com.google.api.gax.rpc.ApiException; import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningRequest; -import com.google.cloud.asset.v1.AnalyzeIamPolicyLongrunningResponse; import com.google.cloud.asset.v1.AssetServiceClient; import com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig; import com.google.cloud.asset.v1.IamPolicyAnalysisOutputConfig.GcsDestination; @@ -69,9 +67,9 @@ public static void analyzeIamPolicyLongrunning( // once, and can be reused for multiple requests. After completing all of your requests, call // the "close" method on the client to safely clean up any remaining background resources. try (AssetServiceClient client = AssetServiceClient.create()) { - OperationFuture - future = client.analyzeIamPolicyLongrunningAsync(request); - System.out.println("Analyze completed successfully:\n" + future.getMetadata().get()); + System.out.println( + "Analyze completed successfully:\n" + + client.analyzeIamPolicyLongrunningAsync(request).getMetadata().get()); } catch (IOException e) { System.out.println("Failed to create client:\n" + e.toString()); } catch (InterruptedException e) {