Revision 94d6d0a3
b/src/Ganeti/Query/Server.hs | ||
---|---|---|
34 | 34 |
import Control.Applicative |
35 | 35 |
import Control.Concurrent |
36 | 36 |
import Control.Exception |
37 |
import Control.Monad (forever, when) |
|
37 |
import Control.Monad (forever, when, zipWithM)
|
|
38 | 38 |
import Data.Bits (bitSize) |
39 | 39 |
import qualified Data.Set as Set (toList) |
40 | 40 |
import Data.IORef |
... | ... | |
221 | 221 |
then return . Bad . GenericError $ "Queue drained" |
222 | 222 |
else handleCall qlock cfg (SubmitJobToDrainedQueue ops) |
223 | 223 |
|
224 |
handleCall qlock cfg (SubmitManyJobs lops) = |
|
225 |
do |
|
226 |
open <- isQueueOpen |
|
227 |
if not open |
|
228 |
then return . Bad . GenericError $ "Queue drained" |
|
229 |
else do |
|
230 |
result_jobids <- allocateJobIds (Config.getMasterCandidates cfg) |
|
231 |
qlock (length lops) |
|
232 |
case result_jobids of |
|
233 |
Bad s -> return . Bad . GenericError $ s |
|
234 |
Ok jids -> do |
|
235 |
jobs <- zipWithM queuedJobFromOpCodes jids lops |
|
236 |
qDir <- queueDir |
|
237 |
write_results <- mapM (writeJobToDisk qDir) jobs |
|
238 |
let annotated_results = zip write_results jids |
|
239 |
succeeded = map snd $ filter (isOk . fst) annotated_results |
|
240 |
when (any isBad write_results) . logWarning |
|
241 |
$ "Writing some jobs failed " ++ show annotated_results |
|
242 |
socketpath <- defaultLuxiSocket |
|
243 |
client <- getClient socketpath |
|
244 |
pickupResults <- mapM (flip callMethod client . PickupJob) |
|
245 |
succeeded |
|
246 |
closeClient client |
|
247 |
when (any isBad pickupResults) |
|
248 |
. logWarning . (++) "Failed to notify maserd: " . show |
|
249 |
$ zip succeeded pickupResults |
|
250 |
return . Ok . JSArray |
|
251 |
. map (\(res, jid) -> |
|
252 |
if isOk res |
|
253 |
then showJSON (True, fromJobId jid) |
|
254 |
else showJSON (False, genericResult id (const "") res)) |
|
255 |
$ annotated_results |
|
256 |
|
|
224 | 257 |
handleCall _ _ op = |
225 | 258 |
return . Bad $ |
226 | 259 |
GenericError ("Luxi call '" ++ strOfOp op ++ "' not implemented") |
Also available in: Unified diff