Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove unnecessary app_properties container, pass services client to …

…plugin action proxy.

Test plan:
- Unit tests pass

Change-Id: I5d5e490908ef26ff33777b3f6b72d4ea14c72b47
  • Loading branch information...
commit 96f119230187ff6e35d246a79343362cba342d6e 1 parent b2e290d
mpage authored
View
1  stager/lib/vcap/stager.rb
@@ -1,4 +1,3 @@
-require 'vcap/stager/app_properties'
require 'vcap/stager/constants'
require 'vcap/stager/config'
require 'vcap/stager/plugin_action_proxy'
View
71 stager/lib/vcap/stager/app_properties.rb
@@ -1,71 +0,0 @@
-require 'yajl'
-
-require 'vcap/json_schema'
-
-module VCAP
- module Stager
- end
-end
-
-class VCAP::Stager::AppProperties
- SCHEMA = VCAP::JsonSchema.build do
- { :name => String,
- :framework => String,
- :runtime => String,
- :plugins => Hash,
- :environment => Hash,
- :resource_limits => {
- :memory => Integer,
- :disk => Integer,
- :fds => Integer,
- },
- :service_bindings => Array,
- }
- end
-
- class << self
- def decode(enc)
- dec = Yajl::Parser.parse(enc, :symbolize_keys => true)
- SCHEMA.validate(dec)
- VCAP::Stager::AppProperties.new(dec[:name],
- dec[:framework],
- dec[:runtime],
- dec[:plugins],
- dec[:environment],
- dec[:resource_limits],
- dec[:service_bindings])
- end
- end
-
- attr_accessor :name
- attr_accessor :framework
- attr_accessor :runtime
- attr_accessor :plugins
- attr_accessor :environment
- attr_accessor :resource_limits
- attr_accessor :service_bindings
-
- def initialize(name, framework, runtime, plugins, environment, resource_limits, service_bindings)
- @name = name
- @framework = framework
- @runtime = runtime
- @plugins = plugins
- @environment = environment
- @resource_limits = resource_limits
- @service_bindings = service_bindings
- end
-
- def encode
- h = {
- :name => @name,
- :framework => @framework,
- :runtime => @runtime,
- :plugins => @plugins,
- :environment => @environment,
- :resource_limits => @resource_limits,
- :service_bindings => @service_bindings,
- }
- Yajl::Encoder.encode(h)
- end
-
-end
View
25 stager/lib/vcap/stager/plugin_action_proxy.rb
@@ -6,30 +6,15 @@ module Stager
# This class exposes actions that modify VCAP resources to staging plugins. An instance
# of it is passed to the plugin as a parameter to the stage() method.
class VCAP::Stager::PluginActionProxy
- def initialize(start_script_path, stop_script_path, droplet)
+ attr_reader :services_client
+
+ def initialize(start_script_path, stop_script_path, droplet, services_client)
@start_script_path = start_script_path
@start_script = nil
@stop_script_path = stop_script_path
@stop_script = nil
- @droplet = droplet
- end
-
- # Creates a service on behalf of the user
- #
- # @param label String The label that uniquely identifies this service
- # @param name String What to call the provisioned service
- # @param plan String Which plan should be provisioned
- # @param plan_option String Optional plan option to select.
- def provision_service(label, name, plan, plan_option=nil)
- @services_client.provision_service(label, name, plan, plan_option, @staging_task_id)
- end
-
- # Binds a service to the application being staged
- #
- # @param name String Name of service to bind
- # @param binding_options Hash Service specific binding options
- def bind_service(name, binding_options)
- raise NotImplementedError
+ @droplet = droplet
+ @services_client = services_client
end
# Returns an open file object that the user can write contents of a
View
33 stager/lib/vcap/stager/plugin_orchestrator.rb
@@ -1,7 +1,9 @@
require 'fileutils'
+require 'rubygems'
-require 'vcap/logging'
+require 'vcap/cloud_controller/ipc'
+require 'vcap/logging'
require 'vcap/stager/constants'
require 'vcap/stager/droplet'
require 'vcap/stager/plugin_action_proxy'
@@ -19,17 +21,24 @@ class VCAP::Stager::PluginOrchestrator
# @param source_dir String Directory containing application source
# @param dest_dir String Directory where the staged droplet should live
# @param app_properties
- def initialize(source_dir, dest_dir, app_properties)
- @source_dir = source_dir
- @dest_dir = dest_dir
- @droplet = VCAP::Stager::Droplet.new(dest_dir)
- @app_properties = app_properties
- @logger = VCAP::Logging.logger('vcap.stager.plugin_orchestrator')
+ # @param cc_info Hash Information needed for contacting the CC
+ # 'host'
+ # 'port'
+ # 'task_id'
+ def initialize(source_dir, dest_dir, app_properties, cc_info)
+ @source_dir = source_dir
+ @dest_dir = dest_dir
+ @droplet = VCAP::Stager::Droplet.new(dest_dir)
+ @app_properties = app_properties
+ @logger = VCAP::Logging.logger('vcap.stager.plugin_orchestrator')
+ @services_client = VCAP::CloudController::Ipc::ServiceConsumerV1Client.new(cc_info['host'],
+ cc_info['port'],
+ :staging_task_id => cc_info['task_id'])
end
def run_plugins
- for name, props in @app_properties.plugins
- require(name)
+ for plugin_info in @app_properties['plugins']
+ require(plugin_info['gem']['name'])
end
framework_plugin, feature_plugins = collect_plugins
@@ -42,7 +51,8 @@ def run_plugins
actions = VCAP::Stager::PluginActionProxy.new(@droplet.framework_start_path,
@droplet.framework_stop_path,
- @droplet)
+ @droplet,
+ @services_client)
@logger.info("Running framework plugin: #{framework_plugin.name}")
framework_plugin.stage(@droplet.app_source_dir, actions, @app_properties)
@@ -50,7 +60,8 @@ def run_plugins
pname = feature_plugin.name
actions = VCAP::Stager::PluginActionProxy.new(@droplet.feature_start_path(pname),
@droplet.feature_stop_path(pname),
- @droplet)
+ @droplet,
+ @services_client)
@logger.info("Running feature plugin: #{feature_plugin.name}")
feature_plugin.stage(framework_plugin, @droplet.app_source_dir, actions, @app_properties)
end
View
4 stager/spec/unit/plugin_action_proxy_spec.rb
@@ -15,7 +15,7 @@
describe '#start_script' do
it 'should return an open file object with mode 755' do
start_path = File.join(@tmpdir, 'start')
- proxy = VCAP::Stager::PluginActionProxy.new(start_path, nil, nil)
+ proxy = VCAP::Stager::PluginActionProxy.new(start_path, nil, nil, nil)
verify_script(proxy.start_script)
end
end
@@ -23,7 +23,7 @@
describe '#stop_script' do
it 'should return an open file object with mode 755' do
stop_path = File.join(@tmpdir, 'stop')
- proxy = VCAP::Stager::PluginActionProxy.new(nil, stop_path, nil)
+ proxy = VCAP::Stager::PluginActionProxy.new(nil, stop_path, nil, nil)
verify_script(proxy.stop_script)
end
end
View
40 stager/spec/unit/plugin_orchestrator_spec.rb
@@ -8,15 +8,25 @@
before :each do
@src_dir = Dir.mktmpdir
@dst_dir = Dir.mktmpdir
- @app_props = VCAP::Stager::AppProperties.new('test',
- 'sinatra',
- 'ruby18',
- {},
- {},
- { :memory => 128,
- :disk => 2048,
- :fds => 1024},
- :service_bindings => [])
+ @cc_info = {
+ 'host' => '127.0.0.1',
+ 'port' => 9090,
+ 'task_id' => 'test_task_id',
+ }
+ @app_props = {
+ 'id' => 1,
+ 'name' => 'testapp',
+ 'framework' => 'sinatra',
+ 'runtime' => 'ruby18',
+ 'plugins' => [],
+ 'service_configs' => [],
+ 'service_bindings' => [],
+ 'resource_limits' => {
+ 'memory' => 128,
+ 'disk' => 2048,
+ 'fds' => 1024,
+ }
+ }
VCAP::Stager::PluginRegistry.reset()
end
@@ -26,15 +36,15 @@
end
it 'should raise an error for unknown plugins' do
- @app_props.plugins = {'unknown_plugin' => {}}
- orch = VCAP::Stager::PluginOrchestrator.new(@src_dir, @dst_dir, @app_props)
+ @app_props['plugins'] = [{'gem' => {'name' => 'invalid_gem'}}]
+ orch = VCAP::Stager::PluginOrchestrator.new(@src_dir, @dst_dir, @app_props, @cc_info)
expect do
orch.run_plugins
end.to raise_error(LoadError)
end
it 'should raise an error if no framework plugin is supplied' do
- orch = VCAP::Stager::PluginOrchestrator.new(@src_dir, @dst_dir, @app_props)
+ orch = VCAP::Stager::PluginOrchestrator.new(@src_dir, @dst_dir, @app_props, @cc_info)
expect do
orch.run_plugins
end.to raise_error(VCAP::Stager::MissingFrameworkPluginError)
@@ -46,7 +56,7 @@
p = create_mock_plugin("plugin_#{i}", :framework)
VCAP::Stager::PluginRegistry.register_plugin(p)
end
- orch = VCAP::Stager::PluginOrchestrator.new(@src_dir, @dst_dir, @app_props)
+ orch = VCAP::Stager::PluginOrchestrator.new(@src_dir, @dst_dir, @app_props, @cc_info)
expect do
orch.run_plugins
end.to raise_error(VCAP::Stager::DuplicateFrameworkPluginError)
@@ -55,7 +65,7 @@
it 'should raise an error if a plugin of unknown type is supplied' do
p = create_mock_plugin(:plugin0, :invalid_plugin_type)
VCAP::Stager::PluginRegistry.register_plugin(p)
- orch = VCAP::Stager::PluginOrchestrator.new(@src_dir, @dst_dir, @app_props)
+ orch = VCAP::Stager::PluginOrchestrator.new(@src_dir, @dst_dir, @app_props, @cc_info)
expect do
orch.run_plugins
end.to raise_error(VCAP::Stager::UnknownPluginTypeError)
@@ -68,7 +78,7 @@
p.should_receive(:stage).with(any_args())
VCAP::Stager::PluginRegistry.register_plugin(p)
end
- orch = VCAP::Stager::PluginOrchestrator.new(@src_dir, @dst_dir, @app_props)
+ orch = VCAP::Stager::PluginOrchestrator.new(@src_dir, @dst_dir, @app_props, @cc_info)
orch.run_plugins
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.