Skip to content

Commit

Permalink
Make new sandbox the default. (digital-asset#5295)
Browse files Browse the repository at this point in the history
* Make new sandbox the default.

changelog_begin

- [DAML SDK] The new sandbox is now the default that runs with ``daml sandbox`` and ``daml start``. The command ``daml sandbox-next`` has been removed. The old sandbox can be invoked via ``daml sandbox-classic`` and ``daml start --sandbox-classic=yes``.

changelog_end

* Update descriptions.

* Change it to a switch

* Change switch help

* Recapitalize
  • Loading branch information
associahedron authored Mar 31, 2020
1 parent 1d0c0df commit dd8a3a3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
5 changes: 4 additions & 1 deletion daml-assistant/daml-helper/src/DA/Daml/Helper/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ data Command
, jsonApiOptions :: JsonApiOptions
, scriptOptions :: ScriptOptions
, shutdownStdinClose :: Bool
, sandboxClassic :: SandboxClassic
}
| Deploy { flags :: LedgerFlags }
| LedgerListParties { flags :: LedgerFlags, json :: JsonFlag }
Expand Down Expand Up @@ -119,7 +120,7 @@ commandParser = subparser $ fold
<$> optional (argument str (metavar "TARGET_PATH" <> help "Project folder to initialize."))

startCmd = Start
<$> optional (SandboxPort <$> option auto (long "sandbox-port" <> metavar "PORT_NUM" <> help "Port number for the sandbox"))
<$> optional (SandboxPort <$> option auto (long "sandbox-port" <> metavar "PORT_NUM" <> help "Port number for the sandbox"))
<*> (OpenBrowser <$> flagYesNoAuto "open-browser" True "Open the browser after navigator" idm)
<*> optional navigatorFlag
<*> jsonApiCfg
Expand All @@ -130,6 +131,7 @@ 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")))
<*> stdinCloseOpt
<*> (SandboxClassic <$> switch (long "sandbox-classic" <> help "Run with Sandbox Classic."))

navigatorFlag =
-- We do not use flagYesNoAuto here since that doesn’t allow us to differentiate
Expand Down Expand Up @@ -336,6 +338,7 @@ runCommand = \case
navigatorOptions
jsonApiOptions
scriptOptions
sandboxClassic
Deploy {..} -> runDeploy flags
LedgerListParties {..} -> runLedgerListParties flags json
LedgerAllocateParties {..} -> runLedgerAllocateParties flags parties
Expand Down
13 changes: 9 additions & 4 deletions daml-assistant/daml-helper/src/DA/Daml/Helper/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module DA.Daml.Helper.Run
, NavigatorOptions(..)
, JsonApiOptions(..)
, ScriptOptions(..)
, SandboxClassic(..)
) where

import Control.Concurrent
Expand Down Expand Up @@ -741,10 +742,11 @@ navigatorPortNavigatorArgs (NavigatorPort p) = ["--port", show p]
navigatorURL :: NavigatorPort -> String
navigatorURL (NavigatorPort p) = "http://localhost:" <> show p

withSandbox :: SandboxPort -> [String] -> (Process () () () -> IO a) -> IO a
withSandbox (SandboxPort port) args a = withTempFile $ \portFile -> do
withSandbox :: SandboxClassic -> SandboxPort -> [String] -> (Process () () () -> IO a) -> IO a
withSandbox (SandboxClassic classic) (SandboxPort port) args a = withTempFile $ \portFile -> do
logbackArg <- getLogbackArg (damlSdkJarFolder </> "sandbox-logback.xml")
withJar damlSdkJar [logbackArg] (["sandbox", "--port", show port, "--port-file", portFile] ++ args) $ \ph -> do
let sandbox = if classic then "sandbox-classic" else "sandbox"
withJar damlSdkJar [logbackArg] ([sandbox, "--port", show port, "--port-file", portFile] ++ args) $ \ph -> do
putStrLn "Waiting for sandbox to start: "
_port <- readPortFile maxRetries portFile
a ph
Expand Down Expand Up @@ -807,6 +809,7 @@ newtype SandboxOptions = SandboxOptions [String]
newtype NavigatorOptions = NavigatorOptions [String]
newtype JsonApiOptions = JsonApiOptions [String]
newtype ScriptOptions = ScriptOptions [String]
newtype SandboxClassic = SandboxClassic { unSandboxClassic :: Bool }

