Skip to content

Commit fe5fc17

Browse files
committed
Merge branch 'ruxit'
2 parents 2f71821 + 6983542 commit fe5fc17

File tree

8 files changed

+305
-1
lines changed

8 files changed

+305
-1
lines changed

.idea/dictionaries/bhale.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/components.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ frameworks:
4848
- "JavaBuildpack::Framework::PlayFrameworkAutoReconfiguration"
4949
- "JavaBuildpack::Framework::PlayFrameworkJPAPlugin"
5050
- "JavaBuildpack::Framework::PostgresqlJDBC"
51+
- "JavaBuildpack::Framework::RuxitAgent"
5152
- "JavaBuildpack::Framework::SpringAutoReconfiguration"
5253
- "JavaBuildpack::Framework::SpringInsight"
5354
- "JavaBuildpack::Framework::YourKitProfiler"

config/ruxit_agent.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2013-2016 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Configuration for the Ruxit framework
17+
---
18+
version: 1.+
19+
repository_root: http://download.ruxit.com/agent/paas/cloudfoundry/java

docs/framework-ruxit_agent.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Ruxit Agent Framework
2+
The Ruxit Agent Framework causes an application to be automatically configured to work with a bound [Ruxit Service][] instance (Free trials available).
3+
4+
<table>
5+
<tr>
6+
<td><strong>Detection Criterion</strong></td><td>Existence of a single bound Ruxit service.
7+
<ul>
8+
<li>Existence of a Ruxit service is defined as the <a href="http://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html#VCAP-SERVICES"><code>VCAP_SERVICES</code></a> payload containing a service who's name, label or tag has <code>ruxit</code> as a substring.</li>
9+
</ul>
10+
</td>
11+
</tr>
12+
<tr>
13+
<td><strong>Tags</strong></td>
14+
<td><tt>ruxit-agent=&lt;version&gt;</tt></td>
15+
</tr>
16+
</table>
17+
Tags are printed to standard output by the buildpack detect script
18+
19+
## User-Provided Service (Optional)
20+
Users may optionally provide their own Ruxit service. A user-provided Ruxit service must have a name or tag with `ruxit` in it so that the Ruxit Agent Framework will automatically configure the application to work with the service.
21+
22+
The credential payload of the service may contain the following entries:
23+
24+
| Name | Description
25+
| ---- | -----------
26+
| `tenant` | Your Ruxit tenant ID is the unique identifier of your Ruxit environment. You can find it easily by looking at the URL in your browser when you are logged into your Ruxit environment. The subdomain `{tenant}` in `https://{tenant}.live.ruxit.com` represents your tenant ID.
27+
| `tenanttoken` | The token for your Ruxit environment. You can find it in the deploy Ruxit section within your environment.
28+
| `server` | (Optional) The Ruxit server connection URL to connect to. Use `host:port` format for a specific port number. Uses `https://{tenant}.live.ruxit.com:443/communication` by default.
29+
30+
## Configuration
31+
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][].
32+
33+
Any environment variables with a `RUXIT_` prefix will be relayed to the droplet to allow full configuration of the agent.
34+
35+
The framework can be configured by modifying the [`config/ruxit_agent.yml`][] file in the buildpack fork. The framework uses the [`Repository` utility support][repositories] and so it supports the [version syntax][] defined there.
36+
37+
| Name | Description
38+
| ---- | -----------
39+
| `repository_root` | The URL of the Ruxit repository index ([details][repositories]).
40+
| `version` | The version of Ruxit to use. Candidate versions can be found in [this listing][].
41+
42+
[Configuration and Extension]: ../README.md#configuration-and-extension
43+
[`config/ruxit_agent.yml`]: ../config/ruxit_agent.yml
44+
[Ruxit Service]: https://ruxit.com
45+
[repositories]: extending-repositories.md
46+
[this listing]: http://download.ruxit.com/agent/paas/cloudfoundry/java/index.yml
47+
[version syntax]: extending-repositories.md#version-syntax-and-ordering

