Commit 6b6e335b authored by Dato Simó's avatar Dato Simó
Browse files

Group.hs: add 'allTags'; adjust loaders and test data for it



This commit adds a Group.allTags field to store the tags of node groups,
and teaches each loader backend in HTools to populate it (additionally, the
IAllocator class in lib/cmdlib.py now includes tags for groups too). Test
data is updated to include an empty set of tags for node groups in all
affected test cases.
Signed-off-by: default avatarDato Simó <dato@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 2f907bad
......@@ -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
}
......
......@@ -130,7 +130,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.
--
......
......@@ -116,7 +116,7 @@ queryClusterInfoMsg = L.QueryClusterInfo
-- | The input data for node group query.
queryGroupsMsg :: L.LuxiOp
queryGroupsMsg =
L.Query L.QRGroup ["uuid", "name", "alloc_policy", "ipolicy"] ()
L.Query L.QRGroup ["uuid", "name", "alloc_policy", "ipolicy", "tags"] ()
-- | Wraper over 'callMethod' doing node query.
queryNodes :: L.Client -> IO (Result JSValue)
......@@ -218,13 +218,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)
......
......@@ -157,7 +157,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)]
......
......@@ -177,7 +177,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)
......
......@@ -83,7 +83,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.
......
......@@ -66,8 +66,9 @@ commaSplit = sepSplit ','
-- | Serialize a single group.
serializeGroup :: Group.Group -> String
serializeGroup grp =
printf "%s|%s|%s" (Group.name grp) (Group.uuid grp)
printf "%s|%s|%s|%s" (Group.name grp) (Group.uuid grp)
(allocPolicyToRaw (Group.allocPolicy grp))
(intercalate "," (Group.allTags grp))
-- | Generate group file data from a group list.
serializeGroups :: Group.List -> String
......@@ -167,9 +168,10 @@ serializeCluster (ClusterData gl nl il ctags cpol) =
loadGroup :: (Monad m) => [String]
-> m (String, Group.Group) -- ^ The result, a tuple of group
-- UUID and group object
loadGroup [name, gid, apol] = do
loadGroup [name, gid, apol, tags] = do
xapol <- allocPolicyFromRaw apol
return (gid, Group.create name gid xapol defIPolicy)
let xtags = commaSplit tags
return (gid, Group.create name gid xapol defIPolicy xtags)
loadGroup s = fail $ "Invalid/incomplete group data: '" ++ show s ++ "'"
......
......@@ -14834,6 +14834,7 @@ class IAllocator(object):
"name": gdata.name,
"alloc_policy": gdata.alloc_policy,
"ipolicy": _CalculateGroupIPolicy(cluster, gdata),
"tags": list(gdata.tags),
})
for guuid, gdata in cfg.GetAllNodeGroupsInfo().items())
 
......
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
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
......
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
......
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