Skip to content

Commit 142de18

Browse files
authored
Merge pull request #853 from BenjaminPerryRoss/ben/detect-geode-tomcat-version
Detect Geode Tomcat module version
2 parents e4c222d + 7afc30b commit 142de18

File tree

11 files changed

+131
-19
lines changed

11 files changed

+131
-19
lines changed

config/open_jdk_jre.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ jvmkill_agent:
2525
memory_calculator:
2626
version: 3.+
2727
repository_root: "{default.repository.root}/memory-calculator/{platform}/{architecture}"
28-
class_count:
29-
headroom:
28+
class_count:
29+
headroom:
3030
stack_threads: 250

config/tomcat.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Cloud Foundry Java Buildpack
2-
# Copyright 2013-2020 the original author or authors.
2+
# Copyright 2013-2021 the original author or authors.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.

lib/java_buildpack/container/tomcat.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
# Cloud Foundry Java Buildpack
4-
# Copyright 2013-2020 the original author or authors.
4+
# Copyright 2013-2021 the original author or authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -52,10 +52,14 @@ def command
5252

5353
# (see JavaBuildpack::Component::ModularComponent#sub_components)
5454
def sub_components(context)
55+
instance = TomcatInstance.new(sub_configuration_context(context, 'tomcat'))
56+
# pass Tomcat major version to geode_store so we can verify compatibility.
57+
tomcat_version = instance.instance_variable_get(:@version)[0]
58+
5559
components = [
56-
TomcatInstance.new(sub_configuration_context(context, 'tomcat')),
60+
instance,
5761
TomcatAccessLoggingSupport.new(sub_configuration_context(context, 'access_logging_support')),
58-
TomcatGeodeStore.new(sub_configuration_context(context, 'geode_store')),
62+
TomcatGeodeStore.new(sub_configuration_context(context, 'geode_store'), tomcat_version),
5963
TomcatInsightSupport.new(context),
6064
TomcatLifecycleSupport.new(sub_configuration_context(context, 'lifecycle_support')),
6165
TomcatLoggingSupport.new(sub_configuration_context(context, 'logging_support')),

lib/java_buildpack/container/tomcat/tomcat_geode_store.rb

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
# Cloud Foundry Java Buildpack
4-
# Copyright 2013-2020 the original author or authors.
4+
# Copyright 2013-2021 the original author or authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -27,11 +27,22 @@ module Container
2727
class TomcatGeodeStore < JavaBuildpack::Component::VersionedDependencyComponent
2828
include JavaBuildpack::Container
2929

30+
# Creates an instance. In addition to the functionality inherited from +VersionedDependencyComponent+
31+
# +@tomcat_version+ instance variable is exposed.
32+
#
33+
# @param [Hash] context a collection of utilities used by components
34+
# @param [String] tomcat_version is the major version of tomcat
35+
def initialize(context, tomcat_version)
36+
super(context)
37+
@tomcat_version = tomcat_version
38+
end
39+
3040
# (see JavaBuildpack::Component::BaseComponent#compile)
3141
def compile
3242
return unless supports?
3343

3444
download_tar(false, tomcat_lib, tar_name)
45+
detect_geode_tomcat_version
3546
mutate_context
3647
mutate_server
3748
create_cache_client_xml
@@ -58,7 +69,6 @@ def supports?
5869
KEY_LOCATORS = 'locators'
5970
KEY_USERS = 'users'
6071

61-
SESSION_MANAGER_CLASS_NAME = 'org.apache.geode.modules.session.catalina.Tomcat9DeltaSessionManager'
6272
REGION_ATTRIBUTES_ID = 'PARTITION_REDUNDANT_HEAP_LRU'
6373
CACHE_CLIENT_LISTENER_CLASS_NAME =
6474
'org.apache.geode.modules.session.catalina.ClientServerCacheLifecycleListener'
@@ -67,7 +77,7 @@ def supports?
6777
SCHEMA_LOCATION = 'http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd'
6878
LOCATOR_REGEXP = Regexp.new('([^\\[]+)\\[([^\\]]+)\\]').freeze
6979

70-
private_constant :FILTER, :KEY_LOCATORS, :KEY_USERS, :SESSION_MANAGER_CLASS_NAME, :REGION_ATTRIBUTES_ID,
80+
private_constant :FILTER, :KEY_LOCATORS, :KEY_USERS, :REGION_ATTRIBUTES_ID,
7181
:CACHE_CLIENT_LISTENER_CLASS_NAME, :SCHEMA_URL, :SCHEMA_INSTANCE_URL, :SCHEMA_LOCATION,
7282
:LOCATOR_REGEXP
7383

@@ -98,7 +108,7 @@ def add_locators(pool)
98108

99109
def add_manager(context)
100110
context.add_element 'Manager',
101-
'className' => SESSION_MANAGER_CLASS_NAME,
111+
'className' => @session_manager_classname,
102112
'enableLocalCache' => 'true',
103113
'regionAttributesId' => REGION_ATTRIBUTES_ID
104114
end
@@ -124,9 +134,41 @@ def create_cache_client_xml
124134
write_xml cache_client_xml_path, document
125135
end
126136

137+
def detect_geode_tomcat_version
138+
geode_tomcat_version = nil
139+
140+
geode_modules_tomcat_pattern = /geode-modules-tomcat(?<version>[0-9]*).*.jar/.freeze
141+
Dir.foreach(@droplet.sandbox + 'lib') do |file|
142+
if geode_modules_tomcat_pattern.match(file)
143+
unless geode_tomcat_version.nil?
144+
raise('Multiple versions of geode-modules-tomcat jar found. ' \
145+
'Please verify your geode_store tar only contains one geode-modules-tomcat jar.')
146+
end
147+
148+
geode_tomcat_version = geode_modules_tomcat_pattern.match(file).named_captures['version']
149+
end
150+
end
151+
152+
if geode_tomcat_version.nil?
153+
raise('Geode Tomcat module not found. ' \
154+
'Please verify your geode_store tar contains a geode-modules-tomcat jar.')
155+
end
156+
157+
puts " Detected Geode Tomcat #{geode_tomcat_version} module"
158+
159+
# leave possibility for generic jar/session manager class that is compatible with all tomcat versions
160+
if !geode_tomcat_version.empty? && geode_tomcat_version != @tomcat_version
161+
puts " WARNING: Tomcat version #{@tomcat_version} " \
162+
"does not match Geode Tomcat #{geode_tomcat_version} module. " \
163+
'If you encounter compatibility issues, please make sure these versions match.'
164+
end
165+
166+
@session_manager_classname =
167+
"org.apache.geode.modules.session.catalina.Tomcat#{geode_tomcat_version}DeltaSessionManager"
168+
end
169+
127170
def mutate_context
128171
puts ' Adding Geode-based Session Replication'
129-
130172
document = read_xml context_xml
131173
context = REXML::XPath.match(document, '/Context').first
132174

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!--
3+
~ Cloud Foundry Java Buildpack
4+
~ Copyright 2013-2020 the original author or authors.
5+
~
6+
~ Licensed under the Apache License, Version 2.0 (the "License");
7+
~ you may not use this file except in compliance with the License.
8+
~ You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
<Context allowLinking='true'>
19+
<Manager className='org.apache.geode.modules.session.catalina.TomcatDeltaSessionManager' enableLocalCache='true' regionAttributesId='PARTITION_REDUNDANT_HEAP_LRU'/>
20+
</Context>
10 KB
Binary file not shown.
10 KB
Binary file not shown.
60 KB
Binary file not shown.

spec/fixtures/stub-geode-store.tar

9.57 KB
Binary file not shown.

spec/java_buildpack/container/tomcat/tomcat_geode_store_spec.rb

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
# Cloud Foundry Java Buildpack
4-
# Copyright 2013-2020 the original author or authors.
4+
# Copyright 2013-2021 the original author or authors.
55
#
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@
2222
describe JavaBuildpack::Container::TomcatGeodeStore do
2323
include_context 'with component help'
2424

25+
let(:component) { described_class.new(context, '9') }
26+
2527
let(:component_id) { 'tomcat' }
2628

2729
let(:configuration) do
@@ -64,8 +66,9 @@
6466

6567
component.compile
6668

67-
expect(sandbox + 'lib/stub-geode-store/stub-jar-1.jar').to exist
68-
expect(sandbox + 'lib/stub-geode-store/stub-jar-2.jar').to exist
69+
expect(sandbox + 'lib/stub-jar-1.jar').to exist
70+
expect(sandbox + 'lib/stub-jar-2.jar').to exist
71+
expect(sandbox + 'lib/geode-modules-tomcat9.jar').to exist
6972
end
7073

7174
it 'mutates context.xml',
@@ -78,6 +81,45 @@
7881
.to eq(Pathname.new('spec/fixtures/container_tomcat_geode_store_context_after.xml').read)
7982
end
8083

84+
it 'prints warning when Tomcat version in buildpack is different from Geode Tomcat module version',
85+
app_fixture: 'container_tomcat_geode_store',
86+
cache_fixture: 'stub-geode-store.tar' do
87+
88+
component = described_class.new(context, '8')
89+
90+
expect { component.compile }.to output(
91+
# rubocop:disable Layout/LineLength
92+
/WARNING: Tomcat version 8 does not match Geode Tomcat 9 module\. If you encounter compatibility issues, please make sure these versions match\./
93+
# rubocop:enable Layout/LineLength
94+
).to_stdout
95+
end
96+
97+
it 'does not add Geode Tomcat module version to Session Manager classname if version is empty',
98+
app_fixture: 'container_tomcat_geode_store',
99+
cache_fixture: 'stub-geode-store-no-tomcat-version.tar' do
100+
101+
component.compile
102+
103+
expect((sandbox + 'conf/context.xml').read)
104+
.to eq(Pathname.new('spec/fixtures/container_no_tomcat_version_geode_store_context_after.xml').read)
105+
end
106+
107+
it 'raises runtime error if multiple Geode Tomcat module jars are detected',
108+
app_fixture: 'container_tomcat_geode_store',
109+
cache_fixture: 'stub-geode-store-tomcat-multi-version.tar' do
110+
111+
expect { component.compile }.to raise_error RuntimeError, 'Multiple versions of geode-modules-tomcat jar found.' \
112+
' Please verify your geode_store tar only contains one geode-modules-tomcat jar.'
113+
end
114+
115+
it 'raises runtime error if no Geode Tomcat module jar is detected',
116+
app_fixture: 'container_tomcat_geode_store',
117+
cache_fixture: 'stub-geode-store-no-geode-tomcat.tar' do
118+
119+
expect { component.compile }.to raise_error RuntimeError, 'Geode Tomcat module not found. ' \
120+
'Please verify your geode_store tar contains a geode-modules-tomcat jar.'
121+
end
122+
81123
it 'mutates server.xml',
82124
app_fixture: 'container_tomcat_geode_store',
83125
cache_fixture: 'stub-geode-store.tar' do
@@ -98,7 +140,7 @@
98140
.to eq(Pathname.new('spec/fixtures/container_tomcat_geode_store_cache_client_after.xml').read)
99141
end
100142

101-
it 'passes security properties to the release',
143+
it 'passes client auth class to the release',
102144
app_fixture: 'container_tomcat_geode_store',
103145
cache_fixture: 'stub-geode-store.tar' do
104146

0 commit comments

Comments
 (0)