---
title: Charmhub | Deploy Charmed Apache Zookeeper using Charmhub - The Open Operator
  Collection
description: Deploy the latest version of Charmed Apache Zookeeper on any cloud.
url: https://charmhub.io/zookeeper/libraries/zookeeper_provider
---

# Charmed Apache Zookeeper

[Canonical](https://charmhub.io/publisher/data-platform "View all packages from Canonical")

* [Canonical](https://charmhub.io/publisher/data-platform "View all packages from Canonical")
* [Databases](https://charmhub.io/?filter=databases)

Platform:

22.04

20.04

18.04

16.04

3/stable 163

```
juju deploy zookeeper --channel 3/stable
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

[Toggle side navigation](https://charmhub.io/zookeeper/libraries/zookeeper_provider#drawer)

## charms.zookeeper.v0.zookeeper\_provider

* [*Docstrings*Docstrings](https://charmhub.io/zookeeper/libraries/zookeeper_provider)
  [*Code*Source code](https://charmhub.io/zookeeper/libraries/zookeeper_provider/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.zookeeper.v0.zookeeper_provider
    ```

    [Download zookeeper\_provider.py](https://charmhub.io/zookeeper/libraries/zookeeper_provider/download)
  + *Last updated* 12 Jul 2022
  + *Revision* Library version 0.2

ZooKeeperProvider class and methods.

`ZooKeeperProvider` handles the provider side abstraction for ZooKeeper client relations.

It abstracts the updating the ZK quorum of authorised users and their ACLs during
`zookeeper_relation_updated/joined` and `zookeeper_relation_broken` events.

During these events, ACLs and user zNodes are updated on the leader for all related applications,
client and peer relation data is set with the necessary information on both side, and new users are
added to the unit's JAAS config file, whereupon which a rolling restart of the ZooKeeper service is
triggered.

Example usage for `ZooKeeperProvider`:

```
class ZooKeeperCharm(CharmBase):
    def __init__(self, *args):
        super().__init__(*args)
        self.provider = ZooKeeperProvider(self)
        self.restart = RollingOpsManager(self, relation="restart", callback=self._on_start)

    def _on_start(self, event):

        # event is passed here to check for RelationBrokenEvents
        # in which case that relation will be removed
        users = self.provider.build_jaas_users(event=event)

        # get_passwords()
        # set_zookeeper_auth_config(passwords, users)
        # restart_snap_service()
```

---

Index

* [class ZooKeeperProvider](https://charmhub.io/zookeeper/libraries/zookeeper_provider#zookeeperprovider)
* + [def \_\_init\_\_(
    self,
    charm)](https://charmhub.io/zookeeper/libraries/zookeeper_provider#zookeeperprovider-__init__)
* + [def app\_relation(
    self)](https://charmhub.io/zookeeper/libraries/zookeeper_provider#zookeeperprovider-app_relation)
* + [def client\_relations(
    self)](https://charmhub.io/zookeeper/libraries/zookeeper_provider#zookeeperprovider-client_relations)
* + [def relation\_config(
    self,
    relation,
    event)](https://charmhub.io/zookeeper/libraries/zookeeper_provider#zookeeperprovider-relation_config)
* + [def build\_jaas\_users(
    self,
    event)](https://charmhub.io/zookeeper/libraries/zookeeper_provider#zookeeperprovider-build_jaas_users)
* + [def relations\_config(
    self,
    event)](https://charmhub.io/zookeeper/libraries/zookeeper_provider#zookeeperprovider-relations_config)
* + [def build\_acls(
    self,
    event)](https://charmhub.io/zookeeper/libraries/zookeeper_provider#zookeeperprovider-build_acls)
* + [def relations\_config\_values\_for\_key(
    self,
    key,
    event)](https://charmhub.io/zookeeper/libraries/zookeeper_provider#zookeeperprovider-relations_config_values_for_key)
* + [def update\_acls(
    self,
    event)](https://charmhub.io/zookeeper/libraries/zookeeper_provider#zookeeperprovider-update_acls)
* + [def apply\_relation\_data(
    self,
    event)](https://charmhub.io/zookeeper/libraries/zookeeper_provider#zookeeperprovider-apply_relation_data)

#### class ZooKeeperProvider

Methods

ZooKeeperProvider.
\_\_init\_\_(

*self*

,
charm
)

ZooKeeperProvider.
app\_relation(

*self*
)

Description

Gets the current ZK peer relation. None

ZooKeeperProvider.
client\_relations(

*self*
)

Description

Gets the relations for all related client applications. None

ZooKeeperProvider.
relation\_config(

*self*

,
relation: Relation

,
event
)

Gets the auth config for a currently related application.

Arguments

relation

the relation you want to build config for

event
(optional)

the corresponding event.
If passed and is `RelationBrokenEvent`, will skip and return `None`

Returns

Dict containing relation `username`, `password`, `chroot`, `acl`
`None` if `RelationBrokenEvent` is passed as event

ZooKeeperProvider.
build\_jaas\_users(

*self*

,
event
)

Builds the necessary user strings to add to ZK JAAS config files.

Arguments

event
(optional)

used for checking `RelationBrokenEvent`

Returns

Newline delimited string of JAAS users from relation data

ZooKeeperProvider.
relations\_config(

*self*

,
event
)

Gets auth configs for all currently related applications.

Arguments

event
(optional)

used for checking `RelationBrokenEvent`

Returns

Dict of key = `relation_id`, value = `relations_config()` for all related apps

ZooKeeperProvider.
build\_acls(

*self*

,
event
)

Gets ACLs for all currently related applications.

Arguments

event
(optional)

used for checking `RelationBrokenEvent`

Returns

Dict of `chroot`s with value as list of ACLs for the `chroot`

ZooKeeperProvider.
relations\_config\_values\_for\_key(

*self*

,
key: str

,
event
)

Grabs a specific auth config value from all related applications.

Arguments

event
(optional)

used for checking `RelationBrokenEvent`

Returns

Set of all app values matching a specific key from `relations_config()`

ZooKeeperProvider.
update\_acls(

*self*

,
event
)

Compares leader auth config to incoming relation config, applies necessary add/update/remove actions.

Arguments

event
(optional)

used for checking `RelationBrokenEvent`

ZooKeeperProvider.
apply\_relation\_data(

*self*

,
event
)

Updates relation data with new auth values upon concluded client\_relation events.

Arguments

event
(optional)

used for checking `RelationBrokenEvent`
