-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[BEAM-151] Work towards moving Dataflow pipeline runner to separate maven module #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
558c5ad
e60e420
a8a3419
7b66b19
7a583cb
aa405d2
e88059f
d4fa5f7
52a4ecb
ab8e54d
acbb3bd
6b1bb22
00d5da0
4f13241
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * 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 com.google.cloud.dataflow.sdk.options; | ||
|
|
||
| /** | ||
| * Properties that can be set when using Pubsub with the Beam SDK. | ||
| */ | ||
| @Description("Options that are used to configure BigQuery. See " | ||
| + "https://cloud.google.com/bigquery/what-is-bigquery for details on BigQuery.") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. description is off
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| public interface PubsubOptions extends ApplicationNameOptions, GcpOptions, | ||
| PipelineOptions, StreamingOptions { | ||
|
|
||
| /** | ||
| * Root URL for use with the Pubsub API. | ||
| */ | ||
| @Description("Root URL for use with the Pubsub API") | ||
| @Default.String("https://pubsub.googleapis.com") | ||
| @Hidden | ||
| String getPubsubRootUrl(); | ||
| void setPubsubRootUrl(String value); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * 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 com.google.cloud.dataflow.sdk.util; | ||
|
|
||
| import static com.google.cloud.dataflow.sdk.util.Transport.getJsonFactory; | ||
| import static com.google.cloud.dataflow.sdk.util.Transport.getTransport; | ||
|
|
||
| import com.google.api.client.auth.oauth2.Credential; | ||
| import com.google.api.client.http.HttpRequestInitializer; | ||
| import com.google.api.services.clouddebugger.v2.Clouddebugger; | ||
| import com.google.api.services.dataflow.Dataflow; | ||
| import com.google.cloud.dataflow.sdk.options.DataflowPipelineOptions; | ||
| import com.google.cloud.hadoop.util.ChainingHttpRequestInitializer; | ||
| import com.google.common.collect.ImmutableList; | ||
|
|
||
| import java.net.MalformedURLException; | ||
| import java.net.URL; | ||
|
|
||
| /** | ||
| * Helpers for cloud communication. | ||
| */ | ||
| public class DataflowTransport { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dataflow or Gcp? I assume these are used outside of Dataflow Service, e.g., PubSubIO on Flink.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see you only moved Dataflow and Clouddebugger. Why only these?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. never mind. resolved.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I left all the GCP IO transports in Transport.java and moved out to the two clients which we use only with Dataflow. In the future, cloud debugger could move out to be generic for others as well. |
||
|
|
||
|
|
||
| private static class ApiComponents { | ||
| public String rootUrl; | ||
| public String servicePath; | ||
|
|
||
| public ApiComponents(String root, String path) { | ||
| this.rootUrl = root; | ||
| this.servicePath = path; | ||
| } | ||
| } | ||
|
|
||
| private static ApiComponents apiComponentsFromUrl(String urlString) { | ||
| try { | ||
| URL url = new URL(urlString); | ||
| String rootUrl = url.getProtocol() + "://" + url.getHost() + | ||
| (url.getPort() > 0 ? ":" + url.getPort() : ""); | ||
| return new ApiComponents(rootUrl, url.getPath()); | ||
| } catch (MalformedURLException e) { | ||
| throw new RuntimeException("Invalid URL: " + urlString); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns a Google Cloud Dataflow client builder. | ||
| */ | ||
| public static Dataflow.Builder newDataflowClient(DataflowPipelineOptions options) { | ||
| String servicePath = options.getDataflowEndpoint(); | ||
| ApiComponents components; | ||
| if (servicePath.contains("://")) { | ||
| components = apiComponentsFromUrl(servicePath); | ||
| } else { | ||
| components = new ApiComponents(options.getApiRootUrl(), servicePath); | ||
| } | ||
|
|
||
| return new Dataflow.Builder(getTransport(), | ||
| getJsonFactory(), | ||
| chainHttpRequestInitializer( | ||
| options.getGcpCredential(), | ||
| // Do not log 404. It clutters the output and is possibly even required by the caller. | ||
| new RetryHttpRequestInitializer(ImmutableList.of(404)))) | ||
| .setApplicationName(options.getAppName()) | ||
| .setRootUrl(components.rootUrl) | ||
| .setServicePath(components.servicePath) | ||
| .setGoogleClientRequestInitializer(options.getGoogleApiTrace()); | ||
| } | ||
|
|
||
| public static Clouddebugger.Builder newClouddebuggerClient(DataflowPipelineOptions options) { | ||
| return new Clouddebugger.Builder(getTransport(), | ||
| getJsonFactory(), | ||
| chainHttpRequestInitializer(options.getGcpCredential(), new RetryHttpRequestInitializer())) | ||
| .setApplicationName(options.getAppName()) | ||
| .setGoogleClientRequestInitializer(options.getGoogleApiTrace()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a Dataflow client that does not automatically retry failed | ||
| * requests. | ||
| */ | ||
| public static Dataflow.Builder | ||
| newRawDataflowClient(DataflowPipelineOptions options) { | ||
| return newDataflowClient(options) | ||
| .setHttpRequestInitializer(options.getGcpCredential()) | ||
| .setGoogleClientRequestInitializer(options.getGoogleApiTrace()); | ||
| } | ||
|
|
||
| private static HttpRequestInitializer chainHttpRequestInitializer( | ||
| Credential credential, HttpRequestInitializer httpRequestInitializer) { | ||
| if (credential == null) { | ||
| return httpRequestInitializer; | ||
| } else { | ||
| return new ChainingHttpRequestInitializer(credential, httpRequestInitializer); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apache header as of #100
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done