Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/nfv artifacts #2

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/app/app/api/api_v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

# ---Create a subapp---
nef_router = APIRouter()
nef_router.include_router(endpoints.testReport.router, prefix="/test-report/v1", tags=["Test Report API"])
nef_router.include_router(endpoints.monitoringevent.router, prefix="/3gpp-monitoring-event/v1", tags=["Monitoring Event API"])
nef_router.include_router(endpoints.qosMonitoring.router, prefix="/3gpp-as-session-with-qos/v1", tags=["Session With QoS API"])
nef_router.include_router(endpoints.bdtManagement.router, prefix="/3gpp-bdt/v1", tags=["Resource Management of Bdt API"])
Expand Down
3 changes: 2 additions & 1 deletion backend/app/app/api/api_v1/endpoints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .gNB import router
from .Cell import router
from .UE import router
from .testReport import router
from .qosInformation import router
from .qosMonitoring import router
from .monitoringevent import router
Expand All @@ -16,4 +17,4 @@
from .cpParameterProvisioning import router
from .pfdManagement import router
from .npConfiguration import router
from .racsProvisioning import router
from .racsProvisioning import router
141 changes: 26 additions & 115 deletions backend/app/app/api/api_v1/endpoints/bdtManagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi.responses import JSONResponse
from pymongo.database import Database
from sqlalchemy.orm import Session
from app import models, schemas
from app import models, schemas, tools
from app.api import deps
from app.crud import crud_mongo, user, ue
from app.db.session import client
Expand All @@ -14,26 +14,17 @@
router = APIRouter()
db_collection= 'BdtManagement'

@router.get("/{scsAsId}/subscriptions", response_model=List[schemas.Bdt])
@router.get("/{scsAsId}/subscriptions")
def read_active_subscriptions(
*,
scsAsId: str = Path(..., title="The ID of the Netapp that creates a subscription", example="myNetapp"),
current_user: models.User = Depends(deps.get_current_active_user),
http_request: Request
) -> Any:
"""
Read all active subscriptions
"""
db_mongo = client.fastapi
retrieved_docs = crud_mongo.read_all(db_mongo, db_collection, current_user.id)
endpoint = http_request.scope['route'].path
tools.reports.update_report(scsAsId, endpoint, "GET")
pass

#Check if there are any active subscriptions
if not retrieved_docs:
raise HTTPException(status_code=404, detail="There are no active subscriptions")

http_response = JSONResponse(content=retrieved_docs, status_code=200)
add_notifications(http_request, http_response, False)
return http_response

#Callback

