Commit eb8402fa authored by Antonio Gines Buendia Lopez's avatar Antonio Gines Buendia Lopez
Browse files

Merge branch 'develop' into...

Merge branch 'develop' into feat/364-elig-path-computation-extended-component-pce-for-externalized-optical-slice-computation
parents 7f34b7f3 7b9f5eb4
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -133,7 +133,7 @@ kubectl create secret generic crdb-data --namespace ${TFS_K8S_NAMESPACE} --type=
printf "\n"
printf "\n"


echo ">>> Create Secret with Apache Kafka..."
echo ">>> Create Secret with Apache Kafka..."
KFK_SERVER_PORT=$(kubectl --namespace ${KFK_NAMESPACE} get service kafka-public -o 'jsonpath={.spec.ports[0].port}')
KFK_SERVER_PORT=$(kubectl --namespace ${KFK_NAMESPACE} get service kafka-service -o 'jsonpath={.spec.ports[0].port}')
kubectl create secret generic kfk-kpi-data --namespace ${TFS_K8S_NAMESPACE} --type='Opaque' \
kubectl create secret generic kfk-kpi-data --namespace ${TFS_K8S_NAMESPACE} --type='Opaque' \
    --from-literal=KFK_NAMESPACE=${KFK_NAMESPACE} \
    --from-literal=KFK_NAMESPACE=${KFK_NAMESPACE} \
    --from-literal=KFK_SERVER_PORT=${KFK_SERVER_PORT}
    --from-literal=KFK_SERVER_PORT=${KFK_SERVER_PORT}
+3 −3
Original line number Original line Diff line number Diff line
@@ -15,7 +15,7 @@
apiVersion: v1
apiVersion: v1
kind: Service
kind: Service
metadata:
metadata:
  name: kafka-public
  name: kafka-service
  labels:
  labels:
    app.kubernetes.io/component: message-broker
    app.kubernetes.io/component: message-broker
    app.kubernetes.io/instance: kafka
    app.kubernetes.io/instance: kafka
@@ -50,7 +50,7 @@ spec:
      app.kubernetes.io/component: message-broker
      app.kubernetes.io/component: message-broker
      app.kubernetes.io/instance: kafka
      app.kubernetes.io/instance: kafka
      app.kubernetes.io/name: kafka
      app.kubernetes.io/name: kafka
  serviceName: "kafka-public"
  serviceName: "kafka-service"
  replicas: 1
  replicas: 1
  minReadySeconds: 5
  minReadySeconds: 5
  template:
  template:
@@ -83,7 +83,7 @@ spec:
          - name: KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP
          - name: KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP
            value: "PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT"
            value: "PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT"
          - name: KAFKA_CFG_ADVERTISED_LISTENERS
          - name: KAFKA_CFG_ADVERTISED_LISTENERS
            value: "PLAINTEXT://kafka-public.kafka.svc.cluster.local:9092,EXTERNAL://localhost:9094"
            value: "PLAINTEXT://kafka-service.kafka.svc.cluster.local:9092,EXTERNAL://localhost:9094"
          - name: KAFKA_CFG_CONTROLLER_LISTENER_NAMES
          - name: KAFKA_CFG_CONTROLLER_LISTENER_NAMES
            value: "CONTROLLER"
            value: "CONTROLLER"
          - name: KAFKA_CFG_CONTROLLER_QUORUM_VOTERS
          - name: KAFKA_CFG_CONTROLLER_QUORUM_VOTERS
+11 −7
Original line number Original line Diff line number Diff line
@@ -22,19 +22,23 @@ def json_policyrule_id(policyrule_uuid : str) -> Dict:
    return {'uuid': {'uuid': policyrule_uuid}}
    return {'uuid': {'uuid': policyrule_uuid}}


