Skip to content

Commit 8de8339

Browse files
committed
Merge branch '437-pivotal-cloud-cache' into 3.x
2 parents f925bc3 + 0e5a542 commit 8de8339

File tree

12 files changed

+431
-12
lines changed

12 files changed

+431
-12
lines changed

config/tomcat.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ redis_store:
3939
database: 0
4040
timeout: 2000
4141
connection_pool_size: 2
42+
geode_store:
43+
version: 0.+
44+
repository_root: "{default.repository.root}/geode-store"

lib/java_buildpack/container/tomcat.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515

1616
require 'java_buildpack/component/modular_component'
1717
require 'java_buildpack/container'
18+
require 'java_buildpack/container/tomcat/tomcat_access_logging_support'
19+
require 'java_buildpack/container/tomcat/tomcat_external_configuration'
20+
require 'java_buildpack/container/tomcat/tomcat_geode_store'
1821
require 'java_buildpack/container/tomcat/tomcat_insight_support'
1922
require 'java_buildpack/container/tomcat/tomcat_instance'
20-
require 'java_buildpack/container/tomcat/tomcat_external_configuration'
2123
require 'java_buildpack/container/tomcat/tomcat_lifecycle_support'
2224
require 'java_buildpack/container/tomcat/tomcat_logging_support'
23-
require 'java_buildpack/container/tomcat/tomcat_access_logging_support'
2425
require 'java_buildpack/container/tomcat/tomcat_redis_store'
2526
require 'java_buildpack/util/java_main_utils'
2627

