Resolve "(CTTC) Replace DLT Gateway functionality with an opensource and Hyper Ledger v2.4+ compliant version"

Closes #165 (closed)

Merge request reports

Loading
+15 −0
Changes for deploy/tfs.sh: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -229,6 +229,21 @@ kubectl create secret generic qdb-data --namespace ${TFS_K8S_NAMESPACE} --type='
    --from-literal=METRICSDB_PASSWORD=${QDB_PASSWORD}
printf "\n"

# Check if "dlt" is in the list of components
if [[ " ${TFS_COMPONENTS[@]} " =~ " dlt " ]]; then
  echo "Create secret for HLF keystore"
  kubectl create secret generic dlt-keystone --namespace ${TFS_K8S_NAMESPACE} --from-file=keystore=${KEY_DIRECTORY_PATH}
  printf "\n"

  echo "Create secret for HLF signcerts"
  kubectl create secret generic dlt-signcerts --namespace ${TFS_K8S_NAMESPACE} --from-file=signcerts.pem=${CERT_DIRECTORY_PATH}
  printf "\n"

  echo "Create secret for HLF ca.crt"
  kubectl create secret generic dlt-ca-crt --namespace ${TFS_K8S_NAMESPACE} --from-file=ca.crt=${TLS_CERT_PATH}
  printf "\n"
fi

echo "Deploying components and collecting environment variables..."
ENV_VARS_SCRIPT=tfs_runtime_env_vars.sh
echo "# Environment variables for TeraFlowSDN deployment" > $ENV_VARS_SCRIPT
+61 −0
Changes for manifests/dltservice.yaml: 61 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -12,6 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: v1
kind: ConfigMap
metadata:
  name: dlt-config
data:
  CHANNEL_NAME: "tfs_channel"                 # Change according to your blockchain configuration
  CHAINCODE_NAME: "tfs_dlt"                   # Change according to your blockchain configuration
  MSP_ID: "ETSI"                              # Change according to your blockchain configuration
  PEER_ENDPOINT: "127.0.0.1:7051"             # Change according to your blockchain configuration
  PEER_HOST_ALIAS: "peer0.org1.tfs.etsi.org"  # Change according to your blockchain configuration
  KEY_DIRECTORY_PATH: "/etc/hyperledger/fabric-keystore/keystore"
  CERT_DIRECTORY_PATH: "/etc/hyperledger/fabric-signcerts/signcerts.pem"
  TLS_CERT_PATH: "/etc/hyperledger/fabric-ca-crt/ca.crt"

---
apiVersion: apps/v1
kind: Deployment
metadata:
@@ -78,6 +93,52 @@ spec:
            limits:
              cpu: 700m
              memory: 1024Mi
          volumeMounts:
            - name: keystore
              mountPath: /etc/hyperledger/fabric-keystore
              readOnly: true
            - name: signcerts
              mountPath: /etc/hyperledger/fabric-signcerts
              readOnly: true
            - name: ca-crt
              mountPath: /etc/hyperledger/fabric-ca-crt
              readOnly: true
          envFrom:
            - configMapRef:
                name: dlt-config
          env:
            - name: KEY_DIRECTORY_PATH
              value: "/etc/hyperledger/fabric-keystore/keystore"
            - name: CERT_DIRECTORY_PATH
              value: "/etc/hyperledger/fabric-signcerts/signcerts.pem"
            - name: TLS_CERT_PATH
              value: "/etc/hyperledger/fabric-ca-crt/ca.crt"
      volumes:
        - name: keystore
          secret:
            secretName: dlt-keystone
        - name: signcerts
          secret:
            secretName: dlt-signcerts
        - name: ca-crt
          secret:
            secretName: dlt-ca-crt

---
apiVersion: v1
kind: Service
metadata:
  name: gatewayservice
spec:
  selector:
    app: dltservice
  ports:
    - protocol: TCP
      port: 50051
      targetPort: 50051
      nodePort: 32001
  type: NodePort

---
apiVersion: v1
kind: Service
+2 −0
Changes for manifests/interdomainservice.yaml: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ spec:
              value: "INFO"
            - name: TOPOLOGY_ABSTRACTOR
              value: "DISABLE"
            - name: DLT_INTEGRATION
              value: "DISABLE"
          readinessProbe:
            exec:
              command: ["/bin/grpc_health_probe", "-addr=:10010"]
