Support for Plain Java and refactored staging.

Change-Id: I88ad35dc9a8783ade4f18cede267ac4e237d607b
This commit is contained in:
AB Srinivasan 2011-08-09 20:35:55 -07:00
Родитель 197850be99
Коммит 301bca233f
22 изменённых файлов: 195 добавлений и 215 удалений

Просмотреть файл

@ -20,7 +20,7 @@ class App < ActiveRecord::Base
AppStates = %w[STOPPED STARTED]
PackageStates = %w[PENDING STAGED FAILED]
Runtimes = %w[ruby18 ruby19 java node erlangR14B02]
Frameworks = %w[sinatra rails3 spring grails node otp_rebar lift unknown]
Frameworks = %w[sinatra rails3 java_web spring grails node otp_rebar lift unknown]
validates_presence_of :name, :framework, :runtime
@ -521,6 +521,9 @@ class App < ActiveRecord::Base
when "rails/1.0"
self.framework = 'rails3'
self.runtime = 'ruby18'
when "java_web/1.0"
self.framework = 'java_web'
self.runtime = 'java'
when "spring_web/1.0"
self.framework = 'spring'
self.runtime = 'java'

Двоичные данные
cloud_controller/spec/fixtures/apps/java_web/source.war поставляемый Normal file

Двоичный файл не отображается.

Двоичные данные
cloud_controller/spec/fixtures/apps/java_web_no_web_config/source.war поставляемый Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -1,7 +1,5 @@
require 'spec_helper'
AUTOSTAGING_JAR = 'auto-reconfiguration-0.6.0-BUILD-SNAPSHOT.jar'
describe "A Grails application being staged without a context-param in its web config and with a default application context config" do
before(:all) do
app_fixture :grails_default_appcontext_no_context_config

Просмотреть файл

