Skip to content

Commit 0ea003c

Browse files
authored
Add Azul Platform Prime to java-buildpack (#954)
* <change synopsis here> <change description here> Bug: n/a Reviewed-By: n/a Tests-Run: n/a modified: README.md modified: config/components.yml new file: config/zing_jre.yml new file: docs/jre-zing_jre.md new file: lib/java_buildpack/jre/zing_jre.rb * modified: config/zing_jre.yml modified: docs/jre-zing_jre.md * Removing installing Java kill agent and memory calculator modified: open_jdk_like.rb * Changes for Zing modified: ../../../lib/java_buildpack/jre/zing_jre.rb * Update zing_jre.rb * Remove changes from open_jdk_like.rb, Updating docs for Azul Prime JRE and some minor changes modified: docs/jre-zing_jre.md modified: lib/java_buildpack/jre/open_jdk_like.rb modified: lib/java_buildpack/jre/zing_jre.rb * Remove changes from open_jdk_like.rb and some minor changes to zing_jre.rb modified: lib/java_buildpack/jre/open_jdk_like.rb modified: lib/java_buildpack/jre/zing_jre.rb
1 parent e6cae92 commit 0ea003c

File tree

5 files changed

+226
-0
lines changed

5 files changed

+226
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ The buildpack supports extension through the use of Git repository forking. The
115115
* [YourKit Profiler](docs/framework-your_kit_profiler.md) ([Configuration](docs/framework-your_kit_profiler.md#configuration))
116116
* Standard JREs
117117
* [Azul Zulu](docs/jre-zulu_jre.md) ([Configuration](docs/jre-zulu_jre.md#configuration))
118+
* [Azul Platform Prime](docs/jre-zing_jre.md) ([Configuration](docs/jre-zing_jre.md#configuration))
118119
* [GraalVM](docs/jre-graal_vm_jre.md) ([Configuration](docs/jre-graal_vm_jre.md#configuration))
119120
* [IBM® SDK, Java™ Technology Edition](docs/jre-ibm_jre.md) ([Configuration](docs/jre-ibm_jre.md#configuration))
120121
* [OpenJDK](docs/jre-open_jdk_jre.md) ([Configuration](docs/jre-open_jdk_jre.md#configuration))

config/components.yml

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jres:
3434
- "JavaBuildpack::Jre::OpenJdkJRE"
3535
# - "JavaBuildpack::Jre::OracleJRE"
3636
# - "JavaBuildpack::Jre::ZuluJRE"
37+
# - "JavaBuildpack::Jre::ZingJRE"
3738
# - "JavaBuildpack::Jre::SapMachineJRE"
3839

3940
# Frameworks are processed in order.

config/zing_jre.yml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2013-2020 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 JRE repositories keyed by vendor
17+
# Pre Java 1.8, permgen was used instead of metaspace. Please see the documentation for more detail.
18+
19+
# You must specify a the repository root of a Azul Platform Prime JRE repository. Please see the documentation for more detail.
20+
# e.g. repository_root: "https://example.com/zing-jre/{platform}/{architecture}"
21+
---
22+
jre:
23+
version: 1.8.0_+
24+
repository_root: ""
25+
jvmkill_agent:
26+
version: 1.+
27+
repository_root: "{default.repository.root}/jvmkill/{platform}/{architecture}"
28+
memory_calculator:
29+
version: 3.+
30+
repository_root: "{default.repository.root}/memory-calculator/{platform}/{architecture}"
31+
class_count:
32+
headroom:
33+
stack_threads: 250

docs/jre-zing_jre.md

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Azul Platform Prime JRE
2+
Azul Platform Prime JRE provides Java runtimes developed by Azul. No versions of the JRE are available by default due to licensing restrictions. Instead you will need to create a repository with the Prime JREs in it and configure the buildpack to use that repository. Unless otherwise configured, the version of Java that will be used is specified in [`config/zing_jre.yml`][].
3+
4+
<table>
5+
<tr>
6+
<td><strong>Detection Criterion</strong></td>
7+
<td>Unconditional. Existence of a single bound Volume Service will result in Terminal heap dumps being written.
8+
<ul>
9+
<li>Existence of a Volume Service 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>heap-dump</code> as a substring.</li>
10+
</ul>
11+
</td>
12+
</tr>
13+
<tr>
14+
<td><strong>Tags</strong></td>
15+
<td><tt>open-jdk-like-jre=&lang;version&rang;, open-jdk-like-memory-calculator=&lang;version&rang;, jvmkill=&lang;version&rang;</tt></td>
16+
</tr>
17+
</table>
18+
Tags are printed to standard output by the buildpack detect script.
19+
20+
21+
## Configuration
22+
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][].
23+
24+
The JRE can be configured by modifying the [`config/zing_jre.yml`][] file in the buildpack fork. The JRE uses the [`Repository` utility support][repositories] and so, it supports the [version syntax][] defined there.
25+
26+
To use Azul Platform Prime JRE instead of OpenJDK without forking java-buildpack, set environment variable and restage:
27+
28+
```bash
29+
cf set-env <app_name> JBP_CONFIG_COMPONENTS '{jres: ["JavaBuildpack::Jre::ZingJRE"]}'
30+
cf set-env <app_name> JBP_CONFIG_ZING_JRE '{ jre: { repository_root: "<INTERNAL_REPOSITORY_URI>" } }'
31+
cf restage <app_name>
32+
```
33+
34+
| Name | Description
35+
| ---- | -----------
36+
| `jre.repository_root` | The URL of the Azul Platform Prime repository index ([details][repositories]).
37+
| `jre.version` | The version of Java runtime to use. Note: version 1.8.0 and higher require the `memory_sizes` and `memory_heuristics` mappings to specify `metaspace` rather than `permgen`.
38+
| `jvmkill.repository_root` | The URL of the `jvmkill` repository index ([details][repositories]).
39+
| `jvmkill.version` | The version of `jvmkill` to use. Candidate versions can be found in the listings for [bionic][jvmkill-bionic].
40+
| `memory_calculator` | Memory calculator defaults, described below under "Memory".
41+
42+
### Additional Resources
43+
The JRE can also be configured by overlaying a set of resources on the default distribution. To do this, add files to the `resources/zing_jre` directory in the buildpack fork.
44+
45+
#### JCE Unlimited Strength
46+
To add the JCE Unlimited Strength `local_policy.jar`, add your file to `resources/zing_jre/lib/security/local_policy.jar`. This file will be overlayed onto the Azul Platform Prime distribution.
47+
48+
#### Custom CA Certificates
49+
To add custom SSL certificates, add your `cacerts` file to `resources/zing_jre/lib/security/cacerts`. This file will be overlayed onto the Azul Platform Prime distribution.
50+
51+
### `jvmkill`
52+
Azul Platform Prime JRE does not use the jvmkill agent instead by default uses the -XX:ExitOnOutOfMemoryError flag which terminates the JVM process when an out-of-memory error occurs.
53+
54+
If a [Volume Service][] with the string `heap-dump` in its name or tag is bound to the application, terminal heap dumps will be written with the pattern `<CONTAINER_DIR>/<SPACE_NAME>-<SPACE_ID[0,8]>/<APPLICATION_NAME>-<APPLICATION_ID[0,8]>/<INSTANCE_INDEX>-<TIMESTAMP>-<INSTANCE_ID[0,8]>.hprof`
55+
56+
```plain
57+
Heapdump written to /var/vcap/data/9ae0b817-1446-4915-9990-74c1bb26f147/pcfdev-space-e91c5c39/java-main-application-892f20ab/0-2017-06-13T18:31:29+0000-7b23124e.hprof
58+
```
59+
60+
### Memory
61+
The total available memory for the application's container is specified when an application is pushed.
62+
The Java buildpack uses this value to control the JRE's use of various
63+
regions of memory and logs the JRE memory settings when the application starts or restarts.
64+
These settings can be influenced by configuring
65+
the `stack_threads` and/or `class_count` mappings (both part of the `memory_calculator` mapping),
66+
and/or Java options relating to memory.
67+
68+
Note: If the total available memory is scaled up or down, the Java buildpack will re-calculate the JRE memory settings the next time the application is started.
69+
70+
#### Total Memory
71+
72+
The user can change the container's total memory available to influence the JRE memory settings.
73+
Unless the user specifies the heap size Java option (`-Xmx`), increasing or decreasing the total memory
74+
available results in the heap size setting increasing or decreasing by a corresponding amount.
75+
76+
#### Loaded Classes
77+
78+
The amount of memory that is allocated to metaspace and compressed class space (or, on Java 7, the permanent generation) is calculated from an estimate of the number of classes that will be loaded. The default behaviour is to estimate the number of loaded classes as a fraction of the number of class files in the application.
79+
If a specific number of loaded classes should be used for calculations, then it should be specified as in the following example:
80+
81+
```yaml
82+
class_count: 500
83+
```
84+
85+
#### Headroom
86+
87+
A percentage of the total memory allocated to the container to be left as headroom and excluded from the memory calculation.
88+
89+
```yaml
90+
headroom: 10
91+
```
92+
93+
#### Stack Threads
94+
95+
The amount of memory that should be allocated to stacks is given as an amount of memory per thread with the Java option `-Xss`. If an explicit number of threads should be used for the calculation of stack memory, then it should be specified as in the following example:
96+
97+
```yaml
98+
stack_threads: 500
99+
```
100+
101+
Note that the default value of 250 threads is optimized for a default Tomcat configuration. If you are using another container, especially something non-blocking like Netty, it's more appropriate to use a significantly smaller value. Typically 25 threads would cover the needs of both the server (Netty) and the threads started by the JVM itself.
102+
103+
#### Java Options
104+
105+
If the JRE memory settings need to be fine-tuned, the user can set one or more Java memory options to
106+
specific values. The heap size can be set explicitly, but changing the value of options other
107+
than the heap size can also affect the heap size. For example, if the user increases
108+
the maximum direct memory size from its default value of 10 Mb to 20 Mb, then this will
109+
reduce the calculated heap size by 10 Mb.
110+
111+
#### Memory Calculation
112+
Memory calculation happens before every `start` of an application and is performed by an external program, the [Java Buildpack Memory Calculator]. There is no need to `restage` an application after scaling the memory as restarting will cause the memory settings to be recalculated.
113+
114+
The container's total available memory is allocated into heap, metaspace and compressed class space (or permanent generation for Java 7),
115+
direct memory, and stack memory settings.
116+
117+
The memory calculation is described in more detail in the [Memory Calculator's README].
118+
119+
The inputs to the memory calculation, except the container's total memory (which is unknown at staging time), are logged during staging, for example:
120+
```
121+
Loaded Classes: 13974, Threads: 300, JAVA_OPTS: ''
122+
```
123+
124+
The container's total memory is logged during `cf push` and `cf scale`, for example:
125+
```
126+
state since cpu memory disk details
127+
#0 running 2017-04-10 02:20:03 PM 0.0% 896K of 1G 1.3M of 1G
128+
```
129+
130+
The JRE memory settings are logged when the application is started or re-started, for example:
131+
```
132+
JVM Memory Configuration: -XX:MaxDirectMemorySize=10M -XX:MaxMetaspaceSize=99199K \
133+
-XX:ReservedCodeCacheSize=240M -XX:CompressedClassSpaceSize=18134K -Xss1M -Xmx368042K
134+
```
135+
136+
[`config/components.yml`]: ../config/components.yml
137+
[`config/zing_jre.yml`]: ../config/zing_jre.yml
138+
[Azul Platform Prime]: https://www.azul.com/products/prime/
139+
[Configuration and Extension]: ../README.md#configuration-and-extension
140+
[Java Buildpack Memory Calculator]: https://github.com/cloudfoundry/java-buildpack-memory-calculator
141+
[jvmkill-bionic]: https://java-buildpack.cloudfoundry.org/jvmkill/bionic/x86_64/index.yml
142+
[Memory Calculator's README]: https://github.com/cloudfoundry/java-buildpack-memory-calculator
143+
[repositories]: extending-repositories.md
144+
[version syntax]: extending-repositories.md#version-syntax-and-ordering
145+
[Volume Service]: https://docs.cloudfoundry.org/devguide/services/using-vol-services.html
146+
[Azul Platform Prime JRE]: jre-zing_jre.md

lib/java_buildpack/jre/zing_jre.rb

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
# Cloud Foundry Java Buildpack
4+
# Copyright 2013-2020 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
require 'fileutils'
19+
require 'java_buildpack/jre'
20+
require 'java_buildpack/jre/open_jdk_like'
21+
22+
module JavaBuildpack
23+
module Jre
24+
25+
# Encapsulates the detect, compile, and release functionality for selecting an Azul Platform Prime JRE.
26+
class ZingJRE < OpenJDKLike
27+
def command
28+
""
29+
end
30+
31+
def sub_components(context)
32+
[
33+
OpenJDKLikeJre.new(sub_configuration_context(context, 'jre')
34+
.merge(component_name: self.class.to_s.space_case)),
35+
OpenJDKLikeSecurityProviders.new(context)
36+
]
37+
end
38+
39+
def release
40+
super
41+
@droplet.add_preformatted_options "-XX:+ExitOnOutOfMemoryError"
42+
end
43+
end
44+
end
45+
end

0 commit comments

Comments
 (0)