Commit 3b87caf9 authored by Jean-Didier Totow's avatar Jean-Didier Totow
Browse files

camel converter first deployment

parent 6fe5fe32
FROM openjdk:slim
COPY --from=python:3.9 / /
COPY requirements.txt /app/requirements.txt
ADD src /app/src
RUN pip install --upgrade pip
RUN pip install -r /app/requirements.txt
EXPOSE 7676
WORKDIR /app/src
ENTRYPOINT ["python", "-u","app.py"]
version: '3'
services:
camel_converter:
image: jdtotow/camel_converter
build:
context: .
container_name: camel_converter
ports:
- 7676:7676
environment:
- PAASAGE_CONFIG_DIR=.paasage #please change it or remove it
- CDO_RESOURCE_PATH=/cdo_path #please change it
volumes:
- ./models:/app/src/models
pyjnius
fastapi
uvicorn
host=localhost
port=2036
repository=repo1
logging=on
userName=morphemic
password=morphemic
\ No newline at end of file
import json, time, os, uvicorn
from fastapi import FastAPI
from loader import CDOClientWapper
from pydantic import BaseModel
model_folder = os.environ.get("MODEL_FOLDER","./models")
class ExportRequest(BaseModel):
resource_name: str
filename: str
class ImportRequest(BaseModel):
resource_name: str
filename: str
app = FastAPI()
@app.post("/import_model")
async def import_model(request: ImportRequest):
filename = model_folder + request.filename
try:
client = CDOClientWapper()
status = client.importModel(filename, request.resource_name)
return {"response": status}
except Exception as e:
return {"response": "error", "message": e}
@app.post("/export_model")
async def export_model(request: ExportRequest):
filename = model_folder + request.filename
try:
client = CDOClientWapper()
status = client.exportModel(filename, request.resource_name)
return {"response": status}
except Exception as e:
return {"response": "error", "message": e}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=7676)
\ No newline at end of file
import os
os.environ["CLASSPATH"] = "./lib/client-repackaged.jar"
os.environ['PAASAGE_CONFIG_DIR'] = os.environ.get("PAASAGE_CONFIG_DIR",".paasage")
from jnius import autoclass
CDOClientClass = autoclass("eu.paasage.mddb.cdo.client.CDOClient")
resource_path = os.environ.get("CDO_RESOURCE_PATH","/users/cdo/")
class CDOClientWapper():
def __init__(self, username=None, password=None):
self.username = username
self.password = password
self.cdo_client = None
self.initialize()
def initialize(self):
if self.username and self.password:
self.cdo_client = CDOClientClass(self.username, self.password)
else:
self.cdo_client = CDOClientClass()
def importModel(self, filename, resource_name):
full_path = resource_path + resource_name
return self.cdo_client.importModel(filename, full_path, True) #True for validating model before storing
def exportModel(self, filename, resource_name):
full_path = resource_path + resource_name
return self.cdo_client.exportModel(full_path, filename)
import requests, json
url_camel_converter = "http://localhost:7676/import_model"
_request = {"filename": "camel-1.xmi", "resource_name": "res-name"}
response = requests.post(url=url_camel_converter, data=json.dumps(_request), headers={"Content-type": "application/json"})
print(response.text)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment