Skip to content

Commit 3b68024

Browse files
author
Christopher Frost
committed
Changes required for Spring Insight on PCF 1.5.x
This commit makes a number of changes which are required for compatibility with Spring Insight on PCF 1.5.x. Close #222 [#102664842]
1 parent 5c66fe7 commit 3b68024

3 files changed

Lines changed: 94 additions & 71 deletions

File tree

lib/java_buildpack/framework/spring_insight.rb

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class SpringInsight < JavaBuildpack::Component::BaseComponent
3333
# @param [Hash] context a collection of utilities used the component
3434
def initialize(context)
3535
super(context)
36-
@version, @uri, @agent_id, @agent_pass = supports? ? find_insight_agent : [nil, nil, nil, nil]
36+
@version, @uri, @agent_transport = find_insight_agent if supports?
3737
end
3838

3939
# (see JavaBuildpack::Component::BaseComponent#detect)
@@ -45,8 +45,7 @@ def detect
4545
def compile
4646
JavaBuildpack::Util::Cache::InternetAvailability.instance.available(
4747
true, 'The Spring Insight download location is always accessible') do
48-
# TODO: AGENT_DOWNLOAD_URI_SUFFIX To be removed once the full path is included in VCAP_SERVICES see #58873498
49-
download(@version, @uri.chomp('/') + AGENT_DOWNLOAD_URI_SUFFIX) { |file| expand file }
48+
download(@version, @uri) { |file| expand file }
5049
end
5150
end
5251

@@ -58,15 +57,11 @@ def release
5857
.add_system_property('insight.logs', logs_directory)
5958
.add_system_property('aspectj.overweaving', true)
6059
.add_system_property('org.aspectj.tracing.factory', 'default')
61-
.add_system_property('insight.transport.type', 'HTTP')
62-
63-
add_agent_configuration
6460
end
6561

6662
protected
6763

68-
# The unique identifier of the component, incorporating the version of the dependency (e.g.
69-
# +spring-insight=1.9.3+)
64+
# The unique identifier of the component, incorporating the version of the dependency)
7065
#
7166
# @param [String] version the version of the dependency
7267
# @return [String] the unique identifier of the component
@@ -76,24 +71,9 @@ def id(version)
7671

7772
private
7873

79-
# TODO: To be removed once the full path is included in VCAP_SERVICES see issue 58873498
80-
AGENT_DOWNLOAD_URI_SUFFIX = '/services/config/agent-download'.freeze
81-
82-
FILTER = /insight/.freeze
74+
FILTER = /p-insight/.freeze
8375

84-
private_constant :AGENT_DOWNLOAD_URI_SUFFIX, :FILTER
85-
86-
def add_agent_configuration
87-
@droplet.java_opts
88-
.add_system_property('agent.http.protocol', 'http')
89-
.add_system_property('agent.http.host', URI(@uri).host)
90-
.add_system_property('agent.http.port', 80)
91-
.add_system_property('agent.http.context.path', 'insight')
92-
.add_system_property('agent.http.username', @agent_id)
93-
.add_system_property('agent.http.password', @agent_pass)
94-
.add_system_property('agent.http.send.json', false)
95-
.add_system_property('agent.http.use.proxy', false)
96-
end
76+
private_constant :FILTER
9777

9878
def expand(file)
9979
with_timing "Expanding Spring Insight to #{@droplet.sandbox.relative_path_from(@droplet.root)}" do
@@ -112,61 +92,58 @@ def unpack_agent_installer(root, file)
11292
FileUtils.mkdir_p(agent_dir)
11393
shell "unzip -qq #{file.path} -d #{installer_dir} 2>&1"
11494
shell "unzip -qq #{uber_agent_zip(installer_dir)} -d #{agent_dir} 2>&1"
95+
move agent_dir,
96+
installer_dir + 'answers.properties',
97+
installer_dir + 'agent.override.properties'
11598

11699
agent_dir
117100
end
118101

119102
def install_insight(agent_dir)
120103
root = Pathname.glob(agent_dir + 'springsource-insight-uber-agent-*')[0]
121104

122-
init_container_libs root
123-
init_insight_cloudfoundry_agent_plugin root
124105
init_insight root
106+
init_insight_properties agent_dir
125107
init_insight_agent_plugins root
126108
init_weaver root
127109
end
128110

