blob: 5a31f42a588ee747d44dbfdb81b7dbbe5db605a9 [file] [log] [blame]
Zsolt Harasztib71c2a02016-09-12 13:12:07 -07001#!/usr/bin/env python
2#
Zsolt Haraszti3eb27a52017-01-03 21:56:48 -08003# Copyright 2017 the original author or authors.
Zsolt Harasztib71c2a02016-09-12 13:12:07 -07004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
Zsolt Harasztiadbb88d2016-09-12 21:24:57 -070018"""Virtual OLT Hardware Abstraction main entry point"""
Zsolt Harasztib71c2a02016-09-12 13:12:07 -070019
20import argparse
Zsolt Harasztib5d72f12017-01-15 20:44:02 -080021import arrow
Zsolt Harasztid7c7c482016-09-13 00:45:38 -070022import os
Zsolt Harasztif2da1d02016-09-13 23:21:35 -070023import time
Zsolt Haraszti023ea7c2016-10-16 19:30:34 -070024
Zsolt Harasztid7c7c482016-09-13 00:45:38 -070025import yaml
Zsolt Haraszti89a27302016-12-08 16:53:06 -080026from simplejson import dumps
Zsolt Harasztie060a7d2016-09-16 11:08:24 -070027from twisted.internet.defer import inlineCallbacks
Zsolt Harasztib5d72f12017-01-15 20:44:02 -080028from twisted.internet.task import LoopingCall
Zsolt Harasztia17f3ec2016-12-08 14:55:49 -080029from zope.interface import implementer
Zsolt Harasztiadbb88d2016-09-12 21:24:57 -070030
Zsolt Haraszti3bfff662016-12-14 23:41:49 -080031from common.event_bus import EventBusClient
32from common.manhole import Manhole
Zsolt Harasztid70cd4d2016-11-03 23:23:36 -070033from common.structlog_setup import setup_logging
Zsolt Haraszti023ea7c2016-10-16 19:30:34 -070034from common.utils.dockerhelpers import get_my_containers_name
35from common.utils.nethelpers import get_my_primary_interface, \
Khen Nursimulu441dedd2016-10-05 14:44:26 -070036 get_my_primary_local_ipv4
Zsolt Haraszti7eeb2b32016-11-06 14:04:55 -080037from voltha.adapters.loader import AdapterLoader
Zsolt Harasztid70cd4d2016-11-03 23:23:36 -070038from voltha.coordinator import Coordinator
Zsolt Harasztidafefe12016-11-14 21:29:58 -080039from voltha.core.core import VolthaCore
Ryan Van Gilder5a0ab622017-03-01 16:39:25 -080040from voltha.core.config.config_backend import load_backend
Zsolt Haraszti99509d32016-12-10 16:41:45 -080041from voltha.northbound.diagnostics import Diagnostics
Zsolt Harasztieb435072016-09-23 17:10:49 -070042from voltha.northbound.grpc.grpc_server import VolthaGrpcServer
khenb95fe9a2016-10-05 11:15:25 -070043from voltha.northbound.kafka.kafka_proxy import KafkaProxy, get_kafka_proxy
Zsolt Harasztid70cd4d2016-11-03 23:23:36 -070044from voltha.northbound.rest.health_check import init_rest_service
Zsolt Haraszti66862032016-11-28 14:28:39 -080045from voltha.protos.common_pb2 import LogLevel
Zsolt Harasztia17f3ec2016-12-08 14:55:49 -080046from voltha.registry import registry, IComponent
Zsolt Haraszti89a27302016-12-08 16:53:06 -080047from common.frameio.frameio import FrameIOManager
48
Zsolt Harasztidafefe12016-11-14 21:29:58 -080049
50VERSION = '0.9.0'
khenb95fe9a2016-10-05 11:15:25 -070051
Zsolt Harasztif2da1d02016-09-13 23:21:35 -070052defs = dict(
Zsolt Harasztif2da1d02016-09-13 23:21:35 -070053 config=os.environ.get('CONFIG', './voltha.yml'),
Zsolt Haraszti553826c2016-09-27 10:24:27 -070054 consul=os.environ.get('CONSUL', 'localhost:8500'),
Zsolt Haraszti109db832016-09-16 16:32:36 -070055 external_host_address=os.environ.get('EXTERNAL_HOST_ADDRESS',
56 get_my_primary_local_ipv4()),
Zsolt Harasztide22bbc2016-09-14 15:27:33 -070057 fluentd=os.environ.get('FLUENTD', None),
Zsolt Haraszti553826c2016-09-27 10:24:27 -070058 grpc_port=os.environ.get('GRPC_PORT', 50055),
59 instance_id=os.environ.get('INSTANCE_ID', os.environ.get('HOSTNAME', '1')),
60 internal_host_address=os.environ.get('INTERNAL_HOST_ADDRESS',
61 get_my_primary_local_ipv4()),
62 interface=os.environ.get('INTERFACE', get_my_primary_interface()),
Zsolt Harasztide22bbc2016-09-14 15:27:33 -070063 rest_port=os.environ.get('REST_PORT', 8880),
khenb95fe9a2016-10-05 11:15:25 -070064 kafka=os.environ.get('KAFKA', 'localhost:9092'),
Zsolt Haraszti3bfff662016-12-14 23:41:49 -080065 manhole_port=os.environ.get('MANHOLE_PORT', 12222),
Ryan Van Gilder5a0ab622017-03-01 16:39:25 -080066 backend=os.environ.get('BACKEND', 'none'),
Zsolt Harasztif2da1d02016-09-13 23:21:35 -070067)
Zsolt Harasztib71c2a02016-09-12 13:12:07 -070068
69
70def parse_args():
Zsolt Harasztib71c2a02016-09-12 13:12:07 -070071 parser = argparse.ArgumentParser()
72
Zsolt Haraszti109db832016-09-16 16:32:36 -070073 _help = ('Path to voltha.yml config file (default: %s). '
74 'If relative, it is relative to main.py of voltha.'
75 % defs['config'])
76 parser.add_argument('-c', '--config',
77 dest='config',
78 action='store',
Zsolt Harasztif2da1d02016-09-13 23:21:35 -070079 default=defs['config'],
Zsolt Haraszti109db832016-09-16 16:32:36 -070080 help=_help)
Zsolt Harasztif2da1d02016-09-13 23:21:35 -070081
Zsolt Haraszti109db832016-09-16 16:32:36 -070082 _help = '<hostname>:<port> to consul agent (default: %s)' % defs['consul']
83 parser.add_argument(
84 '-C', '--consul', dest='consul', action='store',
85 default=defs['consul'],
86 help=_help)
Zsolt Harasztif2da1d02016-09-13 23:21:35 -070087
Zsolt Haraszti109db832016-09-16 16:32:36 -070088 _help = ('<hostname> or <ip> at which Voltha is reachable from outside '
89 'the cluster (default: %s)' % defs['external_host_address'])
90 parser.add_argument('-E', '--external-host-address',
91 dest='external_host_address',
92 action='store',
Zsolt Harasztif2da1d02016-09-13 23:21:35 -070093 default=defs['external_host_address'],
Zsolt Haraszti109db832016-09-16 16:32:36 -070094 help=_help)
Zsolt Harasztif2da1d02016-09-13 23:21:35 -070095
Zsolt Haraszti553826c2016-09-27 10:24:27 -070096 _help = ('port number of the GRPC service exposed by voltha (default: %s)'
97 % defs['grpc_port'])
98 parser.add_argument('-g', '--grpc-port',
99 dest='grpc_port',
100 action='store',
101 default=defs['grpc_port'],
102 help=_help)
Khen Nursimulu441dedd2016-10-05 14:44:26 -0700103
Zsolt Haraszti109db832016-09-16 16:32:36 -0700104 _help = ('<hostname>:<port> to fluentd server (default: %s). (If not '
105 'specified (None), the address from the config file is used'
106 % defs['fluentd'])
107 parser.add_argument('-F', '--fluentd',
108 dest='fluentd',
109 action='store',
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700110 default=defs['fluentd'],
Zsolt Haraszti109db832016-09-16 16:32:36 -0700111 help=_help)
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700112
Zsolt Haraszti109db832016-09-16 16:32:36 -0700113 _help = ('<hostname> or <ip> at which Voltha is reachable from inside the'
114 'cluster (default: %s)' % defs['internal_host_address'])
115 parser.add_argument('-H', '--internal-host-address',
116 dest='internal_host_address',
117 action='store',
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700118 default=defs['internal_host_address'],
Zsolt Haraszti109db832016-09-16 16:32:36 -0700119 help=_help)
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700120
Zsolt Haraszti109db832016-09-16 16:32:36 -0700121 _help = ('unique string id of this voltha instance (default: %s)'
Zsolt Haraszti86be6f12016-09-27 09:56:49 -0700122 % defs['instance_id'])
Zsolt Haraszti109db832016-09-16 16:32:36 -0700123 parser.add_argument('-i', '--instance-id',
124 dest='instance_id',
125 action='store',
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700126 default=defs['instance_id'],
Zsolt Haraszti109db832016-09-16 16:32:36 -0700127 help=_help)
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700128
129 # TODO placeholder, not used yet
Zsolt Haraszti109db832016-09-16 16:32:36 -0700130 _help = 'ETH interface to send (default: %s)' % defs['interface']
131 parser.add_argument('-I', '--interface',
132 dest='interface',
133 action='store',
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700134 default=defs['interface'],
Zsolt Haraszti109db832016-09-16 16:32:36 -0700135 help=_help)
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700136
Zsolt Haraszti3bfff662016-12-14 23:41:49 -0800137 _help = 'open ssh manhole at given port'
138 parser.add_argument('-m', '--manhole-port',
139 dest='manhole_port',
140 action='store',
141 type=int,
142 default=None,
143 help=_help)
144
Zsolt Haraszti109db832016-09-16 16:32:36 -0700145 _help = 'omit startup banner log lines'
146 parser.add_argument('-n', '--no-banner',
147 dest='no_banner',
148 action='store_true',
149 default=False,
150 help=_help)
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700151
Zsolt Haraszti109db832016-09-16 16:32:36 -0700152 _help = 'do not emit periodic heartbeat log messages'
153 parser.add_argument('-N', '--no-heartbeat',
154 dest='no_heartbeat',
155 action='store_true',
156 default=False,
157 help=_help)
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700158
Zsolt Haraszti109db832016-09-16 16:32:36 -0700159 _help = ('port number for the rest service (default: %d)'
160 % defs['rest_port'])
161 parser.add_argument('-R', '--rest-port',
162 dest='rest_port',
163 action='store',
164 type=int,
Zsolt Harasztide22bbc2016-09-14 15:27:33 -0700165 default=defs['rest_port'],
Zsolt Haraszti109db832016-09-16 16:32:36 -0700166 help=_help)
Zsolt Harasztide22bbc2016-09-14 15:27:33 -0700167
Zsolt Haraszti109db832016-09-16 16:32:36 -0700168 _help = "suppress debug and info logs"
169 parser.add_argument('-q', '--quiet',
170 dest='quiet',
Zsolt Haraszti1420def2016-09-18 00:07:31 -0700171 action='count',
Zsolt Haraszti109db832016-09-16 16:32:36 -0700172 help=_help)
Zsolt Harasztiadbb88d2016-09-12 21:24:57 -0700173
Zsolt Haraszti109db832016-09-16 16:32:36 -0700174 _help = 'enable verbose logging'
175 parser.add_argument('-v', '--verbose',
176 dest='verbose',
Zsolt Haraszti1420def2016-09-18 00:07:31 -0700177 action='count',
Zsolt Haraszti109db832016-09-16 16:32:36 -0700178 help=_help)
Zsolt Harasztiadbb88d2016-09-12 21:24:57 -0700179
Zsolt Haraszti109db832016-09-16 16:32:36 -0700180 _help = ('use docker container name as voltha instance id'
181 ' (overrides -i/--instance-id option)')
182 parser.add_argument('--instance-id-is-container-name',
183 dest='instance_id_is_container_name',
184 action='store_true',
185 default=False,
186 help=_help)
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700187
khenb95fe9a2016-10-05 11:15:25 -0700188 _help = ('<hostname>:<port> of the kafka broker (default: %s). (If not '
189 'specified (None), the address from the config file is used'
190 % defs['kafka'])
191 parser.add_argument('-K', '--kafka',
192 dest='kafka',
193 action='store',
194 default=defs['kafka'],
195 help=_help)
196
Ryan Van Gilder5a0ab622017-03-01 16:39:25 -0800197 _help = 'backend to use for config persitence'
198 parser.add_argument('-b', '--backend',
199 default=defs['backend'],
200 choices=['none', 'consul'],
201 help=_help)
202
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700203 args = parser.parse_args()
204
205 # post-processing
206
207 if args.instance_id_is_container_name:
208 args.instance_id = get_my_containers_name()
209
210 return args
Zsolt Harasztib71c2a02016-09-12 13:12:07 -0700211
212
Zsolt Harasztid7c7c482016-09-13 00:45:38 -0700213def load_config(args):
214 path = args.config
215 if path.startswith('.'):
216 dir = os.path.dirname(os.path.abspath(__file__))
217 path = os.path.join(dir, path)
218 path = os.path.abspath(path)
219 with open(path) as fd:
220 config = yaml.load(fd)
221 return config
222
223
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700224def print_banner(log):
Zsolt Harasztib71c2a02016-09-12 13:12:07 -0700225 log.info(' _ ______ __ ________ _____ ')
226 log.info('| | / / __ \/ / /_ __/ / / / |')
227 log.info('| | / / / / / / / / / /_/ / /| |')
228 log.info('| |/ / /_/ / /___/ / / __ / ___ |')
229 log.info('|___/\____/_____/_/ /_/ /_/_/ |_|')
Zsolt Haraszti59b7a882016-09-12 14:42:59 -0700230 log.info('(to stop: press Ctrl-C)')
Zsolt Harasztib71c2a02016-09-12 13:12:07 -0700231
232
Zsolt Harasztia17f3ec2016-12-08 14:55:49 -0800233@implementer(IComponent)
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700234class Main(object):
Zsolt Harasztia17f3ec2016-12-08 14:55:49 -0800235
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700236 def __init__(self):
Zsolt Haraszti1420def2016-09-18 00:07:31 -0700237
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700238 self.args = args = parse_args()
239 self.config = load_config(args)
Zsolt Haraszti1420def2016-09-18 00:07:31 -0700240
241 verbosity_adjust = (args.verbose or 0) - (args.quiet or 0)
Zsolt Haraszti109db832016-09-16 16:32:36 -0700242 self.log = setup_logging(self.config.get('logging', {}),
243 args.instance_id,
Zsolt Haraszti1420def2016-09-18 00:07:31 -0700244 verbosity_adjust=verbosity_adjust,
Zsolt Haraszti109db832016-09-16 16:32:36 -0700245 fluentd=args.fluentd)
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700246
Rouzbahan Rashidi-Tabrizi1c3eba82016-10-27 21:47:18 -0400247 # configurable variables from voltha.yml file
248 #self.configurable_vars = self.config.get('Constants', {})
249
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700250 if not args.no_banner:
251 print_banner(self.log)
Zsolt Harasztib71c2a02016-09-12 13:12:07 -0700252
khenb95fe9a2016-10-05 11:15:25 -0700253 self.startup_components()
254
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700255 if not args.no_heartbeat:
256 self.start_heartbeat()
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800257 self.start_kafka_heartbeat(args.instance_id)
Zsolt Harasztib71c2a02016-09-12 13:12:07 -0700258
Zsolt Haraszti3bfff662016-12-14 23:41:49 -0800259 self.manhole = None
260
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700261 def start(self):
262 self.start_reactor() # will not return except Keyboard interrupt
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700263
Zsolt Harasztia17f3ec2016-12-08 14:55:49 -0800264 def stop(self):
265 pass
266
267 def get_args(self):
268 """Allow access to command line args"""
269 return self.args
270
271 def get_config(self):
272 """Allow access to content of config file"""
273 return self.config
274
Zsolt Haraszti7eeb2b32016-11-06 14:04:55 -0800275 @inlineCallbacks
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700276 def startup_components(self):
Khen Nursimulu3c74d3b2016-11-08 15:14:01 -0800277 try:
278 self.log.info('starting-internal-components')
Zsolt Harasztidafefe12016-11-14 21:29:58 -0800279
Zsolt Harasztia17f3ec2016-12-08 14:55:49 -0800280 registry.register('main', self)
281
Zsolt Haraszti66862032016-11-28 14:28:39 -0800282 yield registry.register(
283 'coordinator',
284 Coordinator(
285 internal_host_address=self.args.internal_host_address,
286 external_host_address=self.args.external_host_address,
287 rest_port=self.args.rest_port,
288 instance_id=self.args.instance_id,
289 config=self.config,
290 consul=self.args.consul)
291 ).start()
Zsolt Harasztidafefe12016-11-14 21:29:58 -0800292
Khen Nursimulu3c74d3b2016-11-08 15:14:01 -0800293 init_rest_service(self.args.rest_port)
Zsolt Harasztieb435072016-09-23 17:10:49 -0700294
Zsolt Haraszti66862032016-11-28 14:28:39 -0800295 yield registry.register(
296 'grpc_server',
297 VolthaGrpcServer(self.args.grpc_port)
298 ).start()
Zsolt Harasztieb435072016-09-23 17:10:49 -0700299
Zsolt Haraszti66862032016-11-28 14:28:39 -0800300 yield registry.register(
301 'kafka_proxy',
Zsolt Haraszti99509d32016-12-10 16:41:45 -0800302 KafkaProxy(
303 self.args.consul,
304 self.args.kafka,
305 config=self.config.get('kafka-proxy', {})
306 )
Zsolt Haraszti66862032016-11-28 14:28:39 -0800307 ).start()
308
309 yield registry.register(
310 'core',
311 VolthaCore(
Zsolt Harasztidafefe12016-11-14 21:29:58 -0800312 instance_id=self.args.instance_id,
313 version=VERSION,
Zsolt Haraszti66862032016-11-28 14:28:39 -0800314 log_level=LogLevel.INFO
315 )
Ryan Van Gilder5a0ab622017-03-01 16:39:25 -0800316 ).start(config_backend=load_backend(self.args))
Zsolt Haraszti7eeb2b32016-11-06 14:04:55 -0800317
Zsolt Haraszti66862032016-11-28 14:28:39 -0800318 yield registry.register(
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800319 'frameio',
320 FrameIOManager()
321 ).start()
322
323 yield registry.register(
Zsolt Haraszti66862032016-11-28 14:28:39 -0800324 'adapter_loader',
325 AdapterLoader(config=self.config.get('adapter_loader', {}))
326 ).start()
khenb95fe9a2016-10-05 11:15:25 -0700327
Zsolt Haraszti99509d32016-12-10 16:41:45 -0800328 yield registry.register(
329 'diag',
330 Diagnostics(config=self.config.get('diagnostics', {}))
331 ).start()
332
Zsolt Haraszti3bfff662016-12-14 23:41:49 -0800333 if self.args.manhole_port is not None:
334 self.start_manhole(self.args.manhole_port)
335
Khen Nursimulu3c74d3b2016-11-08 15:14:01 -0800336 self.log.info('started-internal-services')
337
338 except Exception as e:
339 self.log.exception('Failure to start all components {}'.format(e))
340
Zsolt Haraszti3bfff662016-12-14 23:41:49 -0800341 def start_manhole(self, port):
342 self.manhole = Manhole(
343 port,
344 pws=dict(admin='adminpw'),
345 eventbus = EventBusClient(),
346 **registry.components
347 )
348
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700349 @inlineCallbacks
350 def shutdown_components(self):
351 """Execute before the reactor is shut down"""
352 self.log.info('exiting-on-keyboard-interrupt')
Zsolt Harasztidafefe12016-11-14 21:29:58 -0800353 for component in reversed(registry.iterate()):
354 yield component.stop()
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700355
Zsolt Haraszti3300f742017-01-09 01:14:20 -0800356 import threading
357 self.log.info('THREADS:')
358 main_thread = threading.current_thread()
359 for t in threading.enumerate():
360 if t is main_thread:
361 continue
362 if not t.isDaemon():
363 continue
364 self.log.info('joining thread {} {}'.format(
365 t.getName(), "daemon" if t.isDaemon() else "not-daemon"))
366 t.join()
367
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700368 def start_reactor(self):
369 from twisted.internet import reactor
Zsolt Haraszti109db832016-09-16 16:32:36 -0700370 reactor.callWhenRunning(
371 lambda: self.log.info('twisted-reactor-started'))
372 reactor.addSystemEventTrigger('before', 'shutdown',
373 self.shutdown_components)
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700374 reactor.run()
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700375
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700376 def start_heartbeat(self):
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700377
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700378 t0 = time.time()
379 t0s = time.ctime(t0)
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700380
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700381 def heartbeat():
382 self.log.debug(status='up', since=t0s, uptime=time.time() - t0)
Zsolt Harasztif2da1d02016-09-13 23:21:35 -0700383
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700384 lc = LoopingCall(heartbeat)
385 lc.start(10)
Zsolt Harasztib71c2a02016-09-12 13:12:07 -0700386
khenb95fe9a2016-10-05 11:15:25 -0700387 # Temporary function to send a heartbeat message to the external kafka
388 # broker
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800389 def start_kafka_heartbeat(self, instance_id):
khenb95fe9a2016-10-05 11:15:25 -0700390 # For heartbeat we will send a message to a specific "voltha-heartbeat"
391 # topic. The message is a protocol buf
392 # message
Zsolt Harasztib5d72f12017-01-15 20:44:02 -0800393 message = dict(
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800394 type='heartbeat',
395 voltha_instance=instance_id,
396 ip=get_my_primary_local_ipv4()
Zsolt Harasztib5d72f12017-01-15 20:44:02 -0800397 )
398 topic = "voltha.heartbeat"
khenb95fe9a2016-10-05 11:15:25 -0700399
Zsolt Harasztib5d72f12017-01-15 20:44:02 -0800400 def send_msg():
401 message['ts'] = arrow.utcnow().timestamp
402 kafka_proxy.send_message(topic, dumps(message))
403
Khen Nursimulu3c74d3b2016-11-08 15:14:01 -0800404 kafka_proxy = get_kafka_proxy()
405 if kafka_proxy:
Zsolt Harasztib5d72f12017-01-15 20:44:02 -0800406 lc = LoopingCall(send_msg)
Khen Nursimulu3c74d3b2016-11-08 15:14:01 -0800407 lc.start(10)
408 else:
409 self.log.error('Kafka proxy has not been created!')
Khen Nursimulu441dedd2016-10-05 14:44:26 -0700410
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800411
Zsolt Harasztib71c2a02016-09-12 13:12:07 -0700412if __name__ == '__main__':
Zsolt Harasztie060a7d2016-09-16 11:08:24 -0700413 Main().start()