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

Exclude self from static cluster connectors #7

Merged
merged 2 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ The following parameters are available in the `activemq::instance` defined type:
* [`address_settings`](#-activemq--instance--address_settings)
* [`addresses`](#-activemq--instance--addresses)
* [`allow_failback`](#-activemq--instance--allow_failback)
* [`allow_direct_connections_only`](#-activemq--instance--allow_direct_connections_only)
* [`bind`](#-activemq--instance--bind)
* [`broadcast_groups`](#-activemq--instance--broadcast_groups)
* [`broker_plugins`](#-activemq--instance--broker_plugins)
Expand Down Expand Up @@ -478,6 +479,16 @@ Data type: `Boolean`

Should stop backup on live restart.

##### <a name="-activemq--instance--allow_direct_connections_only"></a>`allow_direct_connections_only`

Data type: `Optional[Boolean]`

When using `static` for [`server_discovery`](#-activemq--server_discovery)
only make connections to the defined connectors and not any other
broker in the cluser.

Default value: `true`

##### <a name="-activemq--instance--bind"></a>`bind`

Data type: `String`
Expand Down
6 changes: 6 additions & 0 deletions manifests/instance.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
# @param allow_failback
# Should stop backup on live restart.
#
# @param allow_direct_connections_only
# When using static server discovery only make connections to the
# defined connectors and not any other broker in the cluser.
#
# @param bind
# Configure which IP address to listen on. Should be either a FQDN
# or an IP address.
Expand Down Expand Up @@ -167,6 +171,7 @@
String $java_xms = $activemq::java_xms,
String $java_xmx = $activemq::java_xmx,
# Optional parameters
Optional[Boolean] $allow_direct_connections_only = true,
Optional[Integer] $global_max_size_mb = undef,
Optional[String] $group = undef,
Optional[Boolean] $service_enable = undef,
Expand Down Expand Up @@ -379,6 +384,7 @@
'address_settings' => $address_settings,
'addresses' => $addresses,
'allow_failback' => $allow_failback,
'allow_direct_connections_only' => $allow_direct_connections_only,
'bind' => $bind,
'broadcast_groups' => $broadcast_groups,
'broker_plugins' => $_broker_plugins,
Expand Down
27 changes: 26 additions & 1 deletion spec/acceptance/activemq_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require 'spec_helper_acceptance'

RSpec::Matchers.define_negated_matcher :not_match, :match

describe 'activemq' do
let(:activemq_checksum) { 'a73331cb959bb0ba9667414682c279bc9ce2aec4c8fecbcdee4670bf9d63bf66010c8c55a6b727b1ad6d51bbccadd663b96a70b867721d9388d54a9391c6af85' }
let(:activemq_group) { 'activemq' }
Expand Down Expand Up @@ -41,13 +43,28 @@
admin_password => '#{activemq_instance_password}',
admin_user => '#{activemq_instance_user}',
checksum => '#{activemq_checksum}',
cluster => false,
cluster => true,
cluster_password => '#{activemq_instance_password}',
cluster_user => '#{activemq_instance_user}',
cluster_name => 'activemq-cluster',
cluster_topology => {
'#{activemq_instance_name}' => {
target_host => 'localhost',
bind => '127.0.0.1',
},
'instance2' => {
target_host => 'localhost',
bind => '127.0.0.2',
}
},
server_discovery => 'static',
download_url => 'http://archive.apache.org/dist/activemq/activemq-artemis/#{activemq_version}/%s',
instances => {
'#{activemq_instance_name}' => {
bind => '127.0.0.1',
port => 61616,
web_port => 8161,
ha_policy => 'live-only',
acceptors => {
artemis => { port => 61616 },
amqp => { port => 5672 },
Expand All @@ -72,6 +89,14 @@
it { expect(file("#{activemq_instance_base}/#{activemq_instance_name}/etc/artemis.profile").content).to match(%r{^ARTEMIS_HOME}) }
it { expect(file("#{activemq_instance_base}/#{activemq_instance_name}/etc/artemis.profile").content).to match(%r{^JAVA_ARGS}) }

# Test that 'artemis-instance1' is not in the static-connectors list
it {
expect(file("#{activemq_instance_base}/#{activemq_instance_name}/etc/broker.xml").content.gsub(%r{.*<static-connectors[^>]*>(.*)</static-connectors>.*}ms, '\1'))
.to match(%r{instance2})
.and not_match(%r{:activemq_instance_name})
}
it { expect(file("#{activemq_instance_base}/#{activemq_instance_name}/etc/broker.xml").content).to match(%r{allow-direct-connections-only="true"}) }

it 'sets up the service' do
expect(service("activemq@#{activemq_instance_name}")).to be_running
expect(service("activemq@#{activemq_instance_name}")).to be_enabled
Expand Down
5 changes: 4 additions & 1 deletion templates/broker.xml.epp
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ under the License.
<message-load-balancing><%= $message_load_balancing %></message-load-balancing>
<max-hops><%= $max_hops %></max-hops>
<% if $activemq::server_discovery == 'static' { -%>
<static-connectors allow-direct-connections-only="true">
<static-connectors allow-direct-connections-only="<%= $allow_direct_connections_only %>">
<% $connectors.each |$key, $value| { -%>
<%# # Do not add the connector that matches the name of this instance. -%>
<% if ($key != "artemis-${name}") { -%>
<connector-ref><%= $key %></connector-ref>
<% } -%>
<% } -%>
</static-connectors>
<% } -%>
Expand Down