129-
def init_container_libs(root)
130-
move container_libs_directory,
131-
root + 'agents/common/insight-bootstrap-generic-*.jar',
132-
root + 'agents/tomcat/7/lib/insight-bootstrap-tomcat-common-*.jar',
133-
root + 'agents/tomcat/7/lib/insight-agent-*.jar'
134-
end
135-
136111
def init_insight(root)
137112
move insight_directory,
138113
root + 'insight/collection-plugins',
139-
root + 'insight/conf'
114+
root + 'insight/conf',
115+
root + 'insight/bootstrap',
116+
root + 'insight/extras'
140117
end
141118

142-
def init_insight_agent_plugins(root)
143-
move insight_directory + 'agent-plugins',
144-
root + 'transport/http/insight-agent-http-*.jar',
145-
root + 'cloudfoundry/insight-agent-cloudfoundry-*.jar'
119+
def init_insight_properties(root)
120+
move insight_directory,
121+
root + 'agent.override.properties'
122+
123+
answers_properties = root + 'answers.properties'
124+
insight_properties = insight_directory + 'conf/insight.properties'
125+
system "cat #{answers_properties} >> #{insight_properties}"
146126
end
147127

148-
def init_insight_cloudfoundry_agent_plugin(root)
149-
move container_libs_directory,
150-
root + 'cloudfoundry/cloudfoundry-runtime-*.jar'
128+
def init_insight_agent_plugins(root)
129+
move insight_directory + 'agent-plugins',
130+
root + 'agents/tomcat/7/lib/insight-agent-*.jar'
131+
transport_jar = transport_plugin root
132+
move insight_directory + 'agent-plugins', transport_jar
151133
end
152134

153135
def init_weaver(root)
154136
move weaver_directory,
155137
root + 'cloudfoundry/insight-weaver-*.jar'
156138
end
157139

158-
def container_libs_directory
159-
@droplet.root + '.spring-insight/container-libs'
160-
end
161-
162140
def find_insight_agent
163141
service = @application.services.find_service FILTER
164-
version = service['label'].match(/(.*)-(.*)/)[2]
165142
credentials = service['credentials']
166-
uri = credentials['dashboard_url']
167-
id = credentials['agent_username']
168-
pass = credentials['agent_password']
169-
[version, uri, id, pass]
143+
version = credentials['version'] || '1.0.0'
144+
uri = credentials['agent_download_url']
145+
transport = credentials['agent_transport'] || 'rabbitmq'
146+
[version, uri, transport]
170147
end
171148

172149
def insight_directory
@@ -186,7 +163,7 @@ def move(destination, *globs)
186163
end
187164

188165
def supports?
189-
@application.services.one_service? FILTER, 'dashboard_url', 'agent_username', 'agent_password'
166+
@application.services.one_service? FILTER, 'agent_download_url', 'service_instance_id'
190167
end
191168

192169
def uber_agent_zip(location)
@@ -203,6 +180,25 @@ def weaver_jar
203180
(weaver_directory + 'insight-weaver-*.jar').glob[0]
204181
end
205182

183+
def transport_plugin(root)
184+
return root + 'transport/http/insight-agent-http-*.jar' if http_transport?
185+
return root + 'transport/rabbitmq/insight-agent-rabbitmq-*.jar' if rabbit_transport?
186+
(root + 'transport/activemq/insight-agent-activemq-*.jar') if active_transport?
187+
end
188+
189+
def http_transport?
190+
@agent_transport.eql? 'http'
191+
end
192+
193+
def rabbit_transport?
194+
@agent_transport.eql? 'rabbitmq'
195+
end
196+
197+
def active_transport?
198+
@agent_transport.eql? 'activemq'
199+
end
200+
206201
end
202+
207203
end
208204
end
5.26 KB
Binary file not shown.

spec/java_buildpack/framework/spring_insight_spec.rb

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,41 @@
3131
context do
3232

