Skip to content

Commit b7e2207

Browse files
committed
Tidy eqx initaws
1 parent f1e9148 commit b7e2207

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

tools/Equinox.Tool/Program.fs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
open Argu
44
open Domain.Infrastructure
55
open Equinox.Tool.Infrastructure
6+
open FSharp.AWS.DynamoDB // Throughput
67
open FSharp.Control
78
open FSharp.UMX
89
open Microsoft.Extensions.DependencyInjection
@@ -68,24 +69,24 @@ and CosmosInitArguments(p : ParseResults<InitParameters>) =
6869
| CosmosModeType.Serverless -> CosmosInit.Provisioning.Serverless
6970
member val SkipStoredProc = p.Contains InitParameters.SkipStoredProc
7071
and [<NoComparison; NoEquality>] TableParameters =
71-
| [<AltCommandLine "-D">] OnDemand
72-
| [<AltCommandLine "-S">] Streaming of Equinox.DynamoStore.Core.Initialization.StreamingMode
73-
| [<AltCommandLine "-rru">] ReadCu of int64
74-
| [<AltCommandLine "-wru">] WriteCu of int64
75-
| [<CliPrefix(CliPrefix.None)>] Dynamo of ParseResults<Storage.Dynamo.Parameters>
72+
| [<AltCommandLine "-D"; Unique>] OnDemand
73+
| [<AltCommandLine "-S"; Unique>] Streaming of Equinox.DynamoStore.Core.Initialization.StreamingMode
74+
| [<AltCommandLine "-rru"; Unique>] ReadCu of int64
75+
| [<AltCommandLine "-wru"; Unique>] WriteCu of int64
76+
| [<CliPrefix(CliPrefix.None); Last>] Dynamo of ParseResults<Storage.Dynamo.Parameters>
7677
interface IArgParserTemplate with
7778
member a.Usage = a |> function
78-
| OnDemand -> "Specify On-Demand Capacity Mode."
79-
| Streaming _ -> "Specify Streaming Mode. Default NEW_IMAGE"
80-
| ReadCu _ -> "Specify Read Capacity Units to provision for the Table. (Ignored in On-Demand mode)"
81-
| WriteCu _ -> "Specify Write Capacity Units to provision for the Table. (Ignored in On-Demand mode)"
79+
| OnDemand -> "Specify On-Demand Capacity Mode. (Default: Provisioned mode)"
80+
| ReadCu _ -> "Specify Read Capacity Units to provision for the Table. (Not applicable in On-Demand mode)"
81+
| WriteCu _ -> "Specify Write Capacity Units to provision for the Table. (Not applicable in On-Demand mode)"
82+
| Streaming _ -> "Specify Streaming Mode. Default: `NEW_IMAGE`"
8283
| Dynamo _ -> "DynamoDB Connection parameters."
8384
and DynamoInitArguments(p : ParseResults<TableParameters>) =
84-
let streaming = p.GetResult(Streaming, Equinox.DynamoStore.Core.Initialization.StreamingMode.Default)
85-
let onDemand = p.Contains OnDemand
86-
let readCu = p.GetResult ReadCu
87-
let writeCu = p.GetResult WriteCu
88-
member _.ProvisioningMode = streaming, if onDemand then None else Some (readCu, writeCu)
85+
member val StreamingMode = p.GetResult(Streaming, Equinox.DynamoStore.Core.Initialization.StreamingMode.Default)
86+
member val Throughput = match p.Contains OnDemand with
87+
| false -> Throughput.Provisioned (ProvisionedThroughput(p.GetResult ReadCu, p.GetResult WriteCu))
88+
| true when p.Contains ReadCu && p.Contains WriteCu -> Storage.missingArg "CUs are not applicable in On-Demand mode"
89+
| true -> Throughput.OnDemand
8990
and [<NoComparison; NoEquality>] ConfigParameters =
9091
| [<CliPrefix(CliPrefix.None); Last; AltCommandLine "ms">] MsSql of ParseResults<Storage.Sql.Ms.Parameters>
9192
| [<CliPrefix(CliPrefix.None); Last; AltCommandLine "my">] MySql of ParseResults<Storage.Sql.My.Parameters>
@@ -362,7 +363,7 @@ module CosmosInit =
362363
let connect log (p : ParseResults<Storage.Cosmos.Parameters>) =
363364
Storage.Cosmos.connect log (Storage.Cosmos.Arguments p) |> fst
364365

