Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 53 additions & 57 deletions lib/java_buildpack/framework/spring_insight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.


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
Expand All @@ -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
Expand All @@ -112,61 +92,58 @@ 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

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)
move weaver_directory,
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
Expand All @@ -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)
Expand All @@ -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
Binary file modified spec/fixtures/stub-insight-agent.jar
Binary file not shown.
46 changes: 23 additions & 23 deletions spec/java_buildpack/framework/spring_insight_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.


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

Expand Down