@ -0,0 +1,36 @@
require 'spec_helper'
require 'fileutils'
describe "A Java web application being staged without a web config" do
before do
app_fixture :java_web_no_web_config
end
it "should fail" do
lambda { stage :java_web }.should raise_error
end
end
describe "A Java web being staged " do
before(:all) do
app_fixture :java_web
end
it "should not be modified during staging" do
stage :java_web do |staged_dir, source_dir|
source_app_files = Dir.glob("#{source_dir}/**/*", File::FNM_DOTMATCH)
staged_app_root = File.join(staged_dir, 'tomcat/webapps/ROOT')
staged_app_files = Dir.glob("#{staged_app_root}/**/*", File::FNM_DOTMATCH)
source_app_files.should_not == nil
staged_app_files.should_not == nil
source_app_files.length.should == staged_app_files.length
source_app_files.each do |filename|
next if File.directory?(filename)
staged_app_file = filename.sub(/#{source_dir}/, "#{staged_app_root}")
File.exists?(staged_app_file).should == true
FileUtils.compare_file(filename, staged_app_file).should == true
end
end
end
end

Просмотреть файл

@ -3,7 +3,6 @@
require 'spec_helper'
AUTOSTAGING_JAR = 'auto-reconfiguration-0.6.0-BUILD-SNAPSHOT.jar'
LIFT_FILTER_CLASS = 'net.liftweb.http.LiftFilter'
CF_LIFT_PROPERTIES_GENERATOR_CLASS =
'org.cloudfoundry.reconfiguration.CloudLiftServicesPropertiesGenerator';
@ -14,7 +13,7 @@ describe "A Lift application being staged without a web.xml in its web config wi
end
it "should be fail the staging" do
lambda { stage :lift }.should raise_error("Scala / Lift application staging failed: web.xml not found")
lambda { stage :lift }.should raise_error("Web application staging failed: web.xml not found")
end
end

Просмотреть файл

@ -1,7 +1,5 @@
require 'spec_helper'
AUTOSTAGING_JAR = 'auto-reconfiguration-0.6.0-BUILD-SNAPSHOT.jar'
describe "A Spring application being staged" do
before do
app_fixture :spring_guestbook
@ -85,7 +83,7 @@ wait $STARTED
end
end
describe "A Java / Spring application being staged without a web config" do
describe "A Spring web application being staged without a web config" do
before do
app_fixture :spring_no_web_config
end
@ -95,7 +93,7 @@ describe "A Java / Spring application being staged without a web config" do
end
end
describe "A Java / Spring application being staged without a context-param in its web config and without a default application context config" do
describe "A Spring web application being staged without a context-param in its web config and without a default application context config" do
before do
app_fixture :spring_no_context_config
end
@ -120,7 +118,7 @@ describe "A Java / Spring application being staged without a context-param in it
end
end
describe "A Java / Spring application being staged without a context-param in its web config and with a default application context config" do
describe "A Spring web application being staged without a context-param in its web config and with a default application context config" do
before(:all) do
app_fixture :spring_default_appcontext_no_context_config
end
@ -167,7 +165,7 @@ describe "A Java / Spring application being staged without a context-param in it
end
describe "A Java / Spring application being staged with a context-param but without a 'contextConfigLocation' param-name in its web config and with a default application context config" do
describe "A Spring web application being staged with a context-param but without a 'contextConfigLocation' param-name in its web config and with a default application context config" do
before(:all) do
app_fixture :spring_default_appcontext_context_param_no_context_config
end
@ -203,7 +201,7 @@ describe "A Java / Spring application being staged with a context-param but with
end
describe "A Java / Spring application being staged with a context-param containing a 'contextConfigLocation' of 'foo' in its web config" do
describe "A Spring web application being staged with a context-param containing a 'contextConfigLocation' of 'foo' in its web config" do
before(:all) do
app_fixture :spring_context_config_foo
end
@ -235,7 +233,7 @@ describe "A Java / Spring application being staged with a context-param containi
end
describe "A Java / Spring application being staged without a Spring DispatcherServlet in its web config" do
describe "A Spring web application being staged without a Spring DispatcherServlet in its web config" do
before(:all) do
app_fixture :spring_context_config_foo
end
@ -253,7 +251,7 @@ describe "A Java / Spring application being staged without a Spring DispatcherSe
end
end
describe "A Java / Spring application being staged with a Spring DispatcherServlet in its web config that does not have a default servlet context config or an 'init-param' config" do
describe "A Spring web application being staged with a Spring DispatcherServlet in its web config that does not have a default servlet context config or an 'init-param' config" do
before(:all) do
app_fixture :spring_servlet_no_init_param
end
@ -294,7 +292,7 @@ describe "A Java / Spring application being staged with a Spring DispatcherServl
end
end
describe "A Java / Spring application being staged with a Spring DispatcherServlet in its web config and containing a default servlet context config but no 'init-param' config" do
describe "A Spring web application being staged with a Spring DispatcherServlet in its web config and containing a default servlet context config but no 'init-param' config" do
before(:all) do
app_fixture :spring_default_servletcontext_no_init_param
end
@ -341,7 +339,7 @@ describe "A Java / Spring application being staged with a Spring DispatcherServl
end
end
describe "A Java / Spring application being staged with a Spring DispatcherServlet in its web config and containing a default servlet context config but no 'contextConfigLocation' in its 'init-param' config" do
describe "A Spring web application being staged with a Spring DispatcherServlet in its web config and containing a default servlet context config but no 'contextConfigLocation' in its 'init-param' config" do
before(:all) do
app_fixture :spring_default_servletcontext_init_param_no_context_config
end
@ -378,7 +376,7 @@ describe "A Java / Spring application being staged with a Spring DispatcherServl
end
describe "A Java / Spring application being staged with a Spring DispatcherServlet in its web config with an 'init-param' config containing a 'contextConfigLocation' of 'foo' in its web config" do
describe "A Spring web application being staged with a Spring DispatcherServlet in its web config with an 'init-param' config containing a 'contextConfigLocation' of 'foo' in its web config" do
before(:all) do
app_fixture :spring_servlet_context_config_foo
end
@ -414,7 +412,7 @@ describe "A Java / Spring application being staged with a Spring DispatcherServl
end
end
describe "A Java / Spring application being staged with 2 Spring DispatcherServlet in its web config containing a default servlet context config but no 'init-param' configs" do
describe "A Spring web application being staged with 2 Spring DispatcherServlet in its web config containing a default servlet context config but no 'init-param' configs" do
before(:all) do
app_fixture :spring_multiple_dispatcherservlets_no_init_param
end
@ -458,7 +456,7 @@ describe "A Java / Spring application being staged with 2 Spring DispatcherServl
end
describe "A Java / Spring application being staged with 2 Spring DispatcherServlets in its web config with an 'init-param' config in each containing a 'contextConfigLocation' of 'foo' in its web config" do
describe "A Spring web application being staged with 2 Spring DispatcherServlets in its web config with an 'init-param' config in each containing a 'contextConfigLocation' of 'foo' in its web config" do
before(:all) do
app_fixture :spring_multiple_dispatcherservlets_context_config_foo
end

Просмотреть файл

@ -1,6 +1,8 @@
require 'tmpdir'
module StagingSpecHelpers
AUTOSTAGING_JAR = 'auto-reconfiguration-0.6.0-BUILD-SNAPSHOT.jar'
# Importantly, this returns a Pathname instance not a String.
# This allows you to write: app_fixture_base_directory.join('subdir', 'subsubdir')
def app_fixture_base_directory
@ -44,7 +46,7 @@ module StagingSpecHelpers
source_tempdir = nil
# TODO - There really needs to be a single helper to track tempdirs.
source_dir = case framework
when /spring|grails/
when /spring|grails|lift|java_web/
source_tempdir = Dir.mktmpdir(@app_fixture)
app_source(source_tempdir)
else
@ -54,7 +56,7 @@ module StagingSpecHelpers
stager.stage_application
return working_dir unless block_given?
Dir.chdir(working_dir) do
yield Pathname.new(working_dir)
yield Pathname.new(working_dir), Pathname.new(app_source)
end
nil
ensure

Просмотреть файл

@ -1,15 +1,15 @@
require File.expand_path('../../java_common/tomcat', __FILE__)
require File.join(File.expand_path('../../java_web', __FILE__), 'plugin.rb')
require 'nokogiri'
class GrailsPlugin < StagingPlugin
class GrailsPlugin < JavaWebPlugin
VMC_GRAILS_PLUGIN = "CloudFoundryGrailsPlugin"
def framework
'grails'
end
def autostaging_template
File.join(File.dirname(__FILE__), '../java_common/resources', 'autostaging_template_grails.xml')
File.join(File.dirname(__FILE__), 'autostaging_template_grails.xml')
end
# Staging is skipped if the Grails configuration in ""WEB-INF/grails.xml" contains
@ -33,57 +33,4 @@ class GrailsPlugin < StagingPlugin
true
end
def stage_application
Dir.chdir(destination_directory) do
create_app_directories
webapp_root = Tomcat.prepare(destination_directory)
copy_source_files(webapp_root)
Tomcat.configure_tomcat_application(destination_directory, webapp_root, self.autostaging_template, environment) unless self.skip_staging(webapp_root)
create_startup_script
end
end
def create_app_directories
FileUtils.mkdir_p File.join(destination_directory, 'logs')
end
# The Tomcat start script runs from the root of the staged application.
def change_directory_for_start
"cd tomcat"
end
# We redefine this here because Tomcat doesn't want to be passed the cmdline
# args that were given to the 'start' script.
def start_command
"./bin/catalina.sh run"
end
def configure_catalina_opts
# We want to set this to what the user requests, *not* set a minum bar
"-Xms#{application_memory}m -Xmx#{application_memory}m"
end
private
def startup_script
vars = environment_hash
vars['CATALINA_OPTS'] = configure_catalina_opts
generate_startup_script(vars) do
<<-GRAILS
export CATALINA_OPTS="$CATALINA_OPTS `ruby resources/set_environment`"
PORT=-1
while getopts ":p:" opt; do
case $opt in
p)
PORT=$OPTARG
;;
esac
done
if [ $PORT -lt 0 ] ; then
echo "Missing or invalid port (-p)"
exit 1
fi
ruby resources/generate_server_xml $PORT
GRAILS
end
end
end

