Connect entity ident service with orchestrator

This commit is contained in:
David Eder 2021-06-01 22:19:06 +02:00
parent 16fa564e22
commit 5acfcd23da
3 changed files with 24 additions and 12 deletions

View File

@ -3,18 +3,21 @@
"id": "1", "id": "1",
"location": [16.0, 48.0], "location": [16.0, 48.0],
"range": 2000, "range": 2000,
"switchingTime": 500 "switchingTime": 500,
"initialColor": "RED"
}, },
{ {
"id": "2", "id": "2",
"location": [16.0, 48.1], "location": [16.0, 48.1],
"range": 800, "range": 800,
"switchingTime": 240 "switchingTime": 240,
"initialColor": "GREEN"
}, },
{ {
"id": "3", "id": "3",
"location": [16.0, 48.2], "location": [16.0, 48.2],
"range": 1000, "range": 1000,
"switchingTime": 360 "switchingTime": 360,
"initialColor": "RED"
} }
] ]

View File

@ -3,6 +3,7 @@ import sys
from random import randrange from random import randrange
from typing import List, Dict from typing import List, Dict
import requests
from dse_shared_libs import daf from dse_shared_libs import daf
from dse_shared_libs.traffic_light_color import TrafficLightColor from dse_shared_libs.traffic_light_color import TrafficLightColor
from dse_shared_libs.message_broker_wrapper import MBWrapper from dse_shared_libs.message_broker_wrapper import MBWrapper
@ -25,18 +26,25 @@ class Orchestrator:
_velocity_mbs: Dict[str, MBWrapper] = {} _velocity_mbs: Dict[str, MBWrapper] = {}
def __init__(self): def __init__(self):
# TODO fetch available car VINs from Entity Ident
self.vins.append('SB164ABN1PE082000')
self.vins.append('SB999ABN1PE082111')
self.vins.append('SB555ABN1PE082555')
print('vins', self.vins)
# TODO fetch available TLs from Entity Ident ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/'
self.tls['traffic-light-1'] = {'color': TrafficLightColor.RED, 'switching_time': 120}
self.tls['traffic-light-2'] = {'color': TrafficLightColor.GREEN, 'switching_time': 240} response = requests.get(ENTITY_IDENT_URL + 'cars')
self.tls['traffic-light-3'] = {'color': TrafficLightColor.RED, 'switching_time': 360} cars = response.json()
response = requests.get(ENTITY_IDENT_URL + 'traffic_lights')
traffic_lights = response.json()
for traffic_light in traffic_lights['cursor']:
self.tls[traffic_light['id']] = {'color': traffic_light['initialColor'], 'switching_time': traffic_light['switchingTime']}
print('tls', self.tls) print('tls', self.tls)
for car in cars['cursor']:
self.vins.append(car['vin'])
print('vins', self.vins)
def setup_msg_queues(self): def setup_msg_queues(self):
# spawn the vehicle related message broker channels # spawn the vehicle related message broker channels
for vin in self.vins: for vin in self.vins:

View File

@ -1,2 +1,3 @@
flask flask
geopy geopy
requests