Commit 7b9f5eb4 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch...

Merge branch 'feat/383-cttc-fix-ci-cd-pipeline-kafka-service-name-and-context-unit-tests' into 'develop'

Resolve "(CTTC) Fix CI/CD pipeline - Kafka service name and Context unit tests"

See merge request !443
parents bf9f7c11 a4f5eca6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ kubectl create secret generic crdb-data --namespace ${TFS_K8S_NAMESPACE} --type=
printf "\n"

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' \
    --from-literal=KFK_NAMESPACE=${KFK_NAMESPACE} \
    --from-literal=KFK_SERVER_PORT=${KFK_SERVER_PORT}
+3 −3
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
apiVersion: v1
kind: Service
metadata:
  name: kafka-public
  name: kafka-service
  labels:
    app.kubernetes.io/component: message-broker
    app.kubernetes.io/instance: kafka
@@ -50,7 +50,7 @@ spec:
      app.kubernetes.io/component: message-broker
      app.kubernetes.io/instance: kafka
      app.kubernetes.io/name: kafka
  serviceName: "kafka-public"
  serviceName: "kafka-service"
  replicas: 1
  minReadySeconds: 5
  template:
@@ -83,7 +83,7 @@ spec:
          - name: KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP
            value: "PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT"
          - 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
            value: "CONTROLLER"
          - name: KAFKA_CFG_CONTROLLER_QUORUM_VOTERS
+11 −7
Original line number Diff line number Diff line
@@ -22,19 +22,23 @@ def json_policyrule_id(policyrule_uuid : str) -> Dict:
    return {'uuid': {'uuid': policyrule_uuid}}

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

    result = {}
+19 −15
Original line number Diff line number Diff line
@@ -82,6 +82,10 @@ def policyrule_set(db_engine : Engine, messagebroker : MessageBroker, request :
        'actionList': json_policyrule_basic.get('actionList', []),
    }, 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)

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

import enum, json
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 typing import Dict
from .enums.PolicyRuleState import ORM_PolicyRuleStateEnum
@@ -33,7 +33,7 @@ class PolicyRuleModel(_Base):
    policyrule_state        = Column(Enum(ORM_PolicyRuleStateEnum), nullable=False)
    policyrule_state_msg    = Column(String, 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_eca_data     = Column(String, nullable=False)
    created_at              = Column(DateTime, nullable=False)
@@ -50,20 +50,30 @@ class PolicyRuleModel(_Base):
        return {'uuid': {'uuid': self.policyrule_uuid}}

    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)

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

        # Compose final Policy Rule
        result = {
            '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:
            result['serviceId'] = self.policyrule_service.dump_id()
Loading