Skip to content

Commit fbaa165

Browse files
committed
Add jdbc persistence for keycloak remote caches
The new flag jdg_keycloak_persistence (default: false) allows to setup the keycloak datasource for persistence of keycloak caches. Also, switch from replicated-cache to distributed-cache for keycloak when crossDC replication (RELAY2 protocol) is enabled.
1 parent 1943840 commit fbaa165

File tree

5 files changed

+58
-11
lines changed

5 files changed

+58
-11
lines changed

roles/infinispan/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ Role Defaults
1818
|`jdg_jgroups_relay_sites`| List of site names for cross-DC relaying | `[]` |
1919
|`jdg_jgroups_relay_site`| Site the inventory host is in when cross-DC is enabled | `''` |
2020
|`jdg_jgroups_jdbcping`| Enable clustering using JDBC PING discovery | `False` |
21-
21+
|`jdg_keycloak_persistence`| Enable persitence datasource for keycloak caches | `False` |
22+
|`jdg_service_user`| posix account for the service installation | `jdg` |
23+
|`jdg_service_group`| posix group for the service installation | `jdg` |
2224

2325

2426
Role Variables

roles/infinispan/defaults/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jdg_bind_address: localhost
1919
jdg_port: 11222
2020
jdg_jgroups_port: 7800
2121
jdg_jgroups_relay_port: 7801
22+
jdg_service_user: jdg
23+
jdg_service_group: jdg
2224

2325
# flag to enable protocol encryption
2426
jdg_default_realm_tls: False
@@ -34,3 +36,6 @@ jdg_jgroups_relay_site: ''
3436

3537
# flag to enable keycloak integration
3638
infinispan_keycloak_caches: False
39+
40+
# flag to enable datasource for keycloak integration
41+
jdg_keycloak_persistence: False

roles/infinispan/handlers/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
- name: restart infinispan
3+
throttle: 1
34
systemd:
45
name: "{{ jdg.service.name }}"
56
state: restarted

roles/infinispan/templates/infinispan.xml.j2

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,53 @@
8383
<cache-container name="keycloak" statistics="true">
8484
{% if jdg_jgroups_relay %}
8585
<transport cluster="{{ jdg_jgroups_relay_site }}" stack="xsite" node-name="{{ inventory_hostname }}" machine="{{ inventory_hostname }}" site="{{ jdg_jgroups_relay_site }}"/>
86-
{% else %}
87-
<transport cluster="datagrid" stack="datagrid" node-name="{{ inventory_hostname }}" machine="{{ inventory_hostname }}"/>
88-
{% endif %}
86+
<replicated-cache name="work"/>
8987
{% for keycloak_cache in jdg_keycloak_cache.caches %}
90-
<replicated-cache name="{{ keycloak_cache }}" mode="SYNC">
88+
<distributed-cache name="{{ keycloak_cache }}" mode="SYNC" owners="2" xmlns:jdbc="urn:infinispan:config:store:jdbc:12.0">
89+
{% if jdg_keycloak_persistence %}
90+
<persistence passivation="false">
91+
<jdbc:string-keyed-jdbc-store fetch-state="false" shared="true" preload="false">
92+
<jdbc:data-source jndi-url="jdbc/datasource"/>
93+
<jdbc:string-keyed-table drop-on-exit="false" create-on-start="true" prefix="DATAGRID">
94+
<jdbc:id-column name="id" type="VARCHAR(255)"/>
95+
<jdbc:data-column name="datum" type="VARBINARY(4000)"/>
96+
<jdbc:timestamp-column name="version" type="BIGINT"/>
97+
<jdbc:segment-column name="S" type="INT"/>
98+
</jdbc:string-keyed-table>
99+
</jdbc:string-keyed-jdbc-store>
100+
</persistence>
101+
{% else %}
91102
<transaction mode="NONE" locking="PESSIMISTIC"/>
92103
<locking acquire-timeout="0" />
104+
{% endif %}
93105
<backups>
94106
{% for site in jdg_jgroups_relay_sites %}
95-
{% if site != jdg_jgroups_relay_site %}<backup site="{{ site }}" strategy="ASYNC"/>{% endif %}
107+
{% if site != jdg_jgroups_relay_site %} <backup site="{{ site }}" strategy="ASYNC"/>
108+
{% endif %}
96109
{% endfor %}
97110
</backups>
98-
</replicated-cache>
111+
</distributed-cache>
112+
{% endfor %}
99113
<security>
100114
<authorization>
101115
<role name="{{ jdg_supervisor.name }}" permissions="READ WRITE EXEC CREATE"/>
102116
</authorization>
103117
</security>
118+
{% else %}
119+
<transport cluster="datagrid" stack="datagrid" node-name="{{ inventory_hostname }}" machine="{{ inventory_hostname }}"/>
120+
<replicated-cache name="work"/>
121+
{% for keycloak_cache in jdg_keycloak_cache.caches %}
122+
<replicated-cache name="{{ keycloak_cache }}" mode="SYNC">
123+
<transaction mode="NONE" locking="PESSIMISTIC"/>
124+
<locking acquire-timeout="0" />
125+
</replicated-cache>
104126
{% endfor %}
127+
<security>
128+
<authorization>
129+
<role name="{{ jdg_supervisor.name }}" permissions="READ WRITE EXEC CREATE"/>
130+
</authorization>
131+
</security>
132+
{% endif %}
105133
</cache-container>
106134
{% endif %}
107135
<server xmlns="urn:infinispan:server:12.1">
@@ -140,7 +168,19 @@
140168
</security-realm>
141169
</security-realms>
142170
</security>
143-
171+
{% if jdg_keycloak_persistence %}
172+
<data-sources>
173+
<data-source name="KeycloakDS" jndi-name="jdbc/datasource" statistics="true">
174+
<connection-factory driver="{{ jdg_jgroups_jdbc.mariadb.driver_class }}"
175+
username="{{ jdg_jgroups_jdbc.mariadb.db_user }}"
176+
password="{{ jdg_jgroups_jdbc.mariadb.db_password }}"
177+
url="{{ jdg_jgroups_jdbc.mariadb.connection_url }}?useUnicode=true&amp;characterEncoding=UTF-8"
178+
new-connection-sql="SELECT 1" transaction-isolation="READ_COMMITTED">
179+
</connection-factory>
180+
<connection-pool initial-size="1" max-size="10" min-size="3" background-validation="1000" idle-removal="1" blocking-timeout="1000" leak-detection="10000"/>
181+
</data-source>
182+
</data-sources>
183+
{% endif %}
144184
<endpoints socket-binding="default" security-realm="default">
145185
<hotrod-connector name="hotrod"/>
146186
<rest-connector name="rest">

roles/infinispan/vars/main.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jdg:
2222
users: "{{ override_jdg_config_users_properties | default('users.properties') }}"
2323
groups: "{{ override_jdg_config_group_properties | default('groups.properties') }}"
2424
user:
25-
name: "{{ override_jdg_user | default('jdg') }}"
25+
name: "{{ jdg_service_user }}"
2626
group:
27-
name: "{{ override_jdg_group | default('jdg') }}"
27+
name: "{{ jdg_service_group }}"
2828
service:
2929
name: "{{ override_jdg_service_name | default('jdg' if jdg_rhn_id is defined else 'infinispan') }}"
3030
users: "{{ [ jdg_supervisor ] + infinispan_users }}"
@@ -48,4 +48,3 @@ jdg_keycloak_cache:
4848
- offlineClientSessions
4949
- loginFailures
5050
- actionTokens
51-
- work

0 commit comments

Comments
 (0)