Skip to content

Commit 9eb55d1

Browse files
authored
Merge pull request #2 from guidograzioli/infinispan_cache
infinispan_cache role for runtime cache config
2 parents f428c9b + 47119d1 commit 9eb55d1

File tree

22 files changed

+548
-17
lines changed

22 files changed

+548
-17
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ jobs:
2828
python -m pip install --upgrade pip
2929
pip install yamllint 'molecule[docker]~=3.5.2' ansible-core flake8 ansible-lint voluptuous
3030
31-
- name: Create default collection path symlink
31+
- name: Install controller node dependencies
32+
run: pip install -r requirements.txt
33+
working-directory: ./ansible_collections/middleware_automation/infinispan
34+
35+
- name: Create default collection path
3236
run: |
33-
mkdir -p /home/runner/.ansible
34-
ln -s /home/runner/work/middleware_automation/infinispan /home/runner/.ansible/collections
37+
mkdir -p /home/runner/.ansible/collections/ansible_collections
3538
3639
- name: Run sanity tests
3740
run: ansible-test sanity --docker -v --color --python ${{ matrix.python_version }}

.github/workflows/release.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ jobs:
99
release:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
12+
- name: Checkout code
13+
uses: actions/checkout@v2
1314
- name: Set up Python
1415
uses: actions/setup-python@v1
1516
with:
@@ -35,4 +36,18 @@ jobs:
3536
env:
3637
ANSIBLE_GALAXY_API_KEY: ${{ secrets.ANSIBLE_GALAXY_API_KEY }}
3738
run: |
38-
ansible-galaxy collection publish *.tar.gz --api-key $ANSIBLE_GALAXY_API_KEY
39+
ansible-galaxy collection publish *.tar.gz --api-key $ANSIBLE_GALAXY_API_KEY
40+
dispatch:
41+
needs: release
42+
strategy:
43+
matrix:
44+
repo: ['ansible-middleware/cross-dc-rhsso-demo', 'ansible-middleware/flange-demo']
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Repository Dispatch
48+
uses: peter-evans/repository-dispatch@v1
49+
with:
50+
token: ${{ secrets.TRIGGERING_USER }}
51+
repository: ${{ matrix.repo }}
52+
event-type: "Dependency released - Infinispan"
53+
client-payload: "{ 'repository': '$GITHUB_REPOSITORY', 'version': '${GITHUB_REF#refs/tags/}' }"

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ collections:
2929
- name: middleware_automation.infinispan
3030
```
3131
32+
The infinispan collection also depends on the following python packages to be present on the controller host:
33+
34+
* lxml
35+
* jmespath
36+
37+
A requirement file is provided to install:
38+
39+
pip install -r requirements.txt
40+
41+
42+
### Included roles
43+
44+
* `infinispan`: performs an installation of Infinispan or DataGrid nodes or cluster, with configuration of static caches.
45+
* `infinispan_cache`: creates Infinispan or DataGrid caches at runtime.
46+
47+
3248
### Choosing between Red Hat products and upstream project
3349

3450
The roles supports installing Red Hat Datagrid from the Customer Portal, when the following variables are defined:
@@ -41,6 +57,7 @@ jdg_rhn_id: '<datagrid_product_id>'
4157

4258
where `datagrid_product_id` is the ID for the specific Data Grid version, ie. _98151_ will install version _8.2.0_)
4359

60+
4461
## License
4562

4663
Apache License v2.0 or later

molecule/default/converge.yml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,55 @@
1919
jdg_username: "supervisor"
2020
jdg_password: "itsme"
2121
cache:
22-
name: test_cache
22+
name: test_cache
23+
- name: "infinispan cache role (xml)"
24+
include_role:
25+
name: ../../roles/infinispan_cache
26+
vars:
27+
deployer_user: "supervisor"
28+
deployer_password: "itsme"
29+
cache_xml: >
30+
<local-cache name="testcachexml" statistics="true">
31+
<encoding media-type="application/x-protostream"/>
32+
</local-cache>
33+
- name: "infinispan cache role (yml)"
34+
include_role:
35+
name: ../../roles/infinispan_cache
36+
vars:
37+
deployer_user: "supervisor"
38+
deployer_password: "itsme"
39+
cache_config:
40+
name: configuredcache
41+
template: replicated
42+
mode: ASYNC
43+
unreliable_return_values: true
44+
transaction_mode: NONE
45+
transaction_locking: PESSIMISTIC
46+
memory_max_size: '100MB'
47+
memory_when_full: 'REMOVE'
48+
expiration_lifespan: 60000
49+
expiration_max_idle: 10000
50+
persistence: false
51+
indexing: false
52+
- name: "infinispan cache role (yml trasanctional)"
53+
include_role:
54+
name: ../../roles/infinispan_cache
55+
vars:
56+
deployer_user: "supervisor"
57+
deployer_password: "itsme"
58+
cache_config:
59+
name: configuredcachexa
60+
template: distributed
61+
mode: SYNC
62+
unreliable_return_values: true
63+
transaction_mode: FULL_XA
64+
transaction_locking: PESSIMISTIC
65+
memory_max_count: '1000'
66+
memory_when_full: 'REMOVE'
67+
expiration_lifespan: 600000
68+
expiration_max_idle: 30000
69+
persistence: false
70+
indexing: true
71+
indexing_entities:
72+
- org.infinispan.sample.Car
73+
- book_sample.Book

molecule/default/molecule.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
dependency:
3-
name: galaxy
3+
name: shell
4+
command: ansible-galaxy collection install -r molecule/default/requirements.yml -p $HOME/.ansible/collections --force-with-deps
45
driver:
56
name: docker
67
platforms:

molecule/default/prepare.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
name:
88
- sudo
99
- iproute
10+
- python3-lxml
1011
state: present

molecule/default/requirements.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
collections:
3+
- name: middleware_automation.redhat_csp_download
4+
version: ">=1.2.1"
5+
- name: community.general
6+
- name: community.docker
7+
version: ">=1.9.1"
8+

molecule/default/verify.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,36 @@
2626
that:
2727
- test_cache_status.json.size == 1
2828
fail_msg: "Test cache error"
29+
- name: "Check test cache (xml) status"
30+
ansible.builtin.uri:
31+
url: http://localhost:11222/rest/v2/caches/testcachexml
32+
url_username: "supervisor"
33+
url_password: "itsme"
34+
register: test_cache_status
35+
- assert:
36+
that:
37+
- test_cache_status.status == 200
38+
- test_cache_status.json.size == 0
39+
fail_msg: "Test cache via XML error"
40+
- name: "Check test cache (yml) status"
41+
ansible.builtin.uri:
42+
url: http://localhost:11222/rest/v2/caches/configuredcache
43+
url_username: "supervisor"
44+
url_password: "itsme"
45+
register: test_cache_status
46+
- assert:
47+
that:
48+
- test_cache_status.status == 200
49+
- test_cache_status.json.size == 0
50+
fail_msg: "Test cache via YML error"
51+
- name: "Check test cache (yml) status"
52+
ansible.builtin.uri:
53+
url: http://localhost:11222/rest/v2/caches/configuredcachexa
54+
url_username: "supervisor"
55+
url_password: "itsme"
56+
register: test_cache_status
57+
- assert:
58+
that:
59+
- test_cache_status.status == 200
60+
- test_cache_status.json.size == 0
61+
fail_msg: "Test cache via YML error"

playbooks/infinispan.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,13 @@
1616
vars:
1717
supervisor_password: "itsme"
1818
infinispan_users: []
19+
- name: "infinispan cache"
20+
include_role:
21+
name: infinispan_cache
22+
vars:
23+
deployer_user: "supervisor"
24+
deployer_password: "itsme"
25+
cache_xml: >
26+
<local-cache name="testcache" statistics="true">
27+
<encoding media-type="application/x-protostream"/>
28+
</local-cache>"

requirements.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#################################################
2+
# python dependencies required to be installed
3+
# on the controller host with:
4+
# pip install -r requirements.txt
5+
#
6+
lxml
7+
jmespath

roles/infinispan/README.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Role Defaults
99

1010
| Variable | Description | Default |
1111
|:---------|:------------|:--------|
12-
|`infinispan_keycloak_caches`| Creates remote caches for keycloak | `False` |
1312
|`jdg_port`| Alternate port for the service | `11222` |
1413
|`jdg_jgroups_port`| Alternate port for the jgroups cluster | `7800` |
1514
|`jdg_jgroups_relay_port`| Alternate port for the jgroups relaying cluster | `7801` |
@@ -32,6 +31,7 @@ Role Defaults
3231
|`jdg_keystore_password`| Keystore password | `changeit` |
3332
|`jdg_keystore_alias`| Alias for the certificate to load from keystore | `{{ inventory_hostname }}` |
3433
|`jdg_keystore_key_password` | Key passphrase for TLS server identity | `''`|
34+
|`infinispan_keycloak_caches`| Creates remote caches for keycloak | `False` |
3535
|`jvm_package`| RHEL java package runtime | `java-1.8.0-openjdk-devel` |
3636

3737

@@ -69,7 +69,13 @@ When setting up cross-DC relaying, also setup mariadb in active-active mode (ie.
6969
Dependencies
7070
------------
7171

72-
The roles depends on the redhat_csp_download roles of [middleware_automation.redhat_csp_download](https://github.com/ansible-middleware/redhat-csp-download) collection.
72+
The roles depends on the `redhat_csp_download` role of [middleware_automation.redhat_csp_download](https://github.com/ansible-middleware/redhat-csp-download) collection. To install, from the collection root directory, run:
73+
74+
ansible-galaxy collections install -r requirements.yml
75+
76+
Python _lxml_ and _jmespath_ libraries are needed on the host that executes this module. To install, from the collection root directory, run:
77+
78+
pip install -r requirements.txt
7379

7480

7581
Example Playbook
@@ -91,6 +97,7 @@ The following is an example playbook that makes use of the role to install Infin
9197
infinispan_users: []
9298
```
9399

