0

I'm trying to connect to Google BigTable using:

 BigtableOptions.Builder bigTableOptions = new BigtableOptions.Builder()
            .setProjectId(options.getProjectId())
            .setInstanceId(options.getInstanceId())
            .setCredentialOptions(
                    CredentialOptions.jsonCredentials(
                                    new FileInputStream(systemResource.toFile())
                    ));

However, I'm getting:

Caused by: java.io.NotSerializableException: java.io.FileInputStream
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)

I've tried with 2.1.0-SNAPSHOT and 2.0.0.

Has anyone else hit this problem?

Thanks.

sanj2sanj
  • 71
  • 6
  • Do you need a different credential object for Dataflow and Cloud Bigtable? By default, the Cloud Bigtable credentials are the same as the Dataflow credentials. – Solomon Duskis Jun 23 '17 at 20:44
  • Works okay when I don't specify the credentials, but was curious to see whether I could explicitly use a "service user". – sanj2sanj Jul 06 '17 at 10:11

1 Answers1

0

I ended up doing this:

// Load the keyfile
final String keyFile = "service-account-keyfile.json"
final Path path = Paths.get(ClassLoader.getSystemResource(keyFile).getPath());
// Load and Convert key to a CredentialOptions object
final GoogleCredentials credentials = GoogleCredentials.fromStream(Files.newInputStream(path))
                .createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
final CredentialOptions bigTableCredentials = CredentialOptions.credential(credentials);

//Use the credentials
final BigtableOptions bigtableOptions =
            new BigtableOptions.Builder()
                    .setCredentialOptions(bigTableCredentials)
sanj2sanj
  • 71
  • 6