Expand All @@ -43,7 +34,7 @@ def read_active_subscriptions(
def bdt_notification(body: schemas.ExNotification):
pass

@router.post("/{scsAsId}/subscriptions", responses={201: {"model" : schemas.Bdt}}, callbacks=bdt_callback_router.routes)
@router.post("/{scsAsId}/subscriptions")
def create_subscription(
*,
scsAsId: str = Path(..., title="The ID of the Netapp that creates a subscription", example="myNetapp"),
Expand All @@ -52,126 +43,46 @@ def create_subscription(
current_user: models.User = Depends(deps.get_current_active_user),
http_request: Request
) -> Any:
"""
Create new subscription.
"""
db_mongo = client.fastapi
json_data = jsonable_encoder(item_in)
json_data.update({'owner_id' : current_user.id})

inserted_doc = crud_mongo.create(db_mongo, db_collection, json_data)

#Create the reference resource and location header
link = str(http_request.url) + '/' + str(inserted_doc.inserted_id)
response_header = {"location" : link}

#Update the subscription with the new resource (link) and return the response (+response header)
crud_mongo.update_new_field(db_mongo, db_collection, inserted_doc.inserted_id, {"link" : link})

#Retrieve the updated document | UpdateResult is not a dict
updated_doc = crud_mongo.read_uuid(db_mongo, db_collection, inserted_doc.inserted_id)

updated_doc.pop("owner_id") #Remove owner_id from the response

http_response = JSONResponse(content=updated_doc, status_code=201, headers=response_header)
add_notifications(http_request, http_response, False)

return http_response
endpoint = http_request.scope['route'].path
json_item = jsonable_encoder(item_in)
tools.reports.update_report(scsAsId, endpoint, "POST", json_item)
pass

@router.get("/{scsAsId}/subscriptions/{subscriptionId}", response_model=schemas.Bdt)
def read_subscription(
@router.put("/{scsAsId}/subscriptions/{subscriptionId}")
def update_subscription(
*,
scsAsId: str = Path(..., title="The ID of the Netapp that creates a subscription", example="myNetapp"),
subscriptionId: str = Path(..., title="Identifier of the subscription resource"),
item_in: schemas.MonitoringEventSubscriptionCreate,
current_user: models.User = Depends(deps.get_current_active_user),
http_request: Request
) -> Any:
"""
Get subscription by id
"""
db_mongo = client.fastapi

try:
retrieved_doc = crud_mongo.read_uuid(db_mongo, db_collection, subscriptionId)
except Exception as ex:
raise HTTPException(status_code=400, detail='Please enter a valid uuid (24-character hex string)')

#Check if the document exists
if not retrieved_doc:
raise HTTPException(status_code=404, detail="Subscription not found")
#If the document exists then validate the owner
if not user.is_superuser(current_user) and (retrieved_doc['owner_id'] != current_user.id):
raise HTTPException(status_code=400, detail="Not enough permissions")

retrieved_doc.pop("owner_id")
http_response = JSONResponse(content=retrieved_doc, status_code=200)
add_notifications(http_request, http_response, False)
return http_response
endpoint = http_request.scope['route'].path
json_item = jsonable_encoder(item_in)
tools.reports.update_report(scsAsId, endpoint, "PUT", json_item, subscriptionId)
pass

@router.put("/{scsAsId}/subscriptions/{subscriptionId}", response_model=schemas.Bdt)
def update_subscription(
@router.get("/{scsAsId}/subscriptions/{subscriptionId}")
def read_subscription(
*,
scsAsId: str = Path(..., title="The ID of the Netapp that creates a subscription", example="myNetapp"),
subscriptionId: str = Path(..., title="Identifier of the subscription resource"),
item_in: schemas.MonitoringEventSubscriptionCreate,
current_user: models.User = Depends(deps.get_current_active_user),
http_request: Request
) -> Any:
"""
Update/Replace an existing subscription resource by id
"""
db_mongo = client.fastapi

try:
retrieved_doc = crud_mongo.read_uuid(db_mongo, db_collection, subscriptionId)
except Exception as ex:
raise HTTPException(status_code=400, detail='Please enter a valid uuid (24-character hex string)')

#Check if the document exists
if not retrieved_doc:
raise HTTPException(status_code=404, detail="Subscription not found")
#If the document exists then validate the owner
if not user.is_superuser(current_user) and (retrieved_doc['owner_id'] != current_user.id):
raise HTTPException(status_code=400, detail="Not enough permissions")

#Update the document
json_data = jsonable_encoder(item_in)
crud_mongo.update_new_field(db_mongo, db_collection, subscriptionId, json_data)
endpoint = http_request.scope['route'].path
tools.reports.update_report(scsAsId, endpoint, "GET", subs_id=subscriptionId)
pass

#Retrieve the updated document | UpdateResult is not a dict
updated_doc = crud_mongo.read_uuid(db_mongo, db_collection, subscriptionId)
updated_doc.pop("owner_id")
http_response = JSONResponse(content=updated_doc, status_code=200)
add_notifications(http_request, http_response, False)
return http_response

@router.delete("/{scsAsId}/subscriptions/{subscriptionId}", response_model=schemas.Bdt)
@router.delete("/{scsAsId}/subscriptions/{subscriptionId}")
def delete_subscription(
*,
scsAsId: str = Path(..., title="The ID of the Netapp that creates a subscription", example="myNetapp"),
subscriptionId: str = Path(..., title="Identifier of the subscription resource"),
current_user: models.User = Depends(deps.get_current_active_user),
http_request: Request
) -> Any:
"""
Delete a subscription
"""
db_mongo = client.fastapi

try:
retrieved_doc = crud_mongo.read_uuid(db_mongo, db_collection, subscriptionId)
except Exception as ex:
raise HTTPException(status_code=400, detail='Please enter a valid uuid (24-character hex string)')


#Check if the document exists
if not retrieved_doc:
raise HTTPException(status_code=404, detail="Subscription not found")
#If the document exists then validate the owner
if not user.is_superuser(current_user) and (retrieved_doc['owner_id'] != current_user.id):
raise HTTPException(status_code=400, detail="Not enough permissions")

crud_mongo.delete_by_uuid(db_mongo, db_collection, subscriptionId)
http_response = JSONResponse(content=retrieved_doc, status_code=200)
add_notifications(http_request, http_response, False)
return http_response
endpoint = http_request.scope['route'].path
tools.reports.update_report(scsAsId, endpoint, "DELETE", subs_id=subscriptionId)
pass
126 changes: 18 additions & 108 deletions backend/app/app/api/api_v1/endpoints/chargeableParty.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi.responses import JSONResponse
from pymongo.database import Database
from sqlalchemy.orm import Session
from app import models, schemas
from app import models, schemas, tools
from app.api import deps
from app.crud import crud_mongo, user, ue
from app.db.session import client
Expand All @@ -21,19 +21,9 @@ def read_active_subscriptions(
current_user: models.User = Depends(deps.get_current_active_user),
http_request: Request
) -> Any:
"""
Read all active transactions
"""
db_mongo = client.fastapi
retrieved_docs = crud_mongo.read_all(db_mongo, db_collection, current_user.id)

#Check if there are any active transactions
if not retrieved_docs:
raise HTTPException(status_code=404, detail="There are no active transactions")

http_response = JSONResponse(content=retrieved_docs, status_code=200)
add_notifications(http_request, http_response, False)
return http_response
endpoint = http_request.scope['route'].path
tools.reports.update_report(scsAsId, endpoint, "GET")
pass

#Callback

Expand All @@ -52,31 +42,10 @@ def create_subscription(
current_user: models.User = Depends(deps.get_current_active_user),
http_request: Request
) -> Any:
"""
Create new subscription.
"""
db_mongo = client.fastapi
json_data = jsonable_encoder(item_in)
json_data.update({'owner_id' : current_user.id})

inserted_doc = crud_mongo.create(db_mongo, db_collection, json_data)

#Create the reference resource and location header
link = str(http_request.url) + '/' + str(inserted_doc.inserted_id)
response_header = {"location" : link}

#Update the subscription with the new resource (link) and return the response (+response header)
crud_mongo.update_new_field(db_mongo, db_collection, inserted_doc.inserted_id, {"link" : link})

#Retrieve the updated document | UpdateResult is not a dict
updated_doc = crud_mongo.read_uuid(db_mongo, db_collection, inserted_doc.inserted_id)

updated_doc.pop("owner_id") #Remove owner_id from the response

http_response = JSONResponse(content=updated_doc, status_code=201, headers=response_header)
add_notifications(http_request, http_response, False)

return http_response
endpoint = http_request.scope['route'].path
json_item = jsonable_encoder(item_in)
tools.reports.update_report(scsAsId, endpoint, "POST", json_item)
pass

@router.get("/{scsAsId}/transactions/{transactionId}", response_model=schemas.ChargeableParty)
def read_subscription(
Expand All @@ -86,27 +55,10 @@ def read_subscription(
current_user: models.User = Depends(deps.get_current_active_user),
http_request: Request
) -> Any:
"""
Get transaction by id
"""
db_mongo = client.fastapi
endpoint = http_request.scope['route'].path
tools.reports.update_report(scsAsId, endpoint, "GET", trans_id=transactionId)
pass

try:
retrieved_doc = crud_mongo.read_uuid(db_mongo, db_collection, transactionId)
except Exception as ex:
raise HTTPException(status_code=400, detail='Please enter a valid uuid (24-character hex string)')

#Check if the document exists
if not retrieved_doc:
raise HTTPException(status_code=404, detail="Transaction not found")
#If the document exists then validate the owner
if not user.is_superuser(current_user) and (retrieved_doc['owner_id'] != current_user.id):
raise HTTPException(status_code=400, detail="Not enough permissions")

retrieved_doc.pop("owner_id")
http_response = JSONResponse(content=retrieved_doc, status_code=200)
add_notifications(http_request, http_response, False)
return http_response

@router.put("/{scsAsId}/transactions/{transactionId}", response_model=schemas.ChargeableParty)
def update_subscription(
Expand All @@ -117,33 +69,10 @@ def update_subscription(
current_user: models.User = Depends(deps.get_current_active_user),
http_request: Request
) -> Any:
"""
Update/Replace an existing transaction resource by id
"""
db_mongo = client.fastapi

try:
retrieved_doc = crud_mongo.read_uuid(db_mongo, db_collection, transactionId)
except Exception as ex:
raise HTTPException(status_code=400, detail='Please enter a valid uuid (24-character hex string)')

#Check if the document exists
if not retrieved_doc:
raise HTTPException(status_code=404, detail="Transaction not found")
#If the document exists then validate the owner
if not user.is_superuser(current_user) and (retrieved_doc['owner_id'] != current_user.id):
raise HTTPException(status_code=400, detail="Not enough permissions")

#Update the document
json_data = jsonable_encoder(item_in)
crud_mongo.update_new_field(db_mongo, db_collection, transactionId, json_data)

#Retrieve the updated document | UpdateResult is not a dict
updated_doc = crud_mongo.read_uuid(db_mongo, db_collection, transactionId)
updated_doc.pop("owner_id")
http_response = JSONResponse(content=updated_doc, status_code=200)
add_notifications(http_request, http_response, False)
return http_response
endpoint = http_request.scope['route'].path
json_item = jsonable_encoder(item_in)
tools.reports.update_report(scsAsId, endpoint, "PUT", json_item, trans_id=transactionId)
pass

@router.delete("/{scsAsId}/transactions/{transactionId}", response_model=schemas.ChargeableParty)
def delete_subscription(
Expand All @@ -153,25 +82,6 @@ def delete_subscription(
current_user: models.User = Depends(deps.get_current_active_user),
http_request: Request
) -> Any:
"""
Delete a subscription
"""
db_mongo = client.fastapi

try:
retrieved_doc = crud_mongo.read_uuid(db_mongo, db_collection, transactionId)
except Exception as ex:
raise HTTPException(status_code=400, detail='Please enter a valid uuid (24-character hex string)')


#Check if the document exists
if not retrieved_doc:
raise HTTPException(status_code=404, detail="Transaction not found")
#If the document exists then validate the owner
if not user.is_superuser(current_user) and (retrieved_doc['owner_id'] != current_user.id):
raise HTTPException(status_code=400, detail="Not enough permissions")

crud_mongo.delete_by_uuid(db_mongo, db_collection, transactionId)
http_response = JSONResponse(content=retrieved_doc, status_code=200)
add_notifications(http_request, http_response, False)
return http_response
endpoint = http_request.scope['route'].path
tools.reports.update_report(scsAsId, endpoint, "DELETE", trans_id=transactionId)
pass
Loading