git.iko.soy/distributed-process
on master help sign in
Make demo work on Azure

(use version of http-conduit merged with upstream master)

commit9ead3eff379660f216ccaf98885b66a579932dda authorEdsko de Vries <edsko@well-typed.com> dateMon 24 Sep 2012, 18:08 (14 years ago) parentf317db7
6 files changed+114−78
azure-service-api/azure-service-api.cabal+1−1 distributed-process-demos/distributed-process-demos.cabal+19−11 distributed-process-demos/src/MasterSlave.hs−66 distributed-process-demos/src/MasterSlave/Azure.hs+37 distributed-process-demos/src/MasterSlave/MasterSlave.hs+35 distributed-process-demos/src/MasterSlave/SimpleLocalnet.hs+22
azure-service-api/azure-service-api.cabal+1−1
@@ -18,7 +18,7 @@ Cabal-Version: >=1.8
1818Library
1919 Exposed-Modules: Network.Azure.ServiceManagement
2020 Build-Depends: base ==4.5.*,
21− http-conduit >= 1.5.1 && < 1.6,
21+ http-conduit >= 1.6.1 && < 1.7,
2222 tls >= 1.0 && < 1.1,
2323 tls-extra >= 0.5 && < 0.6,
2424 bytestring >= 0.9 && < 1.0,
distributed-process-demos/distributed-process-demos.cabal+19−11
@@ -17,16 +17,15 @@ cabal-version: >=1.8
1717
1818flag use-simplelocalnet
1919 description: Use the SimpleLocalnet backend
20− default: False
21− manual: True
20+ default: True
2221
2322flag use-azure
2423 description: Use the Azure backend
25− default: False
26− manual: True
24+ default: True
2725
28−executable distributed-process-masterslave
29− main-is: src/MasterSlave.hs
26+executable distributed-process-simplelocalnet-masterslave
27+ main-is: SimpleLocalnet.hs
28+ hs-source-dirs: src/MasterSlave
3029 build-depends: base ==4.5.*,
3130 distributed-process >= 0.3.2
3231 extensions: BangPatterns, CPP, TemplateHaskell
@@ -35,8 +34,17 @@ executable distributed-process-masterslave
3534 build-depends: distributed-process-simplelocalnet
3635 cpp-options: -DUSE_SIMPLELOCALNET
3736 else
38− if flag(use-azure)
39− build-depends: distributed-process-azure
40− cpp-options: -DUSE_AZURE
41− else
42− buildable: False
37+ buildable: False
38+
39+executable distributed-process-azure-masterslave
40+ main-is: Azure.hs
41+ hs-source-dirs: src/MasterSlave
42+ build-depends: base ==4.5.*,
43+ distributed-process >= 0.3.2
44+ extensions: BangPatterns, CPP, TemplateHaskell
45+ ghc-options: -Wall
46+ if flag(use-azure)
47+ build-depends: distributed-process-azure
48+ cpp-options: -DUSE_AZURE
49+ else
50+ buildable: False
distributed-process-demos/src/MasterSlave.hsdeleted−66
@@ -1,66 +0,0 @@
1−import System.Environment (getArgs)
2−import Control.Monad
3−import Control.Distributed.Process
4−import Control.Distributed.Process.Closure
5−
6−#ifdef USE_SIMPLELOCALNET
7−import Control.Distributed.Process.Node (initRemoteTable)
8−import Control.Distributed.Process.Backend.SimpleLocalnet
9−#endif
10−
11−--------------------------------------------------------------------------------
12−-- Backend agnostic code --
13−--------------------------------------------------------------------------------
14−
15−fib :: Integer -> Integer
16−fib = go (0, 1)
17− where
18− go (!a, !b) !n | n == 0 = a
19− | otherwise = go (b, a + b) (n - 1)
20−
21−slave :: () -> Process ()
22−slave () = forever $ do
23− (pid, n) <- expect
24− send pid (fib n)
25−
26−remotable ['slave]
27−
28−master :: Integer -> [NodeId] -> Process Integer
29−master n slaves = do
30− us <- getSelfPid
31−
32− -- Start processes on the slaves that compute Fibonacci numbers
33− slaveProcesses <- forM slaves $ flip spawn ($(mkClosure 'slave) ())
34−
35− -- Distribute 1 .. n amongst the slave processes
36− forM_ (zip [1 .. n] (cycle slaveProcesses)) $ \(m, them) ->
37− send them (us, m)
38−
39− -- Wait for the result
40− partials <- replicateM (fromInteger n) (expect :: Process Integer)
41−
42− -- And return the sum
43− return (sum partials)
44−
45−rtable :: RemoteTable
46−rtable = __remoteTable initRemoteTable
47−
48−--------------------------------------------------------------------------------
49−-- Using the SimpleLocalnet backend --
50−--------------------------------------------------------------------------------
51−
52−#ifdef USE_SIMPLELOCALNET
53−main :: IO ()
54−main = do
55− args <- getArgs
56−
57− case args of
58− ["master", host, port, n] -> do
59− backend <- initializeBackend host port rtable
60− startMaster backend $ \slaves -> do
61− result <- master (read n) slaves
62− liftIO $ print result
63− ["slave", host, port] -> do
64− backend <- initializeBackend host port rtable
65− startSlave backend
66−#endif -- USE_SIMPLELOCALNET
distributed-process-demos/src/MasterSlave/Azure.hsnew file+37
@@ -0,0 +1,37 @@
1+import System.Environment (getArgs)
2+import Control.Monad
3+import Control.Distributed.Process
4+import Control.Distributed.Process.Closure
5+import Control.Distributed.Process.Backend.Azure
6+import qualified MasterSlave
7+
8+azureMaster :: ([NodeId], Integer) -> Backend -> Process ()
9+azureMaster (slaves, n) _backend = do
10+ result <- MasterSlave.master n slaves
11+ mapM_ terminateNode slaves
12+ remoteSend result
13+
14+remotable ['azureMaster]
15+
16+printResult :: LocalProcess ()
17+printResult = do
18+ result <- localExpect :: LocalProcess Integer
19+ liftIO $ print result
20+
21+main :: IO ()
22+main = do
23+ args <- getArgs
24+ case args of
25+ "onvm":args' -> onVmMain (__remoteTable . MasterSlave.__remoteTable) args'
26+ [sid, x509, pkey, user, cloudService, n] -> do
27+ params <- defaultAzureParameters sid x509 pkey
28+ let params' = params { azureSshUserName = user }
29+ backend <- initializeBackend params' cloudService
30+ vms <- findVMs backend
31+ print vms
32+ nids <- forM vms $ \vm -> spawnNodeOnVM backend vm "8080"
33+ callOnVM backend (head vms) "8081" $
34+ ProcessPair ($(mkClosure 'azureMaster) (nids, read n :: Integer))
35+ printResult
36+ _ ->
37+ error "Invalid command line arguments"
distributed-process-demos/src/MasterSlave/MasterSlave.hsnew file+35
@@ -0,0 +1,35 @@
1+module MasterSlave where
2+
3+import Control.Monad
4+import Control.Distributed.Process
5+import Control.Distributed.Process.Closure
6+
7+fib :: Integer -> Integer
8+fib = go (0, 1)
9+ where
10+ go (!a, !b) !n | n == 0 = a
11+ | otherwise = go (b, a + b) (n - 1)
12+
13+slave :: () -> Process ()
14+slave () = forever $ do
15+ (pid, n) <- expect
16+ send pid (fib n)
17+
18+remotable ['slave]
19+
20+master :: Integer -> [NodeId] -> Process Integer
21+master n slaves = do
22+ us <- getSelfPid
23+
24+ -- Start processes on the slaves that compute Fibonacci numbers
25+ slaveProcesses <- forM slaves $ flip spawn ($(mkClosure 'slave) ())
26+
27+ -- Distribute 1 .. n amongst the slave processes
28+ forM_ (zip [1 .. n] (cycle slaveProcesses)) $ \(m, them) ->
29+ send them (us, m)
30+
31+ -- Wait for the result
32+ partials <- replicateM (fromInteger n) (expect :: Process Integer)
33+
34+ -- And return the sum
35+ return (sum partials)
distributed-process-demos/src/MasterSlave/SimpleLocalnet.hsnew file+22
@@ -0,0 +1,22 @@
1+import System.Environment (getArgs)
2+import Control.Distributed.Process
3+import Control.Distributed.Process.Node (initRemoteTable)
4+import Control.Distributed.Process.Backend.SimpleLocalnet
5+import qualified MasterSlave
6+
7+rtable :: RemoteTable
8+rtable = MasterSlave.__remoteTable initRemoteTable
9+
10+main :: IO ()
11+main = do
12+ args <- getArgs
13+
14+ case args of
15+ ["master", host, port, n] -> do
16+ backend <- initializeBackend host port rtable
17+ startMaster backend $ \slaves -> do
18+ result <- MasterSlave.master (read n) slaves
19+ liftIO $ print result
20+ ["slave", host, port] -> do
21+ backend <- initializeBackend host port rtable
22+ startSlave backend