Instance.hs: rename 'tags' to 'exclTags', provide 'allTags'
authorDato Simó <dato@google.com>
Wed, 10 Oct 2012 16:58:37 +0000 (17:58 +0100)
committerDato Simó <dato@google.com>
Wed, 17 Oct 2012 13:13:32 +0000 (14:13 +0100)
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: Dato Simó <dato@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

htools/Ganeti/HTools/Instance.hs
htools/Ganeti/HTools/Loader.hs
htools/Ganeti/HTools/Node.hs
htools/Ganeti/HTools/Text.hs

index 76465ce..a330afe 100644 (file)
@@ -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.
index 851c84b..d441669 100644 (file)
@@ -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 .
index f744e58..1a14af2 100644 (file)
@@ -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
index 4febe9c..4197f9f 100644 (file)
@@ -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