At the Juju level, the only change to relation-data in the Juju controller and Juju agent protocol that I am aware of, in nearly 10 years, was the addition of application-level data which the leader units can write. relation-set
and relation-get
are the agent-level commands that handle that data, iirc.
All the work in the charm code space, with reactive and now the Python operator framework, uses those agent-level primitives to set and get these key-value relation data structures, and handles the events that come from a counterpart unit updating its data in the structure.
I think the remaining piece of info I would like to see in this thread are:
-
can someone reply with an example of Python using the Python operator framework that gets or sets a value in the relation data, as exposed at the Python operator framework level?
-
can someone reply with an example of a higher-level application-specific application integration class, where the same sort of relation data is exposed, but in an application-centric way?
I would guess at something like this for the framework level expression of the relation-data:
# Raw relation data in the framework
value = self.endpoints['db'][n].remote[m]['addr']
In this rather pedantic guess-a-thon, self
is the application that the charm is driving, endpoints['db']
is the endpoint for the relation indexed by declared name, [n]
is to accommodate the general Juju application graph that allows multiple relations to a particular endpoint (you can connect multiple apps to the same logging service for example), remote[m]
is a way of expressing that I want the unit data set by the unit m
on the other side of the relation rather than the data from a unit of my peers, and ['addr']
is which data I want from that units key-value pairs.
And I would guess at something like this for what a MySQL charm might offer up in an integration library:
# Endpoint that is only ever allowed to have a single database related
import charm.mysql.v3.msqldb as mysql
db = mysql.SingleDB('db')
if db.connected:
ip_addr = db.addr
Waving hands furiously, in this example I am importing the latest minor revision of mysqldb integration library major version 3, telling it to give me an instance for any database attached to the endpoint ‘db’, ignoring units because those have been handled in the integration library class internals that I don’t want to care about (failover etc are all handled internally to the library ideally).