+32 −0
Changes for src/common/method_wrappers/Decorator.py: 32 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -235,3 +235,35 @@ def safe_and_metered_rpc_method(metrics_pool : MetricsPool, logger : logging.Log
                grpc_context.abort(grpc.StatusCode.INTERNAL, str(e))
        return inner_wrapper
    return outer_wrapper

def safe_and_metered_rpc_method_async(metrics_pool: MetricsPool, logger: logging.Logger):
    def outer_wrapper(func):
        method_name = func.__name__
        metrics = metrics_pool.get_metrics(method_name)
        histogram_duration, counter_started, counter_completed, counter_failed = metrics

        async def inner_wrapper(self, request, grpc_context: grpc.aio.ServicerContext):
            counter_started.inc()
            try:
                logger.debug('{:s} request: {:s}'.format(method_name, grpc_message_to_json_string(request)))
                reply = await func(self, request, grpc_context)
                logger.debug('{:s} reply: {:s}'.format(method_name, grpc_message_to_json_string(reply)))
                counter_completed.inc()
                return reply
            except ServiceException as e:  # pragma: no cover (ServiceException not thrown)
                if e.code not in [grpc.StatusCode.NOT_FOUND, grpc.StatusCode.ALREADY_EXISTS]:
                    # Assume not found or already exists is just a condition, not an error
                    logger.exception('{:s} exception'.format(method_name))
                    counter_failed.inc()
                else:
                    counter_completed.inc()
                await grpc_context.abort(e.code, e.details)
            except Exception as e:  # pragma: no cover, pylint: disable=broad-except
                logger.exception('{:s} exception'.format(method_name))
                counter_failed.inc()
                await grpc_context.abort(grpc.StatusCode.INTERNAL, str(e))

        return inner_wrapper

    return outer_wrapper
+72 −0
Changes for src/common/tools/service/GenericGrpcServiceAsync.py: 72 added lines, 0 removed lines.
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.

from typing import Optional, Union
import grpc
import logging
from concurrent import futures
from grpc_health.v1.health import HealthServicer, OVERALL_HEALTH
from grpc_health.v1.health_pb2 import HealthCheckResponse
from grpc_health.v1.health_pb2_grpc import add_HealthServicer_to_server
from common.Settings import get_grpc_bind_address, get_grpc_grace_period, get_grpc_max_workers

class GenericGrpcServiceAsync:
    def __init__(
        self, bind_port: Union[str, int], bind_address: Optional[str] = None, max_workers: Optional[int] = None,
        grace_period: Optional[int] = None, enable_health_servicer: bool = True, cls_name: str = __name__
    ) -> None:
        self.logger = logging.getLogger(cls_name)
        self.bind_port = bind_port
        self.bind_address = get_grpc_bind_address() if bind_address is None else bind_address
        self.max_workers = get_grpc_max_workers() if max_workers is None else max_workers
        self.grace_period = get_grpc_grace_period() if grace_period is None else grace_period
        self.enable_health_servicer = enable_health_servicer
        self.endpoint = None
        self.health_servicer = None
        self.pool = None
        self.server = None

    async def install_servicers(self):
        pass

    async def start(self):
        self.endpoint = '{:s}:{:s}'.format(str(self.bind_address), str(self.bind_port))
        self.logger.info('Starting Service (tentative endpoint: {:s}, max_workers: {:s})...'.format(
            str(self.endpoint), str(self.max_workers)))

        self.pool = futures.ThreadPoolExecutor(max_workers=self.max_workers)
        self.server = grpc.aio.server(self.pool)

        await self.install_servicers()  # Ensure this is awaited

        if self.enable_health_servicer:
            self.health_servicer = HealthServicer(
                experimental_non_blocking=True, experimental_thread_pool=futures.ThreadPoolExecutor(max_workers=1))
            add_HealthServicer_to_server(self.health_servicer, self.server)

        self.bind_port = self.server.add_insecure_port(self.endpoint)
        self.endpoint = '{:s}:{:s}'.format(str(self.bind_address), str(self.bind_port))
        self.logger.info('Listening on {:s}...'.format(str(self.endpoint)))
        await self.server.start()
        if self.enable_health_servicer:
            self.health_servicer.set(OVERALL_HEALTH, HealthCheckResponse.SERVING)

        self.logger.debug('Service started')

    async def stop(self):
        self.logger.debug('Stopping service (grace period {:s} seconds)...'.format(str(self.grace_period)))
        if self.enable_health_servicer:
            self.health_servicer.enter_graceful_shutdown()
        await self.server.stop(self.grace_period)
        self.logger.debug('Service stopped')
Loading
Loading