forked from GoogleCloudPlatform/DataflowTemplates
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added pipeline options for cassandra. Made changes to the required cl…
…ass to support cassandra
- Loading branch information
1 parent
3e375ac
commit 5c2a0aa
Showing
7 changed files
with
245 additions
and
89 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...java/com/google/cloud/teleport/v2/spanner/migrations/utils/CassandraConfigFileReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.google.cloud.teleport.v2.spanner.migrations.utils; | ||
|
||
import com.google.cloud.teleport.v2.spanner.migrations.cassandra.CassandraConfig; | ||
import com.google.gson.FieldNamingPolicy; | ||
import com.google.gson.GsonBuilder; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.channels.Channels; | ||
import java.nio.charset.StandardCharsets; | ||
import org.apache.beam.sdk.io.FileSystems; | ||
import org.apache.commons.io.IOUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** Class to read the Cassandra configuration file in GCS and convert it into a CassandraConfig object. */ | ||
public class CassandraConfigFileReader { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(CassandraConfigFileReader.class); | ||
|
||
public CassandraConfig getCassandraConfig(String cassandraConfigFilePath) { | ||
try (InputStream stream = | ||
Channels.newInputStream( | ||
FileSystems.open(FileSystems.matchNewResource(cassandraConfigFilePath, false)))) { | ||
|
||
String result = IOUtils.toString(stream, StandardCharsets.UTF_8); | ||
CassandraConfig cassandraConfig = | ||
new GsonBuilder() | ||
.setFieldNamingPolicy(FieldNamingPolicy.IDENTITY) | ||
.create() | ||
.fromJson(result, CassandraConfig.class); | ||
|
||
LOG.info("The Cassandra config is: {}", cassandraConfig); | ||
return cassandraConfig; | ||
|
||
} catch (IOException e) { | ||
LOG.error( | ||
"Failed to read Cassandra config file. Make sure it is ASCII or UTF-8 encoded and contains a well-formed JSON string.", | ||
e); | ||
throw new RuntimeException( | ||
"Failed to read Cassandra config file. Make sure it is ASCII or UTF-8 encoded and contains a well-formed JSON string.", | ||
e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.