Commit 9b2d4452 authored by Valentin Reis's avatar Valentin Reis

Merge branch 'nrm-gen' into 'master'

Use json schemas for message formats

See merge request !90
parents cb3132e2 cd1d86b3
Pipeline #7316 passed with stages
in 7 minutes and 1 second
eval "$(lorri direnv)"
---
variables:
ARGOPKGS: "https://xgitlab.cels.anl.gov/argo/argopkgs/-/archive/master/argopkgs-master.tar.gz"
ARGOPKGS: "https://xgitlab.cels.anl.gov/argo/argopkgs/-/archive/nrm-gen/argopkgs-nrm-gen.tar.gz"
EXTRA: "--nrm ./."
stages:
......@@ -11,11 +11,11 @@ stages:
- quality
include:
- https://xgitlab.cels.anl.gov/argo/argopkgs/raw/master/gitlab-ci/argonix.yml
- https://xgitlab.cels.anl.gov/argo/argopkgs/raw/master/gitlab-ci/components.yml
- https://xgitlab.cels.anl.gov/argo/argopkgs/raw/master/gitlab-ci/integration.yml
- https://xgitlab.cels.anl.gov/argo/argopkgs/raw/master/gitlab-ci/applications.yml
- https://xgitlab.cels.anl.gov/argo/argopkgs/raw/master/gitlab-ci/repoquality.yml
- https://xgitlab.cels.anl.gov/argo/argopkgs/raw/nrm-gen/gitlab-ci/argonix.yml
- https://xgitlab.cels.anl.gov/argo/argopkgs/raw/nrm-gen/gitlab-ci/components.yml
- https://xgitlab.cels.anl.gov/argo/argopkgs/raw/nrm-gen/gitlab-ci/integration.yml
- https://xgitlab.cels.anl.gov/argo/argopkgs/raw/nrm-gen/gitlab-ci/applications.yml
- https://xgitlab.cels.anl.gov/argo/argopkgs/raw/nrm-gen/gitlab-ci/repoquality.yml
py.test:
stage: test
......@@ -28,6 +28,6 @@ py.test:
flake8:
stage: style
script:
- nix run -f "$ARGOPKGS" pythonPackages.flake8 --command flake8 nrm/* bin/*
- nix run -f "$ARGOPKGS" pythonPackages.flake8 --command flake8 nrm/*.py bin/*
tags:
- integration
include Makefile
include tox.ini
include nrm/schemas/*.json
......@@ -9,6 +9,8 @@ six = "==1.11.0"
pyzmq = "*"
tornado = "*"
numpy = "*"
warlock = "*"
scipy = "*"
argparse = "*"
[dev-packages]
......
{
"_meta": {
"hash": {
"sha256": "d5e8fee7deb896b70f43c2b0e6b0c768f34b190f7bb79d6caef92b1ffbafa8cd"
},
"pipfile-spec": 6,
"requires": {
"python_version": "2.7"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"e1839a8": {
"editable": true,
"path": "."
},
"numpy": {
"hashes": [
"sha256:1c362ad12dd09a43b348bb28dd2295dd9cdf77f41f0f45965e04ba97f525b864",
"sha256:2156a06bd407918df4ac0122df6497a9c137432118f585e5b17d543e593d1587",
"sha256:24e4149c38489b51fc774b1e1faa9103e82f73344d7a00ba66f6845ab4769f3f",
"sha256:340ec1697d9bb3a9c464028af7a54245298502e91178bddb4c37626d36e197b7",
"sha256:35db8d419345caa4eeaa65cd63f34a15208acd87530a30f0bc25fc84f55c8c80",
"sha256:361370e9b7f5e44c41eee29f2bb5cb3b755abb4b038bce6d6cbe08db7ff9cb74",
"sha256:36e8dcd1813ca92ce7e4299120cee6c03adad33d89b54862c1b1a100443ac399",
"sha256:378378973546ecc1dfaf9e24c160d683dd04df871ecd2dcc86ce658ca20f92c0",
"sha256:419e6faee16097124ee627ed31572c7e80a1070efa25260b78097cca240e219a",
"sha256:4287104c24e6a09b9b418761a1e7b1bbde65105f110690ca46a23600a3c606b8",
"sha256:549f3e9778b148a47f4fb4682955ed88057eb627c9fe5467f33507c536deda9d",
"sha256:5e359e9c531075220785603e5966eef20ccae9b3b6b8a06fdfb66c084361ce92",
"sha256:5ee7f3dbbdba0da75dec7e94bd7a2b10fe57a83e1b38e678200a6ad8e7b14fdc",
"sha256:62d55e96ec7b117d3d5e618c15efcf769e70a6effaee5842857b64fb4883887a",
"sha256:719b6789acb2bc86ea9b33a701d7c43dc2fc56d95107fd3c5b0a8230164d4dfb",
"sha256:7a70f2b60d48828cba94a54a8776b61a9c2657a803d47f5785f8062e3a9c7c55",
"sha256:7b9e37f194f8bcdca8e9e6af92e2cbad79e360542effc2dd6b98d63955d8d8a3",
"sha256:83b8fc18261b70f45bece2d392537c93dc81eb6c539a16c9ac994c47fc79f09a",
"sha256:9473ad28375710ab18378e72b59422399b27e957e9339c413bf00793b4b12df0",
"sha256:95b085b253080e5d09f7826f5e27dce067bae813a132023a77b739614a29de6e",
"sha256:98b86c62c08c2e5dc98a9c856d4a95329d11b1c6058cb9b5191d5ea6891acd09",
"sha256:a3bd01d6d3ed3d7c06d7f9979ba5d68281f15383fafd53b81aa44b9191047cf8",
"sha256:c81a6afc1d2531a9ada50b58f8c36197f8418ef3d0611d4c1d7af93fdcda764f",
"sha256:ce75ed495a746e3e78cfa22a77096b3bff2eda995616cb7a542047f233091268",
"sha256:dae8618c0bcbfcf6cf91350f8abcdd84158323711566a8c5892b5c7f832af76f",
"sha256:df0b02c6705c5d1c25cc35c7b5d6b6f9b3b30833f9d178843397ae55ecc2eebb",
"sha256:e3660744cda0d94b90141cdd0db9308b958a372cfeee8d7188fdf5ad9108ea82",
"sha256:f2362d0ca3e16c37782c1054d7972b8ad2729169567e3f0f4e5dd3cdf85f188e"
],
"index": "pypi",
"version": "==1.15.1"
},
"pyzmq": {
"hashes": [
"sha256:0033622ceaf46350b8b69ef93198cebf2a631f775279f857c3637961689951fa",
"sha256:1478287e2e0d251aaed4442b6e9b9883485328bf455a461b6910fe13912f8a6e",
"sha256:14c43a839fe454ee4cc4289f77c791bff24dc3dc151005c6178eea697766aedd",
"sha256:165ddf9222af3a9fe7a016eb0d59ae2460e6032b070ceff7341147c1e4af588e",
"sha256:17012c4b95f92b9983c9b7a341d730743092592c89a60b522bf78c6c95a4d71a",
"sha256:22a94263f806decdd1277630afd93dff5d70461ddbe8fde337ce9c8cce98add6",
"sha256:513573d9b4d47ace0fefbd8e5577c1aa821d8a07deb069115bbad0898f877794",
"sha256:5f4c356d278a1017caeec91194b499f550a2c16cf2cb0c6a5ce7f1b3dff8d323",
"sha256:67e50b0f66aa606370a0790e4d64ef7d1b3b0617928f4734cdae4d3463926ab7",
"sha256:6a9d15f4c18b2d7f4437ca48dfced25a891d99346c06a58e564ad1af55f2dca7",
"sha256:7ed4a8568213d78acaafe93388c568b062a428d5d6b8e6bc6c17521a120126d3",
"sha256:890143082ac2444d01187dfd0284a1d70db9be199fdacefefc9894f476da5e2a",
"sha256:a5c9bb522653a137cda07cc2dc6200644074181181296b617bdf3d9f8df419e6",
"sha256:a84df0111779d231130f2d62b47d63b1732d89c02d252981bac87b955943e133",
"sha256:b7fe5a6286778171db895d4cf846476ef3197f29fc2f644c39d5d78131dbc8be",
"sha256:bc23fad15d6da82081e89ea0b254a7b6efe6d1c4c58edb16f28e4b4d880086b2",
"sha256:ce5073b889eec66734ffcf547e4bdb75c26692e3471b700b6a6c5ef18c3374b3",
"sha256:cee2ea5f8630975787dc50ca0d154e28170c15bc6f406208f8d104818930f5a2",
"sha256:d586bc45a89d20be90f44df6f3ee8fb95d99091089ba399a95ca25b76fcab93d",
"sha256:d6b5b6196ba51f22d0c708748b9859eb6e3aa50c620bd4025429db6252775cc1",
"sha256:fa1024749c667aa234292c973760eb6b6416981a55ed91ec4ab320af55301cc9",
"sha256:fa7f09cbca8a7a2c0c19ff14e203016d82e6f8cc54df6d0fc8c011cf7ec755ff",
"sha256:fae9be78bccf89284e970ce42b5cc7d825bd0187027109c762b8c61be37ce763"
],
"index": "pypi",
"version": "==16.0.4"
},
"six": {
"hashes": [
"sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9",
"sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb"
],
"index": "pypi",
"version": "==1.11.0"
},
"tornado": {
"hashes": [
"sha256:5ef073ac6180038ccf99411fe05ae9aafb675952a2c8db60592d5daf8401f803",
"sha256:6d14e47eab0e15799cf3cdcc86b0b98279da68522caace2bd7ce644287685f0a",
"sha256:92b7ca81e18ba9ec3031a7ee73d4577ac21d41a0c9b775a9182f43301c3b5f8e",
"sha256:ab587996fe6fb9ce65abfda440f9b61e4f9f2cf921967723540679176915e4c3",
"sha256:b36298e9f63f18cad97378db2222c0e0ca6a55f6304e605515e05a25483ed51a"
],
"index": "pypi",
"version": "==4.5.3"
}
},
"develop": {
"atomicwrites": {
"hashes": [
"sha256:0312ad34fcad8fac3704d441f7b317e50af620823353ec657a53e981f92920c0",
"sha256:ec9ae8adaae229e4f8446952d204a3e4b5fdd2d099f9be3aaf556120135fb3ee"
],
"markers": "python_version >= '2.7' and python_version != '3.0.*' and python_version != '3.1.*' and python_version != '3.2.*' and python_version != '3.3.*'",
"version": "==1.2.1"
},
"attrs": {
"hashes": [
"sha256:10cbf6e27dbce8c30807caf056c8eb50917e0eaafe86347671b57254006c3e69",
"sha256:ca4be454458f9dec299268d472aaa5a11f67a4ff70093396e1ceae9c76cf4bbb"
],
"version": "==18.2.0"
},
"configparser": {
"hashes": [
"sha256:5308b47021bc2340965c371f0f058cc6971a04502638d4244225c49d80db273a"
],
"markers": "python_version < '3.2'",
"version": "==3.5.0"
},
"enum34": {
"hashes": [
"sha256:2d81cbbe0e73112bdfe6ef8576f2238f2ba27dd0d55752a776c41d38b7da2850",
"sha256:644837f692e5f550741432dd3f223bbb9852018674981b1664e5dc339387588a",
"sha256:6bd0f6ad48ec2aa117d3d141940d484deccda84d4fcd884f5c3d93c23ecd8c79",
"sha256:8ad8c4783bf61ded74527bffb48ed9b54166685e4230386a9ed9b1279e2df5b1"
],
"markers": "python_version < '3.4'",
"version": "==1.1.6"
},
"flake8": {
"hashes": [
"sha256:7253265f7abd8b313e3892944044a365e3f4ac3fcdcfb4298f55ee9ddf188ba0",
"sha256:c7841163e2b576d435799169b78703ad6ac1bbb0f199994fc05f700b2a90ea37"
],
"index": "pypi",
"version": "==3.5.0"
},
"funcsigs": {
"hashes": [
"sha256:330cc27ccbf7f1e992e69fef78261dc7c6569012cf397db8d3de0234e6c937ca",
"sha256:a7bb0f2cf3a3fd1ab2732cb49eba4252c2af4240442415b4abce3b87022a8f50"
],
"markers": "python_version < '3.0'",
"version": "==1.0.2"
},
"mccabe": {
"hashes": [
"sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42",
"sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"
],
"version": "==0.6.1"
},
"more-itertools": {
"hashes": [
"sha256:c187a73da93e7a8acc0001572aebc7e3c69daf7bf6881a2cea10650bd4420092",
"sha256:c476b5d3a34e12d40130bc2f935028b5f636df8f372dc2c1c01dc19681b2039e",
"sha256:fcbfeaea0be121980e15bc97b3817b5202ca73d0eae185b4550cbfce2a3ebb3d"
],
"version": "==4.3.0"
},
"pathlib2": {
"hashes": [
"sha256:8eb170f8d0d61825e09a95b38be068299ddeda82f35e96c3301a8a5e7604cb83",
"sha256:d1aa2a11ba7b8f7b21ab852b1fb5afb277e1bb99d5dfc663380b5015c0d80c5a"
],
"markers": "python_version < '3.6'",
"version": "==2.3.2"
},
"pluggy": {
"hashes": [
"sha256:6e3836e39f4d36ae72840833db137f7b7d35105079aee6ec4a62d9f80d594dd1",
"sha256:95eb8364a4708392bae89035f45341871286a333f749c3141c20573d2b3876e1"
],
"markers": "python_version >= '2.7' and python_version != '3.0.*' and python_version != '3.1.*' and python_version != '3.2.*' and python_version != '3.3.*'",
"version": "==0.7.1"
},
"py": {
"hashes": [
"sha256:06a30435d058473046be836d3fc4f27167fd84c45b99704f2fb5509ef61f9af1",
"sha256:50402e9d1c9005d759426988a492e0edaadb7f4e68bcddfea586bc7432d009c6"
],
"markers": "python_version >= '2.7' and python_version != '3.0.*' and python_version != '3.1.*' and python_version != '3.2.*' and python_version != '3.3.*'",
"version": "==1.6.0"
},
"pycodestyle": {
"hashes": [
"sha256:682256a5b318149ca0d2a9185d365d8864a768a28db66a84a2ea946bcc426766",
"sha256:6c4245ade1edfad79c3446fadfc96b0de2759662dc29d07d80a6f27ad1ca6ba9"
],
"version": "==2.3.1"
},
"pyflakes": {
"hashes": [
"sha256:08bd6a50edf8cffa9fa09a463063c425ecaaf10d1eb0335a7e8b1401aef89e6f",
"sha256:8d616a382f243dbf19b54743f280b80198be0bca3a5396f1d2e1fca6223e8805"
],
"version": "==1.6.0"
},
"pytest": {
"hashes": [
"sha256:453cbbbe5ce6db38717d282b758b917de84802af4288910c12442984bde7b823",
"sha256:a8a07f84e680482eb51e244370aaf2caa6301ef265f37c2bdefb3dd3b663f99d"
],
"index": "pypi",
"version": "==3.8.0"
},
"scandir": {
"hashes": [
"sha256:04b8adb105f2ed313a7c2ef0f1cf7aff4871aa7a1883fa4d8c44b5551ab052d6",
"sha256:1444134990356c81d12f30e4b311379acfbbcd03e0bab591de2696a3b126d58e",
"sha256:1b5c314e39f596875e5a95dd81af03730b338c277c54a454226978d5ba95dbb6",
"sha256:346619f72eb0ddc4cf355ceffd225fa52506c92a2ff05318cfabd02a144e7c4e",
"sha256:44975e209c4827fc18a3486f257154d34ec6eaec0f90fef0cca1caa482db7064",
"sha256:61859fd7e40b8c71e609c202db5b0c1dbec0d5c7f1449dec2245575bdc866792",
"sha256:a5e232a0bf188362fa00123cc0bb842d363a292de7126126df5527b6a369586a",
"sha256:c14701409f311e7a9b7ec8e337f0815baf7ac95776cc78b419a1e6d49889a383",
"sha256:c7708f29d843fc2764310732e41f0ce27feadde453261859ec0fca7865dfc41b",
"sha256:c9009c527929f6e25604aec39b0a43c3f831d2947d89d6caaab22f057b7055c8",
"sha256:f5c71e29b4e2af7ccdc03a020c626ede51da471173b4a6ad1e904f2b2e04b4bd"
],
"markers": "python_version < '3.5'",
"version": "==1.9.0"
},
"six": {
"hashes": [
"sha256:70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9",
"sha256:832dc0e10feb1aa2c68dcc57dbb658f1c7e65b9b61af69048abc87a2db00a0eb"
],
"index": "pypi",
"version": "==1.11.0"
}
}
}
......@@ -19,11 +19,8 @@ import nrm.messaging
import uuid
import sys
import time
import collections
RPC_MSG = nrm.messaging.MSGTYPES['up_rpc_req']
logger = logging.getLogger('nrm')
KillArgs = collections.namedtuple("Kill", ["uuid"])
class CommandLineInterface(object):
......@@ -37,12 +34,9 @@ class CommandLineInterface(object):
if uuid:
logger.info("received signal %d, killing the application..",
signum)
command = {'api': 'up_rpc_req',
'type': 'kill',
'container_uuid': uuid
}
msg = RPC_MSG['kill'](**command)
self.client.sendmsg(msg)
self.client.send(
"Kill",
container_uuid=uuid)
logger.info("killed the application, exiting.")
else:
logger.info("received signal %d, exiting", signum)
......@@ -70,33 +64,26 @@ class CommandLineInterface(object):
self.pub_client.connect()
while(True):
msg = self.pub_client.recvmsg()
msg = self.pub_client.recv()
logger.debug("pub message: %s", msg)
def print_if_filter():
if argv.filter:
if argv.filter == msg.type:
if (msg.type == "performance" or
msg.type == "progress"):
print("%s, %s, %s" % (msg.type, time.time(),
if argv.filter == msg.tag:
if (msg.tag == "performance" or
msg.tag == "progress"):
print("%s, %s, %s" % (msg.tag, time.time(),
msg.payload))
if msg.type == "power":
print("%s, %s, %s" % (msg.type, time.time(),
if msg.tag == "power":
print("%s, %s, %s" % (msg.tag, time.time(),
msg.total))
if msg.type == "container_exit":
print("%s, %s, %s" % (msg.type, time.time(),
if msg.tag == "exit":
print("%s, %s, %s" % (msg.tag, time.time(),
msg.profile_data))
else:
print("%s, %s" % (msg.type, time.time()))
print("%s, %s" % (msg.tag, time.time()))
sys.stdout.flush()
print_if_filter()
# if argv.uuid:
# uuid = getattr(msg, 'container_uuid', None)
# if argv.uuid == uuid or msg.type == "power":
# print_if_filter()
# else:
# print_if_filter()
def do_run(self, argv):
""" Connect to the NRM and ask to spawn a container and run a command
......@@ -108,6 +95,7 @@ class CommandLineInterface(object):
# the command a container uuid as a way to make sure that we can make
# the command idempotent.
environ = os.environ
# environ = []
container_uuid = argv.ucontainername or str(uuid.uuid4())
# simple check + error msg + non-zero return code
......@@ -118,26 +106,22 @@ class CommandLineInterface(object):
logger.error("Manifest file not found: %s", path)
sys.exit(1)
command = {'api': 'up_rpc_req',
'type': 'run',
'manifest': sanitize_manifest(argv.manifest),
'path': argv.command,
'args': argv.args,
'environ': dict(environ),
'container_uuid': container_uuid,
}
msg = RPC_MSG['run'](**command)
# command fsm
state = 'init'
outeof = False
erreof = False
exitmsg = None
self.client.sendmsg(msg)
self.client.send(
tag="run",
manifest=sanitize_manifest(argv.manifest),
path=argv.command,
args=argv.args,
environ=dict(environ),
container_uuid=container_uuid)
# 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 == 'process_start'
msg = self.client.recv()
assert msg.tag == 'start'
def handler(signum, frame):
self.do_signal(msg.container_uuid, signum, frame)
......@@ -145,25 +129,24 @@ class CommandLineInterface(object):
state = 'started'
while(True):
msg = self.client.recvmsg()
assert msg.api == 'up_rpc_rep'
assert msg.type in ['stdout', 'stderr', 'exit', 'process_exit']
msg = self.client.recv()
assert msg.tag in ['stdout', 'stderr', 'exit']
if msg.type == 'stdout':
if msg.tag == 'stdout':
logger.debug("container msg: %r", msg)
if msg.payload == 'eof':
outeof = True
else:
print(msg.payload)
print(msg.payload, file=sys.stdout)
sys.stdout.flush()
elif msg.type == 'stderr':
elif msg.tag == 'stderr':
logger.debug("container msg: %r", msg)
if msg.payload == 'eof':
erreof = True
else:
print(msg.payload, file=sys.stderr)
sys.stdout.flush()
elif msg.type == 'process_exit':
sys.stderr.flush()
elif msg.tag == 'exit':
logger.info("process ended: %r", msg)
state = 'exiting'
exitmsg = msg
......@@ -197,13 +180,9 @@ class CommandLineInterface(object):
The NRM should respond to us with one message listing all
containers."""
command = {'api': 'up_rpc_req',
'type': 'list'}
msg = RPC_MSG['list'](**command)
self.client.sendmsg(msg)
msg = self.client.recvmsg()
assert msg.api == 'up_rpc_rep'
assert msg.type == 'list'
self.client.send(tag="list")
msg = self.client.recv()
assert msg.tag == 'list'
logger.info("list response: %r", msg)
def do_kill(self, argv):
......@@ -212,15 +191,9 @@ class CommandLineInterface(object):
The NRM should respond to us with a message containing the exit status
of the top process of the container."""
command = {'api': 'up_rpc_req',
'type': 'kill',
'container_uuid': argv.uuid
}
msg = RPC_MSG['kill'](**command)
self.client.sendmsg(msg)
msg = self.client.recvmsg()
assert msg.api == 'up_rpc_rep'
assert msg.type == 'exit'
self.client.send(tag="kill", container_uuid=argv.uuid)
msg = self.client.recv()
assert msg.tag == 'exit'
logger.info("container exit: %r", msg)
def do_setpower(self, argv):
......@@ -233,15 +206,9 @@ class CommandLineInterface(object):
# timely answer.
# TODO: check that the level makes a little bit of sense in the first
# place
command = {'api': 'up_rpc_req',
'type': 'setpower',
'limit': str(argv.limit),
}
msg = RPC_MSG['setpower'](**command)
self.client.sendmsg(msg)
msg = self.client.recvmsg()
assert msg.api == 'up_rpc_rep'
assert msg.type == 'getpower'
self.client.send(tag="setPower", limit=str(argv.limit))
msg = self.client.recv()
assert msg.tag == 'getPower'
logger.info("command received by the daemon: %r", msg)
def main(self):
......
......@@ -20,7 +20,6 @@ import subprocess
import uuid
from nrm import messaging
PUB_MSG = messaging.MSGTYPES['down_event']
logger = logging.getLogger('perf-wrapper')
......@@ -33,26 +32,19 @@ class PerfWrapper(object):
pass
def shutdown(self):
update = {'api': 'down_event',
'type': 'application_exit',
'application_uuid': self.app_uuid,
}
msg = PUB_MSG['application_exit'](**update)
self.downstream_event.sendmsg(msg)
self.downstream_event.send(tag="exit", application_uuid=self.app_uuid)
def performance_report(self, performance):
update = {'api': 'down_event',
'type': 'performance',
'payload': performance,
'container_uuid': self.container_uuid,
'application_uuid': self.app_uuid,
}
msg = PUB_MSG['performance'](**update)
self.downstream_event.sendmsg(msg)
self.downstream_event.send(
tag="performance",
payload=performance,
container_uuid=self.container_uuid,
application_uuid=self.app_uuid)
def setup(self):
downstream_url = "ipc:///tmp/nrm-downstream-event"
self.downstream_event = messaging.DownstreamEventClient(downstream_url)
logger.info("connecting downstream pub")
self.downstream_event.connect()
logger.info("downstream pub socket connected to: %s", downstream_url)
......@@ -64,13 +56,10 @@ class PerfWrapper(object):
self.app_uuid = str(uuid.uuid4())
logger.info("client uuid: %r", self.app_uuid)
# send an hello to the demon
update = {'api': 'down_event',
'type': 'application_start',
'container_uuid': self.container_uuid,
'application_uuid': self.app_uuid,
}
msg = PUB_MSG['application_start'](**update)
self.downstream_event.sendmsg(msg)
self.downstream_event.send(
tag="start",
container_uuid=self.container_uuid,
application_uuid=self.app_uuid)
def main(self):
parser = argparse.ArgumentParser()
......
......@@ -91,8 +91,8 @@ class ApplicationManager(object):
def register(self, msg, container):
"""Register a new downstream application."""
uuid = msg.application_uuid
container_uuid = msg.container_uuid
uuid = msg['application_uuid']
container_uuid = msg['container_uuid']
progress = 0
threads = False
phase_contexts = dict()
......
......@@ -25,41 +25,41 @@ class Action(object):
self.delta = delta
class ApplicationActuator(object):
"""Actuator in charge of application thread control."""
def __init__(self, am, pubstream):
self.application_manager = am
self.pubstream = pubstream
def available_actions(self, target):
ret = []
for identity, application in \
self.application_manager.applications.iteritems():
if target in application.get_allowed_thread_requests():
delta = application.get_thread_request_impact(target)
ret.append(Action(application, target, delta))
return ret
def execute(self, action):
target_threads = action.target.threads
update = {'type': 'application',
'command': 'threads',
'uuid': action.target.uuid,
'event': 'threads',
}
if action.command == 'i':
payload = target_threads['cur'] + 1
elif action.command == 'd':
payload = target_threads['cur'] - 1
else:
assert False, "impossible command"
update['payload'] = payload
self.pubstream.send_json(update)
def update(self, action):
action.target.do_thread_transition(action.command)
# class ApplicationActuator(object):
#
# """Actuator in charge of application thread control."""
#
# def __init__(self, am, pubstream):
# self.application_manager = am
# self.pubstream = pubstream
#
# def available_actions(self, target):
# ret = []
# for identity, application in \
# self.application_manager.applications.iteritems():
# if target in application.get_allowed_thread_requests():
# delta = application.get_thread_request_impact(target)
# ret.append(Action(application, target, delta))
# return ret
#
# def execute(self, action):
# target_threads = action.target.threads
# update = {'type': 'application',
# 'command': 'threads',
# 'uuid': action.target.uuid,
# 'event': 'threads',
# }
# if action.command == 'i':
# payload = target_threads['cur'] + 1
# elif action.command == 'd':
# payload = target_threads['cur'] - 1
# else:
# assert False, "impossible command"
# update['payload'] = payload
# self.pubstream.send_json()
#
# def update(self, action):
# action.target.do_thread_transition(action.command)
class PowerActuator(object):
......
......@@ -21,13 +21,9 @@ from resources import ResourceManager
from sensor import SensorManager
import signal
from zmq.eventloop import ioloop
from nrm.messaging import MSGTYPES
from nrm.messaging import UpstreamRPCServer, UpstreamPubServer, \
DownstreamEventServer
RPC_MSG = MSGTYPES['up_rpc_rep']
PUB_MSG = MSGTYPES['up_pub']
logger = logging.getLogger('nrm')
......@@ -37,71 +33,66 @@ class Daemon(object):
self.target = 100.0
self.config = config
def do_downstream_receive(self, msg, client):
logger.info("receiving downstream message: %r", msg)
if msg.type == 'application_start':
cid = msg.container_uuid
def do_downstream_receive(self, event, client):
logger.info("receiving downstream message: %r", event)
if event.tag == 'start':
cid = event.container_uuid
container = self.container_manager.containers[cid]
self.application_manager.register(msg, container)
elif msg.type == 'progress':
if msg.application_uuid in self.application_manager.applications:
self.application_manager.register(event, container)
elif event.tag == 'progress':
if event.application_uuid in self.application_manager.applications:
app = self.application_manager.applications[
msg.application_uuid]
app.update_performance(msg)
pub = {'api': 'up_pub',
'type': 'progress',
'payload': msg.payload,
'application_uuid': msg.application_uuid}
self.upstream_pub_server.sendmsg(
PUB_MSG['progress'](**pub))
elif msg.type == 'performance':
if msg.application_uuid in self.application_manager.applications:
event.application_uuid]
app.update_performance(event)
# self.upstream_pub_server.send(event) TODO try this.
self.upstream_pub_server.send(
tag='progress',
payload=event.payload,
application_uuid=event.application_uuid)
elif event.tag == 'performance':
if event.application_uuid in self.application_manager.applications:
app = self.application_manager.applications[
msg.application_uuid]
app.update_performance(msg)
pub = {'api': 'up_pub',
'type': 'performance',
'payload': msg.payload,
'container_uuid': msg.container_uuid}
self.upstream_pub_server.sendmsg(
PUB_MSG['performance'](**pub))
elif msg.type == 'phase_context':
uuid = msg.application_uuid
event.application_uuid]
app.update_performance(event)
self.upstream_pub_server.send(
tag='performance',
payload=event.payload,
container_uuid=event.container_uuid)
elif event.tag == 'phasecontext':
uuid = event.application_uuid
if uuid in self.application_manager.applications:
app = self.application_manager.applications[uuid]
if bool(self.container_manager.containers):
cid = app.container_uuid
c = self.container_manager.containers[cid]
if c.power['policy']:
app.update_phase_context(msg)