100+
94101
Choosing what to install
95102
------------------------
96103

@@ -102,6 +109,7 @@ rhn_username: '<customer portal account username>'
102109
rhn_password: '<customer portal account password>'
103110
```
104111

112+
105113
Keycloak integration
106114
--------------------
107115

@@ -117,11 +125,59 @@ Enabling `infinispan_keycloak_caches` will prepare the following caches in a ded
117125

118126
for more details, refer to the: [INSTALLATION AND CONFIGURATION GUIDE - 3.4.6. Infinispan caches](https://access.redhat.com/documentation/en-us/red_hat_single_sign-on/7.5/html-single/server_installation_and_configuration_guide/index#cache)
119127

128+
129+
Deploying custom cache configurations
130+
-------------------------------------
131+
132+
It is possible to deploy caches statically in the infinispan.xml server configuration, by populating the `jdg_caches` list of dicts.
133+
In case of clustered deployments, this configuration must be executed against all nodes in the cluster, as they are not propagated by the service.
134+
To deploy cache configurations at runtime, refer to the `infinispan_cache` role instead.
135+
136+
For more details, refer to:
137+
* [Configuring Infinispan Caches - 3.1 Declarative cache configuration](https://infinispan.org/docs/stable/titles/configuring/configuring.html#declarative-cache-configuration_cache-configuration)
138+
* [Configuring Infinispan Caches - 3.3 Creating remote caches](https://infinispan.org/docs/stable/titles/configuring/configuring.html#creating-remote-caches)
139+
140+
141+
How to configure caches
142+
-----------------------
143+
144+
A cache configuration can be passed-in as an XML file or string, as it is generated by the infinispan server console; otherwise,
145+
it is possible to define configuration dicts, used to populate the available templates.
146+
147+
148+
To pass XML directly, as string or with a file:
149+
150+
```
151+
jdg_caches:
152+
- cache_xml: >
153+
<local-cache name="testcachexml" statistics="true">
154+
<encoding media-type="application/x-protostream"/>
155+
</local-cache>
156+
- cache_xml: "{{ lookup('file', user_data_file) }}"
157+
158+
```
159+
160+
To configure caches:
161+
162+
```
163+
jdg_caches:
164+
- cache_config:
165+
name: 'my-distributed-cache'
166+
template: 'distribute-cache'
167+
encoding: 'application/x-jboss-marshalling'
168+
persistence: False
169+
170+
```
171+
172+
It is possible to mix and match the two configurations in the `jdg_caches` list.
173+
174+
120175
License
121176
-------
122177

123178
Apache License 2.0
124179

180+
125181
Author Information
126182
------------------
127183

roles/infinispan/defaults/main.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,7 @@ jdg_logfile_enable_hotrod_accesslog: False
6464
# enable additional rest-access.log
6565
jdg_logfile_enable_rest_accesslog: False
6666
# max file size, triggers rotation
67-
jdg_logfile_maxsize: '100 MB'
67+
jdg_logfile_maxsize: '100 MB'
68+
69+
# declarative cache configuration
70+
jdg_caches: []

roles/infinispan/tasks/keycloak.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
---
2-
- name: "Create keycloak remote caches"
3-
include_tasks: cache.yml
2+
- name: "Verify keycloak remote caches"
3+
include_tasks: query_cache.yml
44
vars:
5+
method: GET
56
jdg_url: "{{ 'https' if jdg_default_realm_tls else 'http' }}://{{ jdg.bind_addr }}:{{ jdg.port }}"
67
jdg_username: "{{ jdg_supervisor.name }}"
78
jdg_password: "{{ jdg_supervisor.password }}"

roles/infinispan/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
- jdg_healthcheck
106106
- jdg.port is defined
107107

108-
- name: Create keycloak remote caches
108+
- name: Include tasks for keycloak remote caches
109109
include_tasks: keycloak.yml
110110
when:
111111
- jdg_keycloak_cache.enabled

roles/infinispan/tasks/query_cache.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
- method is defined
99
quiet: true
1010

11-
- name: Set query facts
12-
set_fact:
13-
rest_cache_api_path: /rest/v2/caches/
14-
1511
- name: "Ensures cache {{ cache.name }} exists."
1612
uri:
1713
url: "{{ jdg_url }}{{ rest_cache_api_path }}{{ cache.name }}"

roles/infinispan/vars/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ supervisor_password:
44
infinispan_users: []
55

66
# internal variables
7+
rest_cache_api_path: /rest/v2/caches/
8+
79
jdg_supervisor:
810
name: 'supervisor'
911
password: "{{ supervisor_password }}"

0 commit comments

Comments
 (0)