Received: by 10.216.239.205 with SMTP id c55mr419860wer.12.1349403491413; Thu, 04 Oct 2012 19:18:11 -0700 (PDT) X-BeenThere: ganeti-devel@googlegroups.com Received: by 10.180.20.136 with SMTP id n8ls9032272wie.3.gmail; Thu, 04 Oct 2012 19:18:11 -0700 (PDT) Received: by 10.216.193.131 with SMTP id k3mr420904wen.4.1349403490983; Thu, 04 Oct 2012 19:18:10 -0700 (PDT) Received: by 10.216.193.131 with SMTP id k3mr420903wen.4.1349403490963; Thu, 04 Oct 2012 19:18:10 -0700 (PDT) Return-Path: Received: from mail-wg0-f48.google.com (mail-wg0-f48.google.com [74.125.82.48]) by gmr-mx.google.com with ESMTPS id fb20si1903674wid.3.2012.10.04.19.18.10 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 04 Oct 2012 19:18:10 -0700 (PDT) Received-SPF: pass (google.com: domain of ius...@google.com designates 74.125.82.48 as permitted sender) client-ip=74.125.82.48; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of ius...@google.com designates 74.125.82.48 as permitted sender) smtp.mail=ius...@google.com; dkim=pass header...@google.com Received: by mail-wg0-f48.google.com with SMTP id ds1so793535wgb.17 for ; Thu, 04 Oct 2012 19:18:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=vASTDlDvpcVRI65UhgitAOsV6JXnHCnEAtfuwFP4FDI=; b=GG2FhAFzekTT+e7Z/R3SfpjPAu51RLSaiBOcB/0q3FRhqU9rjLqKQYsZiGvTfNUvAY wi9fx2hrHf9KwGH70i4gM1FFt9GdOpFKdG5VN2W8dzjzF76ncrHmD7BT2n/vV+7hrK11 SWqeHmipONr6PsXZW+j0622NMUNhQmrAhRv7CCipRyRVmMBUvctIHLAJBrTh8s5ZVfO/ CtDIaPNpIN+dZMKHoCXDVzsbUQw1f7+d9wjhXola3bVhQGcMYOBDXTqrZbS7fw6p7yGN dDJ0ZeTK6PjLSU7Q/gop+5fitzmPHUPEQ6SJ/t7pGN4E9E9527DLhxGJKfNsMj3hukxs 7Dkg== d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=vASTDlDvpcVRI65UhgitAOsV6JXnHCnEAtfuwFP4FDI=; b=UWSBqKLEO2D6JKyXL/7vrjijEqIaFjKFJw57dZnCBxZDOrS5BK6IDZRt0NvMQdvXoQ EdH09zB9oTTezeRJNJmo4e5asGCu4SdASGIwnJV5btG8pqRayuIn6wfJEm+M0dlSZEqL 28WRq5muWSj+HUV1o36J50OA3/lQMMp0DufIuaSgiHRmY6YipEpUWJwGE6y91l8zXU3R A/YUZxfpnnH0a/8UiSbndr+sA61lJ1+/yFdR+wDahh9uQ8ackbuu3wPkw2BgAT2l2FfU KkiyAqISz5gRe7uv0thd8VD7H7alArYwjhr+Ley+6/s8hgW2ILP1j3SU151Hp7yn7VBX 1tBA== Received: by 10.216.195.100 with SMTP id o78mr4677103wen.182.1349403489872; Thu, 04 Oct 2012 19:18:09 -0700 (PDT) Return-Path: Received: from epi.example.org (mail.impact-dtg.com. [195.99.145.2]) by mx.google.com with ESMTPS id b3sm3384451wie.0.2012.10.04.19.18.08 (version=SSLv3 cipher=OTHER); Thu, 04 Oct 2012 19:18:09 -0700 (PDT) From: Iustin Pop To: ganeti-devel@googlegroups.com Cc: Iustin Pop Subject: [PATCH master 09/23] Use the new name filtering behaviour in query Date: Fri, 5 Oct 2012 03:17:38 +0100 Message-Id: <6a5f67242286cad6659b73180b637db40fa5a322.1349403142.git.ius...@google.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: References: X-Gm-Message-State: ALoCoQkKh3oAwwtLmrFJcOUzXpTigX/VfJREM+6c5M2ElWFmwtfhWfgVZ3bjvmj45jihaDLVyqDwW9NjHV7pspEKz5GQ8c3D9qYVBEGP97J7mAakN65HKQ/i9OaBXrbP6BEDpVk7PdFJhXwrd+DCsdel3ddUEpLm21mbq2Z/AY33mNl9qnqUdSmna2EnC3pWCWcapwt+XAOLIHFVmt/IQxkTU1ExVnjwnZDTiqkJfSYosQ9fH97WoOM= We do this not quite generically, which means we have to add another layer in the call chain, and rename the current query function, plus add special-case code for each query type. Hopefully we will be able to improve on this in the future. A (good) side effect of this patch is that we get the desired ordering when names are requested, matching the Python code. Signed-off-by: Iustin Pop --- htools/Ganeti/Query/Query.hs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/htools/Ganeti/Query/Query.hs b/htools/Ganeti/Query/Query.hs index a17a920..875e870 100644 --- a/htools/Ganeti/Query/Query.hs +++ b/htools/Ganeti/Query/Query.hs @@ -57,6 +57,7 @@ import Data.Maybe (fromMaybe) import qualified Data.Map as Map import Ganeti.BasicTypes +import Ganeti.Config import Ganeti.JSON import Ganeti.Rpc import Ganeti.Query.Language @@ -66,6 +67,7 @@ import Ganeti.Query.Types import Ganeti.Query.Node import Ganeti.Query.Group import Ganeti.Objects +import Ganeti.Utils -- * Helper functions @@ -146,13 +148,23 @@ query :: ConfigData -- ^ The current configuration -> Bool -- ^ Whether to collect live data -> Query -- ^ The query (item, fields, filter) -> IO (Result QueryResult) -- ^ Result +query cfg live qry = queryInner cfg live qry $ getRequestedNames qry -query cfg live (Query QRNode fields qfilter) = runResultT $ do +-- | Inner query execution function. +queryInner :: ConfigData -- ^ The current configuration + -> Bool -- ^ Whether to collect live data + -> Query -- ^ The query (item, fields, filter) + -> [String] -- ^ Requested names + -> IO (Result QueryResult) -- ^ Result + +queryInner cfg live (Query QRNode fields qfilter) wanted = runResultT $ do cfilter <- resultT $ compileFilter nodeFieldsMap qfilter let selected = getSelectedFields nodeFieldsMap fields (fdefs, fgetters) = unzip selected - nodes = Map.elems . fromContainer $ configNodes cfg live' = live && needsLiveData fgetters + nodes <- resultT $ case wanted of + [] -> Ok . Map.elems . fromContainer $ configNodes cfg + _ -> mapM (getNode cfg) wanted -- runs first pass of the filter, without a runtime context; this -- will limit the nodes that we'll contact for runtime data fnodes <- resultT $ filterM (\n -> evaluateFilter cfg Nothing n cfilter) nodes @@ -163,21 +175,23 @@ query cfg live (Query QRNode fields qfilter) = runResultT $ do nruntimes return QueryResult { qresFields = fdefs, qresData = fdata } -query cfg _ (Query QRGroup fields qfilter) = return $ do +queryInner cfg _ (Query QRGroup fields qfilter) wanted = return $ do -- FIXME: want_diskparams is defaulted to false and not taken as parameter -- This is because the type for DiskParams is right now too generic for merges -- (or else I cannot see how to do this with curent implementation) cfilter <- compileFilter groupFieldsMap qfilter let selected = getSelectedFields groupFieldsMap fields (fdefs, fgetters) = unzip selected - groups = Map.elems . fromContainer $ configNodegroups cfg + groups <- case wanted of + [] -> Ok . Map.elems . fromContainer $ configNodegroups cfg + _ -> mapM (getGroup cfg) wanted -- there is no live data for groups, so filtering is much simpler fgroups <- filterM (\n -> evaluateFilter cfg Nothing n cfilter) groups let fdata = map (\node -> map (execGetter cfg GroupRuntime node) fgetters) fgroups return QueryResult {qresFields = fdefs, qresData = fdata } -query _ _ (Query qkind _ _) = +queryInner _ _ (Query qkind _ _) _ = return . Bad $ "Query '" ++ show qkind ++ "' not supported" -- | Query fields call. -- 1.7.10.4