Commit 2a90e334 authored by Sergio Gimenez's avatar Sergio Gimenez
Browse files

fix(edgecloud): support local smoke flows

parent e2291b96
Loading
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -100,6 +100,9 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
            self.connector_db = ConnectorDB(storage_uri)
        self.catalogue_db = LocalCatalogueDB(local_db_path)

    def _artefact_store(self):
        return self.connector_db or self.catalogue_db

    def onboard_app(self, app_manifest: AppManifest) -> Response:
        print(f"Submitting application: {app_manifest}")
        logging.info("Extracting variables from payload...")
@@ -577,7 +580,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
            "_id": artefact_id,
            **artefact,
        }
        result = self.connector_db.insert_document("artefacts", artefact_document)
        result = self._artefact_store().insert_document("artefacts", artefact_document)
        if isinstance(result, str):
            status_code = 409
            content = {"message": result}
@@ -601,7 +604,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
        :param artefact_id: Unique identifier of the artefact.
        :return: Dictionary with artefact details.
        """
        artefacts = self.connector_db.get_documents_from_collection(
        artefacts = self._artefact_store().get_documents_from_collection(
            "artefacts", input_type="_id", input_value=artefact_id
        )
        if artefacts:
@@ -631,7 +634,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
        :param artefact_id: Unique identifier of the artefact.
        :return:
        """
        _, code = self.connector_db.delete_document("artefacts", _id=artefact_id)
        _, code = self._artefact_store().delete_document("artefacts", _id=artefact_id)
        content = None if code == 200 else {
            "status": 404,
            "code": "NOT_FOUND",
+59 −0
Original line number Diff line number Diff line
@@ -35,6 +35,14 @@ class LocalCatalogueDB:
                )
                """
            )
            conn.execute(
                """
                CREATE TABLE IF NOT EXISTS artefacts (
                    artefact_id TEXT PRIMARY KEY,
                    document TEXT NOT NULL
                )
                """
            )

    def insert_document_service_function(self, document=None, _id=None):
        with self._connect() as conn:
@@ -74,6 +82,16 @@ class LocalCatalogueDB:
    def get_documents_from_collection(
        self, collection_input, input_type=None, input_value=None
    ) -> List[dict]:
        if collection_input == "artefacts":
            query = "SELECT document FROM artefacts"
            params = ()
            if input_type == "_id":
                query += " WHERE artefact_id = ?"
                params = (input_value,)
            with self._connect() as conn:
                rows = conn.execute(query, params).fetchall()
            return [json.loads(row["document"]) for row in rows]

        if collection_input != "service_functions":
            return []

@@ -128,3 +146,44 @@ class LocalCatalogueDB:

    def insert_document_artefact(self, document=None, _id=None):
        return None

    def insert_document(self, collection, document=None, unique_field="_id"):
        if collection != "artefacts":
            return None

        artefact_id = document.get(unique_field) if unique_field else None
        if artefact_id is None:
            return None

        with self._connect() as conn:
            existing = conn.execute(
                "SELECT artefact_id FROM artefacts WHERE artefact_id = ?",
                (artefact_id,),
            ).fetchone()
            if existing is not None:
                return f"Document already exists in {collection}"

            conn.execute(
                "INSERT INTO artefacts (artefact_id, document) VALUES (?, ?)",
                (artefact_id, json.dumps(document)),
            )

        class InsertResult:
            inserted_id = artefact_id

        return InsertResult()

    def delete_document(self, collection, _id: str = None):
        if collection != "artefacts":
            return f"Document not found in {collection}", 404

        with self._connect() as conn:
            existing = conn.execute(
                "SELECT artefact_id FROM artefacts WHERE artefact_id = ?", (_id,)
            ).fetchone()
            if existing is None:
                return f"Document not found in {collection}", 404

            conn.execute("DELETE FROM artefacts WHERE artefact_id = ?", (_id,))

        return "Document deleted successfully", 200
+2 −2
Original line number Diff line number Diff line
@@ -388,7 +388,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
                return new_resp
        return response

    def undeploy_app(self, app_id: str, app_instance_id: str) -> Response:
    def undeploy_app(self, app_instance_id: str, app_id: Optional[str] = None) -> Response:
        response = requests.delete(f"{self.api_url}/apps/deployments/{app_instance_id}")

        if response.status_code == 204:
@@ -611,7 +611,7 @@ class EdgeApplicationManager(EdgeCloudManagementInterface):
    def undeploy_app_gsma(
        self, app_id: str, app_instance_id: str, zone_id: Optional[str] = None
    ) -> Response:
        response = self.undeploy_app(app_id, app_instance_id)
        response = self.undeploy_app(app_instance_id, app_id=app_id)
        if response.status_code == 200:
            new_resp = Response()
            new_resp.status_code = 204