lib/java_buildpack/framework/new_relic_agent.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
require 'fileutils'
1817
require 'java_buildpack/component/versioned_dependency_component'
1918
require 'java_buildpack/framework'
2019

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# Encoding: utf-8
2+
# Cloud Foundry Java Buildpack
3+
# Copyright 2013-2016 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'fileutils'
18+
require 'java_buildpack/component/versioned_dependency_component'
19+
require 'java_buildpack/framework'
20+
21+
module JavaBuildpack
22+
module Framework
23+
24+
# Encapsulates the functionality for enabling zero-touch Ruxit support.
25+
class RuxitAgent < JavaBuildpack::Component::VersionedDependencyComponent
26+
27+
# (see JavaBuildpack::Component::BaseComponent#compile)
28+
def compile
29+
download(@version, @uri) { |file| expand file }
30+
@droplet.copy_resources
31+
end
32+
33+
# (see JavaBuildpack::Component::BaseComponent#release)
34+
def release
35+
credentials = @application.services.find_service(FILTER)['credentials']
36+
37+
@droplet.java_opts.add_agentpath_with_props(agent_path,
38+
SERVER => server(credentials),
39+
TENANT => tenant(credentials),
40+
TENANTTOKEN => tenanttoken(credentials))
41+
42+
environment = @application.environment
43+
environment_variables = @droplet.environment_variables
44+
45+
unless environment.key?(RUXIT_APPLICATION_ID)
46+
environment_variables.add_environment_variable(RUXIT_APPLICATION_ID, application_id)
47+
end
48+
49+
unless environment.key?(RUXIT_CLUSTER_ID)
50+
environment_variables.add_environment_variable(RUXIT_CLUSTER_ID, cluster_id)
51+
end
52+
53+
environment_variables.add_environment_variable(RUXIT_HOST_ID, host_id) unless environment.key?(RUXIT_HOST_ID)
54+
end
55+
56+
protected
57+
58+
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
59+
def supports?
60+
@application.services.one_service? FILTER, TENANT, TENANTTOKEN
61+
end
62+
63+
private
64+
65+
FILTER = /ruxit/.freeze
66+
67+
RUXIT_APPLICATION_ID = 'RUXIT_APPLICATIONID'.freeze
68+
69+
RUXIT_CLUSTER_ID = 'RUXIT_CLUSTER_ID'.freeze
70+
71+
RUXIT_HOST_ID = 'RUXIT_HOST_ID'.freeze
72+
73+
SERVER = 'server'.freeze
74+
75+
TENANT = 'tenant'.freeze
76+
77+
TENANTTOKEN = 'tenanttoken'.freeze
78+
79+
private_constant :FILTER, :RUXIT_APPLICATION_ID, :RUXIT_CLUSTER_ID, :RUXIT_HOST_ID, :SERVER, :TENANT, :TENANTTOKEN
80+
81+
def agent_dir
82+
@droplet.sandbox + 'agent'
83+
end
84+
85+
def agent_path
86+
agent_dir + 'lib64/libruxitagentloader.so'
87+
end
88+
89+
def application_id
90+
@application.details['application_name']
91+
end
92+
93+
def cluster_id
94+
@application.details['application_name']
95+
end
96+
97+
def expand(file)
98+
with_timing "Expanding Ruxit Agent to #{@droplet.sandbox.relative_path_from(@droplet.root)}" do
99+
Dir.mktmpdir do |root|
100+
root_path = Pathname.new(root)
101+
shell "unzip -qq #{file.path} -d #{root_path} 2>&1"
102+
unpack_agent root_path
103+
end
104+
end
105+
end
106+
107+
def host_id
108+
"#{@application.details['application_name']}_${CF_INSTANCE_INDEX}"
109+
end
110+
111+
def server(credentials)
112+
credentials[SERVER] || "https://#{tenant(credentials)}.live.ruxit.com:443/communication"
113+
end
114+
115+
def tenant(credentials)
116+
credentials[TENANT]
117+
end
118+
119+
def tenanttoken(credentials)
120+
credentials[TENANTTOKEN]
121+
end
122+
123+
def unpack_agent(root)
124+
FileUtils.mkdir_p(agent_dir)
125+
FileUtils.mv(root + 'agent/bin', agent_dir)
126+
FileUtils.mv(root + 'agent/conf', agent_dir)
127+
FileUtils.mv(root + 'agent/lib64', agent_dir)
128+
end
129+
130+
end
131+
132+
end
133+
end

