diff --git a/lib/java_buildpack/framework/spring_insight.rb b/lib/java_buildpack/framework/spring_insight.rb index 1d841c380a..71df86e94b 100644 --- a/lib/java_buildpack/framework/spring_insight.rb +++ b/lib/java_buildpack/framework/spring_insight.rb @@ -33,7 +33,7 @@ class SpringInsight < JavaBuildpack::Component::BaseComponent # @param [Hash] context a collection of utilities used the component def initialize(context) super(context) - @version, @uri, @agent_id, @agent_pass = supports? ? find_insight_agent : [nil, nil, nil, nil] + @version, @uri, @agent_transport = find_insight_agent if supports? end # (see JavaBuildpack::Component::BaseComponent#detect) @@ -45,28 +45,23 @@ def detect def compile JavaBuildpack::Util::Cache::InternetAvailability.instance.available( true, 'The Spring Insight download location is always accessible') do - # TODO: AGENT_DOWNLOAD_URI_SUFFIX To be removed once the full path is included in VCAP_SERVICES see #58873498 - download(@version, @uri.chomp('/') + AGENT_DOWNLOAD_URI_SUFFIX) { |file| expand file } + download(@version, @uri) { |file| expand file } end end # (see JavaBuildpack::Component::BaseComponent#release) def release @droplet.java_opts - .add_javaagent(weaver_jar) - .add_system_property('insight.base', insight_directory) - .add_system_property('insight.logs', logs_directory) - .add_system_property('aspectj.overweaving', true) - .add_system_property('org.aspectj.tracing.factory', 'default') - .add_system_property('insight.transport.type', 'HTTP') - - add_agent_configuration + .add_javaagent(weaver_jar) + .add_system_property('insight.base', insight_directory) + .add_system_property('insight.logs', logs_directory) + .add_system_property('aspectj.overweaving', true) + .add_system_property('org.aspectj.tracing.factory', 'default') end protected - # The unique identifier of the component, incorporating the version of the dependency (e.g. - # +spring-insight=1.9.3+) + # The unique identifier of the component, incorporating the version of the dependency) # # @param [String] version the version of the dependency # @return [String] the unique identifier of the component @@ -76,24 +71,9 @@ def id(version) private - # TODO: To be removed once the full path is included in VCAP_SERVICES see issue 58873498 - AGENT_DOWNLOAD_URI_SUFFIX = '/services/config/agent-download'.freeze - - FILTER = /insight/.freeze + FILTER = /p-insight/.freeze - private_constant :AGENT_DOWNLOAD_URI_SUFFIX, :FILTER - - def add_agent_configuration - @droplet.java_opts - .add_system_property('agent.http.protocol', 'http') - .add_system_property('agent.http.host', URI(@uri).host) - .add_system_property('agent.http.port', 80) - .add_system_property('agent.http.context.path', 'insight') - .add_system_property('agent.http.username', @agent_id) - .add_system_property('agent.http.password', @agent_pass) - .add_system_property('agent.http.send.json', false) - .add_system_property('agent.http.use.proxy', false) - end + private_constant :FILTER def expand(file) with_timing "Expanding Spring Insight to #{@droplet.sandbox.relative_path_from(@droplet.root)}" do @@ -112,6 +92,9 @@ def unpack_agent_installer(root, file) FileUtils.mkdir_p(agent_dir) shell "unzip -qq #{file.path} -d #{installer_dir} 2>&1" shell "unzip -qq #{uber_agent_zip(installer_dir)} -d #{agent_dir} 2>&1" + move agent_dir, + installer_dir + 'answers.properties', + installer_dir + 'agent.override.properties' agent_dir end @@ -119,35 +102,34 @@ def unpack_agent_installer(root, file) def install_insight(agent_dir) root = Pathname.glob(agent_dir + 'springsource-insight-uber-agent-*')[0] - init_container_libs root - init_insight_cloudfoundry_agent_plugin root init_insight root + init_insight_properties agent_dir init_insight_agent_plugins root init_weaver root end - def init_container_libs(root) - move container_libs_directory, - root + 'agents/common/insight-bootstrap-generic-*.jar', - root + 'agents/tomcat/7/lib/insight-bootstrap-tomcat-common-*.jar', - root + 'agents/tomcat/7/lib/insight-agent-*.jar' - end - def init_insight(root) move insight_directory, root + 'insight/collection-plugins', - root + 'insight/conf' + root + 'insight/conf', + root + 'insight/bootstrap', + root + 'insight/extras' end - def init_insight_agent_plugins(root) - move insight_directory + 'agent-plugins', - root + 'transport/http/insight-agent-http-*.jar', - root + 'cloudfoundry/insight-agent-cloudfoundry-*.jar' + def init_insight_properties(root) + move insight_directory, + root + 'agent.override.properties' + + answers_properties = root + 'answers.properties' + insight_properties = insight_directory + 'conf/insight.properties' + system "cat #{answers_properties} >> #{insight_properties}" end - def init_insight_cloudfoundry_agent_plugin(root) - move container_libs_directory, - root + 'cloudfoundry/cloudfoundry-runtime-*.jar' + def init_insight_agent_plugins(root) + move insight_directory + 'agent-plugins', + root + 'agents/tomcat/7/lib/insight-agent-*.jar' + transport_jar = transport_plugin root + move insight_directory + 'agent-plugins', transport_jar end def init_weaver(root) @@ -155,18 +137,13 @@ def init_weaver(root) root + 'cloudfoundry/insight-weaver-*.jar' end - def container_libs_directory - @droplet.root + '.spring-insight/container-libs' - end - def find_insight_agent service = @application.services.find_service FILTER - version = service['label'].match(/(.*)-(.*)/)[2] credentials = service['credentials'] - uri = credentials['dashboard_url'] - id = credentials['agent_username'] - pass = credentials['agent_password'] - [version, uri, id, pass] + version = credentials['version'] || '1.0.0' + uri = credentials['agent_download_url'] + transport = credentials['agent_transport'] || 'rabbitmq' + [version, uri, transport] end def insight_directory @@ -186,7 +163,7 @@ def move(destination, *globs) end def supports? - @application.services.one_service? FILTER, 'dashboard_url', 'agent_username', 'agent_password' + @application.services.one_service? FILTER, 'agent_download_url', 'service_instance_id' end def uber_agent_zip(location) @@ -203,6 +180,25 @@ def weaver_jar (weaver_directory + 'insight-weaver-*.jar').glob[0] end + def transport_plugin(root) + return root + 'transport/http/insight-agent-http-*.jar' if http_transport? + return root + 'transport/rabbitmq/insight-agent-rabbitmq-*.jar' if rabbit_transport? + return root + 'transport/activemq/insight-agent-activemq-*.jar' if active_transport? + end + + def http_transport? + @agent_transport.eql? 'http' + end + + def rabbit_transport? + @agent_transport.eql? 'rabbitmq' + end + + def active_transport? + @agent_transport.eql? 'activemq' + end + end + end end diff --git a/spec/fixtures/stub-insight-agent.jar b/spec/fixtures/stub-insight-agent.jar index 6148c8743f..c5ecfa11d0 100644 Binary files a/spec/fixtures/stub-insight-agent.jar and b/spec/fixtures/stub-insight-agent.jar differ diff --git a/spec/java_buildpack/framework/spring_insight_spec.rb b/spec/java_buildpack/framework/spring_insight_spec.rb index 721a4fa541..64577fd17a 100644 --- a/spec/java_buildpack/framework/spring_insight_spec.rb +++ b/spec/java_buildpack/framework/spring_insight_spec.rb @@ -31,51 +31,51 @@ context do before do - allow(services).to receive(:one_service?).with(/insight/, 'dashboard_url', 'agent_username', 'agent_password') - .and_return(true) - allow(services).to receive(:find_service).and_return('label' => 'insight-1.0', - 'credentials' => { 'dashboard_url' => 'test-uri', - 'agent_password' => 'foo', - 'agent_username' => 'bar' }) - allow(application_cache).to receive(:get).with('test-uri/services/config/agent-download') - .and_yield(Pathname.new('spec/fixtures/stub-insight-agent.jar').open, false) + allow(services).to receive(:one_service?) + .with(/p-insight/, 'agent_download_url', 'service_instance_id').and_return(true) + allow(services).to receive(:find_service) + .and_return('label' => 'p-insight', + 'credentials' => { + 'version' => '2.0.0', + 'agent_download_url' => 'test-uri/services/config/agent-download', + 'agent_password' => 'foo', + 'agent_username' => 'bar', + 'service_instance_id' => '12345' }) + allow(application_cache).to receive(:get) + .with('test-uri/services/config/agent-download') + .and_yield(Pathname.new('spec/fixtures/stub-insight-agent.jar').open, false) end - it 'detects with spring-insight-n/a service' do - expect(component.detect).to eq('spring-insight=1.0') + it 'does detect with spring-insight-n/a service' do + expect(component.detect).to eq('spring-insight=2.0.0') end - it 'extracts Spring Insight from the Uber Agent zip file inside the Agent Installer jar' do + it 'does extract Spring Insight from the Uber Agent zip file inside the Agent Installer jar' do component.compile - container_libs_dir = app_dir + '.spring-insight/container-libs' - - expect(sandbox + 'weaver/insight-weaver-cf-2.0.0-CI-SNAPSHOT.jar').to exist - expect(container_libs_dir + 'insight-bootstrap-generic-2.0.0-CI-SNAPSHOT.jar').to exist - expect(container_libs_dir + 'insight-bootstrap-tomcat-common-2.0.0-CI-SNAPSHOT.jar').to exist + expect(sandbox + 'weaver/insight-weaver-2.0.0-CI-SNAPSHOT.jar').to exist expect(sandbox + 'insight/conf/insight.properties').to exist + expect(sandbox + 'insight/agent-plugins/insight-agent-rabbitmq-core-2.0.0-CI-SNAPSHOT.jar').to exist end - it 'guarantees that internet access is available when downloading' do + it 'does guarantee that internet access is available when downloading' do expect_any_instance_of(JavaBuildpack::Util::Cache::InternetAvailability) - .to receive(:available).with(true, 'The Spring Insight download location is always accessible') + .to receive(:available).with(true, 'The Spring Insight download location is always accessible') component.compile end - it 'updates JAVA_OPTS', + it 'does update JAVA_OPTS', app_fixture: 'framework_spring_insight' do component.release - expect(java_opts).to include('-javaagent:$PWD/.java-buildpack/spring_insight/weaver/' \ - 'insight-weaver-1.2.4-CI-SNAPSHOT.jar') + expect(java_opts).to include( + '-javaagent:$PWD/.java-buildpack/spring_insight/weaver/insight-weaver-1.2.4-CI-SNAPSHOT.jar') expect(java_opts).to include('-Dinsight.base=$PWD/.java-buildpack/spring_insight/insight') expect(java_opts).to include('-Dinsight.logs=$PWD/.java-buildpack/spring_insight/insight/logs') expect(java_opts).to include('-Daspectj.overweaving=true') expect(java_opts).to include('-Dorg.aspectj.tracing.factory=default') - expect(java_opts).to include('-Dagent.http.username=bar') - expect(java_opts).to include('-Dagent.http.password=foo') end end