def json_policyrule(
def json_policyrule(
    policyrule_uuid : str, policy_priority : int = 1, policy_kpi_id : str = '',
    policyrule_uuid : str,
    policy_state : PolicyRuleStateEnum = PolicyRuleStateEnum.POLICY_UNDEFINED, policy_state_message : str = '',
    state : PolicyRuleStateEnum = PolicyRuleStateEnum.POLICY_UNDEFINED, state_message : str = '',
    action_list : List[Dict] = [], service_id : Optional[Dict] = None, device_id_list : List[Dict] = []
    priority : int = 1, action_list : List[Dict] = [], list_kpi_id : List[str] = list(),
    service_id : Optional[Dict] = None, device_id_list : List[Dict] = []
) -> Dict:
) -> Dict:
    basic = {
    basic = {
        'policyRuleId': json_policyrule_id(policyrule_uuid),
        'policyRuleId': json_policyrule_id(policyrule_uuid),
        'policyRuleState': {
        'policyRuleState': {
            'policyRuleState': policy_state,
            'policyRuleState': state,
            'policyRuleStateMessage': policy_state_message,
            'policyRuleStateMessage': state_message,
        },
        },
        'priority': policy_priority,
        'policyRulePriority': priority,
        'kpiId': {'kpi_id': {'uuid': policy_kpi_id}},
        'actionList': action_list,
        'actionList': action_list,
        'policyRuleKpiList': [
            {'policyRuleKpiUuid': {'uuid': kpi_id}}
            for kpi_id in list_kpi_id
        ],
    }
    }


    result = {}
    result = {}
