Skip to content

Commit

Permalink
minimal edits to support changes to multicontainer implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AadilLatif committed Mar 26, 2024
1 parent 79c391f commit 2e4948d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
1 change: 0 additions & 1 deletion LocalFeeder/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,4 @@ async def configure(component_struct:ComponentStruct):
return JSONResponse(response, 200)

if __name__ == "__main__":
port = int(sys.argv[2])
uvicorn.run(app, host="0.0.0.0", port=int(os.environ['PORT']))
2 changes: 1 addition & 1 deletion broker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ RUN pip install -r requirements.txt

EXPOSE 8766/tcp

CMD ["python", "server.py", "10.5.0.2", "8766"]
CMD ["python", "server.py"]
28 changes: 16 additions & 12 deletions broker/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
from oedisi.componentframework.system_configuration import WiringDiagram, ComponentStruct
from oedisi.types.common import ServerReply, HeathCheck


logger = logging.getLogger('uvicorn.error')


app = FastAPI()

is_kubernetes_env = os.environ['KUBERNETES_SERVICE_NAME'] if 'KUBERNETES_SERVICE_NAME' in os.environ else None
Expand Down Expand Up @@ -86,7 +90,7 @@ async def upload_profiles(file: UploadFile):
f.write(data)

url = build_url(ip, port, ["profiles"])
logging.info(f"making a request to url - {url}")
logger.info(f"making a request to url - {url}")

files = {"file": open(file.filename, "rb")}
r = requests.post(url, files=files)
Expand Down Expand Up @@ -115,7 +119,7 @@ async def upload_model(file: UploadFile):
f.write(data)

url = build_url(ip, port, ["model"])
logging.info(f"making a request to url - {url}")
logger.info(f"making a request to url - {url}")

files = {"file": open(file.filename, "rb")}
r = requests.post(url, files=files)
Expand All @@ -135,10 +139,10 @@ def download_results():
port = int(services[service]["ports"][0].split(":")[0])

url = build_url(host, port, ["download"])
logging.info(f"making a request to url - {url}")
logger.info(f"making a request to url - {url}")

response = requests.get(url)
logging.info(f"Response from {service} has {len(response.content)} bytes")
logger.info(f"Response from {service} has {len(response.content)} bytes")
with open(f"{service}.feather", "wb") as out_file:
out_file.write(response.content)

Expand All @@ -164,19 +168,20 @@ def terminate_simulation():

def run_simulation():
services, component_map, broker_ip, api_port = read_settings()
logging.info(f"{broker_ip}, {api_port}")
print(services)
logger.info(f"{broker_ip}, {api_port}")
initstring = f"-f {len(component_map)} --name=mainbroker --loglevel=trace --local_interface={broker_ip} --localport=23404"
logging.info(f"Broker initaialization string: {initstring}")
logger.info(f"Broker initaialization string: {initstring}")
broker = h.helicsCreateBroker("zmq", "", initstring)
logging.info(broker)
logger.info(broker)
isconnected = h.helicsBrokerIsConnected(broker)
logging.info(f"Broker connected: {isconnected}")
logging.info(str(component_map))
logger.info(f"Broker connected: {isconnected}")
logger.info(str(component_map))
replies = []
for service_ip, service_port in component_map.items():

url = build_url(service_ip, service_port, ["run"])
logging.info(f"making a request to url - {url}")
logger.info(f"making a request to url - {url}")

myobj = {
"broker_port": 23404,
Expand Down Expand Up @@ -217,12 +222,11 @@ async def configure(wiring_diagram:WiringDiagram):
component_model.links.append(link)

url = build_url(component.host, component.container_port, ["configure"])
logging.info(f"making a request to url - {url}")
logger.info(f"making a request to url - {url}")

r = requests.post(url, json=component_model.dict())
assert r.status_code==200, f"POST request to update configuration failed for url - {url}"
return JSONResponse(ServerReply(detail="Sucessfully updated config files for all containers").dict(), 200)

if __name__ == "__main__":
port = int(sys.argv[2])
uvicorn.run(app, host="0.0.0.0", port=int(os.environ['PORT']))
1 change: 0 additions & 1 deletion measuring_federate/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,5 @@ async def configure(component_struct:ComponentStruct):
return JSONResponse(response, 200)

if __name__ == "__main__":
port = int(sys.argv[2])
uvicorn.run(app, host="0.0.0.0", port=int(os.environ['PORT']))

1 change: 0 additions & 1 deletion recorder/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,4 @@ async def configure(component_struct:ComponentStruct):
return JSONResponse(response, 200)

if __name__ == "__main__":
port = int(sys.argv[2])
uvicorn.run(app, host="0.0.0.0", port=int(os.environ['PORT']))
1 change: 0 additions & 1 deletion wls_federate/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,4 @@ async def configure(component_struct:ComponentStruct):
return JSONResponse(response, 200)

if __name__ == "__main__":
port = int(sys.argv[2])
uvicorn.run(app, host="0.0.0.0", port=int(os.environ['PORT']))

0 comments on commit 2e4948d

Please sign in to comment.