Skip to content

Commit

Permalink
Merge pull request #178 from guidograzioli/177_federation_no_connectors
Browse files Browse the repository at this point in the history
Fix broker.xml connector and connector-ref when using federation
  • Loading branch information
guidograzioli authored Sep 24, 2024
2 parents 7a2d7db + e49129a commit 70a20d6
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
with:
fqcn: 'middleware_automation/amq'
molecule_tests: >-
[ "default", "static_cluster", "replication", "live_only", "amq_upgrade", "mask_passwords", "custom_xml", "uninstall" ]
[ "default", "static_cluster", "replication", "live_only", "federation", "amq_upgrade", "mask_passwords", "custom_xml", "uninstall" ]
58 changes: 58 additions & 0 deletions molecule/federation/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
- name: Converge
hosts: all
gather_facts: yes
vars:
activemq_cluster_enabled: false
activemq_ha_enabled: false
activemq_shared_storage: false
activemq_replication: false
activemq_scale_down_enabled: false
activemq_configure_firewalld: false
activemq_systemd_wait_for_log: false
activemq_systemd_wait_for_port: true
activemq_cluster_discovery: "provided"
activemq_nio_enabled: true
activemq_cors_strict_checking: false
activemq_prometheus_enabled: false
activemq_acceptors:
- name: "{{ inventory_hostname }}"
bind_address: 0.0.0.0
bind_port: "{{ activemq_port }}"
parameters:
tcpSendBufferSize: 1048576
tcpReceiveBufferSize: 1048576
protocols: CORE,AMQP
useEpoll: true
sslEnabled: false
activemq_connectors:
- name: instance1
address: instance1
- name: instance2
address: instance2
activemq_addresses:
- name: queue.in
anycast:
- name: queue.in
- name: queue.out
anycast:
- name: queue.out
- name: DLQ
anycast:
- name: DLQ
parameters:
durable: True
- name: ExpiryQueue
anycast:
- name: ExpiryQueue
- name: a.test
anycast:
- name: a.test
- name: b.test
anycast:
- name: b.test
parameters:
max_consumers: 1
delay_before_dispatch: 3
roles:
- middleware_automation.amq.activemq
83 changes: 83 additions & 0 deletions molecule/federation/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
driver:
name: docker
platforms:
- name: instance1
image: registry.access.redhat.com/ubi9/ubi-init:latest
pre_build_image: true
privileged: true
command: "/usr/sbin/init"
networks:
- name: amq
tmpfs:
- /run
- /tmp
- name: instance2
image: registry.access.redhat.com/ubi9/ubi-init:latest
pre_build_image: true
privileged: true
command: "/usr/sbin/init"
networks:
- name: amq
tmpfs:
- /run
- /tmp
provisioner:
name: ansible
config_options:
defaults:
interpreter_python: auto_silent
ssh_connection:
pipelining: false
playbooks:
prepare: prepare.yml
converge: converge.yml
verify: verify.yml
inventory:
host_vars:
localhost:
ansible_python_interpreter: "{{ ansible_playbook_python }}"
instance1:
activemq_federations:
- name: amq-federation
upstreams:
- name: instance2
user: amq-broker
password: amq-broker
static_connectors:
- instance2
queue_policies:
- name: TEST
includes:
- queue_match: TEST
address_match: TEST
instance2:
activemq_federations:
- name: amq-federation
upstreams:
- name: instance1
user: amq-broker
password: amq-broker
static_connectors:
- instance1
queue_policies:
- name: TEST
includes:
- queue_match: TEST
address_match: TEST
env:
ANSIBLE_FORCE_COLOR: "true"
verifier:
name: ansible
scenario:
test_sequence:
- cleanup
- destroy
- create
- prepare
- converge
- idempotence
- side_effect
- verify
- cleanup
- destroy
6 changes: 6 additions & 0 deletions molecule/federation/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Prepare
hosts: all
tasks:
- name: "Run preparation common to all scenario"
ansible.builtin.include_tasks: ../prepare.yml
1 change: 1 addition & 0 deletions molecule/federation/roles
69 changes: 69 additions & 0 deletions molecule/federation/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
- name: Verify
hosts: all
tasks:
- name: Populate service facts
ansible.builtin.service_facts:

