@@ -13,23 +13,19 @@ import System.IO
13 , hSetBinaryMode
13 , hSetBinaryMode
15import Data.Binary (decode)
15import Data.Binary (decode)
16−import qualified Data.ByteString.Lazy as BSL (ByteString, getContents)
16+import qualified Data.ByteString.Lazy as BSL (ByteString, getContents, length)
17import Control.Monad (unless, forM, forM_, join)
17import Control.Monad (unless, forM, forM_, join)
18−import Control.Exception (throwIO)
18+import Control.Exception (throwIO, SomeException)
19−import Control.Distributed.Process.Backend.Azure
19+import Control.Applicative ((<$>), (<*>), (<|>))
20− ( AzureParameters(azureSshUserName)
20+import Control.Monad.IO.Class (liftIO)
21− , defaultAzureParameters
21+
22− , initializeBackend
22+-- SSH
24− , CloudService(cloudServiceName, cloudServiceVMs)
25− , VirtualMachine(vmName)
26− , Backend(copyToVM, checkMD5, callOnVM)
28import qualified Network.SSH.Client.LibSSH2.Foreign as SSH
23import qualified Network.SSH.Client.LibSSH2.Foreign as SSH
29 ( initialize
24 ( initialize
32−import Control.Applicative ((<$>), (<*>), (<|>))
27+
28+-- Command line options
33import Options.Applicative
29import Options.Applicative
35 , strOption
31 , strOption
@@ -47,17 +43,30 @@ import Options.Applicative
50import Control.Distributed.Process
48import Control.Distributed.Process
51 ( RemoteTable
49 ( RemoteTable
54 , unClosure
52 , unClosure
57import Control.Distributed.Process.Node (newLocalNode, runProcess, initRemoteTable)
56import Control.Distributed.Process.Node (newLocalNode, runProcess, initRemoteTable)
58import Control.Distributed.Process.Serializable (Serializable)
57import Control.Distributed.Process.Serializable (Serializable)
59import Control.Distributed.Process.Closure (SerializableDict)
58import Control.Distributed.Process.Closure (SerializableDict)
60import Network.Transport.TCP (createTransport, defaultTCPParameters)
59import Network.Transport.TCP (createTransport, defaultTCPParameters)
60+import Control.Distributed.Process.Backend.Azure
61+ ( AzureParameters(azureSshUserName)
62+ , defaultAzureParameters
65+ , CloudService(cloudServiceName, cloudServiceVMs)
66+ , VirtualMachine(vmName)
67+ , Backend(copyToVM, checkMD5, callOnVM)
69+import qualified Control.Distributed.Process.Backend.Azure as Azure (remoteTable)
62--------------------------------------------------------------------------------
71--------------------------------------------------------------------------------
63-- Main --
72-- Main --
@@ -112,7 +121,9 @@ genericMain remoteTable cmds = do
112 ProcessPair rProc lProc dict ->
121 ProcessPair rProc lProc dict ->
113 callOnVM backend dict vm (remotePort cmd) rProc >>= lProc
122 callOnVM backend dict vm (remotePort cmd) rProc >>= lProc
114 OnVmCommand (vmCmd@OnVmRun {}) -> do
123 OnVmCommand (vmCmd@OnVmRun {}) -> do
115− onVmRun (remoteTable initRemoteTable) (onVmIP vmCmd) (onVmPort vmCmd)
124+ onVmRun (remoteTable . Azure.remoteTable $ initRemoteTable)
118 opts = info (helper <*> commandParser)
129 opts = info (helper <*> commandParser)
@@ -144,13 +155,16 @@ azureParameters opts (Just sshOpts) = do
144onVmRun :: RemoteTable -> String -> String -> IO ()
155onVmRun :: RemoteTable -> String -> String -> IO ()
145onVmRun rtable host port = do
156onVmRun rtable host port = do
146 hSetBinaryMode stdin True
157 hSetBinaryMode stdin True
158+ hSetBinaryMode stdout True
147 proc <- BSL.getContents :: IO BSL.ByteString
159 proc <- BSL.getContents :: IO BSL.ByteString
148 mTransport <- createTransport host port defaultTCPParameters
160 mTransport <- createTransport host port defaultTCPParameters
149 case mTransport of
161 case mTransport of
150 Left err -> throwIO err
162 Left err -> throwIO err
151 Right transport -> do
163 Right transport -> do
152 node <- newLocalNode transport rtable
164 node <- newLocalNode transport rtable
153− runProcess node $ join . unClosure . decode $ proc
166+ catch (join . unClosure . decode $ proc)
167+ (\e -> liftIO (print (e :: SomeException) >> throwIO e))
155--------------------------------------------------------------------------------
169--------------------------------------------------------------------------------
156-- Command line options --
170-- Command line options --