Skip to content
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

tweak BigQuery default project detection #195

Merged
merged 2 commits into from
Jul 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ val guavaVersion = "19.0"
val hadoopVersion = "2.7.2"
val hamcrestVersion = "1.3"
val hbaseVersion = "1.0.2"
val ini4jVersion = "0.5.4"
val javaLshVersion = "0.9"
val jodaConvertVersion = "1.8.1"
val junitVersion = "4.12"
Expand Down Expand Up @@ -192,8 +191,7 @@ lazy val scioCore: Project = Project(
"com.twitter" %% "chill" % chillVersion,
"com.twitter" % "chill-protobuf" % chillVersion,
"commons-io" % "commons-io" % commonsIoVersion,
"org.apache.commons" % "commons-math3" % commonsMath3Version,
"org.ini4j" % "ini4j" % ini4jVersion
"org.apache.commons" % "commons-math3" % commonsMath3Version
)
)
).dependsOn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.google.cloud.dataflow.sdk.io.BigQueryIO
import com.google.cloud.dataflow.sdk.io.BigQueryIO.Write.CreateDisposition._
import com.google.cloud.dataflow.sdk.io.BigQueryIO.Write.WriteDisposition._
import com.google.cloud.dataflow.sdk.io.BigQueryIO.Write.{CreateDisposition, WriteDisposition}
import com.google.cloud.dataflow.sdk.options.GcpOptions.DefaultProjectFactory
import com.google.cloud.dataflow.sdk.util.{BigQueryTableInserter, BigQueryTableRowIterator}
import com.google.common.base.Charsets
import com.google.common.hash.Hashing
Expand Down Expand Up @@ -498,12 +499,17 @@ object BigQueryClient {
*/
def defaultInstance(): BigQueryClient = {
if (instance == null) {
val project = sys.props(PROJECT_KEY)
if (project == null) {
throw new RuntimeException(
s"Property $PROJECT_KEY not set. Use -D$PROJECT_KEY=<BILLING_PROJECT>")
instance = if (sys.props(PROJECT_KEY) != null) {
BigQueryClient(sys.props(PROJECT_KEY))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only reason this is still here is for backwards compatibility, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or in environments with no default, i.e. Travis.

} else {
val project = new DefaultProjectFactory().create(null)
if (project != null) {
BigQueryClient(project)
} else {
throw new RuntimeException(
s"Property $PROJECT_KEY not set. Use -D$PROJECT_KEY=<BILLING_PROJECT>")
}
}
instance = BigQueryClient(project)
}
instance
}
Expand Down

This file was deleted.

26 changes: 12 additions & 14 deletions scio-repl/src/main/scala/com/spotify/scio/repl/ScioILoop.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package com.spotify.scio.repl

import java.io.BufferedReader

import com.google.cloud.dataflow.sdk.options.GcpOptions.DefaultProjectFactory
import com.google.cloud.dataflow.sdk.options.{DataflowPipelineOptions, PipelineOptionsFactory}
import com.spotify.scio.bigquery.BigQueryClient
import com.spotify.scio.scioVersion
import com.spotify.scio.util.GCloudConfigUtils

import scala.tools.nsc.GenericRunnerSettings
import scala.tools.nsc.interpreter.{IR, JPrintWriter}
Expand Down Expand Up @@ -211,20 +211,18 @@ class ScioILoop(scioClassLoader: ScioReplClassLoader,

val key = BigQueryClient.PROJECT_KEY

if (sys.props(key) == null) {
val project = GCloudConfigUtils.getGCloudProjectId
project match {
case Some(project_id) =>
echo(s"Using '$project_id' as your BigQuery project.")
sys.props(key) = project_id
create(project_id)
case None =>
echo(s"System property '$key' not set. BigQueryClient is not available.")
echo(s"Set it with '-D$key=<PROJECT-NAME>' command line argument.")
IR.Success
}
} else {
if (sys.props(key) != null) {
create(sys.props(key))
} else {
val defaultProject = new DefaultProjectFactory().create(null)
if (defaultProject != null) {
echo(s"Using '$defaultProject' as your BigQuery project.")
create(defaultProject)
} else {
echo(s"System property '$key' not set. BigQueryClient is not available.")
echo(s"Set it with '-D$key=<PROJECT-NAME>' command line argument.")
IR.Success
}
}
}

Expand Down