From f403450d9442a3d26eda3d2a0b476c85acb38bd7 Mon Sep 17 00:00:00 2001 From: Peter Tran Date: Wed, 24 May 2017 12:31:40 -0400 Subject: [PATCH 1/5] [#145612229] add session state caching support for geode Signed-off-by: Emily Casey --- .gitignore | 1 + .idea/.name | 1 - .idea/.rakeTasks | 7 - .idea/compiler.xml | 23 --- .../copyright/Apache_License__Version_2_0.xml | 9 - .idea/copyright/profiles_settings.xml | 7 - .idea/dictionaries/bhale.xml | 124 ------------- .idea/encodings.xml | 6 - .idea/inspectionProfiles/Project_Default.xml | 7 - .../inspectionProfiles/profiles_settings.xml | 7 - .idea/misc.xml | 8 - .idea/modules.xml | 8 - .idea/runConfigurations/All_Tests__2_2_.xml | 42 ----- .idea/runConfigurations/All_Tests__2_3_.xml | 36 ---- .idea/runConfigurations/All_Tests__2_4_.xml | 36 ---- .../Without_Integration_Tests__2_2_.xml | 42 ----- .../Without_Integration_Tests__2_3_.xml | 36 ---- .../Without_Integration_Tests__2_4_.xml | 36 ---- .idea/runConfigurations/rubocop.xml | 25 --- .idea/runConfigurations/versions.xml | 25 --- .idea/runConfigurations/versions__YAML_.xml | 25 --- .idea/scopes/scope_settings.xml | 5 - .idea/vcs.xml | 7 - Gemfile.lock | 7 + config/tomcat.yml | 3 + lib/java_buildpack/buildpack.rb | 1 - lib/java_buildpack/container/tomcat.rb | 2 + .../container/tomcat/tomcat_geode_store.rb | 168 ++++++++++++++++++ .../container/tomcat/tomcat_instance.rb | 1 - .../container/tomcat/tomcat_redis_store.rb | 2 - .../.java-buildpack/tomcat/conf/context.xml | 19 ++ .../.java-buildpack/tomcat/conf/server.xml | 34 ++++ .../WEB-INF/.gitkeep | 0 ..._tomcat_geode_store_cache_client_after.xml | 21 +++ ...ainer_tomcat_geode_store_context_after.xml | 19 ++ ...tainer_tomcat_geode_store_server_after.xml | 29 +++ spec/fixtures/stub-geode-store.jar | 0 spec/fixtures/stub-geode-store.tar | Bin 0 -> 444 bytes .../tomcat/tomcat_geode_store_spec.rb | 125 +++++++++++++ spec/java_buildpack/container/tomcat_spec.rb | 6 + 40 files changed, 434 insertions(+), 526 deletions(-) delete mode 100644 .idea/.name delete mode 100644 .idea/.rakeTasks delete mode 100644 .idea/compiler.xml delete mode 100644 .idea/copyright/Apache_License__Version_2_0.xml delete mode 100644 .idea/copyright/profiles_settings.xml delete mode 100644 .idea/dictionaries/bhale.xml delete mode 100644 .idea/encodings.xml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/runConfigurations/All_Tests__2_2_.xml delete mode 100644 .idea/runConfigurations/All_Tests__2_3_.xml delete mode 100644 .idea/runConfigurations/All_Tests__2_4_.xml delete mode 100644 .idea/runConfigurations/Without_Integration_Tests__2_2_.xml delete mode 100644 .idea/runConfigurations/Without_Integration_Tests__2_3_.xml delete mode 100644 .idea/runConfigurations/Without_Integration_Tests__2_4_.xml delete mode 100644 .idea/runConfigurations/rubocop.xml delete mode 100644 .idea/runConfigurations/versions.xml delete mode 100644 .idea/runConfigurations/versions__YAML_.xml delete mode 100644 .idea/scopes/scope_settings.xml delete mode 100644 .idea/vcs.xml create mode 100644 lib/java_buildpack/container/tomcat/tomcat_geode_store.rb create mode 100644 spec/fixtures/container_tomcat_geode_store/.java-buildpack/tomcat/conf/context.xml create mode 100644 spec/fixtures/container_tomcat_geode_store/.java-buildpack/tomcat/conf/server.xml create mode 100644 spec/fixtures/container_tomcat_geode_store/WEB-INF/.gitkeep create mode 100644 spec/fixtures/container_tomcat_geode_store_cache_client_after.xml create mode 100644 spec/fixtures/container_tomcat_geode_store_context_after.xml create mode 100644 spec/fixtures/container_tomcat_geode_store_server_after.xml create mode 100644 spec/fixtures/stub-geode-store.jar create mode 100644 spec/fixtures/stub-geode-store.tar create mode 100644 spec/java_buildpack/container/tomcat/tomcat_geode_store_spec.rb diff --git a/.gitignore b/.gitignore index 2ac22b33dc..0773738198 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.idea/**/* .idea/tasks.xml .idea/workspace.xml .yardoc diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 01fc3717f5..0000000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -java-buildpack \ No newline at end of file diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks deleted file mode 100644 index 28643eaeb3..0000000000 --- a/.idea/.rakeTasks +++ /dev/null @@ -1,7 +0,0 @@ - - diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 217af471a9..0000000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - diff --git a/.idea/copyright/Apache_License__Version_2_0.xml b/.idea/copyright/Apache_License__Version_2_0.xml deleted file mode 100644 index 893ada61a7..0000000000 --- a/.idea/copyright/Apache_License__Version_2_0.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index 2fca47b2b3..0000000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/dictionaries/bhale.xml b/.idea/dictionaries/bhale.xml deleted file mode 100644 index 7af11507f1..0000000000 --- a/.idea/dictionaries/bhale.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - addons - agentpath - appdynamics - applicationid - argv - aspectsecurity - atpack - bootclasspath - buildpack - cacert - chrystoki - cklog - codeclimate - constantized - constantizes - cpio - creat - cryptoki - dhttp - dirname - distapplication - dnewrelic - dotmatch - enterprisemanager - etag - extname - ffoo - filenames - fileutils - findex - formatters - fsync - getwd - heroku - httpok - introscope - isengard - javaagent - jdk's - jmxremote - jrebel - jres - jsome - jtest - killjava - libcklog - libcrpytoki - libcryptoki - libruxitagentloader - libyjpagent - ljust - lunaclient - lunajsp - mainclass - metaspace - mkdir - mktmpdir - modularly - mountainlion - mutators - myhost - mypass - myuser - newrelic - newrelicagent - overweaving - pathnames - permgen - pkill - postofficehub - preformatted - priv - progname - proto - ratpack - rbconfig - rdonly - readlink - redhat - rexml - rspec - rstrip - rubo - rubocop - ruxit - safenet - scriptdir - sessionname - shellwords - simplecov - socketfactory - stderr - strftime - stringifies - stubcontainer - stubframework - stubjre - submodules - tasklib - teamserver - tenanttoken - tmpdir - tokenized - uber - ubuntu - uname - undoc - upcase - upto - webapp - webapps - webmock - wildcarded - wronly - xbootclasspath - yardoc - yieldparam - zipfile - - - \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index f758959656..0000000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 48eede57c8..0000000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 3b312839bf..0000000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index acd064c15c..0000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index e80b43be78..0000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/All_Tests__2_2_.xml b/.idea/runConfigurations/All_Tests__2_2_.xml deleted file mode 100644 index 0f31a50950..0000000000 --- a/.idea/runConfigurations/All_Tests__2_2_.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/All_Tests__2_3_.xml b/.idea/runConfigurations/All_Tests__2_3_.xml deleted file mode 100644 index 16757fc1af..0000000000 --- a/.idea/runConfigurations/All_Tests__2_3_.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/All_Tests__2_4_.xml b/.idea/runConfigurations/All_Tests__2_4_.xml deleted file mode 100644 index 02bfb110fc..0000000000 --- a/.idea/runConfigurations/All_Tests__2_4_.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/Without_Integration_Tests__2_2_.xml b/.idea/runConfigurations/Without_Integration_Tests__2_2_.xml deleted file mode 100644 index c700635527..0000000000 --- a/.idea/runConfigurations/Without_Integration_Tests__2_2_.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/Without_Integration_Tests__2_3_.xml b/.idea/runConfigurations/Without_Integration_Tests__2_3_.xml deleted file mode 100644 index e1ba536bb0..0000000000 --- a/.idea/runConfigurations/Without_Integration_Tests__2_3_.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/Without_Integration_Tests__2_4_.xml b/.idea/runConfigurations/Without_Integration_Tests__2_4_.xml deleted file mode 100644 index 567a5e49a4..0000000000 --- a/.idea/runConfigurations/Without_Integration_Tests__2_4_.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/rubocop.xml b/.idea/runConfigurations/rubocop.xml deleted file mode 100644 index c43c11bf4f..0000000000 --- a/.idea/runConfigurations/rubocop.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/versions.xml b/.idea/runConfigurations/versions.xml deleted file mode 100644 index 36aac7eca9..0000000000 --- a/.idea/runConfigurations/versions.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/versions__YAML_.xml b/.idea/runConfigurations/versions__YAML_.xml deleted file mode 100644 index 1acd036c8b..0000000000 --- a/.idea/runConfigurations/versions__YAML_.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b843..0000000000 --- a/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 275077f825..0000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/Gemfile.lock b/Gemfile.lock index 65d9bc33f4..a881b6a021 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,6 +4,7 @@ GEM addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) ast (2.3.0) + coderay (1.1.1) crack (0.4.3) safe_yaml (~> 1.0.0) diff-lcs (1.3) @@ -12,6 +13,10 @@ GEM parser (2.4.0.0) ast (~> 2.2) powerpack (0.1.1) + pry (0.10.4) + coderay (~> 1.1.0) + method_source (~> 0.8.1) + slop (~> 3.4) public_suffix (2.0.5) rainbow (2.2.2) rake @@ -42,6 +47,7 @@ GEM ruby-progressbar (1.8.1) rubyzip (1.2.1) safe_yaml (1.0.4) + slop (3.6.0) tee (1.0.0) terminal-table (1.8.0) unicode-display_width (~> 1.1, >= 1.1.1) @@ -56,6 +62,7 @@ PLATFORMS ruby DEPENDENCIES + pry rake redcarpet rspec diff --git a/config/tomcat.yml b/config/tomcat.yml index e1ff5a78a9..fa12afd1fb 100644 --- a/config/tomcat.yml +++ b/config/tomcat.yml @@ -39,3 +39,6 @@ redis_store: database: 0 timeout: 2000 connection_pool_size: 2 +geode_store: + version: 0.+ + repository_root: "https://tomcat-javabuildpack-spike.s3.amazonaws.com/geode-store" \ No newline at end of file diff --git a/lib/java_buildpack/buildpack.rb b/lib/java_buildpack/buildpack.rb index af0803f2dc..4c1177d05c 100644 --- a/lib/java_buildpack/buildpack.rb +++ b/lib/java_buildpack/buildpack.rb @@ -229,7 +229,6 @@ def with_buildpack(app_dir, message) app_dir = Pathname.new(File.expand_path(app_dir)) Logging::LoggerFactory.instance.setup app_dir application = Component::Application.new(app_dir) - yield new(app_dir, application) if block_given? rescue => e handle_error(e, message) diff --git a/lib/java_buildpack/container/tomcat.rb b/lib/java_buildpack/container/tomcat.rb index e81475b89a..0f657bc6d0 100644 --- a/lib/java_buildpack/container/tomcat.rb +++ b/lib/java_buildpack/container/tomcat.rb @@ -17,6 +17,7 @@ require 'java_buildpack/container' require 'java_buildpack/container/tomcat/tomcat_insight_support' require 'java_buildpack/container/tomcat/tomcat_instance' +require 'java_buildpack/container/tomcat/tomcat_geode_store' require 'java_buildpack/container/tomcat/tomcat_external_configuration' require 'java_buildpack/container/tomcat/tomcat_lifecycle_support' require 'java_buildpack/container/tomcat/tomcat_logging_support' @@ -54,6 +55,7 @@ def sub_components(context) TomcatLoggingSupport.new(sub_configuration_context(context, 'logging_support')), TomcatAccessLoggingSupport.new(sub_configuration_context(context, 'access_logging_support')), TomcatRedisStore.new(sub_configuration_context(context, 'redis_store')), + TomcatGeodeStore.new(sub_configuration_context(context, 'geode_store')), TomcatInsightSupport.new(context) ] diff --git a/lib/java_buildpack/container/tomcat/tomcat_geode_store.rb b/lib/java_buildpack/container/tomcat/tomcat_geode_store.rb new file mode 100644 index 0000000000..b615b9e312 --- /dev/null +++ b/lib/java_buildpack/container/tomcat/tomcat_geode_store.rb @@ -0,0 +1,168 @@ +# Cloud Foundry Java Buildpack +# Copyright 2013-2017 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'java_buildpack/component/versioned_dependency_component' +require 'java_buildpack/container' +require 'java_buildpack/container/tomcat/tomcat_utils' +require 'java_buildpack/logging/logger_factory' + +module JavaBuildpack + module Container + + # Encapsulates the detect, compile, and release functionality for Tomcat Redis support. + class TomcatGeodeStore < JavaBuildpack::Component::VersionedDependencyComponent + include JavaBuildpack::Container + + # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) + def supports? + @application.services.one_service? FILTER, KEY_LOCATORS, KEY_USERS + end + + # (see JavaBuildpack::Component::BaseComponent#release) + def release + return unless supports? + credentials = @application.services.find_service(FILTER)['credentials'] + user = credentials[KEY_USERS].find { |u| u['username'] == 'cluster_operator' } + + @droplet.java_opts.add_system_property 'gemfire.security-username', 'cluster_operator' + @droplet.java_opts.add_system_property 'gemfire.security-password', user['password'] + @droplet.java_opts.add_system_property 'gemfire.security-client-auth-init', + 'io.pivotal.cloudcache.ClientAuthInitialize.create' + end + + # (see JavaBuildpack::Component::BaseComponent#compile) + def compile + return unless supports? + download_tar(false, tomcat_lib, tar_name) + mutate_context + mutate_server + create_cache_client_xml + end + + private + + def cache_client_xml_path + @droplet.sandbox + 'conf' + cache_client_xml + end + + def cache_client_xml + 'cache-client.xml' + end + + FILTER = /session-replication/ + KEY_LOCATORS = 'locators'.freeze + KEY_USERS = 'users'.freeze + + SESSION_MANAGER_CLASS_NAME = 'org.apache.geode.modules.session.catalina.Tomcat8DeltaSessionManager'.freeze + REGION_ATTRIBUTES_ID = 'PARTITION_REDUNDANT_HEAP_LRU'.freeze + CACHE_CLIENT_LISTENER_CLASS_NAME = 'org.apache.geode.modules.session.catalina.ClientServerCacheLifecycleListener'.freeze + SCHEMA_URL = 'http://geode.apache.org/schema/cache'.freeze + SCHEMA_INSTANCE_URL = 'http://www.w3.org/2001/XMLSchema-instance'.freeze + SCHEMA_LOCATION = 'http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd'.freeze + LOCATOR_REGEXP = Regexp.new("([^\\[]+)\\[([^\\]]+)\\]").freeze + FUNCTION_SERVICE_CLASS_NAMES = [ + 'org.apache.geode.modules.util.CreateRegionFunction', + 'org.apache.geode.modules.util.TouchPartitionedRegionEntriesFunction', + 'org.apache.geode.modules.util.TouchReplicatedRegionEntriesFunction', + 'org.apache.geode.modules.util.RegionSizeFunction'].freeze + + private_constant :FILTER, :KEY_LOCATORS, :KEY_USERS + + def tar_name + "geode-store-#{@version}.tar.gz" + end + + def add_manager(context) + context.add_element 'Manager', + 'className' => SESSION_MANAGER_CLASS_NAME, + 'enableLocalCache' => 'true', + 'regionAttributesId' => REGION_ATTRIBUTES_ID + end + + def add_listener(server) + server.add_element 'Listener', + 'className' => CACHE_CLIENT_LISTENER_CLASS_NAME + end + + def add_client_cache(document) + client_cache = document.add_element 'client-cache', + 'xmlns' => SCHEMA_URL, + 'xmlns:xsi' => SCHEMA_INSTANCE_URL, + 'xsi:schemaLocation' => SCHEMA_LOCATION, + 'version' => '1.0' + + add_pool client_cache + add_function_service client_cache + end + + def add_pool(client_cache) + pool = client_cache.add_element 'pool', + 'name' => 'sessions', + 'subscription-enabled' => 'true' + add_locators pool + end + + def add_locators(pool) + service = @application.services.find_service FILTER + service['credentials']['locators'].each do |locator| + match_info = LOCATOR_REGEXP.match(locator) + pool.add_element 'locator', + 'host' => match_info[1], + 'port' => match_info[2] + end + end + + def add_function_service(client_cache) + function_service = client_cache.add_element 'function-service' + add_functions function_service + end + + def add_functions(function_service) + FUNCTION_SERVICE_CLASS_NAMES.each do |function_class_name| + function = function_service.add_element 'function' + class_name = function.add_element 'class-name' + class_name.add_text(function_class_name) + end + end + + def create_cache_client_xml + document = REXML::Document.new('') + add_client_cache document + write_xml cache_client_xml_path, document + end + + def mutate_context + puts ' Adding Geode-based Session Replication' + + document = read_xml context_xml + context = REXML::XPath.match(document, '/Context').first + + add_manager context + + write_xml context_xml, document + end + + def mutate_server + document = read_xml server_xml + + server = REXML::XPath.match(document, '/Server').first + + add_listener server + + write_xml server_xml, document + end + end + end +end diff --git a/lib/java_buildpack/container/tomcat/tomcat_instance.rb b/lib/java_buildpack/container/tomcat/tomcat_instance.rb index 1406f53a46..277f913965 100644 --- a/lib/java_buildpack/container/tomcat/tomcat_instance.rb +++ b/lib/java_buildpack/container/tomcat/tomcat_instance.rb @@ -93,7 +93,6 @@ def expand(file) with_timing "Expanding #{@component_name} to #{@droplet.sandbox.relative_path_from(@droplet.root)}" do FileUtils.mkdir_p @droplet.sandbox shell "tar xzf #{file.path} -C #{@droplet.sandbox} --strip 1 --exclude webapps 2>&1" - @droplet.copy_resources configure_linking configure_jasper diff --git a/lib/java_buildpack/container/tomcat/tomcat_redis_store.rb b/lib/java_buildpack/container/tomcat/tomcat_redis_store.rb index a1eb8a74da..e4ddb2c723 100644 --- a/lib/java_buildpack/container/tomcat/tomcat_redis_store.rb +++ b/lib/java_buildpack/container/tomcat/tomcat_redis_store.rb @@ -107,8 +107,6 @@ def mutate_context write_xml context_xml, document end - end - end end diff --git a/spec/fixtures/container_tomcat_geode_store/.java-buildpack/tomcat/conf/context.xml b/spec/fixtures/container_tomcat_geode_store/.java-buildpack/tomcat/conf/context.xml new file mode 100644 index 0000000000..7f96549265 --- /dev/null +++ b/spec/fixtures/container_tomcat_geode_store/.java-buildpack/tomcat/conf/context.xml @@ -0,0 +1,19 @@ + + + + + diff --git a/spec/fixtures/container_tomcat_geode_store/.java-buildpack/tomcat/conf/server.xml b/spec/fixtures/container_tomcat_geode_store/.java-buildpack/tomcat/conf/server.xml new file mode 100644 index 0000000000..925aa05504 --- /dev/null +++ b/spec/fixtures/container_tomcat_geode_store/.java-buildpack/tomcat/conf/server.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + diff --git a/spec/fixtures/container_tomcat_geode_store/WEB-INF/.gitkeep b/spec/fixtures/container_tomcat_geode_store/WEB-INF/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/fixtures/container_tomcat_geode_store_cache_client_after.xml b/spec/fixtures/container_tomcat_geode_store_cache_client_after.xml new file mode 100644 index 0000000000..b68c118145 --- /dev/null +++ b/spec/fixtures/container_tomcat_geode_store_cache_client_after.xml @@ -0,0 +1,21 @@ + + + + + + + + + org.apache.geode.modules.util.CreateRegionFunction + + + org.apache.geode.modules.util.TouchPartitionedRegionEntriesFunction + + + org.apache.geode.modules.util.TouchReplicatedRegionEntriesFunction + + + org.apache.geode.modules.util.RegionSizeFunction + + + diff --git a/spec/fixtures/container_tomcat_geode_store_context_after.xml b/spec/fixtures/container_tomcat_geode_store_context_after.xml new file mode 100644 index 0000000000..412053d479 --- /dev/null +++ b/spec/fixtures/container_tomcat_geode_store_context_after.xml @@ -0,0 +1,19 @@ + + + + + diff --git a/spec/fixtures/container_tomcat_geode_store_server_after.xml b/spec/fixtures/container_tomcat_geode_store_server_after.xml new file mode 100644 index 0000000000..56b8728e04 --- /dev/null +++ b/spec/fixtures/container_tomcat_geode_store_server_after.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + diff --git a/spec/fixtures/stub-geode-store.jar b/spec/fixtures/stub-geode-store.jar new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spec/fixtures/stub-geode-store.tar b/spec/fixtures/stub-geode-store.tar new file mode 100644 index 0000000000000000000000000000000000000000..816deb94d163df84d7f623093bba2a8fad996123 GIT binary patch literal 444 zcmb2|=3r25(TQYWzI<6b6}3+!3M4}VV0#wRUQ1LBt%lCJ)N%d z>_G^7$h2u~$7MRgMIL++U}U^^Mn{Q9Mn;Aw=xp`g38@y65fU}A&N8L8fA4(xKQ}2M zflVvzIfJL6;1wOFBL!#o_0`SGTX#^gYG2;`+VgY1eY|#c_lehQSC_s!^Yg4DTX>JW zjqat-pRRuVvNvK^SF7=()+ZA)G}rdXKU$S_etJfvjktKN(mJc&#H?@27xlaLB)I?i zbL{VR$&6O+D}pgRJPz%gi!7NmPBnO(VZ7Jlqr|h~Tx%uElkkv+N5v&;Ph9I>kg@sb z!~6-HF+4lwb~3bIkU4vbO(>P^&{~IIqW^BF$i8@Z^1mDN#Q(l$4*tAWoCs< z8?;n^%Ex|gcvA0L^YcE3rSR%W^Z$oxp8J1ePA7xL&-)$Ee%6chGzA)PxgFGyU|pO* S6vtVffuSPu?okE}1_l5jImZhC literal 0 HcmV?d00001 diff --git a/spec/java_buildpack/container/tomcat/tomcat_geode_store_spec.rb b/spec/java_buildpack/container/tomcat/tomcat_geode_store_spec.rb new file mode 100644 index 0000000000..f2db71aa68 --- /dev/null +++ b/spec/java_buildpack/container/tomcat/tomcat_geode_store_spec.rb @@ -0,0 +1,125 @@ +# Cloud Foundry Java Buildpack +# Copyright 2013-2017 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require 'spec_helper' +require 'component_helper' +require 'java_buildpack/container/tomcat/tomcat_geode_store' + +describe JavaBuildpack::Container::TomcatGeodeStore do + include_context 'component_helper' + + let(:component_id) { 'tomcat' } + + let(:configuration) do + { 'database' => 'test-database', + 'timeout' => 'test-timeout', + 'connection_pool_size' => 'test-connection-pool-size' } + end + + it 'does not detect without a session-replication service' do + expect(component.detect).to be_nil + end + + it 'does nothing when it does not detect', + app_fixture: 'container_tomcat_geode_store', + cache_fixture: 'stub-geode-store.tar' do + + component.compile + + expect(sandbox + "lib/stub-geode-store/stub-jar-1.jar").not_to exist + expect(sandbox + "lib/stub-geode-store/stub-jar-2.jar").not_to exist + end + + context 'when there is a session-replication service' do + before do + allow(services).to receive(:one_service?).with(/session-replication/, 'locators', 'users') + .and_return(true) + allow(services).to receive(:find_service).and_return( + { + 'credentials' => { + 'locators' => ['some-locator[some-port]', 'some-other-locator[some-other-port]'], + 'users' => + [ + { + 'password' => 'fake-password', + 'username' => 'cluster_operator' + } + ] + } + } + ) + + end + + it 'detect with a session-replication service' do + expect(component.detect).to eq("tomcat-geode-store=#{version}") + end + + it 'copies resources', + app_fixture: 'container_tomcat_geode_store', + cache_fixture: 'stub-geode-store.tar' do + + component.compile + + expect(sandbox + "lib/stub-geode-store/stub-jar-1.jar").to exist + expect(sandbox + "lib/stub-geode-store/stub-jar-2.jar").to exist + end + + it 'mutates context.xml', + app_fixture: 'container_tomcat_geode_store', + cache_fixture: 'stub-geode-store.tar' do + + component.compile + + expect((sandbox + 'conf/context.xml').read) + .to eq(Pathname.new('spec/fixtures/container_tomcat_geode_store_context_after.xml').read) + end + + it 'mutates server.xml', + app_fixture: 'container_tomcat_geode_store', + cache_fixture: 'stub-geode-store.tar' do + + component.compile + + expect((sandbox + 'conf/server.xml').read) + .to eq(Pathname.new('spec/fixtures/container_tomcat_geode_store_server_after.xml').read) + end + + it 'adds a cache-client.xml', + app_fixture: 'container_tomcat_geode_store', + cache_fixture: 'stub-geode-store.tar' do + + component.compile + + expect((sandbox + 'conf/cache-client.xml').read) + .to eq(Pathname.new('spec/fixtures/container_tomcat_geode_store_cache_client_after.xml').read) + end + + it 'passes security properties to the release', + app_fixture: 'container_tomcat_geode_store', + cache_fixture: 'stub-geode-store.tar' do + + component.release + + expect(java_opts).to include('-Dgemfire.security-client-auth-init=io.pivotal.cloudcache.ClientAuthInitialize.create') + expect(java_opts).to include('-Dgemfire.security-username=cluster_operator') + expect(java_opts).to include('-Dgemfire.security-password=fake-password') + end + + it 'detects with a session-replication service' do + expect(component.detect).to eq("tomcat-geode-store=#{version}") + end + end +end diff --git a/spec/java_buildpack/container/tomcat_spec.rb b/spec/java_buildpack/container/tomcat_spec.rb index ee65087d6c..b3e84f99e7 100644 --- a/spec/java_buildpack/container/tomcat_spec.rb +++ b/spec/java_buildpack/container/tomcat_spec.rb @@ -19,6 +19,7 @@ require 'java_buildpack/container/tomcat' require 'java_buildpack/container/tomcat/tomcat_insight_support' require 'java_buildpack/container/tomcat/tomcat_instance' +require 'java_buildpack/container/tomcat/tomcat_geode_store' require 'java_buildpack/container/tomcat/tomcat_lifecycle_support' require 'java_buildpack/container/tomcat/tomcat_logging_support' require 'java_buildpack/container/tomcat/tomcat_access_logging_support' @@ -32,6 +33,7 @@ let(:configuration) do { 'tomcat' => tomcat_configuration, 'lifecycle_support' => lifecycle_support_configuration, + 'geode_store' => geode_store_configuration, 'logging_support' => logging_support_configuration, 'access_logging_support' => access_logging_support_configuration, 'redis_store' => redis_store_configuration, @@ -44,6 +46,8 @@ let(:logging_support_configuration) { instance_double('logging-support-configuration') } + let(:geode_store_configuration) { instance_double('geode_store_configuration') } + let(:access_logging_support_configuration) { instance_double('logging-support-configuration') } let(:redis_store_configuration) { instance_double('redis-store-configuration') } @@ -73,6 +77,8 @@ .to receive(:new).with(sub_configuration_context(tomcat_configuration)) allow(JavaBuildpack::Container::TomcatLifecycleSupport) .to receive(:new).with(sub_configuration_context(lifecycle_support_configuration)) + allow(JavaBuildpack::Container::TomcatGeodeStore) + .to receive(:new).with(sub_configuration_context(geode_store_configuration)) allow(JavaBuildpack::Container::TomcatLoggingSupport) .to receive(:new).with(sub_configuration_context(logging_support_configuration)) allow(JavaBuildpack::Container::TomcatAccessLoggingSupport) From e29180669a96c6540eca218a4f777fb582b3e68a Mon Sep 17 00:00:00 2001 From: Jammy Louie Date: Fri, 2 Jun 2017 10:54:10 -0400 Subject: [PATCH 2/5] do not ignore .idea directory and ensure we include the infrastructure files --- .gitignore | 1 - .idea/.name | 1 + .idea/.rakeTasks | 7 + .idea/compiler.xml | 23 ++++ .../copyright/Apache_License__Version_2_0.xml | 9 ++ .idea/copyright/profiles_settings.xml | 7 + .idea/dictionaries/bhale.xml | 122 ++++++++++++++++++ .idea/encodings.xml | 6 + .idea/inspectionProfiles/Project_Default.xml | 7 + .../inspectionProfiles/profiles_settings.xml | 7 + .idea/misc.xml | 8 ++ .idea/modules.xml | 8 ++ .idea/runConfigurations/All_Tests__2_2_.xml | 42 ++++++ .idea/runConfigurations/All_Tests__2_3_.xml | 36 ++++++ .idea/runConfigurations/All_Tests__2_4_.xml | 36 ++++++ .../Without_Integration_Tests__2_2_.xml | 42 ++++++ .../Without_Integration_Tests__2_3_.xml | 36 ++++++ .../Without_Integration_Tests__2_4_.xml | 36 ++++++ .idea/runConfigurations/rubocop.xml | 25 ++++ .idea/runConfigurations/versions.xml | 25 ++++ .idea/runConfigurations/versions__JSON_.xml | 25 ++++ .idea/runConfigurations/versions__YAML_.xml | 25 ++++ .idea/scopes/scope_settings.xml | 5 + .idea/vcs.xml | 7 + 24 files changed, 545 insertions(+), 1 deletion(-) create mode 100644 .idea/.name create mode 100644 .idea/.rakeTasks create mode 100644 .idea/compiler.xml create mode 100644 .idea/copyright/Apache_License__Version_2_0.xml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/dictionaries/bhale.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations/All_Tests__2_2_.xml create mode 100644 .idea/runConfigurations/All_Tests__2_3_.xml create mode 100644 .idea/runConfigurations/All_Tests__2_4_.xml create mode 100644 .idea/runConfigurations/Without_Integration_Tests__2_2_.xml create mode 100644 .idea/runConfigurations/Without_Integration_Tests__2_3_.xml create mode 100644 .idea/runConfigurations/Without_Integration_Tests__2_4_.xml create mode 100644 .idea/runConfigurations/rubocop.xml create mode 100644 .idea/runConfigurations/versions.xml create mode 100644 .idea/runConfigurations/versions__JSON_.xml create mode 100644 .idea/runConfigurations/versions__YAML_.xml create mode 100644 .idea/scopes/scope_settings.xml create mode 100644 .idea/vcs.xml diff --git a/.gitignore b/.gitignore index 0773738198..2ac22b33dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -.idea/**/* .idea/tasks.xml .idea/workspace.xml .yardoc diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000000..01fc3717f5 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +java-buildpack \ No newline at end of file diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks new file mode 100644 index 0000000000..28643eaeb3 --- /dev/null +++ b/.idea/.rakeTasks @@ -0,0 +1,7 @@ + + diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000000..217af471a9 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/.idea/copyright/Apache_License__Version_2_0.xml b/.idea/copyright/Apache_License__Version_2_0.xml new file mode 100644 index 0000000000..893ada61a7 --- /dev/null +++ b/.idea/copyright/Apache_License__Version_2_0.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000000..2fca47b2b3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/dictionaries/bhale.xml b/.idea/dictionaries/bhale.xml new file mode 100644 index 0000000000..e3ff95b37b --- /dev/null +++ b/.idea/dictionaries/bhale.xml @@ -0,0 +1,122 @@ + + + + addons + agentpath + appdynamics + applicationid + argv + atpack + bootclasspath + buildpack + cacert + chrystoki + cklog + codeclimate + constantized + constantizes + cpio + creat + cryptoki + dhttp + dirname + distapplication + dnewrelic + dotmatch + enterprisemanager + etag + extname + ffoo + filenames + fileutils + findex + formatters + fsync + getwd + heroku + httpok + introscope + isengard + javaagent + jdk's + jmxremote + jrebel + jres + jsome + jtest + killjava + libcklog + libcrpytoki + libcryptoki + libruxitagentloader + libyjpagent + ljust + lunaclient + lunajsp + mainclass + metaspace + mkdir + mktmpdir + modularly + mountainlion + mutators + myhost + mypass + myuser + newrelic + newrelicagent + overweaving + pathnames + permgen + pkill + postofficehub + preformatted + priv + progname + proto + ratpack + rbconfig + rdonly + readlink + redhat + rexml + rspec + rstrip + rubo + rubocop + ruxit + safenet + scriptdir + sessionname + shellwords + simplecov + socketfactory + stderr + strftime + stringifies + stubcontainer + stubframework + stubjre + submodules + tasklib + tenanttoken + tmpdir + tokenized + uber + ubuntu + uname + undoc + upcase + upto + webapp + webapps + webmock + wildcarded + wronly + xbootclasspath + yardoc + yieldparam + zipfile + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000000..f758959656 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000000..48eede57c8 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000000..3b312839bf --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000000..acd064c15c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000000..e80b43be78 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/All_Tests__2_2_.xml b/.idea/runConfigurations/All_Tests__2_2_.xml new file mode 100644 index 0000000000..0f31a50950 --- /dev/null +++ b/.idea/runConfigurations/All_Tests__2_2_.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/All_Tests__2_3_.xml b/.idea/runConfigurations/All_Tests__2_3_.xml new file mode 100644 index 0000000000..16757fc1af --- /dev/null +++ b/.idea/runConfigurations/All_Tests__2_3_.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/All_Tests__2_4_.xml b/.idea/runConfigurations/All_Tests__2_4_.xml new file mode 100644 index 0000000000..02bfb110fc --- /dev/null +++ b/.idea/runConfigurations/All_Tests__2_4_.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Without_Integration_Tests__2_2_.xml b/.idea/runConfigurations/Without_Integration_Tests__2_2_.xml new file mode 100644 index 0000000000..c700635527 --- /dev/null +++ b/.idea/runConfigurations/Without_Integration_Tests__2_2_.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Without_Integration_Tests__2_3_.xml b/.idea/runConfigurations/Without_Integration_Tests__2_3_.xml new file mode 100644 index 0000000000..e1ba536bb0 --- /dev/null +++ b/.idea/runConfigurations/Without_Integration_Tests__2_3_.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Without_Integration_Tests__2_4_.xml b/.idea/runConfigurations/Without_Integration_Tests__2_4_.xml new file mode 100644 index 0000000000..567a5e49a4 --- /dev/null +++ b/.idea/runConfigurations/Without_Integration_Tests__2_4_.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/rubocop.xml b/.idea/runConfigurations/rubocop.xml new file mode 100644 index 0000000000..c43c11bf4f --- /dev/null +++ b/.idea/runConfigurations/rubocop.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/versions.xml b/.idea/runConfigurations/versions.xml new file mode 100644 index 0000000000..36aac7eca9 --- /dev/null +++ b/.idea/runConfigurations/versions.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/versions__JSON_.xml b/.idea/runConfigurations/versions__JSON_.xml new file mode 100644 index 0000000000..1d3402880a --- /dev/null +++ b/.idea/runConfigurations/versions__JSON_.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/versions__YAML_.xml b/.idea/runConfigurations/versions__YAML_.xml new file mode 100644 index 0000000000..1acd036c8b --- /dev/null +++ b/.idea/runConfigurations/versions__YAML_.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 0000000000..922003b843 --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000000..275077f825 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + From 58ec767d275a79efcbc612fc8da035cc1fc892b7 Mon Sep 17 00:00:00 2001 From: Jammy Louie Date: Fri, 2 Jun 2017 15:50:50 -0400 Subject: [PATCH 3/5] make changes as asked per PR --- Gemfile.lock | 10 +- lib/java_buildpack/buildpack.rb | 1 + lib/java_buildpack/container/tomcat.rb | 14 +- .../container/tomcat/tomcat_geode_store.rb | 120 +++++++++--------- .../container/tomcat/tomcat_instance.rb | 1 + .../container/tomcat/tomcat_redis_store.rb | 2 + .../tomcat/tomcat_geode_store_spec.rb | 45 +++---- spec/java_buildpack/container/tomcat_spec.rb | 28 ++-- 8 files changed, 106 insertions(+), 115 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a881b6a021..7de1621fab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -4,19 +4,17 @@ GEM addressable (2.5.1) public_suffix (~> 2.0, >= 2.0.2) ast (2.3.0) - coderay (1.1.1) crack (0.4.3) safe_yaml (~> 1.0.0) diff-lcs (1.3) hashdiff (0.3.4) +<<<<<<< e29180669a96c6540eca218a4f777fb582b3e68a parallel (1.11.2) +======= +>>>>>>> make changes as asked per PR parser (2.4.0.0) ast (~> 2.2) powerpack (0.1.1) - pry (0.10.4) - coderay (~> 1.1.0) - method_source (~> 0.8.1) - slop (~> 3.4) public_suffix (2.0.5) rainbow (2.2.2) rake @@ -47,7 +45,6 @@ GEM ruby-progressbar (1.8.1) rubyzip (1.2.1) safe_yaml (1.0.4) - slop (3.6.0) tee (1.0.0) terminal-table (1.8.0) unicode-display_width (~> 1.1, >= 1.1.1) @@ -62,7 +59,6 @@ PLATFORMS ruby DEPENDENCIES - pry rake redcarpet rspec diff --git a/lib/java_buildpack/buildpack.rb b/lib/java_buildpack/buildpack.rb index 4c1177d05c..af0803f2dc 100644 --- a/lib/java_buildpack/buildpack.rb +++ b/lib/java_buildpack/buildpack.rb @@ -229,6 +229,7 @@ def with_buildpack(app_dir, message) app_dir = Pathname.new(File.expand_path(app_dir)) Logging::LoggerFactory.instance.setup app_dir application = Component::Application.new(app_dir) + yield new(app_dir, application) if block_given? rescue => e handle_error(e, message) diff --git a/lib/java_buildpack/container/tomcat.rb b/lib/java_buildpack/container/tomcat.rb index 0f657bc6d0..04aa30e932 100644 --- a/lib/java_buildpack/container/tomcat.rb +++ b/lib/java_buildpack/container/tomcat.rb @@ -15,13 +15,13 @@ require 'java_buildpack/component/modular_component' require 'java_buildpack/container' +require 'java_buildpack/container/tomcat/tomcat_access_logging_support' +require 'java_buildpack/container/tomcat/tomcat_external_configuration' +require 'java_buildpack/container/tomcat/tomcat_geode_store' require 'java_buildpack/container/tomcat/tomcat_insight_support' require 'java_buildpack/container/tomcat/tomcat_instance' -require 'java_buildpack/container/tomcat/tomcat_geode_store' -require 'java_buildpack/container/tomcat/tomcat_external_configuration' require 'java_buildpack/container/tomcat/tomcat_lifecycle_support' require 'java_buildpack/container/tomcat/tomcat_logging_support' -require 'java_buildpack/container/tomcat/tomcat_access_logging_support' require 'java_buildpack/container/tomcat/tomcat_redis_store' require 'java_buildpack/util/java_main_utils' @@ -50,13 +50,13 @@ def command # (see JavaBuildpack::Component::ModularComponent#sub_components) def sub_components(context) components = [ + TomcatAccessLoggingSupport.new(sub_configuration_context(context, 'access_logging_support')), + TomcatGeodeStore.new(sub_configuration_context(context, 'geode_store')), TomcatInstance.new(sub_configuration_context(context, 'tomcat')), + TomcatInsightSupport.new(context), TomcatLifecycleSupport.new(sub_configuration_context(context, 'lifecycle_support')), TomcatLoggingSupport.new(sub_configuration_context(context, 'logging_support')), - TomcatAccessLoggingSupport.new(sub_configuration_context(context, 'access_logging_support')), - TomcatRedisStore.new(sub_configuration_context(context, 'redis_store')), - TomcatGeodeStore.new(sub_configuration_context(context, 'geode_store')), - TomcatInsightSupport.new(context) + TomcatRedisStore.new(sub_configuration_context(context, 'redis_store')) ] tomcat_configuration = @configuration['tomcat'] diff --git a/lib/java_buildpack/container/tomcat/tomcat_geode_store.rb b/lib/java_buildpack/container/tomcat/tomcat_geode_store.rb index b615b9e312..a3c49e036e 100644 --- a/lib/java_buildpack/container/tomcat/tomcat_geode_store.rb +++ b/lib/java_buildpack/container/tomcat/tomcat_geode_store.rb @@ -25,14 +25,16 @@ module Container class TomcatGeodeStore < JavaBuildpack::Component::VersionedDependencyComponent include JavaBuildpack::Container - # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) - def supports? - @application.services.one_service? FILTER, KEY_LOCATORS, KEY_USERS + # (see JavaBuildpack::Component::BaseComponent#compile) + def compile + download_tar(false, tomcat_lib, tar_name) + mutate_context + mutate_server + create_cache_client_xml end # (see JavaBuildpack::Component::BaseComponent#release) def release - return unless supports? credentials = @application.services.find_service(FILTER)['credentials'] user = credentials[KEY_USERS].find { |u| u['username'] == 'cluster_operator' } @@ -42,24 +44,14 @@ def release 'io.pivotal.cloudcache.ClientAuthInitialize.create' end - # (see JavaBuildpack::Component::BaseComponent#compile) - def compile - return unless supports? - download_tar(false, tomcat_lib, tar_name) - mutate_context - mutate_server - create_cache_client_xml - end - - private + protected - def cache_client_xml_path - @droplet.sandbox + 'conf' + cache_client_xml + # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) + def supports? + @application.services.one_service? FILTER, KEY_LOCATORS, KEY_USERS end - def cache_client_xml - 'cache-client.xml' - end + private FILTER = /session-replication/ KEY_LOCATORS = 'locators'.freeze @@ -67,28 +59,45 @@ def cache_client_xml SESSION_MANAGER_CLASS_NAME = 'org.apache.geode.modules.session.catalina.Tomcat8DeltaSessionManager'.freeze REGION_ATTRIBUTES_ID = 'PARTITION_REDUNDANT_HEAP_LRU'.freeze - CACHE_CLIENT_LISTENER_CLASS_NAME = 'org.apache.geode.modules.session.catalina.ClientServerCacheLifecycleListener'.freeze + CACHE_CLIENT_LISTENER_CLASS_NAME = + 'org.apache.geode.modules.session.catalina.ClientServerCacheLifecycleListener'.freeze SCHEMA_URL = 'http://geode.apache.org/schema/cache'.freeze SCHEMA_INSTANCE_URL = 'http://www.w3.org/2001/XMLSchema-instance'.freeze SCHEMA_LOCATION = 'http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd'.freeze - LOCATOR_REGEXP = Regexp.new("([^\\[]+)\\[([^\\]]+)\\]").freeze + LOCATOR_REGEXP = Regexp.new('([^\\[]+)\\[([^\\]]+)\\]').freeze FUNCTION_SERVICE_CLASS_NAMES = [ 'org.apache.geode.modules.util.CreateRegionFunction', 'org.apache.geode.modules.util.TouchPartitionedRegionEntriesFunction', 'org.apache.geode.modules.util.TouchReplicatedRegionEntriesFunction', - 'org.apache.geode.modules.util.RegionSizeFunction'].freeze + 'org.apache.geode.modules.util.RegionSizeFunction' + ].freeze - private_constant :FILTER, :KEY_LOCATORS, :KEY_USERS + private_constant :FILTER, :KEY_LOCATORS, :KEY_USERS, :SESSION_MANAGER_CLASS_NAME, :REGION_ATTRIBUTES_ID, + :CACHE_CLIENT_LISTENER_CLASS_NAME, :SCHEMA_URL, :SCHEMA_INSTANCE_URL, :SCHEMA_LOCATION, + :LOCATOR_REGEXP, :FUNCTION_SERVICE_CLASS_NAMES - def tar_name - "geode-store-#{@version}.tar.gz" + def add_client_cache(document) + client_cache = document.add_element 'client-cache', + 'xmlns' => SCHEMA_URL, + 'xmlns:xsi' => SCHEMA_INSTANCE_URL, + 'xsi:schemaLocation' => SCHEMA_LOCATION, + 'version' => '1.0' + + add_pool client_cache + add_function_service client_cache end - def add_manager(context) - context.add_element 'Manager', - 'className' => SESSION_MANAGER_CLASS_NAME, - 'enableLocalCache' => 'true', - 'regionAttributesId' => REGION_ATTRIBUTES_ID + def add_functions(function_service) + FUNCTION_SERVICE_CLASS_NAMES.each do |function_class_name| + function = function_service.add_element 'function' + class_name = function.add_element 'class-name' + class_name.add_text(function_class_name) + end + end + + def add_function_service(client_cache) + function_service = client_cache.add_element 'function-service' + add_functions function_service end def add_listener(server) @@ -96,15 +105,21 @@ def add_listener(server) 'className' => CACHE_CLIENT_LISTENER_CLASS_NAME end - def add_client_cache(document) - client_cache = document.add_element 'client-cache', - 'xmlns' => SCHEMA_URL, - 'xmlns:xsi' => SCHEMA_INSTANCE_URL, - 'xsi:schemaLocation' => SCHEMA_LOCATION, - 'version' => '1.0' + def add_locators(pool) + service = @application.services.find_service FILTER + service['credentials']['locators'].each do |locator| + match_info = LOCATOR_REGEXP.match(locator) + pool.add_element 'locator', + 'host' => match_info[1], + 'port' => match_info[2] + end + end - add_pool client_cache - add_function_service client_cache + def add_manager(context) + context.add_element 'Manager', + 'className' => SESSION_MANAGER_CLASS_NAME, + 'enableLocalCache' => 'true', + 'regionAttributesId' => REGION_ATTRIBUTES_ID end def add_pool(client_cache) @@ -114,27 +129,12 @@ def add_pool(client_cache) add_locators pool end - def add_locators(pool) - service = @application.services.find_service FILTER - service['credentials']['locators'].each do |locator| - match_info = LOCATOR_REGEXP.match(locator) - pool.add_element 'locator', - 'host' => match_info[1], - 'port' => match_info[2] - end - end - - def add_function_service(client_cache) - function_service = client_cache.add_element 'function-service' - add_functions function_service + def cache_client_xml + 'cache-client.xml' end - def add_functions(function_service) - FUNCTION_SERVICE_CLASS_NAMES.each do |function_class_name| - function = function_service.add_element 'function' - class_name = function.add_element 'class-name' - class_name.add_text(function_class_name) - end + def cache_client_xml_path + @droplet.sandbox + 'conf' + cache_client_xml end def create_cache_client_xml @@ -163,6 +163,12 @@ def mutate_server write_xml server_xml, document end + + def tar_name + "geode-store-#{@version}.tar.gz" + end + end + end end diff --git a/lib/java_buildpack/container/tomcat/tomcat_instance.rb b/lib/java_buildpack/container/tomcat/tomcat_instance.rb index 277f913965..1406f53a46 100644 --- a/lib/java_buildpack/container/tomcat/tomcat_instance.rb +++ b/lib/java_buildpack/container/tomcat/tomcat_instance.rb @@ -93,6 +93,7 @@ def expand(file) with_timing "Expanding #{@component_name} to #{@droplet.sandbox.relative_path_from(@droplet.root)}" do FileUtils.mkdir_p @droplet.sandbox shell "tar xzf #{file.path} -C #{@droplet.sandbox} --strip 1 --exclude webapps 2>&1" + @droplet.copy_resources configure_linking configure_jasper diff --git a/lib/java_buildpack/container/tomcat/tomcat_redis_store.rb b/lib/java_buildpack/container/tomcat/tomcat_redis_store.rb index e4ddb2c723..a1eb8a74da 100644 --- a/lib/java_buildpack/container/tomcat/tomcat_redis_store.rb +++ b/lib/java_buildpack/container/tomcat/tomcat_redis_store.rb @@ -107,6 +107,8 @@ def mutate_context write_xml context_xml, document end + end + end end diff --git a/spec/java_buildpack/container/tomcat/tomcat_geode_store_spec.rb b/spec/java_buildpack/container/tomcat/tomcat_geode_store_spec.rb index f2db71aa68..26dab5a30d 100644 --- a/spec/java_buildpack/container/tomcat/tomcat_geode_store_spec.rb +++ b/spec/java_buildpack/container/tomcat/tomcat_geode_store_spec.rb @@ -32,33 +32,19 @@ expect(component.detect).to be_nil end - it 'does nothing when it does not detect', - app_fixture: 'container_tomcat_geode_store', - cache_fixture: 'stub-geode-store.tar' do - - component.compile - - expect(sandbox + "lib/stub-geode-store/stub-jar-1.jar").not_to exist - expect(sandbox + "lib/stub-geode-store/stub-jar-2.jar").not_to exist - end - context 'when there is a session-replication service' do before do allow(services).to receive(:one_service?).with(/session-replication/, 'locators', 'users') .and_return(true) allow(services).to receive(:find_service).and_return( - { - 'credentials' => { - 'locators' => ['some-locator[some-port]', 'some-other-locator[some-other-port]'], - 'users' => - [ - { - 'password' => 'fake-password', - 'username' => 'cluster_operator' - } - ] - } - } + 'credentials' => { + 'locators' => ['some-locator[some-port]', 'some-other-locator[some-other-port]'], + 'users' => + [ + { 'password' => 'fake-password', + 'username' => 'cluster_operator' } + ] + } ) end @@ -68,13 +54,13 @@ end it 'copies resources', - app_fixture: 'container_tomcat_geode_store', - cache_fixture: 'stub-geode-store.tar' do + app_fixture: 'container_tomcat_geode_store', + cache_fixture: 'stub-geode-store.tar' do component.compile - expect(sandbox + "lib/stub-geode-store/stub-jar-1.jar").to exist - expect(sandbox + "lib/stub-geode-store/stub-jar-2.jar").to exist + expect(sandbox + 'lib/stub-geode-store/stub-jar-1.jar').to exist + expect(sandbox + 'lib/stub-geode-store/stub-jar-2.jar').to exist end it 'mutates context.xml', @@ -113,13 +99,12 @@ component.release - expect(java_opts).to include('-Dgemfire.security-client-auth-init=io.pivotal.cloudcache.ClientAuthInitialize.create') + expect(java_opts).to include( + '-Dgemfire.security-client-auth-init=io.pivotal.cloudcache.ClientAuthInitialize.create' + ) expect(java_opts).to include('-Dgemfire.security-username=cluster_operator') expect(java_opts).to include('-Dgemfire.security-password=fake-password') end - it 'detects with a session-replication service' do - expect(component.detect).to eq("tomcat-geode-store=#{version}") - end end end diff --git a/spec/java_buildpack/container/tomcat_spec.rb b/spec/java_buildpack/container/tomcat_spec.rb index b3e84f99e7..281fab0b86 100644 --- a/spec/java_buildpack/container/tomcat_spec.rb +++ b/spec/java_buildpack/container/tomcat_spec.rb @@ -17,12 +17,12 @@ require 'component_helper' require 'fileutils' require 'java_buildpack/container/tomcat' +require 'java_buildpack/container/tomcat/tomcat_access_logging_support' +require 'java_buildpack/container/tomcat/tomcat_geode_store' require 'java_buildpack/container/tomcat/tomcat_insight_support' require 'java_buildpack/container/tomcat/tomcat_instance' -require 'java_buildpack/container/tomcat/tomcat_geode_store' require 'java_buildpack/container/tomcat/tomcat_lifecycle_support' require 'java_buildpack/container/tomcat/tomcat_logging_support' -require 'java_buildpack/container/tomcat/tomcat_access_logging_support' require 'java_buildpack/container/tomcat/tomcat_redis_store' describe JavaBuildpack::Container::Tomcat do @@ -31,16 +31,16 @@ let(:component) { StubTomcat.new context } let(:configuration) do - { 'tomcat' => tomcat_configuration, - 'lifecycle_support' => lifecycle_support_configuration, + { 'access_logging_support' => access_logging_support_configuration, + 'external_configuration' => tomcat_external_configuration, 'geode_store' => geode_store_configuration, + 'lifecycle_support' => lifecycle_support_configuration, 'logging_support' => logging_support_configuration, - 'access_logging_support' => access_logging_support_configuration, 'redis_store' => redis_store_configuration, - 'external_configuration' => tomcat_external_configuration } + 'tomcat' => tomcat_configuration } end - let(:tomcat_configuration) { { 'external_configuration_enabled' => false } } + let(:access_logging_support_configuration) { instance_double('logging-support-configuration') } let(:lifecycle_support_configuration) { instance_double('lifecycle-support-configuration') } @@ -48,10 +48,10 @@ let(:geode_store_configuration) { instance_double('geode_store_configuration') } - let(:access_logging_support_configuration) { instance_double('logging-support-configuration') } - let(:redis_store_configuration) { instance_double('redis-store-configuration') } + let(:tomcat_configuration) { { 'external_configuration_enabled' => false } } + let(:tomcat_external_configuration) { instance_double('tomcat_external_configuration') } it 'detects WEB-INF', @@ -73,19 +73,19 @@ end it 'creates submodules' do + allow(JavaBuildpack::Container::TomcatAccessLoggingSupport) + .to receive(:new).with(sub_configuration_context(access_logging_support_configuration)) + allow(JavaBuildpack::Container::TomcatGeodeStore) + .to receive(:new).with(sub_configuration_context(geode_store_configuration)) allow(JavaBuildpack::Container::TomcatInstance) .to receive(:new).with(sub_configuration_context(tomcat_configuration)) + allow(JavaBuildpack::Container::TomcatInsightSupport).to receive(:new).with(context) allow(JavaBuildpack::Container::TomcatLifecycleSupport) .to receive(:new).with(sub_configuration_context(lifecycle_support_configuration)) - allow(JavaBuildpack::Container::TomcatGeodeStore) - .to receive(:new).with(sub_configuration_context(geode_store_configuration)) allow(JavaBuildpack::Container::TomcatLoggingSupport) .to receive(:new).with(sub_configuration_context(logging_support_configuration)) - allow(JavaBuildpack::Container::TomcatAccessLoggingSupport) - .to receive(:new).with(sub_configuration_context(access_logging_support_configuration)) allow(JavaBuildpack::Container::TomcatRedisStore) .to receive(:new).with(sub_configuration_context(redis_store_configuration)) - allow(JavaBuildpack::Container::TomcatInsightSupport).to receive(:new).with(context) component.sub_components context end From e8bf0bbf01391ea2a21d8611462e5cacedc63f3c Mon Sep 17 00:00:00 2001 From: Jammy Louie Date: Mon, 5 Jun 2017 10:35:49 -0400 Subject: [PATCH 4/5] fix build pack compile issue. reintroduce the check for support in release and compile --- lib/java_buildpack/container/tomcat.rb | 6 +++--- lib/java_buildpack/container/tomcat/tomcat_geode_store.rb | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/java_buildpack/container/tomcat.rb b/lib/java_buildpack/container/tomcat.rb index 04aa30e932..8138fe6864 100644 --- a/lib/java_buildpack/container/tomcat.rb +++ b/lib/java_buildpack/container/tomcat.rb @@ -50,13 +50,13 @@ def command # (see JavaBuildpack::Component::ModularComponent#sub_components) def sub_components(context) components = [ + TomcatInstance.new(sub_configuration_context(context, 'tomcat')), TomcatAccessLoggingSupport.new(sub_configuration_context(context, 'access_logging_support')), TomcatGeodeStore.new(sub_configuration_context(context, 'geode_store')), - TomcatInstance.new(sub_configuration_context(context, 'tomcat')), - TomcatInsightSupport.new(context), TomcatLifecycleSupport.new(sub_configuration_context(context, 'lifecycle_support')), TomcatLoggingSupport.new(sub_configuration_context(context, 'logging_support')), - TomcatRedisStore.new(sub_configuration_context(context, 'redis_store')) + TomcatRedisStore.new(sub_configuration_context(context, 'redis_store')), + TomcatInsightSupport.new(context) ] tomcat_configuration = @configuration['tomcat'] diff --git a/lib/java_buildpack/container/tomcat/tomcat_geode_store.rb b/lib/java_buildpack/container/tomcat/tomcat_geode_store.rb index a3c49e036e..b42fab975f 100644 --- a/lib/java_buildpack/container/tomcat/tomcat_geode_store.rb +++ b/lib/java_buildpack/container/tomcat/tomcat_geode_store.rb @@ -27,6 +27,7 @@ class TomcatGeodeStore < JavaBuildpack::Component::VersionedDependencyComponent # (see JavaBuildpack::Component::BaseComponent#compile) def compile + return unless supports? download_tar(false, tomcat_lib, tar_name) mutate_context mutate_server @@ -35,6 +36,7 @@ def compile # (see JavaBuildpack::Component::BaseComponent#release) def release + return unless supports? credentials = @application.services.find_service(FILTER)['credentials'] user = credentials[KEY_USERS].find { |u| u['username'] == 'cluster_operator' } From 8158283834362c5d2feea256c759fdd871adabfb Mon Sep 17 00:00:00 2001 From: Pulkit Chandra Date: Wed, 28 Jun 2017 10:56:50 -0400 Subject: [PATCH 5/5] Fix merge conflicts --- Gemfile.lock | 3 --- 1 file changed, 3 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 7de1621fab..65d9bc33f4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,10 +8,7 @@ GEM safe_yaml (~> 1.0.0) diff-lcs (1.3) hashdiff (0.3.4) -<<<<<<< e29180669a96c6540eca218a4f777fb582b3e68a parallel (1.11.2) -======= ->>>>>>> make changes as asked per PR parser (2.4.0.0) ast (~> 2.2) powerpack (0.1.1)