Commit 24bb769a authored by Swann Perarnau's avatar Swann Perarnau

[refactor] move perfwrapper to new API

parent 4bca474a
Pipeline #4757 passed with stages
in 2 minutes and 10 seconds
...@@ -4,12 +4,13 @@ from __future__ import print_function ...@@ -4,12 +4,13 @@ from __future__ import print_function
import argparse import argparse
import logging import logging
import zmq
import os import os
import tempfile import tempfile
import subprocess import subprocess
import uuid import uuid
from nrm import messaging
PUB_MSG = messaging.MSGTYPES['down_event']
logger = logging.getLogger('perf-wrapper') logger = logging.getLogger('perf-wrapper')
...@@ -22,30 +23,26 @@ class PerfWrapper(object): ...@@ -22,30 +23,26 @@ class PerfWrapper(object):
pass pass
def shutdown(self): def shutdown(self):
update = {'type': 'application', update = {'api': 'down_event',
'event': 'exit', 'type': 'application_exit',
'uuid': self.app_uuid, 'application_uuid': self.app_uuid,
} }
self.downstream_pub_socket.send_json(update) msg = PUB_MSG['application_exit'](**update)
self.downstream_event.sendmsg(msg)
def progress_report(self, progress): def progress_report(self, progress):
update = {'type': 'application', update = {'api': 'down_event',
'event': 'progress', 'type': 'progress',
'payload': progress, 'payload': progress,
'uuid': self.app_uuid,
} }
self.downstream_pub_socket.send_json(update) msg = PUB_MSG['progress'](**update)
self.downstream_event.sendmsg(msg)
def setup(self): def setup(self):
context = zmq.Context() downstream_url = "ipc:///tmp/nrm-downstream-event"
self.downstream_pub_socket = context.socket(zmq.PUB) self.downstream_event = messaging.DownstreamEventClient(downstream_url)
self.downstream_event.wait_connected()
downstream_pub_param = "ipc:///tmp/nrm-downstream-in" logger.info("downstream pub socket connected to: %s", downstream_url)
self.downstream_pub_socket.connect(downstream_pub_param)
logger.info("downstream pub socket connected to: %s",
downstream_pub_param)
# retrieve our container uuid # retrieve our container uuid
self.container_uuid = os.environ.get('ARGO_CONTAINER_UUID') self.container_uuid = os.environ.get('ARGO_CONTAINER_UUID')
...@@ -54,16 +51,14 @@ class PerfWrapper(object): ...@@ -54,16 +51,14 @@ class PerfWrapper(object):
exit(1) exit(1)
self.app_uuid = str(uuid.uuid4()) self.app_uuid = str(uuid.uuid4())
logger.info("client uuid: %r", self.app_uuid) logger.info("client uuid: %r", self.app_uuid)
# send an hello to the demon # send an hello to the demon
update = {'type': 'application', update = {'api': 'down_event',
'event': 'start', 'type': 'application_start',
'container': self.container_uuid, 'container_uuid': self.container_uuid,
'uuid': self.app_uuid, 'application_uuid': self.app_uuid,
'progress': True,
'threads': {'min': 1, 'cur': 1, 'max': 1},
} }
self.downstream_pub_socket.send_json(update) msg = PUB_MSG['application_start'](**update)
self.downstream_event.sendmsg(msg)
def main(self): def main(self):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
......
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