diff --git a/lib/java_buildpack/framework/app_dynamics_agent.rb b/lib/java_buildpack/framework/app_dynamics_agent.rb index 2b77246a24..5a676e827a 100644 --- a/lib/java_buildpack/framework/app_dynamics_agent.rb +++ b/lib/java_buildpack/framework/app_dynamics_agent.rb @@ -39,7 +39,8 @@ def compile default_conf_dir = resources_dir + @droplet.component_id + 'defaults' copy_appd_default_configuration(default_conf_dir) - override_default_config_if_applicable + override_default_config_remote + override_default_config_local @droplet.copy_resources end @@ -169,7 +170,7 @@ def check_if_resource_exists(resource_uri, conf_file) # Check for configuration files on a remote server. If found, copy to conf dir under each ver* dir # @return [Void] - def override_default_config_if_applicable + def override_default_config_remote return unless @application.environment['APPD_CONF_HTTP_URL'] JavaBuildpack::Util::Cache::InternetAvailability.instance.available( @@ -194,6 +195,27 @@ def override_default_config_if_applicable end end end + + # Check for configuration files locally. If found, copy to conf dir under each ver* dir + # @return [Void] + def override_default_config_local + return unless @application.environment['APPD_CONF_DIR'] + + app_conf_dir = @application.root + @application.environment['APPD_CONF_DIR'] + + raise "AppDynamics configuration source dir #{app_conf_dir} does not exist" unless Dir.exist?(app_conf_dir) + + @logger.info { "Copy override configuration files from #{app_conf_dir}" } + CONFIG_FILES.each do |conf_file| + conf_file_path = app_conf_dir + conf_file + + next unless File.file?(conf_file_path) + + Dir.glob(@droplet.sandbox + 'ver*') do |target_directory| + FileUtils.cp_r conf_file_path, target_directory + '/conf/' + conf_file + end + end + end end end end diff --git a/spec/fixtures/framework_app_dynamics_agent/BOOT-INF/classes/appdynamics/conf/app-agent-config.xml b/spec/fixtures/framework_app_dynamics_agent/BOOT-INF/classes/appdynamics/conf/app-agent-config.xml new file mode 100644 index 0000000000..b934fa90f3 --- /dev/null +++ b/spec/fixtures/framework_app_dynamics_agent/BOOT-INF/classes/appdynamics/conf/app-agent-config.xml @@ -0,0 +1,730 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + com.singularity.ee.agent.appagent.kernel.DynamicServiceManager + + + + + + + + + + BCIEngine,TransactionMonitoringService,SnapshotService + + + + + + + + BCIEngine + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + BCIEngine + + + + + + + + + + + + + + + + + + + + + + + + + + + + BCIEngine,SnapshotService + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + JMXService + + + BCIEngine + + + + + + + + + + + + + + + + + + + + + + + + + + BCIEngine + + + + + + + + + + + + + + + + + + + + + + + BCIEngine + + + + + TransactionMonitoringService + + + + + + + + + + + + + + diff --git a/spec/fixtures/stub-app-dynamics-agent.zip b/spec/fixtures/stub-app-dynamics-agent.zip index a973e1e9dd..5e879a4c58 100644 Binary files a/spec/fixtures/stub-app-dynamics-agent.zip and b/spec/fixtures/stub-app-dynamics-agent.zip differ diff --git a/spec/java_buildpack/framework/app_dynamics_agent_spec.rb b/spec/java_buildpack/framework/app_dynamics_agent_spec.rb index 40630aedf9..9927e80ca9 100644 --- a/spec/java_buildpack/framework/app_dynamics_agent_spec.rb +++ b/spec/java_buildpack/framework/app_dynamics_agent_spec.rb @@ -189,6 +189,31 @@ component.compile end end + + context do + + let(:environment) { { 'APPD_CONF_DIR' => 'BOOT-INF/classes/appdynamics/conf' } } + + it 'sets APPD_CONF_DIR env var to copy config files from app dir', + app_fixture: 'framework_app_dynamics_agent', + cache_fixture: 'stub-app-dynamics-agent.zip' do + + component.compile + expect(File.read(sandbox + 'ver21.1.0.31582/conf/app-agent-config.xml')).to include 'sourced by APPD_CONF_DIR' + end + end + + context do + + let(:environment) { { 'APPD_CONF_DIR' => 'BOOT-INF/classes/appdynamics/conf-false' } } + + it 'sets APPD_CONF_DIR env var to copy config files from incorrect app dir', + app_fixture: 'framework_app_dynamics_agent', + cache_fixture: 'stub-app-dynamics-agent.zip' do + + expect { component.compile }.to raise_error(RuntimeError, /AppDynamics configuration source dir/) + end + end end end end