Commit ea53f899 authored by Karagkounis Dimitris's avatar Karagkounis Dimitris
Browse files

add support for application submission

parent a06eae69
Loading
Loading
Loading
Loading
+7 −4
Changes for edge_cloud_management_api/controllers/app_controllers.py: 7 added lines, 4 removed lines.
Original line number Diff line number Diff line
import uuid
from flask import jsonify

from pydantic import ValidationError
from edge_cloud_management_api.managers.db_manager import MongoManager
from edge_cloud_management_api.managers.log_manager import logger
from edge_cloud_management_api.models.application_models import AppManifest

@@ -12,12 +14,13 @@ def submit_app(body: dict):
    try:
        # Validate the input data using Pydantic
        validated_data = AppManifest(**body)

        validated_data_dict = validated_data.model_dump(mode="json")
        validated_data_dict["_id"] = str(uuid.uuid4())
        # Insert into MongoDB
        # app_id = mongo.db.applications.insert_one(validated_data.dict()).inserted_id
        app_id = 3
        with MongoManager() as db:
            document_id = db.insert_document("apps", validated_data_dict)
            return (
            jsonify({"message": "Application submitted successfully!", "appId": str(app_id)}),
                jsonify({"appId": str(document_id)}),
                201,
            )

+5 −5
Changes for edge_cloud_management_api/models/application_models.py: 5 added lines, 5 removed lines.
Original line number Diff line number Diff line
from pydantic import UUID4, BaseModel, HttpUrl, Field
from typing import List, Optional
from ipaddress import IPv4Address, IPv6Address
from pydantic import BaseModel, HttpUrl, Field  # , UUID4
from typing import Any, List, Optional
from enum import Enum
# from ipaddress import IPv4Address, IPv6Address

# from edge_cloud_management_api.models.edge_cloud_models import EdgeCloudZone

@@ -105,14 +105,14 @@ class AppManifest(BaseModel):
        memory: int
        storage: int

    appId: Optional[UUID4]
    # appId: Optional[UUID4]
    name: str = Field(..., pattern="^[A-Za-z][A-Za-z0-9_]{1,63}$")
    appProvider: str = Field(..., pattern="^[A-Za-z][A-Za-z0-9_]{7,63}$")
    version: str  # application version
    packageType: PackageType
    operatingSystem: Optional[OperatingSystem]
    appRepo: AppRepo
    requiredResources: RequiredResources
    requiredResources: Any  # Optional[RequiredResources]
    componentSpec: List[ComponentSpec]


+0 −1
Changes for tests/fixtures/submit_app.json: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
{
    "appId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "name": "H38L1jMMndtyRR3WFCSI_he_m4NwQ0rggZYrOX9r09shL597SF4bGHoqUI5t",
    "appProvider": "rQxQr3mSdo3dgYZTh1Hq55CWIqsEPHqB80P9_ja3HH8Bp9Hj9Ygc",
    "version": "string",
+23 −5
Changes for tests/unit/controllers/test_app_controllers.py: 23 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -39,11 +39,28 @@ def mock_get_all_cloud_zones():
        yield mock_function


example_submit_input = {
    "name": "etO2zndyzpL1P",
    "appProvider": "TBPhbx4MO6n",
    "version": "string",
    "packageType": "QCOW2",
    "operatingSystem": {"architecture": "x86_64", "family": "RHEL", "version": "OS_VERSION_UBUNTU_2204_LTS", "license": "OS_LICENSE_TYPE_FREE"},
    "appRepo": {
        "type": "PRIVATEREPO",
        "imagePath": "https://charts.bitnami.com/bitnami/helm/example-chart:0.1.0",
        "userName": "string",
        "credentials": "string",
        "authType": "DOCKER",
        "checksum": "string",
    },
    "requiredResources": {},
    "componentSpec": [{"componentName": "string", "networkInterfaces": [{"interfaceId": "zKJ9YWHujxe73gorEzEImKfr6", "protocol": "TCP", "port": 65535, "visibilityType": "VISIBILITY_EXTERNAL"}]}],
}


@pytest.mark.parametrize(
    "x_correlator, body, expected_response_status, expected_response_body",
    [
        (None, {}, 201, {"appId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"}),
    ],
    [(None, example_submit_input, 201, {"appId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"})],
)
def test_submit_app(
    x_correlator,
@@ -57,11 +74,12 @@ def test_submit_app(
    Test the get_edge_cloud_zones controller.
    """
    with test_app.test_request_context():
        response, response_status = submit_app(x_correlator, body)
        response, response_status = submit_app(body)
        assert response_status == expected_response_status
        if expected_response_status == 400:
            assert response.json["code"] == "VALIDATION_ERROR"
        # elif expected_response_status == 201:
        elif expected_response_status == 201:
            assert "appId" in response.json
            # assert len(response.json) == expected_count
            # mock_get_all_cloud_zones.assert_called_once()
        else: