git.iko.soy/distributed-process
on master help sign in
Improve docs
3b8e9f4Edsko de Vries
distributed-process-azure/src/Control/Distributed/Process/Backend/Azure.hs+43−7
@@ -177,10 +177,11 @@
177--
177--
178-- [First Example: Echo]
178-- [First Example: Echo]
179--
179--
180+-- When we run the @cloud-haskell-azure-echo@ demo on our local machine, it
180−-- The @echo@ demo starts a new Cloud Haskell node, waits for input from the
181+-- starts a new Cloud Haskell node on the specified remote virtual machine. It
181−-- user on the local machine, sends this to the remote machine. The remote
182+-- then repeatedly waits for input from the user on the local machine, sends
182−-- machine will echo this back; the local machine will wait for the echo, show
183+-- this to the remote virtual machine which will echo it back, and wait for and
183−-- the echo, and repeat.
184+-- show the echo.
184--
185--
185-- Before you can try it you will first need to copy the executable (for
186-- Before you can try it you will first need to copy the executable (for
186-- example, using scp, although the Azure backend also provides this natively
187-- example, using scp, although the Azure backend also provides this natively
@@ -233,16 +234,35 @@
233-- > main = do
234-- > main = do
234-- > args <- getArgs
235-- > args <- getArgs
235-- > case args of
236-- > case args of
237+-- > "onvm":args' ->
238+-- > -- Pass execution to 'onVmMain' if we are running on the VM
239+-- > -- ('callOnVM' will provide the right arguments)
236−-- > "onvm":args' -> onVmMain __remoteTable args'
240+-- > onVmMain __remoteTable args'
241+-- >
237-- > sid:x509:pkey:user:cloudService:virtualMachine:port:_ -> do
242-- > sid:x509:pkey:user:cloudService:virtualMachine:port:_ -> do
243+-- > -- Initialize the Azure backend
238-- > params <- defaultAzureParameters sid x509 pkey
244-- > params <- defaultAzureParameters sid x509 pkey
239-- > let params' = params { azureSshUserName = user }
245-- > let params' = params { azureSshUserName = user }
240-- > backend <- initializeBackend params' cloudService
246-- > backend <- initializeBackend params' cloudService
247+-- >
248+-- > -- Find the specified virtual machine
241-- > Just vm <- findNamedVM backend virtualMachine
249-- > Just vm <- findNamedVM backend virtualMachine
250+-- >
251+-- > -- Run the echo client proper
242-- > callOnVM backend vm port $
252-- > callOnVM backend vm port $
243-- > ProcessPair ($(mkClosure 'echoRemote) ())
253-- > ProcessPair ($(mkClosure 'echoRemote) ())
244-- > echoLocal
254-- > echoLocal
245--
255--
256+-- The most important part of this code is the last three lines
257+--
258+-- > callOnVM backend vm port $
259+-- > ProcessPair ($(mkClosure 'echoRemote) ())
260+-- > echoLocal
261+--
262+-- 'callOnVM' creats a new Cloud Haskell node on the specified virtual machine,
263+-- then runs @echoRemote@ on the remote machine and @echoLocal@ on the local
264+-- machine.
265+--
246-- [Second Example: Ping]
266-- [Second Example: Ping]
247--
267--
248-- The second example differs from the @echo@ demo in that it uses both
268-- The second example differs from the @echo@ demo in that it uses both
@@ -263,7 +283,13 @@
263-- > <<virtual machine name>> \
283-- > <<virtual machine name>> \
264-- > <<port number>>
284-- > <<port number>>
265--
285--
286+-- As before, when we execute this on our local machine, it starts a new Cloud
287+-- Haskell node on the specified remote virtual machine and then executes the
288+-- ping server. Unlike with the echo example, however, this command will
289+-- terminate once the Cloud Haskell node has been set up, leaving the ping
290+-- server running in the background.
291+--
266−-- Finally, we can run the ping client:
292+-- Once the ping server is running we can run the ping client:
267--
293--
268-- > cloud-haskell-azure-ping client \
294-- > cloud-haskell-azure-ping client \
269-- > <<subscription ID>> \
295-- > <<subscription ID>> \
@@ -339,16 +365,26 @@
339-- > main = do
365-- > main = do
340-- > args <- getArgs
366-- > args <- getArgs
341-- > case args of
367-- > case args of
368+-- > "onvm":args' ->
369+-- > -- Pass execution to 'onVmMain' if we are running on the VM
342−-- > "onvm":args' -> onVmMain __remoteTable args'
370+-- > onVmMain __remoteTable args'
371+-- >
343-- > "list":sid:x509:pkey:_ -> do
372-- > "list":sid:x509:pkey:_ -> do
373+-- > -- List all available cloud services
374+-- > -- (useful, but not strictly necessary for the example)
344-- > params <- defaultAzureParameters sid x509 pkey
375-- > params <- defaultAzureParameters sid x509 pkey
345-- > css <- cloudServices (azureSetup params)
376-- > css <- cloudServices (azureSetup params)
346-- > mapM_ print css
377-- > mapM_ print css
378+-- >
347-- > cmd:sid:x509:pkey:user:cloudService:virtualMachine:port:_ -> do
379-- > cmd:sid:x509:pkey:user:cloudService:virtualMachine:port:_ -> do
380+-- > -- Initialize the backend and find the right VM
348-- > params <- defaultAzureParameters sid x509 pkey
381-- > params <- defaultAzureParameters sid x509 pkey
349-- > let params' = params { azureSshUserName = user }
382-- > let params' = params { azureSshUserName = user }
350-- > backend <- initializeBackend params' cloudService
383-- > backend <- initializeBackend params' cloudService
351-- > Just vm <- findNamedVM backend virtualMachine
384-- > Just vm <- findNamedVM backend virtualMachine
385+-- >
386+-- > -- The same binary can behave as the client or the server,
387+-- > -- depending on the command line arguments
352-- > case cmd of
388-- > case cmd of
353-- > "server" -> spawnOnVM backend vm port ($(mkClosure 'pingServer) ())
389-- > "server" -> spawnOnVM backend vm port ($(mkClosure 'pingServer) ())
354-- > "client" -> callOnVM backend vm port $
390-- > "client" -> callOnVM backend vm port $