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

DLT:

MockBlockchain:
- Implemented mock-blockchain module to facilitate testing and debugging of DLT connector & workflows
- Added manifests, Dockerfile, etc.

DLT Connector:
- corrected requirements.in
- updated Dockerfile
- WIP: implementation of test_unitary.py

DLT Gateway:
- Improved/extended Dockerfile
- Moved Dockerfile to correct folder
- Corrected import path for proto files
parent abce48da
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!16DLT component (and related) improvements
Showing
with 456 additions and 53 deletions
...@@ -162,6 +162,7 @@ cython_debug/ ...@@ -162,6 +162,7 @@ cython_debug/
# TeraFlowSDN-generated files # TeraFlowSDN-generated files
tfs_runtime_env_vars.sh tfs_runtime_env_vars.sh
tfs_bchain_runtime_env_vars.sh
delete_local_deployment.sh delete_local_deployment.sh
local_docker_deployment.sh local_docker_deployment.sh
local_k8s_deployment.sh local_k8s_deployment.sh
......
#!/bin/bash
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# 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.
########################################################################################################################
# Read deployment settings
########################################################################################################################
# Set the URL of your local Docker registry where the images will be uploaded to.
REGISTRY_IMAGE="http://localhost:32000/tfs/"
# Set the tag you want to use for your images.
IMAGE_TAG="dev"
# Set the name of the Kubernetes namespace to deploy to.
K8S_NAMESPACE="tfs-bchain"
COMPONENT="mock_blockchain"
########################################################################################################################
# Automated steps start here
########################################################################################################################
# Constants
GITLAB_REPO_URL="registry.gitlab.com/teraflow-h2020/controller"
TMP_FOLDER="./tmp"
# Create a tmp folder for files modified during the deployment
TMP_MANIFESTS_FOLDER="$TMP_FOLDER/manifests"
mkdir -p $TMP_MANIFESTS_FOLDER
TMP_LOGS_FOLDER="$TMP_FOLDER/logs"
mkdir -p $TMP_LOGS_FOLDER
echo "Deleting and Creating a new namespace..."
kubectl delete namespace $K8S_NAMESPACE
kubectl create namespace $K8S_NAMESPACE
printf "\n"
echo "Deploying components and collecting environment variables..."
ENV_VARS_SCRIPT=tfs_bchain_runtime_env_vars.sh
echo "# Environment variables for TeraFlow Mock-Blockchain deployment" > $ENV_VARS_SCRIPT
PYTHONPATH=$(pwd)/src
echo "Processing '$COMPONENT' component..."
IMAGE_NAME="$COMPONENT:$IMAGE_TAG"
IMAGE_URL=$(echo "$REGISTRY_IMAGE/$IMAGE_NAME" | sed 's,//,/,g' | sed 's,http:/,,g')
echo " Building Docker image..."
BUILD_LOG="$TMP_LOGS_FOLDER/build_${COMPONENT}.log"
docker build -t "$IMAGE_NAME" -f ./src/dlt/mock_blockchain/Dockerfile . > "$BUILD_LOG"
if [ -n "$REGISTRY_IMAGE" ]; then
echo " Pushing Docker image to '$REGISTRY_IMAGE'..."
TAG_LOG="$TMP_LOGS_FOLDER/tag_${COMPONENT}.log"
docker tag "$IMAGE_NAME" "$IMAGE_URL" > "$TAG_LOG"
PUSH_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}.log"
docker push "$IMAGE_URL" > "$PUSH_LOG"
fi
echo " Adapting '$COMPONENT' manifest file..."
MANIFEST="$TMP_MANIFESTS_FOLDER/${COMPONENT}.yaml"
cp ./manifests/"${COMPONENT}".yaml "$MANIFEST"
if [ -n "$REGISTRY_IMAGE" ]; then
# Registry is set
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:${VERSION}#image: $IMAGE_URL#g" "$MANIFEST"
sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Always#g" "$MANIFEST"
else
# Registry is not set
VERSION=$(grep -i "${GITLAB_REPO_URL}/${COMPONENT}:" "$MANIFEST" | cut -d ":" -f3)
sed -E -i "s#image: $GITLAB_REPO_URL/$COMPONENT:${VERSION}#image: $IMAGE_NAME#g" "$MANIFEST"
sed -E -i "s#imagePullPolicy: .*#imagePullPolicy: Never#g" "$MANIFEST"
fi
echo " Deploying '$COMPONENT' component to Kubernetes..."
DEPLOY_LOG="$TMP_LOGS_FOLDER/deploy_${COMPONENT}.log"
kubectl --namespace $K8S_NAMESPACE apply -f "$MANIFEST" > "$DEPLOY_LOG"
COMPONENT_OBJNAME=$(echo "${COMPONENT}" | sed "s/\_/-/")
kubectl --namespace $K8S_NAMESPACE scale deployment --replicas=0 ${COMPONENT_OBJNAME} >> "$DEPLOY_LOG"
kubectl --namespace $K8S_NAMESPACE scale deployment --replicas=1 ${COMPONENT_OBJNAME} >> "$DEPLOY_LOG"
echo " Collecting env-vars for '$COMPONENT' component..."
SERVICE_DATA=$(kubectl get service ${COMPONENT_OBJNAME} --namespace $K8S_NAMESPACE -o json)
# Env vars for service's host address
SERVICE_HOST=$(echo ${SERVICE_DATA} | jq -r '.spec.clusterIP')
ENVVAR_HOST=$(echo "${COMPONENT}_SERVICE_HOST" | tr '[:lower:]' '[:upper:]')
echo "export ${ENVVAR_HOST}=${SERVICE_HOST}" >> $ENV_VARS_SCRIPT
# Env vars for service's 'grpc' port
SERVICE_PORT_GRPC=$(echo ${SERVICE_DATA} | jq -r '.spec.ports[] | select(.name=="grpc") | .port')
ENVVAR_PORT_GRPC=$(echo "${COMPONENT}_SERVICE_PORT_GRPC" | tr '[:lower:]' '[:upper:]')
echo "export ${ENVVAR_PORT_GRPC}=${SERVICE_PORT_GRPC}" >> $ENV_VARS_SCRIPT
printf "\n"
echo "Waiting for '$COMPONENT' component..."
kubectl wait --namespace $K8S_NAMESPACE \
--for='condition=available' --timeout=300s deployment/${COMPONENT_OBJNAME}
printf "\n"
echo "Deployment Resources:"
kubectl --namespace $K8S_NAMESPACE get all
printf "\n"
echo "Done!"
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# 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: mock-blockchain
spec:
selector:
matchLabels:
app: mock-blockchain
template:
metadata:
labels:
app: mock-blockchain
spec:
terminationGracePeriodSeconds: 5
containers:
- name: server
image: registry.gitlab.com/teraflow-h2020/controller/mock_blockchain:latest
imagePullPolicy: Always
ports:
- containerPort: 50051
env:
- name: LOG_LEVEL
value: "DEBUG"
readinessProbe:
exec:
command: ["/bin/grpc_health_probe", "-addr=:50051"]
livenessProbe:
exec:
command: ["/bin/grpc_health_probe", "-addr=:50051"]
resources:
requests:
cpu: 250m
memory: 512Mi
limits:
cpu: 700m
memory: 1024Mi
---
apiVersion: v1
kind: Service
metadata:
name: mock-blockchain
spec:
type: ClusterIP
selector:
app: mock-blockchain
ports:
- name: grpc
protocol: TCP
port: 50051
targetPort: 50051
...@@ -49,6 +49,9 @@ class ServiceNameEnum(Enum): ...@@ -49,6 +49,9 @@ class ServiceNameEnum(Enum):
PATHCOMP = 'pathcomp' PATHCOMP = 'pathcomp'
WEBUI = 'webui' WEBUI = 'webui'
# Used for test and debugging only
DLT_GATEWAY = 'dlt-gateway'
# Default gRPC service ports # Default gRPC service ports
DEFAULT_SERVICE_GRPC_PORTS = { DEFAULT_SERVICE_GRPC_PORTS = {
ServiceNameEnum.CONTEXT .value : 1010, ServiceNameEnum.CONTEXT .value : 1010,
...@@ -63,6 +66,9 @@ DEFAULT_SERVICE_GRPC_PORTS = { ...@@ -63,6 +66,9 @@ DEFAULT_SERVICE_GRPC_PORTS = {
ServiceNameEnum.CYBERSECURITY.value : 10000, ServiceNameEnum.CYBERSECURITY.value : 10000,
ServiceNameEnum.INTERDOMAIN .value : 10010, ServiceNameEnum.INTERDOMAIN .value : 10010,
ServiceNameEnum.PATHCOMP .value : 10020, ServiceNameEnum.PATHCOMP .value : 10020,
# Used for test and debugging only
ServiceNameEnum.DLT_GATEWAY .value : 50051,
} }
# Default HTTP/REST-API service ports # Default HTTP/REST-API service ports
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
import grpc, itertools, json, logging, time import grpc, itertools, json, logging, time
from typing import Dict, Iterator, Optional, Tuple from typing import Any, Dict, Iterator, Optional, Tuple
from common.tests.MockMessageBroker import Message, MockMessageBroker from common.tests.MockMessageBroker import Message, MockMessageBroker
from common.tools.grpc.Tools import grpc_message_to_json_string from common.tools.grpc.Tools import grpc_message_to_json_string
from common.proto.context_pb2 import EVENTTYPE_CREATE, EVENTTYPE_REMOVE, EVENTTYPE_UPDATE, Empty, TeraFlowController from common.proto.context_pb2 import EVENTTYPE_CREATE, EVENTTYPE_REMOVE, EVENTTYPE_UPDATE, Empty, TeraFlowController
...@@ -27,8 +27,8 @@ from common.proto.dlt_gateway_pb2_grpc import DltGatewayServiceServicer ...@@ -27,8 +27,8 @@ from common.proto.dlt_gateway_pb2_grpc import DltGatewayServiceServicer
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
DltRecordKey = Tuple[str, DltRecordOperationEnum, str] # domain_uuid, operation, record_uuid DltRecordKey = Tuple[str, Any, str] # domain_uuid, DltRecordOperationEnum, record_uuid
DltRecordDict = Dict[DltRecordKey, DltRecord] # dlt_record_key => dlt_record DltRecordDict = Dict[DltRecordKey, DltRecord] # dlt_record_key => dlt_record
class AlreadyExistsException(Exception): class AlreadyExistsException(Exception):
pass pass
......
FROM zenika/kotlin
# Copy controller project
COPY . /controller
# Build gateway
WORKDIR /controller/src/dlt/gateway
RUN ./gradlew build
EXPOSE 50051
RUN echo "#!/bin/sh" >> /runscript.sh
RUN echo "echo 195.37.154.24 peer0.org1.example.com >> /etc/hosts;\
echo 195.37.154.24 peer0.org2.example.com >> /etc/hosts;\
echo 195.37.154.24 orderer0.example.com >> /etc/hosts;" >> /runscript.sh
RUN echo "cd /controller/src/dlt/gateway; ./gradlew runServer" >> /runscript.sh
RUN chmod +x /runscript.sh
ENTRYPOINT ["sh", "/runscript.sh"]
FROM python:3-slim # Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# 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 # Install dependencies
RUN apt-get --yes --quiet --quiet update && \ RUN apt-get --yes --quiet --quiet update && \
...@@ -14,25 +28,42 @@ RUN GRPC_HEALTH_PROBE_VERSION=v0.2.0 && \ ...@@ -14,25 +28,42 @@ RUN GRPC_HEALTH_PROBE_VERSION=v0.2.0 && \
chmod +x /bin/grpc_health_probe chmod +x /bin/grpc_health_probe
# Get generic Python packages # Get generic Python packages
RUN python3 -m pip install --upgrade pip setuptools wheel pip-tools RUN python3 -m pip install --upgrade pip
RUN python3 -m pip install --upgrade setuptools wheel
RUN python3 -m pip install --upgrade pip-tools
# Set working directory # Get common Python packages
# Note: this step enables sharing the previous Docker build steps among all the Python components
WORKDIR /var/teraflow 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 module sub-folders # Create proto sub-folder, copy .proto files, and generate Python code
RUN mkdir -p /var/teraflow/slice 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' {} \;
# Get Python packages per module # Create component sub-folders, get specific Python packages
COPY slice/requirements.in slice/requirements.in RUN mkdir -p /var/teraflow/dlt/connector
RUN pip-compile --output-file=slice/requirements.txt slice/requirements.in WORKDIR /var/teraflow/dlt/connector
RUN python3 -m pip install -r slice/requirements.in COPY src/dlt/connector/requirements.in requirements.in
RUN pip-compile --quiet --output-file=requirements.txt requirements.in
RUN python3 -m pip install -r requirements.txt
# Add files into working directory # Add component files into working directory
COPY common/. common WORKDIR /var/teraflow
COPY context/. context COPY src/context/. context/
COPY interdomain/. interdomain COPY src/dlt/connector/. dlt/connector
COPY service/. service
COPY slice/. slice
# Start slice service # Start the service
ENTRYPOINT ["python", "-m", "slice.service"] ENTRYPOINT ["python", "-m", "dlt.connector.service"]
grpcio==1.43.0
grpcio-health-checking==1.43.0
prometheus-client==0.13.0
protobuf==3.19.3
pytest==6.2.5
pytest-benchmark==3.4.1
...@@ -18,8 +18,14 @@ from common.orm.Database import Database ...@@ -18,8 +18,14 @@ from common.orm.Database import Database
from common.message_broker.MessageBroker import MessageBroker from common.message_broker.MessageBroker import MessageBroker
from common.proto.context_pb2 import Context, ContextId, Device, DeviceId, Link, LinkId, Topology, TopologyId from common.proto.context_pb2 import Context, ContextId, Device, DeviceId, Link, LinkId, Topology, TopologyId
from context.client.ContextClient import ContextClient from context.client.ContextClient import ContextClient
from .PrepareTestScenario import context_db_mb, context_service, context_client # pylint: disable=unused-import from .PrepareTestScenario import (
from .Objects import CONTEXTS, TOPOLOGIES, DEVICES, LINKS # pylint: disable=unused-import
dltgateway_service,
context_service_a, context_client_a, dltconnector_service_a, dltconnector_client_a,
context_service_b, context_client_b, dltconnector_service_b, dltconnector_client_b)
from .Objects import (
DA_CONTEXTS, DA_TOPOLOGIES, DA_DEVICES, DA_LINKS,
DB_CONTEXTS, DB_TOPOLOGIES, DB_DEVICES, DB_LINKS)
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
LOGGER.setLevel(logging.DEBUG) LOGGER.setLevel(logging.DEBUG)
...@@ -27,9 +33,6 @@ LOGGER.setLevel(logging.DEBUG) ...@@ -27,9 +33,6 @@ LOGGER.setLevel(logging.DEBUG)
def test_create_events( def test_create_events(
context_client : ContextClient, # pylint: disable=redefined-outer-name context_client : ContextClient, # pylint: disable=redefined-outer-name
context_db_mb : Tuple[Database, MessageBroker]): # pylint: disable=redefined-outer-name context_db_mb : Tuple[Database, MessageBroker]): # pylint: disable=redefined-outer-name
context_database = context_db_mb[0]
context_database.clear_all()
for context in CONTEXTS : context_client.SetContext (Context (**context )) for context in CONTEXTS : context_client.SetContext (Context (**context ))
for topology in TOPOLOGIES: context_client.SetTopology(Topology(**topology)) for topology in TOPOLOGIES: context_client.SetTopology(Topology(**topology))
...@@ -41,3 +44,11 @@ def test_create_events( ...@@ -41,3 +44,11 @@ def test_create_events(
for device in DEVICES : context_client.RemoveDevice (DeviceId (**device ['device_id' ])) for device in DEVICES : context_client.RemoveDevice (DeviceId (**device ['device_id' ]))
for topology in TOPOLOGIES: context_client.RemoveTopology(TopologyId(**topology['topology_id'])) for topology in TOPOLOGIES: context_client.RemoveTopology(TopologyId(**topology['topology_id']))
for context in CONTEXTS : context_client.RemoveContext (ContextId (**context ['context_id' ])) for context in CONTEXTS : context_client.RemoveContext (ContextId (**context ['context_id' ]))
dltgateway_client = DltGatewayClient(host='127.0.0.1', port=50051)
dltgateway_collector = DltEventsCollector(dltgateway_client, log_events_received=True)
dltgateway_collector.start()
dltgateway_collector.stop()
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# 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 zenika/kotlin:1.4-jdk12
# Make working directory move to it and copy DLT Gateway code
RUN mkdir -p /var/teraflow/dlt/gateway
WORKDIR /var/teraflow/dlt/gateway
COPY src/dlt/gateway/. ./
# Make directory for proto files and copy them
RUN mkdir proto
COPY proto/*.proto ./proto/
# Build DLT Gateway
RUN ./gradlew build
EXPOSE 50051
# Create entrypoint.sh script
RUN echo "#!/bin/sh" > /entrypoint.sh
RUN echo "echo 195.37.154.24 peer0.org1.example.com >> /etc/hosts" >> /entrypoint.sh
RUN echo "echo 195.37.154.24 peer0.org2.example.com >> /etc/hosts" >> /entrypoint.sh
RUN echo "echo 195.37.154.24 orderer0.example.com >> /etc/hosts" >> /entrypoint.sh
RUN echo "cd /var/teraflow/dlt/gateway" >> /entrypoint.sh
RUN echo "./gradlew runServer" >> /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Gateway entry point
ENTRYPOINT ["sh", "/entrypoint.sh"]
...@@ -107,7 +107,7 @@ task("runServer", JavaExec::class) { ...@@ -107,7 +107,7 @@ task("runServer", JavaExec::class) {
sourceSets { sourceSets {
main { main {
proto { proto {
srcDir("../../../proto") srcDir("proto")
srcDir("src/main/kotlin/proto") srcDir("src/main/kotlin/proto")
} }
} }
......
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# 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++ && \
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/mock_blockchain
WORKDIR /var/teraflow/mock_blockchain
COPY src/dlt/mock_blockchain/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/dlt/mock_blockchain/. mock_blockchain
# Start the service
ENTRYPOINT ["python", "-m", "mock_blockchain.service"]
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# 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 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# 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 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# 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 logging, signal, sys, threading
from common.Constants import ServiceNameEnum
from common.Settings import get_log_level, get_service_port_grpc
from common.proto.dlt_gateway_pb2_grpc import add_DltGatewayServiceServicer_to_server
from common.tests.MockServicerImpl_DltGateway import MockServicerImpl_DltGateway
from common.tools.service.GenericGrpcService import GenericGrpcService
terminate = threading.Event()
logging.basicConfig(level=get_log_level())
LOGGER = logging.getLogger(__name__)
class MockDltGatewayService(GenericGrpcService):
def __init__(self, cls_name: str = 'MockDltGatewayService') -> None:
port = get_service_port_grpc(ServiceNameEnum.DLT_GATEWAY)
super().__init__(port, cls_name=cls_name)
self.dltgateway_servicer = MockServicerImpl_DltGateway()
# pylint: disable=attribute-defined-outside-init
def install_servicers(self):
add_DltGatewayServiceServicer_to_server(self.dltgateway_servicer, self.server)
def signal_handler(signal, frame): # pylint: disable=redefined-outer-name
LOGGER.warning('Terminate signal received')
terminate.set()
def main():
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
LOGGER.info('Starting...')
# Starting Mock DLT gateway service
grpc_service = MockDltGatewayService()
grpc_service.start()
# Wait for Ctrl+C or termination signal
while not terminate.wait(timeout=0.1): pass
LOGGER.info('Terminating...')
grpc_service.stop()
LOGGER.info('Bye')
return 0
if __name__ == '__main__':
sys.exit(main())
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