Skip to content

Commit b533b6c

Browse files
committed
Debug Framework
This change adds a framework that contributes Java debug configuration to an application. Note that this is only useful in Diego-based containers with SSH access enabled. [#105552412]
1 parent 955a77e commit b533b6c

File tree

7 files changed

+182
-5
lines changed

7 files changed

+182
-5
lines changed

.idea/dictionaries/bhale.xml

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

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ $ cf set-env my-application JBP_CONFIG_JAVA_MAIN '{arguments: "-server.port=\$PO
4848
Environment variable can also be specified in the applications `manifest` file. For example, to specify an environment variable in an applications manifest file that disables Auto-reconfiguration.
4949

5050
```bash
51-
env:
51+
env:
5252
JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: false}'
5353
```
5454

5555
This final example shows how to change the version of Tomcat that is used by the buildpack with an environment variable specified in the applications manifest file.
5656

5757
```bash
58-
env:
58+
env:
5959
JBP_CONFIG_TOMCAT: '{tomcat: { version: 8.0.+ }}'
6060
```
6161

@@ -77,8 +77,9 @@ To learn how to configure various properties of the buildpack, follow the "Confi
7777
* [Tomcat](docs/container-tomcat.md) ([Configuration](docs/container-tomcat.md#configuration))
7878
* Standard Frameworks
7979
* [AppDynamics Agent](docs/framework-app_dynamics_agent.md) ([Configuration](docs/framework-app_dynamics_agent.md#configuration))
80-
* [Introscope Agent](docs/framework-introscope_agent.md) ([Configuration](docs/framework-introscope_agent.md#configuration))
80+
* [Debug](docs/framework-debug.md) ([Configuration](docs/debug.md#configuration))
8181
* [DynaTrace Agent](docs/framework-dyna_trace_agent.md) ([Configuration](docs/framework-dyna_trace_agent.md#configuration))
82+
* [Introscope Agent](docs/framework-introscope_agent.md) ([Configuration](docs/framework-introscope_agent.md#configuration))
8283
* [Java Options](docs/framework-java_opts.md) ([Configuration](docs/framework-java_opts.md#configuration))
8384
* [JRebel Agent](docs/framework-jrebel_agent.md) ([Configuration](docs/framework-jrebel_agent.md#configuration))
8485
* [Luna Security Provider](docs/framework-luna_security_provider.md) ([Configuration](docs/framework-luna_security_provider.md#configuration))
@@ -174,4 +175,4 @@ This buildpack is released under version 2.0 of the [Apache License][].
174175
[Pull requests]: http://help.github.com/send-pull-requests
175176
[Running Cloud Foundry locally]: http://docs.cloudfoundry.org/deploying/run-local.html
176177
[Spring Boot]: http://projects.spring.io/spring-boot/
177-
[Wikipedia]: https://en.wikipedia.org/wiki/YAML#Basic_components_of_YAML
178+
[Wikipedia]: https://en.wikipedia.org/wiki/YAML#Basic_components_of_YAML

config/components.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ jres:
3636

3737
frameworks:
3838
- "JavaBuildpack::Framework::AppDynamicsAgent"
39-
# - "JavaBuildpack::Framework::IntroscopeAgent"
39+
- "JavaBuildpack::Framework::Debug"
4040
# - "JavaBuildpack::Framework::DynaTraceAgent"
41+
# - "JavaBuildpack::Framework::IntroscopeAgent"
4142
- "JavaBuildpack::Framework::JrebelAgent"
4243
# - "JavaBuildpack::Framework::LunaSecurityProvider"
4344
- "JavaBuildpack::Framework::MariaDbJDBC"

config/debug.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2014-2015 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+
# Debug configuration
17+
---
18+
enabled: false
19+
port: 8000
20+
suspend: false

docs/framework-debug.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Debug Framework
2+
The Debug Framework contributes Java debug configuration to the application at runtime. **Note:** This framework is only useful in Diego-based containers with SSH access enabled.
3+
4+
<table>
5+
<tr>
6+
<td><strong>Detection Criterion</strong></td>
7+
<td><tt>enabled</tt> set in the <tt>config/debug.yml</tt> file</td>
8+
</tr>
9+
<tr>
10+
<td><strong>Tags</strong></td>
11+
<td><tt>debug</tt></td>
12+
</tr>
13+
</table>
14+
Tags are printed to standard output by the buildpack detect script
15+
16+
## Configuration
17+
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][].
18+
19+
The framework can be configured by creating or modifying the [`config/debug.yml`][] file in the buildpack fork.
20+
21+
| Name | Description
22+
| ---- | -----------
23+
| `enabled` | Whether to enable Java debuging
24+
| `port` | The port that the debug agent will listen on
25+
| `suspend` | Whether to suspend execution until a debugger has attached. Note, enabling this may cause application start to timeout and be restarted.
26+
27+
[`config/debug.yml`]: ../config/debug.yml
28+
[Configuration and Extension]: ../README.md#configuration-and-extension
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Encoding: utf-8
2+
# Cloud Foundry Java Buildpack
3+
# Copyright 2013-2015 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 'java_buildpack/component/base_component'
18+
require 'java_buildpack/framework'
19+
require 'java_buildpack/util/dash_case'
20+
21+
module JavaBuildpack
22+
module Framework
23+
24+
# Encapsulates the functionality for contributing Java debug options to an application.
25+
class Debug < JavaBuildpack::Component::BaseComponent
26+
27+
# (see JavaBuildpack::Component::BaseComponent#detect)
28+
def detect
29+
enabled? ? Debug.to_s.dash_case : nil
30+
end
31+
32+
# (see JavaBuildpack::Component::BaseComponent#compile)
33+
def compile
34+
end
35+
36+
# (see JavaBuildpack::Component::BaseComponent#release)
37+
def release
38+
@droplet.java_opts.add_preformatted_options debug
39+
end
40+
41+
private
42+
43+
def debug
44+
"-agentlib:jdwp=transport=dt_socket,server=y,address=#{port},suspend=#{suspend}"
45+
end
46+
47+
def enabled?
48+
@configuration['enabled']
49+
end
50+
51+
def port
52+
@configuration['port'] || 8000
53+
end
54+
55+
def suspend
56+
@configuration['suspend'] ? 'y' : 'n'
57+
end
58+
59+
end
60+
61+
end
62+
end
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Encoding: utf-8
2+
# Cloud Foundry Java Buildpack
3+
# Copyright 2013-2015 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/debug'
20+
21+
describe JavaBuildpack::Framework::Debug do
22+
include_context 'component_helper'
23+
24+
it 'does not detect if not enabled' do
25+
expect(component.detect).to be_nil
26+
end
27+
28+
context do
29+
let(:configuration) { { 'enabled' => true } }
30+
31+
it 'detects when enabled' do
32+
expect(component.detect).to eq('debug')
33+
end
34+
35+
it 'uses 8000 as the default port' do
36+
component.release
37+
expect(java_opts).to include('-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n')
38+
end
39+
40+
it 'does not suspend by default' do
41+
component.release
42+
expect(java_opts).to include('-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n')
43+
end
44+
end
45+
46+
context do
47+
let(:configuration) { { 'enabled' => true, 'port' => 8001 } }
48+
49+
it 'uses configured port' do
50+
component.release
51+
expect(java_opts).to include('-agentlib:jdwp=transport=dt_socket,server=y,address=8001,suspend=n')
52+
end
53+
end
54+
55+
context do
56+
let(:configuration) { { 'enabled' => true, 'suspend' => true } }
57+
58+
it 'uses configured suspend' do
59+
component.release
60+
expect(java_opts).to include('-agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=y')
61+
end
62+
end
63+
64+
end

0 commit comments

Comments
 (0)