Skip to content

Commit 411241d

Browse files
committed
Detect Geode Tomcat module version
1 parent 43de808 commit 411241d

13 files changed

+148
-19
lines changed

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: 6 additions & 2 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,8 +52,12 @@ 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+
@configuration['geode_store']['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')),
5862
TomcatGeodeStore.new(sub_configuration_context(context, 'geode_store')),
5963
TomcatInsightSupport.new(context),

lib/java_buildpack/container/tomcat/tomcat_geode_store.rb

Lines changed: 38 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.
@@ -32,6 +32,7 @@ def compile
3232
return unless supports?
3333

3434
download_tar(false, tomcat_lib, tar_name)
35+
detect_geode_tomcat_version
3536
mutate_context
3637
mutate_server
3738
create_cache_client_xml
@@ -58,7 +59,6 @@ def supports?
5859
KEY_LOCATORS = 'locators'
5960
KEY_USERS = 'users'
6061

61-
SESSION_MANAGER_CLASS_NAME = 'org.apache.geode.modules.session.catalina.Tomcat9DeltaSessionManager'
6262
REGION_ATTRIBUTES_ID = 'PARTITION_REDUNDANT_HEAP_LRU'
6363
CACHE_CLIENT_LISTENER_CLASS_NAME =
6464
'org.apache.geode.modules.session.catalina.ClientServerCacheLifecycleListener'
@@ -67,7 +67,7 @@ def supports?
6767
SCHEMA_LOCATION = 'http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd'
6868
LOCATOR_REGEXP = Regexp.new('([^\\[]+)\\[([^\\]]+)\\]').freeze
6969

70-
private_constant :FILTER, :KEY_LOCATORS, :KEY_USERS, :SESSION_MANAGER_CLASS_NAME, :REGION_ATTRIBUTES_ID,
70+
private_constant :FILTER, :KEY_LOCATORS, :KEY_USERS, :REGION_ATTRIBUTES_ID,
7171
:CACHE_CLIENT_LISTENER_CLASS_NAME, :SCHEMA_URL, :SCHEMA_INSTANCE_URL, :SCHEMA_LOCATION,
7272
:LOCATOR_REGEXP
7373

@@ -98,7 +98,7 @@ def add_locators(pool)
9898

9999
def add_manager(context)
100100
context.add_element 'Manager',
101-
'className' => SESSION_MANAGER_CLASS_NAME,
101+
'className' => @session_manager_classname,
102102
'enableLocalCache' => 'true',
103103
'regionAttributesId' => REGION_ATTRIBUTES_ID
104104
end
@@ -124,9 +124,42 @@ def create_cache_client_xml
124124
write_xml cache_client_xml_path, document
125125
end
126126

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

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-2021 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>
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-2021 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.Tomcat8DeltaSessionManager' enableLocalCache='true' regionAttributesId='PARTITION_REDUNDANT_HEAP_LRU'/>
20+
</Context>

spec/fixtures/container_tomcat_geode_store_context_after.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version='1.0' encoding='UTF-8'?>
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.
10 KB
Binary file not shown.
10 KB
Binary file not shown.
60 KB
Binary file not shown.
30 KB
Binary file not shown.

0 commit comments

Comments
 (0)