[Pkg-ganeti-devel] [ganeti] 27/165: Add a function computing the lost-allocations metric
Apollon Oikonomopoulos
apoikos at moszumanska.debian.org
Tue Aug 11 13:53:10 UTC 2015
This is an automated email from the git hooks/post-receive script.
apoikos pushed a commit to branch master
in repository ganeti.
commit fc23345aee1e21f5fe763f98c8357c8a746e17b1
Author: Klaus Aehlig <aehlig at google.com>
Date: Fri Jan 23 17:38:30 2015 +0100
Add a function computing the lost-allocations metric
This is the difference between the allocation vector before and after
the instance is placed on the node, and the remaining disk space as
a tie breaker. Note that the natural order on ([Int], Int) is the order
of the lost-allocations metric.
As it might not be possible to place the instance on the node at all,
the metric is wrapped in an OpResult.
Signed-off-by: Klaus Aehlig <aehlig at google.com>
Reviewed-by: Petr Pudlak <pudlak at google.com>
---
src/Ganeti/HTools/Dedicated.hs | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/Ganeti/HTools/Dedicated.hs b/src/Ganeti/HTools/Dedicated.hs
index d42f880..5b1e2e8 100644
--- a/src/Ganeti/HTools/Dedicated.hs
+++ b/src/Ganeti/HTools/Dedicated.hs
@@ -36,6 +36,8 @@ module Ganeti.HTools.Dedicated
( isDedicated
, testInstances
, allocationVector
+ , Metric
+ , lostAllocationsMetric
) where
import Control.Applicative (liftA2)
@@ -95,3 +97,23 @@ allocationVector :: [Instance.Instance] -> Node.Node -> [Int]
allocationVector insts node =
map (\ inst -> length $ iterateOk (`Node.addPri` inst) node) insts
+-- | The metric do be used in dedicated allocation.
+type Metric = ([Int], Int)
+
+-- | Given the test instances and an instance to be placed, compute
+-- the lost allocations metrics for that node, together with the
+-- modified node. Return Bad if it is not possible to place the
+-- instance on that node.
+lostAllocationsMetric :: Alg.AlgorithmOptions
+ -> [Instance.Instance]
+ -> Instance.Instance
+ -> Node.Node
+ -> T.OpResult (Metric, Node.Node)
+lostAllocationsMetric opts insts inst node = do
+ let allocVec = allocationVector insts
+ before = allocVec node
+ force = Alg.algIgnoreSoftErrors opts
+ node' <- Node.addPriEx force node inst
+ let after = allocVec node'
+ disk = Node.fDsk node'
+ return ((zipWith (-) before after, disk), node')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ganeti/ganeti.git
More information about the Pkg-ganeti-devel
mailing list