@@ -50,9 +51,10 @@ def command
5051
def sub_components(context)
5152
components = [
5253
TomcatInstance.new(sub_configuration_context(context, 'tomcat')),
54+
TomcatAccessLoggingSupport.new(sub_configuration_context(context, 'access_logging_support')),
55+
TomcatGeodeStore.new(sub_configuration_context(context, 'geode_store')),
5356
TomcatLifecycleSupport.new(sub_configuration_context(context, 'lifecycle_support')),
5457
TomcatLoggingSupport.new(sub_configuration_context(context, 'logging_support')),
55-
TomcatAccessLoggingSupport.new(sub_configuration_context(context, 'access_logging_support')),
5658
TomcatRedisStore.new(sub_configuration_context(context, 'redis_store')),
5759
TomcatInsightSupport.new(context)
5860
]
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2013-2017 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
require 'java_buildpack/component/versioned_dependency_component'
17+
require 'java_buildpack/container'
18+
require 'java_buildpack/container/tomcat/tomcat_utils'
19+
require 'java_buildpack/logging/logger_factory'
20+
21+
module JavaBuildpack
22+
module Container
23+
24+
# Encapsulates the detect, compile, and release functionality for Tomcat Redis support.
25+
class TomcatGeodeStore < JavaBuildpack::Component::VersionedDependencyComponent
26+
include JavaBuildpack::Container
27+
28+
# (see JavaBuildpack::Component::BaseComponent#compile)
29+
def compile
30+
return unless supports?
31+
download_tar(false, tomcat_lib, tar_name)
32+
mutate_context
33+
mutate_server
34+
create_cache_client_xml
35+
end
36+
37+
# (see JavaBuildpack::Component::BaseComponent#release)
38+
def release
39+
return unless supports?
40+
credentials = @application.services.find_service(FILTER)['credentials']
41+
user = credentials[KEY_USERS].find { |u| u['username'] == 'cluster_operator' }
42+
43+
@droplet.java_opts.add_system_property 'gemfire.security-username', 'cluster_operator'
44+
@droplet.java_opts.add_system_property 'gemfire.security-password', user['password']
45+
@droplet.java_opts.add_system_property 'gemfire.security-client-auth-init',
46+
'io.pivotal.cloudcache.ClientAuthInitialize.create'
47+
end
48+
49+
protected
50+
51+
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
52+
def supports?
53+
@application.services.one_service? FILTER, KEY_LOCATORS, KEY_USERS
54+
end
55+
56+
private
57+
58+
FILTER = /session-replication/
59+
KEY_LOCATORS = 'locators'.freeze
60+
KEY_USERS = 'users'.freeze
61+
62+
SESSION_MANAGER_CLASS_NAME = 'org.apache.geode.modules.session.catalina.Tomcat8DeltaSessionManager'.freeze
63+
REGION_ATTRIBUTES_ID = 'PARTITION_REDUNDANT_HEAP_LRU'.freeze
64+
CACHE_CLIENT_LISTENER_CLASS_NAME =
65+
'org.apache.geode.modules.session.catalina.ClientServerCacheLifecycleListener'.freeze
66+
SCHEMA_URL = 'http://geode.apache.org/schema/cache'.freeze
67+
SCHEMA_INSTANCE_URL = 'http://www.w3.org/2001/XMLSchema-instance'.freeze
68+
SCHEMA_LOCATION = 'http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd'.freeze
69+
LOCATOR_REGEXP = Regexp.new('([^\\[]+)\\[([^\\]]+)\\]').freeze
70+
FUNCTION_SERVICE_CLASS_NAMES = [
71+
'org.apache.geode.modules.util.CreateRegionFunction',
72+
'org.apache.geode.modules.util.TouchPartitionedRegionEntriesFunction',
73+
'org.apache.geode.modules.util.TouchReplicatedRegionEntriesFunction',
74+
'org.apache.geode.modules.util.RegionSizeFunction'
75+
].freeze
76+
77+
private_constant :FILTER, :KEY_LOCATORS, :KEY_USERS, :SESSION_MANAGER_CLASS_NAME, :REGION_ATTRIBUTES_ID,
78+
:CACHE_CLIENT_LISTENER_CLASS_NAME, :SCHEMA_URL, :SCHEMA_INSTANCE_URL, :SCHEMA_LOCATION,
79+
:LOCATOR_REGEXP, :FUNCTION_SERVICE_CLASS_NAMES
80+
81+
def add_client_cache(document)
82+
client_cache = document.add_element 'client-cache',
83+
'xmlns' => SCHEMA_URL,
84+
'xmlns:xsi' => SCHEMA_INSTANCE_URL,
85+
'xsi:schemaLocation' => SCHEMA_LOCATION,
86+
'version' => '1.0'
87+
88+
add_pool client_cache
89+
add_function_service client_cache
90+
end
91+
92+
def add_functions(function_service)
93+
FUNCTION_SERVICE_CLASS_NAMES.each do |function_class_name|
94+
function = function_service.add_element 'function'
95+
class_name = function.add_element 'class-name'
96+
class_name.add_text(function_class_name)
97+
end
98+
end
99+
100+
def add_function_service(client_cache)
101+
function_service = client_cache.add_element 'function-service'
102+
add_functions function_service
103+
end
104+
105+
def add_listener(server)
106+
server.add_element 'Listener',
107+
'className' => CACHE_CLIENT_LISTENER_CLASS_NAME
108+
end
109+
110+
def add_locators(pool)
111+
service = @application.services.find_service FILTER
112+
service['credentials']['locators'].each do |locator|
113+
match_info = LOCATOR_REGEXP.match(locator)
114+
pool.add_element 'locator',
115+
'host' => match_info[1],
116+
'port' => match_info[2]
117+
end
118+
end
119+
120+
def add_manager(context)
121+
context.add_element 'Manager',
122+
'className' => SESSION_MANAGER_CLASS_NAME,
123+
'enableLocalCache' => 'true',
124+
'regionAttributesId' => REGION_ATTRIBUTES_ID
125+
end
126+
127+
def add_pool(client_cache)
128+
pool = client_cache.add_element 'pool',
129+
'name' => 'sessions',
130+
'subscription-enabled' => 'true'
131+
add_locators pool
132+
end
133+
134+
def cache_client_xml
135+
'cache-client.xml'
136+
end
137+
138+
def cache_client_xml_path
139+
@droplet.sandbox + 'conf' + cache_client_xml
140+
end
141+
142+
def create_cache_client_xml
143+
document = REXML::Document.new('<?xml version="1.0" encoding="UTF-8"?>')
144+
add_client_cache document
145+
write_xml cache_client_xml_path, document
146+
end
147+
148+
def mutate_context
149+
puts ' Adding Geode-based Session Replication'
150+
151+
document = read_xml context_xml
152+
context = REXML::XPath.match(document, '/Context').first
153+
154+
add_manager context
155+
156+
write_xml context_xml, document
157+
end
158+
159+
def mutate_server
160+
document = read_xml server_xml
161+
162+
server = REXML::XPath.match(document, '/Server').first
163+
164+
add_listener server
165+
166+
write_xml server_xml, document
167+
end
168+
169+
def tar_name
170+
"geode-store-#{@version}.tar.gz"
171+
end
172+
173+
end
174+
175+
end
176+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<!--
3+
~ Copyright 2013-2017 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<Context allowLinking='true'>
19+
</Context>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<!--
3+
~ Copyright 2013-2017 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the 'License');
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an 'AS IS' BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<Server port='-1'>
18+
19+
<Service name='Catalina'>
20+
<Connector port='${http.port}' bindOnInit='false' connectionTimeout='20000'/>
21+
22+
<Engine defaultHost='localhost' name='Catalina'>
23+
<Valve className='org.apache.catalina.valves.RemoteIpValve' protocolHeader='x-forwarded-proto'/>
24+
<Valve className='com.gopivotal.cloudfoundry.tomcat.logging.access.CloudFoundryAccessLoggingValve'
25+
pattern='[ACCESS] %{org.apache.catalina.AccessLog.RemoteAddr}r %l %t %D %F %B %S vcap_request_id:%{X-Vcap-Request-Id}i'
26+
enabled='${access.logging.enabled}'/>
27+
<Host name='localhost'
28+
failCtxIfServletStartFails='true'>
29+
<Listener className='com.gopivotal.cloudfoundry.tomcat.lifecycle.ApplicationStartupFailureDetectingLifecycleListener'/>
30+
</Host>
31+
</Engine>
32+
</Service>
33+
34+
</Server>

