Skip to content

Commit e48f524

Browse files
committed
refactor: API now rely on gnpy function without re-implementation
Change-Id: Ib71f62f74eaa9fd87606a977f1f2c830b71668d9
1 parent 6637ca8 commit e48f524

24 files changed

Lines changed: 280 additions & 20 deletions

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3.9-slim
2+
COPY . /oopt-gnpy-api
3+
WORKDIR /oopt-gnpy-api
4+
RUN apt update; apt install -y git
5+
RUN pip install .
6+
RUN mkdir -p /opt/application/oopt-gnpy/autodesign
7+
CMD [ "python", "./samples/rest_example.py" ]

gnpyapi/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
"""GNPy official API
44
"""
5+
from flask import Flask
6+
7+
app = Flask(__name__)

gnpyapi/core/exception/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# coding: utf-8
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# coding: utf-8
2+
3+
4+
class ConfigError(Exception):
5+
""" Exception raise for configuration file error
6+
Attributes:
7+
message -- explanation of the error
8+
"""
9+
10+
def __init__(self, message):
11+
self.message = message
12+
13+
def __str__(self):
14+
return self.message
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# coding: utf-8
2+
3+
4+
class EquipmentError(Exception):
5+
""" Exception raise for equipment error
6+
Attributes:
7+
message -- explanation of the error
8+
"""
9+
10+
def __init__(self, message):
11+
self.message = message
12+
13+
def __str__(self):
14+
return self.message
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# coding: utf-8
2+
import json
3+
import re
4+
5+
import werkzeug
6+
7+
from gnpyapi.core.model.error import Error
8+
9+
_reaesc = re.compile(r'\x1b[^m]*m')
10+
11+
12+
def common_error_handler(exception):
13+
"""
14+
15+
:type exception: Exception
16+
17+
"""
18+
status_code = 500
19+
if not isinstance(exception, werkzeug.exceptions.HTTPException):
20+
exception = werkzeug.exceptions.InternalServerError()
21+
exception.description = "Something went wrong on our side."
22+
else:
23+
status_code = exception.code
24+
response = Error(message=exception.name, description=exception.description,
25+
code=status_code)
26+
27+
return werkzeug.Response(response=json.dumps(response.__dict__), status=status_code, mimetype='application/json')
28+
29+
30+
def bad_request_handler(exception):
31+
exception_str = " ".join(str(exception).split())
32+
response = Error(message='bad request', description=_reaesc.sub('', exception_str.replace("\n", " ")),
33+
code=400)
34+
return werkzeug.Response(response=json.dumps(response.__dict__), status=400, mimetype='application/json')
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# coding: utf-8
2+
3+
4+
class PathComputationError(Exception):
5+
""" Exception raise for path computation error error
6+
Attributes:
7+
message -- explanation of the error
8+
"""
9+
10+
def __init__(self, message):
11+
self.message = message
12+
13+
def __str__(self):
14+
return self.message
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# coding: utf-8
2+
3+
class TopologyError(Exception):
4+
""" Exception raise for topology error
5+
Attributes:
6+
message -- explanation of the error
7+
"""
8+
9+
def __init__(self, message):
10+
self.message = message
11+
12+
def __str__(self):
13+
return self.message

gnpyapi/core/model/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# coding: utf-8

0 commit comments

Comments
 (0)