Просмотреть файл

@ -0,0 +1,79 @@
require File.expand_path('../../common', __FILE__)
require File.join(File.expand_path('../', __FILE__), 'tomcat.rb')
class JavaWebPlugin < StagingPlugin
def framework
'java_web'
end
def autostaging_template
nil
end
def skip_staging webapp_root
true
end
def stage_application
Dir.chdir(destination_directory) do
create_app_directories
webapp_root = Tomcat.prepare(destination_directory)
copy_source_files(webapp_root)
web_config_file = File.join(webapp_root, 'WEB-INF/web.xml')
unless File.exist? web_config_file
raise "Web application staging failed: web.xml not found"
end
do_pre_tomcat_config_setup(webapp_root)
Tomcat.configure_tomcat_application(destination_directory, webapp_root, self.autostaging_template, environment) unless self.skip_staging(webapp_root)
create_startup_script
end
end
def do_pre_tomcat_config_setup webapp_path
end
def create_app_directories
FileUtils.mkdir_p File.join(destination_directory, 'logs')
end
# The Tomcat start script runs from the root of the staged application.
def change_directory_for_start
"cd tomcat"
end
# We redefine this here because Tomcat doesn't want to be passed the cmdline
# args that were given to the 'start' script.
def start_command
"./bin/catalina.sh run"
end
def configure_catalina_opts
# We want to set this to what the user requests, *not* set a minum bar
"-Xms#{application_memory}m -Xmx#{application_memory}m"
end
private
def startup_script
vars = environment_hash
vars['CATALINA_OPTS'] = configure_catalina_opts
generate_startup_script(vars) do
<<-JAVA
export CATALINA_OPTS="$CATALINA_OPTS `ruby resources/set_environment`"
env > env.log
PORT=-1
while getopts ":p:" opt; do
case $opt in
p)
PORT=$OPTARG
;;
esac
done
if [ $PORT -lt 0 ] ; then
echo "Missing or invalid port (-p)"
exit 1
fi
ruby resources/generate_server_xml $PORT
JAVA
end
end
end

