Skip to content

Commit 56233d6

Browse files
Christopher Frostnebhale
authored andcommitted
Tomcat Redis Session Replication
When the Tomcat Redis sub-component detects a service with a name, label, or tag that has `session-replication` as a substring but both 'host' and 'hostname' as credentials it will fail to use the service. This commit changes the service detection logic to require at least one credential from a group instead of exactly one credential from a group. It is up to the individual containers to handle the credentials provided. In the case of the Tomcat Redis sub-component 'hostname' will win but this is not documented and users should not rely on that behaviour in the instances where both 'host' and 'hostname' are provided with different values. [#80362118]
1 parent ecfa274 commit 56233d6

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

lib/java_buildpack/component/services.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def initialize(raw)
3333
# +filter+ matches exactly one service, +false+ otherwise.
3434
#
3535
# @param [Regexp, String] filter a +RegExp+ or +String+ to match against the name, label, and tags of the services
36-
# @param [String] required_credentials an optional list of keys or groups of keys, where at one key from the
36+
# @param [String] required_credentials an optional list of keys or groups of keys, where at least one key from the
3737
# group, must exist in the credentials payload of the candidate service
3838
# @return [Boolean] +true+ if the +filter+ matches exactly one service with the required credentials, +false+
3939
# otherwise.
@@ -69,7 +69,7 @@ def find_service(filter)
6969

7070
def credentials?(candidate, required_keys)
7171
required_keys.all? do |k|
72-
k.is_a?(Array) ? k.one? { |g| candidate.key?(g) } : candidate.key?(k)
72+
k.is_a?(Array) ? k.any? { |g| candidate.key?(g) } : candidate.key?(k)
7373
end
7474
end
7575

spec/java_buildpack/component/services_spec.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
let(:service) do
2525
{ 'name' => 'test-name', 'label' => 'test-label', 'tags' => ['test-tag'], 'plan' => 'test-plan',
26-
'credentials' => { 'uri' => 'test-uri' } }
26+
'credentials' => { 'uri' => 'test-uri', 'h1' => 'foo', 'h2' => 'foo' } }
2727
end
2828

2929
let(:services) { described_class.new('test' => [service]) }
@@ -58,11 +58,21 @@
5858
expect(services.one_service?(/test-tag/, 'uri')).to be
5959
end
6060

61-
it 'should return true from one_service? if there is a matching service with required group credentials' do
61+
it 'should return true from one_service? if there is a matching service with one required group credentials' do
6262
expect(services.one_service? 'test-tag', %w(uri other)).to be
6363
expect(services.one_service?(/test-tag/, %w(uri other))).to be
6464
end
6565

66+
it 'should return true from one_service? if there is a matching service with two required group credentials' do
67+
expect(services.one_service? 'test-tag', %w(h1 h2)).to be
68+
expect(services.one_service?(/test-tag/, %w(h1 h2))).to be
69+
end
70+
71+
it 'should return false from one_service? if there is a matching service with no required group credentials' do
72+
expect(services.one_service? 'test-tag', %w(foo bar)).not_to be
73+
expect(services.one_service?(/test-tag/, %w(foo bar))).not_to be
74+
end
75+
6676
it 'should return nil from find_service? if there is no service that matches' do
6777
expect(services.find_service 'bad-test').to be_nil
6878
expect(services.find_service(/bad-test/)).to be_nil

0 commit comments

Comments
 (0)