Skip to content
Snippets Groups Projects
Commit 6aa08173 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'feat/183-create-qosprofile-component' into 'develop'

Resolve "Create QoSProfile component"

See merge request !257
parents 36858aff b9333b2d
No related branches found
No related tags found
2 merge requests!294Release TeraFlowSDN 4.0,!257Resolve "Create QoSProfile component"
Showing
with 685 additions and 2 deletions
......@@ -25,6 +25,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
.my_venv/
# requirements.txt # removed to enable tracking versions of packages over time
# PyInstaller
......
......@@ -51,6 +51,7 @@ include:
- local: '/src/kpi_value_writer/.gitlab-ci.yml'
- local: '/src/telemetry/.gitlab-ci.yml'
- local: '/src/analytics/.gitlab-ci.yml'
- local: '/src/qos_profile/.gitlab-ci.yml'
# This should be last one: end-to-end integration tests
- local: '/src/tests/.gitlab-ci.yml'
# 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:
annotations:
config.linkerd.io/skip-outbound-ports: "4222"
labels:
app: qos-profileservice
spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: labs.etsi.org:5050/tfs/controller/qos_profile:latest
imagePullPolicy: Always
ports:
- containerPort: 20040
- containerPort: 9192
env:
- name: LOG_LEVEL
value: "INFO"
- name: CRDB_DATABASE
value: "tfs_qos_profile"
envFrom:
- secretRef:
name: crdb-data
readinessProbe:
exec:
command: ["/bin/grpc_health_probe", "-addr=:20040"]
livenessProbe:
exec:
command: ["/bin/grpc_health_probe", "-addr=:20040"]
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: 20040
targetPort: 20040
- name: metrics
protocol: TCP
port: 9192
targetPort: 9192
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: qos-profileservice-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: qos-profileservice
minReplicas: 1
maxReplicas: 20
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 80
#behavior:
# scaleDown:
# stabilizationWindowSeconds: 30
......@@ -28,6 +28,9 @@ export TFS_COMPONENTS="context device pathcomp service slice nbi webui load_gene
# Uncomment to activate Monitoring Framework (new)
#export TFS_COMPONENTS="${TFS_COMPONENTS} kpi_manager kpi_value_writer kpi_value_api telemetry analytics automation"
# Uncomment to activate QoS Profiles
#export TFS_COMPONENTS="${TFS_COMPONENTS} qos_profile"
# Uncomment to activate BGP-LS Speaker
#export TFS_COMPONENTS="${TFS_COMPONENTS} bgpls_speaker"
......
......@@ -536,7 +536,7 @@ message Constraint_Custom {
}
message Constraint_Schedule {
float start_timestamp = 1;
double start_timestamp = 1;
float duration_days = 2;
}
......@@ -599,6 +599,16 @@ message Constraint_Exclusions {
repeated LinkId link_ids = 4;
}
message QoSProfileId {
context.Uuid qos_profile_id = 1;
}
message Constraint_QoSProfile {
QoSProfileId qos_profile_id = 1;
string qos_profile_name = 2;
}
message Constraint {
ConstraintActionEnum action = 1;
oneof constraint {
......@@ -611,6 +621,7 @@ message Constraint {
Constraint_SLA_Availability sla_availability = 8;
Constraint_SLA_Isolation_level sla_isolation = 9;
Constraint_Exclusions exclusions = 10;
Constraint_QoSProfile qos_profile = 11;
}
}
......
// 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.
syntax = "proto3";
package qos_profile;
import "context.proto";
message QoSProfileValueUnitPair {
int32 value = 1;
string unit = 2;
}
message QoDConstraintsRequest {
context.QoSProfileId qos_profile_id = 1;
double start_timestamp = 2;
float duration = 3;
}
message QoSProfile {
context.QoSProfileId qos_profile_id = 1;
string name = 2;
string description = 3;
string status = 4;
QoSProfileValueUnitPair targetMinUpstreamRate = 5;
QoSProfileValueUnitPair maxUpstreamRate = 6;
QoSProfileValueUnitPair maxUpstreamBurstRate = 7;
QoSProfileValueUnitPair targetMinDownstreamRate = 8;
QoSProfileValueUnitPair maxDownstreamRate = 9;
QoSProfileValueUnitPair maxDownstreamBurstRate = 10;
QoSProfileValueUnitPair minDuration = 11;
QoSProfileValueUnitPair maxDuration = 12;
int32 priority = 13;
QoSProfileValueUnitPair packetDelayBudget = 14;
QoSProfileValueUnitPair jitter = 15;
int32 packetErrorLossRate = 16;
}
service QoSProfileService {
rpc CreateQoSProfile (QoSProfile ) returns ( QoSProfile ) {}
rpc UpdateQoSProfile (QoSProfile ) returns ( QoSProfile ) {}
rpc DeleteQoSProfile (context.QoSProfileId ) returns ( context.Empty ) {}
rpc GetQoSProfile (context.QoSProfileId ) returns ( QoSProfile ) {}
rpc GetQoSProfiles (context.Empty ) returns (stream QoSProfile ) {}
rpc GetConstraintListFromQoSProfile (QoDConstraintsRequest) returns (stream context.Constraint) {}
}
#!/bin/bash
# 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.
########################################################################################################################
# Define your deployment settings here
########################################################################################################################
# If not already set, set the name of the Kubernetes namespace to deploy to.
export TFS_K8S_NAMESPACE=${TFS_K8S_NAMESPACE:-"tfs"}
########################################################################################################################
# Automated steps start here
########################################################################################################################
kubectl --namespace $TFS_K8S_NAMESPACE logs deployment/qos_profileservice -c server
......@@ -70,6 +70,7 @@ class ServiceNameEnum(Enum):
TELEMETRYBACKEND = 'telemetry-backend'
ANALYTICSFRONTEND = 'analytics-frontend'
ANALYTICSBACKEND = 'analytics-backend'
QOSPROFILE = 'qos-profile'
# Used for test and debugging only
DLT_GATEWAY = 'dltgateway'
......@@ -100,6 +101,7 @@ DEFAULT_SERVICE_GRPC_PORTS = {
ServiceNameEnum.OPTICALCONTROLLER .value : 10060,
ServiceNameEnum.QKD_APP .value : 10070,
ServiceNameEnum.BGPLS .value : 20030,
ServiceNameEnum.QOSPROFILE .value : 20040,
ServiceNameEnum.KPIMANAGER .value : 30010,
ServiceNameEnum.KPIVALUEAPI .value : 30020,
ServiceNameEnum.KPIVALUEWRITER .value : 30030,
......
......@@ -69,7 +69,8 @@ def compose_constraints_data(
constraint_name = '{:s}:{:s}:{:s}'.format(parent_kind, kind.value, endpoint_uuid)
elif kind in {
ConstraintKindEnum.SCHEDULE, ConstraintKindEnum.SLA_CAPACITY, ConstraintKindEnum.SLA_LATENCY,
ConstraintKindEnum.SLA_AVAILABILITY, ConstraintKindEnum.SLA_ISOLATION, ConstraintKindEnum.EXCLUSIONS
ConstraintKindEnum.SLA_AVAILABILITY, ConstraintKindEnum.SLA_ISOLATION, ConstraintKindEnum.EXCLUSIONS,
ConstraintKindEnum.QOS_PROFILE
}:
constraint_name = '{:s}:{:s}:'.format(parent_kind, kind.value)
else:
......
......@@ -31,6 +31,7 @@ class ConstraintKindEnum(enum.Enum):
SLA_LATENCY = 'sla_latency'
SLA_AVAILABILITY = 'sla_availability'
SLA_ISOLATION = 'sla_isolation'
QOS_PROFILE = 'qos_profile'
EXCLUSIONS = 'exclusions'
class ServiceConstraintModel(_Base):
......
# 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.
# Build, tag, and push the Docker image to the GitLab Docker registry
build qos_profile:
variables:
IMAGE_NAME: "qos_profile" # name of the microservice
IMAGE_TAG: "latest" # tag of the container image (production, development, etc)
stage: build
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker buildx build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$IMAGE_NAME/Dockerfile .
- docker tag "$IMAGE_NAME:$IMAGE_TAG" "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
- docker push "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
after_script:
- docker images --filter="dangling=true" --quiet | xargs -r docker rmi
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
- changes:
- src/common/**/*.py
- proto/*.proto
- src/$IMAGE_NAME/**/*.{py,in,yml}
- src/$IMAGE_NAME/Dockerfile
- src/$IMAGE_NAME/tests/*.py
- manifests/${IMAGE_NAME}service.yaml
- .gitlab-ci.yml
# Apply unit test to the component
unit_test qos_profile:
variables:
IMAGE_NAME: "qos_profile" # name of the microservice
IMAGE_TAG: "latest" # tag of the container image (production, development, etc)
stage: unit_test
needs:
- build qos_profile
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create --driver=bridge teraflowbridge; fi
# QoSProfile-related
- if docker container ls | grep crdb; then docker rm -f crdb; else echo "CockroachDB container is not in the system"; fi
- if docker volume ls | grep crdb; then docker volume rm -f crdb; else echo "CockroachDB volume is not in the system"; fi
- if docker container ls | grep $IMAGE_NAME; then docker rm -f $IMAGE_NAME; else echo "$IMAGE_NAME image is not in the system"; fi
script:
- docker pull "cockroachdb/cockroach:latest-v22.2"
- docker pull "$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG"
# environment preparation
- docker volume create crdb
- >
docker run --name crdb -d --network=teraflowbridge -p 26257:26257 -p 8080:8080
--env COCKROACH_DATABASE=tfs_test --env COCKROACH_USER=tfs --env COCKROACH_PASSWORD=tfs123
--volume "crdb:/cockroach/cockroach-data"
cockroachdb/cockroach:latest-v22.2 start-single-node
- echo "Waiting for initialization..."
- while ! docker logs crdb 2>&1 | grep -q 'finished creating default user \"tfs\"'; do sleep 1; done
- docker logs crdb
- docker ps -a
- CRDB_ADDRESS=$(docker inspect crdb --format "{{.NetworkSettings.Networks.teraflowbridge.IPAddress}}")
- echo $CRDB_ADDRESS
- >
# QoSProfile preparation
- >
docker run --name $IMAGE_NAME -d -p 3030:3030
--env "CRDB_URI=cockroachdb://tfs:tfs123@${CRDB_ADDRESS}:26257/tfs_test?sslmode=require"
--volume "$PWD/src/$IMAGE_NAME/tests:/opt/results"
--network=teraflowbridge
$CI_REGISTRY_IMAGE/$IMAGE_NAME:$IMAGE_TAG
# Check status before the tests
- sleep 5
- docker ps -a
- docker logs $IMAGE_NAME
# Run the tests
- >
docker exec -i $IMAGE_NAME bash -c
"coverage run -m pytest --log-level=INFO --verbose $IMAGE_NAME/tests/test_crud.py --junitxml=/opt/results/${IMAGE_NAME}_report.xml"
- docker exec -i $IMAGE_NAME bash -c "coverage report --include='${IMAGE_NAME}/*' --show-missing"
coverage: '/TOTAL\s+\d+\s+\d+\s+(\d+%)/'
after_script:
# Check status after the tests
- docker ps -a
- docker logs $IMAGE_NAME
- docker rm -f $IMAGE_NAME crdb
- docker volume rm -f crdb
- docker network rm teraflowbridge
- docker volume prune --force
- docker image prune --force
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH)'
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == "develop"'
- changes:
- src/common/**/*.py
- proto/*.proto
- src/$IMAGE_NAME/**/*.{py,in,yml}
- src/$IMAGE_NAME/Dockerfile
- src/$IMAGE_NAME/tests/*.py
- manifests/${IMAGE_NAME}service.yaml
- .gitlab-ci.yml
artifacts:
when: always
reports:
junit: src/$IMAGE_NAME/tests/${IMAGE_NAME}_report.xml
# 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.
# 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.
FROM python:3.9-slim
# Install dependencies
RUN apt-get --yes --quiet --quiet update && \
apt-get --yes --quiet --quiet install wget g++ git && \
rm -rf /var/lib/apt/lists/*
# Set Python to show logs as they occur
ENV PYTHONUNBUFFERED=0
# Download the gRPC health probe
RUN GRPC_HEALTH_PROBE_VERSION=v0.2.0 && \
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
chmod +x /bin/grpc_health_probe
# Get generic Python packages
RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install --upgrade setuptools wheel
RUN python3 -m pip install --upgrade pip-tools
# Get common Python packages
# Note: this step enables sharing the previous Docker build steps among all the Python components
WORKDIR /var/teraflow
COPY common_requirements.in common_requirements.in
RUN pip-compile --quiet --output-file=common_requirements.txt common_requirements.in
RUN python3 -m pip install -r common_requirements.txt
# Add common files into working directory
WORKDIR /var/teraflow/common
COPY src/common/. ./
RUN rm -rf proto
# Create proto sub-folder, copy .proto files, and generate Python code
RUN mkdir -p /var/teraflow/common/proto
WORKDIR /var/teraflow/common/proto
RUN touch __init__.py
COPY proto/*.proto ./
RUN python3 -m grpc_tools.protoc -I=. --python_out=. --grpc_python_out=. *.proto
RUN rm *.proto
RUN find . -type f -exec sed -i -E 's/(import\ .*)_pb2/from . \1_pb2/g' {} \;
# Create component sub-folders, get specific Python packages
RUN mkdir -p /var/teraflow/qos_profile
WORKDIR /var/teraflow/qos_profile
COPY src/qos_profile/requirements.in requirements.in
RUN pip-compile --quiet --output-file=requirements.txt requirements.in
RUN python3 -m pip install -r requirements.txt
# Add component files into working directory
WORKDIR /var/teraflow
COPY src/qos_profile/. qos_profile/
# Start the service
ENTRYPOINT ["python", "-m", "qos_profile.service"]
# 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.
# 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.
from typing import Iterator
import grpc, logging
from common.Constants import ServiceNameEnum
from common.Settings import get_service_host, get_service_port_grpc
from common.proto.context_pb2 import Empty, QoSProfileId
from common.proto.qos_profile_pb2 import QoSProfile, QoDConstraintsRequest
from common.proto.context_pb2 import Constraint
from common.proto.qos_profile_pb2_grpc import QoSProfileServiceStub
from common.tools.client.RetryDecorator import retry, delay_exponential
from common.tools.grpc.Tools import grpc_message_to_json_string
LOGGER = logging.getLogger(__name__)
MAX_RETRIES = 15
DELAY_FUNCTION = delay_exponential(initial=0.01, increment=2.0, maximum=5.0)
RETRY_DECORATOR = retry(max_retries=MAX_RETRIES, delay_function=DELAY_FUNCTION, prepare_method_name='connect')
class QoSProfileClient:
def __init__(self, host=None, port=None):
if not host: host = get_service_host(ServiceNameEnum.QOSPROFILE)
if not port: port = get_service_port_grpc(ServiceNameEnum.QOSPROFILE)
self.endpoint = '{:s}:{:s}'.format(str(host), str(port))
LOGGER.debug('Creating channel to {:s}...'.format(str(self.endpoint)))
self.channel = None
self.stub = None
self.connect()
LOGGER.debug('Channel created')
def connect(self):
self.channel = grpc.insecure_channel(self.endpoint)
self.stub = QoSProfileServiceStub(self.channel)
def close(self):
if self.channel is not None: self.channel.close()
self.channel = None
self.stub = None
@RETRY_DECORATOR
def CreateQoSProfile(self, request: QoSProfile) -> QoSProfile:
LOGGER.debug('CreateQoSProfile request: {:s}'.format(grpc_message_to_json_string(request)))
response = self.stub.CreateQoSProfile(request)
LOGGER.debug('CreateQoSProfile result: {:s}'.format(grpc_message_to_json_string(response)))
return response
@RETRY_DECORATOR
def UpdateQoSProfile(self, request: QoSProfile) -> QoSProfile:
LOGGER.debug('UpdateQoSProfile request: {:s}'.format(grpc_message_to_json_string(request)))
response = self.stub.UpdateQoSProfile(request)
LOGGER.debug('UpdateQoSProfile result: {:s}'.format(grpc_message_to_json_string(response)))
return response
@RETRY_DECORATOR
def DeleteQoSProfile(self, request: QoSProfileId) -> Empty:
LOGGER.debug('DeleteQoSProfile request: {:s}'.format(grpc_message_to_json_string(request)))
response = self.stub.DeleteQoSProfile(request)
LOGGER.debug('DeleteQoSProfile result: {:s}'.format(grpc_message_to_json_string(response)))
return response
@RETRY_DECORATOR
def GetQoSProfile(self, request: QoSProfileId) -> QoSProfile:
LOGGER.debug('GetQoSProfile request: {:s}'.format(grpc_message_to_json_string(request)))
response = self.stub.GetQoSProfile(request)
LOGGER.debug('GetQoSProfile result: {:s}'.format(grpc_message_to_json_string(response)))
return response
@RETRY_DECORATOR
def GetQoSProfiles(self, request: Empty) -> Iterator[QoSProfile]:
LOGGER.debug('GetQoSProfiles request: {:s}'.format(grpc_message_to_json_string(request)))
response = self.stub.GetQoSProfiles(request)
LOGGER.debug('GetQoSProfiles result: {:s}'.format(grpc_message_to_json_string(response)))
return response
@RETRY_DECORATOR
def GetConstraintListFromQoSProfile(self, request: QoDConstraintsRequest) -> Iterator[Constraint]:
LOGGER.debug('GetConstraintListFromQoSProfile request: {:s}'.format(grpc_message_to_json_string(request)))
response = self.stub.GetConstraintListFromQoSProfile(request)
LOGGER.debug('GetConstraintListFromQoSProfile result: {:s}'.format(grpc_message_to_json_string(response)))
return response
# 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.
# 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.
psycopg2-binary==2.9.*
SQLAlchemy==1.4.*
sqlalchemy-cockroachdb==1.4.*
SQLAlchemy-Utils==0.38.*
# 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.
import sqlalchemy
from common.Constants import ServiceNameEnum
from common.Settings import get_service_port_grpc
from common.proto.qos_profile_pb2_grpc import add_QoSProfileServiceServicer_to_server
from common.tools.service.GenericGrpcService import GenericGrpcService
from .QoSProfileServiceServicerImpl import QoSProfileServiceServicerImpl
class QoSProfileService(GenericGrpcService):
def __init__(self, db_engine: sqlalchemy.engine.Engine, cls_name: str = __name__) -> None:
port = get_service_port_grpc(ServiceNameEnum.QOSPROFILE)
super().__init__(port, cls_name=cls_name)
self.qos_profile_servicer = QoSProfileServiceServicerImpl(db_engine)
def install_servicers(self):
add_QoSProfileServiceServicer_to_server(self.qos_profile_servicer, self.server)
# 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.
import grpc, logging, sqlalchemy
from typing import Iterator
import grpc._channel
from common.method_wrappers.Decorator import MetricsPool, safe_and_metered_rpc_method
from common.proto.context_pb2 import Constraint, ConstraintActionEnum, Constraint_QoSProfile, Constraint_Schedule, Empty, QoSProfileId
from common.proto.qos_profile_pb2 import QoSProfile, QoDConstraintsRequest
from common.proto.qos_profile_pb2_grpc import QoSProfileServiceServicer
from .database.QoSProfile import set_qos_profile, delete_qos_profile, get_qos_profile, get_qos_profiles
LOGGER = logging.getLogger(__name__)
METRICS_POOL = MetricsPool('QoSProfile', 'RPC')
class QoSProfileServiceServicerImpl(QoSProfileServiceServicer):
def __init__(self, db_engine: sqlalchemy.engine.Engine) -> None:
LOGGER.debug('Servicer Created')
self.db_engine = db_engine
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def CreateQoSProfile(self, request: QoSProfile, context: grpc.ServicerContext) -> QoSProfile:
qos_profile = get_qos_profile(self.db_engine, request.qos_profile_id.qos_profile_id.uuid)
if qos_profile is not None:
context.set_details(f'QoSProfile {request.qos_profile_id.qos_profile_id.uuid} already exists')
context.set_code(grpc.StatusCode.ALREADY_EXISTS)
return QoSProfile()
return set_qos_profile(self.db_engine, request)
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def UpdateQoSProfile(self, request: QoSProfile, context: grpc.ServicerContext) -> QoSProfile:
qos_profile = get_qos_profile(self.db_engine, request.qos_profile_id.qos_profile_id.uuid)
if qos_profile is None:
context.set_details(f'QoSProfile {request.qos_profile_id.qos_profile_id.uuid} not found')
context.set_code(grpc.StatusCode.NOT_FOUND)
return QoSProfile()
return set_qos_profile(self.db_engine, request)
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def DeleteQoSProfile(self, request: QoSProfileId, context: grpc.ServicerContext) -> Empty:
qos_profile = get_qos_profile(self.db_engine, request.qos_profile_id.uuid)
if qos_profile is None:
context.set_details(f'QoSProfile {request.qos_profile_id.uuid} not found')
context.set_code(grpc.StatusCode.NOT_FOUND)
return QoSProfile()
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:
qos_profile = get_qos_profile(self.db_engine, request.qos_profile_id.uuid)
if qos_profile is None:
context.set_details(f'QoSProfile {request.qos_profile_id.uuid} not found')
context.set_code(grpc.StatusCode.NOT_FOUND)
return QoSProfile()
return qos_profile
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def GetQoSProfiles(self, request: Empty, context: grpc.ServicerContext) -> Iterator[QoSProfile]:
yield from get_qos_profiles(self.db_engine, request)
@safe_and_metered_rpc_method(METRICS_POOL, LOGGER)
def GetConstraintListFromQoSProfile(self, request: QoDConstraintsRequest, context: grpc.ServicerContext) -> Iterator[Constraint]:
qos_profile = get_qos_profile(self.db_engine, request.qos_profile_id.qos_profile_id.uuid)
if qos_profile is None:
context.set_details(f'QoSProfile {request.qos_profile_id.qos_profile_id.uuid} not found')
context.set_code(grpc.StatusCode.NOT_FOUND)
yield Constraint()
qos_profile_constraint = Constraint_QoSProfile()
qos_profile_constraint.qos_profile_name = qos_profile.name
qos_profile_constraint.qos_profile_id.CopyFrom(qos_profile.qos_profile_id)
constraint_qos = Constraint()
constraint_qos.action = ConstraintActionEnum.CONSTRAINTACTION_SET
constraint_qos.qos_profile.CopyFrom(qos_profile_constraint)
yield constraint_qos
constraint_schedule = Constraint()
constraint_schedule.action = ConstraintActionEnum.CONSTRAINTACTION_SET
constraint_schedule.schedule.CopyFrom(Constraint_Schedule(start_timestamp=request.start_timestamp, duration_days=request.duration/86400))
yield constraint_schedule
# 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.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment