mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(emr): use the cluster's regional private DNS domain for instances and the master (#5169)
* fix(emr): use the cluster's regional private DNS domain for instances and the master ListInstances built every synthetic instance's PrivateDnsName as ip-10-0-0-N.ec2.internal, the us-east-1 domain, in every region, while RunJobFlow set MasterPublicDnsName to <region>.compute.internal, which is wrong in us-east-1. Both now use the shared EC2 helper, so names end in ec2.internal in us-east-1 and <region>.compute.internal elsewhere, as EC2 itself does since #5033. * fix(emr): report the regional master DNS name for a cluster stored before the fix DescribeCluster returned the stored MasterPublicDnsName, so a us-east-1 cluster persisted before the previous commit kept reporting <region>.compute.internal after an upgrade. The name is now derived from the cluster's region when the response is built.
This commit is contained in:
1 parent
17c99047b9
commit
4115becdf2
4 files changed
+64
-6
No files matched your search
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.core.common.AwsEndpoints;
|
||||
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsJson11Controller;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegions;
|
||||
import io.github.hectorvent.floci.services.emr.model.EmrBlockPublicAccess;
|
||||
import io.github.hectorvent.floci.services.emr.model.EmrCluster;
|
||||
import io.github.hectorvent.floci.services.emr.model.EmrInstanceFleet;
|
||||
@@ -492,7 +493,7 @@ public class EmrHandler {
|
||||
}
|
||||
node.put("NormalizedInstanceHours", c.getNormalizedInstanceHours());
|
||||
if (c.getMasterPublicDnsName() != null) {
|
||||
node.put("MasterPublicDnsName", c.getMasterPublicDnsName());
|
||||
node.put("MasterPublicDnsName", EmrService.masterDnsName(c.getRegion()));
|
||||
}
|
||||
if (c.getAutoScalingRole() != null) {
|
||||
node.put("AutoScalingRole", c.getAutoScalingRole());
|
||||
@@ -628,8 +629,9 @@ public class EmrHandler {
|
||||
node.put("Id", "ci-" + index + cluster.getId());
|
||||
node.put("Ec2InstanceId", "i-" + String.format("%017d", index));
|
||||
node.put("PublicDnsName", AwsEndpoints.ec2PublicDns("203.0.113." + index, cluster.getRegion()));
|
||||
node.put("PrivateDnsName", "ip-10-0-0-" + index + ".ec2.internal");
|
||||
node.put("PrivateIpAddress", "10.0.0." + index);
|
||||
String privateIp = "10.0.0." + index;
|
||||
node.put("PrivateDnsName", AwsRegions.ec2PrivateIpDnsName(privateIp, cluster.getRegion()));
|
||||
node.put("PrivateIpAddress", privateIp);
|
||||
node.put("InstanceGroupId", group.getId());
|
||||
if (group.getMarket() != null) {
|
||||
node.put("Market", group.getMarket());
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegions;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -86,7 +87,7 @@ public class EmrService {
|
||||
cluster.setInstanceCollectionType(cluster.getInstanceFleets().isEmpty()
|
||||
? "INSTANCE_GROUP" : "INSTANCE_FLEET");
|
||||
cluster.setAutoTerminate(!cluster.isKeepJobFlowAliveWhenNoSteps());
|
||||
cluster.setMasterPublicDnsName("ip-10-0-0-1." + region + ".compute.internal");
|
||||
cluster.setMasterPublicDnsName(masterDnsName(region));
|
||||
cluster.setCreationDateTime(Instant.now());
|
||||
for (EmrInstanceGroup g : cluster.getInstanceGroups()) {
|
||||
g.setId("ig-" + randomId(13));
|
||||
@@ -108,6 +109,11 @@ public class EmrService {
|
||||
return cluster;
|
||||
}
|
||||
|
||||
/** The master node's private DNS name, derived from the region so a stored name never goes stale. */
|
||||
static String masterDnsName(String region) {
|
||||
return AwsRegions.ec2PrivateIpDnsName("10.0.0.1", region);
|
||||
}
|
||||
|
||||
public EmrCluster describeCluster(String id) {
|
||||
return requireCluster(id);
|
||||
}
|
||||
|
||||
+23
@@ -70,4 +70,27 @@ class EmrClusterRegionIntegrationTest {
|
||||
call(HOME, "TerminateJobFlows", "{\"JobFlowIds\":[\"" + clusterId + "\"]}")
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
// Catches: an instance's or the master's private DNS name in the wrong region's domain.
|
||||
@Test
|
||||
void listedInstancesUseTheClustersRegionalPrivateDnsDomain() {
|
||||
String clusterId = call(HOME, "RunJobFlow",
|
||||
"{\"Name\":\"region-dns\",\"ReleaseLabel\":\"emr-7.5.0\","
|
||||
+ "\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
|
||||
+ "\"InstanceGroups\":[{\"Name\":\"master\",\"InstanceRole\":\"MASTER\","
|
||||
+ "\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":1}]}}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("JobFlowId");
|
||||
|
||||
call(HOME, "ListInstances", "{\"ClusterId\":\"" + clusterId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("Instances[0].PrivateDnsName", equalTo("ip-10-0-0-1.eu-west-1.compute.internal"))
|
||||
.body("Instances[0].PrivateIpAddress", equalTo("10.0.0.1"));
|
||||
call(HOME, "DescribeCluster", "{\"ClusterId\":\"" + clusterId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("Cluster.MasterPublicDnsName", equalTo("ip-10-0-0-1.eu-west-1.compute.internal"));
|
||||
|
||||
call(HOME, "TerminateJobFlows", "{\"JobFlowIds\":[\"" + clusterId + "\"]}")
|
||||
.then().statusCode(200);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.emr;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.restassured.response.Response;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
@@ -10,6 +11,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
@@ -30,6 +32,9 @@ class EmrIntegrationTest {
|
||||
private static String clusterId;
|
||||
private static String stepId;
|
||||
|
||||
@Inject
|
||||
EmrService emrService;
|
||||
|
||||
@BeforeAll
|
||||
static void configure() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
@@ -67,7 +72,8 @@ class EmrIntegrationTest {
|
||||
.body("Cluster.Status.State", equalTo("WAITING"))
|
||||
.body("Cluster.ReleaseLabel", equalTo("emr-7.5.0"))
|
||||
.body("Cluster.InstanceCollectionType", equalTo("INSTANCE_GROUP"))
|
||||
.body("Cluster.AutoTerminate", equalTo(false));
|
||||
.body("Cluster.AutoTerminate", equalTo(false))
|
||||
.body("Cluster.MasterPublicDnsName", equalTo("ip-10-0-0-1.ec2.internal"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,7 +99,8 @@ class EmrIntegrationTest {
|
||||
call("ListInstances", "{\"ClusterId\":\"" + clusterId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("Instances", hasSize(3)) // 1 master + 2 core
|
||||
.body("Instances[0].Status.State", equalTo("RUNNING"));
|
||||
.body("Instances[0].Status.State", equalTo("RUNNING"))
|
||||
.body("Instances[0].PrivateDnsName", endsWith(".ec2.internal"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -245,4 +252,24 @@ class EmrIntegrationTest {
|
||||
.then().statusCode(200)
|
||||
.body("Cluster.Status.State", equalTo("WAITING"));
|
||||
}
|
||||
|
||||
// Catches: a cluster stored before the DNS fix keeps reporting its old us-east-1 master name.
|
||||
@Test
|
||||
void storedClusterReportsTheRegionalMasterDnsName() {
|
||||
String id = call("RunJobFlow",
|
||||
"{\"Name\":\"stale-dns\",\"ReleaseLabel\":\"emr-7.5.0\","
|
||||
+ "\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
|
||||
+ "\"InstanceGroups\":[{\"Name\":\"master\",\"InstanceRole\":\"MASTER\","
|
||||
+ "\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":1}]}}")
|
||||
.then().statusCode(200)
|
||||
.extract().path("JobFlowId");
|
||||
emrService.describeCluster(id).setMasterPublicDnsName("ip-10-0-0-1.us-east-1.compute.internal");
|
||||
|
||||
call("DescribeCluster", "{\"ClusterId\":\"" + id + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("Cluster.MasterPublicDnsName", equalTo("ip-10-0-0-1.ec2.internal"));
|
||||
|
||||
call("TerminateJobFlows", "{\"JobFlowIds\":[\"" + id + "\"]}")
|
||||
.then().statusCode(200);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user