Temporal Charm
[osm/devops.git] / installers / charm / osm-nbi / src / charm.py
index 454b155..77c8a18 100755 (executable)
@@ -41,6 +41,7 @@ from charms.osm_libs.v0.utils import (
     check_service_active,
 )
 from charms.osm_nbi.v0.nbi import NbiProvides
+from charms.osm_temporal.v0.temporal import TemporalRequires
 from lightkube.models.core_v1 import ServicePort
 from ops.charm import ActionEvent, CharmBase, RelationJoinedEvent
 from ops.framework import StoredState
@@ -82,6 +83,7 @@ class OsmNbiCharm(CharmBase):
         )
         self.kafka = KafkaRequires(self)
         self.nbi = NbiProvides(self)
+        self.temporal = TemporalRequires(self)
         self.mongodb_client = MongoClient(self, "mongodb")
         self.prometheus_client = PrometheusClient(self, "prometheus")
         self.keystone_client = KeystoneClient(self, "keystone")
@@ -113,7 +115,8 @@ class OsmNbiCharm(CharmBase):
             # Eventually it will become ready after the first pebble-ready event.
             check_container_ready(self.container)
 
-            self._configure_service(self.container)
+            if not self.debug_mode.started:
+                self._configure_service(self.container)
             self._update_ingress_config()
             self._update_nbi_relation()
             # Update charm status
@@ -181,6 +184,8 @@ class OsmNbiCharm(CharmBase):
             # Action events
             self.on.get_debug_mode_information_action: self._on_get_debug_mode_information_action,
             self.on.nbi_relation_joined: self._update_nbi_relation,
+            self.on["temporal"].relation_changed: self._on_config_changed,
+            self.on["temporal"].relation_broken: self._on_required_relation_broken,
         }
         for relation in [self.on[rel_name] for rel_name in ["mongodb", "prometheus", "keystone"]]:
             event_handler_mapping[relation.relation_changed] = self._on_config_changed
@@ -214,6 +219,8 @@ class OsmNbiCharm(CharmBase):
             missing_relations.append("prometheus")
         if self.keystone_client.is_missing_data_in_app():
             missing_relations.append("keystone")
+        if not self.temporal.host or not self.temporal.port:
+            missing_relations.append("temporal")
 
         if missing_relations:
             relations_str = ", ".join(missing_relations)
@@ -288,6 +295,9 @@ class OsmNbiCharm(CharmBase):
                         "OSMNBI_SERVER_SSL_CERTIFICATE": "",
                         "OSMNBI_SERVER_SSL_PRIVATE_KEY": "",
                         "OSMNBI_SERVER_SSL_PASS_PHRASE": "",
+                        # Temporal configuration
+                        "OSMNBI_TEMPORAL_HOST": self.temporal.host,
+                        "OSMNBI_TEMPORAL_PORT": self.temporal.port,
                     },
                 }
             },