3333
before do
34-
allow(services).to receive(:one_service?).with(/insight/, 'dashboard_url', 'agent_username', 'agent_password')
35-
.and_return(true)
36-
allow(services).to receive(:find_service).and_return('label' => 'insight-1.0',
37-
'credentials' => { 'dashboard_url' => 'test-uri',
38-
'agent_password' => 'foo',
39-
'agent_username' => 'bar' })
40-
allow(application_cache).to receive(:get).with('test-uri/services/config/agent-download')
34+
allow(services).to receive(:one_service?)
35+
.with(/p-insight/, 'agent_download_url', 'service_instance_id').and_return(true)
36+
allow(services).to receive(:find_service)
37+
.and_return('label' => 'p-insight',
38+
'credentials' => {
39+
'version' => '2.0.0',
40+
'agent_download_url' => 'test-uri/services/config/agent-download',
41+
'agent_password' => 'foo',
42+
'agent_username' => 'bar',
43+
'service_instance_id' => '12345' })
44+
allow(application_cache).to receive(:get)
45+
.with('test-uri/services/config/agent-download')
4146
.and_yield(Pathname.new('spec/fixtures/stub-insight-agent.jar').open, false)
4247
end
4348

44-
it 'detects with spring-insight-n/a service' do
45-
expect(component.detect).to eq('spring-insight=1.0')
49+
it 'does detect with spring-insight-n/a service' do
50+
expect(component.detect).to eq('spring-insight=2.0.0')
4651
end
4752

48-
it 'extracts Spring Insight from the Uber Agent zip file inside the Agent Installer jar' do
53+
it 'does extract Spring Insight from the Uber Agent zip file inside the Agent Installer jar' do
4954
component.compile
5055

51-
container_libs_dir = app_dir + '.spring-insight/container-libs'
52-
53-
expect(sandbox + 'weaver/insight-weaver-cf-2.0.0-CI-SNAPSHOT.jar').to exist
54-
expect(container_libs_dir + 'insight-bootstrap-generic-2.0.0-CI-SNAPSHOT.jar').to exist
55-
expect(container_libs_dir + 'insight-bootstrap-tomcat-common-2.0.0-CI-SNAPSHOT.jar').to exist
56+
expect(sandbox + 'weaver/insight-weaver-2.0.0-CI-SNAPSHOT.jar').to exist
5657
expect(sandbox + 'insight/conf/insight.properties').to exist
58+
expect(sandbox + 'insight/agent-plugins/insight-agent-rabbitmq-core-2.0.0-CI-SNAPSHOT.jar').to exist
5759
end
5860

59-
it 'guarantees that internet access is available when downloading' do
61+
it 'does guarantee that internet access is available when downloading' do
6062
expect_any_instance_of(JavaBuildpack::Util::Cache::InternetAvailability)
6163
.to receive(:available).with(true, 'The Spring Insight download location is always accessible')
6264

6365
component.compile
6466
end
6567

66-
it 'updates JAVA_OPTS',
68+
it 'does update JAVA_OPTS',
6769
app_fixture: 'framework_spring_insight' do
6870

6971
component.release
@@ -74,9 +76,34 @@
7476
expect(java_opts).to include('-Dinsight.logs=$PWD/.java-buildpack/spring_insight/insight/logs')
7577
expect(java_opts).to include('-Daspectj.overweaving=true')
7678
expect(java_opts).to include('-Dorg.aspectj.tracing.factory=default')
77-
expect(java_opts).to include('-Dagent.http.username=bar')
78-
expect(java_opts).to include('-Dagent.http.password=foo')
7979
end
8080
end
8181

82+
context do
83+
84+
it 'does extract Spring Insight from the Uber Agent zip file and copy the ActiveMQ plugin' do
85+
allow(services).to receive(:one_service?)
86+
.with(/p-insight/, 'agent_download_url', 'service_instance_id').and_return(true)
87+
allow(services).to receive(:find_service)
88+
.and_return('label' => 'p-insight',
89+
'credentials' => {
90+
'version' => '2.0.0',
91+
'agent_download_url' => 'test-uri/services/config/agent-download',
92+
'agent_password' => 'foo',
93+
'agent_username' => 'bar',
94+
'service_instance_id' => '12345',
95+
'agent_transport' => 'activemq' })
96+
allow(application_cache).to receive(:get)
97+
.with('test-uri/services/config/agent-download')
98+
.and_yield(Pathname.new('spec/fixtures/stub-insight-agent.jar').open, false)
99+
100+
component.compile
101+
102+
expect(sandbox + 'weaver/insight-weaver-2.0.0-CI-SNAPSHOT.jar').to exist
103+
expect(sandbox + 'insight/conf/insight.properties').to exist
104+
expect(sandbox + 'insight/agent-plugins/insight-agent-activemq-2.0.0-CI-SNAPSHOT.jar').to exist
105+
end
106+
107+
end
108+
82109
end

0 commit comments

Comments
 (0)