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

Add support for endpoint_override in Schema Tool for DynamoDB #183

Merged
merged 2 commits into from
Apr 12, 2021
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
17 changes: 9 additions & 8 deletions tools/scalar-schema/src/scalar_schema/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,25 @@
[nil "--dynamo" "Operate for DynamoDB"]
[nil "--jdbc" "Operate for a JDBC database"]
["-h" "--host DB_HOST" "Address of Cassandra like IP or URI address of your Cosmos DB account"]
["-P" "--port DB_PORT" "Port of Cassandra. This option is ignored when Cosmos DB and DynamoDB."
["-P" "--port DB_PORT" "Port of Cassandra"
:parse-fn #(Integer/parseInt %)]
["-u" "--user USERNAME" "Username of the database. This option is ignored when Cosmos DB and DynamoDB."]
["-p" "--password PASSWORD" "Password of Cassandra or Cosmos DB account or a JDBC database"]
["-u" "--user USERNAME" "Username of Cassandra or a JDBC database"]
["-p" "--password PASSWORD" "Password of a database"]
["-f" "--schema-file SCHEMA_JSON" "Schema file"]
["-r" "--ru RESOURCE_UNIT" "Base RU for each table on Cosmos DB or DynamoDB. The RU of the coordinator for Scalar DB transaction is specified by this option. This option is ignored when Cassandra."
["-r" "--ru RESOURCE_UNIT" "Base RU for each table on Cosmos DB or DynamoDB. The RU of the coordinator for Scalar DB transaction is specified by this option"
:parse-fn #(Integer/parseInt %)]
["-R" "--replication-factor REPLICATION_FACTOR"
"The number of replicas. This options is ignored when Cosmos DB and DynamoDB."
"The number of replicas for Cassandra"
:default 1 :parse-fn #(Integer/parseInt %)]
["-n" "--network-strategy NETWORK_STRATEGY"
"The network topology strategy. SimpleStrategy or NetworkTopologyStrategy. This option is ignored when Cosmos DB and DynamoDB."]
"The network topology strategy for Cassandra. SimpleStrategy or NetworkTopologyStrategy"]
["-D" "--delete-all" "All database will be deleted, if this is enabled."]
[nil "--region REGION" "Region where the tool creates tables for DynamoDB"]
[nil "--prefix NAMESPACE_PREFIX" "Namespace prefix. The prefix is added to all the namespaces."]
["-j" "--jdbc-url JDBC_URL" "JDBC URL for a JDBC database"]
[nil "--no-scaling" "Disable auto-scaling for Cosmos DB and DynamoDB. This option is ignored when Cassandra and JDBC databases"]
[nil "--no-backup" "Disable continuous backup for DynamoDB. This option is ignored when Cosmos DB and Cassandra and JDBC databases."]
[nil "--no-scaling" "Disable auto-scaling for Cosmos DB and DynamoDB"]
[nil "--no-backup" "Disable continuous backup for DynamoDB"]
[nil "--endpoint-override ENDPOINT_OVERRIDE" "Endpoint with which the DynamoDB SDK should communicate"]
[nil "--help"]])

(defn -main [& args]
Expand Down
13 changes: 8 additions & 5 deletions tools/scalar-schema/src/scalar_schema/dynamo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
"blob" ScalarAttributeType/B})

(defn- get-client
[user password region]
[user password region endpoint-override]
(-> (DynamoDbClient/builder)
(.credentialsProvider (dynamo/get-credentials-provider user password))
(.region (Region/of region))
(#(if endpoint-override
(.endpointOverride % (java.net.URI/create endpoint-override)) %))
.build))

(defn- table-exists?
Expand Down Expand Up @@ -207,9 +209,9 @@
(log/warn table "doesn't exist"))))

(defn make-dynamo-operator
[{:keys [user password region no-scaling no-backup]}]
(let [client (get-client user password region)
scaling-client (scaling/get-scaling-client user password region)]
[{:keys [user password region no-scaling no-backup endpoint-override]}]
(let [client (get-client user password region endpoint-override)
scaling-client (scaling/get-scaling-client user password region endpoint-override)]
(reify proto/IOperator
(create-table [_ schema opts]
(create-table client schema opts)
Expand All @@ -219,7 +221,8 @@
(when-not no-backup
(backup/enable-continuous-backup client schema)))
(delete-table [_ schema _]
(scaling/disable-auto-scaling scaling-client schema)
(when-not no-scaling
(scaling/disable-auto-scaling scaling-client schema))
(delete-table client schema))
(close [_ _]
(.close client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
:index-write ScalableDimension/DYNAMODB_INDEX_WRITE_CAPACITY_UNITS})

(defn get-scaling-client
[user password region]
[user password region endpoint-override]
(-> (ApplicationAutoScalingClient/builder)
(.credentialsProvider (dynamo/get-credentials-provider user password))
(.region (Region/of region))
(#(if endpoint-override
(.endpointOverride % (java.net.URI/create endpoint-override)) %))
.build))

(defn- get-resource-id
Expand Down