- name: Populate activemq facts
middleware_automation.amq.activemq_facts:
base_url: http://localhost:8161
auth_username: amq-broker
auth_password: amq-broker
validate_certs: false

- name: Check if amq-broker service is started
ansible.builtin.assert:
that:
- ansible_facts.services["amq-broker.service"]["state"] == "running"
- ansible_facts.services["amq-broker.service"]["status"] == "enabled"

- name: Read content of instance1 logs
ansible.builtin.slurp:
src: /var/log/activemq/amq-broker/artemis.log
register: slurped_log_instance1
delegate_to: instance1
run_once: true
no_log: true

- name: Read content of instance2 logs
ansible.builtin.slurp:
src: /var/log/activemq/amq-broker/artemis.log
register: slurped_log_instance2
delegate_to: instance2
run_once: true
no_log: true

- name: Check cluster status
run_once: true
block:
- name: Check live-only on instance1
ansible.builtin.assert:
that:
- "'live Message Broker is starting' in slurped_log_instance1.content|b64decode or 'Primary message broker is starting' in slurped_log_instance1.content|b64decode"
quiet: true
- name: Check live-only on instance2
ansible.builtin.assert:
that:
- "'live message broker is starting' in slurped_log_instance2.content|b64decode or 'Primary message broker is starting' in slurped_log_instance2.content|b64decode"
quiet: true

- name: Check cluster status via jolokia facts (master)
ansible.builtin.assert:
that:
- ansible_facts.activemq.Active == true
- ansible_facts.activemq.Backup == false
- ansible_facts.activemq.Clustered == false
- ansible_facts.activemq.SharedStore == false
- ansible_facts.activemq.HAPolicy == "Primary Only"
when: inventory_hostname == 'instance1'

- name: Check cluster status via jolokia facts
ansible.builtin.assert:
that:
- ansible_facts.activemq.Active == true
- ansible_facts.activemq.Backup == false
- ansible_facts.activemq.Clustered == false
- ansible_facts.activemq.SharedStore == false
- ansible_facts.activemq.HAPolicy == "Primary Only"
when: inventory_hostname == 'instance2'
3 changes: 2 additions & 1 deletion roles/activemq/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ activemq_replication: false
activemq_replicated: false
## cluster discovery: >
# 'jgroups' for shared file ping, 'multicast' for UDP multicast
# 'static' for static declaration + ansible_play_hosts, 'provided' for using activemq_cluster_connections only
# 'static' for static declaration + ansible_play_hosts
# 'provided' for using activemq_cluster_connections only (for federation keep the list empty)
activemq_cluster_discovery: static
activemq_cluster_connections: []
activemq_scale_down_enabled: false
Expand Down
25 changes: 21 additions & 4 deletions roles/activemq/tasks/connectors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@
loop_control:
loop_var: connector
label: "{{ connector.name }}"
no_log: true
no_log: false

- name: Ensure connectors element exists in broker.xml
middleware_automation.common.xml:
path: "{{ activemq.instance_home }}/etc/broker.xml"
xpath: /conf:configuration/core:core/core:connectors
input_type: xml
state: present
namespaces:
conf: urn:activemq
core: urn:activemq:core
pretty_print: true
become: true

- name: Create connector configuration in broker.xml
middleware_automation.common.xml:
Expand All @@ -24,15 +36,14 @@
core: urn:activemq:core
pretty_print: true
become: true
no_log: true
no_log: false
notify:
- restart amq_broker

- name: Configure cluster connections
- name: Configure discovery/broadcast groups
become: true
when:
- activemq_cluster_discovery == 'static' or activemq_cluster_discovery == 'provided'
- activemq_ha_enabled or activemq_cluster_enabled
block:
- name: Remove discovery groups
middleware_automation.common.xml:
Expand All @@ -52,6 +63,12 @@
conf: urn:activemq
core: urn:activemq:core

- name: Configure cluster connections
become: true
when:
- activemq_cluster_discovery == 'static' or activemq_cluster_discovery == 'provided'
- activemq_ha_enabled or activemq_cluster_enabled
block:
- name: Create cluster connections configuration string
ansible.builtin.set_fact:
cluster_connections: "{{ lookup('template', 'cluster_connections.broker.xml.j2') }}"
Expand Down
1 change: 0 additions & 1 deletion roles/activemq/tasks/federations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
pretty_print: true
become: true


