Skip to content

Commit d8661d6

Browse files
authored
Merge branch '9.0' into backport/9.0/pr-134506
2 parents ab2b6a7 + 55c0a28 commit d8661d6

File tree

5 files changed

+83
-5
lines changed

5 files changed

+83
-5
lines changed

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/VersionPropertiesBuildService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.Properties;
2323
import javax.inject.Inject;
2424

25-
abstract class VersionPropertiesBuildService implements BuildService<VersionPropertiesBuildService.Params>, AutoCloseable {
25+
public abstract class VersionPropertiesBuildService implements BuildService<VersionPropertiesBuildService.Params>, AutoCloseable {
2626

2727
private final Properties properties;
2828

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/transport/TransportVersionGenerationFuncTest.groovy

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,46 @@ class TransportVersionGenerationFuncTest extends AbstractTransportVersionFuncTes
443443
assertUpperBound("9.2", "new_tv,8124000")
444444
assertReferableDefinition("new_tv", "8124000")
445445
}
446+
447+
def "alternate upper bound larger"() {
448+
given:
449+
referencedTransportVersion("new_tv")
450+
file("myserver/alt_upper_bound.csv").text = "some_tv,8126000"
451+
file("myserver/build.gradle") << """
452+
tasks.named('generateTransportVersionDefinition') {
453+
alternateUpperBoundFile = project.file("alt_upper_bound.csv")
454+
}
455+
tasks.named('validateTransportVersionResources') {
456+
shouldValidateDensity = false
457+
}
458+
"""
459+
460+
when:
461+
def result = runGenerateAndValidateTask().build()
462+
then:
463+
assertGenerateAndValidateSuccess(result)
464+
assertUpperBound("9.2", "new_tv,8127000")
465+
assertReferableDefinition("new_tv", "8127000")
466+
}
467+
468+
def "alternate upper bound less"() {
469+
given:
470+
referencedTransportVersion("new_tv")
471+
file("myserver/alt_upper_bound.csv").text = "some_tv,8122100"
472+
file("myserver/build.gradle") << """
473+
tasks.named('generateTransportVersionDefinition') {
474+
alternateUpperBoundFile = project.file("alt_upper_bound.csv")
475+
}
476+
tasks.named('validateTransportVersionResources') {
477+
shouldValidateDensity = false
478+
}
479+
"""
480+
481+
when:
482+
def result = runGenerateAndValidateTask().build()
483+
then:
484+
assertGenerateAndValidateSuccess(result)
485+
assertUpperBound("9.2", "new_tv,8124000")
486+
assertReferableDefinition("new_tv", "8124000")
487+
}
446488
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/transport/GenerateTransportVersionDefinitionTask.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
import org.gradle.api.DefaultTask;
1313
import org.gradle.api.file.ConfigurableFileCollection;
14+
import org.gradle.api.file.RegularFileProperty;
1415
import org.gradle.api.provider.Property;
1516
import org.gradle.api.services.ServiceReference;
1617
import org.gradle.api.tasks.Input;
18+
import org.gradle.api.tasks.InputFile;
1719
import org.gradle.api.tasks.InputFiles;
1820
import org.gradle.api.tasks.Optional;
1921
import org.gradle.api.tasks.PathSensitive;
@@ -22,6 +24,9 @@
2224
import org.gradle.api.tasks.options.Option;
2325

2426
import java.io.IOException;
27+
import java.nio.charset.StandardCharsets;
28+
import java.nio.file.Files;
29+
import java.nio.file.Path;
2530
import java.util.ArrayList;
2631
import java.util.Collections;
2732
import java.util.HashSet;
@@ -74,6 +79,14 @@ public abstract class GenerateTransportVersionDefinitionTask extends DefaultTask
7479
@Input
7580
public abstract Property<String> getCurrentUpperBoundName();
7681

82+
/**
83+
* An additional upper bound file that will be consulted when generating a transport version.
84+
* The larger of this and the current upper bound will be used to create the new primary id.
85+
*/
86+
@InputFile
87+
@Optional
88+
public abstract RegularFileProperty getAlternateUpperBoundFile();
89+
7790
@TaskAction
7891
public void run() throws IOException {
7992
TransportVersionResourcesService resources = getResourceService().get();
@@ -119,7 +132,7 @@ private List<TransportVersionId> updateUpperBounds(
119132
if (targetId == null) {
120133
// Case: an id doesn't yet exist for this upper bound, so create one
121134
int targetIncrement = upperBoundName.equals(currentUpperBoundName) ? increment : 1;
122-
targetId = TransportVersionId.fromInt(existingUpperBound.definitionId().complete() + targetIncrement);
135+
targetId = createTargetId(existingUpperBound, targetIncrement);
123136
var newUpperBound = new TransportVersionUpperBound(upperBoundName, definitionName, targetId);
124137
resources.writeUpperBound(newUpperBound);
125138
}
@@ -237,4 +250,21 @@ private TransportVersionId maybeGetExistingId(
237250
return null; // no existing id for this upper bound
238251
}
239252

253+
private TransportVersionId createTargetId(TransportVersionUpperBound existingUpperBound, int increment) throws IOException {
254+
int currentId = existingUpperBound.definitionId().complete();
255+
256+
// allow for an alternate upper bound file to be consulted. This supports Serverless basing its
257+
// own transport version ids on the greater of server or serverless
258+
if (getAlternateUpperBoundFile().isPresent()) {
259+
Path altUpperBoundPath = getAlternateUpperBoundFile().get().getAsFile().toPath();
260+
String contents = Files.readString(altUpperBoundPath, StandardCharsets.UTF_8);
261+
var altUpperBound = TransportVersionUpperBound.fromString(altUpperBoundPath, contents);
262+
if (altUpperBound.definitionId().complete() > currentId) {
263+
currentId = altUpperBound.definitionId().complete();
264+
}
265+
}
266+
267+
return TransportVersionId.fromInt(currentId + increment);
268+
}
269+
240270
}

libs/entitlement/src/main/java/org/elasticsearch/entitlement/initialization/HardcodedEntitlements.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ private static List<Scope> createServerEntitlements(Path pidFile) {
114114
new FilesEntitlement(serverModuleFileDatas)
115115
)
116116
),
117-
new Scope("java.desktop", List.of(new LoadNativeLibrariesEntitlement())),
117+
new Scope(
118+
"java.desktop",
119+
List.of(
120+
new LoadNativeLibrariesEntitlement(),
121+
new ManageThreadsEntitlement() // For sun.java2d.Disposer. TODO: https://elasticco.atlassian.net/browse/ES-12888
122+
)
123+
),
118124
new Scope(
119125
"java.xml",
120126
List.of(

libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PolicyManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class PolicyManager {
5151
*/
5252
static final Logger generalLogger = LogManager.getLogger(PolicyManager.class);
5353

54-
static final Set<String> MODULES_EXCLUDED_FROM_SYSTEM_MODULES = Set.of("java.desktop", "java.xml");
54+
public static final Set<String> MODULES_EXCLUDED_FROM_SYSTEM_MODULES = Set.of("java.desktop", "java.xml");
5555

5656
/**
5757
* Identifies a particular entitlement {@link Scope} within a {@link Policy}.
@@ -91,7 +91,7 @@ public enum ComponentKind {
9191
* If this kind corresponds to a single component, this is that component's name;
9292
* otherwise null.
9393
*/
94-
final String componentName;
94+
public final String componentName;
9595

9696
ComponentKind(String componentName) {
9797
this.componentName = componentName;

0 commit comments

Comments
 (0)