Revision ad56f735
b/src/Ganeti/Rpc.hs | ||
---|---|---|
33 | 33 |
, ERpcError |
34 | 34 |
, explainRpcError |
35 | 35 |
, executeRpcCall |
36 |
, executeRpcCalls |
|
36 | 37 |
, logRpcErrors |
37 | 38 |
|
38 | 39 |
, rpcCallName |
... | ... | |
198 | 199 |
logError $ "Error in the RPC HTTP reply: " ++ show err |
199 | 200 |
in mapM_ logOneRpcErr allElems |
200 | 201 |
|
201 |
-- | Execute RPC call for many nodes in parallel. |
|
202 |
executeRpcCall :: (Rpc a b) => [Node] -> a -> IO [(Node, ERpcError b)] |
|
203 |
executeRpcCall nodes call = do |
|
202 |
-- | Get options for RPC call |
|
203 |
getOptionsForCall :: (Rpc a b) => FilePath -> a -> [CurlOption] |
|
204 |
getOptionsForCall certPath call = |
|
205 |
[ CurlTimeout (fromIntegral $ rpcCallTimeout call) |
|
206 |
, CurlSSLCert certPath |
|
207 |
, CurlSSLKey certPath |
|
208 |
, CurlCAInfo certPath |
|
209 |
] |
|
210 |
|
|
211 |
-- | Execute multiple RPC calls in parallel |
|
212 |
executeRpcCalls :: (Rpc a b) => [(Node, a)] -> IO [(Node, ERpcError b)] |
|
213 |
executeRpcCalls nodeCalls = do |
|
204 | 214 |
cert_file <- P.nodedCertFile |
205 |
let opts = [ CurlTimeout (fromIntegral $ rpcCallTimeout call) |
|
206 |
, CurlSSLCert cert_file |
|
207 |
, CurlSSLKey cert_file |
|
208 |
, CurlCAInfo cert_file |
|
209 |
] |
|
210 |
opts_urls = map (\n -> |
|
211 |
case prepareHttpRequest opts n call of |
|
215 |
let (nodes, calls) = unzip nodeCalls |
|
216 |
opts = map (getOptionsForCall cert_file) calls |
|
217 |
opts_urls = zipWith3 (\n c o -> |
|
218 |
case prepareHttpRequest o n c of |
|
212 | 219 |
Left v -> Left v |
213 | 220 |
Right request -> |
214 | 221 |
Right (CurlPostFields [requestData request]: |
215 | 222 |
requestOpts request, |
216 | 223 |
requestUrl request) |
217 |
) nodes
|
|
224 |
) nodes calls opts
|
|
218 | 225 |
-- split the opts_urls list; we don't want to pass the |
219 | 226 |
-- failed-already nodes to Curl |
220 | 227 |
let (lefts, rights, trail) = splitEithers opts_urls |
... | ... | |
223 | 230 |
Bad msg -> error msg |
224 | 231 |
Ok r -> return r |
225 | 232 |
-- now parse the replies |
226 |
let results'' = map (parseHttpReply call) results'
|
|
233 |
let results'' = zipWith parseHttpReply calls results'
|
|
227 | 234 |
pairedList = zip nodes results'' |
228 | 235 |
logRpcErrors pairedList |
229 | 236 |
return pairedList |
230 | 237 |
|
238 |
-- | Execute an RPC call for many nodes in parallel. |
|
239 |
executeRpcCall :: (Rpc a b) => [Node] -> a -> IO [(Node, ERpcError b)] |
|
240 |
executeRpcCall nodes call = executeRpcCalls . zip nodes $ repeat call |
|
241 |
|
|
231 | 242 |
-- | Helper function that is used to read dictionaries of values. |
232 | 243 |
sanitizeDictResults :: [(String, J.Result a)] -> ERpcError [(String, a)] |
233 | 244 |
sanitizeDictResults = |
Also available in: Unified diff