Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KNOX-2835 SQL DB based topology monitor #670

Merged
merged 7 commits into from
Nov 15, 2022

Conversation

zeroflag
Copy link
Contributor

@zeroflag zeroflag commented Nov 9, 2022

What changes were proposed in this pull request?

This is a similar implementation as the existing zookeeper based monitor, but it uses the SQL DB. Zookeeper is not always available and the DB is already used by the token state service.

The purpose of this monitor is to periodically check the DB for shared-providers and descriptors and update the local file system with the changes from the DB.

  1. If a provider/descriptor is deleted from the db but exists on the file system the monitor is going to delete it from the file system
  2. If a provider/descriptor exists in the DB but missing from the file system the monitor is going to download it from the DB to the FS.
  3. If a provider/descriptor in the DB has a different content than the corresponding local file, then the monitor is going to update the local file with the content from he DB. However to avoid too frequent and unnecessary IO operations we only change the local files if the remote change happened after the last synchronization time (if it happened in the past, we assume the changes were already synced to the disk). So One can change the local files on the disk without worrying about losing their local changes (until someone updates the DB).

The provider logic is implementeed in DbRemoteConfigurationMonitor.

The original DefaultRemoteConfigurationMonitor was renamed to ZkRemoteConfigurationMonitor.

Since the original zookeeper based monitor was already hooked in the Admin UI and Admin API, the new implementation also supports both the UI + API.

How was this patch tested?

gateway-site.xml

<property>
    <name>gateway.service.remoteconfigurationmonitor.impl</name>
    <value>org.apache.knox.gateway.topology.monitor.db.DbRemoteConfigurationMonitorService</value>
</property>
<property>
    <name>gateway.database.type</name>
    <value>mysql</value>
</property>
<property>
    <name>gateway.database.connection.url</name>
    <value>jdbc:mysql://root:root@localhost:3306/knox</value>
</property>

Creating provider with curl:

$    curl -X PUT -H "Content-Type: application/json" -v -k -u admin:admin-password -d "{'x':'y'}" https://localhost:8443/gateway/admin/api/v1/providerconfig/newprov

Checking the DB:

mysql> select * from knox_providers;
+--------------+-----------+---------------------+
| name         | content   | last_modified_time  |
+--------------+-----------+---------------------+
| newprov.json | {'x':'y'} | 2022-11-09 09:45:28 |
+--------------+-----------+---------------------+
1 row in set (0.00 sec)

Checking the local FS:

$ cat conf/shared-providers/newprov.json 
{'x':'y'} 

Creating descriptor with curl:

$ curl -X PUT -H "Content-Type: application/json" -v -k -u admin:admin-password -d "{'x':'y'}" https://localhost:8443/gateway/admin/api/v1/descriptors/newdesc

Checking the DB:

mysql> select * from knox_descriptors;
+--------------+---------------+---------------------+
| name         | content       | last_modified_time  |
+--------------+---------------+---------------------+
| newdesc.json | {'abc':'def'} | 2022-11-09 09:47:06 |
+--------------+---------------+---------------------+

Checking the local FS:

$ cat conf/descriptors/newdesc.json 
{'abc':'def'}

Deleting provider with curl:

$ curl -X DELETE -H "Content-Type: application/json" -v -k -u admin:admin-password  https://localhost:8443/gateway/admin/api/v1/providerconfig/newprov.json

Checking the DB and FS:

$ ls conf/shared-providers/

mysql> select * from knox_providers;
Empty set (0.00 sec)

Deleting descriptor with curl:

$ curl -X DELETE -H "Content-Type: application/json" -v -k -u admin:admin-password  https://localhost:8443/gateway/admin/api/v1/descriptors/newdesc.json

Checking the DB and FS:

$ cat conf/descriptors/newdesc.json 

mysql> select * from knox_descriptors;
Empty set (0.00 sec)

Repeated the same tests using the Admin UI.

@zeroflag zeroflag self-assigned this Nov 9, 2022
@zeroflag zeroflag requested review from moresandeep, smolnar82 and pzampino and removed request for moresandeep November 9, 2022 09:29
Copy link
Contributor

@smolnar82 smolnar82 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zeroflag zeroflag merged commit 6d3f960 into apache:master Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants