diff --git a/components/entitiy_ident/mongo/traffic_lights.json b/components/entitiy_ident/mongo/traffic_lights.json index dc3b4c4..c641bdc 100644 --- a/components/entitiy_ident/mongo/traffic_lights.json +++ b/components/entitiy_ident/mongo/traffic_lights.json @@ -3,18 +3,21 @@ "id": "1", "location": [16.0, 48.0], "range": 2000, - "switchingTime": 500 + "switchingTime": 500, + "initialColor": "RED" }, { "id": "2", "location": [16.0, 48.1], "range": 800, - "switchingTime": 240 + "switchingTime": 240, + "initialColor": "GREEN" }, { "id": "3", "location": [16.0, 48.2], "range": 1000, - "switchingTime": 360 + "switchingTime": 360, + "initialColor": "RED" } ] \ No newline at end of file diff --git a/components/orchestration/orchestrator.py b/components/orchestration/orchestrator.py index d377503..2b04a73 100644 --- a/components/orchestration/orchestrator.py +++ b/components/orchestration/orchestrator.py @@ -3,6 +3,7 @@ import sys from random import randrange from typing import List, Dict +import requests from dse_shared_libs import daf from dse_shared_libs.traffic_light_color import TrafficLightColor from dse_shared_libs.message_broker_wrapper import MBWrapper @@ -25,18 +26,25 @@ class Orchestrator: _velocity_mbs: Dict[str, MBWrapper] = {} 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 - self.tls['traffic-light-1'] = {'color': TrafficLightColor.RED, 'switching_time': 120} - self.tls['traffic-light-2'] = {'color': TrafficLightColor.GREEN, 'switching_time': 240} - self.tls['traffic-light-3'] = {'color': TrafficLightColor.RED, 'switching_time': 360} + ENTITY_IDENT_URL = 'http://entityident:5002/api/v1/resources/' + + response = requests.get(ENTITY_IDENT_URL + 'cars') + 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) + for car in cars['cursor']: + self.vins.append(car['vin']) + + print('vins', self.vins) + def setup_msg_queues(self): # spawn the vehicle related message broker channels for vin in self.vins: diff --git a/components/orchestration/requirements.txt b/components/orchestration/requirements.txt index c1233dc..61d6c22 100644 --- a/components/orchestration/requirements.txt +++ b/components/orchestration/requirements.txt @@ -1,2 +1,3 @@ flask geopy +requests \ No newline at end of file