diff --git a/bin/cmd b/bin/cmd index ce923f2ca4e0e3e18d1e477f450600e8814ce2c4..694c5e40900af336e06ab7541f545d0d7aa81ddd 100755 --- a/bin/cmd +++ b/bin/cmd @@ -44,13 +44,14 @@ class CommandLineInterface(object): # the command a container uuid as a way to make sure that we can make # the command idempotent. environ = os.environ + container_uuid = argv.ucontainername or str(uuid.uuid4()) command = {'api': 'up_rpc_req', 'type': 'run', 'manifest': argv.manifest, 'path': argv.command, 'args': argv.args, 'environ': dict(environ), - 'container_uuid': argv.ucontainername or str(uuid.uuid4()), + 'container_uuid': container_uuid, } msg = RPC_MSG['run'](**command) # command fsm @@ -63,12 +64,7 @@ class CommandLineInterface(object): # the first message tells us if we started a container or not msg = self.client.recvmsg() assert msg.api == 'up_rpc_rep' - assert msg.type in ['start', 'process_start'] - new_container = False - if msg.type == 'start': - new_container = True - msg = self.client.recvmsg() - assert msg.type == 'process_start' + assert msg.type == 'process_start' state = 'started' while(True): msg = self.client.recvmsg() @@ -85,17 +81,13 @@ class CommandLineInterface(object): erreof = True elif msg.type == 'process_exit': logger.info("process ended: %r", msg) - if not new_container: - state = 'exiting' - elif msg.type == 'exit': - if state == 'started': - state = 'exiting' - exitmsg = msg - else: - logger.info("unexpected exit message: %r", msg) + state = 'exiting' + exitmsg = msg + else: + logger.error("unexpected message: %r", msg) if outeof and erreof and state == 'exiting': state = 'exit' - logger.info("container ended: %r", exitmsg) + logger.info("command ended: %r", exitmsg) break def do_list(self, argv): diff --git a/nrm/daemon.py b/nrm/daemon.py index 5f27201377f57ce14c3284d46f09b19881a42379..9680fb4e8d68366b09aed4a53858a4d32ce90327 100644 --- a/nrm/daemon.py +++ b/nrm/daemon.py @@ -100,14 +100,14 @@ class Daemon(object): p = container.power['profile'] p['start'] = self.machine_info['energy']['energy'] p['start']['time'] = self.machine_info['time'] - update = {'api': 'up_rpc_rep', - 'type': 'start', + update = {'api': 'up_pub', + 'type': 'container_start', 'container_uuid': container_uuid, 'errno': 0 if container else -1, 'power': container.power['policy'] or dict() } - self.upstream_rpc_server.sendmsg(RPC_MSG['start'](**update), - client) + self.upstream_pub_server.sendmsg( + PUB_MSG['container_start'](**update)) self.container_owner[container.uuid] = client # now deal with the process itself @@ -219,8 +219,8 @@ class Daemon(object): # kill everything if self.container_owner[container.uuid] == clientid: # deal with container exit - msg = {'api': 'up_rpc_rep', - 'type': 'exit', + msg = {'api': 'up_pub', + 'type': 'container_exit', 'container_uuid': container.uuid, 'profile_data': dict(), } @@ -242,8 +242,8 @@ class Daemon(object): container.uuid, diff) msg['profile_data'] = diff self.container_manager.delete(container.uuid) - self.upstream_rpc_server.sendmsg( - RPC_MSG['exit'](**msg), clientid) + self.upstream_pub_server.sendmsg( + PUB_MSG['container_exit'](**msg)) del self.container_owner[container.uuid] else: logger.debug("child update ignored") diff --git a/nrm/messaging.py b/nrm/messaging.py index 053bcd3e818c1211b6d39fca0fa07d112c5cb4bc..4c71924ee8d94d871dc6a4155e067dd7fa65eef1 100644 --- a/nrm/messaging.py +++ b/nrm/messaging.py @@ -29,23 +29,24 @@ MSGFORMATS['up_rpc_req'] = {'list': {}, 'kill': {'container_uuid': basestring}, 'setpower': {'limit': basestring}, } -MSGFORMATS['up_rpc_rep'] = {'start': {'container_uuid': basestring, - 'errno': int, - 'power': dict}, - 'list': {'payload': list}, +MSGFORMATS['up_rpc_rep'] = {'list': {'payload': list}, 'stdout': {'container_uuid': basestring, 'payload': basestring}, 'stderr': {'container_uuid': basestring, 'payload': basestring}, - 'exit': {'container_uuid': basestring, - 'profile_data': dict}, 'process_start': {'container_uuid': basestring, 'pid': int}, 'process_exit': {'container_uuid': basestring, 'status': basestring}, 'getpower': {'limit': basestring}, } -MSGFORMATS['up_pub'] = {'power': {'total': int, 'limit': float}} +MSGFORMATS['up_pub'] = {'power': {'total': int, 'limit': float}, + 'container_start': {'container_uuid': basestring, + 'errno': int, + 'power': dict}, + 'container_exit': {'container_uuid': basestring, + 'profile_data': dict}, + } # Mirror of the message formats, using namedtuples as the actual transport # for users of this messaging layer.