Skip to content

Commit

Permalink
Fix AntFixture configuration cache compatibility
Browse files Browse the repository at this point in the history
We need to resolve the address and port from a fixture as ValueSource
  • Loading branch information
breskeby committed Nov 16, 2024
1 parent 6e4b8a7 commit a2871e3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ import org.elasticsearch.gradle.OS

import org.elasticsearch.gradle.internal.AntFixtureStop
import org.elasticsearch.gradle.internal.AntTask
import org.elasticsearch.gradle.testclusters.TestClusterInfo
import org.elasticsearch.gradle.testclusters.TestClusterValueSource
import org.elasticsearch.gradle.testclusters.TestClustersRegistry
import org.gradle.api.GradleException
import org.gradle.api.file.ProjectLayout
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory
import org.gradle.api.provider.ValueSource
import org.gradle.api.provider.ValueSourceParameters
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskProvider

Expand Down Expand Up @@ -290,4 +297,22 @@ class AntFixture extends AntTask {
protected File getRunLog() {
return new File(cwd, 'run.log')
}

@Internal
Provider<AntFixtureValueSource> getAddressAndPortSource() {
return providerFactory.of(AntFixtureValueSource.class, spec -> {
spec.getParameters().getPortFile().set(portsFile);
});
}

static abstract class AntFixtureValueSource implements ValueSource<String, AntFixtureValueSource.Parameters> {
@Override
String obtain() {
return getParameters().getPortFile().map { it.readLines("UTF-8").get(0) }.get()
}

interface Parameters extends ValueSourceParameters {
Property<File> getPortFile();
}
}
}
29 changes: 18 additions & 11 deletions plugins/discovery-ec2/qa/amazon-ec2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ tasks.named("yamlRestTest").configure { enabled = false }
dependsOn project.sourceSets.yamlRestTest.runtimeClasspath
FileCollection cp = project.sourceSets.yamlRestTest.runtimeClasspath
env 'CLASSPATH', "${-> cp.asPath}"
executable = "${buildParams.runtimeJavaHome}/bin/java"
executable = "${buildParams.runtimeJavaHome.get() }/bin/java"
args 'org.elasticsearch.discovery.ec2.AmazonEC2Fixture', baseDir, "${buildDir}/testclusters/yamlRestTest${action}-1/config/unicast_hosts.txt"
}

Expand All @@ -68,21 +68,28 @@ tasks.named("yamlRestTest").configure { enabled = false }
classpath = yamlRestTestSourceSet.getRuntimeClasspath()
}

if(action == 'ContainerCredentials') {
def addressAndPortSource = fixture.get().addressAndPortSource
testClusters.matching { it.name == "yamlRestTestContainerCredentials" }.configureEach {
environment 'AWS_CONTAINER_CREDENTIALS_FULL_URI',
() -> addressAndPortSource.map{ addr -> "http://${addr}/ecs_credentials_endpoint" }.get(), IGNORE_VALUE
}
}

tasks.named("check").configure {
dependsOn(yamlRestTestTask)
}

Provider<String> addressAndPort = fixture.get().addressAndPortProvider
def addressAndPortSource = fixture.get().addressAndPortSource

testClusters.matching { it.name == yamlRestTestTask.name}.configureEach {
numberOfNodes = ec2NumberOfNodes
plugin ':plugins:discovery-ec2'

setting 'discovery.seed_providers', 'ec2'
setting 'network.host', '_ec2_'
setting 'discovery.ec2.endpoint', { "http://${-> addressAndPort.get()}" }, IGNORE_VALUE
setting 'discovery.ec2.endpoint', { "http://${-> addressAndPortSource.get()}" }, IGNORE_VALUE
systemProperty "com.amazonaws.sdk.ec2MetadataServiceEndpointOverride", { "http://${-> addressAndPort.get() }" }, IGNORE_VALUE
systemProperty "com.amazonaws.sdk.ec2MetadataServiceEndpointOverride", { "http://${-> addressAndPortSource.get()}" }, IGNORE_VALUE
}
}

Expand All @@ -108,12 +115,12 @@ testClusters.matching { it.name == "yamlRestTestSystemProperties" }.configureEac
tasks.named("ec2FixtureContainerCredentials").configure {
env 'ACTIVATE_CONTAINER_CREDENTIALS', true
}

def someProvider = tasks.findByName("ec2FixtureContainerCredentials").addressAndPortProvider
testClusters.matching { it.name == "yamlRestTestContainerCredentials" }.configureEach {
environment 'AWS_CONTAINER_CREDENTIALS_FULL_URI',
{ "http://${-> someProvider.get()}/ecs_credentials_endpoint" }, IGNORE_VALUE
}
//
//def addressAndPortProvider = tasks.findByName("ec2FixtureContainerCredentials").addressAndPortProvider
//testClusters.matching { it.name == "yamlRestTestContainerCredentials" }.configureEach {
// environment 'AWS_CONTAINER_CREDENTIALS_FULL_URI',
// { "http://${-> addressAndPortProvider.get()}/ecs_credentials_endpoint" }, IGNORE_VALUE
//}

// Extra config for InstanceProfile
tasks.named("ec2FixtureInstanceProfile").configure {
Expand Down

0 comments on commit a2871e3

Please sign in to comment.