You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/08/24 00:15:21 UTC

[GitHub] [beam] Abacn opened a new pull request, #22833: Support customized HttpTransport for GCS

Abacn opened a new pull request, #22833:
URL: https://github.com/apache/beam/pull/22833

   Resolve #22504. (Keep the issue open as a concrete solution is in planning).
   
   * Add corresponding setter method for Transport.getTransport
   
   **Please** add a meaningful description for your change here
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] [**Choose reviewer(s)**](https://beam.apache.org/contribute/#make-your-change) and mention them in a comment (`R: @username`).
    - [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
    - [ ] Update `CHANGES.md` with noteworthy changes.
    - [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
   
   See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://beam.apache.org/contribute/get-started-contributing/#make-the-reviewers-job-easier).
   
   To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
   
   GitHub Actions Tests Status (on master branch)
   ------------------------------------------------------------------------------------------------
   [![Build python source distribution and wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
   [![Python tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Java tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
   [![Go tests](https://github.com/apache/beam/workflows/Go%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
   
   See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI.
   


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] github-actions[bot] commented on pull request #22833: Support customized HttpTransport for GCS

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #22833:
URL: https://github.com/apache/beam/pull/22833#issuecomment-1240635010

   Reminder, please take a look at this pr: @robertwb 


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] Abacn closed pull request #22833: Support customized HttpTransport for GCS

Posted by GitBox <gi...@apache.org>.
Abacn closed pull request #22833: Support customized HttpTransport for GCS
URL: https://github.com/apache/beam/pull/22833


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] Abacn commented on pull request #22833: Support customized HttpTransport for GCS

Posted by GitBox <gi...@apache.org>.
Abacn commented on PR #22833:
URL: https://github.com/apache/beam/pull/22833#issuecomment-1225878925

   R: @chamikaramj 
   
   Is there a security concern to expose this?


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] Abacn commented on pull request #22833: Support customized HttpTransport for GCS

Posted by GitBox <gi...@apache.org>.
Abacn commented on PR #22833:
URL: https://github.com/apache/beam/pull/22833#issuecomment-1240828379

   Closed because prefer other approach (pipeline options)


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] Abacn commented on a diff in pull request #22833: Support customized HttpTransport for GCS

Posted by GitBox <gi...@apache.org>.
Abacn commented on code in PR #22833:
URL: https://github.com/apache/beam/pull/22833#discussion_r959560176


##########
sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/TransportTest.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.gcp.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import com.google.api.client.http.HttpTransport;
+import com.google.api.client.http.LowLevelHttpRequest;
+import java.io.IOException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Test case for {@link Transport}. */
+@RunWith(JUnit4.class)
+public class TransportTest {
+
+  private static class MockHttpTransport extends HttpTransport {
+
+    @Override
+    protected LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
+      return null;
+    }
+  }
+
+  @Test
+  public void testGetSetTransport() {
+    HttpTransport defaultTransport = Transport.getTransport();
+    try {
+      Transport.setHttpTransport(new MockHttpTransport());

Review Comment:
   That's good point. Should be able to avoid this potential flakes by making MockHttpTransport functionable (embed a real transport object in it)



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] Abacn commented on pull request #22833: Support customized HttpTransport for GCS

Posted by GitBox <gi...@apache.org>.
Abacn commented on PR #22833:
URL: https://github.com/apache/beam/pull/22833#issuecomment-1230619568

   Run Java PreCommit


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] chamikaramj commented on a diff in pull request #22833: Support customized HttpTransport for GCS

Posted by GitBox <gi...@apache.org>.
chamikaramj commented on code in PR #22833:
URL: https://github.com/apache/beam/pull/22833#discussion_r959108560


##########
sdks/java/extensions/google-cloud-platform-core/src/test/java/org/apache/beam/sdk/extensions/gcp/util/TransportTest.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.extensions.gcp.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import com.google.api.client.http.HttpTransport;
+import com.google.api.client.http.LowLevelHttpRequest;
+import java.io.IOException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Test case for {@link Transport}. */
+@RunWith(JUnit4.class)
+public class TransportTest {
+
+  private static class MockHttpTransport extends HttpTransport {
+
+    @Override
+    protected LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
+      return null;
+    }
+  }
+
+  @Test
+  public void testGetSetTransport() {
+    HttpTransport defaultTransport = Transport.getTransport();
+    try {
+      Transport.setHttpTransport(new MockHttpTransport());

Review Comment:
   Just noting that this changes the transport globally so probably good to monitor pre-commit test suite for any related flakes for other tests that are run parallelly (I believe Gradle does this).



##########
sdks/java/extensions/google-cloud-platform-core/src/main/java/org/apache/beam/sdk/extensions/gcp/util/Transport.java:
##########
@@ -34,29 +34,64 @@
 import org.apache.beam.sdk.extensions.gcp.auth.NullCredentialInitializer;
 import org.apache.beam.sdk.extensions.gcp.options.GcsOptions;
 import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList;
+import org.apache.http.annotation.Experimental;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /** Helpers for cloud communication. */
 public class Transport {
 
+  private static final Logger LOG = LoggerFactory.getLogger(Transport.class);
+
+  private static @Nullable HttpTransport httpTransport;
+
   private static class SingletonHelper {
     /** Global instance of the JSON factory. */
     private static final JsonFactory JSON_FACTORY;
 
     /** Global instance of the HTTP transport. */
-    private static final HttpTransport HTTP_TRANSPORT;
+    private static final HttpTransport DEFAULT_HTTP_TRANSPORT;
 
     static {
       try {
         JSON_FACTORY = JacksonFactory.getDefaultInstance();
-        HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
+        DEFAULT_HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
       } catch (GeneralSecurityException | IOException e) {
         throw new RuntimeException(e);
       }
     }
   }
 
-  public static HttpTransport getTransport() {
-    return SingletonHelper.HTTP_TRANSPORT;
+  /**
+   * Get previously set instance of {@link HttpTransport}. If not set, returns the default global
+   * instance constructed from {@link GoogleNetHttpTransport#newTrustedTransport()}.
+   */
+  public static synchronized HttpTransport getTransport() {
+    if (httpTransport == null) {
+      httpTransport = SingletonHelper.DEFAULT_HTTP_TRANSPORT;
+    }
+    return httpTransport;
+  }
+
+  /**
+   * Set a customized instance of {@link HttpTransport} with trust store and mTLS settings. Refer to
+   * https://github.com/googleapis/google-auth-library-java#configuring-a-proxy for the construction
+   * of customized instance of HttpTransport. Reset to default HttpTransport by passing null to this
+   * method.
+   */
+  @Experimental
+  public static synchronized void setHttpTransport(HttpTransport transport) {
+    // TDOO(https://github.com/apache/beam/issues/22504) Support customized HttpTransport through
+    // pipeline options then remove this experimental method.

Review Comment:
   Is it possible to introduce a single pipeline option that sets the full transport object (instead of getting into details about customizing the transport) ?



-- 
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.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] github-actions[bot] commented on pull request #22833: Support customized HttpTransport for GCS

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #22833:
URL: https://github.com/apache/beam/pull/22833#issuecomment-1225924743

   Assigning reviewers. If you would like to opt out of this review, comment `assign to next reviewer`:
   
   R: @robertwb for label java.
   
   Available commands:
   - `stop reviewer notifications` - opt out of the automated review tooling
   - `remind me after tests pass` - tag the comment author after tests pass
   - `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
   
   The PR bot will only process comments in the main thread (not review comments).


-- 
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.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org