spec/fixtures/container_tomcat_geode_store/WEB-INF/.gitkeep

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<client-cache xmlns='http://geode.apache.org/schema/cache' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd' version='1.0'>
3+
<pool name='sessions' subscription-enabled='true'>
4+
<locator host='some-locator' port='some-port'/>
5+
<locator host='some-other-locator' port='some-other-port'/>
6+
</pool>
7+
<function-service>
8+
<function>
9+
<class-name>org.apache.geode.modules.util.CreateRegionFunction</class-name>
10+
</function>
11+
<function>
12+
<class-name>org.apache.geode.modules.util.TouchPartitionedRegionEntriesFunction</class-name>
13+
</function>
14+
<function>
15+
<class-name>org.apache.geode.modules.util.TouchReplicatedRegionEntriesFunction</class-name>
16+
</function>
17+
<function>
18+
<class-name>org.apache.geode.modules.util.RegionSizeFunction</class-name>
19+
</function>
20+
</function-service>
21+
</client-cache>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!--
3+
~ Copyright 2013-2017 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<Context allowLinking='true'>
18+
<Manager className='org.apache.geode.modules.session.catalina.Tomcat8DeltaSessionManager' enableLocalCache='true' regionAttributesId='PARTITION_REDUNDANT_HEAP_LRU'/>
19+
</Context>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<!--
3+
~ Copyright 2013-2017 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the 'License');
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an 'AS IS' BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
<Server port='-1'>
18+
<Service name='Catalina'>
19+
<Connector port='${http.port}' bindOnInit='false' connectionTimeout='20000'/>
20+
<Engine defaultHost='localhost' name='Catalina'>
21+
<Valve className='org.apache.catalina.valves.RemoteIpValve' protocolHeader='x-forwarded-proto'/>
22+
<Valve className='com.gopivotal.cloudfoundry.tomcat.logging.access.CloudFoundryAccessLoggingValve' pattern='[ACCESS] %{org.apache.catalina.AccessLog.RemoteAddr}r %l %t %D %F %B %S vcap_request_id:%{X-Vcap-Request-Id}i' enabled='${access.logging.enabled}'/>
23+
<Host name='localhost' failCtxIfServletStartFails='true'>
24+
<Listener className='com.gopivotal.cloudfoundry.tomcat.lifecycle.ApplicationStartupFailureDetectingLifecycleListener'/>
25+
</Host>
26+
</Engine>
27+
</Service>
28+
<Listener className='org.apache.geode.modules.session.catalina.ClientServerCacheLifecycleListener'/>
29+
</Server>

spec/fixtures/stub-geode-store.tar

444 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)