spec/fixtures/stub-ruxit-agent.zip

996 Bytes
Binary file not shown.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# Encoding: utf-8
2+
# Cloud Foundry Java Buildpack
3+
# Copyright 2013-2016 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
require 'spec_helper'
18+
require 'component_helper'
19+
require 'java_buildpack/framework/ruxit_agent'
20+
require 'java_buildpack/util/tokenized_version'
21+
22+
describe JavaBuildpack::Framework::RuxitAgent do
23+
include_context 'component_helper'
24+
25+
it 'does not detect without ruxit-n/a service' do
26+
expect(component.detect).to be_nil
27+
end
28+
29+
context do
30+
31+
before do
32+
allow(services).to receive(:one_service?).with(/ruxit/, 'tenant', 'tenanttoken').and_return(true)
33+
end
34+
35+
it 'detects with ruxit-n/a service' do
36+
expect(component.detect).to eq("ruxit-agent=#{version}")
37+
end
38+
39+
it 'downloads Ruxit agent zip',
40+
cache_fixture: 'stub-ruxit-agent.zip' do
41+
42+
component.compile
43+
44+
expect(sandbox + 'agent/lib64/libruxitagentloader.so').to exist
45+
end
46+
47+
it 'updates JAVA_OPTS' do
48+
allow(services).to receive(:find_service).and_return('credentials' => { 'tenant' => 'test-tenant',
49+
'tenanttoken' => 'test-token' })
50+
component.release
51+
52+
expect(java_opts).to include('-agentpath:$PWD/.java-buildpack/ruxit_agent/agent/lib64/libruxitagentloader.so=' \
53+
'server=https://test-tenant.live.ruxit.com:443/communication,tenant=test-tenant,tenanttoken=test-token')
54+
end
55+
56+
it 'updates JAVA_OPTS with custom server' do
57+
allow(services).to receive(:find_service).and_return('credentials' => { 'server' => 'test-server',
58+
'tenant' => 'test-tenant',
59+
'tenanttoken' => 'test-token' })
60+
component.release
61+
62+
expect(java_opts).to include('-agentpath:$PWD/.java-buildpack/ruxit_agent/agent/lib64/libruxitagentloader.so=' \
63+
'server=test-server,tenant=test-tenant,tenanttoken=test-token')
64+
end
65+
66+
it 'updates environment variables' do
67+
allow(services).to receive(:find_service).and_return('credentials' => { 'tenant' => 'test-tenant',
68+
'tenanttoken' => 'test-token' })
69+
component.release
70+
71+
expect(environment_variables).to include('RUXIT_APPLICATIONID=test-application-name')
72+
expect(environment_variables).to include('RUXIT_CLUSTER_ID=test-application-name')
73+
expect(environment_variables).to include('RUXIT_HOST_ID=test-application-name_${CF_INSTANCE_INDEX}')
74+
end
75+
76+
context do
77+
78+
let(:environment) do
79+
{ 'RUXIT_APPLICATIONID' => 'test-application-id',
80+
'RUXIT_CLUSTER_ID' => 'test-cluster-id',
81+
'RUXIT_HOST_ID' => 'test-host-id' }
82+
end
83+
84+
it 'does not update environment variables if they exist', :show_output do
85+
allow(services).to receive(:find_service).and_return('credentials' => { 'tenant' => 'test-tenant',
86+
'tenanttoken' => 'test-token' })
87+
component.release
88+
89+
expect(environment_variables).not_to include(/RUXIT_APPLICATIONID/)
90+
expect(environment_variables).not_to include(/RUXIT_CLUSTER_ID/)
91+
expect(environment_variables).not_to include(/RUXIT_HOST_ID/)
92+
end
93+
94+
end
95+
96+
end
97+
98+
end

0 commit comments

Comments
 (0)