Просмотреть файл

@ -0,0 +1,7 @@
#!/usr/bin/env ruby
require File.expand_path('../../common', __FILE__)
plugin_class = StagingPlugin.load_plugin_for('java_web')
plugin_class.validate_arguments!
plugin_class.new(*ARGV).stage_application
# vim: ts=2 sw=2 filetype=ruby

Просмотреть файл

@ -24,17 +24,15 @@ class Tomcat
end
def self.configure_tomcat_application(staging_dir, webapp_root, autostaging_template, environment)
configure_autostaging(webapp_root, autostaging_template)
if autostaging_template
configure_autostaging(webapp_root, autostaging_template)
end
end
def self.configure_autostaging(webapp_path, autostaging_template)
web_config_file = File.join(webapp_path, 'WEB-INF/web.xml')
autostaging_context = get_autostaging_context autostaging_template
if File.exist? web_config_file
modify_autostaging_context(autostaging_context, web_config_file, webapp_path)
else
raise "Spring / J2EE application staging failed: web.xml not found"
end
modify_autostaging_context(autostaging_context, web_config_file, webapp_path)
jar_dest = File.join(webapp_path, 'WEB-INF/lib')
copy_jar AUTOSTAGING_JAR, jar_dest
end

Просмотреть файл

@ -1,9 +1,9 @@
# Copyright (c) 2009-2011 VMware, Inc.
# Author: A.B.Srinivasan - asrinivasan@vmware.com
require File.expand_path('../../java_common/tomcat', __FILE__)
require File.join(File.expand_path('../../java_web', __FILE__), 'plugin.rb')
class LiftPlugin < StagingPlugin
class LiftPlugin < JavaWebPlugin
LIFT_FILTER_CLASS = 'net.liftweb.http.LiftFilter'
CF_LIFT_PROPERTIES_GENERATOR_CLASS =
@ -13,68 +13,17 @@ class LiftPlugin < StagingPlugin
'lift'
end
# Note that we use the Spring auto staging template
def autostaging_template
File.join(File.dirname(__FILE__), '../java_common/resources', 'autostaging_template_spring.xml')
File.join(File.dirname(__FILE__), '../spring', 'autostaging_template_spring.xml')
end
def skip_staging webapp_root
false
end
def stage_application
Dir.chdir(destination_directory) do
create_app_directories
webapp_root = Tomcat.prepare(destination_directory)
copy_source_files(webapp_root)
configure_cf_lift_servlet_context_listener(webapp_root)
Tomcat.configure_tomcat_application(destination_directory, webapp_root, self.autostaging_template, environment) unless self.skip_staging(webapp_root)
create_startup_script
end
end
def create_app_directories
FileUtils.mkdir_p File.join(destination_directory, 'logs')
end
# The Tomcat start script runs from the root of the staged application.
def change_directory_for_start
"cd tomcat"
end
# We redefine this here because Tomcat doesn't want to be passed the cmdline
# args that were given to the 'start' script.
def start_command
"./bin/catalina.sh run"
end
def configure_catalina_opts
# We want to set this to what the user requests, *not* set a minum bar
"-Xms#{application_memory}m -Xmx#{application_memory}m"
end
private
def startup_script
vars = environment_hash
vars['CATALINA_OPTS'] = configure_catalina_opts
generate_startup_script(vars) do
<<-LIFT
export CATALINA_OPTS="$CATALINA_OPTS `ruby resources/set_environment`"
env > env.log
PORT=-1
while getopts ":p:" opt; do
case $opt in
p)
PORT=$OPTARG
;;
esac
done
if [ $PORT -lt 0 ] ; then
echo "Missing or invalid port (-p)"
exit 1
fi
ruby resources/generate_server_xml $PORT
LIFT
end
def do_pre_tomcat_config_setup webapp_path
configure_cf_lift_servlet_context_listener(webapp_path)
end
# We introspect the web configuration ('WEB-INF/web.xml' file) and
@ -85,27 +34,23 @@ ruby resources/generate_server_xml $PORT
# information of the services used by the application.
def configure_cf_lift_servlet_context_listener(webapp_path)
web_config_file = File.join(webapp_path, 'WEB-INF/web.xml')
if File.exist? web_config_file
web_config = Nokogiri::XML(open(web_config_file))
prefix = web_config.root.namespace ? "xmlns:" : ''
lift_filter = web_config.xpath("//web-app/filter[contains(
normalize-space(#{prefix}filter-class),
'#{LIFT_FILTER_CLASS}')]")
unless lift_filter == nil || lift_filter.empty?
servlet_node = web_config.xpath("//web-app/servlet")
if servlet_node == nil || servlet_node.empty?
target_node = lift_filter.first
else
target_node = servlet_node.first
end
servlet_context_listener = generate_cf_servlet_context_listener(web_config)
target_node.add_previous_sibling(servlet_context_listener)
File.open(web_config_file, 'w') {|f| f.write(web_config.to_xml) }
web_config = Nokogiri::XML(open(web_config_file))
prefix = web_config.root.namespace ? "xmlns:" : ''
lift_filter = web_config.xpath("//web-app/filter[contains(
normalize-space(#{prefix}filter-class),
'#{LIFT_FILTER_CLASS}')]")
unless lift_filter == nil || lift_filter.empty?
servlet_node = web_config.xpath("//web-app/servlet")
if servlet_node == nil || servlet_node.empty?
target_node = lift_filter.first
else
raise "Scala / Lift application staging failed: no LiftFilter class found in web.xml"
target_node = servlet_node.first
end
servlet_context_listener = generate_cf_servlet_context_listener(web_config)
target_node.add_previous_sibling(servlet_context_listener)
File.open(web_config_file, 'w') {|f| f.write(web_config.to_xml) }
else
raise "Scala / Lift application staging failed: web.xml not found"
raise "Scala / Lift application staging failed: no LiftFilter class found in web.xml"
end
end

