Commit 874f8c3f authored by Shayan Hajipour's avatar Shayan Hajipour
Browse files

feat: QoSProfile component added:

- manifest added
- debug in QoSProfile-related contextservice methods
- debug in QoSProfile crud operations and changing id to string
- Dockerfile added
- integration tests added
parent 8772ed2d
Loading
Loading
Loading
Loading
+72 −0
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: qos-profileservice
spec:
  selector:
    matchLabels:
      app: qos-profileservice
  #replicas: 1
  template:
    metadata:
      labels:
        app: qos-profileservice
    spec:
      terminationGracePeriodSeconds: 5
      containers:
        - name: server
          image: labs.etsi.org:5050/tfs/controller/qos_profile:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 30060
            - containerPort: 9192
          env:
            - name: LOG_LEVEL
              value: "INFO"
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:30060"]
          livenessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:30060"]
          resources:
            requests:
              cpu: 250m
              memory: 128Mi
            limits:
              cpu: 1000m
              memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
  name: qos-profileservice
  labels:
    app: qos-profileservice
spec:
  type: ClusterIP
  selector:
    app: qos-profileservice
  ports:
    - name: grpc
      protocol: TCP
      port: 30060
      targetPort: 30060
    - name: metrics
      protocol: TCP
      port: 9192
      targetPort: 9192
+2 −2
Original line number Diff line number Diff line
@@ -264,11 +264,11 @@ class ContextServiceServicerImpl(ContextServiceServicer, ContextPolicyServiceSer

    @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
    def DeleteQoSProfile(self, request : QoSProfileId, context : grpc.ServicerContext) -> Empty:
        return delete_qos_profile(self.db_engine, request)
        return delete_qos_profile(self.db_engine, request.qos_profile_id.uuid)

    @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
    def GetQoSProfile(self, request : QoSProfileId, context : grpc.ServicerContext) -> QoSProfile:
        return get_qos_profile(self.db_engine, request)
        return get_qos_profile(self.db_engine, request.qos_profile_id.uuid)

    @safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
    def GetQoSProfiles(self, request : Empty, context : grpc.ServicerContext) -> Iterator[QoSProfile]:
+32 −10
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ from sqlalchemy.orm import Session, sessionmaker
from sqlalchemy_cockroachdb import run_transaction
from typing import List, Optional

from common.proto.context_pb2 import Empty, QoSProfileId, QoSProfileValueUnitPair, QoSProfile
from common.proto.context_pb2 import Empty, Uuid, QoSProfileId, QoSProfileValueUnitPair, QoSProfile
from common.method_wrappers.ServiceExceptions import NotFoundException
from common.tools.grpc.Tools import grpc_message_to_json
from .models.QoSProfile import QoSProfileModel
@@ -27,8 +27,8 @@ from .models.QoSProfile import QoSProfileModel
LOGGER = logging.getLogger(__name__)

def grpc_message_to_qos_table_data(message: QoSProfile) -> dict:
    return [{
    'qos_profile_id'            : message.qos_profile_id.uuid,
    return {
    'qos_profile_id'            : message.qos_profile_id.qos_profile_id.uuid,
    'name'                      : message.name,
    'description'               : message.description,
    'status'                    : message.status,
@@ -44,11 +44,11 @@ def grpc_message_to_qos_table_data(message: QoSProfile) -> dict:
    'packetDelayBudget'         : grpc_message_to_json(message.packetDelayBudget),
    'jitter'                    : grpc_message_to_json(message.jitter),
    'packetErrorLossRate'       : message.packetErrorLossRate,
    }]
    }

def qos_table_data_to_grpc_message(data: QoSProfileModel) -> QoSProfile:
    QoSProfile(
    qos_profile_id            = QoSProfileId(uuid=data.qos_profile_id),
    return QoSProfile(
    qos_profile_id            = QoSProfileId(qos_profile_id=Uuid(uuid=data.qos_profile_id)),
    name                      = data.name,
    description               = data.description,
    status                    = data.status,
@@ -69,10 +69,32 @@ def qos_table_data_to_grpc_message(data: QoSProfileModel) -> QoSProfile:
def set_qos_profile(db_engine : Engine, request : QoSProfile) -> QoSProfile:
    qos_profile_data = grpc_message_to_qos_table_data(request)
    def callback(session : Session) -> bool:
        stmt = insert(QoSProfileModel).values(qos_profile_data)
        session.execute(stmt)
        return get_qos_profile(db_engine, request.qos_profile_id.uuid)
    return run_transaction(sessionmaker(bind=db_engine), callback)
        stmt = insert(QoSProfileModel).values([qos_profile_data])
        stmt = stmt.on_conflict_do_update(index_elements=[QoSProfileModel.qos_profile_id],
            set_=dict(

                    name                      = stmt.excluded.name,
                    description               = stmt.excluded.description,
                    status                    = stmt.excluded.status,
                    targetMinUpstreamRate     = stmt.excluded.targetMinUpstreamRate,
                    maxUpstreamRate           = stmt.excluded.maxUpstreamRate,
                    maxUpstreamBurstRate      = stmt.excluded.maxUpstreamBurstRate,
                    targetMinDownstreamRate   = stmt.excluded.targetMinDownstreamRate,
                    maxDownstreamRate         = stmt.excluded.maxDownstreamRate,
                    maxDownstreamBurstRate    = stmt.excluded.maxDownstreamBurstRate,
                    minDuration               = stmt.excluded.minDuration,
                    maxDuration               = stmt.excluded.maxDuration,
                    priority                  = stmt.excluded.priority,
                    packetDelayBudget         = stmt.excluded.packetDelayBudget,
                    jitter                    = stmt.excluded.jitter,
                    packetErrorLossRate       = stmt.excluded.packetErrorLossRate,
                )
        )
        stmt = stmt.returning(QoSProfileModel)
        qos_profile = session.execute(stmt).fetchall()
        return qos_profile[0]
    qos_profile_row = run_transaction(sessionmaker(bind=db_engine), callback)
    return qos_table_data_to_grpc_message(qos_profile_row)

def delete_qos_profile(db_engine : Engine, request : str) -> Empty:
    def callback(session : Session) -> bool:
+1 −7
Original line number Diff line number Diff line
@@ -13,19 +13,13 @@
# limitations under the License.

from sqlalchemy import Column, Integer, String, JSON
from sqlalchemy.dialects.postgresql import UUID
from typing import TypedDict
from ._Base import _Base


class QoSProfileValueUnitPair(TypedDict):
    value: int
    unit: str

class QoSProfileModel(_Base):
    __tablename__ = 'qos_profile'

    qos_profile_id            = Column(UUID(as_uuid=False), primary_key=True)
    qos_profile_id            = Column(String, primary_key=True)
    name                      = Column(String, nullable=False)
    description               = Column(String, nullable=False)
    status                    = Column(String, nullable=False)
+14 −0
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI OSG/SDG TeraFlowSDN (TFS) (https://tfs.etsi.org/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Loading