Scheduled maintenance on Saturday, 27 September 2025, from 07:00 AM to 4:00 PM GMT (09:00 AM to 6:00 PM CEST) - some services may be unavailable -

Skip to content
Snippets Groups Projects
Select Git revision
  • 3af6c738304f4032a6e12cf67c8aacf677ae16d9
  • master default
  • feat/320-cttc-ietf-simap-basic-support-with-kafka-yang-push
  • feat/307-update-python-version-service
  • feat/292-cttc-implement-integration-test-for-ryu-openflow
  • cnit_tapi
  • feat/314-tid-new-service-for-ipowdm-configuration-fron-orchestrator-to-ipowdm-controller
  • feat/327-tid-new-service-to-ipowdm-controller-to-manage-transceivers-configuration-on-external-agent
  • cnit-p2mp-premerge
  • feat/325-tid-nbi-e2e-to-manage-e2e-path-computation
  • feat/326-tid-external-management-of-devices-telemetry-nbi
  • openroadm-flex-grid
  • feat/310-cttc-implement-nbi-connector-to-interface-with-osm-client
  • develop protected
  • feat/324-tid-nbi-ietf_l3vpn-deploy-fail
  • feat/321-add-support-for-gnmi-configuration-via-proto
  • feat/322-add-read-support-for-ipinfusion-devices-via-netconf
  • feat/323-add-support-for-restconf-protocol-in-devices
  • feat/policy-refactor
  • feat/192-cttc-implement-telemetry-backend-collector-gnmi-openconfig
  • feat/307-update-python-version
  • feat/telemetry-collector-int
  • v5.0.0 protected
  • v4.0.0 protected
  • demo-dpiab-eucnc2024
  • v3.0.0 protected
  • v2.1.0 protected
  • v2.0.0 protected
  • v1.0.0 protected
29 results

add_license_header_to_files.sh

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Variables.py 3.38 KiB
    # 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 logging
    from enum import Enum
    from confluent_kafka import KafkaException
    from confluent_kafka.admin import AdminClient, NewTopic
    from common.Settings import get_setting
    
    
    LOGGER = logging.getLogger(__name__)
    
    class KafkaConfig(Enum):
        KFK_SERVER_ADDRESS_TEMPLATE = 'kafka-service.{:s}.svc.cluster.local:{:s}'
        KFK_NAMESPACE               = get_setting('KFK_NAMESPACE')
        KFK_PORT                    = get_setting('KFK_SERVER_PORT')
        # SERVER_ADDRESS              = "127.0.0.1:9092"
        SERVER_ADDRESS =  KFK_SERVER_ADDRESS_TEMPLATE.format(KFK_NAMESPACE, KFK_PORT)
        ADMIN_CLIENT                = AdminClient({'bootstrap.servers': SERVER_ADDRESS })
    
    class KafkaTopic(Enum):
        REQUEST  = 'topic_request' 
        RESPONSE = 'topic_response'
        RAW      = 'topic_raw' 
        LABELED  = 'topic_labeled'
        VALUE    = 'topic_value'
    
        @staticmethod
        def create_all_topics() -> bool:
            """
                Method to create Kafka topics defined as class members
            """
            all_topics = [member.value for member in KafkaTopic]
            LOGGER.debug("Kafka server address is: {:} ".format(KafkaConfig.SERVER_ADDRESS.value))
            if( KafkaTopic.create_new_topic_if_not_exists( all_topics )):
                LOGGER.debug("All topics are created sucsessfully")
                return True
            else:
                LOGGER.debug("Error creating all topics")
                return False
        
        @staticmethod
        def create_new_topic_if_not_exists(new_topics: list) -> bool:
            """
            Method to create Kafka topic if it does not exist.
            Args:
                list of topic: containing the topic name(s) to be created on Kafka
            """
            LOGGER.debug("Topics names to be verified and created: {:}".format(new_topics))
            for topic in new_topics:
                try:
                    topic_metadata = KafkaConfig.ADMIN_CLIENT.value.list_topics(timeout=5)
                    # LOGGER.debug("Existing topic list: {:}".format(topic_metadata.topics))
                    if topic not in topic_metadata.topics:
                        # If the topic does not exist, create a new topic
                        print("Topic {:} does not exist. Creating...".format(topic))
                        LOGGER.debug("Topic {:} does not exist. Creating...".format(topic))
                        new_topic = NewTopic(topic, num_partitions=1, replication_factor=1)
                        KafkaConfig.ADMIN_CLIENT.value.create_topics([new_topic])
                    else:
                        print("Topic name already exists: {:}".format(topic))
                        LOGGER.debug("Topic name already exists: {:}".format(topic))
                except Exception as e:
                    LOGGER.debug("Failed to create topic: {:}".format(e))
                    return False
            return True
    
    # create all topics after the deployments (Telemetry and Analytics)