示例#1
0
 def _convert_listener_template(self, lst):
     if not lst or len(lst) == 0:
         raise KafkaListenerRelationEmptyListenerDictError()
     listeners = lst.replace("*BINDING*", get_hostname(self.binding_addr))
     listeners = listeners.replace("*ADVERTISE*",
                                   get_hostname(self.advertise_addr))
     listeners = json.loads(listeners)
     return listeners
示例#2
0
 def on_zookeeper_relation_joined(self, event):
     # Get unit's own hostname and pass that via relation
     r = event.relation
     hostname = self._hostname if self._hostname \
         else get_hostname(self.binding_addr)
     r.data[self.unit]["endpoint"] = \
         "{}:{}".format(hostname, self._port)
示例#3
0
    def _get_api_url(self, advertise_addr):
        """Returns the API endpoint for a given service. If the config
        is not manually set, then the advertise_addr is used instead."""

        return "{}://{}:{}".format(
            "https" if self.is_ssl_enabled() else "http",
            self.config["api_url"] if len(self.config["api_url"]) > 0 else
            get_hostname(advertise_addr), self.config.get("clientPort", 0))
示例#4
0
 def on_mds_relation_changed(self, event):
     hostname = self._hostname if self._hostname \
         else get_hostname(self.binding_addr)
     url = "{}://{}:{}".format(self._protocol,
                               hostname,
                               self._port)
     self.mds_url = url
     if not self.unit.is_leader():
         return
     self._check_rbac_enabled()
     if len(self.state.mds_super_user) == 0:
         raise KafkaMDSRelationConfigIncorrectError(
             "mds_super_user")
     if len(self.state.mds_super_user_pwd) == 0:
         raise KafkaMDSRelationConfigIncorrectError(
             "mds_super_user_password")
    def set_schema_url(self, url, port, prot):
        """DEPRECATED
           Use schema_url instead"""

        if not self.relations:
            return
        if not self.unit.is_leader():
            return
        # URL is set to config on schema registry, then the same value will
        # be passed by each of the schema registry instances. On the requester
        # side, the value collected is put on a set, which will end as one
        # single URL.
        for r in self.relations:
            r.data[self.model.app]["url"] = \
                "{}://{}:{}".format(
                    prot if len(prot) > 0 else "https",
                    url if len(url) > 0 else get_hostname(
                        self.advertise_addr),
                    port)
示例#6
0
 def hostname(self):
     return self._hostname if self._hostname \
         else get_hostname(self.binding_addr)
 def hostname(self):
     return get_hostname(self.binding_addr)