mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(emr): run Hive's metastore service on a docker cluster with Hive (#7636)
A cluster's Hive steps kept their metastore in an embedded Derby
database in the cluster's /mnt, so only one Hive step at a time could
use it ("Another instance of Derby may have already booted the
database"), and Spark steps, with a catalog of their own, saw a Hive
step's tables only through the Glue Data Catalog. "By default, Hive
records metastore information in a MySQL database on the primary node's
file system", and the Glue Data Catalog is the one to pick "when you
require a persistent Hive metastore or a Hive metastore shared by
different clusters".
- On a cluster whose Applications name Hive, the primary node's
container runs Hive's metastore service on port 9083, once its HDFS
is up: with the image's Hadoop configuration, as Hive steps run, the
cluster's HDFS, its Derby database in the node's own volume, which
only the service opens, and its warehouse in the HDFS. The node is
ready once it listens, and ends if it exits, as for the HDFS daemons.
- It is on the cluster's own Docker network with the HDFS, so only the
cluster's steps reach it. It reaches tables' S3 locations through S3A
on Floci's S3, with a session for the cluster's EC2 instance
profile's role, which goes with the container: at the host's address
when Floci runs on the host, and as floci when Floci runs in a
container, which joins the cluster's network for it, as it joins EC2
VPC networks, and leaves it when the HDFS container goes. A start
that fails, or a container an earlier Floci left, does not keep
Floci there, and one Docker keeps Floci on stays known for the next
teardown.
- It gets the cluster's core-site and hive-site after its own
settings, as EMR's primary node does, so a hive-site warehouse folder
holds for it as for the steps. One an earlier Floci left running
starts again, as its session went with that Floci, and so does one
given Floci's address before Floci could join its network.
- A Floci that crashed is still on that network when it starts again,
and Docker lists it first, so what Floci launched then joined it and
reached the cluster's HDFS and metastore. Floci's own network is no
longer one it made, an EMR cluster's or a VPC's, its earlier owner
label included, or one Docker cannot inspect, unless it is on no
other, and its DNS server takes its address from that network.
- In a namespace the steps share, host or container:<id>, it does not
run: Hive 3.1 has no setting for the address it listens on, so it
would serve every interface of the namespace. Hive steps keep the
embedded Derby database there, as they do with no network.
- Hive steps get its URI in place of the embedded Derby settings, and
Spark steps' Hive client gets it too, so a Spark step reads a Hive
step's tables and makes tables a Hive step reads; a hive-site or
spark-hive-site naming the Glue Data Catalog's client factory still
uses Floci's Glue.
- Two Hive sessions starting at once both upload Hive's exec jar to
the same HDFS folder when it is not there, and one could launch Tez
tasks with a jar that changed under it, so the primary node puts it
there first, under the name Hive gives it.
EmrHiveStepsDockerIntegrationTest runs two Hive steps at once on a
cluster's metastore, and a Spark step that reads a Hive step's table
and makes one the next Hive step reads.
This commit is contained in:
1 parent
ee2cdfc4f8
commit
ba9a9c8155
19 files changed
+1200
-147
No files matched your search
@@ -0,0 +1,70 @@
|
||||
package io.floci.aws.core.common.dns;
|
||||
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.docker.ContainerDetector;
|
||||
import io.floci.aws.core.common.docker.CurrentContainerNetworkResolver;
|
||||
import io.vertx.core.AsyncResult;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.Handler;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.datagram.DatagramSocket;
|
||||
import jakarta.enterprise.inject.Instance;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/** The address the embedded DNS server gives the containers Floci launches. */
|
||||
class EmbeddedDnsServerAddressTest {
|
||||
|
||||
@Test
|
||||
void ownAddressIsThisContainersOnTheNetworkItsContainersJoin() throws Exception {
|
||||
CurrentContainerNetworkResolver currentContainer = mock(CurrentContainerNetworkResolver.class);
|
||||
// Not the host's lookup, which takes the first of its networks by name, one Floci made after a crash.
|
||||
when(currentContainer.resolveContainerIp()).thenReturn(Optional.of("172.19.0.2"));
|
||||
|
||||
assertEquals("172.19.0.2", EmbeddedDnsServer.ownAddress(currentContainer));
|
||||
}
|
||||
|
||||
@Test
|
||||
void ownAddressIsTheHostsLookupWhenThatNetworkCannotBeTold() throws Exception {
|
||||
CurrentContainerNetworkResolver currentContainer = mock(CurrentContainerNetworkResolver.class);
|
||||
when(currentContainer.resolveContainerIp()).thenReturn(Optional.empty());
|
||||
|
||||
assertEquals(InetAddress.getLocalHost().getHostAddress(), EmbeddedDnsServer.ownAddress(currentContainer));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void inAContainerTheServerAnswersAtThatAddress() {
|
||||
ContainerDetector containerDetector = mock(ContainerDetector.class);
|
||||
when(containerDetector.isRunningInContainer()).thenReturn(true);
|
||||
CurrentContainerNetworkResolver currentContainer = mock(CurrentContainerNetworkResolver.class);
|
||||
when(currentContainer.resolveContainerIp()).thenReturn(Optional.of("172.19.0.2"));
|
||||
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
when(config.hostname()).thenReturn(Optional.empty());
|
||||
when(config.dns().extraSuffixes()).thenReturn(Optional.empty());
|
||||
when(config.dns().containerFallbackServers()).thenReturn(List.of());
|
||||
when(config.dns().spoofAwsEndpoints()).thenReturn(false);
|
||||
Vertx vertx = mock(Vertx.class);
|
||||
DatagramSocket socket = mock(DatagramSocket.class);
|
||||
when(vertx.createDatagramSocket(any())).thenReturn(socket);
|
||||
when(socket.listen(eq(53), eq("0.0.0.0"), any())).thenAnswer(invocation -> {
|
||||
invocation.<Handler<AsyncResult<DatagramSocket>>>getArgument(2).handle(Future.succeededFuture(socket));
|
||||
return socket;
|
||||
});
|
||||
|
||||
EmbeddedDnsServer server = new EmbeddedDnsServer(config, containerDetector, vertx, mock(Instance.class),
|
||||
mock(Instance.class), mock(Instance.class), currentContainer);
|
||||
|
||||
assertEquals(Optional.of("172.19.0.2"), server.getServerIp());
|
||||
}
|
||||
}
|
||||
+37
@@ -460,6 +460,43 @@ class ContainerLifecycleManagerNetworkTest {
|
||||
verify(connectCmd).exec();
|
||||
}
|
||||
|
||||
@Test
|
||||
void ensureConnectedJoinsARunningContainerToTheNetworkUnderItsAliasOnlyWhenItIsNotOnIt() {
|
||||
NetworkSettings networks = mock(NetworkSettings.class);
|
||||
when(inspectOf("floci").getNetworkSettings()).thenReturn(networks);
|
||||
when(networks.getNetworks()).thenReturn(Map.of("floci_default", new ContainerNetwork()),
|
||||
Map.of("floci_default", new ContainerNetwork(), "emr-j-1-hdfs", new ContainerNetwork()));
|
||||
|
||||
manager().ensureConnected("floci", "emr-j-1-hdfs", "floci");
|
||||
manager().ensureConnected("floci", "emr-j-1-hdfs", "floci");
|
||||
|
||||
verify(connectCmd).withContainerId("floci");
|
||||
verify(connectCmd).withNetworkId("emr-j-1-hdfs");
|
||||
ArgumentCaptor<ContainerNetwork> endpoint = ArgumentCaptor.forClass(ContainerNetwork.class);
|
||||
verify(connectCmd).withContainerNetwork(endpoint.capture());
|
||||
assertEquals(List.of("floci"), endpoint.getValue().getAliases());
|
||||
// Docker refuses to join a container to a network it is on.
|
||||
verify(connectCmd, times(1)).exec();
|
||||
}
|
||||
|
||||
@Test
|
||||
void disconnectFromNetworkLeavesOnlyANetworkTheContainerIsOnAndSaysWhetherItLeft() {
|
||||
NetworkSettings networks = mock(NetworkSettings.class);
|
||||
when(inspectOf("floci").getNetworkSettings()).thenReturn(networks);
|
||||
when(networks.getNetworks()).thenReturn(Map.of("emr-j-1-hdfs", new ContainerNetwork()));
|
||||
|
||||
assertTrue(manager().disconnectFromNetwork("floci", "emr-j-1-hdfs"));
|
||||
assertTrue(manager().disconnectFromNetwork("floci", "emr-j-2-hdfs"));
|
||||
|
||||
verify(disconnectCmd).withContainerId("floci");
|
||||
verify(disconnectCmd).withNetworkId("emr-j-1-hdfs");
|
||||
verify(disconnectCmd).withForce(true);
|
||||
verify(disconnectCmd, times(1)).exec();
|
||||
// One Docker keeps it on is not left.
|
||||
doThrow(new ConflictException("the daemon is busy")).when(disconnectCmd).exec();
|
||||
assertFalse(manager().disconnectFromNetwork("floci", "emr-j-1-hdfs"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void removeNetworkSaysWhetherTheNetworkIsGone() {
|
||||
when(dockerClient.removeNetworkCmd("removed")).thenReturn(mock(RemoveNetworkCmd.class));
|
||||
|
||||
+107
@@ -3,8 +3,10 @@ package io.floci.aws.core.common.docker;
|
||||
import com.github.dockerjava.api.DockerClient;
|
||||
import com.github.dockerjava.api.command.InspectContainerCmd;
|
||||
import com.github.dockerjava.api.command.InspectContainerResponse;
|
||||
import com.github.dockerjava.api.command.InspectNetworkCmd;
|
||||
import com.github.dockerjava.api.model.ContainerNetwork;
|
||||
import com.github.dockerjava.api.model.ExposedPort;
|
||||
import com.github.dockerjava.api.model.Network;
|
||||
import com.github.dockerjava.api.model.Ports;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -12,9 +14,12 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -45,6 +50,70 @@ class CurrentContainerNetworkResolverTest {
|
||||
assertEquals(Optional.of("172.24.0.2"), resolver.resolveContainerIp());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveNetworkName_skipsANetworkFlociMadeWhichItIsStillOnAfterACrash() {
|
||||
// Docker lists a container's networks by name, so the cluster's comes first.
|
||||
CurrentContainerNetworkResolver resolver = resolverOn(networks(
|
||||
"floci-aws-emr-j-1-hdfs", "172.20.0.2",
|
||||
"floci_default", "172.19.0.2"), "floci-aws-emr-j-1-hdfs");
|
||||
|
||||
assertEquals(Optional.of("floci_default"), resolver.resolveNetworkName());
|
||||
assertEquals(Optional.of("172.19.0.2"), resolver.resolveContainerIp());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveNetworkName_prefersTheDefaultBridgeToANetworkFlociMade() {
|
||||
CurrentContainerNetworkResolver resolver = resolverOn(networks(
|
||||
"floci-aws-emr-j-1-hdfs", "172.20.0.2",
|
||||
"bridge", "172.17.0.2"), "floci-aws-emr-j-1-hdfs");
|
||||
|
||||
assertEquals(Optional.of("bridge"), resolver.resolveNetworkName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveNetworkName_takesANetworkFlociMadeWhenItIsOnNoOther() {
|
||||
CurrentContainerNetworkResolver resolver = resolverOn(networks(
|
||||
"floci-aws-emr-j-1-hdfs", "172.20.0.2",
|
||||
"floci-aws-emr-j-2-hdfs", "172.21.0.2"), "floci-aws-emr-j-1-hdfs", "floci-aws-emr-j-2-hdfs");
|
||||
|
||||
assertEquals(Optional.of("floci-aws-emr-j-1-hdfs"), resolver.resolveNetworkName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveNetworkName_prefersTheUsersNetworkToOneDockerCannotInspect() {
|
||||
CurrentContainerNetworkResolver resolver = resolverOn(networks(
|
||||
"first", "172.20.0.2",
|
||||
"floci_default", "172.19.0.2"), name -> {
|
||||
if ("first".equals(name)) {
|
||||
throw new IllegalStateException("The daemon is busy");
|
||||
}
|
||||
return Map.of();
|
||||
});
|
||||
|
||||
assertEquals(Optional.of("floci_default"), resolver.resolveNetworkName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveNetworkName_takesTheFirstUserDefinedNetworkWhenDockerCannotInspectAny() {
|
||||
CurrentContainerNetworkResolver resolver = resolverOn(networks(
|
||||
"bridge", "172.17.0.2",
|
||||
"first", "172.20.0.2"), name -> {
|
||||
throw new IllegalStateException("The daemon is busy");
|
||||
});
|
||||
|
||||
assertEquals(Optional.of("first"), resolver.resolveNetworkName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveNetworkName_skipsAVpcNetworkWithOnlyItsEarlierOwnerLabel() {
|
||||
CurrentContainerNetworkResolver resolver = resolverOn(networks(
|
||||
"floci-vpc-1", "172.20.0.2",
|
||||
"floci_default", "172.19.0.2"), name -> "floci-vpc-1".equals(name)
|
||||
? Map.of("floci_vpc_owner_port", "4566") : Map.of());
|
||||
|
||||
assertEquals(Optional.of("floci_default"), resolver.resolveNetworkName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveNetworkName_returnsEmptyOutsideContainer() {
|
||||
DockerClient dockerClient = mock(DockerClient.class);
|
||||
@@ -151,6 +220,44 @@ class CurrentContainerNetworkResolverTest {
|
||||
return inspectCmd;
|
||||
}
|
||||
|
||||
// A resolver in a container on networks, of which Floci made those named.
|
||||
private static CurrentContainerNetworkResolver resolverOn(Map<String, ContainerNetwork> networks,
|
||||
String... madeByFloci) {
|
||||
Set<String> made = Set.of(madeByFloci);
|
||||
return resolverOn(networks, name -> made.contains(name)
|
||||
? Map.of(ContainerStorageHelper.OWNER_LABEL, "default/4566") : Map.of());
|
||||
}
|
||||
|
||||
// A resolver in a container on networks, each of which Docker inspects with the labels given, or fails to.
|
||||
private static CurrentContainerNetworkResolver resolverOn(Map<String, ContainerNetwork> networks,
|
||||
Function<String, Map<String, String>> labels) {
|
||||
DockerClient dockerClient = mock(DockerClient.class);
|
||||
ContainerDetector containerDetector = mock(ContainerDetector.class);
|
||||
when(containerDetector.isRunningInContainer()).thenReturn(true);
|
||||
InspectContainerCmd inspectCmd = mock(InspectContainerCmd.class);
|
||||
InspectContainerResponse inspect = mock(InspectContainerResponse.class, RETURNS_DEEP_STUBS);
|
||||
when(dockerClient.inspectContainerCmd("floci-container")).thenReturn(inspectCmd);
|
||||
when(inspectCmd.exec()).thenReturn(inspect);
|
||||
when(inspect.getNetworkSettings().getNetworks()).thenReturn(networks);
|
||||
when(dockerClient.inspectNetworkCmd()).thenAnswer(invocation -> {
|
||||
InspectNetworkCmd cmd = mock(InspectNetworkCmd.class);
|
||||
when(cmd.withNetworkId(anyString())).thenAnswer(id -> {
|
||||
String name = id.getArgument(0);
|
||||
InspectNetworkCmd named = mock(InspectNetworkCmd.class);
|
||||
when(named.exec()).thenAnswer(exec -> {
|
||||
// Read first: one that throws inside the stubbing below would leave Mockito half way through it.
|
||||
Map<String, String> found = labels.apply(name);
|
||||
Network network = mock(Network.class);
|
||||
when(network.getLabels()).thenReturn(found);
|
||||
return network;
|
||||
});
|
||||
return named;
|
||||
});
|
||||
return cmd;
|
||||
});
|
||||
return new TestResolver(dockerClient, containerDetector, "floci-container");
|
||||
}
|
||||
|
||||
private static Map<String, ContainerNetwork> networks(String firstName, String firstIp,
|
||||
String secondName, String secondIp) {
|
||||
Map<String, ContainerNetwork> networks = new LinkedHashMap<>();
|
||||
|
||||
@@ -24,13 +24,18 @@ import io.floci.aws.core.common.docker.ContainerLifecycleManager;
|
||||
import io.floci.aws.core.common.docker.ContainerLiveness;
|
||||
import io.floci.aws.core.common.docker.ContainerSpec;
|
||||
import io.floci.aws.core.common.docker.ContainerStorageHelper;
|
||||
import io.floci.aws.core.common.docker.CurrentContainerNetworkResolver;
|
||||
import io.floci.aws.core.common.docker.LaunchedContainerAwsEnv;
|
||||
import io.floci.aws.services.emrserverless.SparkJobRunner;
|
||||
import io.floci.aws.services.iam.model.SessionCreds;
|
||||
import io.floci.aws.services.lambda.launcher.ImageCacheService;
|
||||
import io.floci.aws.services.lambda.launcher.LambdaExecutionRoleCredentials;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InOrder;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -74,13 +79,20 @@ class EmrClusterStorageTest {
|
||||
private static final String HOST = "ip-10-0-0-1.ec2.internal";
|
||||
private static final String READY = "test -f /tmp/floci-hdfs-ready";
|
||||
private static final BooleanSupplier NOT_STOPPED = () -> false;
|
||||
// A cluster with Hive, whose EC2 instance profile's role is r, with no core-site or hive-site.
|
||||
private static final ClusterStorage.HiveMetastore METASTORE =
|
||||
new ClusterStorage.HiveMetastore("arn:aws:iam::123456789012:role/r", Map.of());
|
||||
|
||||
private final EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
private final DockerClient docker = mock(DockerClient.class);
|
||||
private final ContainerLifecycleManager lifecycle = mock(ContainerLifecycleManager.class);
|
||||
private final ContainerBuilder containerBuilder = mock(ContainerBuilder.class);
|
||||
private final ContainerBuilder.Builder spec = mock(ContainerBuilder.Builder.class, RETURNS_SELF);
|
||||
private final EmrClusterStorage storage = new EmrClusterStorage(lifecycle, containerBuilder, config);
|
||||
private final LaunchedContainerAwsEnv awsEnv = mock(LaunchedContainerAwsEnv.class);
|
||||
private final LambdaExecutionRoleCredentials roleCredentials = mock(LambdaExecutionRoleCredentials.class);
|
||||
private final CurrentContainerNetworkResolver currentContainer = mock(CurrentContainerNetworkResolver.class);
|
||||
private final EmrClusterStorage storage = new EmrClusterStorage(lifecycle, containerBuilder, awsEnv,
|
||||
roleCredentials, currentContainer, config);
|
||||
private final String hdfsName = ContainerStorageHelper.dockerName(config, "emr-j-1-hdfs");
|
||||
|
||||
@BeforeEach
|
||||
@@ -109,10 +121,10 @@ class EmrClusterStorageTest {
|
||||
List<List<String>> looks = ContainerExecStubs.completeEveryExec(docker, "c-1", List.of(1L, 0L), "", "");
|
||||
|
||||
SparkJobRunner.Storage started = storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", NOT_STOPPED);
|
||||
"floci-network", null, NOT_STOPPED);
|
||||
|
||||
SparkJobRunner.Storage volumes = storage.volumes("j-1");
|
||||
assertEquals(new SparkJobRunner.Storage(volumes.home(), volumes.mnt(), HOST, "172.18.0.5", hdfsName), started);
|
||||
assertEquals(volumes.withHdfs(HOST, "172.18.0.5", hdfsName), started);
|
||||
verify(spec).withName(hdfsName);
|
||||
verify(spec).withUser("root");
|
||||
verify(spec).withEnv("FLOCI_HDFS_HOST", HOST);
|
||||
@@ -167,9 +179,13 @@ class EmrClusterStorageTest {
|
||||
"until curl -sf -m 5 \"http://127.0.0.1:9870/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo\"",
|
||||
"| grep -q \"\\\"Safemode\\\" : \\\"\\\"\"; do",
|
||||
"[ \"$(jobs -rp | wc -l)\" = 2 ] || exit 1; sleep 0.2; done;",
|
||||
"hdfs dfs -mkdir -p /tmp /user/hadoop || exit 1;",
|
||||
"touch /tmp/floci-hdfs-ready;",
|
||||
"hdfs dfs -mkdir -p /tmp /user/hadoop || exit 1;"))
|
||||
&& entrypoint.get(2).contains(String.join(" ", "fi;", "touch /tmp/floci-hdfs-ready;",
|
||||
"wait -n; rm -f /tmp/floci-hdfs-ready; kill $(jobs -rp) 2>/dev/null; exit 1'"))));
|
||||
// A cluster without Hive runs no metastore service, and its primary node does not talk to Floci.
|
||||
verify(spec, never()).withEnv(eq("FLOCI_HIVE_METASTORE"), anyString());
|
||||
verify(spec, never()).withJavaTrustStore();
|
||||
assertNull(started.hiveMetastore());
|
||||
// One left stopped by a restart goes first.
|
||||
InOrder order = inOrder(lifecycle);
|
||||
order.verify(lifecycle).removeIfExistsStrict(hdfsName);
|
||||
@@ -186,7 +202,7 @@ class EmrClusterStorageTest {
|
||||
ContainerExecStubs.completeEveryExec(docker, hdfsName, 0L, "", "");
|
||||
|
||||
SparkJobRunner.Storage started = storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"host", NOT_STOPPED);
|
||||
"host", null, NOT_STOPPED);
|
||||
|
||||
assertEquals("127.0.0.1", started.hdfsAddress());
|
||||
// Steps share the host's network with it, so they join no other.
|
||||
@@ -202,7 +218,7 @@ class EmrClusterStorageTest {
|
||||
when(lifecycle.probeContainer("c-1")).thenReturn(ContainerLiveness.RUNNING);
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-1", 0L, "", "");
|
||||
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "host", NOT_STOPPED);
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "host", null, NOT_STOPPED);
|
||||
|
||||
// The host's other interfaces would otherwise serve its files, without permissions, to anyone reaching them.
|
||||
verify(spec).withEnv("FLOCI_HDFS_BIND", "127.0.0.1");
|
||||
@@ -218,7 +234,7 @@ class EmrClusterStorageTest {
|
||||
when(lifecycle.probeContainer("c-2")).thenReturn(ContainerLiveness.RUNNING);
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-2", 0L, "", "");
|
||||
|
||||
SparkJobRunner.Storage started = storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, null,
|
||||
SparkJobRunner.Storage started = storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, null, null,
|
||||
NOT_STOPPED);
|
||||
|
||||
// Docker joins a container placed in another's namespace to no other network, so its steps reach it there.
|
||||
@@ -229,6 +245,357 @@ class EmrClusterStorageTest {
|
||||
verify(lifecycle, never()).ensureNetwork(anyString(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aClusterWithHivesPrimaryNodeRunsItsMetastoreServiceToo() {
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-6", Map.of()));
|
||||
when(lifecycle.probeContainer("c-6")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveContainerNetworkIp("c-6", hdfsName)).thenReturn("172.18.0.7");
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-6", 0L, "", "");
|
||||
// A session for the cluster's instance profile's role, as its steps' S3 would have.
|
||||
Optional<SessionCreds> session = Optional.of(new SessionCreds("ASIAMETASTORE", "secret", "token"));
|
||||
when(roleCredentials.forRole("arn:aws:iam::123456789012:role/EMR_EC2_DefaultRole", "123456789012",
|
||||
hdfsName)).thenReturn(session);
|
||||
// Floci on the host, reached at the host's address.
|
||||
when(awsEnv.flociEndpoint(false)).thenReturn("http://host.docker.internal:4566");
|
||||
when(awsEnv.sdkBaselineEnv("us-east-1", Optional.empty(), "http://host.docker.internal:4566", session,
|
||||
"123456789012")).thenReturn(List.of("AWS_ACCESS_KEY_ID=ASIAMETASTORE"));
|
||||
|
||||
SparkJobRunner.Storage started = storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network",
|
||||
new ClusterStorage.HiveMetastore("arn:aws:iam::123456789012:role/EMR_EC2_DefaultRole", Map.of()),
|
||||
NOT_STOPPED);
|
||||
|
||||
assertEquals("thrift://ip-10-0-0-1.ec2.internal:9083", started.hiveMetastore());
|
||||
verify(spec).withEnv(List.of("AWS_ACCESS_KEY_ID=ASIAMETASTORE"));
|
||||
verify(spec).withHostDockerInternalOnLinux();
|
||||
verify(spec).withJavaTrustStore();
|
||||
// Floci's resolver would answer with an address on Floci's network, which the cluster's does not reach.
|
||||
verify(spec, never()).withEmbeddedDns();
|
||||
verify(lifecycle, never()).ensureConnected(anyString(), anyString(), anyString());
|
||||
// Floci's S3 through S3A, as for the cluster's steps.
|
||||
verify(spec).withEnv(eq("FLOCI_HIVE_METASTORE"), argThat(settings -> settings.startsWith(
|
||||
"--hiveconf fs.s3a.endpoint=http://host.docker.internal:4566"
|
||||
+ " --hiveconf fs.s3a.endpoint.region=us-east-1 ")
|
||||
&& settings.contains(" --hiveconf fs.s3.impl=org.apache.hadoop.fs.s3a.S3AFileSystem ")));
|
||||
// Hive's exec jar where a Hive session would upload it, so two at once do not race to.
|
||||
verify(spec).withEntrypoint(argThat(entrypoint -> entrypoint.get(2).contains(
|
||||
"hdfs dfs -mkdir -p /user/hive/warehouse /tmp/hadoop/.hiveJars || exit 1; "
|
||||
+ "jar=$(ls /usr/lib/hive/lib/hive-exec-[0-9]*.jar | head -1); hdfs dfs -put -f \"$jar\" "
|
||||
+ "/tmp/hadoop/.hiveJars/$(basename \"$jar\" .jar)"
|
||||
+ "-$(sha256sum \"$jar\" | cut -d\" \" -f1).jar")));
|
||||
// With the image's Hadoop configuration, as Hive steps run; in a folder Derby can write its log in; its
|
||||
// database on the primary node's own volume, its warehouse in the HDFS, ready only once it listens, and the
|
||||
// node gone if it exits while starting.
|
||||
verify(spec).withEntrypoint(argThat(entrypoint -> entrypoint.get(2).contains(
|
||||
"cd /tmp; LOGS_DIR=/tmp/floci-hive-logs HADOOP_CONF_DIR=/etc/hadoop/conf"
|
||||
+ " hive --service metastore -p 9083"
|
||||
+ " --hiveconf fs.defaultFS=hdfs://$FLOCI_HDFS_HOST:8020 $FLOCI_HIVE_METASTORE"
|
||||
+ " --hiveconf \"javax.jdo.option.ConnectionURL=jdbc:derby:;"
|
||||
+ "databaseName=/mnt/var/lib/hive/metastore_db;create=true\"")
|
||||
&& entrypoint.get(2).contains(
|
||||
"hive.metastore.warehouse.dir=hdfs://$FLOCI_HDFS_HOST:8020/user/hive/warehouse"
|
||||
+ " \"${site[@]}\" &")
|
||||
&& entrypoint.get(2).contains("until (exec 3<>/dev/tcp/127.0.0.1/9083) 2>/dev/null; do "
|
||||
+ "[ \"$(jobs -rp | wc -l)\" = 3 ] || exit 1; sleep 0.2; done; "
|
||||
+ "fi; touch /tmp/floci-hdfs-ready")));
|
||||
|
||||
// The session goes with the container.
|
||||
storage.remove("j-1");
|
||||
verify(roleCredentials).unregister("123456789012", "ASIAMETASTORE");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMetastoresSessionGoesWithItsContainerOnAResetOrAShutdownAndWhenItCannotStart() {
|
||||
ClusterStorage.HiveMetastore metastore = METASTORE;
|
||||
when(roleCredentials.forRole("arn:aws:iam::123456789012:role/r", "123456789012", hdfsName))
|
||||
.thenReturn(Optional.of(new SessionCreds("ASIAONE", "s", "t")), Optional.of(new SessionCreds("ASIATWO",
|
||||
"s", "t")));
|
||||
when(awsEnv.flociEndpoint(false)).thenReturn("http://host.docker.internal:4566");
|
||||
when(awsEnv.sdkBaselineEnv(anyString(), any(), anyString(), any(), anyString())).thenReturn(List.of());
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-8", Map.of()))
|
||||
.thenThrow(new IllegalStateException("Could not start the container"));
|
||||
when(lifecycle.probeContainer("c-8")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveContainerNetworkIp("c-8", hdfsName)).thenReturn("172.18.0.10");
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-8", 0L, "", "");
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", metastore, NOT_STOPPED);
|
||||
|
||||
storage.stopManagedContainers();
|
||||
verify(roleCredentials).unregister("123456789012", "ASIAONE");
|
||||
assertThrows(IllegalStateException.class, () -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", metastore, NOT_STOPPED));
|
||||
|
||||
verify(roleCredentials).unregister("123456789012", "ASIATWO");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMetastoreStartedAgainAfterItsContainerStoppedReleasesTheSessionOfTheOneBefore() {
|
||||
ClusterStorage.HiveMetastore metastore = METASTORE;
|
||||
when(roleCredentials.forRole("arn:aws:iam::123456789012:role/r", "123456789012", hdfsName))
|
||||
.thenReturn(Optional.of(new SessionCreds("ASIAONE", "s", "t")),
|
||||
Optional.of(new SessionCreds("ASIATWO", "s", "t")));
|
||||
when(awsEnv.flociEndpoint(false)).thenReturn("http://host.docker.internal:4566");
|
||||
when(awsEnv.sdkBaselineEnv(anyString(), any(), anyString(), any(), anyString())).thenReturn(List.of());
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-8", Map.of()),
|
||||
new ContainerLifecycleManager.ContainerInfo("c-9", Map.of()));
|
||||
when(lifecycle.probeContainer("c-8")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.probeContainer("c-9")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveContainerNetworkIp("c-8", hdfsName)).thenReturn("172.18.0.10");
|
||||
when(lifecycle.resolveContainerNetworkIp("c-9", hdfsName)).thenReturn("172.18.0.11");
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-8", 0L, "", "");
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-9", 0L, "", "");
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", metastore, NOT_STOPPED);
|
||||
|
||||
// Its metastore exited, which ended the container; the cluster's next step starts it again.
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", metastore, NOT_STOPPED);
|
||||
|
||||
verify(roleCredentials).unregister("123456789012", "ASIAONE");
|
||||
verify(roleCredentials, never()).unregister("123456789012", "ASIATWO");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMetastoresSessionStaysWhileDockerKeepsItsContainer() {
|
||||
ClusterStorage.HiveMetastore metastore = METASTORE;
|
||||
when(roleCredentials.forRole("arn:aws:iam::123456789012:role/r", "123456789012", hdfsName))
|
||||
.thenReturn(Optional.of(new SessionCreds("ASIAONE", "s", "t")));
|
||||
when(awsEnv.flociEndpoint(false)).thenReturn("http://host.docker.internal:4566");
|
||||
when(awsEnv.sdkBaselineEnv(anyString(), any(), anyString(), any(), anyString())).thenReturn(List.of());
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-8", Map.of()));
|
||||
when(lifecycle.probeContainer("c-8")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveContainerNetworkIp("c-8", hdfsName)).thenReturn("172.18.0.10");
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-8", 0L, "", "");
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", metastore, NOT_STOPPED);
|
||||
doThrow(new IllegalStateException("Failed to remove container " + hdfsName)).doNothing()
|
||||
.when(lifecycle).removeIfExistsStrict(hdfsName);
|
||||
|
||||
storage.stopManagedContainers();
|
||||
// Its metastore may still reach S3 with it.
|
||||
verify(roleCredentials, never()).unregister(anyString(), anyString());
|
||||
storage.stopManagedContainers();
|
||||
|
||||
verify(roleCredentials).unregister("123456789012", "ASIAONE");
|
||||
}
|
||||
|
||||
@Test
|
||||
void inANamespaceTheStepsShareTheMetastoreServiceDoesNotRunAsItWouldServeEveryInterface() {
|
||||
when(containerBuilder.resolveDockerNetwork(Optional.of("host"))).thenReturn(Optional.of("host"));
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-1", Map.of()));
|
||||
when(lifecycle.probeContainer("c-1")).thenReturn(ContainerLiveness.RUNNING);
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-1", 0L, "", "");
|
||||
|
||||
SparkJobRunner.Storage started = storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "host",
|
||||
METASTORE, NOT_STOPPED);
|
||||
|
||||
// Hive steps keep a metastore of their own.
|
||||
assertNull(started.hiveMetastore());
|
||||
verify(spec, never()).withEnv(eq("FLOCI_HIVE_METASTORE"), anyString());
|
||||
verify(roleCredentials, never()).forRole(anyString(), anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void withFlociInAContainerItsContainerJoinsTheClustersNetworkForTheMetastoreToReachItsS3() {
|
||||
when(currentContainer.resolveContainerId()).thenReturn(Optional.of("floci-container"));
|
||||
when(awsEnv.flociEndpoint(false)).thenReturn("http://172.20.0.2:4566");
|
||||
when(awsEnv.sdkBaselineEnv(anyString(), any(), anyString(), any(), anyString())).thenReturn(List.of());
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-6", Map.of()));
|
||||
when(lifecycle.probeContainer("c-6")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveContainerNetworkIp("c-6", hdfsName)).thenReturn("172.18.0.7");
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-6", 0L, "", "");
|
||||
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network",
|
||||
METASTORE, NOT_STOPPED);
|
||||
|
||||
// Docker keeps the cluster's network apart from Floci's, where Floci's address is.
|
||||
InOrder start = inOrder(lifecycle);
|
||||
start.verify(lifecycle).ensureNetwork(eq(hdfsName), any());
|
||||
start.verify(lifecycle).ensureConnected("floci-container", hdfsName, "floci");
|
||||
start.verify(lifecycle).createAndStart(any());
|
||||
verify(awsEnv).sdkBaselineEnv(anyString(), any(), eq("http://floci:4566"), any(), anyString());
|
||||
verify(spec).withEnv(eq("FLOCI_HIVE_METASTORE"), argThat(settings -> settings.startsWith(
|
||||
"--hiveconf fs.s3a.endpoint=http://floci:4566 ")));
|
||||
|
||||
// It leaves the network with the container, so the network can go.
|
||||
when(lifecycle.removeNetwork(hdfsName)).thenReturn(true);
|
||||
storage.remove("j-1");
|
||||
InOrder removal = inOrder(lifecycle);
|
||||
removal.verify(lifecycle).removeIfExistsStrict(hdfsName);
|
||||
removal.verify(lifecycle).disconnectFromNetwork("floci-container", hdfsName);
|
||||
removal.verify(lifecycle).removeNetwork(hdfsName);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFlociContainerThatCannotJoinTheClustersNetworkLeavesTheMetastoreFlocisOwnAddress() {
|
||||
when(currentContainer.resolveContainerId()).thenReturn(Optional.of("floci-container"));
|
||||
doThrow(new DockerException("No such container: floci-container", 404))
|
||||
.when(lifecycle).ensureConnected("floci-container", hdfsName, "floci");
|
||||
when(awsEnv.flociEndpoint(false)).thenReturn("http://192.168.1.5:4566");
|
||||
when(awsEnv.sdkBaselineEnv(anyString(), any(), anyString(), any(), anyString())).thenReturn(List.of());
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-6", Map.of()));
|
||||
when(lifecycle.probeContainer("c-6")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveContainerNetworkIp("c-6", hdfsName)).thenReturn("172.18.0.7");
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-6", 0L, "", "");
|
||||
|
||||
SparkJobRunner.Storage started = storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", METASTORE, NOT_STOPPED);
|
||||
|
||||
// The HDFS still starts, as do its steps' tables there.
|
||||
assertEquals("172.18.0.7", started.hdfsAddress());
|
||||
verify(spec).withEnv(eq("FLOCI_HIVE_METASTORE"), argThat(settings -> settings.startsWith(
|
||||
"--hiveconf fs.s3a.endpoint=http://192.168.1.5:4566 ")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMetastoreThisFlociStartedIsUsedAsItIsHavingFlocisContainerJoinItsNetworkAgain() {
|
||||
when(currentContainer.resolveContainerId()).thenReturn(Optional.of("floci-container"));
|
||||
when(awsEnv.flociEndpoint(false)).thenReturn("http://172.20.0.2:4566");
|
||||
when(awsEnv.sdkBaselineEnv(anyString(), any(), anyString(), any(), anyString())).thenReturn(List.of());
|
||||
// Started by this process, then found running by the cluster's next step.
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING, ContainerLiveness.RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-6", Map.of()));
|
||||
when(lifecycle.probeContainer("c-6")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveContainerNetworkIp(anyString(), eq(hdfsName))).thenReturn("172.18.0.7");
|
||||
runningOn(hdfsName, hdfsName);
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-6", 0L, "", "");
|
||||
ContainerExecStubs.completeEveryExec(docker, hdfsName, 0L, "", "");
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", METASTORE, NOT_STOPPED);
|
||||
|
||||
SparkJobRunner.Storage found = storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", METASTORE, NOT_STOPPED);
|
||||
|
||||
assertEquals("thrift://ip-10-0-0-1.ec2.internal:9083", found.hiveMetastore());
|
||||
verify(lifecycle, times(1)).createAndStart(any());
|
||||
// In case Floci's container has left the network since.
|
||||
verify(lifecycle, times(2)).ensureConnected("floci-container", hdfsName, "floci");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMetastoreAnEarlierFlociLeftRunningStartsAgainWithASessionOfThisOnes() {
|
||||
// Its session went with the process that started it.
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.RUNNING);
|
||||
runningOn(hdfsName, hdfsName);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-9", Map.of()));
|
||||
when(lifecycle.probeContainer("c-9")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveContainerNetworkIp("c-9", hdfsName)).thenReturn("172.18.0.9");
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-9", 0L, "", "");
|
||||
Optional<SessionCreds> session = Optional.of(new SessionCreds("ASIANEW", "s", "t"));
|
||||
when(roleCredentials.forRole("arn:aws:iam::123456789012:role/r", "123456789012", hdfsName)).thenReturn(session);
|
||||
when(awsEnv.flociEndpoint(false)).thenReturn("http://host.docker.internal:4566");
|
||||
when(awsEnv.sdkBaselineEnv("us-east-1", Optional.empty(), "http://host.docker.internal:4566", session,
|
||||
"123456789012")).thenReturn(List.of("AWS_ACCESS_KEY_ID=ASIANEW"));
|
||||
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", METASTORE, NOT_STOPPED);
|
||||
|
||||
InOrder order = inOrder(lifecycle);
|
||||
order.verify(lifecycle).removeIfExistsStrict(hdfsName);
|
||||
order.verify(lifecycle).createAndStart(any());
|
||||
verify(spec).withEnv(List.of("AWS_ACCESS_KEY_ID=ASIANEW"));
|
||||
// On the data its volume keeps.
|
||||
verify(lifecycle, never()).removeVolume(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMetastoreStartedWhileFlocisContainerCouldNotJoinItsNetworkStartsAgainOnceItCan() {
|
||||
when(currentContainer.resolveContainerId()).thenReturn(Optional.of("floci-container"));
|
||||
doThrow(new DockerException("The daemon is busy", 500)).doNothing()
|
||||
.when(lifecycle).ensureConnected("floci-container", hdfsName, "floci");
|
||||
when(awsEnv.flociEndpoint(false)).thenReturn("http://172.20.0.2:4566");
|
||||
when(awsEnv.sdkBaselineEnv(anyString(), any(), anyString(), any(), anyString())).thenReturn(List.of());
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING, ContainerLiveness.RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-6", Map.of()),
|
||||
new ContainerLifecycleManager.ContainerInfo("c-7", Map.of()));
|
||||
when(lifecycle.probeContainer("c-6")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.probeContainer("c-7")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveContainerNetworkIp(anyString(), eq(hdfsName))).thenReturn("172.18.0.7");
|
||||
runningOn(hdfsName, hdfsName);
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-6", 0L, "", "");
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-7", 0L, "", "");
|
||||
// Given Floci's address on Floci's network, which the cluster's does not reach.
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", METASTORE, NOT_STOPPED);
|
||||
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", METASTORE, NOT_STOPPED);
|
||||
|
||||
// A join cannot change the address it was given, so it starts again with Floci's on its network.
|
||||
verify(lifecycle, times(2)).createAndStart(any());
|
||||
// It had no session to give back: the role has none here.
|
||||
verify(roleCredentials, never()).unregister(any(), any());
|
||||
verify(spec).withEnv(eq("FLOCI_HIVE_METASTORE"), argThat(settings -> settings.startsWith(
|
||||
"--hiveconf fs.s3a.endpoint=http://floci:4566 ")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMetastoreThatFailsToStartHasFlocisContainerLeaveItsNetwork() {
|
||||
when(currentContainer.resolveContainerId()).thenReturn(Optional.of("floci-container"));
|
||||
when(awsEnv.flociEndpoint(false)).thenReturn("http://172.20.0.2:4566");
|
||||
when(awsEnv.sdkBaselineEnv(anyString(), any(), anyString(), any(), anyString())).thenReturn(List.of());
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenThrow(new IllegalStateException("Could not start the container"));
|
||||
|
||||
assertThrows(IllegalStateException.class, () -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST,
|
||||
IMAGE, "floci-network", METASTORE, NOT_STOPPED));
|
||||
|
||||
InOrder order = inOrder(lifecycle);
|
||||
order.verify(lifecycle).ensureConnected("floci-container", hdfsName, "floci");
|
||||
order.verify(lifecycle).createAndStart(any());
|
||||
order.verify(lifecycle).disconnectFromNetwork("floci-container", hdfsName);
|
||||
}
|
||||
|
||||
@Test
|
||||
void anHdfsWhoseNetworkDockerKeepsFlocisContainerOnStaysKnownForTheNextTeardown() {
|
||||
when(currentContainer.resolveContainerId()).thenReturn(Optional.of("floci-container"));
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveContainerNetworkIp(hdfsName, hdfsName)).thenReturn("172.18.0.9");
|
||||
runningOn(hdfsName, hdfsName);
|
||||
ContainerExecStubs.completeEveryExec(docker, hdfsName, 0L, "", "");
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", null, NOT_STOPPED);
|
||||
when(lifecycle.disconnectFromNetwork("floci-container", hdfsName)).thenReturn(false, true);
|
||||
|
||||
storage.stopManagedContainers();
|
||||
storage.stopManagedContainers();
|
||||
storage.stopManagedContainers();
|
||||
|
||||
// Kept on it the first time, so still known; off it the second; not asked again the third.
|
||||
verify(lifecycle, times(2)).disconnectFromNetwork("floci-container", hdfsName);
|
||||
// Nor is a storage whose network Docker keeps it on gone.
|
||||
when(lifecycle.disconnectFromNetwork("floci-container", hdfsName)).thenReturn(false);
|
||||
when(lifecycle.removeVolume(anyString())).thenReturn(true);
|
||||
when(lifecycle.removeNetwork(hdfsName)).thenReturn(true);
|
||||
assertFalse(storage.remove("j-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMetastoreGetsTheClustersCoreSiteAndHiveSiteAfterItsOwnSettings() {
|
||||
when(awsEnv.flociEndpoint(false)).thenReturn("http://host.docker.internal:4566");
|
||||
when(awsEnv.sdkBaselineEnv(anyString(), any(), anyString(), any(), anyString())).thenReturn(List.of());
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-6", Map.of()));
|
||||
when(lifecycle.probeContainer("c-6")).thenReturn(ContainerLiveness.RUNNING);
|
||||
when(lifecycle.resolveContainerNetworkIp("c-6", hdfsName)).thenReturn("172.18.0.7");
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-6", 0L, "", "");
|
||||
Map<String, String> settings = new LinkedHashMap<>();
|
||||
settings.put("fs.s3a.endpoint", "http://s3.example:9000");
|
||||
settings.put("hive.metastore.warehouse.dir", "s3://bucket/warehouse dir");
|
||||
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network",
|
||||
new ClusterStorage.HiveMetastore("arn:aws:iam::123456789012:role/r", settings), NOT_STOPPED);
|
||||
|
||||
// One to a line, so a value with a space stays one argument.
|
||||
verify(spec).withEnv("FLOCI_HIVE_METASTORE_SITE", String.join("\n", "--hiveconf",
|
||||
"fs.s3a.endpoint=http://s3.example:9000", "--hiveconf",
|
||||
"hive.metastore.warehouse.dir=s3://bucket/warehouse dir"));
|
||||
// Last, so each replaces the service's own, its S3 and warehouse among them.
|
||||
verify(spec).withEntrypoint(argThat(entrypoint -> entrypoint.get(2).contains(
|
||||
"[ -z \"$FLOCI_HIVE_METASTORE_SITE\" ] || mapfile -t site <<< \"$FLOCI_HIVE_METASTORE_SITE\"; cd /tmp;")
|
||||
&& entrypoint.get(2).contains(
|
||||
"hive.metastore.warehouse.dir=hdfs://$FLOCI_HDFS_HOST:8020/user/hive/warehouse"
|
||||
+ " \"${site[@]}\" &")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aClustersHdfsStartsFromTheImageIdItsPullResolvedWhichAnotherPullCannotMove() {
|
||||
String id = "sha256:" + "a".repeat(64);
|
||||
@@ -241,7 +608,7 @@ class EmrClusterStorageTest {
|
||||
when(lifecycle.resolveContainerNetworkIp("c-1", hdfsName)).thenReturn("172.18.0.5");
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-1", 0L, "", "");
|
||||
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", NOT_STOPPED);
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", null, NOT_STOPPED);
|
||||
|
||||
verify(containerBuilder).newContainer(id);
|
||||
verify(containerBuilder, never()).newContainer(IMAGE);
|
||||
@@ -258,7 +625,7 @@ class EmrClusterStorageTest {
|
||||
when(lifecycle.probeContainer("c-1")).thenReturn(ContainerLiveness.RUNNING);
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-1", 0L, "", "");
|
||||
|
||||
assertEquals("127.0.0.1", storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "host",
|
||||
assertEquals("127.0.0.1", storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "host", null,
|
||||
NOT_STOPPED).hdfsAddress());
|
||||
|
||||
verify(lifecycle).removeIfExistsStrict(hdfsName);
|
||||
@@ -300,11 +667,11 @@ class EmrClusterStorageTest {
|
||||
return null;
|
||||
}).when(lifecycle).ensureVolume(eq(hdfsName), any());
|
||||
Future<SparkJobRunner.Storage> starting = steps.submit(
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "host", NOT_STOPPED));
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "host", null, NOT_STOPPED));
|
||||
assertTrue(firstLooked.await(10, TimeUnit.SECONDS));
|
||||
Future<SparkJobRunner.Storage> waiting = steps.submit(() -> {
|
||||
second.set(Thread.currentThread());
|
||||
return storage.hdfs("j-2", "123456789012", "us-east-1", HOST, IMAGE, "host", NOT_STOPPED);
|
||||
return storage.hdfs("j-2", "123456789012", "us-east-1", HOST, IMAGE, "host", null, NOT_STOPPED);
|
||||
});
|
||||
|
||||
assertEquals("127.0.0.1", starting.get(10, TimeUnit.SECONDS).hdfsAddress());
|
||||
@@ -334,7 +701,7 @@ class EmrClusterStorageTest {
|
||||
when(lifecycle.probeContainer("c-1")).thenReturn(ContainerLiveness.RUNNING);
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-1", 0L, "", "");
|
||||
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "host", NOT_STOPPED);
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "host", null, NOT_STOPPED);
|
||||
|
||||
verify(lifecycle).createAndStart(any());
|
||||
}
|
||||
@@ -346,7 +713,8 @@ class EmrClusterStorageTest {
|
||||
.when(lifecycle).removeIfExistsStrict(hdfsName);
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", NOT_STOPPED));
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", null, NOT_STOPPED));
|
||||
|
||||
// Not a name clash on the create that follows.
|
||||
assertEquals("Failed to remove stale container " + hdfsName, failure.getMessage());
|
||||
@@ -362,7 +730,8 @@ class EmrClusterStorageTest {
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-1", 0L, "", "");
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", NOT_STOPPED));
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", null, NOT_STOPPED));
|
||||
|
||||
assertEquals("The HDFS of EMR cluster j-1 has no address on Docker network " + hdfsName,
|
||||
failure.getMessage());
|
||||
@@ -376,7 +745,7 @@ class EmrClusterStorageTest {
|
||||
ContainerExecStubs.completeEveryExec(docker, hdfsName, 0L, "", "");
|
||||
|
||||
assertEquals("172.18.0.6", storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", NOT_STOPPED).hdfsAddress());
|
||||
"floci-network", null, NOT_STOPPED).hdfsAddress());
|
||||
|
||||
verify(lifecycle, never()).createAndStart(any());
|
||||
verify(lifecycle, never()).removeIfExists(anyString());
|
||||
@@ -388,7 +757,8 @@ class EmrClusterStorageTest {
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.UNKNOWN);
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", NOT_STOPPED));
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", null, NOT_STOPPED));
|
||||
|
||||
assertEquals("Could not tell whether the HDFS of EMR cluster j-1 runs", failure.getMessage());
|
||||
verify(lifecycle, never()).removeIfExists(anyString());
|
||||
@@ -407,7 +777,7 @@ class EmrClusterStorageTest {
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-7", 0L, "", "");
|
||||
|
||||
assertEquals("172.18.0.8", storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", NOT_STOPPED).hdfsAddress());
|
||||
"floci-network", null, NOT_STOPPED).hdfsAddress());
|
||||
|
||||
InOrder order = inOrder(lifecycle);
|
||||
order.verify(lifecycle).removeIfExistsStrict(hdfsName);
|
||||
@@ -423,7 +793,8 @@ class EmrClusterStorageTest {
|
||||
List<List<String>> looks = ContainerExecStubs.completeEveryExec(docker, "c-3", 1L, "", "");
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", NOT_STOPPED));
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", null, NOT_STOPPED));
|
||||
|
||||
assertEquals("The HDFS of EMR cluster j-1 stopped before it was ready", failure.getMessage());
|
||||
assertEquals(List.of(), looks);
|
||||
@@ -431,7 +802,8 @@ class EmrClusterStorageTest {
|
||||
|
||||
@Test
|
||||
void aClustersHdfsThatIsNotReadyInTimeFailsToStart() {
|
||||
EmrClusterStorage impatient = new EmrClusterStorage(lifecycle, containerBuilder, config, Duration.ZERO,
|
||||
EmrClusterStorage impatient = new EmrClusterStorage(lifecycle, containerBuilder, awsEnv,
|
||||
roleCredentials, currentContainer, config, Duration.ZERO,
|
||||
System::nanoTime);
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-4", Map.of()));
|
||||
@@ -439,7 +811,8 @@ class EmrClusterStorageTest {
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-4", 1L, "", "");
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> impatient.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", NOT_STOPPED));
|
||||
() -> impatient.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", null, NOT_STOPPED));
|
||||
|
||||
assertEquals("The HDFS of EMR cluster j-1 did not start within 0 seconds", failure.getMessage());
|
||||
}
|
||||
@@ -448,7 +821,8 @@ class EmrClusterStorageTest {
|
||||
void aStepWaitingWhileAnotherStartsItsClustersHdfsHasOnlyWhatIsLeftOfTheStartTimeout() throws Exception {
|
||||
AtomicLong clock = new AtomicLong();
|
||||
long timeout = Duration.ofMinutes(2).toNanos();
|
||||
EmrClusterStorage timed = new EmrClusterStorage(lifecycle, containerBuilder, config, Duration.ofMinutes(2),
|
||||
EmrClusterStorage timed = new EmrClusterStorage(lifecycle, containerBuilder, awsEnv,
|
||||
roleCredentials, currentContainer, config, Duration.ofMinutes(2),
|
||||
clock::get);
|
||||
// The first step starts it; the second, which waited for it, finds it running.
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING, ContainerLiveness.RUNNING);
|
||||
@@ -470,11 +844,12 @@ class EmrClusterStorageTest {
|
||||
ExecutorService steps = Executors.newFixedThreadPool(2);
|
||||
try {
|
||||
Future<SparkJobRunner.Storage> first = steps.submit(
|
||||
() -> timed.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", NOT_STOPPED));
|
||||
() -> timed.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", null, NOT_STOPPED));
|
||||
assertTrue(firstLooks.await(10, TimeUnit.SECONDS));
|
||||
Future<SparkJobRunner.Storage> waiting = steps.submit(() -> {
|
||||
second.set(Thread.currentThread());
|
||||
return timed.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", NOT_STOPPED);
|
||||
return timed.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", null, NOT_STOPPED);
|
||||
});
|
||||
|
||||
assertThrows(ExecutionException.class, () -> first.get(10, TimeUnit.SECONDS));
|
||||
@@ -492,7 +867,8 @@ class EmrClusterStorageTest {
|
||||
@Test
|
||||
void aStepWaitingForItsClustersHdfsThroughATeardownStopsAsItsDriverWouldAndStartsItNoMore() {
|
||||
AtomicLong clock = new AtomicLong();
|
||||
EmrClusterStorage timed = new EmrClusterStorage(lifecycle, containerBuilder, config, Duration.ofMinutes(2),
|
||||
EmrClusterStorage timed = new EmrClusterStorage(lifecycle, containerBuilder, awsEnv,
|
||||
roleCredentials, currentContainer, config, Duration.ofMinutes(2),
|
||||
clock::get);
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-5", Map.of()));
|
||||
@@ -505,7 +881,7 @@ class EmrClusterStorageTest {
|
||||
});
|
||||
|
||||
assertThrows(ClusterStorage.Stopped.class,
|
||||
() -> timed.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", NOT_STOPPED));
|
||||
() -> timed.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", null, NOT_STOPPED));
|
||||
|
||||
verify(lifecycle, times(1)).createAndStart(any());
|
||||
// As it starts, one left from before goes, and the teardown removes it; the step does again, in case it
|
||||
@@ -519,7 +895,7 @@ class EmrClusterStorageTest {
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
|
||||
assertThrows(ClusterStorage.Stopped.class,
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", () -> true));
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", null, () -> true));
|
||||
|
||||
verify(lifecycle, never()).createAndStart(any());
|
||||
verify(lifecycle, never()).removeIfExists(anyString());
|
||||
@@ -530,7 +906,8 @@ class EmrClusterStorageTest {
|
||||
@Test
|
||||
void theFirstPullOfItsImageIsNoPartOfTheHdfsStartTimeout() {
|
||||
AtomicLong clock = new AtomicLong();
|
||||
EmrClusterStorage timed = new EmrClusterStorage(lifecycle, containerBuilder, config, Duration.ofMinutes(2),
|
||||
EmrClusterStorage timed = new EmrClusterStorage(lifecycle, containerBuilder, awsEnv,
|
||||
roleCredentials, currentContainer, config, Duration.ofMinutes(2),
|
||||
clock::get);
|
||||
// The Hive image is not there yet, and its pull takes five minutes.
|
||||
when(lifecycle.resolveImageForLaunch(IMAGE, ImagePullBehavior.PREFER_CACHED, null)).thenAnswer(pull -> {
|
||||
@@ -544,7 +921,7 @@ class EmrClusterStorageTest {
|
||||
// Not ready the first time it is looked at, then ready.
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-4", List.of(1L, 0L), "", "");
|
||||
|
||||
assertEquals("172.18.0.11", timed.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network",
|
||||
assertEquals("172.18.0.11", timed.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", null,
|
||||
NOT_STOPPED).hdfsAddress());
|
||||
}
|
||||
|
||||
@@ -561,7 +938,7 @@ class EmrClusterStorageTest {
|
||||
when(running.exec()).thenReturn(List.of(other));
|
||||
|
||||
IllegalStateException failure = assertThrows(IllegalStateException.class,
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "host", NOT_STOPPED));
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "host", null, NOT_STOPPED));
|
||||
|
||||
// Its daemons, on the ports j-2's hold, would never bind, and j-2's would answer for them.
|
||||
assertEquals("The HDFS of EMR cluster j-1 cannot start while that of EMR cluster j-2 runs in the network"
|
||||
@@ -575,7 +952,8 @@ class EmrClusterStorageTest {
|
||||
void aStepCancelledWhileItsClustersHdfsStartsStopsAndLeavesItToTheClustersOtherSteps() {
|
||||
AtomicBoolean cancelled = new AtomicBoolean();
|
||||
AtomicLong clock = new AtomicLong();
|
||||
EmrClusterStorage timed = new EmrClusterStorage(lifecycle, containerBuilder, config, Duration.ofMinutes(2),
|
||||
EmrClusterStorage timed = new EmrClusterStorage(lifecycle, containerBuilder, awsEnv,
|
||||
roleCredentials, currentContainer, config, Duration.ofMinutes(2),
|
||||
clock::get);
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
when(lifecycle.createAndStart(any())).thenReturn(new ContainerLifecycleManager.ContainerInfo("c-8", Map.of()));
|
||||
@@ -588,7 +966,8 @@ class EmrClusterStorageTest {
|
||||
});
|
||||
|
||||
assertThrows(ClusterStorage.Stopped.class,
|
||||
() -> timed.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", cancelled::get));
|
||||
() -> timed.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", null, cancelled::get));
|
||||
|
||||
// Only one left from before went, as it started; the one it started is the next step's.
|
||||
verify(lifecycle, times(1)).removeIfExistsStrict(hdfsName);
|
||||
@@ -607,7 +986,7 @@ class EmrClusterStorageTest {
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-9", 0L, "", "");
|
||||
|
||||
assertEquals("172.18.0.10", storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", NOT_STOPPED).hdfsAddress());
|
||||
"floci-network", null, NOT_STOPPED).hdfsAddress());
|
||||
|
||||
verify(lifecycle).createAndStart(any());
|
||||
}
|
||||
@@ -619,7 +998,8 @@ class EmrClusterStorageTest {
|
||||
when(docker.execCreateCmd(hdfsName)).thenThrow(new DockerException("The daemon is busy", 500));
|
||||
|
||||
assertThrows(DockerException.class,
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", NOT_STOPPED));
|
||||
() -> storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE,
|
||||
"floci-network", null, NOT_STOPPED));
|
||||
|
||||
verify(lifecycle, never()).createAndStart(any());
|
||||
verify(lifecycle, never()).removeIfExists(anyString());
|
||||
@@ -675,7 +1055,7 @@ class EmrClusterStorageTest {
|
||||
when(lifecycle.resolveContainerNetworkIp(hdfsName, hdfsName)).thenReturn("172.18.0.9");
|
||||
runningOn(hdfsName, hdfsName);
|
||||
ContainerExecStubs.completeEveryExec(docker, hdfsName, 0L, "", "");
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", NOT_STOPPED);
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", null, NOT_STOPPED);
|
||||
|
||||
assertFalse(storage.remove("j-1"));
|
||||
// The next reset or shutdown removes it.
|
||||
@@ -688,7 +1068,7 @@ class EmrClusterStorageTest {
|
||||
void withNoNetworkItsStepsRunWithoutAnHdfs() {
|
||||
when(containerBuilder.resolveDockerNetwork(Optional.of("none"))).thenReturn(Optional.of("none"));
|
||||
|
||||
SparkJobRunner.Storage storageOnly = storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "none",
|
||||
SparkJobRunner.Storage storageOnly = storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "none", null,
|
||||
NOT_STOPPED);
|
||||
|
||||
// Docker joins a container placed there to no network, the HDFS's included.
|
||||
@@ -709,7 +1089,7 @@ class EmrClusterStorageTest {
|
||||
when(lifecycle.probeContainer("c-1")).thenReturn(ContainerLiveness.RUNNING);
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-1", 0L, "", "");
|
||||
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "container:b", NOT_STOPPED);
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "container:b", null, NOT_STOPPED);
|
||||
|
||||
verify(lifecycle).createAndStart(any());
|
||||
verify(spec).withDockerNetwork(Optional.of("container:b"));
|
||||
@@ -726,7 +1106,7 @@ class EmrClusterStorageTest {
|
||||
containerIdOf("3333", "3333");
|
||||
ContainerExecStubs.completeEveryExec(docker, hdfsName, 0L, "", "");
|
||||
|
||||
assertEquals("127.0.0.1", storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "container:floci",
|
||||
assertEquals("127.0.0.1", storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "container:floci", null,
|
||||
NOT_STOPPED).hdfsAddress());
|
||||
|
||||
verify(lifecycle, never()).createAndStart(any());
|
||||
@@ -748,7 +1128,7 @@ class EmrClusterStorageTest {
|
||||
when(lifecycle.probeContainer("c-1")).thenReturn(ContainerLiveness.RUNNING);
|
||||
ContainerExecStubs.completeEveryExec(docker, "c-1", 0L, "", "");
|
||||
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "container:b", NOT_STOPPED);
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "container:b", null, NOT_STOPPED);
|
||||
|
||||
verify(lifecycle).createAndStart(any());
|
||||
}
|
||||
@@ -759,7 +1139,7 @@ class EmrClusterStorageTest {
|
||||
when(lifecycle.resolveContainerNetworkIp(hdfsName, hdfsName)).thenReturn("172.18.0.9");
|
||||
runningOn(hdfsName, hdfsName);
|
||||
ContainerExecStubs.completeEveryExec(docker, hdfsName, 0L, "", "");
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", NOT_STOPPED);
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", null, NOT_STOPPED);
|
||||
|
||||
storage.stopManagedContainers();
|
||||
storage.stopManagedContainers();
|
||||
@@ -775,7 +1155,7 @@ class EmrClusterStorageTest {
|
||||
when(lifecycle.resolveContainerNetworkIp(hdfsName, hdfsName)).thenReturn("172.18.0.9");
|
||||
runningOn(hdfsName, hdfsName);
|
||||
ContainerExecStubs.completeEveryExec(docker, hdfsName, 0L, "", "");
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", NOT_STOPPED);
|
||||
storage.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", null, NOT_STOPPED);
|
||||
doThrow(new IllegalStateException("Failed to remove container " + hdfsName)).doNothing()
|
||||
.when(lifecycle).removeIfExistsStrict(hdfsName);
|
||||
|
||||
@@ -850,6 +1230,30 @@ class EmrClusterStorageTest {
|
||||
verify(lifecycle, times(2)).removeIfExistsStrict(ended);
|
||||
}
|
||||
|
||||
@Test
|
||||
void theSweepHasFlocisContainerLeaveTheNetworksItRemoves() {
|
||||
when(currentContainer.resolveContainerId()).thenReturn(Optional.of("floci-container"));
|
||||
ListContainersCmd list = mock(ListContainersCmd.class, RETURNS_SELF);
|
||||
when(docker.listContainersCmd()).thenReturn(list);
|
||||
when(list.exec()).thenReturn(List.of());
|
||||
ListNetworksCmd networks = mock(ListNetworksCmd.class, RETURNS_SELF);
|
||||
when(docker.listNetworksCmd()).thenReturn(networks);
|
||||
Network keptNetwork = hdfsNetwork("emr-j-up-hdfs", "j-up");
|
||||
Network goneNetwork = hdfsNetwork("emr-j-ended-hdfs", "j-ended");
|
||||
when(networks.exec()).thenReturn(List.of(keptNetwork, goneNetwork));
|
||||
ListVolumesCmd volumes = mock(ListVolumesCmd.class, RETURNS_SELF);
|
||||
when(docker.listVolumesCmd()).thenReturn(volumes);
|
||||
when(volumes.exec()).thenReturn(mock(ListVolumesResponse.class));
|
||||
|
||||
storage.removeAllBut(Set.of("j-up"));
|
||||
|
||||
// An earlier Floci's container, this one after a restart, joined it, and Docker removes no network in use.
|
||||
InOrder order = inOrder(lifecycle);
|
||||
order.verify(lifecycle).disconnectFromNetwork("floci-container", "emr-j-ended-hdfs");
|
||||
order.verify(lifecycle).removeNetwork("emr-j-ended-hdfs");
|
||||
verify(lifecycle, never()).disconnectFromNetwork("floci-container", "emr-j-up-hdfs");
|
||||
}
|
||||
|
||||
// The container name runs with networkMode as its network mode, as Docker inspects it.
|
||||
private void runningOn(String name, String networkMode) {
|
||||
InspectContainerCmd inspect = mock(InspectContainerCmd.class);
|
||||
|
||||
@@ -77,7 +77,7 @@ class EmrHiveStepsDockerIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void hiveStepsKeepTheirTablesInTheClustersMetastoreAndHdfsForTheStepsAfterThem() {
|
||||
void hiveAndSparkStepsShareTheClustersMetastoreServiceAndHdfs() {
|
||||
startCluster(HIVE_AND_SPARK, "[]", null);
|
||||
put("queries/load.q", """
|
||||
create external table kv (k string, v int)
|
||||
@@ -107,8 +107,39 @@ class EmrHiveStepsDockerIntegrationTest {
|
||||
String pinned = addStep("command-runner.jar", "hadoop", "fs", "-cat", "hdfs:///floci/pinned/*");
|
||||
assertEquals("COMPLETED", state(pinned));
|
||||
assertEquals("a\nb\nc\n", stepLog(pinned, "stdout.gz"));
|
||||
// The metastore is the cluster's own, a database in its /mnt.
|
||||
assertEquals("COMPLETED", state(addStep("command-runner.jar", "test", "-d", "/mnt/var/lib/hive/metastore_db")));
|
||||
// A Spark step uses the cluster's metastore too: it reads Hive's table, and makes one a Hive step reads.
|
||||
put("jobs/catalog.py", """
|
||||
import sys
|
||||
from pyspark.sql import SparkSession
|
||||
spark = SparkSession.builder.enableHiveSupport().getOrCreate()
|
||||
rows = sorted(f"{row.k}{row.v}" for row in spark.sql("select k, v from scaled").collect())
|
||||
spark.createDataFrame([(" ".join(rows),)], ["value"]).coalesce(1).write.text(sys.argv[1])
|
||||
spark.sql("create table from_spark stored as textfile as select upper(k) as k from scaled")
|
||||
""");
|
||||
assertEquals("COMPLETED", state(addStep("command-runner.jar", "spark-submit", s3Uri("jobs/catalog.py"),
|
||||
s3Uri("out/spark/"))));
|
||||
assertEquals("a10 b20 c30\n", objects("out/spark/"));
|
||||
String fromSpark = addStep("command-runner.jar", "hive-script", "--run-hive-script", "--args",
|
||||
"-e", "select k from from_spark order by k;");
|
||||
assertEquals("COMPLETED", state(fromSpark));
|
||||
assertTrue(stepLog(fromSpark, "stdout.gz").contains("A\nB\nC\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hiveStepsRunningAtOnceShareTheClustersMetastoreService() {
|
||||
startCluster(HIVE_AND_SPARK, "[]", null, 2);
|
||||
|
||||
// The first holds its session past the second's, which an embedded Derby database would refuse.
|
||||
String slow = addStep("command-runner.jar", "hive-script", "--run-hive-script", "--args",
|
||||
"-e", "create table slow (k string); !sleep 20; insert into slow values ('s');");
|
||||
String quick = addStep("command-runner.jar", "hive-script", "--run-hive-script", "--args",
|
||||
"-e", "create table quick as select 'q' as k;");
|
||||
assertEquals("COMPLETED", state(quick));
|
||||
assertEquals("COMPLETED", state(slow));
|
||||
String both = addStep("command-runner.jar", "hive-script", "--run-hive-script", "--args",
|
||||
"-e", "select k from slow union all select k from quick order by k;");
|
||||
assertEquals("COMPLETED", state(both));
|
||||
assertTrue(stepLog(both, "stdout.gz").contains("q\ns\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,8 +193,14 @@ class EmrHiveStepsDockerIntegrationTest {
|
||||
|
||||
/** A cluster with {@code applications}, {@code configurations} and a bootstrap action's script, if not null. */
|
||||
private void startCluster(String applications, String configurations, String bootstrapScript) {
|
||||
startCluster(applications, configurations, bootstrapScript, 1);
|
||||
}
|
||||
|
||||
/** As {@link #startCluster(String, String, String)}, running up to {@code stepConcurrency} steps at once. */
|
||||
private void startCluster(String applications, String configurations, String bootstrapScript,
|
||||
int stepConcurrency) {
|
||||
ObjectNode request = JSON.createObjectNode().put("Name", "hive-steps").put("ReleaseLabel", "emr-7.5.0")
|
||||
.put("LogUri", s3Uri("logs/"));
|
||||
.put("LogUri", s3Uri("logs/")).put("StepConcurrencyLevel", stepConcurrency);
|
||||
try {
|
||||
request.set("Applications", JSON.readTree(applications));
|
||||
request.set("Configurations", JSON.readTree(configurations));
|
||||
|
||||
@@ -333,12 +333,13 @@ class EmrServiceContainerStepsTest {
|
||||
assertEquals(3, service.listInstanceGroups(cluster.getId()).get(0).getRunningInstanceCount());
|
||||
fixture.runStepThread();
|
||||
|
||||
// A cluster without Hive runs no metastore service.
|
||||
List<String> started = Arrays.asList(cluster.getId(), "ip-10-0-0-1.ec2.internal",
|
||||
"public.ecr.aws/emr-serverless/hive/emr-7.5.0:latest", null);
|
||||
"public.ecr.aws/emr-serverless/hive/emr-7.5.0:latest", null, "false", null);
|
||||
assertEquals(List.of(started, started), fixture.clusterStorage.hdfs);
|
||||
assertEquals(new SparkJobRunner.Storage(cluster.getId() + "-home", cluster.getId() + "-mnt",
|
||||
"ip-10-0-0-1.ec2.internal", EmrServiceFixture.RecordingStorage.HDFS_ADDRESS,
|
||||
EmrServiceFixture.RecordingStorage.HDFS_NETWORK), runner.jobs.get(0).storage());
|
||||
assertEquals(new SparkJobRunner.Storage(cluster.getId() + "-home", cluster.getId() + "-mnt")
|
||||
.withHdfs("ip-10-0-0-1.ec2.internal", EmrServiceFixture.RecordingStorage.HDFS_ADDRESS,
|
||||
EmrServiceFixture.RecordingStorage.HDFS_NETWORK), runner.jobs.get(0).storage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -824,7 +825,10 @@ class EmrServiceContainerStepsTest {
|
||||
// Its cluster's Spark settings are not Hive's.
|
||||
assertEquals(Map.of(), job.sparkDefaults());
|
||||
assertEquals(Map.of("HADOOP_HEAPSIZE", "2048"), job.environment());
|
||||
assertEquals(hdfsStorage(cluster), job.storage());
|
||||
// A cluster with Hive's primary node runs its metastore service, which its steps use, with its hive-site.
|
||||
assertEquals("true", fixture.clusterStorage.hdfs.get(0).get(4));
|
||||
assertEquals(Map.of("hive.exec.reducers.max", "8"), fixture.clusterStorage.metastores.get(0).settings());
|
||||
assertEquals(hdfsStorage(cluster).withHiveMetastore("thrift://ip-10-0-0-1.ec2.internal:9083"), job.storage());
|
||||
assertEquals("s3://logs/emr/" + cluster.getId() + "/steps/" + stepId + "/", job.logFolder());
|
||||
assertEquals(List.of(cluster.getId()), fixture.clusterStorage.created);
|
||||
assertEquals("COMPLETED", service.describeStep(cluster.getId(), stepId).getState());
|
||||
@@ -1227,9 +1231,9 @@ class EmrServiceContainerStepsTest {
|
||||
// A spark-submit step through command-runner.jar, written for a cluster with YARN.
|
||||
// A cluster's storage as a step gets it, its HDFS on the primary node of a cluster with no instance groups.
|
||||
private static SparkJobRunner.Storage hdfsStorage(EmrCluster cluster) {
|
||||
return new SparkJobRunner.Storage(cluster.getId() + "-home", cluster.getId() + "-mnt",
|
||||
"ip-10-0-0-1.ec2.internal", EmrServiceFixture.RecordingStorage.HDFS_ADDRESS,
|
||||
EmrServiceFixture.RecordingStorage.HDFS_NETWORK);
|
||||
return new SparkJobRunner.Storage(cluster.getId() + "-home", cluster.getId() + "-mnt")
|
||||
.withHdfs("ip-10-0-0-1.ec2.internal", EmrServiceFixture.RecordingStorage.HDFS_ADDRESS,
|
||||
EmrServiceFixture.RecordingStorage.HDFS_NETWORK);
|
||||
}
|
||||
|
||||
// The AWS CLI's Hive step: command-runner.jar running hive-script with the step's arguments after its --args.
|
||||
|
||||
@@ -63,6 +63,8 @@ final class EmrServiceFixture {
|
||||
final List<String> created = new ArrayList<>();
|
||||
// Each HDFS started: its cluster, primary node's host name, image and Docker network.
|
||||
final List<List<String>> hdfs = new ArrayList<>();
|
||||
// Each HDFS's metastore service asked for.
|
||||
final List<HiveMetastore> metastores = new ArrayList<>();
|
||||
RuntimeException hdfsFailure;
|
||||
// Runs as each HDFS starts, with what tells it the step is past starting.
|
||||
Consumer<BooleanSupplier> whileStartingHdfs = stopped -> { };
|
||||
@@ -84,13 +86,19 @@ final class EmrServiceFixture {
|
||||
|
||||
@Override
|
||||
public SparkJobRunner.Storage hdfs(String clusterId, String accountId, String region, String host,
|
||||
String image, String dockerNetwork, BooleanSupplier stopped) {
|
||||
hdfs.add(Arrays.asList(clusterId, host, image, dockerNetwork));
|
||||
String image, String dockerNetwork, HiveMetastore hiveMetastore,
|
||||
BooleanSupplier stopped) {
|
||||
hdfs.add(Arrays.asList(clusterId, host, image, dockerNetwork, String.valueOf(hiveMetastore != null),
|
||||
hiveMetastore != null ? hiveMetastore.role() : null));
|
||||
if (hiveMetastore != null) {
|
||||
metastores.add(hiveMetastore);
|
||||
}
|
||||
whileStartingHdfs.accept(stopped);
|
||||
if (hdfsFailure != null) {
|
||||
throw hdfsFailure;
|
||||
}
|
||||
return volumes(clusterId).withHdfs(host, HDFS_ADDRESS, HDFS_NETWORK);
|
||||
SparkJobRunner.Storage storage = volumes(clusterId).withHdfs(host, HDFS_ADDRESS, HDFS_NETWORK);
|
||||
return hiveMetastore != null ? storage.withHiveMetastore("thrift://" + host + ":9083") : storage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -297,6 +297,27 @@ class EmrSparkStepsTest {
|
||||
assertEquals(Map.of(), EmrSparkSteps.coreSite(null, objectMapper));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aClustersHiveMetastoreServiceGetsItsCoreSiteThenItsHiveSiteWhichWins() {
|
||||
String configurations = """
|
||||
[{"Classification": "core-site", "Properties": {"fs.s3a.connection.maximum": "50",
|
||||
"hive.exec.scratchdir": "/tmp/core"}},
|
||||
{"Classification": "hive-site", "Properties": {"hive.exec.scratchdir": "/tmp/hive",
|
||||
"hive.metastore.warehouse.dir": "s3://bucket/warehouse/"}},
|
||||
{"Classification": "spark-hive-site", "Properties": {"hive.metastore.warehouse.dir": "s3://other/"}},
|
||||
{"Classification": "tez-site", "Properties": {"tez.am.resource.memory.mb": "2048"}}]
|
||||
""";
|
||||
|
||||
Map<String, String> settings = EmrSparkSteps.hiveMetastoreSettings(configurations, objectMapper);
|
||||
|
||||
// Not spark-hive-site, Spark's own, nor tez-site, which the service does not read.
|
||||
assertEquals(Map.of("fs.s3a.connection.maximum", "50", "hive.exec.scratchdir", "/tmp/hive",
|
||||
"hive.metastore.warehouse.dir", "s3://bucket/warehouse/"), settings);
|
||||
assertEquals(List.of("fs.s3a.connection.maximum", "hive.exec.scratchdir", "hive.metastore.warehouse.dir"),
|
||||
List.copyOf(settings.keySet()));
|
||||
assertEquals(Map.of(), EmrSparkSteps.hiveMetastoreSettings(null, objectMapper));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theClustersSparkLog4j2PropertiesComeFromItsConfigurations() {
|
||||
String configurations = """
|
||||
|
||||
+45
-6
@@ -82,8 +82,8 @@ class EmrServerlessSparkRunnerTest {
|
||||
private static final String ENDPOINT = "http://floci:4566";
|
||||
// A cluster's storage, its HDFS running on its primary node.
|
||||
private static final SparkJobRunner.Storage STORAGE = new SparkJobRunner.Storage(
|
||||
"floci-aws-emr-j-2AXXXXXXGAPLF-home", "floci-aws-emr-j-2AXXXXXXGAPLF-mnt", "ip-10-0-0-1.ec2.internal",
|
||||
"172.18.0.5", "floci-aws-emr-j-2AXXXXXXGAPLF-hdfs");
|
||||
"floci-aws-emr-j-2AXXXXXXGAPLF-home", "floci-aws-emr-j-2AXXXXXXGAPLF-mnt")
|
||||
.withHdfs("ip-10-0-0-1.ec2.internal", "172.18.0.5", "floci-aws-emr-j-2AXXXXXXGAPLF-hdfs");
|
||||
|
||||
private final EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
private final ContainerLifecycleManager lifecycle = mock(ContainerLifecycleManager.class);
|
||||
@@ -249,11 +249,29 @@ class EmrServerlessSparkRunnerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void anEmrHiveStepsHiveReachesItsClustersHdfsAndKeepsItsMetastoreInItsMnt() {
|
||||
void anEmrHiveStepsHiveReachesItsClustersHdfsAndMetastoreServiceOnItsPrimaryNode() {
|
||||
List<String> arguments = EmrServerlessSparkRunner.hiveArguments(
|
||||
hiveStep(List.of("--hiveconf", "hive.exec.reducers.max=8", "-f", "s3://bucket/queries/report.q")),
|
||||
ENDPOINT);
|
||||
|
||||
int tez = arguments.indexOf("tez.am.client.am.port-range=40000-40100");
|
||||
assertEquals(List.of(
|
||||
"--hiveconf", "fs.defaultFS=hdfs://ip-10-0-0-1.ec2.internal:8020",
|
||||
"--hiveconf", "hive.metastore.client.factory.class="
|
||||
+ "org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClientFactory",
|
||||
"--hiveconf", "hive.metastore.uris=thrift://ip-10-0-0-1.ec2.internal:9083",
|
||||
"--hiveconf", "hive.exec.reducers.max=8", "-f", "s3://bucket/queries/report.q"),
|
||||
arguments.subList(tez + 1, arguments.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anEmrHiveStepWhereNoMetastoreServiceRunsKeepsItsMetastoreInItsClustersMnt() {
|
||||
// As in a network namespace the steps share, where the service would listen on every interface.
|
||||
SparkJobRunner.Job step = hiveStep(List.of("-f", "s3://bucket/queries/report.q"));
|
||||
List<String> arguments = EmrServerlessSparkRunner.hiveArguments(step.onStorage(
|
||||
new SparkJobRunner.Storage("j-1-home", "j-1-mnt").withHdfs("ip-10-0-0-1.ec2.internal", "127.0.0.1",
|
||||
null)), ENDPOINT);
|
||||
|
||||
int tez = arguments.indexOf("tez.am.client.am.port-range=40000-40100");
|
||||
assertEquals(List.of(
|
||||
"--hiveconf", "fs.defaultFS=hdfs://ip-10-0-0-1.ec2.internal:8020",
|
||||
@@ -263,8 +281,11 @@ class EmrServerlessSparkRunnerTest {
|
||||
+ "jdbc:derby:;databaseName=/mnt/var/lib/hive/metastore_db;create=true",
|
||||
"--hiveconf", "hive.metastore.schema.verification=false",
|
||||
"--hiveconf", "datanucleus.schema.autoCreateAll=true",
|
||||
"--hiveconf", "hive.exec.reducers.max=8", "-f", "s3://bucket/queries/report.q"),
|
||||
"-f", "s3://bucket/queries/report.q"),
|
||||
arguments.subList(tez + 1, arguments.size()));
|
||||
// Nor does its Spark steps' Hive client get one.
|
||||
assertFalse(EmrServerlessSparkRunner.sparkSubmitArguments(stepJob(Map.of()), ENDPOINT).stream()
|
||||
.anyMatch(argument -> argument.startsWith("spark.hadoop.hive.metastore.uris=")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -592,6 +613,23 @@ class EmrServerlessSparkRunnerTest {
|
||||
"s3://bucket/jobs/report.py"), arguments.subList(20, arguments.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSparkStepOnAClusterWithHiveUsesItsMetastoreServiceUnlessItsSparkHiveSiteNamesAnother() {
|
||||
String glue = "spark.hadoop.hive.metastore.client.factory.class="
|
||||
+ "com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory";
|
||||
SparkJobRunner.Job job = stepJob(Map.of("spark.hadoop.hive.metastore.client.factory.class",
|
||||
"com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory"))
|
||||
.onStorage(STORAGE.withHiveMetastore("thrift://ip-10-0-0-1.ec2.internal:9083"));
|
||||
|
||||
List<String> arguments = EmrServerlessSparkRunner.sparkSubmitArguments(job, ENDPOINT);
|
||||
|
||||
int metastore = arguments.indexOf("spark.hadoop.hive.metastore.uris=thrift://ip-10-0-0-1.ec2.internal:9083");
|
||||
assertTrue(metastore > 0, arguments.toString());
|
||||
assertEquals("--conf", arguments.get(metastore - 1));
|
||||
// Floci's, before the cluster's spark-defaults and spark-hive-site, which win.
|
||||
assertTrue(arguments.indexOf(glue) > metastore, arguments.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aCommandOnAClusterGivesItsHadoopCommandTheClustersHdfsToo() {
|
||||
ContainerBuilder builder = mock(ContainerBuilder.class);
|
||||
@@ -1438,8 +1476,9 @@ class EmrServerlessSparkRunnerTest {
|
||||
return new SparkJobRunner.Job("emr", "s-1", "123456789012", "eu-west-1", "emr-7.5.0", HIVE, null, null,
|
||||
"floci-network", "arn:aws:iam::123456789012:role/emr-ec2", Map.of(), application,
|
||||
List.of("hive-script", "--run-hive-script", "--args"), Duration.ZERO, null, null, Map.of(), List.of(),
|
||||
new SparkJobRunner.Storage("j-1-home", "j-1-mnt", "ip-10-0-0-1.ec2.internal", "172.18.0.5",
|
||||
"j-1-hdfs"), Map.of(), Map.of(), Map.of(), Map.of(), Map.of());
|
||||
new SparkJobRunner.Storage("j-1-home", "j-1-mnt").withHdfs("ip-10-0-0-1.ec2.internal", "172.18.0.5",
|
||||
"j-1-hdfs").withHiveMetastore("thrift://ip-10-0-0-1.ec2.internal:9083"),
|
||||
Map.of(), Map.of(), Map.of(), Map.of(), Map.of());
|
||||
}
|
||||
|
||||
private static SparkJobRunner.Job customImageJob(String customImage) {
|
||||
|
||||
Reference in new issue
Block a user