forked from cloudfoundry/java-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintroscope_agent.rb
More file actions
129 lines (103 loc) · 4.3 KB
/
Copy pathintroscope_agent.rb
File metadata and controls
129 lines (103 loc) · 4.3 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# frozen_string_literal: true
# Cloud Foundry Java Buildpack
# Copyright 2013-2018 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'
require 'java_buildpack/util/to_b'
module JavaBuildpack
module Framework
# Encapsulates the functionality for enabling zero-touch Introscope support.
class IntroscopeAgent < JavaBuildpack::Component::VersionedDependencyComponent
# (see JavaBuildpack::Component::BaseComponent#compile)
def compile
download_tar
@droplet.copy_resources
end
# (see JavaBuildpack::Component::BaseComponent#release)
def release
credentials = @application.services.find_service(FILTER, 'url')['credentials']
java_opts = @droplet.java_opts
java_opts
.add_javaagent(agent_jar)
.add_system_property('com.wily.introscope.agentProfile', agent_profile)
.add_system_property('introscope.agent.hostName', agent_host_name)
.add_system_property('com.wily.introscope.agent.agentName', agent_name(credentials))
.add_system_property('introscope.agent.defaultProcessName', default_process_name)
java_opts.add_system_property('agentManager.credential', credential(credentials)) if credential(credentials)
add_url(credentials, java_opts)
end
protected
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
def supports?
@application.services.one_service? FILTER, 'url'
end
private
FILTER = /introscope/
private_constant :FILTER
def agent_host_name
@application.details['application_uris'][0]
end
def agent_jar
@droplet.sandbox + 'Agent.jar'
end
def add_url(credentials, java_opts)
agent_manager = url(credentials)
host, port, socket_factory = parse_url(agent_manager)
java_opts.add_system_property('agentManager.url.1', agent_manager)
java_opts.add_system_property('introscope.agent.enterprisemanager.transport.tcp.host.DEFAULT', host)
java_opts.add_system_property('introscope.agent.enterprisemanager.transport.tcp.port.DEFAULT', port)
java_opts.add_system_property('introscope.agent.enterprisemanager.transport.tcp.socketfactory.DEFAULT',
socket_factory)
end
# Parse the agent manager url, split first by '://', and then with ':'
# components is of the format [host, port, socket_factory]
def parse_url(url)
components = url.split('://')
components.unshift('') if components.length == 1
components[1] = components[1].split(':')
components.flatten!
components.push(protocol_mapping(components[0]))
components.shift
components
end
def agent_name(credentials)
credentials['agent_name'] || @configuration['default_agent_name']
end
def agent_profile
@droplet.sandbox + 'core/config/IntroscopeAgent.profile'
end
def default_process_name
@application.details['application_name']
end
def protocol_mapping(protocol)
socket_factory_base = 'com.wily.isengard.postofficehub.link.net.'
protocol_socket_factory = {
'' => socket_factory_base + 'DefaultSocketFactory',
'ssl' => socket_factory_base + 'SSLSocketFactory',
'http' => socket_factory_base + 'HttpTunnelingSocketFactory',
'https' => socket_factory_base + 'HttpsTunnelingSocketFactory'
}
protocol_socket_factory[protocol] || protocol
end
def url(credentials)
credentials['url']
end
def credential(credentials)
credentials['credential']
end
end
end
end