Commit 9afe59c7 authored by Swann Perarnau's avatar Swann Perarnau

[refactor] Fix container namedtuple

This patch propagates the process object into the container namedtuple,
fix a couple of bad function calls and adapt the run command handler to
use that process object instead of just the pid of it.
parent edeb413b
...@@ -4,11 +4,10 @@ from aci import ImageManifest ...@@ -4,11 +4,10 @@ from aci import ImageManifest
from collections import namedtuple from collections import namedtuple
import logging import logging
import os import os
import signal
from subprograms import ChrtClient, NodeOSClient, resources from subprograms import ChrtClient, NodeOSClient, resources
logger = logging.getLogger('nrm') logger = logging.getLogger('nrm')
Container = namedtuple('Container', ['uuid', 'manifest', 'pid']) Container = namedtuple('Container', ['uuid', 'manifest', 'process'])
class ContainerManager(object): class ContainerManager(object):
...@@ -72,7 +71,7 @@ class ContainerManager(object): ...@@ -72,7 +71,7 @@ class ContainerManager(object):
c = Container(container_name, manifest, process) c = Container(container_name, manifest, process)
self.pids[process.pid] = c self.pids[process.pid] = c
self.containers[container_name] = c self.containers[container_name] = c
return process.pid return process
def delete(self, uuid): def delete(self, uuid):
"""Delete a container and kill all related processes.""" """Delete a container and kill all related processes."""
...@@ -80,7 +79,7 @@ class ContainerManager(object): ...@@ -80,7 +79,7 @@ class ContainerManager(object):
self.resourcemanager.update(uuid) self.resourcemanager.update(uuid)
c = self.containers[uuid] c = self.containers[uuid]
del self.containers[uuid] del self.containers[uuid]
del self.pids[c.pid.pid] del self.pids[c.process.pid]
def kill(self, uuid): def kill(self, uuid):
"""Kill all the processes of a container.""" """Kill all the processes of a container."""
...@@ -88,11 +87,11 @@ class ContainerManager(object): ...@@ -88,11 +87,11 @@ class ContainerManager(object):
c = self.containers[uuid] c = self.containers[uuid]
logger.debug("killing %r:", c) logger.debug("killing %r:", c)
try: try:
c.pid.terminate() c.process.proc.terminate()
except OSError: except OSError:
pass pass
def list(self): def list(self):
"""List the containers in the system.""" """List the containers in the system."""
return [{'uuid': c.uuid, 'pid': c.pid.pid} for c in return [{'uuid': c.uuid, 'pid': c.process.pid} for c in
self.containers.values()] self.containers.values()]
...@@ -119,24 +119,16 @@ class Daemon(object): ...@@ -119,24 +119,16 @@ class Daemon(object):
logger.info("new target measure: %g", self.target) logger.info("new target measure: %g", self.target)
elif command == 'run': elif command == 'run':
logger.info("new container required: %r", msg) logger.info("new container required: %r", msg)
pid = self.container_manager.create(msg) process = self.container_manager.create(msg)
if pid > 0: self.containerpids[process.pid] = msg['uuid']
self.containerpids[pid] = msg['uuid'] # TODO: obviously we need to send more info than that
# TODO: obviously we need to send more info than that update = {'type': 'container',
update = {'type': 'container', 'event': 'start',
'event': 'start', 'uuid': msg['uuid'],
'uuid': msg['uuid'], 'errno': 0,
'errno': 0, 'pid': process.pid,
'pid': pid, }
} self.upstream_pub.send_json(update)
self.upstream_pub.send_json(update)
else:
update = {'type': 'container',
'event': 'start',
'uuid': msg['uuid'],
'errno': pid,
}
self.upstream_pub.send_json(update)
elif command == 'kill': elif command == 'kill':
logger.info("asked to kill container: %r", msg) logger.info("asked to kill container: %r", msg)
response = self.container_manager.kill(msg['uuid']) response = self.container_manager.kill(msg['uuid'])
......
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