Skip to content
This repository was archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #31 from 5GEVE/fix-threads
Browse files Browse the repository at this point in the history
Fix threads
  • Loading branch information
TheWall89 authored May 29, 2020
2 parents 9e34211 + 24c5602 commit aaf9a75
Show file tree
Hide file tree
Showing 17 changed files with 461 additions and 403 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.6 as base
FROM python:3.6-slim as base
EXPOSE 5000
RUN apt-get update && apt-get install -y python3-dev
RUN apt-get update && apt-get install -y build-essential
RUN ["pip3", "install", "pipenv"]
ENV PIPENV_VENV_IN_PROJECT 1
WORKDIR /usr/src/app
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ and insert your NFVO data.
Deploy with:

```shell script
docker pull python:3.6
docker pull python:3.6-slim
docker-compose build
docker-compose up
```
Expand All @@ -63,7 +63,7 @@ SITEINV_INTERVAL: '300'
Then, deploy with:

```shell script
docker pull python:3.6
docker pull python:3.6-slim
docker-compose build
docker-compose up
```
Expand Down Expand Up @@ -128,6 +128,18 @@ pipenv run python manage.py seed
FLASK_ENV=development flask run
```

Some features like notifications need [celery](https://docs.celeryproject.org/en/stable/index.html) and
[redis](https://redislabs.com/).
Simply setup a docker container with redis and run a celery worker.

```shell script
docker run -p 6379:6379 --name some-redis -d redis
export REDIS_HOST=localhost
celery -A tasks worker -B --loglevel=info
```

---

Please, always use `pipenv` to add dependencies:

```shell script
Expand Down
4 changes: 2 additions & 2 deletions adaptation_layer/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ robotframework-mockserver = "*"

[packages]
flask = "==1.0.2"
pycurl = "*"
requests = "*"
pyaml = "*"
uwsgi = "*"
Expand All @@ -26,7 +25,8 @@ pytest = "*"
jsonschema = "*"
prance = "*"
openapi-spec-validator = "*"
apscheduler = "==3.6.3"
celery = "==4.4.2"
redis = "==3.5.2"

[requires]
python_version = "3.6"
86 changes: 50 additions & 36 deletions adaptation_layer/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 5 additions & 15 deletions adaptation_layer/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,35 @@
# limitations under the License.
import logging
import os
from datetime import datetime

from apscheduler.schedulers.background import BackgroundScheduler
from flask import jsonify, abort, request, make_response, Flask
from flask_migrate import Migrate
from requests import HTTPError

import config
import driver.manager as manager
import siteinventory
import sqlite
import tasks
from error_handler import NfvoNotFound, NsNotFound, NsdNotFound, \
init_errorhandler, NfvoCredentialsNotFound, SubscriptionNotFound
from error_handler import Unauthorized, BadRequest, ServerError, NsOpNotFound
from notifications import forward_notification

SITEINV = os.getenv('SITEINV', 'false').lower()

logging.basicConfig(level=logging.INFO)
app = Flask(__name__)
app.config.from_object(config.Config)
init_errorhandler(app)
notif_sched = BackgroundScheduler({'apscheduler.timezone': 'UTC'})
notif_sched.start()

if SITEINV == 'true':
app.logger.info('using siteinventory')
database = siteinventory.SiteInventory()
database = siteinventory
tasks.post_osm_vims.delay()
else:
app.logger.info('using sqlite')
sqlite.db.init_app(app)
migrate = Migrate(app, sqlite.db)
database = sqlite.SQLite()
database = sqlite


@app.route('/nfvo', methods=['GET'])
Expand Down Expand Up @@ -291,13 +287,7 @@ def post_notification(nfvo_id):
required = ('nsInstanceId', 'operation', 'operationState')
if not all(k in request.json for k in required):
abort(400, 'One of {0} is missing'.format(str(required)))
try:
subs = database.search_subs_by_ns_instance(request.json['nsInstanceId'])
notif_sched.add_job(forward_notification,
'date', run_date=datetime.utcnow(),
args=[request.json, subs])
except (ServerError, HTTPError) as e:
abort(500, description=e.description)
tasks.forward_notification.delay(request.json)
return make_response('', 204)


Expand Down
50 changes: 0 additions & 50 deletions adaptation_layer/database.py

This file was deleted.

28 changes: 11 additions & 17 deletions adaptation_layer/driver/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from database import Database
from .interface import Driver
from .onap import ONAP
from .osm import OSM

_drivers = {}


def get_driver(nfvo_id: int, db: Database) -> Driver:
global _drivers
if nfvo_id not in _drivers:
nfvo = db.get_nfvo_by_id(nfvo_id)
nfvo_type = nfvo['type'].casefold()
nfvo_cred = db.get_nfvo_cred(nfvo_id)
if nfvo_type == 'osm':
_drivers[nfvo_id] = OSM(nfvo_cred)
elif nfvo_type == 'onap':
_drivers[nfvo_id] = ONAP(nfvo_cred)
else:
raise NotImplementedError(
'Driver type: {} is not implemented'.format(nfvo_type))
return _drivers[nfvo_id]
def get_driver(nfvo_id: int, db) -> Driver:
nfvo = db.get_nfvo_by_id(nfvo_id)
nfvo_type = nfvo['type'].casefold()
nfvo_cred = db.get_nfvo_cred(nfvo_id)
if nfvo_type == 'osm':
return OSM(nfvo_cred)
elif nfvo_type == 'onap':
return ONAP(nfvo_cred)
else:
raise NotImplementedError(
'Driver type: {} is not implemented'.format(nfvo_type))
8 changes: 1 addition & 7 deletions adaptation_layer/driver/osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,9 @@ def scale_ns(self, nsId: str, args=None) -> Tuple[None, Headers]:

@_authenticate
def get_op_list(self, args: Dict = None) -> Tuple[BodyList, Headers]:
nsId = args['args']['nsInstanceId'] \
if args['args'] and 'nsInstanceId' in args['args'] else None
_url = "{0}/nslcm/v1/ns_lcm_op_occs".format(self._base_path)
_url = self._build_url_query(_url, args)
try:
osm_op_list, osm_headers = self._exec_get(
_url, headers=self._headers)
except ResourceNotFound:
raise NsNotFound(ns_id=nsId)
osm_op_list, osm_headers = self._exec_get(_url, headers=self._headers)
sol_op_list = []
for op in osm_op_list:
sol_op_list.append(self._op_im_converter(op))
Expand Down
Loading

0 comments on commit aaf9a75

Please sign in to comment.