withOptsFromProjectConfig :: T.Text -> [String] -> ProjectConfig -> IO [String]
withOptsFromProjectConfig fieldName cliOpts projectConfig = do
Expand All @@ -828,6 +831,7 @@ runStart
-> NavigatorOptions
-> JsonApiOptions
-> ScriptOptions
-> SandboxClassic
-> IO ()
runStart
sandboxPortM
Expand All @@ -840,6 +844,7 @@ runStart
(NavigatorOptions navigatorOpts)
(JsonApiOptions jsonApiOpts)
(ScriptOptions scriptOpts)
sandboxClassic
= withProjectRoot Nothing (ProjectCheck "daml start" True) $ \_ _ -> do
let sandboxPort = fromMaybe defaultSandboxPort sandboxPortM
projectConfig <- getProjectConfig
Expand All @@ -863,7 +868,7 @@ runStart
scriptOpts <- withOptsFromProjectConfig "script-options" scriptOpts projectConfig
doBuild
let scenarioArgs = maybe [] (\scenario -> ["--scenario", scenario]) mbScenario
withSandbox sandboxPort (darPath : scenarioArgs ++ sandboxOpts) $ \sandboxPh -> do
withSandbox sandboxClassic sandboxPort (darPath : scenarioArgs ++ sandboxOpts) $ \sandboxPh -> do
withNavigator' shouldStartNavigator sandboxPh sandboxPort navigatorPort navigatorOpts $ \navigatorPh -> do
whenJust mbInitScript $ \initScript -> do
procScript <- toAssistantCommand $
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import com.digitalasset.daml.lf.engine.trigger.{RunnerMain => Trigger}
import com.digitalasset.extractor.{Main => Extractor}
import com.digitalasset.http.{Main => JsonApi}
import com.digitalasset.navigator.{NavigatorBackend => Navigator}
import com.digitalasset.platform.sandbox.{SandboxMain => Sandbox}
import com.digitalasset.platform.sandboxnext.{Main => SandboxNext}
import com.digitalasset.platform.sandbox.{SandboxMain => SandboxClassic}
import com.digitalasset.platform.sandboxnext.{Main => Sandbox}

object SdkMain {
def main(args: Array[String]): Unit = {
Expand All @@ -25,7 +25,7 @@ object SdkMain {
case "json-api" => JsonApi.main(rest)
case "navigator" => Navigator.main(rest)
case "sandbox" => Sandbox.main(rest)
case "sandbox-next" => SandboxNext.main(rest)
case "sandbox-classic" => SandboxClassic.main(rest)
case _ => sys.exit(1)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,11 +337,11 @@ quickstartTests quickstartDir mvnDir = testGroup "quickstart"
(\s -> connect s (addrAddress addr))
-- waitForProcess' will block on Windows so we explicitly kill the process.
terminateProcess ph
, testCase "Sandbox Next startup" $
, testCase "Sandbox Classic startup" $
withCurrentDirectory quickstartDir $
withDevNull $ \devNull -> do
p :: Int <- fromIntegral <$> getFreePort
let sandboxProc = (shell $ unwords ["daml", "sandbox-next", "--wall-clock-time", "--port", show p, ".daml/dist/quickstart-0.0.1.dar"]) { std_out = UseHandle devNull, std_in = CreatePipe }
let sandboxProc = (shell $ unwords ["daml", "sandbox-classic", "--wall-clock-time", "--port", show p, ".daml/dist/quickstart-0.0.1.dar"]) { std_out = UseHandle devNull, std_in = CreatePipe }
withCreateProcess sandboxProc $
\_ _ _ ph -> race_ (waitForProcess' sandboxProc ph) $ do
waitForConnectionOnPort (threadDelay 100000) p
Expand Down Expand Up @@ -410,7 +410,7 @@ quickstartTests quickstartDir mvnDir = testGroup "quickstart"
withDevNull $ \devNull1 ->
withDevNull $ \devNull2 -> do
sandboxPort :: Int <- fromIntegral <$> getFreePort
let sandboxProc = (shell $ unwords ["daml", "sandbox", "--", "--port", show sandboxPort, "--", "--static-time", "--scenario", "Main:setup", ".daml/dist/quickstart-0.0.1.dar"]) { std_out = UseHandle devNull1, std_in = CreatePipe }
let sandboxProc = (shell $ unwords ["daml", "sandbox-classic", "--", "--port", show sandboxPort, "--", "--static-time", "--scenario", "Main:setup", ".daml/dist/quickstart-0.0.1.dar"]) { std_out = UseHandle devNull1, std_in = CreatePipe }
withCreateProcess sandboxProc $
\_ _ _ ph -> race_ (waitForProcess' sandboxProc ph) $ do
waitForConnectionOnPort (threadDelay 500000) sandboxPort
Expand Down
8 changes: 4 additions & 4 deletions release/sdk-config.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ commands:
completion: true
- name: sandbox
path: daml-helper/daml-helper
desc: "Launch the Sandbox"
desc: "Launch Sandbox"
args: ["run-jar", "--logback-config=daml-sdk/sandbox-logback.xml", "daml-sdk/daml-sdk.jar", "sandbox"]
- name: sandbox-next
- name: sandbox-classic
path: daml-helper/daml-helper
desc: "Launch the Sandbox's upcoming implementation (experimental, for testing purposes)"
args: ["run-jar", "--logback-config=daml-sdk/sandbox-logback.xml", "daml-sdk/daml-sdk.jar", "sandbox-next"]
desc: "Launch Sandbox Classic (the default Sandbox implementation for SDK <= 0.13.55)"
args: ["run-jar", "--logback-config=daml-sdk/sandbox-logback.xml", "daml-sdk/daml-sdk.jar", "sandbox-classic"]
- name: navigator
path: daml-helper/daml-helper
desc: "Launch the Navigator"
Expand Down

0 comments on commit dd8a3a3

Please sign in to comment.