- name: Create federations configuration in broker.xml
middleware_automation.common.xml:
path: "{{ activemq.instance_home }}/etc/broker.xml"
Expand Down
18 changes: 9 additions & 9 deletions roles/activemq/templates/federations.broker.xml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
{% if upstream.parameters.check_period is defined %}<check-period>{{ upstream.parameters.check_period }}</check-period>{% endif %}
{% if upstream.parameters.call_failover_timeout is defined %}<call-failover-timeout>{{ upstream.parameters.call_failover_timeout }}</call-failover-timeout>{% endif %}
{% endif %}
{% if upstream["static_connectors"] is defined and upstream["static_connectors"] |length > 0 %}
{% if upstream["static_connectors"] is defined and upstream["static_connectors"] | length > 0 %}
<static-connectors>
{% for connector_ref in upstream["static_connectors"] %}
<connector-ref>"{{ connector_ref }}"</connector-ref>
<connector-ref>{{ connector_ref }}</connector-ref>
{% endfor %}
</static-connectors>
{% endif %}
Expand Down Expand Up @@ -52,7 +52,7 @@
{% if downstream["static_connectors"] is defined and downstream["static_connectors"] |length > 0 %}
<static-connectors>
{% for connector_ref in downstream["static_connectors"] %}
<connector-ref>"{{ connector_ref }}"</connector-ref>
<connector-ref>{{ connector_ref }}</connector-ref>
{% endfor %}
</static-connectors>
{% endif %}
Expand All @@ -73,26 +73,26 @@
{% if federation["queue_policies"] is defined and federation["queue_policies"] |length > 0 %}
{% for policy in federation["queue_policies"] %}
<queue-policy name="{{ policy.name }}" {% if policy.parameters is defined %}{% for param in lookup('ansible.builtin.dict', policy.parameters, wantlist=true) %} {{ param.key | replace('_','-') }}="{{ param.value }}"{% endfor %}{% endif %}>
{% if policy.includes is defined and policy.includes |length > 0 %}{% for include in policy.includes %}
{% if policy.includes is defined and policy.includes | length > 0 %}{% for include in policy.includes %}
<include queue-match="{{include.queue_match}}" address-match="{{include.address_match}}"/>
{% endfor %}{% endif %}
{% if policy.excludes is defined and policy.excludes |length > 0 %}{% for exclude in policy.excludes %}
{% if policy.excludes is defined and policy.excludes | length > 0 %}{% for exclude in policy.excludes %}
<exclude queue-match="{{exclude.queue_match}}" address-match="{{exclude.address_match}}"/>
{% endfor %}{% endif %}
</queue-policy>
{% endfor %}{% endif %}
{% if federation["address_policies"] is defined and federation["address_policies"] |length > 0 %}
{% for policy in federation["address_policies"] %}
<address-policy name="{{ policy.name }}" {% if policy.parameters is defined %}{% for param in lookup('ansible.builtin.dict', policy.parameters, wantlist=true) %} {{ param.key | replace('_','-') }}="{{ param.value }}"{% endfor %}{% endif %}>
{% if policy.includes is defined and policy.includes |length > 0 %}{% for include in policy.includes %}
{% if policy.includes is defined and policy.includes | length > 0 %}{% for include in policy.includes %}
<include address-match="{{include}}"/>
{% endfor %}{% endif %}
{% if policy.excludes is defined and policy.excludes |length > 0 %}{% for exclude in policy.excludes %}
{% if policy.excludes is defined and policy.excludes | length > 0 %}{% for exclude in policy.excludes %}
<exclude address-match="{{exclude}}"/>
{% endfor %}{% endif %}
</address-policy>
{% endfor %}{% endif %}
{% if federation["transformers"] is defined and federation["transformers"] |length > 0 %}
{% if federation["transformers"] is defined and federation["transformers"] | length > 0 %}
{% for transformer in federation["transformers"] %}
<transformer name="{{ transformer.name }}">
<class-name>{{transformer.class_name}}</class-name>
Expand All @@ -103,4 +103,4 @@
{% endif %}
</transformer>
{% endfor %}{% endif %}
</federation>
</federation>

0 comments on commit 70a20d6

Please sign in to comment.