Commit 80939202 authored by Waleed Akbar's avatar Waleed Akbar
Browse files

Cleaning code for merge

parent 12909611
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ spec:
    port: 9093
    protocol: TCP
    targetPort: 9093
  - name: external
  - name: external    # for testing purposes (To expose Kafka outside the cluster)
    port: 9094
    protocol: TCP
    targetPort: 9094
@@ -73,7 +73,7 @@ spec:
          containerPort: 9092
        - name: control-plane
          containerPort: 9093
        - name: external
        - name: external    # for testing purposes
          containerPort: 9094
        env:
          - name: KAFKA_CFG_NODE_ID
@@ -81,7 +81,7 @@ spec:
          - name: KAFKA_CFG_PROCESS_ROLES
            value: "controller,broker"
          - name: KAFKA_CFG_LISTENERS
            value: "PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:9094"
            value: "PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:9094" # EXTERNAL://:9094 for testing purposes
          - name: KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP
            value: "PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT"
          - name: KAFKA_CFG_ADVERTISED_LISTENERS
+0 −1
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ export TFS_COMPONENTS="context device pathcomp service webui"

# Uncomment to activate Monitoring Framework (new)
#export TFS_COMPONENTS="${TFS_COMPONENTS} kpi_manager kpi_value_writer kpi_value_api telemetry analytics automation"
export TFS_COMPONENTS="${TFS_COMPONENTS} kpi_manager telemetry"

# Uncomment to activate QoS Profiles
#export TFS_COMPONENTS="${TFS_COMPONENTS} qos_profile"
+2 −6
Original line number Diff line number Diff line
@@ -43,12 +43,8 @@ class KafkaConfig(Enum):
    def get_kafka_address() -> str:
        kafka_server_address  = get_setting('KFK_SERVER_ADDRESS', default=None)
        if kafka_server_address is None:
            try:
                KFK_NAMESPACE = get_setting('KFK_NAMESPACE')
                KFK_PORT      = get_setting('KFK_SERVER_PORT')
            except Exception:
                KFK_NAMESPACE = 'kafka'
                KFK_PORT      = '9092'
            KFK_NAMESPACE = get_setting('KFK_NAMESPACE', default='kafka')
            KFK_PORT      = get_setting('KFK_SERVER_PORT', default='9092')
            kafka_server_address = KFK_SERVER_ADDRESS_TEMPLATE.format(KFK_NAMESPACE, KFK_PORT)
        return kafka_server_address
        
+0 −1
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ import logging, signal, sys, threading
from typing import Optional
from prometheus_client.exposition import start_http_server
from common.Settings import get_log_level, get_metrics_port
from common.Constants import ServiceNameEnum
from common.tools.kafka.Variables import KafkaTopic
from .TelemetryBackendService import TelemetryBackendService

+0 −83
Original line number Diff line number Diff line
# Copyright 2022-2024 ETSI 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 anytree
from typing import Any, List, Optional, Union
from apscheduler.job import Job

class TreeNode(anytree.node.Node):
    def __init__(self, name, parent=None, children=None, **kwargs) -> None:
        super().__init__(name, parent=parent, children=children, **kwargs)
        self.value : Optional[Any] = None

    def get_full_path(self):
        return self.separator.join([''] + [str(node.name) for node in self.path])

class RawStyle(anytree.render.AbstractStyle):
    def __init__(self):
        """
        Raw style.

        >>> from anytree import Node, RenderTree
        >>> root = Node("root")
        >>> s0 = Node("sub0", parent=root)
        >>> s0b = Node("sub0B", parent=s0)
        >>> s0a = Node("sub0A", parent=s0)
        >>> s1 = Node("sub1", parent=root)
        >>> print(RenderTree(root, style=RawStyle()))
        Node('/root')
        Node('/root/sub0')
        Node('/root/sub0/sub0B')
        Node('/root/sub0/sub0A')
        Node('/root/sub1')
        """
        super(RawStyle, self).__init__('', '', '')

def get_subnode(
    resolver : anytree.Resolver, root : TreeNode, key_or_path : Union[str, List[str]], default : Optional[Any] = None):

    if isinstance(key_or_path, str): key_or_path = key_or_path.split('/')
    node = root
    for path_item in key_or_path:
        try:
            node = resolver.get(node, path_item)
        except anytree.ChildResolverError:
            return default
    return node

def set_subnode_value(resolver : anytree.Resolver, root : TreeNode, key_or_path : Union[str, List[str]], value : Any):
    if isinstance(key_or_path, str): key_or_path = key_or_path.split('/')
    node = root
    for path_item in key_or_path:
        try:
            node = resolver.get(node, path_item)
        except anytree.ChildResolverError:
            node = TreeNode(path_item, parent=node)
    if isinstance(node.value, dict) and isinstance(value, dict):
        node.value.update(value)
    else:
        node.value = value

def dump_subtree(root : TreeNode):
    if not isinstance(root, TreeNode): raise Exception('root must be a TreeNode')
    results = []
    for row in anytree.RenderTree(root, style=RawStyle()):
        node : TreeNode = row.node
        path = node.get_full_path()[2:] # get full path except the heading root placeholder "/."
        if len(path) == 0: continue
        value = node.value
        if value is None: continue
        if isinstance(value, Job): value = str(value)
        results.append((path, value))
    return results
Loading