Просмотреть файл

@ -0,0 +1,22 @@
---
name: "java_web"
runtimes:
- "java":
description: "Java 6"
version: "1.6"
executable: "java"
default: true
app_servers:
- "tomcat":
description: "Tomcat"
executable: "false"
default: true
detection:
- "*.war": true
staged_services:
- "name": "mysql"
"version": "*"
- "name": "postgresql"
"version": "*"
# vim: filetype=yaml

Просмотреть файл

@ -1,70 +1,16 @@
require File.expand_path('../../java_common/tomcat', __FILE__)
require File.join(File.expand_path('../../java_web', __FILE__), 'plugin.rb')
class SpringPlugin < StagingPlugin
class SpringPlugin < JavaWebPlugin
def framework
'spring'
end
def autostaging_template
File.join(File.dirname(__FILE__), '../java_common/resources', 'autostaging_template_spring.xml')
File.join(File.dirname(__FILE__), 'autostaging_template_spring.xml')
end
def skip_staging webapp_root
false
end
def stage_application
Dir.chdir(destination_directory) do
create_app_directories
webapp_root = Tomcat.prepare(destination_directory)
copy_source_files(webapp_root)
Tomcat.configure_tomcat_application(destination_directory, webapp_root, self.autostaging_template, environment) unless self.skip_staging(webapp_root)
create_startup_script
end
end
def create_app_directories
FileUtils.mkdir_p File.join(destination_directory, 'logs')
end
# The Tomcat start script runs from the root of the staged application.
def change_directory_for_start
"cd tomcat"
end
# We redefine this here because Tomcat doesn't want to be passed the cmdline
# args that were given to the 'start' script.
def start_command
"./bin/catalina.sh run"
end
def configure_catalina_opts
# We want to set this to what the user requests, *not* set a minum bar
"-Xms#{application_memory}m -Xmx#{application_memory}m"
end
private
def startup_script
vars = environment_hash
vars['CATALINA_OPTS'] = configure_catalina_opts
generate_startup_script(vars) do
<<-SPRING
export CATALINA_OPTS="$CATALINA_OPTS `ruby resources/set_environment`"
env > env.log
PORT=-1
while getopts ":p:" opt; do
case $opt in
p)
PORT=$OPTARG
;;
esac
done
if [ $PORT -lt 0 ] ; then
echo "Missing or invalid port (-p)"
exit 1
fi
ruby resources/generate_server_xml $PORT
SPRING
end
end
end