Skip to content

Commit db867e2

Browse files
committed
Merge branch 'fix-generic-manager-relationships' into 'master'
Fix generic manager relationships Closes #29 See merge request acs/public/villas/controller!24
2 parents eb40676 + a566a72 commit db867e2

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

doc/openapi.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ info:
1212
url: https://www.apache.org/licenses/LICENSE-2.0
1313

1414
servers:
15-
- url: https://villas.k8s.eonerc.rwth-aachen.de/api/v1
15+
- url: https://villas.k8s.eonerc.rwth-aachen.de/controller/api/v1
1616
description: Demo instance at RWTH Aachen
1717

1818
paths:

villas/controller/api.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
REGEX_UUID = r'\b[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}-[0-9a-fA-F]' \
99
r'{4}-[0-9a-fA-F]{4}-\b[0-9a-fA-F]{12}\b'
1010

11+
BASE = '/api/v1'
12+
1113

1214
class RequestHandler(tornado.web.RequestHandler):
1315

@@ -32,7 +34,7 @@ def run(self):
3234
port = self.controller.config.api.port
3335
self.app.listen(port)
3436

35-
LOGGER.info('Starting API')
37+
LOGGER.info('Starting API at http://localhost:%d%s', port, BASE)
3638

3739
self.loop = IOLoop.current(instance=True)
3840
self.loop.start()
@@ -48,7 +50,7 @@ def handlers(self):
4850
}
4951

5052
return [
51-
(r'/', MainRequestHandler, args),
52-
(r'/health', HealthRequestHandler, args),
53-
(r'/component/('+REGEX_UUID+r')', ComponentRequestHandler, args)
53+
(BASE + r'/', MainRequestHandler, args),
54+
(BASE + r'/health', HealthRequestHandler, args),
55+
(BASE + r'/component/('+REGEX_UUID+r')', ComponentRequestHandler, args) # noqa E501
5456
]

villas/controller/config.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44
import os
55
import dotmap
6+
from typing import List
67

78
from os import getcwd
89
from xdg import (
@@ -75,7 +76,7 @@ def find_default_path(self, filename='config',
7576
return fn
7677

7778
@property
78-
def components(self):
79+
def components(self) -> List[Component]:
7980
return [Component.from_dict(c) for c in self.config.components]
8081

8182
def __getattr__(self, attr):

villas/controller/controller.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from villas.controller.api import Api
99
from villas.controller import __version__ as version
10+
from villas.controller.config import Config
1011
from villas.controller.components.managers.generic import GenericManager
1112

1213

@@ -17,25 +18,25 @@ class ControllerMixin(kombu.mixins.ConsumerProducerMixin):
1718

1819
def __init__(self, connection, args):
1920
self.args = args
20-
self.config = args.config
21+
self.config: Config = args.config
2122

22-
comps = self.config.components
23-
self.components = {c.uuid: c for c in comps if c.enabled}
2423
self.connection = connection
2524
self.exchange = kombu.Exchange(name='villas',
2625
type='headers',
2726
durable=True)
2827

2928
self.publish_queue = queue.Queue()
3029

30+
# Components are activated by first call to on_iteration()
31+
self.components = {}
32+
self.active_components = {}
33+
3134
manager = self.add_managers()
3235

33-
for _, comp in self.components.items():
36+
comps = [c for c in self.config.components if c.enabled]
37+
for comp in comps:
3438
LOGGER.info('Adding %s', comp)
35-
comp.set_manager(manager)
36-
37-
# Components are activated by first call to on_iteration()
38-
self.active_components = {}
39+
manager.add_component(comp)
3940

4041
def get_consumers(self, _, channel):
4142
return map(lambda comp: comp.get_consumer(channel),
@@ -59,6 +60,8 @@ def add_managers(self):
5960
location=socket.gethostname()
6061
)
6162

63+
mgr.mixin = self
64+
6265
self.components[mgr.uuid] = mgr
6366
else:
6467
mgr = mgrs[0]

0 commit comments

Comments
 (0)