Commit 50946595 authored by Valentin Reis's avatar Valentin Reis

draft

parent 167bdfc1
Pipeline #7872 failed with stages
in 15 minutes and 31 seconds
......@@ -19,7 +19,7 @@ from nrm.aci import ImageManifest
from nrm.subprograms import (
ChrtClient,
NodeOSClient,
resources,
Resources,
SingularityClient,
)
......@@ -76,7 +76,7 @@ class ContainerManager(object):
# ask the resource manager for resources
ncpus = manifest.app["slice"]["cpus"]
nmems = manifest.app["slice"]["mems"]
req = resources(ncpus, nmems)
req = Resources(ncpus, nmems)
allocated = self.resourcemanager.schedule(container_name, req)
logger.info("create: allocation: %r", allocated)
......
......@@ -11,7 +11,7 @@
from __future__ import print_function
import logging
from nrm.subprograms import HwlocClient, resources
from nrm.subprograms import HwlocClient, Resources
logger = logging.getLogger("nrm")
......@@ -45,23 +45,23 @@ class ResourceManager(object):
retmems = sorted(self.available.mems)[: request.mems]
else:
retmems = self.available.mems
ret = resources(retcpus, retmems)
ret = Resources(retcpus, retmems)
# make sure we don't remember an error
if ret.cpus:
self.update(uuid, ret)
return ret
def update(self, uuid, allocation=resources([], [])):
def update(self, uuid, allocation=Resources([], [])):
"""Update resource tracking according to new allocation.
The new allocation is saved, and available resources updated."""
added = {}
freed = {}
prev = self.allocations.get(uuid, resources([], []))
prev = self.allocations.get(uuid, Resources([], []))
for attr, val in prev._asdict().items():
added[attr] = set(getattr(allocation, attr)) - set(val)
freed[attr] = set(val) - set(getattr(allocation, attr))
if allocation != resources([], []):
if allocation != Resources([], []):
self.allocations[uuid] = allocation
logger.info("updated allocation for %r: %r", uuid, self.available)
else:
......@@ -70,5 +70,5 @@ class ResourceManager(object):
new = {}
for attr, val in self.available._asdict().items():
new[attr] = list(set(val) - set(added[attr]) | set(freed[attr]))
self.available = resources(**new)
self.available = Resources(**new)
logger.info("updated available resources: %r", self.available)
......@@ -15,11 +15,17 @@ import xml.etree.ElementTree
import tornado.process as process # type: ignore
import subprocess
from typing import NamedTuple, List
logger = logging.getLogger("nrm")
resources = collections.namedtuple("Resources", ["cpus", "mems"])
def logpopen(p, args, stdout, stderr):
class Resources(NamedTuple):
cpus: List[int]
mems: List[int]
def logpopen(p, args, stdout, stderr) -> None:
"""log popen cmd."""
logger.debug("popen cmd: %r", args)
logger.debug("popen return code: %s", p.returncode)
......@@ -27,7 +33,7 @@ def logpopen(p, args, stdout, stderr):
logger.debug("popen, stderr: %r", stderr)
def bitmask2list(mask):
def bitmask2list(mask) -> List[int]:
"""Convert a bitmask to the list of power of 2 set to 1."""
i = int(mask or "0x0", base=16)
ret = []
......@@ -38,7 +44,7 @@ def bitmask2list(mask):
return ret
def list2bitmask(l):
def list2bitmask(l) -> str:
"""Convert a list into a bitmask."""
m = 0
for e in l:
......@@ -74,7 +80,7 @@ class NodeOSClient(object):
cpus.extend(l.split())
for l in memlines:
mems.extend(l.split())
return resources([int(x) for x in cpus], [int(x) for x in mems])
return Resources([int(x) for x in cpus], [int(x) for x in mems])
def create(self, name, params):
"""Create container, according to params."""
......@@ -251,7 +257,7 @@ class HwlocClient(object):
stdout, stderr = p.communicate()
logpopen(p, args, stdout, stderr)
xmlroot = xml.etree.ElementTree.fromstring(stdout)
ret = resources([], [])
ret = Resources([], [])
for obj in xmlroot.iter("object"):
if obj.attrib["type"] == "NUMANode":
ret.mems.append(int(obj.attrib["os_index"]))
......@@ -296,7 +302,7 @@ class HwlocClient(object):
cpusets = stdout.splitlines()
dret = {}
for c in cpusets:
dret[c] = resources(bitmask2list(c), [])
dret[c] = Resources(bitmask2list(c), [])
# list all resources, and display cpusets too
# this will give us the memories associated with each cpuset.
......
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