forked from cloudfoundry/java-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathriverbed_appinternals_agent.rb
110 lines (85 loc) · 3.2 KB
/
riverbed_appinternals_agent.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# frozen_string_literal: true
# Cloud Foundry Java Buildpack
# Copyright 2013-2019 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'fileutils'
require 'java_buildpack/component/versioned_dependency_component'
require 'java_buildpack/framework'
module JavaBuildpack
module Framework
# Encapsulates the functionality for running the Riverbed Appinternals Agent support.
class RiverbedAppinternalsAgent < JavaBuildpack::Component::VersionedDependencyComponent
# Creates an instance
#
# @param [Hash] context a collection of utilities used the component
def initialize(context)
super(context)
@uri = download_url(credentials, @uri)
end
# (see JavaBuildpack::Component::BaseComponent#compile)
def compile
download_zip(false, @droplet.sandbox, @component_name)
@droplet.copy_resources
end
# (see JavaBuildpack::Component::BaseComponent#release)
def release
@droplet.environment_variables
.add_environment_variable('AIX_INSTRUMENT_ALL', 1)
.add_environment_variable('DSA_PORT', dsa_port(credentials))
.add_environment_variable('RVBD_AGENT_FILES', 1)
.add_environment_variable('RVBD_AGENT_PORT', agent_port(credentials))
.add_environment_variable('RVBD_JBP_VERSION', @version)
@droplet.java_opts.add_agentpath(agent_path)
return unless rvbd_moniker(credentials)
@droplet.java_opts.add_system_property('riverbed.moniker', rvbd_moniker(credentials))
end
protected
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
def supports?
@application.services.one_service?(FILTER)
end
private
PROFILERURL = 'profilerUrlLinux'
FILTER = /appinternals/.freeze
private_constant :FILTER
def agent_path
@droplet.sandbox + 'agent/lib' + lib_name
end
def credentials
service['credentials'] unless service.nil?
end
def service
@application.services.find_service(FILTER)
end
def agent_port(credentials)
credentials['rvbd_agent_port'] || 7073
end
def architecture
`uname -m`.strip
end
def dsa_port(credentials)
credentials['rvbd_dsa_port'] || 2111
end
def lib_name
%w[x86_64 i686].include?(architecture) ? 'librpilj64.so' : 'librpilj.so'
end
def rvbd_moniker(credentials)
credentials['rvbd_moniker'] || @configuration['rvbd_moniker']
end
def download_url(credentials, default_url)
(credentials[PROFILERURL] unless credentials.nil?) || default_url
end
end
end
end