Skip to content

Commit

Permalink
[distribution/archives] [Linux] [x64] Provide the variant of the dist…
Browse files Browse the repository at this point in the history
…ributions bundled with JRE (#8195)

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta committed Aug 1, 2023
1 parent 896573f commit a72c2cc
Show file tree
Hide file tree
Showing 21 changed files with 612 additions and 265 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Start replication checkpointTimers on primary before segments upload to remote store. ([#8221]()https://github.com/opensearch-project/OpenSearch/pull/8221)
- Introduce new static cluster setting to control slice computation for concurrent segment search. ([#8847](https://github.com/opensearch-project/OpenSearch/pull/8884))
- Add configuration for file cache size to max remote data ratio to prevent oversubscription of file cache ([#8606](https://github.com/opensearch-project/OpenSearch/pull/8606))
- [distribution/archives] [Linux] [x64] Provide the variant of the distributions bundled with JRE ([#8195]()https://github.com/opensearch-project/OpenSearch/pull/8195)

### Dependencies
- Bump `org.apache.logging.log4j:log4j-core` from 2.17.1 to 2.20.0 ([#8307](https://github.com/opensearch-project/OpenSearch/pull/8307))
Expand Down
5 changes: 4 additions & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ This repository is split into many top level directories. The most important one

### `distribution`

Builds our tar and zip archives and our rpm and deb packages.
Builds our tar and zip archives and our rpm and deb packages. There are several flavors of the distributions, with the classifier included in the name of the final deliverable (archive or package):
- default (no classifier), the distribution with bundled JDK
- `-no-jdk-` - the distribution without bundled JDK/JRE, assumes the JDK/JRE is going to be pre-installed on the target systems
- `-jre-` - the distribution bundled with JRE (smaller footprint), supported as experimental feature for some platforms

### `libs`

Expand Down
15 changes: 15 additions & 0 deletions buildSrc/src/main/java/org/opensearch/gradle/JavaPackageType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.gradle;

public enum JavaPackageType {
NONE,
JRE,
JDK
}
197 changes: 197 additions & 0 deletions buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.gradle;

import org.gradle.api.Buildable;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.TaskDependency;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

abstract class JavaVariant implements Buildable, Iterable<File> {

private static final List<String> ALLOWED_ARCHITECTURES = Collections.unmodifiableList(
Arrays.asList("aarch64", "x64", "s390x", "ppc64le")
);
private static final List<String> ALLOWED_VENDORS = Collections.unmodifiableList(Arrays.asList("adoptium", "adoptopenjdk", "openjdk"));
private static final List<String> ALLOWED_PLATFORMS = Collections.unmodifiableList(
Arrays.asList("darwin", "freebsd", "linux", "mac", "windows")
);
private static final Pattern VERSION_PATTERN = Pattern.compile("(\\d+)(\\.\\d+\\.\\d+)?\\+(\\d+(?:\\.\\d+)?)(@([a-f0-9]{32}))?");
private static final Pattern LEGACY_VERSION_PATTERN = Pattern.compile("(\\d)(u\\d+)(?:\\+|\\-)(b\\d+?)(@([a-f0-9]{32}))?");

private final String name;
private final Configuration configuration;

private final Property<String> vendor;
private final Property<String> version;
private final Property<String> platform;
private final Property<String> architecture;
private String baseVersion;
private String major;
private String build;
private String hash;

JavaVariant(String name, Configuration configuration, ObjectFactory objectFactory) {
this.name = name;
this.configuration = configuration;
this.vendor = objectFactory.property(String.class);
this.version = objectFactory.property(String.class);
this.platform = objectFactory.property(String.class);
this.architecture = objectFactory.property(String.class);
}

public String getName() {
return name;
}

public String getVendor() {
return vendor.get();

Check warning on line 63 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L63

Added line #L63 was not covered by tests
}

public void setVendor(final String vendor) {
if (ALLOWED_VENDORS.contains(vendor) == false) {
throw new IllegalArgumentException("unknown vendor [" + vendor + "] for jdk [" + name + "], must be one of " + ALLOWED_VENDORS);
}
this.vendor.set(vendor);
}

public String getVersion() {
return version.get();

Check warning on line 74 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L74

Added line #L74 was not covered by tests
}

public void setVersion(String version) {
if (VERSION_PATTERN.matcher(version).matches() == false && LEGACY_VERSION_PATTERN.matcher(version).matches() == false) {
throw new IllegalArgumentException("malformed version [" + version + "] for jdk [" + name + "]");
}
parseVersion(version);
this.version.set(version);
}

public String getPlatform() {
return platform.get();

Check warning on line 86 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L86

Added line #L86 was not covered by tests
}

public void setPlatform(String platform) {
if (ALLOWED_PLATFORMS.contains(platform) == false) {
throw new IllegalArgumentException(
"unknown platform [" + platform + "] for jdk [" + name + "], must be one of " + ALLOWED_PLATFORMS
);
}
this.platform.set(platform);
}

public String getArchitecture() {
return architecture.get();

Check warning on line 99 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L99

Added line #L99 was not covered by tests
}

public void setArchitecture(final String architecture) {
String jdkArchitecture = translateJdkArchitecture(architecture);
if (ALLOWED_ARCHITECTURES.contains(jdkArchitecture) == false) {
throw new IllegalArgumentException(
"unknown architecture [" + jdkArchitecture + "] for jdk [" + name + "], must be one of " + ALLOWED_ARCHITECTURES
);
}
this.architecture.set(jdkArchitecture);
}

public String getBaseVersion() {
return baseVersion;

Check warning on line 113 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L113

Added line #L113 was not covered by tests
}

public String getMajor() {
return major;

Check warning on line 117 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L117

Added line #L117 was not covered by tests
}

public String getBuild() {
return build;

Check warning on line 121 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L121

Added line #L121 was not covered by tests
}

public String getHash() {
return hash;

Check warning on line 125 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L125

Added line #L125 was not covered by tests
}

public String getPath() {
return configuration.getSingleFile().toString();

Check warning on line 129 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L129

Added line #L129 was not covered by tests
}

public String getConfigurationName() {
return configuration.getName();

Check warning on line 133 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L133

Added line #L133 was not covered by tests
}

@Override
public String toString() {
return getPath();

Check warning on line 138 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L138

Added line #L138 was not covered by tests
}

@Override
public TaskDependency getBuildDependencies() {
return configuration.getBuildDependencies();

Check warning on line 143 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L143

Added line #L143 was not covered by tests
}

// internal, make this jdks configuration unmodifiable
void finalizeValues() {
if (version.isPresent() == false) {
throw new IllegalArgumentException("version not specified for jdk [" + name + "]");
}
if (platform.isPresent() == false) {
throw new IllegalArgumentException("platform not specified for jdk [" + name + "]");
}
if (vendor.isPresent() == false) {
throw new IllegalArgumentException("vendor not specified for jdk [" + name + "]");
}
if (architecture.isPresent() == false) {
throw new IllegalArgumentException("architecture not specified for jdk [" + name + "]");
}
version.finalizeValue();
platform.finalizeValue();
vendor.finalizeValue();
architecture.finalizeValue();
}

Check warning on line 164 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L160-L164

Added lines #L160 - L164 were not covered by tests

@Override
public Iterator<File> iterator() {
return configuration.iterator();

Check warning on line 168 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L168

Added line #L168 was not covered by tests
}

private void parseVersion(String version) {
// decompose the bundled jdk version, broken into elements as: [feature, interim, update, build]
// Note the "patch" version is not yet handled here, as it has not yet been used by java.
Matcher jdkVersionMatcher = VERSION_PATTERN.matcher(version);
if (jdkVersionMatcher.matches() == false) {
// Try again with the pre-Java9 version format
jdkVersionMatcher = LEGACY_VERSION_PATTERN.matcher(version);

if (jdkVersionMatcher.matches() == false) {
throw new IllegalArgumentException("Malformed jdk version [" + version + "]");

Check warning on line 180 in buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java

View check run for this annotation

Codecov / codecov/patch

buildSrc/src/main/java/org/opensearch/gradle/JavaVariant.java#L180

Added line #L180 was not covered by tests
}
}

baseVersion = jdkVersionMatcher.group(1) + (jdkVersionMatcher.group(2) != null ? (jdkVersionMatcher.group(2)) : "");
major = jdkVersionMatcher.group(1);
build = jdkVersionMatcher.group(3);
hash = jdkVersionMatcher.group(5);
}

private String translateJdkArchitecture(String architecture) {
/*
* Jdk uses aarch64 from ARM. Translating from arm64 to aarch64 which Jdk understands.
*/
return "arm64".equals(architecture) ? "aarch64" : architecture;
}

}
Loading

0 comments on commit a72c2cc

Please sign in to comment.