+19 −15
Original line number Original line Diff line number Diff line
@@ -82,6 +82,10 @@ def policyrule_set(db_engine : Engine, messagebroker : MessageBroker, request :
        'actionList': json_policyrule_basic.get('actionList', []),
        'actionList': json_policyrule_basic.get('actionList', []),
    }, sort_keys=True)
    }, sort_keys=True)


    policyrule_list_kpi_id = [
        kpi_id.policyRuleKpiUuid.uuid for kpi_id in policyrule_basic.policyRuleKpiList
    ]

    now = datetime.datetime.now(datetime.timezone.utc)
    now = datetime.datetime.now(datetime.timezone.utc)


    policyrule_data = [{
    policyrule_data = [{
@@ -89,8 +93,8 @@ def policyrule_set(db_engine : Engine, messagebroker : MessageBroker, request :
        'policyrule_kind'        : policyrule_kind,
        'policyrule_kind'        : policyrule_kind,
        'policyrule_state'       : policyrule_state,
        'policyrule_state'       : policyrule_state,
        'policyrule_state_msg'   : policyrule_state_msg,
        'policyrule_state_msg'   : policyrule_state_msg,
        'policyrule_priority' : policyrule_basic.priority,
        'policyrule_priority'    : policyrule_basic.policyRulePriority,
        'policyrule_kpi_id'   : policyrule_basic.kpiId.kpi_id.uuid,
        'policyrule_list_kpi_id' : policyrule_list_kpi_id,
        'policyrule_eca_data'    : policyrule_eca_data,
        'policyrule_eca_data'    : policyrule_eca_data,
        'created_at'             : now,
        'created_at'             : now,
        'updated_at'             : now,
        'updated_at'             : now,
@@ -120,7 +124,7 @@ def policyrule_set(db_engine : Engine, messagebroker : MessageBroker, request :
                policyrule_state       = stmt.excluded.policyrule_state,
                policyrule_state       = stmt.excluded.policyrule_state,
                policyrule_state_msg   = stmt.excluded.policyrule_state_msg,
                policyrule_state_msg   = stmt.excluded.policyrule_state_msg,
                policyrule_priority    = stmt.excluded.policyrule_priority,
                policyrule_priority    = stmt.excluded.policyrule_priority,
                policyrule_kpi_id    = stmt.excluded.policyrule_kpi_id,
                policyrule_list_kpi_id = stmt.excluded.policyrule_list_kpi_id,
                policyrule_eca_data    = stmt.excluded.policyrule_eca_data,
                policyrule_eca_data    = stmt.excluded.policyrule_eca_data,
                updated_at             = stmt.excluded.updated_at,
                updated_at             = stmt.excluded.updated_at,
            )
            )
+16 −6
Original line number Original line Diff line number Diff line
@@ -14,7 +14,7 @@


import enum, json
import enum, json
from sqlalchemy import CheckConstraint, Column, DateTime, Enum, ForeignKey, Integer, String
from sqlalchemy import CheckConstraint, Column, DateTime, Enum, ForeignKey, Integer, String
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.dialects.postgresql import ARRAY, UUID
from sqlalchemy.orm import relationship
from sqlalchemy.orm import relationship
from typing import Dict
from typing import Dict
from .enums.PolicyRuleState import ORM_PolicyRuleStateEnum
from .enums.PolicyRuleState import ORM_PolicyRuleStateEnum
@@ -33,7 +33,7 @@ class PolicyRuleModel(_Base):
    policyrule_state        = Column(Enum(ORM_PolicyRuleStateEnum), nullable=False)
    policyrule_state        = Column(Enum(ORM_PolicyRuleStateEnum), nullable=False)
    policyrule_state_msg    = Column(String, nullable=False)
    policyrule_state_msg    = Column(String, nullable=False)
    policyrule_priority     = Column(Integer, nullable=False)
    policyrule_priority     = Column(Integer, nullable=False)
    policyrule_kpi_id       = Column(String, nullable=False)
    policyrule_list_kpi_id  = Column(ARRAY(String, dimensions=1), nullable=False)
    policyrule_service_uuid = Column(ForeignKey('service.service_uuid', ondelete='RESTRICT'), nullable=True, index=True)
    policyrule_service_uuid = Column(ForeignKey('service.service_uuid', ondelete='RESTRICT'), nullable=True, index=True)
    policyrule_eca_data     = Column(String, nullable=False)
    policyrule_eca_data     = Column(String, nullable=False)
    created_at              = Column(DateTime, nullable=False)
    created_at              = Column(DateTime, nullable=False)
@@ -50,20 +50,30 @@ class PolicyRuleModel(_Base):
        return {'uuid': {'uuid': self.policyrule_uuid}}
        return {'uuid': {'uuid': self.policyrule_uuid}}


    def dump(self) -> Dict:
    def dump(self) -> Dict:
        # Load JSON-encoded Event-Condition-Action (ECA) model data and populate with policy basic details
        # Load JSON-encoded Event-Condition-Action (ECA) model data
        policyrule_basic = json.loads(self.policyrule_eca_data)
        policyrule_basic = json.loads(self.policyrule_eca_data)

        # Populate policy rule basic details
        policyrule_basic.update({
        policyrule_basic.update({
            'policyRuleId': self.dump_id(),
            'policyRuleId': self.dump_id(),
            'policyRuleState': {
            'policyRuleState': {
                'policyRuleState': self.policyrule_state.value,
                'policyRuleState': self.policyrule_state.value,
                'policyRuleStateMessage': self.policyrule_state_msg,
                'policyRuleStateMessage': self.policyrule_state_msg,
            },
            },
            'priority': self.policyrule_priority,
            'policyRulePriority': self.policyrule_priority,
            'kpiId': {'kpi_id': {'uuid': self.policyrule_kpi_id}},
            'policyRuleKpiList': [
                {'policyRuleKpiUuid': {'uuid': kpi_id}}
                for kpi_id in self.policyrule_list_kpi_id
            ]
        })
        })

        # Compose final Policy Rule
        result = {
        result = {
            'policyRuleBasic': policyrule_basic,
            'policyRuleBasic': policyrule_basic,
            'deviceList': [{'device_uuid': {'uuid': pr_d.device_uuid}} for pr_d in self.policyrule_devices],
            'deviceList': [
                {'device_uuid': {'uuid': pr_d.device_uuid}}
                for pr_d in self.policyrule_devices
            ],
        }
        }
        if self.policyrule_kind == PolicyRuleKindEnum.SERVICE:
        if self.policyrule_kind == PolicyRuleKindEnum.SERVICE:
            result['serviceId'] = self.policyrule_service.dump_id()
            result['serviceId'] = self.policyrule_service.dump_id()
Loading