Skip to content

Commit

Permalink
Drop sandbox-kv from the SDK (digital-asset#12717)
Browse files Browse the repository at this point in the history
Depends on digital-asset#12716 and digital-asset#12625 (CI fails until they are merged & this
is rebased so no chance of merging this accidentally).

changelog_begin
changelog_end
  • Loading branch information
cocreature authored Feb 3, 2022
1 parent 2885a3e commit 6ff7dc2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 54 deletions.
7 changes: 1 addition & 6 deletions daml-assistant/daml-helper/src/DA/Daml/Helper/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,13 @@ commandParser = subparser $ fold
jsonApiOptions <- many (strOption (long "json-api-option" <> metavar "JSON_API_OPTION" <> help "Pass option to HTTP JSON API"))
scriptOptions <- many (strOption (long "script-option" <> metavar "SCRIPT_OPTION" <> help "Pass option to Daml script interpreter"))
shutdownStdinClose <- stdinCloseOpt
sandboxChoice <- sandboxChoiceOpt
sandboxPortSpec <- sandboxCantonPortSpecOpt
pure $ Start StartOptions{..} shutdownStdinClose

sandboxPortOpt name desc =
optional (option (maybeReader (toSandboxPortSpec <=< readMaybe))
(long name <> metavar "PORT_NUM" <> help desc))

sandboxChoiceOpt =
flag' SandboxKV (long "sandbox-kv" <> help "Deprecated. Run with Sandbox KV.")
<|> flag SandboxCanton SandboxCanton (long "sandbox-canton" <> help "Run with Canton Sandbox. The 2.0 default.")
<*> sandboxCantonPortSpecOpt

sandboxCantonPortSpecOpt = do
adminApiSpec <- sandboxPortOpt "sandbox-admin-api-port" "Port number for the canton admin API (--sandbox-canton only)"
domainPublicApiSpec <- sandboxPortOpt "sandbox-domain-public-port" "Port number for the canton domain public API (--sandbox-canton only)"
Expand Down
45 changes: 7 additions & 38 deletions daml-assistant/daml-helper/src/DA/Daml/Helper/Start.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module DA.Daml.Helper.Start
, toSandboxPortSpec
, JsonApiPort(..)
, JsonApiConfig(..)
, SandboxChoice(..)
, SandboxCantonPortSpec(..)
) where

Expand Down Expand Up @@ -49,10 +48,6 @@ toSandboxPortSpec n
| n == 0 = Just FreePort
| otherwise = Just (SpecifiedPort (SandboxPort n))

fromSandboxPortSpec :: SandboxPortSpec -> Int
fromSandboxPortSpec FreePort = 0
fromSandboxPortSpec (SpecifiedPort (SandboxPort n)) = n

newtype SandboxPort = SandboxPort { unSandboxPort :: Int }
newtype NavigatorPort = NavigatorPort Int
newtype JsonApiPort = JsonApiPort Int
Expand Down Expand Up @@ -81,37 +76,19 @@ determineCantonOptions ledgerApiSpec SandboxCantonPortSpec{..} portFile = do
let cantonStaticTime = StaticTime False
pure CantonOptions {..}

withSandbox :: StartOptions -> FilePath -> [String] -> [String] -> (Process () () () -> SandboxPort -> IO a) -> IO a
withSandbox StartOptions{..} darPath scenarioArgs sandboxArgs kont =
case sandboxChoice of
SandboxKV -> oldSandbox "sandbox-kv"
SandboxCanton cantonPortSpec -> cantonSandbox cantonPortSpec

withSandbox :: StartOptions -> FilePath -> [String] -> (Process () () () -> SandboxPort -> IO a) -> IO a
withSandbox StartOptions{..} darPath sandboxArgs kont =
cantonSandbox
where
cantonSandbox cantonPortSpec = withTempDir $ \tempDir -> do
cantonSandbox = withTempDir $ \tempDir -> do
let portFile = tempDir </> "sandbox-portfile"
cantonOptions <- determineCantonOptions sandboxPortM cantonPortSpec portFile
cantonOptions <- determineCantonOptions sandboxPortM sandboxPortSpec portFile
withCantonSandbox cantonOptions sandboxArgs $ \ph -> do
putStrLn "Waiting for canton sandbox to start."
sandboxPort <- readPortFileWith decodeCantonSandboxPort (unsafeProcessHandle ph) maxRetries portFile
runLedgerUploadDar (sandboxLedgerFlags sandboxPort) (Just darPath)
kont ph (SandboxPort sandboxPort)

oldSandbox sandbox = withTempDir $ \tempDir -> do
let portFile = tempDir </> "sandbox-portfile"
let args = concat
[ [ sandbox ]
, concat [ [ "--port", show (fromSandboxPortSpec portSpec) ] | Just portSpec <- [sandboxPortM] ]
, [ "--port-file", portFile ]
, [ darPath ]
, scenarioArgs
, sandboxArgs
]
withSdkJar args "sandbox-logback.xml" $ \ph -> do
putStrLn "Waiting for sandbox to start: "
port <- readPortFile (unsafeProcessHandle ph) maxRetries portFile
kont ph (SandboxPort port)