365-
let containerAndOrDb log (p : ParseResults<InitParameters>) = async {
366+
let containerAndOrDb log (p : ParseResults<InitParameters>) =
366367
let a = CosmosInitArguments p
367368
match p.GetSubCommand() with
368369
| InitParameters.Cosmos cp ->
@@ -377,28 +378,29 @@ module CosmosInit =
377378
| CosmosInit.Provisioning.Serverless ->
378379
let modeStr = "Serverless"
379380
log.Information("Provisioning `Equinox.CosmosStore` Store in {mode:l} mode with automatic RU/s as configured in account", modeStr)
380-
return! CosmosInit.init log client (dName, cName) a.ProvisioningMode a.SkipStoredProc
381-
| x -> Storage.missingArg $"unexpected subcommand %A{x}" }
381+
CosmosInit.init log client (dName, cName) a.ProvisioningMode a.SkipStoredProc
382+
| x -> Storage.missingArg $"unexpected subcommand %A{x}"
382383

383384
module DynamoInit =
384385

385386
open Equinox.DynamoStore
386387

387-
let table (log : ILogger) (p : ParseResults<TableParameters>) = async {
388-
let streaming, throughput = (DynamoInitArguments p).ProvisioningMode
388+
let table (log : ILogger) (p : ParseResults<TableParameters>) =
389+
let a = DynamoInitArguments p
389390
match p.GetSubCommand() with
390391
| TableParameters.Dynamo sp ->
391-
let a = Storage.Dynamo.Arguments sp
392-
let client = a.Connector.CreateClient()
393-
let tableName = a.Table
394-
match throughput with
395-
| Some (rcu, wcu) ->
396-
log.Information("Provisioning `Equinox.DynamoStore` Table {table} with {read}/{write}CU; streaming {streaming}", tableName, rcu, wcu, streaming)
397-
do! Core.Initialization.provision client tableName (Throughput.Provisioned (ProvisionedThroughput(rcu, wcu)), streaming)
398-
| None ->
399-
log.Information("Provisioning `Equinox.DynamoStore` Table {table} with On-Demand capacity management; streaming {streaming}", tableName, streaming)
400-
do! Core.Initialization.provision client tableName (Throughput.OnDemand, streaming)
401-
| x -> Storage.missingArg $"unexpected subcommand %A{x}" }
392+
let sa = Storage.Dynamo.Arguments sp
393+
let t, s = a.Throughput, a.StreamingMode
394+
match t with
395+
| Throughput.Provisioned t ->
396+
log.Information("Provisioning `Equinox.DynamoStore` Table {table} with {read}R/{write}WCU Provisioned capacity; streaming {streaming}",
397+
sa.Table, t.ReadCapacityUnits, t.WriteCapacityUnits, a.StreamingMode)
398+
| Throughput.OnDemand ->
399+
log.Information("Provisioning `Equinox.DynamoStore` Table {table} with On-Demand capacity management; streaming {streaming}",
400+
sa.Table, a.StreamingMode)
401+
let client = sa.Connector.CreateClient()
402+
Core.Initialization.provision client sa.Table (t, s)
403+
| x -> Storage.missingArg $"unexpected subcommand %A{x}"
402404

403405
module SqlInit =
404406

@@ -420,7 +422,7 @@ module CosmosStats =
420422
member container.QueryValue<'T>(sqlQuery : string) =
421423
let query : Microsoft.Azure.Cosmos.FeedResponse<'T> = container.GetItemQueryIterator<'T>(sqlQuery).ReadNextAsync() |> Async.AwaitTaskCorrect |> Async.RunSynchronously
422424
query |> Seq.exactlyOne
423-
let run (log : ILogger, _verboseConsole, _maybeSeq) (p : ParseResults<StatsParameters>) = async {
425+
let run (log : ILogger, _verboseConsole, _maybeSeq) (p : ParseResults<StatsParameters>) =
424426
match p.GetSubCommand() with
425427
| StatsParameters.Cosmos sp ->
426428
let doS, doD, doE = p.Contains StatsParameters.Streams, p.Contains StatsParameters.Documents, p.Contains StatsParameters.Events
@@ -438,9 +440,8 @@ module CosmosStats =
438440
let res = container.QueryValue<int>(sql)
439441
log.Information("{stat}: {result:N0}", name, res)})
440442
|> if inParallel then Async.Parallel else Async.Sequential
441-
|> Async.Ignore
442-
|> Async.RunSynchronously
443-
| x -> Storage.missingArg $"unexpected subcommand %A{x}" }
443+
|> Async.Ignore<unit[]>
444+
| x -> Storage.missingArg $"unexpected subcommand %A{x}"
444445

445446
module Dump =
446447

0 commit comments

Comments
 (0)