Commit 2f907bad authored by Dato Simó's avatar Dato Simó
Browse files

Instance.hs: rename 'tags' to 'exclTags', provide 'allTags'



The mergeData function in Loader.hs included a step to filter an instance's
tags to include only the exclusion tags (as specified via the commandline,
or cluster-level tags). Later on, code in Node.hs assumed Instance.tags to
contain only tags to be used for exclusion.

Because in the future we will need to access the full list of an instance's
tags (and not only exclusion tags), this commits deprecates the 'tags'
field, and introduces Instance.exclTags and Instance.allTags.

Instance.allTags is now populated from the different backends (Text, Luxi,
Rapi, etc.), and Instance.exclTags is only populated from Loader.mergeData,
as was done previously. This means that loading tags from e.g. Text or Simu
and assuming that they'll be used as exclusion tags without going through
Loader.hs will no longer work; but this was already the case with other
fields, and 'mergeData' or 'loadExternalData' continue to be the only entry
points to get a consistent view of the cluster. (Additionally, there were
no tests that made this assumption that I could find.)
Signed-off-by: default avatarDato Simó <dato@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 0397694e
......@@ -78,9 +78,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
......@@ -173,11 +174,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.
......
......@@ -151,12 +151,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)
......@@ -226,7 +226,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 .
......
......@@ -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
......
......@@ -107,7 +107,7 @@ serializeInstance nl inst =
(Instance.vcpus inst) (instanceStatusToRaw (Instance.runSt inst))
(if Instance.autoBalance inst then "Y" else "N")
pnode snode (diskTemplateToRaw (Instance.diskTemplate inst))
(intercalate "," (Instance.tags inst)) (Instance.spindleUse inst)
(intercalate "," (Instance.allTags inst)) (Instance.spindleUse inst)
-- | Generate instance file data from instance objects.
serializeInstances :: Node.List -> Instance.List -> String
......
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