Commit 659d769d authored by Dato Simó's avatar Dato Simó
Browse files

Merge branch 'devel-2.6' into master

* devel-2.6:
  htools-excl.test: add test case for exclusion tags in hbal
  Instance.hs: rename 'tags' to 'exclTags', provide 'allTags'
  Group.hs: add 'allTags'; adjust loaders and test data for it
  Add hbal-excl-tags.data to Makefile.am, missed in 0397694e



Conflicts:
	Makefile.am: hbal-excl-tags.data moved under htest/
	htools/Ganeti/HTools/Luxi.hs: types from Qlang are now used
	htools/Ganeti/HTools/QC.hs: defGroup definition now in TestHTools.hs
	lib/cmdlib.py: IAllocator class now in iallocator.py
	test/htools-excl.test: moved under htest/
Signed-off-by: default avatarDato Simó <dato@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parents 18ccdced b898de8f
......@@ -795,6 +795,7 @@ TEST_FILES = \
htest/data/hail-invalid-reloc.json \
htest/data/hail-node-evac.json \
htest/data/hail-reloc-drbd.json \
htest/data/hbal-excl-tags.data \
htest/data/hbal-split-insts.data \
htest/data/invalid-node.data \
htest/data/missing-resources.data \
......
......@@ -76,7 +76,7 @@ nullIPolicy = Types.IPolicy
defGroup :: Group.Group
defGroup = flip Group.setIdx 0 $
Group.create "default" Types.defaultGroupID Types.AllocPreferred
nullIPolicy
nullIPolicy []
defGroupList :: Group.List
defGroupList = Container.fromList [(Group.idx defGroup, defGroup)]
......
default|fake-uuid-01|preferred
default|fake-uuid-01|preferred|
node1.example.com|1024|0|1024|95367|95367|4|N|fake-uuid-01|1
node2.example.com|1024|0|896|95367|94343|4|N|fake-uuid-01|1
......
......@@ -43,6 +43,7 @@
"spindle-ratio": 32.0
},
"alloc_policy": "preferred",
"tags": [],
"name": "default"
}
},
......
......@@ -43,6 +43,7 @@
"spindle-ratio": 32.0
},
"alloc_policy": "preferred",
"tags": [],
"name": "default"
},
"uuid-group-2": {
......@@ -84,6 +85,7 @@
"spindle-ratio": 32.0
},
"alloc_policy": "preferred",
"tags": [],
"name": "empty"
}
},
......
......@@ -43,6 +43,7 @@
"spindle-ratio": 32.0
},
"alloc_policy": "preferred",
"tags": [],
"name": "default"
}
},
......
......@@ -43,6 +43,7 @@
"spindle-ratio": 32.0
},
"alloc_policy": "preferred",
"tags": [],
"name": "default"
}
},
......
group-01|fake-uuid-01|preferred|
node-01|16384|0|14336|409600|153600|16|N|fake-uuid-01|1
node-02|16384|0|13312|409600|153600|16|N|fake-uuid-01|1
dns1|1024|51200|1|running|Y|node-01|node-02|drbd|service-group:dns,foo|1
dns2|1024|51200|1|running|Y|node-01|node-02|drbd|service-group:dns,foo|1
ftp1|1024|51200|1|running|Y|node-02|node-01|drbd|test:ftp,bar|1
ftp2|1024|51200|1|running|Y|node-02|node-01|drbd|test:ftp,bar|1
admin|1024|51200|1|running|Y|node-02|node-01|drbd|foo|1
htools:iextags:service-group
group-01|fake-uuid-01|preferred
group-02|fake-uuid-02|preferred
group-01|fake-uuid-01|preferred|
group-02|fake-uuid-02|preferred|
node-01-001|98304|0|96256|8388608|8355840|16|N|fake-uuid-01|1
node-01-002|98304|0|96256|8388608|8355840|16|N|fake-uuid-01|1
......
group-01|fake-uuid-01|preferred
group-01|fake-uuid-01|preferred|
node-01-001|1024|0|1024|95367|95367|4|N|fake-uuid-01|1
node-01-002|1024|0|896|95367|94343|4|N|fake-uuid-01|1
......
default|fake-uuid-01|preferred
default|fake-uuid-01|preferred|
node1|1024|0|1024|95367|95367|4|N|fake-uuid-01|1
node2|1024|0|0|95367|0|4|N|fake-uuid-01|1
......
......@@ -8,3 +8,8 @@
./htest/hbal $BACKEND_EXCL --exclude-instances new-0 --select-instances new-1
>>>= 0
# Test exclusion tags too (both from the command line and cluster tags).
./htest/hbal -t $TESTDATA_DIR/hbal-excl-tags.data --exclusion-tags test
>>> /Cluster score improved/
>>>= 0
......@@ -46,6 +46,7 @@ data Group = Group
, idx :: T.Gdx -- ^ Internal index for book-keeping
, allocPolicy :: T.AllocPolicy -- ^ The allocation policy for this group
, iPolicy :: T.IPolicy -- ^ The instance policy for this group
, allTags :: [String] -- ^ The tags for this group
} deriving (Show, Read, Eq)
-- Note: we use the name as the alias, and the UUID as the official
......@@ -66,12 +67,13 @@ type List = Container.Container Group
-- * Initialization functions
-- | Create a new group.
create :: String -> T.GroupID -> T.AllocPolicy -> T.IPolicy -> Group
create name_init id_init apol_init ipol_init =
create :: String -> T.GroupID -> T.AllocPolicy -> T.IPolicy -> [String] -> Group
create name_init id_init apol_init ipol_init tags_init =
Group { name = name_init
, uuid = id_init
, allocPolicy = apol_init
, iPolicy = ipol_init
, allTags = tags_init
, idx = -1
}
......
......@@ -131,7 +131,8 @@ parseGroup u a = do
name <- extract "name"
apol <- extract "alloc_policy"
ipol <- extract "ipolicy"
return (u, Group.create name u apol ipol)
tags <- extract "tags"
return (u, Group.create name u apol ipol tags)
-- | Top-level parser.
--
......
......@@ -79,9 +79,10 @@ data Instance = Instance
, util :: T.DynUtil -- ^ Dynamic resource usage
, movable :: Bool -- ^ Can and should the instance be moved?
, autoBalance :: Bool -- ^ Is the instance auto-balanced?
, tags :: [String] -- ^ List of instance tags
, diskTemplate :: T.DiskTemplate -- ^ The disk template of the instance
, spindleUse :: Int -- ^ The numbers of used spindles
, allTags :: [String] -- ^ List of all instance tags
, exclTags :: [String] -- ^ List of instance exclusion tags
} deriving (Show, Read, Eq)
instance T.Element Instance where
......@@ -174,11 +175,12 @@ create name_init mem_init dsk_init vcpus_init run_init tags_init
, sNode = sn
, idx = -1
, util = T.baseUtil
, tags = tags_init
, movable = supportsMoves dt
, autoBalance = auto_balance_init
, diskTemplate = dt
, spindleUse = su
, allTags = tags_init
, exclTags = []
}
-- | Changes the index.
......
......@@ -148,12 +148,12 @@ setNodePolicy gl node =
gpol = Group.iPolicy grp
in Node.setPolicy gpol node
-- | Remove non-selected tags from the exclusion list.
filterExTags :: [String] -> Instance.Instance -> Instance.Instance
filterExTags tl inst =
let old_tags = Instance.tags inst
new_tags = filter (\tag -> any (`isPrefixOf` tag) tl) old_tags
in inst { Instance.tags = new_tags }
-- | Update instance with exclusion tags list.
updateExclTags :: [String] -> Instance.Instance -> Instance.Instance
updateExclTags tl inst =
let allTags = Instance.allTags inst
exclTags = filter (\tag -> any (`isPrefixOf` tag) tl) allTags
in inst { Instance.exclTags = exclTags }
-- | Update the movable attribute.
updateMovable :: [String] -- ^ Selected instances (if not empty)
......@@ -223,7 +223,7 @@ mergeData um extags selinsts exinsts cdata@(ClusterData gl nl il2 tags _) =
node_names = map Node.name (Container.elems nl)
common_suffix = longestDomain (node_names ++ inst_names)
il4 = Container.map (computeAlias common_suffix .
filterExTags allextags .
updateExclTags allextags .
updateMovable selinst_names exinst_names) il3
nl2 = foldl' fixNodes nl (Container.elems il4)
nl3 = Container.map (setNodePolicy gl .
......
......@@ -118,7 +118,7 @@ queryClusterInfoMsg = L.QueryClusterInfo
-- | The input data for node group query.
queryGroupsMsg :: L.LuxiOp
queryGroupsMsg =
L.Query Qlang.QRGroup ["uuid", "name", "alloc_policy", "ipolicy"]
L.Query Qlang.QRGroup ["uuid", "name", "alloc_policy", "ipolicy", "tags"]
Qlang.EmptyFilter
-- | Wraper over 'callMethod' doing node query.
......@@ -221,13 +221,14 @@ getGroups jsv = extractArray jsv >>= mapM parseGroup
-- | Parses a given group information.
parseGroup :: [(JSValue, JSValue)] -> Result (String, Group.Group)
parseGroup [uuid, name, apol, ipol] = do
parseGroup [uuid, name, apol, ipol, tags] = do
xname <- annotateResult "Parsing new group" (fromJValWithStatus name)
let convert a = genericConvert "Group" xname a
xuuid <- convert "uuid" uuid
xapol <- convert "alloc_policy" apol
xipol <- convert "ipolicy" ipol
return (xuuid, Group.create xname xuuid xapol xipol)
xtags <- convert "tags" tags
return (xuuid, Group.create xname xuuid xapol xipol xtags)
parseGroup v = fail ("Invalid group query result: " ++ show v)
......
......@@ -126,7 +126,7 @@ data Node = Node
-- computations
, utilPool :: T.DynUtil -- ^ Total utilisation capacity
, utilLoad :: T.DynUtil -- ^ Sum of instance utilisation
, pTags :: TagMap -- ^ Map of primary instance tags and their count
, pTags :: TagMap -- ^ Primary instance exclusion tags and their count
, group :: T.Gdx -- ^ The node's group (index)
, iPolicy :: T.IPolicy -- ^ The instance policy (of the node's group)
} deriving (Show, Read, Eq)
......@@ -327,7 +327,7 @@ setPri t inst = t { pList = Instance.idx inst:pList t
, uCpu = new_count
, pCpu = fromIntegral new_count / tCpu t
, utilLoad = utilLoad t `T.addUtil` Instance.util inst
, pTags = addTags (pTags t) (Instance.tags inst)
, pTags = addTags (pTags t) (Instance.exclTags inst)
, instSpindles = calcSpindleUse t inst
}
where new_count = Instance.applyIfOnline inst (+ Instance.vcpus inst)
......@@ -376,7 +376,7 @@ removePri t inst =
in t { pList = new_plist, fMem = new_mem, fDsk = new_dsk
, failN1 = new_failn1, pMem = new_mp, pDsk = new_dp
, uCpu = new_ucpu, pCpu = new_rcpu, utilLoad = new_load
, pTags = delTags (pTags t) (Instance.tags inst)
, pTags = delTags (pTags t) (Instance.exclTags inst)
, instSpindles = new_spindles
}
......@@ -440,7 +440,7 @@ addPriEx force t inst =
new_dp = computePDsk new_dsk (tDsk t)
l_cpu = T.iPolicyVcpuRatio $ iPolicy t
new_load = utilLoad t `T.addUtil` Instance.util inst
inst_tags = Instance.tags inst
inst_tags = Instance.exclTags inst
old_tags = pTags t
strict = not force
in case () of
......
......@@ -186,7 +186,8 @@ parseGroup a = do
uuid <- extract "uuid"
apol <- extract "alloc_policy"
ipol <- extract "ipolicy"
return (uuid, Group.create name uuid apol ipol)
tags <- extract "tags"
return (uuid, Group.create name uuid apol ipol tags)
-- | Parse cluster data from the info resource.
parseCluster :: JSObject JSValue -> Result ([String], IPolicy)
......
......@@ -84,7 +84,7 @@ createGroup grpIndex spec = do
(fromIntegral cpu) False spindles grpIndex
) [1..ncount]
grp = Group.create (printf "group-%02d" grpIndex)
(printf "fake-uuid-%02d" grpIndex) apol defIPolicy
(printf "fake-uuid-%02d" grpIndex) apol defIPolicy []
return (Group.setIdx grp grpIndex, nodes)
-- | Builds the cluster data from node\/instance files.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment