File tree Expand file tree Collapse file tree 4 files changed +29
-5
lines changed
sdks/java/io/google-cloud-platform/src
main/java/org/apache/beam/sdk/io/gcp/firestore
test/java/org/apache/beam/sdk/io/gcp/firestore/it Expand file tree Collapse file tree 4 files changed +29
-5
lines changed Original file line number Diff line number Diff line change 1717 */
1818package org .apache .beam .sdk .io .gcp .firestore ;
1919
20+ import org .apache .beam .sdk .extensions .gcp .options .GcpOptions ;
2021import org .apache .beam .sdk .options .Default ;
2122import org .apache .beam .sdk .options .Description ;
2223import org .apache .beam .sdk .options .PipelineOptions ;
@@ -75,4 +76,14 @@ public interface FirestoreOptions extends PipelineOptions {
7576 * @param host the host and port to connect to
7677 */
7778 void setFirestoreHost (String host );
79+
80+ /** The Firestore project ID to connect to. */
81+ @ Description ("Firestore project ID" )
82+ @ Nullable
83+ String getFirestoreProject ();
84+
85+ /**
86+ * Set the Firestore project ID, it will override the value from {@link GcpOptions#getProject()}.
87+ */
88+ void setFirestoreProject (String firestoreProject );
7889}
Original file line number Diff line number Diff line change @@ -635,9 +635,14 @@ public void setup() {
635635 /** {@inheritDoc} */
636636 @ Override
637637 public final void startBundle (StartBundleContext c ) {
638- String project = c .getPipelineOptions ().as (GcpOptions .class ).getProject ();
638+ String project = c .getPipelineOptions ().as (FirestoreOptions .class ).getFirestoreProject ();
639+ if (project == null ) {
640+ project = c .getPipelineOptions ().as (GcpOptions .class ).getProject ();
641+ }
639642 projectId =
640- requireNonNull (project , "project must be defined on GcpOptions of PipelineOptions" );
643+ requireNonNull (
644+ project ,
645+ "project must be defined on FirestoreOptions or GcpOptions of PipelineOptions" );
641646 firestoreStub = firestoreStatefulComponentFactory .getFirestoreStub (c .getPipelineOptions ());
642647 }
643648
Original file line number Diff line number Diff line change @@ -202,11 +202,16 @@ public void setup() {
202202
203203 @ Override
204204 public final void startBundle (StartBundleContext c ) {
205- String project = c .getPipelineOptions ().as (GcpOptions .class ).getProject ();
205+ String project = c .getPipelineOptions ().as (FirestoreOptions .class ).getFirestoreProject ();
206+ if (project == null ) {
207+ project = c .getPipelineOptions ().as (GcpOptions .class ).getProject ();
208+ }
206209 String databaseId = c .getPipelineOptions ().as (FirestoreOptions .class ).getFirestoreDb ();
207210 databaseRootName =
208211 DatabaseRootName .of (
209- requireNonNull (project , "project must be defined on GcpOptions of PipelineOptions" ),
212+ requireNonNull (
213+ project ,
214+ "project must be defined on FirestoreOptions or GcpOptions of PipelineOptions" ),
210215 requireNonNull (
211216 databaseId ,
212217 "firestoreDb must be defined on FirestoreOptions of PipelineOptions" ));
Original file line number Diff line number Diff line change 1717 */
1818package org .apache .beam .sdk .io .gcp .firestore .it ;
1919
20+ import static org .apache .beam .vendor .guava .v32_1_2_jre .com .google .common .base .MoreObjects .firstNonNull ;
21+
2022import com .google .api .core .ApiFunction ;
2123import com .google .api .core .ApiFuture ;
2224import com .google .api .core .ApiFutures ;
@@ -132,7 +134,8 @@ public FirestoreTestingHelper(CleanupMode cleanupMode) {
132134 firestoreOptions =
133135 FirestoreOptions .newBuilder ()
134136 .setCredentials (gcpOptions .getGcpCredential ())
135- .setProjectId (gcpOptions .getProject ())
137+ .setProjectId (
138+ firstNonNull (firestoreBeamOptions .getFirestoreProject (), gcpOptions .getProject ()))
136139 .setDatabaseId (firestoreBeamOptions .getFirestoreDb ())
137140 .setHost (firestoreBeamOptions .getFirestoreHost ())
138141 .build ();
You can’t perform that action at this time.
0 commit comments