withNavigator :: SandboxPort -> NavigatorPort -> [String] -> (Process () () () -> IO a) -> IO a
withNavigator (SandboxPort sandboxPort) navigatorPort args a = do
let navigatorArgs = concat
Expand Down Expand Up @@ -164,13 +141,9 @@ data StartOptions = StartOptions
, navigatorOptions :: [String]
, jsonApiOptions :: [String]
, scriptOptions :: [String]
, sandboxChoice :: !SandboxChoice
, sandboxPortSpec :: !SandboxCantonPortSpec
}

data SandboxChoice
= SandboxKV
| SandboxCanton !SandboxCantonPortSpec

data SandboxCantonPortSpec = SandboxCantonPortSpec
{ adminApiSpec :: !(Maybe SandboxPortSpec)
, domainPublicApiSpec :: !(Maybe SandboxPortSpec)
Expand All @@ -182,9 +155,6 @@ runStart startOptions@StartOptions{..} =
withProjectRoot Nothing (ProjectCheck "daml start" True) $ \_ _ -> do
projectConfig <- getProjectConfig Nothing
darPath <- getDarPath
mbScenario :: Maybe String <-
requiredE "Failed to parse scenario" $
queryProjectConfig ["scenario"] projectConfig
mbInitScript :: Maybe String <-
requiredE "Failed to parse init-script" $
queryProjectConfig ["init-script"] projectConfig
Expand All @@ -199,8 +169,7 @@ runStart startOptions@StartOptions{..} =
scriptOpts <- withOptsFromProjectConfig "script-options" scriptOptions projectConfig
doBuild
doCodegen projectConfig
let scenarioArgs = maybe [] (\scenario -> ["--scenario", scenario]) mbScenario
withSandbox startOptions darPath scenarioArgs sandboxOpts $ \sandboxPh sandboxPort -> do
withSandbox startOptions darPath sandboxOpts $ \sandboxPh sandboxPort -> do
let doRunInitScript =
whenJust mbInitScript $ \initScript -> do
putStrLn "Running the initialization script."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import com.daml.lf.engine.trigger.{ServiceMain => TriggerService}
import com.daml.auth.middleware.oauth2.{Main => Oauth2Middleware}
import com.daml.http.{Main => JsonApi}
import com.daml.navigator.{NavigatorBackend => Navigator}
import com.daml.platform.sandboxnext.{Main => SandboxKV}
import com.daml.script.export.{Main => Export}

object SdkMain {
Expand All @@ -27,7 +26,6 @@ object SdkMain {
case "trigger-service" => TriggerService.main(rest)
case "oauth2-middleware" => Oauth2Middleware.main(rest)
case "navigator" => Navigator.main(rest)
case "sandbox-kv" => SandboxKV.main(rest)
case _ => sys.exit(1)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ damlStart tmpDir = do
let startProc =
(shell $ unwords
[ "daml start"
, "--sandbox-canton"
, "--start-navigator=no"
, "--sandbox-port", show sandboxPort
, "--json-api-port", show jsonApiPort
Expand Down Expand Up @@ -371,7 +370,7 @@ damlToolTests =
damlStartTests :: IO DamlStartResource -> TestTree
damlStartTests getDamlStart =
-- We use testCaseSteps to make sure each of these tests runs in sequence, not in parallel.
testCaseSteps "daml start --sandbox-canton" $ \step -> do
testCaseSteps "daml start" $ \step -> do
let subtest :: forall t. String -> IO t -> IO t
subtest m p = step m >> p
subtest "sandbox and json-api come up" $ do
Expand Down Expand Up @@ -565,8 +564,7 @@ damlStartNotSharedTest = testCase "daml start --sandbox-port=0" $
, "start-navigator: false"
]
withDamlServiceIn tmpDir "start"
[ "--sandbox-canton"
, "--sandbox-port=0"
[ "--sandbox-port=0"
, "--json-api-port=0"
, "--json-api-option=--port-file=jsonapi.port"
] $ \ ph -> do
Expand Down
4 changes: 0 additions & 4 deletions release/sdk-config.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ commands:
path: daml-helper/daml-helper
desc: "Launch Canton Sandbox"
args: ["sandbox"]
- name: sandbox-kv
path: daml-helper/daml-helper
desc: "Deprecated. Launch Sandbox KV (the default Sandbox implementation for SDK < 2.0.0)"
args: ["run-jar", "--logback-config=sandbox-logback.xml", "daml-sdk/daml-sdk.jar", "sandbox-kv"]
- name: navigator
path: daml-helper/daml-helper
desc: "Launch the Navigator"
Expand Down

0 comments on commit 6ff7dc2

Please sign in to comment.