[ 
https://issues.apache.org/jira/browse/BEAM-8472?focusedWorklogId=337628&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-337628
 ]

ASF GitHub Bot logged work on BEAM-8472:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 02/Nov/19 00:34
            Start Date: 02/Nov/19 00:34
    Worklog Time Spent: 10m 
      Work Description: aaltay commented on pull request #9974: [BEAM-8472] Get 
default GCP region from gcloud (Java)
URL: https://github.com/apache/beam/pull/9974#discussion_r341790105
 
 

 ##########
 File path: 
runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/DataflowRunner.java
 ##########
 @@ -357,6 +357,50 @@ public static DataflowRunner fromOptions(PipelineOptions 
options) {
     return new DataflowRunner(dataflowOptions);
   }
 
+  /**
+   * Get a default value for Google Cloud region according to
+   * https://cloud.google.com/compute/docs/gcloud-compute/#default-properties. 
If no other default
+   * can be found, returns "us-central1".
+   */
+  static String getDefaultGcpRegion() {
+    String environmentRegion = System.getenv("CLOUDSDK_COMPUTE_REGION");
+    if (environmentRegion != null && !environmentRegion.isEmpty()) {
+      LOG.info("Using default GCP region {} from $CLOUDSDK_COMPUTE_REGION", 
environmentRegion);
+      return environmentRegion;
+    }
+    try {
+      ProcessBuilder pb =
+          new ProcessBuilder(Arrays.asList("gcloud", "config", "get-value", 
"compute/region"));
+      Process process = pb.start();
+      BufferedReader reader =
+          new BufferedReader(
+              new InputStreamReader(process.getInputStream(), 
StandardCharsets.UTF_8));
+      BufferedReader errorReader =
+          new BufferedReader(
+              new InputStreamReader(process.getErrorStream(), 
StandardCharsets.UTF_8));
+      process.waitFor(1, TimeUnit.SECONDS);
 
 Review comment:
   - Is 1 second enough?
   - Should we check the return value of this call? (IIUC it returns false for 
timeout.)
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 337628)
    Time Spent: 1h 50m  (was: 1h 40m)

> Get default GCP region from gcloud
> ----------------------------------
>
>                 Key: BEAM-8472
>                 URL: https://issues.apache.org/jira/browse/BEAM-8472
>             Project: Beam
>          Issue Type: Improvement
>          Components: runner-dataflow
>            Reporter: Kyle Weaver
>            Assignee: Kyle Weaver
>            Priority: Major
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> Currently, we default to us-central1 if --region flag is not set. The Google 
> Cloud SDK generally tries to get a default value in this case for 
> convenience, which we should follow. 
> [https://cloud.google.com/compute/docs/gcloud-compute/#order_of_precedence_for_default_properties]



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to