Skip to content

Commit

Permalink
Merge pull request #67 from openEDI/al/config
Browse files Browse the repository at this point in the history
new implementation for multicontainer use case
  • Loading branch information
AadilLatif authored Apr 16, 2024
2 parents 1369855 + 1173caa commit e4bdf56
Show file tree
Hide file tree
Showing 17 changed files with 526 additions and 144 deletions.
9 changes: 9 additions & 0 deletions LocalFeeder/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.10.6-slim-bullseye
RUN apt-get update
RUN apt-get install -y git ssh
RUN mkdir LocalFeeder
COPY . ./LocalFeeder
WORKDIR ./LocalFeeder
RUN pip install -r requirements.txt
EXPOSE 5678/tcp
CMD ["python", "server.py"]
2 changes: 1 addition & 1 deletion LocalFeeder/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ boto3
xarray
fastapi
uvicorn
oedisi==1.2.1
oedisi
python-multipart
50 changes: 33 additions & 17 deletions LocalFeeder/server.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
from fastapi import FastAPI, BackgroundTasks, UploadFile, Request
from fastapi.exceptions import HTTPException
from fastapi.responses import JSONResponse
from sender_cosim import run_simulator
import traceback
import asyncio
import json
import logging
import os
import zipfile
import uvicorn
import socket
import sys
import json
import time
import traceback
import zipfile
import sys
import os

import uvicorn
from fastapi import BackgroundTasks, FastAPI, Request, UploadFile
from fastapi.exceptions import HTTPException
from fastapi.responses import JSONResponse
from oedisi.types.common import BrokerConfig, HeathCheck, ServerReply
from sender_cosim import run_simulator
from oedisi.componentframework.system_configuration import ComponentStruct
from oedisi.types.common import ServerReply, HeathCheck, DefaultFileNames
from oedisi.types.common import BrokerConfig

REQUEST_TIMEOUT_SEC = 1200

Expand Down Expand Up @@ -49,7 +51,7 @@ def read_root():
return JSONResponse(response, 200)


@app.get("/sensor/")
@app.get("/sensor")
async def sensor():
logging.info(os.getcwd())
sensor_path = os.path.join(base_path, "sensors", "sensors.json")
Expand All @@ -61,7 +63,7 @@ async def sensor():
return data


@app.post("/profiles/")
@app.post("/profiles")
async def upload_profiles(file: UploadFile):
try:
data = file.file.read()
Expand Down Expand Up @@ -94,7 +96,7 @@ async def upload_profiles(file: UploadFile):
)


@app.post("/model/")
@app.post("/model")
async def upload_model(file: UploadFile):
try:
data = file.file.read()
Expand Down Expand Up @@ -123,7 +125,7 @@ async def upload_model(file: UploadFile):
HTTPException(500, "Unknown error while uploading userdefined opendss model.")


@app.post("/run/")
@app.post("/run")
async def run_feeder(
broker_config: BrokerConfig, background_tasks: BackgroundTasks
): # :BrokerConfig
Expand All @@ -138,6 +140,20 @@ async def run_feeder(
HTTPException(500, str(err))


@app.post("/configure")
async def configure(component_struct:ComponentStruct):
component = component_struct.component
params = component.parameters
params["name"] = component.name
links = {}
for link in component_struct.links:
links[link.target_port] = f"{link.source}/{link.source_port}"
json.dump(links , open(DefaultFileNames.INPUT_MAPPING.value, "w"))
json.dump(params , open(DefaultFileNames.STATIC_INPUTS.value, "w"))
response = ServerReply(
detail = f"Sucessfully updated configuration files."
).dict()
return JSONResponse(response, 200)

if __name__ == "__main__":
port = int(sys.argv[2])
uvicorn.run(app, host="0.0.0.0", port=port)
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"]
19 changes: 19 additions & 0 deletions broker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
networks:
custom-network:
driver: bridge
ipam:
config:
- gateway: 10.5.0.1
subnet: 10.5.0.0/16
services:
oedisi_broker:
build:
context: ./broker/.
environment:
PORT: '8766'
hostname: broker
image: aadillatif/oedisi_broker
networks:
custom-network: {}
ports:
- 8766:8766
2 changes: 1 addition & 1 deletion broker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ helics-apps==3.4.0
pyyaml
fastapi
uvicorn
oedisi==1.2.1
oedisi
grequests
python-multipart
Loading

0 comments on commit e4bdf56

Please sign in to comment.