-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add initial transport version generation task #134333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
848aa5b
Add initial transport version generation task
rjernst 08a64f0
update from feedback
rjernst 623e5a2
[CI] Auto commit changes from spotless
45d5478
fix test
rjernst 4118497
cleanup
rjernst 387e3f9
Merge branch 'main' into transport/generate-initial
rjernst 5937b16
remove printout
rjernst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...rg/elasticsearch/gradle/internal/transport/GenerateInitialTransportVersionFuncTest.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.gradle.internal.transport | ||
|
||
import org.gradle.testkit.runner.BuildResult | ||
import org.gradle.testkit.runner.TaskOutcome | ||
|
||
class GenerateInitialTransportVersionFuncTest extends AbstractTransportVersionFuncTest { | ||
def runGenerateAndValidateTask(String... additionalArgs) { | ||
List<String> args = new ArrayList<>() | ||
args.add(":myserver:validateTransportVersionResources") | ||
args.add(":myserver:generateInitialTransportVersion") | ||
args.addAll(additionalArgs); | ||
return gradleRunner(args.toArray()) | ||
} | ||
|
||
def runGenerateTask(String... additionalArgs) { | ||
List<String> args = new ArrayList<>() | ||
args.add(":myserver:generateInitialTransportVersion") | ||
args.addAll(additionalArgs); | ||
return gradleRunner(args.toArray()) | ||
} | ||
|
||
void assertGenerateSuccess(BuildResult result) { | ||
assert result.task(":myserver:generateInitialTransportVersion").outcome == TaskOutcome.SUCCESS | ||
} | ||
|
||
void assertGenerateFailure(BuildResult result, String expectedOutput) { | ||
assert result.task(":myserver:generateInitialTransportVersion").outcome == TaskOutcome.FAILED | ||
assertOutputContains(result.output, expectedOutput) | ||
} | ||
|
||
void assertValidateSuccess(BuildResult result) { | ||
assert result.task(":myserver:validateTransportVersionResources").outcome == TaskOutcome.SUCCESS | ||
} | ||
|
||
void assertGenerateAndValidateSuccess(BuildResult result) { | ||
assertGenerateSuccess(result) | ||
assertValidateSuccess(result) | ||
} | ||
|
||
def "setup is valid"() { | ||
when: | ||
def result = runGenerateAndValidateTask("--release-version", "9.0.0").build() | ||
|
||
then: | ||
assertGenerateAndValidateSuccess(result) | ||
// should have been idempotent, nothing actually changed | ||
assertNoChanges(); | ||
} | ||
|
||
def "new minor also creates next upper bound"() { | ||
given: | ||
// version properties will be updated by release automation before running initial version generation | ||
versionPropertiesFile.text = versionPropertiesFile.text.replace("9.2.0", "9.3.0") | ||
|
||
when: | ||
System.out.println("Running generation initial task") | ||
def result = runGenerateAndValidateTask("--release-version", "9.2.0").build() | ||
System.out.println("Done running generation task") | ||
|
||
then: | ||
assertGenerateAndValidateSuccess(result) | ||
assertUnreferableDefinition("initial_9.2.0", "8124000") | ||
assertUpperBound("9.2", "initial_9.2.0,8124000") | ||
assertUpperBound("9.3", "initial_9.2.0,8124000") | ||
} | ||
|
||
def "patch updates existing upper bound"() { | ||
when: | ||
def result = runGenerateAndValidateTask("--release-version", "9.1.2").build() | ||
|
||
then: | ||
assertGenerateAndValidateSuccess(result) | ||
assertUnreferableDefinition("initial_9.1.2", "8012002") | ||
assertUpperBound("9.1", "initial_9.1.2,8012002") | ||
} | ||
|
||
def "cannot create upper bound file for patch"() { | ||
when: | ||
def result = runGenerateTask("--release-version", "9.3.7").buildAndFail() | ||
|
||
then: | ||
assertGenerateFailure(result, "Missing upper bound 9.3 for release version 9.3.7") | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...java/org/elasticsearch/gradle/internal/transport/GenerateInitialTransportVersionTask.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.gradle.internal.transport; | ||
|
||
import org.elasticsearch.gradle.Version; | ||
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.provider.Property; | ||
import org.gradle.api.services.ServiceReference; | ||
import org.gradle.api.tasks.Input; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.api.tasks.options.Option; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public abstract class GenerateInitialTransportVersionTask extends DefaultTask { | ||
|
||
@ServiceReference("transportVersionResources") | ||
abstract Property<TransportVersionResourcesService> getResourceService(); | ||
|
||
@Input | ||
@Option(option = "release-version", description = "The Elasticsearch release version this transport version will be associated with") | ||
public abstract Property<String> getReleaseVersion(); | ||
|
||
@Input | ||
abstract Property<Version> getCurrentVersion(); | ||
|
||
@TaskAction | ||
public void run() throws IOException { | ||
Version releaseVersion = Version.fromString(getReleaseVersion().get()); | ||
String upperBoundName = getUpperBoundName(releaseVersion); | ||
TransportVersionResourcesService resources = getResourceService().get(); | ||
TransportVersionUpperBound upstreamUpperBound = resources.getUpperBoundFromUpstream(upperBoundName); | ||
String initialDefinitionName = "initial_" + releaseVersion; | ||
TransportVersionDefinition existingDefinition = resources.getUnreferableDefinitionFromUpstream(initialDefinitionName); | ||
|
||
if (existingDefinition != null) { | ||
// this initial version has already been created upstream | ||
return; | ||
} | ||
|
||
if (upstreamUpperBound == null) { | ||
throw new RuntimeException("Missing upper bound " + upperBoundName + " for release version " + releaseVersion); | ||
} | ||
// minors increment by 1000 to create a unique base, patches increment by 1 as other patches do | ||
int increment = releaseVersion.getRevision() == 0 ? 1000 : 1; | ||
var id = TransportVersionId.fromInt(upstreamUpperBound.definitionId().complete() + increment); | ||
var definition = new TransportVersionDefinition(initialDefinitionName, List.of(id)); | ||
resources.writeUnreferableDefinition(definition); | ||
var newUpperBound = new TransportVersionUpperBound(upperBoundName, initialDefinitionName, id); | ||
resources.writeUpperBound(newUpperBound); | ||
|
||
if (releaseVersion.getRevision() == 0) { | ||
Version currentVersion = getCurrentVersion().get(); | ||
String currentUpperBoundName = getUpperBoundName(currentVersion); | ||
var currentUpperBound = new TransportVersionUpperBound(currentUpperBoundName, initialDefinitionName, id); | ||
resources.writeUpperBound(currentUpperBound); | ||
} | ||
} | ||
|
||
private String getUpperBoundName(Version version) { | ||
return version.getMajor() + "." + version.getMinor(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were going to use
VersionPropertiesBuildService
here?