mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
refactor(emr): run Floci's Trino through a query engine interface (#9848)
Floci's Trino machinery, its coordinator beside the metastore, its workers, catalogs, CLI step command, outside host, readiness and password authenticator files, now reads what is Trino's own from an EmrQueryEngine, which EmrTrino implements, so that PrestoDB can be another engine. Nothing a user sees changes: container names, labels, messages, settings and the cluster image's name stay as they were. The variables a Trino container's entrypoint writes its files from are now FLOCI_ENGINE_*.
This commit is contained in:
1 parent
a0d4cc0ac8
commit
7b74d7f797
18 files changed
+1098
-753
No files matched your search
@@ -46,8 +46,8 @@ public interface ClusterStorage {
|
||||
}
|
||||
|
||||
/**
|
||||
* Cluster {@code clusterId}'s network, its own, made when missing, with its instance metadata relay running there in
|
||||
* {@code relayImage}, which the cluster's containers join to read their nodes' metadata at 169.254.169.254; null
|
||||
* Cluster {@code clusterId}'s network, its own, made when missing, with its instance metadata relay running there
|
||||
* in {@code relayImage}, which the cluster's containers join to read their nodes' metadata at 169.254.169.254; null
|
||||
* where its steps share a namespace or have no network, or no relay serves the metadata.
|
||||
*/
|
||||
default String metadataNetwork(String clusterId, String accountId, String region, String relayImage,
|
||||
@@ -82,12 +82,11 @@ public interface ClusterStorage {
|
||||
* unless it is running, and returns the cluster's storage with them: its primary node's {@code host} name, which a
|
||||
* step's container resolves to the address given, on the network given, the metastore's URI, and YARN's
|
||||
* ResourceManager with the address Floci has on that network, the metastore and YARN only on a network of the
|
||||
* cluster's own, where Trino's coordinator runs too, in a container of its own on the primary node's network,
|
||||
* when {@code hiveMetastore} asks for it, and its workers ({@link Trino}). Its core and task nodes, {@code yarn}'s,
|
||||
* run in containers of their own on that network, and {@code yarn} is read as they start, so a resize since the
|
||||
* step was queued counts, as Trino's own nodes are. A failure
|
||||
* to start them is thrown, and {@link Stopped} once {@code stopped} says the step is past starting, or a teardown
|
||||
* has stopped the HDFS.
|
||||
* cluster's own, where its query engine's coordinator runs too, in a container of its own on the primary node's
|
||||
* network, when {@code hiveMetastore} asks for it, and its workers ({@link QueryEngine}). Its core and task nodes,
|
||||
* {@code yarn}'s, run in containers of their own on that network, and {@code yarn} is read as they start, so a
|
||||
* resize since the step was queued counts, as the engine's own nodes are. A failure to start them is thrown, and
|
||||
* {@link Stopped} once {@code stopped} says the step is past starting, or a teardown has stopped the HDFS.
|
||||
*/
|
||||
SparkJobRunner.Storage hdfs(String clusterId, String accountId, String region, String host, String image,
|
||||
String dockerNetwork, HiveMetastore hiveMetastore, Supplier<Yarn> yarn,
|
||||
@@ -101,12 +100,12 @@ public interface ClusterStorage {
|
||||
void resize(String clusterId, Supplier<Yarn> yarn);
|
||||
|
||||
/**
|
||||
* Brings the Trino workers of {@code clusterId}, a cluster whose Trino has nodes of its own
|
||||
* ({@link Trino#ownNodes}), to its core and task nodes as they are at that moment, when a step has started its
|
||||
* Trino: a worker on a node that is new starts, and one on a node that is no longer wanted goes, while the rest
|
||||
* carry on. Clusters no step has started yet get theirs when one does.
|
||||
* Brings the query engine's workers of {@code clusterId}, a cluster whose engine has nodes of its own
|
||||
* ({@link QueryEngine#ownNodes}), to its core and task nodes as they are at that moment, when a step has started
|
||||
* its engine: a worker on a node that is new starts, and one on a node that is no longer wanted goes, while the
|
||||
* rest carry on. Clusters no step has started yet get theirs when one does.
|
||||
*/
|
||||
default void resizeTrino(String clusterId) {
|
||||
default void resizeQueryEngine(String clusterId) {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,49 +118,50 @@ public interface ClusterStorage {
|
||||
|
||||
/**
|
||||
* Hive's metastore service on a cluster's primary node, which reaches S3 as the cluster's EC2 instance profile's
|
||||
* {@code role} does, or as its account when that is null, with the cluster's {@code settings}, its
|
||||
* {@code core-site} and {@code hive-site} properties, after its own, and {@code trino} beside it unless that is
|
||||
* {@code role} does, or as its account when that is null, with the cluster's {@code settings}, its {@code
|
||||
* core-site} and {@code hive-site} properties, after its own, and {@code queryEngine} beside it unless that is
|
||||
* null, as EMR installs {@code hcatalog-server} with Trino; with the cluster's HDFS unless {@code hdfs} is false,
|
||||
* as on a cluster with Trino alone from emr-7.14.0 ({@link EmrSparkSteps#trinoAlone}), whose primary node runs
|
||||
* the metastore without it.
|
||||
* as on a cluster with Trino alone from emr-7.14.0 ({@link EmrSparkSteps#trinoAlone}), whose primary node runs the
|
||||
* metastore without it.
|
||||
*/
|
||||
record HiveMetastore(String role, Map<String, String> settings, Trino trino, boolean hdfs) {
|
||||
record HiveMetastore(String role, Map<String, String> settings, QueryEngine queryEngine, boolean hdfs) {
|
||||
|
||||
/** The metastore alone, beside the cluster's HDFS. */
|
||||
HiveMetastore(String role, Map<String, String> settings) {
|
||||
this(role, settings, null, true);
|
||||
}
|
||||
|
||||
/** The metastore and {@code trino}, beside the cluster's HDFS. */
|
||||
HiveMetastore(String role, Map<String, String> settings, Trino trino) {
|
||||
this(role, settings, trino, true);
|
||||
/** The metastore and {@code queryEngine}, beside the cluster's HDFS. */
|
||||
HiveMetastore(String role, Map<String, String> settings, QueryEngine queryEngine) {
|
||||
this(role, settings, queryEngine, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Trino on a cluster: its coordinator on the primary node, and its workers on the core and task nodes, no more than
|
||||
* {@code maxWorkers} of them, each container getting {@code workerMemoryMb}. The {@code image} they run from, the
|
||||
* memory the coordinator's container gets,
|
||||
* the cluster's {@code trino-connector-<catalog>} properties by catalog, which its catalogs get after Floci's (see
|
||||
* {@link EmrTrino#catalogs}), its {@code trino-config} properties, which its {@code config.properties} gets after
|
||||
* Floci's (see {@link EmrTrino#config}), its {@code trino-node} and {@code trino-log} properties, which its
|
||||
* {@code node.properties} and {@code log.properties} get after its image's own (see {@link EmrTrino#ENTRYPOINT}),
|
||||
* the variables its {@code trino-env} exports, which its environment gets after Floci's own, its
|
||||
* {@code trino-exchange-manager} properties, null where it has none, which make its exchange manager (see
|
||||
* {@link EmrTrino#exchangeManager}), its {@code trino-password-authenticator} properties, which make its password
|
||||
* authenticator, and the image its bootstrap actions left, null where it has none, from which the files those
|
||||
* properties name are copied into the coordinator's container ({@link EmrTrino#authenticatorFiles}), as EMR's
|
||||
* Trino finds what they wrote on the primary node it runs on, and into a worker's from its node's own, else that
|
||||
* one. Every node reaches S3 and Glue as the metastore does. Its workers run on {@code yarn}'s nodes, sharing each
|
||||
* node's network, on a cluster that runs YARN, and on {@code ownNodes}, its core and task nodes as they are when
|
||||
* read, on one with Trino alone from emr-7.14.0, whose nodes run no YARN or HDFS
|
||||
* ({@link EmrSparkSteps#trinoAlone}): there a worker is all its node runs, in a container of its own on the
|
||||
* cluster's network at its node's host name. {@code ownNodes} is null on any other cluster.
|
||||
* A query engine on a cluster, {@code engine}, Trino: its coordinator on the primary node, and its workers on the
|
||||
* core and task nodes, no more than {@code maxWorkers} of them, each container getting {@code workerMemoryMb}. The
|
||||
* {@code image} they run from, the memory the coordinator's container gets, the cluster's {@code
|
||||
* <engine>-connector-<catalog>} properties by catalog, which its catalogs get after Floci's (see {@link
|
||||
* EmrQueryEngine#catalogs}), its {@code <engine>-config} properties, which its {@code config.properties} gets after
|
||||
* Floci's (see {@link EmrQueryEngine#config}), its {@code <engine>-node} and {@code <engine>-log} properties, which
|
||||
* its {@code node.properties} and {@code log.properties} get after its image's own (see {@link
|
||||
* EmrQueryEngine#entrypoint}), the variables its {@code <engine>-env} exports, which its environment gets after
|
||||
* Floci's own, its {@code trino-exchange-manager} properties, null where it has none, which make its exchange
|
||||
* manager (see {@link EmrTrino#exchangeManager}), its {@code <engine>-password-authenticator} properties, which
|
||||
* make its password authenticator, and the image its bootstrap actions left, null where it has none, from which the
|
||||
* files those properties name are copied into the coordinator's container ({@link
|
||||
* EmrQueryEngine#authenticatorFiles}), as EMR's engine finds what they wrote on the primary node it runs on, and
|
||||
* into a worker's from its node's own, else that one. Every node reaches S3 and Glue as the metastore does. Its
|
||||
* workers run on {@code yarn}'s nodes, sharing each node's network, on a cluster that runs YARN, and on {@code
|
||||
* ownNodes}, its core and task nodes as they are when read, on one with Trino alone from emr-7.14.0, whose nodes
|
||||
* run no YARN or HDFS ({@link EmrSparkSteps#trinoAlone}): there a worker is all its node runs, in a container of
|
||||
* its own on the cluster's network at its node's host name. {@code ownNodes} is null on any other cluster.
|
||||
*/
|
||||
record Trino(String image, int memoryMb, Map<String, Map<String, String>> connectors, Map<String, String> config,
|
||||
Map<String, String> node, Map<String, String> log, Map<String, String> environment,
|
||||
Map<String, String> exchangeManager, Map<String, String> passwordAuthenticator,
|
||||
String bootstrapImage, int maxWorkers, int workerMemoryMb, Supplier<List<Node>> ownNodes) {
|
||||
record QueryEngine(EmrQueryEngine engine, String image, int memoryMb, Map<String, Map<String, String>> connectors,
|
||||
Map<String, String> config, Map<String, String> node, Map<String, String> log,
|
||||
Map<String, String> environment, Map<String, String> exchangeManager,
|
||||
Map<String, String> passwordAuthenticator, String bootstrapImage, int maxWorkers,
|
||||
int workerMemoryMb, Supplier<List<Node>> ownNodes) {
|
||||
|
||||
/**
|
||||
* The nodes that run its workers: {@code yarn}'s, else its own, read now, else none
|
||||
@@ -248,10 +248,10 @@ public interface ClusterStorage {
|
||||
}
|
||||
|
||||
/**
|
||||
* Where Floci reaches {@code port}, its Trino's, on {@code clusterId}'s primary node: empty until that Trino has
|
||||
* answered queries ({@link #hdfs}), and while it is not running, or where Floci cannot reach it.
|
||||
* Where Floci reaches {@code port}, its query engine's, on {@code clusterId}'s primary node: empty until that
|
||||
* engine has answered queries ({@link #hdfs}), and while it is not running, or where Floci cannot reach it.
|
||||
*/
|
||||
default Optional<ContainerLifecycleManager.EndpointInfo> trinoInterface(String clusterId, int port) {
|
||||
default Optional<ContainerLifecycleManager.EndpointInfo> queryEngineInterface(String clusterId, int port) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,193 @@
|
||||
package io.floci.aws.services.emr;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* A SQL query engine of the Presto line that Floci runs on a {@code docker} cluster whose {@code Applications} name it,
|
||||
* with its setting on: Trino ({@link EmrTrino}). No AWS image carries one, so its coordinator runs on the primary node
|
||||
* from its project's image of the version the release's page in the Release Guide gives, in a container of its own that
|
||||
* shares the primary node's network, beside the cluster's Hive metastore, and a worker the same way on each of the core
|
||||
* and task nodes Floci runs, up to its setting. Its steps run its CLI, and clients outside the cluster reach it through
|
||||
* Floci on a host of the cluster's own. What one engine does otherwise than another is here; a container's entrypoint
|
||||
* writes the engine's files from the variables below, which every engine shares.
|
||||
*/
|
||||
interface EmrQueryEngine {
|
||||
|
||||
/**
|
||||
* The port the coordinator listens on, on the primary node, unless the cluster's {@code <engine>-config} names
|
||||
* another: "By default, Amazon EMR configures the Presto web interface on the Presto coordinator to use port 8889
|
||||
* (for PrestoDB and Trino)".
|
||||
*/
|
||||
int PORT = 8889;
|
||||
/**
|
||||
* A catalog's name as Floci takes it: the engine's own, letters, digits and underscores, which the entrypoint
|
||||
* passes as the name of a shell variable.
|
||||
*/
|
||||
Pattern CATALOG_NAME = Pattern.compile("[a-z][a-z0-9_]*");
|
||||
/** The variables an engine's container's entrypoint writes its configuration, node and log properties from. */
|
||||
String CONFIG_VARIABLE = "FLOCI_ENGINE_CONFIG";
|
||||
String NODE_VARIABLE = "FLOCI_ENGINE_NODE";
|
||||
String LOG_VARIABLE = "FLOCI_ENGINE_LOG";
|
||||
/** The variables it writes its exchange manager and that manager's Hadoop configuration from, where it has one. */
|
||||
String EXCHANGE_VARIABLE = "FLOCI_ENGINE_EXCHANGE";
|
||||
String EXCHANGE_SITE_VARIABLE = "FLOCI_ENGINE_EXCHANGE_SITE";
|
||||
/** The variable it writes its password authenticator from. */
|
||||
String PASSWORD_AUTHENTICATOR_VARIABLE = "FLOCI_ENGINE_PASSWORD_AUTHENTICATOR";
|
||||
/** The prefix of the variables it writes its catalogs from, one each, the rest of whose name names it. */
|
||||
String CATALOG_PREFIX = "FLOCI_ENGINE_CATALOG_";
|
||||
/** The folder of the cluster's image that holds EMR's command for the engine's CLI ({@link #commandName}). */
|
||||
String COMMAND_FOLDER = "/usr/bin";
|
||||
|
||||
/** The application's name, as the Release Guide's list of applications spells it, such as {@code Trino}. */
|
||||
String application();
|
||||
|
||||
/**
|
||||
* What the names of the engine's classifications start with, such as {@code trino}: {@code <prefix>-config} changes
|
||||
* its {@code config.properties} and {@code <prefix>-connector-<catalog>} a catalog's properties.
|
||||
*/
|
||||
String prefix();
|
||||
|
||||
/**
|
||||
* The component label of the engine's containers on a cluster, which go with its nodes, and the last part of their
|
||||
* names, such as {@code emr-trino}.
|
||||
*/
|
||||
String component();
|
||||
|
||||
/**
|
||||
* The label under Floci's host name of the hosts clients outside the cluster reach the engine at, one per cluster
|
||||
* ({@link #address}).
|
||||
*/
|
||||
String hostLabel();
|
||||
|
||||
/**
|
||||
* Whether the engine has an exchange manager, which the cluster's {@code <prefix>-exchange-manager} makes, for its
|
||||
* fault-tolerant execution: Trino's ({@link EmrTrino#exchangeManager}).
|
||||
*/
|
||||
boolean exchanges();
|
||||
|
||||
/** The variable a step's CLI command reads the coordinator's address from. */
|
||||
String serverVariable();
|
||||
|
||||
/**
|
||||
* An engine's container's entrypoint, the coordinator's or a worker's, which writes the engine's files from the
|
||||
* variables this interface names, then starts the engine as its image does.
|
||||
*/
|
||||
String entrypoint();
|
||||
|
||||
/**
|
||||
* What tells the engine's container is ready, a command run in it that takes no credentials, as a query would need
|
||||
* those of an engine that takes passwords, which Floci does not have.
|
||||
*/
|
||||
List<String> readyCheck();
|
||||
|
||||
/** The engine's CLI in its image, an executable jar, which the cluster's image takes. */
|
||||
String imageCli();
|
||||
|
||||
/** Where the cluster's image keeps that jar. */
|
||||
String cli();
|
||||
|
||||
/** The name of EMR's command for the CLI, in {@link #COMMAND_FOLDER} of the cluster's image. */
|
||||
String commandName();
|
||||
|
||||
/** That command: the CLI to the cluster's coordinator, unless the step names a server of its own. */
|
||||
String command();
|
||||
|
||||
/**
|
||||
* The coordinator's {@code config.properties}: a coordinator that runs the queries too only where the cluster has
|
||||
* no workers, on the cluster's {@link #port}, the cluster's {@code secret} for its nodes, and the cluster's
|
||||
* {@code <engine>-config} after Floci's.
|
||||
*/
|
||||
Map<String, String> config(Map<String, String> classification, boolean withWorkers, String secret);
|
||||
|
||||
/**
|
||||
* A worker's {@code config.properties}: no coordinator, finding it on the primary node named {@code primaryHost} at
|
||||
* the cluster's {@link #port}, the cluster's {@code secret}, and the cluster's {@code <engine>-config} after these.
|
||||
*/
|
||||
Map<String, String> workerConfig(Map<String, String> classification, String primaryHost, String secret);
|
||||
|
||||
/**
|
||||
* A worker's {@code node.properties} additions: the address the other nodes reach it at, its node's {@code host},
|
||||
* then the cluster's {@code <engine>-node}, but the node's id, which must be every node's own.
|
||||
*/
|
||||
Map<String, String> workerNode(Map<String, String> classification, String host);
|
||||
|
||||
/**
|
||||
* The engine's catalogs, by name, for {@code connectors}, the cluster's {@code <engine>-connector-<catalog>}
|
||||
* classifications' properties by catalog: their metastore on the primary node, at {@code metastoreHost}, and
|
||||
* Floci's S3 and Glue at {@code endpoint} in {@code region}.
|
||||
*/
|
||||
Map<String, Map<String, String>> catalogs(Map<String, Map<String, String>> connectors, String metastoreHost,
|
||||
String endpoint, String region);
|
||||
|
||||
/**
|
||||
* The files a cluster's {@code <engine>-password-authenticator} properties name, each once, in their order: those
|
||||
* whose path is absolute, as the engine's container has no folder of the cluster's own a relative one would be in.
|
||||
*/
|
||||
List<String> authenticatorFiles(Map<String, String> passwordAuthenticator);
|
||||
|
||||
/**
|
||||
* The image the engine runs from for a release: {@code template} with the release's version of the engine for
|
||||
* {@code %s}, as its page in the Release Guide gives it without AWS's build suffix, or {@code template} itself when
|
||||
* it has no {@code %s}. Null for a release whose version Floci does not know, which then runs no engine.
|
||||
*/
|
||||
default String image(String template, String releaseLabel) {
|
||||
if (template == null || template.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
if (!template.contains("%s")) {
|
||||
return template;
|
||||
}
|
||||
return EmrReleaseCatalog.release(releaseLabel)
|
||||
.flatMap(release -> release.applications().stream()
|
||||
.filter(application -> application().equals(application.name())).findFirst())
|
||||
.map(application -> template.formatted(application.version()))
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* The address clients outside the cluster reach its engine at, through Floci at {@code baseUrl}: a host of the
|
||||
* cluster's own under {@link #hostLabel}, as EMR's clients reach the primary node's.
|
||||
*/
|
||||
default String address(String baseUrl, String clusterId) {
|
||||
URI base = URI.create(baseUrl);
|
||||
return base.getScheme() + "://" + clusterId.toLowerCase(Locale.ROOT) + "." + hostLabel() + "."
|
||||
+ base.getRawAuthority();
|
||||
}
|
||||
|
||||
/** Every engine Floci runs. */
|
||||
static List<EmrQueryEngine> all() {
|
||||
return List.of(EmrTrino.ENGINE);
|
||||
}
|
||||
|
||||
/**
|
||||
* The port the engine listens on: the {@code http-server.http.port} of the cluster's {@code <engine>-config}, or
|
||||
* EMR's.
|
||||
*/
|
||||
static int port(Map<String, String> config) {
|
||||
String port = config.get("http-server.http.port");
|
||||
if (port != null) {
|
||||
try {
|
||||
return Integer.parseInt(port.trim());
|
||||
} catch (NumberFormatException ignored) {
|
||||
// The engine refuses it as it starts, and says so in its log.
|
||||
}
|
||||
}
|
||||
return PORT;
|
||||
}
|
||||
|
||||
/** The address a step's CLI reaches the coordinator at, on the primary node named {@code host}. */
|
||||
static String server(String host, int port) {
|
||||
return "http://" + host + ":" + port;
|
||||
}
|
||||
|
||||
/** {@code properties} as the lines of a Java properties file, in their order. */
|
||||
static String properties(Map<String, String> properties) {
|
||||
return properties.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue())
|
||||
.collect(Collectors.joining("\n"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package io.floci.aws.services.emr;
|
||||
|
||||
import io.floci.aws.core.common.AppUiRoute;
|
||||
import io.floci.aws.core.common.AppUiRoutes;
|
||||
import io.floci.aws.core.common.RequestScopes;
|
||||
import io.floci.aws.core.common.docker.ContainerLifecycleManager;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A cluster's query engine as clients outside the cluster reach it, through Floci, on a host of the cluster's own,
|
||||
* {@code <cluster id>.<the engine's host label>.<Floci's host and port>} ({@link EmrQueryEngine#address}), as EMR's
|
||||
* clients reach the engine on the primary node: no AWS API gives an address for it. The host asks for no credentials
|
||||
* of its own: the cluster's engine asks for those its {@code <engine>-config} and
|
||||
* {@code <engine>-password-authenticator} configure, and where they configure none, whoever reaches Floci's port
|
||||
* reaches the cluster's engine. The engine names a query's next pages by the host it was asked on, which the request
|
||||
* keeps, and by the scheme it was reached over, which goes on as {@code X-Forwarded-Proto}. A cluster whose engine is
|
||||
* not running yet has its primary node started, as an application UI link does, and the request answered with a
|
||||
* {@code 503}, which the engine's clients try again on. One of these serves each engine, for the bean of its routes
|
||||
* ({@link EmrTrinoRoutes}).
|
||||
*/
|
||||
final class EmrQueryEngineRoutes implements AppUiRoutes {
|
||||
|
||||
// No source gives these, as no AWS API serves the engines; they are Floci's: the cluster's id, then the engine's
|
||||
// name.
|
||||
static final String NO_SUCH_CLUSTER = "No EMR cluster %s runs Floci's %s.";
|
||||
static final String CLUSTER_ENDED = "EMR cluster %s is no longer running, and its %s is there only while it is"
|
||||
+ " RUNNING or WAITING.";
|
||||
static final String NOT_READY = "The %2$s of EMR cluster %1$s is starting. Try again in a moment.";
|
||||
// How long a port found for a cluster's engine is used before it is asked for again, as for the application UIs.
|
||||
private static final Duration ENDPOINT_RECHECK = Duration.ofSeconds(10);
|
||||
// A cluster's id, as a host name holds it, without case.
|
||||
private static final Pattern CLUSTER_ID = Pattern.compile("j-[a-z0-9]+");
|
||||
|
||||
private final EmrQueryEngine engine;
|
||||
private final EmrService clusters;
|
||||
private final Clock clock;
|
||||
// Where Floci found each cluster's engine, and when, by account and cluster.
|
||||
private final Map<String, Found> endpoints = new ConcurrentHashMap<>();
|
||||
|
||||
EmrQueryEngineRoutes(EmrQueryEngine engine, EmrService clusters, Clock clock) {
|
||||
this.engine = engine;
|
||||
this.clusters = clusters;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
private record Found(ContainerLifecycleManager.EndpointInfo endpoint, Instant at) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String hostLabel() {
|
||||
return engine.hostLabel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String service() {
|
||||
return "emr";
|
||||
}
|
||||
|
||||
/**
|
||||
* The route of a request whose {@code Host} is {@code hostHeader}, over {@code scheme}: to the engine of the
|
||||
* cluster the host names, once it answers queries; null where the host is not one of a cluster's engine.
|
||||
*/
|
||||
@Override
|
||||
public AppUiRoute route(String hostHeader, String scheme) {
|
||||
String host = hostHeader.toLowerCase(Locale.ROOT);
|
||||
int dot = host.indexOf('.');
|
||||
if (dot <= 0 || !host.startsWith(engine.hostLabel() + ".", dot + 1)
|
||||
|| !CLUSTER_ID.matcher(host.substring(0, dot)).matches()) {
|
||||
return null;
|
||||
}
|
||||
// A cluster's id is j- and capitals and digits, which the host holds in lower case.
|
||||
String clusterId = "j-" + host.substring(2, dot).toUpperCase(Locale.ROOT);
|
||||
EmrService.QueryEngineCluster cluster = clusters.queryEngineCluster(clusterId)
|
||||
.filter(found -> found.engine() == engine).orElse(null);
|
||||
String name = engine.application();
|
||||
if (cluster == null) {
|
||||
return AppUiRoute.refused(404, String.format(NO_SUCH_CLUSTER, clusterId, name));
|
||||
}
|
||||
String key = cluster.accountId() + "/" + cluster.clusterId();
|
||||
if (!EmrClusterLifecycle.RUNNING.equals(cluster.state())
|
||||
&& !EmrClusterLifecycle.WAITING.equals(cluster.state())) {
|
||||
endpoints.remove(key);
|
||||
return EmrClusterLifecycle.isTerminated(cluster.state())
|
||||
|| EmrClusterLifecycle.TERMINATING.equals(cluster.state())
|
||||
? AppUiRoute.refused(404, String.format(CLUSTER_ENDED, cluster.clusterId(), name))
|
||||
: AppUiRoute.refused(503, String.format(NOT_READY, cluster.clusterId(), name));
|
||||
}
|
||||
Instant now = clock.instant();
|
||||
Found found = endpoints.get(key);
|
||||
if (found == null || !now.isBefore(found.at().plus(ENDPOINT_RECHECK))) {
|
||||
ContainerLifecycleManager.EndpointInfo endpoint = RequestScopes.callAs(cluster.accountId(),
|
||||
cluster.region(), () -> clusters.queryEngineInterface(cluster.clusterId(), cluster.port()))
|
||||
.orElse(null);
|
||||
if (endpoint == null) {
|
||||
endpoints.remove(key);
|
||||
RequestScopes.runAs(cluster.accountId(), cluster.region(),
|
||||
() -> clusters.startPrimaryNode(cluster.clusterId()));
|
||||
return AppUiRoute.refused(503, String.format(NOT_READY, cluster.clusterId(), name));
|
||||
}
|
||||
found = new Found(endpoint, now);
|
||||
endpoints.put(key, found);
|
||||
}
|
||||
Found routed = found;
|
||||
return new AppUiRoute(found.endpoint().host(), found.endpoint().port(), Map.of(),
|
||||
() -> endpoints.remove(key, routed), 0, null, 503, String.format(NOT_READY, cluster.clusterId(), name))
|
||||
.withHeaders(Map.of("X-Forwarded-Proto", scheme));
|
||||
}
|
||||
}
|
||||
@@ -49,8 +49,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
* release's HDFS and YARN do not run on its newer Hadoop, so its image gets the whole of that release's Hadoop, in a
|
||||
* folder apart, which only its primary node's daemons run from. For a cluster with Pig, which no AWS image carries,
|
||||
* the image gets Tez, as Pig's scripts run on it, and Apache Pig, downloaded as it is made ({@link PigDistribution}),
|
||||
* whose checksum its name holds. For a cluster with Floci's Trino, it gets Trino's CLI from the Trino image the
|
||||
* cluster's coordinator runs, never started either, and EMR's {@code trino-cli} command ({@link EmrTrino#COMMAND}),
|
||||
* whose checksum its name holds. For a cluster with Floci's query engine, it gets the engine's CLI from the image
|
||||
* the cluster's coordinator runs, never started either, and EMR's command for it ({@link EmrQueryEngine#command}),
|
||||
* and its name holds that image's id.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@@ -65,8 +65,8 @@ public class EmrReleaseImages implements ReleaseImages {
|
||||
private static final String EMR_SHARE = "/usr/share/aws/emr";
|
||||
private static final String GOODIES = EMR_SHARE + "/serverless-goodies/lib";
|
||||
private static final String HIVE_GOODIES = "serverless-goodies-hive/lib";
|
||||
// What the Hive image adds for a cluster without Hive: the Hadoop services the EMR Serverless image lacks, which its
|
||||
// own Hadoop's client links name.
|
||||
// What the Hive image adds for a cluster without Hive: the Hadoop services the EMR Serverless image lacks, which
|
||||
// its own Hadoop's client links name.
|
||||
static final List<Copy> HADOOP_COPIES = List.of(
|
||||
new Copy("/usr/lib/hadoop-hdfs", "/usr/lib"),
|
||||
new Copy("/usr/lib/hadoop-mapreduce", "/usr/lib"),
|
||||
@@ -96,9 +96,6 @@ public class EmrReleaseImages implements ReleaseImages {
|
||||
new Copy("/usr/lib/tez", "/usr/lib"),
|
||||
new Copy("/etc/tez", "/etc"),
|
||||
new Copy(GOODIES, EMR_SHARE, HIVE_GOODIES));
|
||||
// What a cluster with Floci's Trino adds, from Trino's image: Trino's CLI, for its trino-cli (EmrTrino.COMMAND).
|
||||
static final Copy TRINO_CLI = new Copy(EmrTrino.IMAGE_CLI, "/usr/lib",
|
||||
EmrTrino.CLI.substring("/usr/lib/".length()));
|
||||
private static final String HADOOP_APART = "/opt";
|
||||
// What it adds for a release of the AWS runtime for Apache Spark: another release's Hadoop, whole and kept apart.
|
||||
static final List<Copy> HADOOP_APART_COPIES = List.of(
|
||||
@@ -145,33 +142,37 @@ public class EmrReleaseImages implements ReleaseImages {
|
||||
*/
|
||||
@Override
|
||||
public String image(String releaseLabel, String sparkImage, String hiveImage, boolean withHive,
|
||||
boolean withPig, String trinoImage) {
|
||||
boolean withPig, EmrQueryEngine queryEngine, String engineImage) {
|
||||
List<Copy> copies = copies(releaseLabel, withHive, withPig);
|
||||
PigDistribution pig = withPig && hadoopFolder(releaseLabel) == null ? pigDistribution : null;
|
||||
String trino = trinoImage != null ? containerBuilder.resolveImage(trinoImage) : null;
|
||||
// What is copied, the Pig written after it, by its checksum, and Trino's CLI with its command.
|
||||
String engine = engineImage != null ? containerBuilder.resolveImage(engineImage) : null;
|
||||
Copy cli = engine != null ? engineCli(queryEngine) : null;
|
||||
// What is copied, the Pig written after it, by its checksum, and the engine's CLI with its command.
|
||||
String content = copies + (pig != null ? "\n" + pig.identity() : "")
|
||||
+ (trino != null ? "\n" + TRINO_CLI + "\n" + EmrTrino.COMMAND : "");
|
||||
+ (engine != null ? "\n" + cli + "\n" + queryEngine.command() : "");
|
||||
String spark = containerBuilder.resolveImage(sparkImage);
|
||||
String hive = containerBuilder.resolveImage(hiveImage);
|
||||
String repository = ContainerStorageHelper.dockerName(config, COMPONENT);
|
||||
String kind = Digests.sha256Hex(releaseLabel + "\n" + spark + "\n" + hive + "\n" + content
|
||||
+ (trino != null ? "\n" + trino : "")).substring(0, 12);
|
||||
+ (engine != null ? "\n" + engine : "")).substring(0, 12);
|
||||
synchronized (making.computeIfAbsent(repository + ":" + kind, name -> new Object())) {
|
||||
String sparkId = imageCacheService.resolveForLaunch(spark, ImagePullBehavior.PREFER_CACHED, null)
|
||||
.imageId();
|
||||
String hiveId = imageCacheService.resolveForLaunch(hive, ImagePullBehavior.PREFER_CACHED, null).imageId();
|
||||
String trinoId = trino != null
|
||||
? imageCacheService.resolveForLaunch(trino, ImagePullBehavior.PREFER_CACHED, null).imageId() : null;
|
||||
String engineId = engine != null
|
||||
? imageCacheService.resolveForLaunch(engine, ImagePullBehavior.PREFER_CACHED, null).imageId()
|
||||
: null;
|
||||
String tag = releaseLabel + "-" + Digests.sha256Hex(sparkId + "\n" + hiveId + "\n" + content
|
||||
+ (trinoId != null ? "\n" + trinoId : "")).substring(0, 12);
|
||||
+ (engineId != null ? "\n" + engineId : "")).substring(0, 12);
|
||||
DockerClient docker = lifecycleManager.getDockerClient();
|
||||
try {
|
||||
return hold(docker.inspectImageCmd(repository + ":" + tag).exec().getId());
|
||||
} catch (NotFoundException e) {
|
||||
LOG.infov("Making {0}:{1} for EMR clusters {2}, from {3} and {4}", repository, tag,
|
||||
(withHive ? "with Hive" : "without Hive") + (pig != null ? ", with Pig" : "")
|
||||
+ (trino != null ? ", with Trino's CLI from " + trino : ""), spark, hive);
|
||||
+ (engine != null ? ", with " + queryEngine.application() + "'s CLI from " + engine
|
||||
: ""),
|
||||
spark, hive);
|
||||
}
|
||||
String user = docker.inspectImageCmd(sparkId).exec().getConfig().getUser();
|
||||
Map<String, String> labels = new LinkedHashMap<>();
|
||||
@@ -203,14 +204,14 @@ public class EmrReleaseImages implements ReleaseImages {
|
||||
RetryingTarCopier.copyBytes(docker, target, PigDistribution.COMMAND_FOLDER, PigDistribution.NAME,
|
||||
PigDistribution.COMMAND.getBytes(StandardCharsets.UTF_8), 0755);
|
||||
}
|
||||
if (trinoId != null) {
|
||||
String cli = docker.createContainerCmd(trinoId).withLabels(labels).exec().getId();
|
||||
containers.add(cli);
|
||||
RetryingTarCopier.copyStreamed(docker, target, TRINO_CLI.into(), TRINO_CLI.from(),
|
||||
out -> copy(docker.copyArchiveFromContainerCmd(cli, TRINO_CLI.from()).exec(), out,
|
||||
TRINO_CLI));
|
||||
RetryingTarCopier.copyBytes(docker, target, EmrTrino.COMMAND_FOLDER, EmrTrino.COMMAND_NAME,
|
||||
EmrTrino.COMMAND.getBytes(StandardCharsets.UTF_8), 0755);
|
||||
if (engineId != null) {
|
||||
String cliSource = docker.createContainerCmd(engineId).withLabels(labels).exec().getId();
|
||||
containers.add(cliSource);
|
||||
RetryingTarCopier.copyStreamed(docker, target, cli.into(), cli.from(),
|
||||
out -> copy(docker.copyArchiveFromContainerCmd(cliSource, cli.from()).exec(), out,
|
||||
cli));
|
||||
RetryingTarCopier.copyBytes(docker, target, EmrQueryEngine.COMMAND_FOLDER,
|
||||
queryEngine.commandName(), queryEngine.command().getBytes(StandardCharsets.UTF_8), 0755);
|
||||
}
|
||||
made = lifecycleManager.commit(target, repository, tag,
|
||||
user == null || user.isBlank() ? "root" : user, labels);
|
||||
@@ -239,6 +240,14 @@ public class EmrReleaseImages implements ReleaseImages {
|
||||
|
||||
// Another release's Hadoop for an emr-spark-* release, which has neither Hive nor Pig; Hive, Tez and those Hadoop
|
||||
// services for a cluster with Hive; Tez and those services for one with Pig alone; those services alone otherwise.
|
||||
/**
|
||||
* What a cluster with Floci's {@code engine} adds, from the engine's image: its CLI, for EMR's command for it
|
||||
* ({@link EmrQueryEngine#command}).
|
||||
*/
|
||||
static Copy engineCli(EmrQueryEngine engine) {
|
||||
return new Copy(engine.imageCli(), "/usr/lib", engine.cli().substring("/usr/lib/".length()));
|
||||
}
|
||||
|
||||
static List<Copy> copies(String releaseLabel, boolean withHive, boolean withPig) {
|
||||
if (hadoopFolder(releaseLabel) != null) {
|
||||
return HADOOP_APART_COPIES;
|
||||
|
||||
@@ -202,13 +202,9 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
private final String dockerNetwork;
|
||||
// Whether a cluster whose Applications name Pig gets Apache Pig in its image (floci.services.emr.pig.enabled).
|
||||
private final boolean pigEnabled;
|
||||
// Whether a cluster whose Applications name Trino runs it (floci.services.emr.trino.enabled), from which image, the
|
||||
// release's Trino version for %s, with how much memory for its coordinator, and how many workers with how much.
|
||||
private final boolean trinoEnabled;
|
||||
private final String trinoImageTemplate;
|
||||
private final int trinoMemoryMb;
|
||||
private final int trinoMaxWorkers;
|
||||
private final int trinoWorkerMemoryMb;
|
||||
// The query engines a cluster whose Applications name one runs, by engine, each with its settings: Trino where
|
||||
// floci.services.emr.trino.enabled runs it.
|
||||
private final Map<EmrQueryEngine, EngineSettings> engineSettings;
|
||||
// What the NodeManager of a cluster that runs YARN offers its containers.
|
||||
private final ClusterStorage.Yarn nodeManager;
|
||||
private final int maxWorkerNodes;
|
||||
@@ -391,11 +387,9 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
this.hiveImageTemplate = config.services().emr().hiveImageTemplate().orElse(null);
|
||||
this.dockerNetwork = config.services().emr().dockerNetwork().orElse(null);
|
||||
this.pigEnabled = config.services().emr().pig().enabled();
|
||||
this.trinoEnabled = config.services().emr().trino().enabled();
|
||||
this.trinoImageTemplate = trinoEnabled ? config.services().emr().trino().image() : null;
|
||||
this.trinoMemoryMb = trinoEnabled ? config.services().emr().trino().memoryMb() : 0;
|
||||
this.trinoMaxWorkers = trinoEnabled ? config.services().emr().trino().maxWorkers() : 0;
|
||||
this.trinoWorkerMemoryMb = trinoEnabled ? config.services().emr().trino().workerMemoryMb() : 0;
|
||||
EmulatorConfig.EmrTrinoConfig trino = config.services().emr().trino();
|
||||
this.engineSettings = trino.enabled() ? Map.of(EmrTrino.ENGINE, new EngineSettings(trino.image(),
|
||||
trino.memoryMb(), trino.maxWorkers(), trino.workerMemoryMb())) : Map.of();
|
||||
this.nodeManager = new ClusterStorage.Yarn(config.services().emr().yarnNodeMemoryMb(),
|
||||
config.services().emr().yarnNodeVcores());
|
||||
this.maxWorkerNodes = config.services().emr().yarnMaxWorkerNodes();
|
||||
@@ -1070,18 +1064,19 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
}
|
||||
|
||||
/**
|
||||
* A cluster's Trino as clients outside the cluster reach it: the cluster's account, Region, id and state, and the
|
||||
* port Trino listens on.
|
||||
* A cluster's query engine as clients outside the cluster reach it: the cluster's account, Region, id and state,
|
||||
* the engine, and the port it listens on.
|
||||
*/
|
||||
public record TrinoCluster(String accountId, String region, String clusterId, String state, int port) {
|
||||
public record QueryEngineCluster(String accountId, String region, String clusterId, String state,
|
||||
EmrQueryEngine engine, int port) {
|
||||
}
|
||||
|
||||
/**
|
||||
* The cluster of that id, whichever account and Region holds it, as the host clients reach its Trino at names it
|
||||
* ({@link EmrTrino#address}); empty where there is none, or it runs no Trino of Floci's. Looked up by its id in
|
||||
* each account that holds clusters, not by a scan, as every request to its Trino asks.
|
||||
* The cluster of that id, whichever account and Region holds it, as the host clients reach its query engine at
|
||||
* names it ({@link EmrQueryEngine#address}); empty where there is none, or it runs no engine of Floci's. Looked up
|
||||
* by its id in each account that holds clusters, not by a scan, as every request to its engine asks.
|
||||
*/
|
||||
public Optional<TrinoCluster> trinoCluster(String clusterId) {
|
||||
public Optional<QueryEngineCluster> queryEngineCluster(String clusterId) {
|
||||
AccountAwareStorageBackend.AccountEntry<EmrCluster> entry = call(() -> clusterStore
|
||||
.findAllAccountEntries(clusterId).stream().findFirst().orElse(null));
|
||||
if (entry == null || entry.value().getRegion() == null) {
|
||||
@@ -1090,14 +1085,18 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
String accountId = entry.accountId();
|
||||
String region = entry.value().getRegion();
|
||||
return RequestScopes.callAs(accountId, region, () -> findDescribedCluster(entry.key()))
|
||||
.filter(this::runsTrino)
|
||||
.map(cluster -> new TrinoCluster(accountId, region, cluster.getId(), cluster.getState(),
|
||||
EmrTrino.port(EmrSparkSteps.trinoConfig(cluster.getConfigurations(), SNAPSHOT_MAPPER))));
|
||||
.filter(this::runsQueryEngine)
|
||||
.map(cluster -> {
|
||||
EmrQueryEngine engine = queryEngineOf(cluster);
|
||||
return new QueryEngineCluster(accountId, region, cluster.getId(), cluster.getState(), engine,
|
||||
EmrQueryEngine.port(EmrSparkSteps.engineConfig(engine, cluster.getConfigurations(),
|
||||
SNAPSHOT_MAPPER)));
|
||||
});
|
||||
}
|
||||
|
||||
/** Where Floci reaches the cluster's Trino on {@code port}, once it has answered queries. */
|
||||
public Optional<ContainerLifecycleManager.EndpointInfo> trinoInterface(String clusterId, int port) {
|
||||
return clusterStorage == null ? Optional.empty() : clusterStorage.trinoInterface(clusterId, port);
|
||||
/** Where Floci reaches the cluster's query engine on {@code port}, once it has answered queries. */
|
||||
public Optional<ContainerLifecycleManager.EndpointInfo> queryEngineInterface(String clusterId, int port) {
|
||||
return clusterStorage == null ? Optional.empty() : clusterStorage.queryEngineInterface(clusterId, port);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1449,9 +1448,9 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
/**
|
||||
* The session's ServerUrl, "The Spark Connect server URL for the session", which a client uses "with the
|
||||
* Credentials returned by GetSessionEndpoint to connect directly to the session": Floci's own address in Spark
|
||||
* Connect's {@code sc://} form, where {@link SparkConnectProxy} takes a call carrying GetSessionEndpoint's token
|
||||
* on to the session's server, so that no client reaches the server without one. The model gives no example of
|
||||
* AWS's.
|
||||
* Connect's {@code sc://} form, where {@link SparkConnectProxy} takes a call carrying GetSessionEndpoint's
|
||||
* token on to the session's server, so that no client reaches the server without one. The model gives no
|
||||
* example of AWS's.
|
||||
*/
|
||||
@Override
|
||||
protected void ready(EmrSession stored) {
|
||||
@@ -2086,8 +2085,8 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether {@code key} is a Region's configuration's, {@code <Region>::<name>}. A name may hold "::" itself, so a key
|
||||
* stored before is told apart by what precedes the first one: a Region {@link RegionResolver#isKnownRegion}
|
||||
* Whether {@code key} is a Region's configuration's, {@code <Region>::<name>}. A name may hold "::" itself, so a
|
||||
* key stored before is told apart by what precedes the first one: a Region {@link RegionResolver#isKnownRegion}
|
||||
* admits, as {@code RegionScopedStorage} tells its keys apart.
|
||||
*/
|
||||
private static boolean isRegionalKey(String key) {
|
||||
@@ -3148,23 +3147,13 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
String hdfsHost = masterPrivateDnsName(cluster);
|
||||
String hdfsImage = hdfsImage(cluster.getReleaseLabel());
|
||||
Supplier<ClusterStorage.Yarn> nodeYarn = runsYarn(cluster) ? currentYarn(cluster, accountId, region) : null;
|
||||
String trinoImage = trinoImage(cluster);
|
||||
ClusterStorage.Trino trino = trinoImage == null ? null : new ClusterStorage.Trino(trinoImage, trinoMemoryMb,
|
||||
EmrSparkSteps.trinoConnectors(cluster.getConfigurations(), SNAPSHOT_MAPPER),
|
||||
EmrSparkSteps.trinoConfig(cluster.getConfigurations(), SNAPSHOT_MAPPER),
|
||||
EmrSparkSteps.trinoNode(cluster.getConfigurations(), SNAPSHOT_MAPPER),
|
||||
EmrSparkSteps.trinoLog(cluster.getConfigurations(), SNAPSHOT_MAPPER),
|
||||
EmrSparkSteps.trinoEnvironment(cluster.getConfigurations(), SNAPSHOT_MAPPER),
|
||||
EmrSparkSteps.trinoExchangeManager(cluster.getConfigurations(), SNAPSHOT_MAPPER),
|
||||
EmrSparkSteps.trinoPasswordAuthenticator(cluster.getConfigurations(), SNAPSHOT_MAPPER),
|
||||
cluster.getBootstrapImage(), trinoMaxWorkers, trinoWorkerMemoryMb,
|
||||
trinoOwnNodes(cluster) ? currentNodes(cluster, accountId, region) : null);
|
||||
ClusterStorage.QueryEngine queryEngine = queryEngine(cluster, accountId, region);
|
||||
boolean withHdfs = !EmrSparkSteps.trinoAlone(cluster.getReleaseLabel(), cluster.getApplications(),
|
||||
SNAPSHOT_MAPPER);
|
||||
ClusterStorage.HiveMetastore hiveMetastore = withHiveImage(cluster)
|
||||
? new ClusterStorage.HiveMetastore(instanceProfileRole(cluster, accountId),
|
||||
EmrSparkSteps.hiveMetastoreSettings(cluster.getConfigurations(), SNAPSHOT_MAPPER), trino,
|
||||
withHdfs)
|
||||
EmrSparkSteps.hiveMetastoreSettings(cluster.getConfigurations(), SNAPSHOT_MAPPER),
|
||||
queryEngine, withHdfs)
|
||||
: null;
|
||||
SparkJobRunner.Storage onlyVolumes = volumes;
|
||||
BiFunction<String, BooleanSupplier, SparkJobRunner.Storage> hdfs = volumes == null ? null
|
||||
@@ -3221,9 +3210,7 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
application != null ? application : List.of(), command, Duration.ZERO,
|
||||
EmrSparkSteps.logFolder(cluster, step), null,
|
||||
stepEnvironment(step, cluster, command != null && pig,
|
||||
runsTrino(cluster) ? EmrTrino.server(masterPrivateDnsName(cluster),
|
||||
EmrTrino.port(EmrSparkSteps.trinoConfig(cluster.getConfigurations(),
|
||||
SNAPSHOT_MAPPER))) : null),
|
||||
runsQueryEngine(cluster) ? queryEngineOf(cluster) : null),
|
||||
List.of(),
|
||||
storage, EmrSparkSteps.coreSite(cluster.getConfigurations(), SNAPSHOT_MAPPER),
|
||||
EmrSparkSteps.sparkLog4j2(cluster.getConfigurations(), SNAPSHOT_MAPPER),
|
||||
@@ -3249,22 +3236,24 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
}
|
||||
}
|
||||
|
||||
// A cluster with Trino starts its primary node, and Trino on it, as it becomes ready, steps or none.
|
||||
// A cluster with a query engine starts its primary node, and the engine on it, as it becomes ready, steps or
|
||||
// none.
|
||||
@Override
|
||||
public void ready(EmrCluster cluster, String region) {
|
||||
if (tornDown || !runsTrino(cluster)) {
|
||||
if (tornDown || !runsQueryEngine(cluster)) {
|
||||
return;
|
||||
}
|
||||
String accountId = regionResolver.getAccountId();
|
||||
String clusterId = cluster.getId();
|
||||
LOG.infov("EMR cluster {0} starts its Trino, which clients outside the cluster reach at {1}", clusterId,
|
||||
EmrTrino.address(baseUrl, clusterId));
|
||||
EmrQueryEngine engine = queryEngineOf(cluster);
|
||||
LOG.infov("EMR cluster {0} starts its {1}, which clients outside the cluster reach at {2}", clusterId,
|
||||
engine.application(), engine.address(baseUrl, clusterId));
|
||||
try {
|
||||
// On a thread of its own, which reads the cluster under the service's lock, so once this is stored.
|
||||
stepExecutor.execute(() -> RequestScopes.runAs(accountId, region, () -> startPrimaryNode(clusterId)));
|
||||
} catch (RuntimeException e) {
|
||||
LOG.warnv(e, "Could not start the primary node of EMR cluster {0} for its Trino: {1}", clusterId,
|
||||
e.getMessage());
|
||||
LOG.warnv(e, "Could not start the primary node of EMR cluster {0} for its {1}: {2}", clusterId,
|
||||
engine.application(), e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3366,8 +3355,9 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
clusterStorage.remove(launch.clusterId());
|
||||
}
|
||||
if (outcome.stopped()) {
|
||||
// A cancelled step's cluster-mode driver wrote only to its application's logs, which go in S3 before its
|
||||
// cluster's storage can; one that never ran has none, and Floci's own teardown leaves them on the node.
|
||||
// A cancelled step's cluster-mode driver wrote only to its application's logs, which go in S3 before
|
||||
// its cluster's storage can; one that never ran has none, and Floci's own teardown leaves them on the
|
||||
// node.
|
||||
if (containerLogs != null && progress.driverStarted && teardowns.get() == launch.teardownsBefore()) {
|
||||
clusterStorage.archiveContainerLogs(launch.clusterId(), launch.accountId(), launch.region(),
|
||||
containerLogs);
|
||||
@@ -3456,31 +3446,71 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
String release = cluster.getReleaseLabel();
|
||||
String spark = EmrServerlessSparkRunner.image(imageTemplate, release);
|
||||
String hive = hdfsImage(release);
|
||||
String trino = trinoImage(cluster);
|
||||
return () -> releaseImages.image(release, spark, hive, withHive, withPig, trino);
|
||||
EmrQueryEngine engine = queryEngineOf(cluster);
|
||||
String engineImage = engineImage(cluster);
|
||||
return () -> releaseImages.image(release, spark, hive, withHive, withPig, engine, engineImage);
|
||||
}
|
||||
|
||||
// Whether a cluster's image has Hive, and its primary node Hive's metastore service: it installs Hive or HCatalog,
|
||||
// or runs Floci's Trino, with which EMR installs hive-client and hcatalog-server.
|
||||
// or runs Floci's query engine, with which EMR installs hive-client and hcatalog-server.
|
||||
private boolean withHiveImage(EmrCluster cluster) {
|
||||
return EmrSparkSteps.installsHive(cluster.getReleaseLabel(), cluster.getApplications(), SNAPSHOT_MAPPER)
|
||||
|| trinoImage(cluster) != null;
|
||||
|| queryEngineOf(cluster) != null;
|
||||
}
|
||||
|
||||
// Whether a cluster runs Floci's Trino: in the docker runner mode, on a network of the cluster's own, where its
|
||||
// primary node runs the metastore, with an image for its Trino (trinoImage).
|
||||
private boolean runsTrino(EmrCluster cluster) {
|
||||
return runsOnClusters() && clusterStorage.ownNetwork(dockerNetwork) && trinoImage(cluster) != null;
|
||||
// Whether a cluster runs Floci's query engine: in the docker runner mode, on a network of the cluster's own, where
|
||||
// its primary node runs the metastore, with an engine (queryEngineOf).
|
||||
private boolean runsQueryEngine(EmrCluster cluster) {
|
||||
return runsOnClusters() && clusterStorage.ownNetwork(dockerNetwork) && queryEngineOf(cluster) != null;
|
||||
}
|
||||
|
||||
// The image a cluster's Trino runs from: it installs Trino, floci.services.emr.trino.enabled runs it, and its
|
||||
// release's Trino version is known (EmrTrino.image); null otherwise.
|
||||
private String trinoImage(EmrCluster cluster) {
|
||||
if (!trinoEnabled || !EmrSparkSteps.installsTrino(cluster.getReleaseLabel(), cluster.getApplications(),
|
||||
SNAPSHOT_MAPPER)) {
|
||||
// The query engine a cluster runs: one its Applications name, whose setting runs it (engineSettings), where its
|
||||
// release's version of it is known (EmrQueryEngine.image); null otherwise.
|
||||
private EmrQueryEngine queryEngineOf(EmrCluster cluster) {
|
||||
for (Map.Entry<EmrQueryEngine, EngineSettings> settings : engineSettings.entrySet()) {
|
||||
EmrQueryEngine engine = settings.getKey();
|
||||
if (EmrSparkSteps.installsEngine(engine, cluster.getReleaseLabel(), cluster.getApplications(),
|
||||
SNAPSHOT_MAPPER)
|
||||
&& engine.image(settings.getValue().imageTemplate(), cluster.getReleaseLabel()) != null) {
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// The image a cluster's query engine runs from (queryEngineOf); null where it runs none.
|
||||
private String engineImage(EmrCluster cluster) {
|
||||
EmrQueryEngine engine = queryEngineOf(cluster);
|
||||
return engine == null ? null
|
||||
: engine.image(engineSettings.get(engine).imageTemplate(), cluster.getReleaseLabel());
|
||||
}
|
||||
|
||||
// A cluster's query engine as its storage starts it, from the engine's settings and the cluster's classifications
|
||||
// for it, its workers on nodes of its own where it has them (engineOwnNodes); null where it runs none.
|
||||
private ClusterStorage.QueryEngine queryEngine(EmrCluster cluster, String accountId, String region) {
|
||||
EmrQueryEngine engine = queryEngineOf(cluster);
|
||||
if (engine == null) {
|
||||
return null;
|
||||
}
|
||||
return EmrTrino.image(trinoImageTemplate, cluster.getReleaseLabel());
|
||||
EngineSettings settings = engineSettings.get(engine);
|
||||
String configurations = cluster.getConfigurations();
|
||||
return new ClusterStorage.QueryEngine(engine, engineImage(cluster), settings.memoryMb(),
|
||||
EmrSparkSteps.engineConnectors(engine, configurations, SNAPSHOT_MAPPER),
|
||||
EmrSparkSteps.engineConfig(engine, configurations, SNAPSHOT_MAPPER),
|
||||
EmrSparkSteps.engineNode(engine, configurations, SNAPSHOT_MAPPER),
|
||||
EmrSparkSteps.engineLog(engine, configurations, SNAPSHOT_MAPPER),
|
||||
EmrSparkSteps.engineEnvironment(engine, configurations, SNAPSHOT_MAPPER),
|
||||
EmrSparkSteps.engineExchangeManager(engine, configurations, SNAPSHOT_MAPPER),
|
||||
EmrSparkSteps.enginePasswordAuthenticator(engine, configurations, SNAPSHOT_MAPPER),
|
||||
cluster.getBootstrapImage(), settings.maxWorkers(), settings.workerMemoryMb(),
|
||||
engineOwnNodes(cluster) ? currentNodes(cluster, accountId, region) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* What Floci runs a query engine with: the image of its project its version for {@code %s} makes, the memory its
|
||||
* coordinator's container gets, and how many workers it runs with how much each.
|
||||
*/
|
||||
private record EngineSettings(String imageTemplate, int memoryMb, int maxWorkers, int workerMemoryMb) {
|
||||
}
|
||||
|
||||
// Whether a cluster's image has Floci's Pig: it installs Pig, and floci.services.emr.pig.enabled adds it.
|
||||
@@ -3491,15 +3521,18 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
|
||||
// The variables a step that is not a Hive step runs with: its cluster's spark-env exports and its own Properties
|
||||
// (see EmrSparkSteps.environment), for a command on a cluster with Floci's Pig, its Pig configuration, and on one
|
||||
// with Floci's Trino, where its trino-cli reaches the coordinator, unless trinoServer is null.
|
||||
// with Floci's query engine, engine unless that is null, where the engine's CLI reaches the coordinator on the
|
||||
// primary node, at the port its <engine>-config names.
|
||||
private static Map<String, String> stepEnvironment(EmrStep step, EmrCluster cluster, boolean pig,
|
||||
String trinoServer) {
|
||||
EmrQueryEngine engine) {
|
||||
Map<String, String> variables = EmrSparkSteps.environment(step, cluster.getConfigurations(), SNAPSHOT_MAPPER);
|
||||
if (pig) {
|
||||
variables.putAll(EmrSparkSteps.pigEnvironment(cluster.getConfigurations(), SNAPSHOT_MAPPER));
|
||||
}
|
||||
if (trinoServer != null) {
|
||||
variables.put(EmrTrino.SERVER_VARIABLE, trinoServer);
|
||||
if (engine != null) {
|
||||
variables.put(engine.serverVariable(), EmrQueryEngine.server(masterPrivateDnsName(cluster),
|
||||
EmrQueryEngine.port(EmrSparkSteps.engineConfig(engine, cluster.getConfigurations(),
|
||||
SNAPSHOT_MAPPER))));
|
||||
}
|
||||
return variables;
|
||||
}
|
||||
@@ -3528,7 +3561,8 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
&& EmrSparkSteps.names(cluster.getApplications(), SNAPSHOT_MAPPER, "Tez"));
|
||||
}
|
||||
|
||||
// What a cluster asks of YARN when it is read, which may be later than now; what it asks now, if it has gone by then.
|
||||
// What a cluster asks of YARN when it is read, which may be later than now; what it asks now, if it has gone by
|
||||
// then.
|
||||
private Supplier<ClusterStorage.Yarn> currentYarn(EmrCluster cluster, String accountId, String region) {
|
||||
String clusterId = cluster.getId();
|
||||
ClusterStorage.Yarn asked = yarnOf(cluster);
|
||||
@@ -3545,10 +3579,11 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
() -> call(() -> clusterStore.get(clusterId).map(this::workerNodes).orElse(asked)));
|
||||
}
|
||||
|
||||
// Whether a cluster's Trino has nodes of its own (ClusterStorage.Trino.ownNodes): Floci runs its Trino, and it has
|
||||
// Trino alone from emr-7.14.0, whose core and task nodes run Trino's workers and no YARN or HDFS.
|
||||
private boolean trinoOwnNodes(EmrCluster cluster) {
|
||||
return runsTrino(cluster)
|
||||
// Whether a cluster's query engine has nodes of its own (ClusterStorage.QueryEngine.ownNodes): Floci runs its
|
||||
// engine, and it has Trino alone from emr-7.14.0, whose core and task nodes run Trino's workers and no YARN or
|
||||
// HDFS.
|
||||
private boolean engineOwnNodes(EmrCluster cluster) {
|
||||
return runsQueryEngine(cluster)
|
||||
&& EmrSparkSteps.trinoAlone(cluster.getReleaseLabel(), cluster.getApplications(), SNAPSHOT_MAPPER);
|
||||
}
|
||||
|
||||
@@ -3559,7 +3594,8 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
if (runsYarn(cluster)) {
|
||||
return workerNodes(cluster);
|
||||
}
|
||||
return trinoOwnNodes(cluster) ? ClusterStorage.Trino.workers(workerNodes(cluster), trinoMaxWorkers) : List.of();
|
||||
return engineOwnNodes(cluster) ? ClusterStorage.QueryEngine.workers(workerNodes(cluster),
|
||||
engineSettings.get(queryEngineOf(cluster)).maxWorkers()) : List.of();
|
||||
}
|
||||
|
||||
// A resize reaches the nodes of a cluster a step has started them on, on another thread, as they take a while, and
|
||||
@@ -3567,7 +3603,7 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
// those it asks for then.
|
||||
private void resizeNodes(EmrCluster cluster) {
|
||||
boolean yarnNodes = runsYarn(cluster);
|
||||
if (cluster.isStorageCreated() && (yarnNodes || trinoOwnNodes(cluster))) {
|
||||
if (cluster.isStorageCreated() && (yarnNodes || engineOwnNodes(cluster))) {
|
||||
String accountId = regionResolver.getAccountId();
|
||||
String region = regionOf(cluster);
|
||||
Supplier<ClusterStorage.Yarn> yarn = yarnNodes ? currentYarn(cluster, accountId, region) : null;
|
||||
@@ -3588,7 +3624,7 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
if (yarn != null) {
|
||||
clusterStorage.resize(clusterId, yarn);
|
||||
} else {
|
||||
clusterStorage.resizeTrino(clusterId);
|
||||
clusterStorage.resizeQueryEngine(clusterId);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -3684,11 +3720,11 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
|
||||
/**
|
||||
* Whether a cluster's primary node runs YARN, which its steps' Spark runs on: "the primary node runs the YARN
|
||||
* ResourceManager service", and a core node "YARN NodeManager daemons, Hadoop MapReduce tasks, and Spark executors".
|
||||
* It does on a network of the cluster's own, as its metastore does, unless the cluster has Trino alone from
|
||||
* emr-7.14.0, which runs no YARN ({@link EmrSparkSteps#trinoAlone}). A cluster bootstrapped by an earlier Floci
|
||||
* runs from an image that may hold no YARN, so it keeps to local mode, its HDFS in the release's Hive image, as it
|
||||
* did.
|
||||
* ResourceManager service", and a core node "YARN NodeManager daemons, Hadoop MapReduce tasks, and Spark
|
||||
* executors". It does on a network of the cluster's own, as its metastore does, unless the cluster has Trino alone
|
||||
* from emr-7.14.0, which runs no YARN ({@link EmrSparkSteps#trinoAlone}). A cluster bootstrapped by an earlier
|
||||
* Floci runs from an image that may hold no YARN, so it keeps to local mode, its HDFS in the release's Hive image,
|
||||
* as it did.
|
||||
*/
|
||||
private boolean runsYarn(EmrCluster cluster) {
|
||||
return releaseImages != null && clusterStorage != null && clusterStorage.ownNetwork(dockerNetwork)
|
||||
@@ -4009,7 +4045,7 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
private AddedNodes addedNodes(String clusterId, String accountId) {
|
||||
Optional<EmrCluster> found = clusterStore.get(clusterId).filter(EmrService::nodesMayStart);
|
||||
if (found.isEmpty() || found.get().getBootstrapImage() == null
|
||||
|| !runsYarn(found.get()) && !trinoOwnNodes(found.get())) {
|
||||
|| !runsYarn(found.get()) && !engineOwnNodes(found.get())) {
|
||||
return null;
|
||||
}
|
||||
EmrCluster cluster = found.get();
|
||||
@@ -4347,8 +4383,8 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
return instance;
|
||||
}
|
||||
|
||||
// The EC2 instance a cluster's node, named as ClusterStorage.identify has it, is as the cluster stands now; null for
|
||||
// a cluster that is gone.
|
||||
// The EC2 instance a cluster's node, named as ClusterStorage.identify has it, is as the cluster stands now; null
|
||||
// for a cluster that is gone.
|
||||
private Instance nodeIdentity(String clusterId, String accountId, String region, String node) {
|
||||
int dash = node.indexOf('-');
|
||||
int group = Integer.parseInt(node.substring(0, dash));
|
||||
@@ -4358,8 +4394,8 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
|
||||
}
|
||||
|
||||
/**
|
||||
* The availability zone a cluster's instances are in: the one DescribeCluster's {@code Ec2InstanceAttributes} gives,
|
||||
* else its Region's first.
|
||||
* The availability zone a cluster's instances are in: the one DescribeCluster's {@code Ec2InstanceAttributes}
|
||||
* gives, else its Region's first.
|
||||
*/
|
||||
static String availabilityZone(EmrCluster cluster) {
|
||||
String recorded = null;
|
||||
|
||||
@@ -168,11 +168,11 @@ final class EmrSparkSteps {
|
||||
}
|
||||
|
||||
/**
|
||||
* The command a step that is not a Spark step runs, or null for one Floci does not run: a
|
||||
* {@code command-runner.jar} step's arguments, its command first, unless it runs {@code pig-script} on a cluster
|
||||
* that installs Pig, which Floci has not added ({@code pigMissing}), where EMR's would run it; on one that does not,
|
||||
* EMR's {@code pig-script} runs and finds no {@code pig}, as it does there. Floci's S3DistCp with the arguments of an
|
||||
* {@code s3-dist-cp} one; a {@code script-runner.jar} step's script, the first of its arguments, with the rest.
|
||||
* The command a step that is not a Spark step runs, or null for one Floci does not run: a {@code
|
||||
* command-runner.jar} step's arguments, its command first, unless it runs {@code pig-script} on a cluster that
|
||||
* installs Pig, which Floci has not added ({@code pigMissing}), where EMR's would run it; on one that does not,
|
||||
* EMR's {@code pig-script} runs and finds no {@code pig}, as it does there. Floci's S3DistCp with the arguments of
|
||||
* an {@code s3-dist-cp} one; a {@code script-runner.jar} step's script, the first of its arguments, with the rest.
|
||||
*/
|
||||
static List<String> command(EmrStep step, boolean pigMissing) {
|
||||
String jar = step.getJar();
|
||||
@@ -297,20 +297,28 @@ final class EmrSparkSteps {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Whether a cluster installs {@code engine}: its {@code Applications} name it, as {@link #installs} has it. */
|
||||
static boolean installsEngine(EmrQueryEngine engine, String releaseLabel, String applications,
|
||||
ObjectMapper objectMapper) {
|
||||
return installs(releaseLabel, applications, objectMapper, engine.application());
|
||||
}
|
||||
|
||||
/**
|
||||
* The properties of a cluster's {@code trino-connector-<catalog>} classifications by catalog, in the order they
|
||||
* come, a later configuration's winning, each of which changes "Trino's {@code <catalog>.properties} file". One
|
||||
* whose catalog is not a name Trino takes ({@link EmrTrino#CATALOG_NAME}) names none.
|
||||
* The properties of a cluster's {@code <engine>-connector-<catalog>} classifications by catalog, in the order they
|
||||
* come, a later configuration's winning, each of which changes "Trino's {@code <catalog>.properties} file", for
|
||||
* Trino. One whose catalog is not a name the engine takes ({@link EmrQueryEngine#CATALOG_NAME}) names none.
|
||||
*/
|
||||
static Map<String, Map<String, String>> trinoConnectors(String configurations, ObjectMapper objectMapper) {
|
||||
static Map<String, Map<String, String>> engineConnectors(EmrQueryEngine engine, String configurations,
|
||||
ObjectMapper objectMapper) {
|
||||
String prefix = engine.prefix() + "-connector-";
|
||||
Map<String, Map<String, String>> connectors = new LinkedHashMap<>();
|
||||
for (JsonNode configuration : stored(configurations, objectMapper)) {
|
||||
String classification = configuration.path("Classification").asText();
|
||||
if (!classification.startsWith(EmrTrino.CONNECTOR_PREFIX)) {
|
||||
if (!classification.startsWith(prefix)) {
|
||||
continue;
|
||||
}
|
||||
String catalog = classification.substring(EmrTrino.CONNECTOR_PREFIX.length());
|
||||
if (!EmrTrino.CATALOG_NAME.matcher(catalog).matches()) {
|
||||
String catalog = classification.substring(prefix.length());
|
||||
if (!EmrQueryEngine.CATALOG_NAME.matcher(catalog).matches()) {
|
||||
continue;
|
||||
}
|
||||
Map<String, String> properties = connectors.computeIfAbsent(catalog, name -> new LinkedHashMap<>());
|
||||
@@ -320,45 +328,50 @@ final class EmrSparkSteps {
|
||||
return connectors;
|
||||
}
|
||||
|
||||
/** The properties of a cluster's {@code trino-config}, which its Trino's {@code config.properties} gets. */
|
||||
static Map<String, String> trinoConfig(String configurations, ObjectMapper objectMapper) {
|
||||
return properties(configurations, objectMapper, EmrTrino.CONFIG_CLASSIFICATION);
|
||||
/** The properties of a cluster's {@code <engine>-config}, which its engine's {@code config.properties} gets. */
|
||||
static Map<String, String> engineConfig(EmrQueryEngine engine, String configurations, ObjectMapper objectMapper) {
|
||||
return properties(configurations, objectMapper, engine.prefix() + "-config");
|
||||
}
|
||||
|
||||
/** The properties of a cluster's {@code trino-node}, which its Trino's {@code node.properties} gets. */
|
||||
static Map<String, String> trinoNode(String configurations, ObjectMapper objectMapper) {
|
||||
return properties(configurations, objectMapper, EmrTrino.NODE_CLASSIFICATION);
|
||||
/** The properties of a cluster's {@code <engine>-node}, which its engine's {@code node.properties} gets. */
|
||||
static Map<String, String> engineNode(EmrQueryEngine engine, String configurations, ObjectMapper objectMapper) {
|
||||
return properties(configurations, objectMapper, engine.prefix() + "-node");
|
||||
}
|
||||
|
||||
/**
|
||||
* The properties of a cluster's {@code trino-exchange-manager}, which make its Trino's exchange manager, or null
|
||||
* where it has none: one with no properties gives EMR's default, "To use the default settings, set the following
|
||||
* configuration: { "Classification": "trino-exchange-manager" }".
|
||||
* where it has none, as on a cluster of an engine with no exchange manager ({@link EmrQueryEngine#exchanges}):
|
||||
* one with no properties gives EMR's default, "To use the default settings, set the following configuration:
|
||||
* { "Classification": "trino-exchange-manager" }".
|
||||
*/
|
||||
static Map<String, String> trinoExchangeManager(String configurations, ObjectMapper objectMapper) {
|
||||
return classified(configurations, objectMapper, EmrTrino.EXCHANGE_CLASSIFICATION).isEmpty() ? null
|
||||
: properties(configurations, objectMapper, EmrTrino.EXCHANGE_CLASSIFICATION);
|
||||
static Map<String, String> engineExchangeManager(EmrQueryEngine engine, String configurations,
|
||||
ObjectMapper objectMapper) {
|
||||
String classification = engine.prefix() + "-exchange-manager";
|
||||
return !engine.exchanges() || classified(configurations, objectMapper, classification).isEmpty() ? null
|
||||
: properties(configurations, objectMapper, classification);
|
||||
}
|
||||
|
||||
/**
|
||||
* The properties of a cluster's {@code trino-password-authenticator}, which make its Trino's
|
||||
* The properties of a cluster's {@code <engine>-password-authenticator}, which make its engine's
|
||||
* {@code password-authenticator.properties}.
|
||||
*/
|
||||
static Map<String, String> trinoPasswordAuthenticator(String configurations, ObjectMapper objectMapper) {
|
||||
return properties(configurations, objectMapper, EmrTrino.PASSWORD_AUTHENTICATOR_CLASSIFICATION);
|
||||
static Map<String, String> enginePasswordAuthenticator(EmrQueryEngine engine, String configurations,
|
||||
ObjectMapper objectMapper) {
|
||||
return properties(configurations, objectMapper, engine.prefix() + "-password-authenticator");
|
||||
}
|
||||
|
||||
/** The properties of a cluster's {@code trino-log}, which make its Trino's {@code log.properties}. */
|
||||
static Map<String, String> trinoLog(String configurations, ObjectMapper objectMapper) {
|
||||
return properties(configurations, objectMapper, EmrTrino.LOG_CLASSIFICATION);
|
||||
/** The properties of a cluster's {@code <engine>-log}, which make its engine's {@code log.properties}. */
|
||||
static Map<String, String> engineLog(EmrQueryEngine engine, String configurations, ObjectMapper objectMapper) {
|
||||
return properties(configurations, objectMapper, engine.prefix() + "-log");
|
||||
}
|
||||
|
||||
/**
|
||||
* The variables a cluster's {@code trino-env} exports, its nested {@code export} classification's properties, as
|
||||
* "If any classification ends in env, use the export sub-classification", which its Trino's environment gets.
|
||||
* The variables a cluster's {@code <engine>-env} exports, its nested {@code export} classification's properties,
|
||||
* as "If any classification ends in env, use the export sub-classification", which its engine's environment gets.
|
||||
*/
|
||||
static Map<String, String> trinoEnvironment(String configurations, ObjectMapper objectMapper) {
|
||||
return exports(configurations, objectMapper, EmrTrino.ENV_CLASSIFICATION);
|
||||
static Map<String, String> engineEnvironment(EmrQueryEngine engine, String configurations,
|
||||
ObjectMapper objectMapper) {
|
||||
return exports(configurations, objectMapper, engine.prefix() + "-env");
|
||||
}
|
||||
|
||||
// Whether a cluster's Applications name any of names, in any case, unless its release is of the AWS runtime for
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
package io.floci.aws.services.emr;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Trino on a {@code docker} cluster whose {@code Applications} name it, with
|
||||
@@ -30,12 +26,12 @@ import java.util.stream.Collectors;
|
||||
* Trino's CLI, which this class writes for the image they run in, and clients outside the cluster reach it through
|
||||
* Floci on a host of the cluster's own ({@link EmrTrinoRoutes}).
|
||||
*/
|
||||
final class EmrTrino {
|
||||
final class EmrTrino implements EmrQueryEngine {
|
||||
|
||||
/** Trino, the one engine of this class. */
|
||||
static final EmrTrino ENGINE = new EmrTrino();
|
||||
/** The application's name, as the Release Guide's list of applications spells it. */
|
||||
static final String APPLICATION = "Trino";
|
||||
/** The port Trino listens on, on the primary node, unless the cluster's {@code trino-config} names another. */
|
||||
static final int PORT = 8889;
|
||||
/** The prefix of the classifications that each change a catalog, the rest of whose name names it. */
|
||||
static final String CONNECTOR_PREFIX = "trino-connector-";
|
||||
/** The classification that changes Trino's {@code config.properties}. */
|
||||
@@ -58,11 +54,6 @@ final class EmrTrino {
|
||||
"ldap.ssl.truststore.path", "ldap.ssl-trust-certificate");
|
||||
/** The catalog every Trino cluster has. */
|
||||
static final String HIVE = "hive";
|
||||
/**
|
||||
* A catalog's name as Floci takes it: Trino's own, letters, digits and underscores, which the entrypoint passes as
|
||||
* the name of a shell variable.
|
||||
*/
|
||||
static final Pattern CATALOG_NAME = Pattern.compile("[a-z][a-z0-9_]*");
|
||||
/** The component label of a cluster's Trino container, which goes with its primary node's. */
|
||||
static final String COMPONENT = "emr-trino";
|
||||
/**
|
||||
@@ -76,8 +67,7 @@ final class EmrTrino {
|
||||
static final String IMAGE_CLI = "/usr/bin/trino";
|
||||
/** Where the cluster's image keeps that jar. */
|
||||
static final String CLI = "/usr/lib/trino/trino-cli";
|
||||
/** The folder of EMR's {@code trino-cli} command, and its name. */
|
||||
static final String COMMAND_FOLDER = "/usr/bin";
|
||||
/** The name of EMR's {@code trino-cli} command, in {@link #COMMAND_FOLDER}. */
|
||||
static final String COMMAND_NAME = "trino-cli";
|
||||
/**
|
||||
* EMR's {@code trino-cli}: the CLI on the image's Java 17, which a release whose default is Java 8 has besides, to
|
||||
@@ -94,19 +84,12 @@ final class EmrTrino {
|
||||
done
|
||||
exec "$java" -jar %1$s --server "${%2$s:-localhost:%3$d}" "$@"
|
||||
""".formatted(CLI, SERVER_VARIABLE, PORT);
|
||||
/** The variables the Trino container's entrypoint writes its configuration, node and log properties from. */
|
||||
static final String CONFIG_VARIABLE = "FLOCI_TRINO_CONFIG";
|
||||
static final String NODE_VARIABLE = "FLOCI_TRINO_NODE";
|
||||
static final String LOG_VARIABLE = "FLOCI_TRINO_LOG";
|
||||
static final String EXCHANGE_VARIABLE = "FLOCI_TRINO_EXCHANGE";
|
||||
static final String PASSWORD_AUTHENTICATOR_VARIABLE = "FLOCI_TRINO_PASSWORD_AUTHENTICATOR";
|
||||
/**
|
||||
* The Hadoop configuration Trino's {@code hdfs} exchange manager reads, as EMR's {@code hdfs.config.resources}
|
||||
* names "the paths to core-site.xml, hdfs-site.xml files", which the entrypoint writes from the variable after
|
||||
* ({@link #exchangeSite}).
|
||||
*/
|
||||
static final String EXCHANGE_HDFS_CONFIG = "/etc/trino/exchange-core-site.xml";
|
||||
static final String EXCHANGE_SITE_VARIABLE = "FLOCI_TRINO_EXCHANGE_SITE";
|
||||
/**
|
||||
* The property of Trino's {@code config.properties} that holds the secret its nodes sign their requests to each
|
||||
* other with, which Trino needs with authentication on and every node shares.
|
||||
@@ -114,8 +97,6 @@ final class EmrTrino {
|
||||
static final String SHARED_SECRET = "internal-communication.shared-secret";
|
||||
/** The property of Trino's {@code node.properties} that names a node, which must be every node's own. */
|
||||
static final String NODE_ID = "node.id";
|
||||
/** The prefix of the variables it writes its catalogs from, one each, the rest of whose name names it. */
|
||||
static final String CATALOG_PREFIX = "FLOCI_TRINO_CATALOG_";
|
||||
/**
|
||||
* A Trino container's entrypoint, the coordinator's or a worker's: its configuration, as Floci gives it, the
|
||||
* cluster's shared secret in it ({@link #config}); the cluster's node and log properties after those of its image's
|
||||
@@ -159,51 +140,64 @@ final class EmrTrino {
|
||||
private EmrTrino() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The image Trino runs from for a release: {@code template} with the release's Trino version for {@code %s}, as
|
||||
* its page in the Release Guide gives it without AWS's build suffix, or {@code template} itself when it has no
|
||||
* {@code %s}. Null for a release whose version Floci does not know, which then runs no Trino.
|
||||
*/
|
||||
static String image(String template, String releaseLabel) {
|
||||
if (template == null || template.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
if (!template.contains("%s")) {
|
||||
return template;
|
||||
}
|
||||
return EmrReleaseCatalog.release(releaseLabel)
|
||||
.flatMap(release -> release.applications().stream()
|
||||
.filter(application -> APPLICATION.equals(application.name())).findFirst())
|
||||
.map(application -> template.formatted(application.version()))
|
||||
.orElse(null);
|
||||
@Override
|
||||
public String application() {
|
||||
return APPLICATION;
|
||||
}
|
||||
|
||||
/** The port Trino listens on: the {@code http-server.http.port} of the cluster's {@code trino-config}, or EMR's. */
|
||||
static int port(Map<String, String> config) {
|
||||
String port = config.get("http-server.http.port");
|
||||
if (port != null) {
|
||||
try {
|
||||
return Integer.parseInt(port.trim());
|
||||
} catch (NumberFormatException ignored) {
|
||||
// Trino refuses it as it starts, and says so in its log.
|
||||
}
|
||||
}
|
||||
return PORT;
|
||||
@Override
|
||||
public String prefix() {
|
||||
return "trino";
|
||||
}
|
||||
|
||||
/** The address a step's {@code trino-cli} reaches the coordinator at, on the primary node named {@code host}. */
|
||||
static String server(String host, int port) {
|
||||
return "http://" + host + ":" + port;
|
||||
@Override
|
||||
public String component() {
|
||||
return COMPONENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* The address clients outside the cluster reach its Trino at, through Floci at {@code baseUrl}: a host of the
|
||||
* cluster's own under {@link #HOST_LABEL}, as EMR's clients reach the primary node's.
|
||||
*/
|
||||
static String address(String baseUrl, String clusterId) {
|
||||
URI base = URI.create(baseUrl);
|
||||
return base.getScheme() + "://" + clusterId.toLowerCase(Locale.ROOT) + "." + HOST_LABEL + "."
|
||||
+ base.getRawAuthority();
|
||||
@Override
|
||||
public String hostLabel() {
|
||||
return HOST_LABEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exchanges() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serverVariable() {
|
||||
return SERVER_VARIABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String entrypoint() {
|
||||
return ENTRYPOINT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> readyCheck() {
|
||||
return READY_CHECK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String imageCli() {
|
||||
return IMAGE_CLI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String cli() {
|
||||
return CLI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String commandName() {
|
||||
return COMMAND_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String command() {
|
||||
return COMMAND;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,12 +216,13 @@ final class EmrTrino {
|
||||
* classification's properties after these, each in its place, as "you can override the configuration with your own
|
||||
* secret key".
|
||||
*/
|
||||
static Map<String, String> config(Map<String, String> classification, boolean withWorkers, String secret) {
|
||||
@Override
|
||||
public Map<String, String> config(Map<String, String> classification, boolean withWorkers, String secret) {
|
||||
Map<String, String> config = new LinkedHashMap<>();
|
||||
config.put("coordinator", "true");
|
||||
config.put("node-scheduler.include-coordinator", String.valueOf(!withWorkers));
|
||||
config.put("http-server.http.port", String.valueOf(PORT));
|
||||
config.put("discovery.uri", "http://localhost:" + port(classification));
|
||||
config.put("discovery.uri", "http://localhost:" + EmrQueryEngine.port(classification));
|
||||
config.put("http-server.process-forwarded", "true");
|
||||
config.put(SHARED_SECRET, secret);
|
||||
config.putAll(classification);
|
||||
@@ -240,11 +235,12 @@ final class EmrTrino {
|
||||
* {@code trino-config} after these, as "configuration properties must be set on the coordinator and all worker
|
||||
* nodes" unless Trino says otherwise of one.
|
||||
*/
|
||||
static Map<String, String> workerConfig(Map<String, String> classification, String primaryHost, String secret) {
|
||||
@Override
|
||||
public Map<String, String> workerConfig(Map<String, String> classification, String primaryHost, String secret) {
|
||||
Map<String, String> config = new LinkedHashMap<>();
|
||||
config.put("coordinator", "false");
|
||||
config.put("http-server.http.port", String.valueOf(PORT));
|
||||
config.put("discovery.uri", server(primaryHost, port(classification)));
|
||||
config.put("discovery.uri", EmrQueryEngine.server(primaryHost, EmrQueryEngine.port(classification)));
|
||||
config.put(SHARED_SECRET, secret);
|
||||
config.putAll(classification);
|
||||
return config;
|
||||
@@ -257,7 +253,8 @@ final class EmrTrino {
|
||||
* needs "unique for every node": that one is the coordinator's, and the entrypoint names a worker after its
|
||||
* node's host, as it does a node given no id.
|
||||
*/
|
||||
static Map<String, String> workerNode(Map<String, String> classification, String host) {
|
||||
@Override
|
||||
public Map<String, String> workerNode(Map<String, String> classification, String host) {
|
||||
Map<String, String> node = new LinkedHashMap<>();
|
||||
node.put("node.internal-address", host);
|
||||
node.putAll(classification);
|
||||
@@ -327,7 +324,8 @@ final class EmrTrino {
|
||||
* Trino's catalogs, by name: {@code hive}, then each that {@code connectors}, the cluster's
|
||||
* {@code trino-connector-<catalog>} classifications' properties by catalog, name (see {@link #catalog}).
|
||||
*/
|
||||
static Map<String, Map<String, String>> catalogs(Map<String, Map<String, String>> connectors,
|
||||
@Override
|
||||
public Map<String, Map<String, String>> catalogs(Map<String, Map<String, String>> connectors,
|
||||
String metastoreHost, String endpoint, String region) {
|
||||
Map<String, Map<String, String>> catalogs = new LinkedHashMap<>();
|
||||
catalogs.put(HIVE, catalog(HIVE, connectors.getOrDefault(HIVE, Map.of()), metastoreHost, endpoint, region));
|
||||
@@ -380,14 +378,9 @@ final class EmrTrino {
|
||||
* once, in their order: those whose path is absolute, as Trino's container has no folder of the cluster's own a
|
||||
* relative one would be in.
|
||||
*/
|
||||
static List<String> authenticatorFiles(Map<String, String> passwordAuthenticator) {
|
||||
@Override
|
||||
public List<String> authenticatorFiles(Map<String, String> passwordAuthenticator) {
|
||||
return AUTHENTICATOR_FILES.stream().map(passwordAuthenticator::get)
|
||||
.filter(path -> path != null && path.trim().startsWith("/")).map(String::trim).distinct().toList();
|
||||
}
|
||||
|
||||
/** {@code properties} as the lines of a Java properties file, in their order. */
|
||||
static String properties(Map<String, String> properties) {
|
||||
return properties.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue())
|
||||
.collect(Collectors.joining("\n"));
|
||||
}
|
||||
}
|
||||
@@ -2,47 +2,21 @@ package io.floci.aws.services.emr;
|
||||
|
||||
import io.floci.aws.core.common.AppUiRoute;
|
||||
import io.floci.aws.core.common.AppUiRoutes;
|
||||
import io.floci.aws.core.common.RequestScopes;
|
||||
import io.floci.aws.core.common.docker.ContainerLifecycleManager;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A cluster's Trino as clients outside the cluster reach it, through Floci, on a host of the cluster's own,
|
||||
* {@code <cluster id>.}{@value EmrTrino#HOST_LABEL}{@code .<Floci's host and port>} ({@link EmrTrino#address}), as
|
||||
* EMR's clients reach Trino on the primary node: no AWS API gives an address for it. The host asks for no credentials
|
||||
* of its own: the cluster's Trino asks for those its {@code trino-config} and {@code trino-password-authenticator}
|
||||
* configure, and where they configure none, whoever reaches Floci's port reaches the cluster's Trino. Trino names a
|
||||
* query's next pages by the host it was asked on, which the request keeps, and by the scheme it was reached over, which
|
||||
* goes on as {@code X-Forwarded-Proto}, and takes a password only where that scheme is HTTPS, through Floci with its
|
||||
* TLS on. A cluster whose Trino is not running yet has its primary node started, as an application UI link does, and
|
||||
* the request answered with a {@code 503}, which Trino's clients try again on.
|
||||
* {@code <cluster id>.}{@value EmrTrino#HOST_LABEL}{@code .<Floci's host and port>}, as
|
||||
* {@link EmrQueryEngineRoutes} routes it. Trino takes a password only where the scheme a client reached it over is
|
||||
* HTTPS, through Floci with its TLS on.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class EmrTrinoRoutes implements AppUiRoutes {
|
||||
|
||||
// No source gives these, as no AWS API serves Trino; they are Floci's.
|
||||
static final String NO_SUCH_CLUSTER = "No EMR cluster %s runs Floci's Trino.";
|
||||
static final String CLUSTER_ENDED = "EMR cluster %s is no longer running, and its Trino is there only while it is"
|
||||
+ " RUNNING or WAITING.";
|
||||
static final String NOT_READY = "The Trino of EMR cluster %s is starting. Try again in a moment.";
|
||||
// How long a port found for a cluster's Trino is used before it is asked for again, as for the application UIs.
|
||||
private static final Duration ENDPOINT_RECHECK = Duration.ofSeconds(10);
|
||||
// A cluster's id, as a host name holds it, without case.
|
||||
private static final Pattern CLUSTER_ID = Pattern.compile("j-[a-z0-9]+");
|
||||
|
||||
private final EmrService clusters;
|
||||
private final Clock clock;
|
||||
// Where Floci found each cluster's Trino, and when, by account and cluster.
|
||||
private final Map<String, Found> endpoints = new ConcurrentHashMap<>();
|
||||
private final EmrQueryEngineRoutes routes;
|
||||
|
||||
@Inject
|
||||
public EmrTrinoRoutes(EmrService clusters) {
|
||||
@@ -50,68 +24,21 @@ public class EmrTrinoRoutes implements AppUiRoutes {
|
||||
}
|
||||
|
||||
EmrTrinoRoutes(EmrService clusters, Clock clock) {
|
||||
this.clusters = clusters;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
private record Found(ContainerLifecycleManager.EndpointInfo endpoint, Instant at) {
|
||||
this.routes = new EmrQueryEngineRoutes(EmrTrino.ENGINE, clusters, clock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String hostLabel() {
|
||||
return EmrTrino.HOST_LABEL;
|
||||
return routes.hostLabel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String service() {
|
||||
return "emr";
|
||||
return routes.service();
|
||||
}
|
||||
|
||||
/**
|
||||
* The route of a request whose {@code Host} is {@code hostHeader}, over {@code scheme}: to the Trino of the
|
||||
* cluster the host names, once it answers queries; null where the host is not one of a cluster's Trino.
|
||||
*/
|
||||
@Override
|
||||
public AppUiRoute route(String hostHeader, String scheme) {
|
||||
String host = hostHeader.toLowerCase(Locale.ROOT);
|
||||
int dot = host.indexOf('.');
|
||||
if (dot <= 0 || !host.startsWith(EmrTrino.HOST_LABEL + ".", dot + 1)
|
||||
|| !CLUSTER_ID.matcher(host.substring(0, dot)).matches()) {
|
||||
return null;
|
||||
}
|
||||
// A cluster's id is j- and capitals and digits, which the host holds in lower case.
|
||||
String clusterId = "j-" + host.substring(2, dot).toUpperCase(Locale.ROOT);
|
||||
EmrService.TrinoCluster cluster = clusters.trinoCluster(clusterId).orElse(null);
|
||||
if (cluster == null) {
|
||||
return AppUiRoute.refused(404, String.format(NO_SUCH_CLUSTER, clusterId));
|
||||
}
|
||||
String key = cluster.accountId() + "/" + cluster.clusterId();
|
||||
if (!EmrClusterLifecycle.RUNNING.equals(cluster.state())
|
||||
&& !EmrClusterLifecycle.WAITING.equals(cluster.state())) {
|
||||
endpoints.remove(key);
|
||||
return EmrClusterLifecycle.isTerminated(cluster.state())
|
||||
|| EmrClusterLifecycle.TERMINATING.equals(cluster.state())
|
||||
? AppUiRoute.refused(404, String.format(CLUSTER_ENDED, cluster.clusterId()))
|
||||
: AppUiRoute.refused(503, String.format(NOT_READY, cluster.clusterId()));
|
||||
}
|
||||
Instant now = clock.instant();
|
||||
Found found = endpoints.get(key);
|
||||
if (found == null || !now.isBefore(found.at().plus(ENDPOINT_RECHECK))) {
|
||||
ContainerLifecycleManager.EndpointInfo endpoint = RequestScopes.callAs(cluster.accountId(),
|
||||
cluster.region(), () -> clusters.trinoInterface(cluster.clusterId(), cluster.port()))
|
||||
.orElse(null);
|
||||
if (endpoint == null) {
|
||||
endpoints.remove(key);
|
||||
RequestScopes.runAs(cluster.accountId(), cluster.region(),
|
||||
() -> clusters.startPrimaryNode(cluster.clusterId()));
|
||||
return AppUiRoute.refused(503, String.format(NOT_READY, cluster.clusterId()));
|
||||
}
|
||||
found = new Found(endpoint, now);
|
||||
endpoints.put(key, found);
|
||||
}
|
||||
Found routed = found;
|
||||
return new AppUiRoute(found.endpoint().host(), found.endpoint().port(), Map.of(),
|
||||
() -> endpoints.remove(key, routed), 0, null, 503, String.format(NOT_READY, cluster.clusterId()))
|
||||
.withHeaders(Map.of("X-Forwarded-Proto", scheme));
|
||||
return routes.route(hostHeader, scheme);
|
||||
}
|
||||
}
|
||||
@@ -16,15 +16,15 @@ public interface ReleaseImages {
|
||||
*/
|
||||
default String image(String releaseLabel, String sparkImage, String hiveImage, boolean withHive,
|
||||
boolean withPig) {
|
||||
return image(releaseLabel, sparkImage, hiveImage, withHive, withPig, null);
|
||||
return image(releaseLabel, sparkImage, hiveImage, withHive, withPig, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link #image(String, String, String, boolean, boolean)}, with EMR's {@code trino-cli} for the Trino of
|
||||
* {@code trinoImage}, unless that is null, which pulling that image may take long too.
|
||||
* {@link #image(String, String, String, boolean, boolean)}, with EMR's command for the CLI of {@code engine}, the
|
||||
* query engine of {@code engineImage}, unless that is null, which pulling that image may take long too.
|
||||
*/
|
||||
String image(String releaseLabel, String sparkImage, String hiveImage, boolean withHive, boolean withPig,
|
||||
String trinoImage);
|
||||
EmrQueryEngine engine, String engineImage);
|
||||
|
||||
/**
|
||||
* The step or the bootstrap that {@link #image} gave {@code imageId} to has ended, so a newer image of its kind may
|
||||
|
||||
@@ -138,8 +138,8 @@ class EmrClusterStorageTest {
|
||||
// The same with Trino beside it, from the image of emr-7.5.0's Trino.
|
||||
private static final ClusterStorage.HiveMetastore TRINO_METASTORE =
|
||||
new ClusterStorage.HiveMetastore("arn:aws:iam::123456789012:role/r", Map.of(),
|
||||
new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of(), Map.of(), Map.of(), Map.of(),
|
||||
Map.of(), null, Map.of(), null, 0, 1024, null));
|
||||
new ClusterStorage.QueryEngine(EmrTrino.ENGINE, "trinodb/trino:446", 2048, Map.of(), Map.of(),
|
||||
Map.of(), Map.of(), Map.of(), null, Map.of(), null, 0, 1024, null));
|
||||
|
||||
private final EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
private final DockerClient docker = mock(DockerClient.class);
|
||||
@@ -1848,7 +1848,8 @@ class EmrClusterStorageTest {
|
||||
String later = "application_1_0002/container_1_0002_01_000001/stdout";
|
||||
List<List<String>> listings = nodeLogs(Map.of(earlier, "one"));
|
||||
storage.archiveContainerLogs("j-1", "123456789012", "us-east-1", "s3://logs/j-1/containers/");
|
||||
// A primary node whose core nodes run the NodeManagers has no such folder, which is none to list and no failure.
|
||||
// A primary node whose core nodes run the NodeManagers has no such folder, which is none to list and no
|
||||
// failure.
|
||||
assertEquals(List.of(List.of("bash", "-c", "[ ! -d /mnt/yarn/logs ] || exec find /mnt/yarn/logs -mindepth 3"
|
||||
+ " -maxdepth 3 -type f -printf '%s %P\\n'")), listings);
|
||||
|
||||
@@ -2026,7 +2027,7 @@ class EmrClusterStorageTest {
|
||||
verify(trinoSpec).withEnv(EmrTrino.LOG_VARIABLE, "");
|
||||
// No trino-exchange-manager, so no exchange manager, as on EMR.
|
||||
verify(trinoSpec, never()).withEnv(eq(EmrTrino.EXCHANGE_VARIABLE), anyString());
|
||||
verify(trinoSpec).withEnv(EmrTrino.CATALOG_PREFIX + "hive", EmrTrino.properties(EmrTrino.catalog("hive",
|
||||
verify(trinoSpec).withEnv(EmrTrino.CATALOG_PREFIX + "hive", EmrQueryEngine.properties(EmrTrino.catalog("hive",
|
||||
Map.of(), "localhost", "http://host.docker.internal:4566", "us-east-1")));
|
||||
verify(trinoSpec).withEntrypoint(List.of("/bin/bash", "-c", EmrTrino.ENTRYPOINT));
|
||||
verify(trinoSpec).withJavaTrustStore();
|
||||
@@ -2056,7 +2057,7 @@ class EmrClusterStorageTest {
|
||||
when(currentContainer.resolveContainerId()).thenReturn(Optional.empty());
|
||||
|
||||
// Not started yet.
|
||||
assertTrue(ticking.trinoInterface("j-1", 8889).isEmpty());
|
||||
assertTrue(ticking.queryEngineInterface("j-1", 8889).isEmpty());
|
||||
ticking.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", TRINO_METASTORE, null,
|
||||
NOT_STOPPED);
|
||||
|
||||
@@ -2064,15 +2065,15 @@ class EmrClusterStorageTest {
|
||||
verify(spec).withLoopbackPortBinding(8889, 0);
|
||||
when(lifecycle.probeContainer(hdfsName)).thenReturn(ContainerLiveness.RUNNING);
|
||||
ContainerExecStubs.completeEveryExec(docker, hdfsName, 0L, "", "");
|
||||
assertEquals(Optional.of(published), ticking.trinoInterface("j-1", 8889));
|
||||
assertEquals(Optional.of(published), ticking.queryEngineInterface("j-1", 8889));
|
||||
// A Trino that has stopped is not reached.
|
||||
when(lifecycle.probeContainer(trinoName)).thenReturn(ContainerLiveness.NOT_RUNNING);
|
||||
assertTrue(ticking.trinoInterface("j-1", 8889).isEmpty());
|
||||
assertTrue(ticking.queryEngineInterface("j-1", 8889).isEmpty());
|
||||
when(lifecycle.probeContainer(trinoName)).thenReturn(ContainerLiveness.RUNNING);
|
||||
|
||||
ticking.remove("j-1");
|
||||
|
||||
assertTrue(ticking.trinoInterface("j-1", 8889).isEmpty());
|
||||
assertTrue(ticking.queryEngineInterface("j-1", 8889).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2085,8 +2086,8 @@ class EmrClusterStorageTest {
|
||||
authenticator.put("password-authenticator.name", "file");
|
||||
authenticator.put("file.password-file", "/etc/trino/password.db");
|
||||
ClusterStorage.HiveMetastore metastore = new ClusterStorage.HiveMetastore("arn:aws:iam::123456789012:role/r",
|
||||
Map.of(), new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of(), Map.of(),
|
||||
Map.of("node.environment", "production"), Map.of("io.trino", "DEBUG"),
|
||||
Map.of(), new ClusterStorage.QueryEngine(EmrTrino.ENGINE, "trinodb/trino:446", 2048, Map.of(),
|
||||
Map.of(), Map.of("node.environment", "production"), Map.of("io.trino", "DEBUG"),
|
||||
Map.of("DB_PASSWORD", "s3cret"), Map.of("exchange.base-directories", "s3://spool/exchange"),
|
||||
authenticator, null, 0, 1024, null));
|
||||
|
||||
@@ -2138,12 +2139,12 @@ class EmrClusterStorageTest {
|
||||
verify(trinoSpec, times(3)).withEnv(eq(EmrTrino.CONFIG_VARIABLE), configs.capture());
|
||||
String coordinator = configs.getAllValues().get(0);
|
||||
assertTrue(coordinatorConfig(false, coordinator), coordinator);
|
||||
String worker = EmrTrino.properties(EmrTrino.workerConfig(Map.of(), HOST, secretIn(coordinator)));
|
||||
String worker = EmrQueryEngine.properties(EmrTrino.ENGINE.workerConfig(Map.of(), HOST, secretIn(coordinator)));
|
||||
assertEquals(List.of(worker, worker), configs.getAllValues().subList(1, 3));
|
||||
// Each reached at its node's host, its catalogs' metastore on the primary node.
|
||||
verify(trinoSpec).withEnv(EmrTrino.NODE_VARIABLE, "node.internal-address=" + CORE_HOST);
|
||||
verify(trinoSpec).withEnv(EmrTrino.NODE_VARIABLE, "node.internal-address=" + TASK_HOST);
|
||||
verify(trinoSpec, times(2)).withEnv(EmrTrino.CATALOG_PREFIX + "hive", EmrTrino.properties(
|
||||
verify(trinoSpec, times(2)).withEnv(EmrTrino.CATALOG_PREFIX + "hive", EmrQueryEngine.properties(
|
||||
EmrTrino.catalog("hive", Map.of(), HOST, "http://host.docker.internal:4566", "us-east-1")));
|
||||
// Each with a session of its own for the cluster's role, and waited for as the coordinator is.
|
||||
verify(trinoSpec).withEnv(List.of("AWS_ACCESS_KEY_ID=ASIACOREWORKER"));
|
||||
@@ -2273,7 +2274,7 @@ class EmrClusterStorageTest {
|
||||
verify(trinoSpec, times(3)).withEnv(eq(EmrTrino.CONFIG_VARIABLE), configs.capture());
|
||||
String coordinator = configs.getAllValues().get(0);
|
||||
assertTrue(coordinatorConfig(false, coordinator), coordinator);
|
||||
String worker = EmrTrino.properties(EmrTrino.workerConfig(Map.of(), HOST, secretIn(coordinator)));
|
||||
String worker = EmrQueryEngine.properties(EmrTrino.ENGINE.workerConfig(Map.of(), HOST, secretIn(coordinator)));
|
||||
assertEquals(List.of(worker, worker), configs.getAllValues().subList(1, 3));
|
||||
verify(trinoSpec).withEnv(EmrTrino.NODE_VARIABLE, "node.internal-address=" + CORE_HOST);
|
||||
assertFalse(stubs.asked().get(coreWorker).isEmpty());
|
||||
@@ -2307,7 +2308,7 @@ class EmrClusterStorageTest {
|
||||
verify(trinoSpec).withLinkLocalIp("169.254.0.2");
|
||||
nodes.set(List.of());
|
||||
|
||||
storage.resizeTrino("j-1");
|
||||
storage.resizeQueryEngine("j-1");
|
||||
|
||||
verify(relays).release("169.254.0.2");
|
||||
}
|
||||
@@ -2335,7 +2336,7 @@ class EmrClusterStorageTest {
|
||||
int before = removed.size();
|
||||
nodes.set(List.of(TASK_NODE));
|
||||
|
||||
ticking.resizeTrino("j-1");
|
||||
ticking.resizeQueryEngine("j-1");
|
||||
|
||||
// The new node's worker joins the coordinator as it becomes ready; the leaving node's goes.
|
||||
verify(trinoSpec).withName(taskWorker);
|
||||
@@ -2352,13 +2353,13 @@ class EmrClusterStorageTest {
|
||||
ticking.hdfs("j-1", "123456789012", "us-east-1", HOST, IMAGE, "floci-network", trinoAlone(4, nodes::get), null,
|
||||
NOT_STOPPED);
|
||||
runningOn(coreWorker, hdfsName);
|
||||
ticking.resizeTrino("j-1");
|
||||
ticking.resizeQueryEngine("j-1");
|
||||
verify(trinoSpec, times(1)).withName(coreWorker);
|
||||
List<String> removed = stubs.trino().removed();
|
||||
int before = removed.size();
|
||||
|
||||
nodes.set(List.of(new ClusterStorage.Node("1-1", CORE_HOST, true, "sha256:node")));
|
||||
ticking.resizeTrino("j-1");
|
||||
ticking.resizeQueryEngine("j-1");
|
||||
|
||||
// Kept while its node has the same image; started again once the node's own bootstrap has left one, so its
|
||||
// password authenticator's files are the node's.
|
||||
@@ -2368,7 +2369,7 @@ class EmrClusterStorageTest {
|
||||
|
||||
@Test
|
||||
void aResizeBeforeAStepHasStartedTheClustersTrinoStartsNoWorker() {
|
||||
storage.resizeTrino("j-1");
|
||||
storage.resizeQueryEngine("j-1");
|
||||
|
||||
verify(lifecycle, never()).createAndStart(any());
|
||||
}
|
||||
@@ -2377,15 +2378,15 @@ class EmrClusterStorageTest {
|
||||
// workers on nodes of its own, as they are when read, each container getting 1024 MB.
|
||||
private static ClusterStorage.HiveMetastore trinoAlone(int maxWorkers, Supplier<List<ClusterStorage.Node>> nodes) {
|
||||
return new ClusterStorage.HiveMetastore("arn:aws:iam::123456789012:role/r", Map.of(),
|
||||
new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of(), Map.of(), Map.of(), Map.of(), Map.of(),
|
||||
null, Map.of(), null, maxWorkers, 1024, nodes), false);
|
||||
new ClusterStorage.QueryEngine(EmrTrino.ENGINE, "trinodb/trino:446", 2048, Map.of(), Map.of(),
|
||||
Map.of(), Map.of(), Map.of(), null, Map.of(), null, maxWorkers, 1024, nodes), false);
|
||||
}
|
||||
|
||||
// A cluster whose Trino runs up to maxWorkers workers, each container getting 1024 MB.
|
||||
private static ClusterStorage.HiveMetastore trinoWithWorkers(int maxWorkers) {
|
||||
return new ClusterStorage.HiveMetastore("arn:aws:iam::123456789012:role/r", Map.of(),
|
||||
new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of(), Map.of(), Map.of(), Map.of(), Map.of(),
|
||||
null, Map.of(), null, maxWorkers, 1024, null));
|
||||
new ClusterStorage.QueryEngine(EmrTrino.ENGINE, "trinodb/trino:446", 2048, Map.of(), Map.of(),
|
||||
Map.of(), Map.of(), Map.of(), null, Map.of(), null, maxWorkers, 1024, null));
|
||||
}
|
||||
|
||||
// Trino's coordinator as trinoStarts has it, and each node named so running in a container whose id is its name's
|
||||
@@ -2531,8 +2532,8 @@ class EmrClusterStorageTest {
|
||||
ldap.put("ldap.ssl.truststore.path", "/home/hadoop/ldap/truststore.pem");
|
||||
ldap.put("ldap.ssl.keystore.path", "/home/hadoop/ldap/keystore.pem");
|
||||
return new ClusterStorage.HiveMetastore("arn:aws:iam::123456789012:role/r", Map.of(),
|
||||
new ClusterStorage.Trino("trinodb/trino:446", memoryMb, Map.of(), Map.of(), Map.of(), Map.of(),
|
||||
Map.of(), null, ldap, "sha256:bootstrapped", 0, 1024, null));
|
||||
new ClusterStorage.QueryEngine(EmrTrino.ENGINE, "trinodb/trino:446", memoryMb, Map.of(), Map.of(),
|
||||
Map.of(), Map.of(), Map.of(), null, ldap, "sha256:bootstrapped", 0, 1024, null));
|
||||
}
|
||||
|
||||
// An archive whose one file's header says it is size bytes, with none of its content after it.
|
||||
@@ -3787,7 +3788,7 @@ class EmrClusterStorageTest {
|
||||
// Whether config is the coordinator's configuration, running the queries too or not, with a shared secret Floci
|
||||
// made: 32 random bytes in Base64.
|
||||
private static boolean coordinatorConfig(boolean includesItself, String config) {
|
||||
String expected = EmrTrino.properties(EmrTrino.config(Map.of(), !includesItself, "SECRET"));
|
||||
String expected = EmrQueryEngine.properties(EmrTrino.ENGINE.config(Map.of(), !includesItself, "SECRET"));
|
||||
return Pattern.matches(Pattern.quote(expected).replace("SECRET", "\\E[A-Za-z0-9+/]{43}=\\Q"), config);
|
||||
}
|
||||
|
||||
|
||||
@@ -188,8 +188,8 @@ class EmrReleaseImagesTest {
|
||||
.toList());
|
||||
expected.add("cli:/usr/bin/trino");
|
||||
assertEquals(expected, copied);
|
||||
assertEquals("/usr/lib", EmrReleaseImages.TRINO_CLI.into());
|
||||
assertEquals("trino/trino-cli", EmrReleaseImages.TRINO_CLI.as());
|
||||
assertEquals("/usr/lib", EmrReleaseImages.engineCli(EmrTrino.ENGINE).into());
|
||||
assertEquals("trino/trino-cli", EmrReleaseImages.engineCli(EmrTrino.ENGINE).as());
|
||||
verify(docker).removeContainerCmd("cli");
|
||||
ArgumentCaptor<String> tags = ArgumentCaptor.forClass(String.class);
|
||||
ArgumentCaptor<Map<String, String>> labels = mapCaptor();
|
||||
@@ -571,7 +571,8 @@ class EmrReleaseImagesTest {
|
||||
when(listImages.exec()).thenAnswer(invocation -> listed);
|
||||
when(docker.listImagesCmd()).thenReturn(listImages);
|
||||
|
||||
assertEquals("sha256:made", images.image(release, SPARK, HIVE, withHive, withPig, trino));
|
||||
assertEquals("sha256:made", images.image(release, SPARK, HIVE, withHive, withPig,
|
||||
trino != null ? EmrTrino.ENGINE : null, trino));
|
||||
return copied;
|
||||
}
|
||||
|
||||
|
||||
@@ -1128,12 +1128,13 @@ class EmrServiceContainerStepsTest {
|
||||
"public.ecr.aws/emr-serverless/hive/emr-7.5.0:latest", "true", "false")),
|
||||
fixture.releaseImages.asked);
|
||||
assertEquals(List.of("trinodb/trino:446"), fixture.releaseImages.trinoImages);
|
||||
assertEquals(new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of("hive", Map.of("hive.metastore",
|
||||
"glue"), "tpch", Map.of()), Map.of("http-server.http.port", "8890"),
|
||||
Map.of("node.environment", "production"), Map.of("io.trino", "DEBUG"),
|
||||
assertEquals(new ClusterStorage.QueryEngine(EmrTrino.ENGINE, "trinodb/trino:446", 2048,
|
||||
Map.of("hive", Map.of("hive.metastore", "glue"), "tpch", Map.of()),
|
||||
Map.of("http-server.http.port", "8890"), Map.of("node.environment", "production"),
|
||||
Map.of("io.trino", "DEBUG"),
|
||||
Map.of("DB_PASSWORD", "s3cret"), Map.of(), Map.of("password-authenticator.name", "ldap", "ldap.url",
|
||||
"ldaps://ldap.example.com:636"), null, 4, 1024, null),
|
||||
fixture.clusterStorage.metastores.get(0).trino());
|
||||
fixture.clusterStorage.metastores.get(0).queryEngine());
|
||||
SparkJobRunner.Job job = runner.jobs.get(0);
|
||||
assertEquals(args, job.command());
|
||||
String host = fixture.clusterStorage.hdfs.get(0).get(1);
|
||||
@@ -1156,8 +1157,9 @@ class EmrServiceContainerStepsTest {
|
||||
fixture.runStepThread();
|
||||
fixture.runStepThread();
|
||||
assertEquals(List.of("true"), runner.jobs.get(0).command());
|
||||
assertEquals(new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of(), Map.of(), Map.of(), Map.of(),
|
||||
Map.of(), null, Map.of(), null, 4, 1024, null), fixture.clusterStorage.metastores.get(0).trino());
|
||||
assertEquals(new ClusterStorage.QueryEngine(EmrTrino.ENGINE, "trinodb/trino:446", 2048, Map.of(), Map.of(),
|
||||
Map.of(), Map.of(), Map.of(), null, Map.of(), null, 4, 1024, null),
|
||||
fixture.clusterStorage.metastores.get(0).queryEngine());
|
||||
assertEquals(0, fixture.stepThreadsWaiting());
|
||||
}
|
||||
|
||||
@@ -1181,10 +1183,10 @@ class EmrServiceContainerStepsTest {
|
||||
}
|
||||
|
||||
// What the actions wrote is in the image they left, the primary node's.
|
||||
assertEquals(new ClusterStorage.Trino("trinodb/trino:446", 2048, Map.of(),
|
||||
assertEquals(new ClusterStorage.QueryEngine(EmrTrino.ENGINE, "trinodb/trino:446", 2048, Map.of(),
|
||||
Map.of("http-server.authentication.type", "PASSWORD"), Map.of(), Map.of(), Map.of(), null,
|
||||
Map.of("password-authenticator.name", "file", "file.password-file", "/home/hadoop/password.db"),
|
||||
"sha256:" + id, 4, 1024, null), bootstrapping.clusterStorage.metastores.get(0).trino());
|
||||
"sha256:" + id, 4, 1024, null), bootstrapping.clusterStorage.metastores.get(0).queryEngine());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1203,7 +1205,7 @@ class EmrServiceContainerStepsTest {
|
||||
// metastore EMR installs with Trino runs, and the release's Trino, 479.
|
||||
ClusterStorage.HiveMetastore metastore = fixture.clusterStorage.metastores.get(0);
|
||||
assertFalse(metastore.hdfs());
|
||||
assertEquals("trinodb/trino:479", metastore.trino().image());
|
||||
assertEquals("trinodb/trino:479", metastore.queryEngine().image());
|
||||
assertEquals(List.of(), fixture.clusterStorage.yarns);
|
||||
// In the release's Hive image, as on a cluster without YARN.
|
||||
assertEquals("public.ecr.aws/emr-serverless/hive/emr-7.14.0:latest", fixture.clusterStorage.hdfs.get(0).get(2));
|
||||
@@ -1233,7 +1235,7 @@ class EmrServiceContainerStepsTest {
|
||||
assertEquals(2, fixture.clusterStorage.yarns.size());
|
||||
// Their Trino's workers run on YARN's nodes.
|
||||
assertTrue(fixture.clusterStorage.metastores.stream()
|
||||
.allMatch(metastore -> metastore.trino().ownNodes() == null));
|
||||
.allMatch(metastore -> metastore.queryEngine().ownNodes() == null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1249,7 +1251,7 @@ class EmrServiceContainerStepsTest {
|
||||
fixture.runStepThread();
|
||||
|
||||
// Its core and task nodes run Trino's workers, and no YARN.
|
||||
ClusterStorage.Trino trino = fixture.clusterStorage.metastores.get(0).trino();
|
||||
ClusterStorage.QueryEngine trino = fixture.clusterStorage.metastores.get(0).queryEngine();
|
||||
assertEquals(List.of("1-1", "2-1"), trino.ownNodes().get().stream().map(ClusterStorage.Node::id).toList());
|
||||
assertEquals(List.of(), fixture.clusterStorage.yarns);
|
||||
String task = cluster.getInstanceGroups().get(2).getId();
|
||||
@@ -1286,7 +1288,7 @@ class EmrServiceContainerStepsTest {
|
||||
bootstrap.bootstraps.forEach(ran -> roles.put(String.valueOf(ran.node()), ran.instanceRole()));
|
||||
assertEquals(Map.of("null", "MASTER", "1-1", "CORE", "2-1", "TASK"), roles);
|
||||
assertEquals(List.of("sha256:" + id + "-1-1", "sha256:" + id + "-2-1"), bootstrapping.clusterStorage.metastores
|
||||
.get(0).trino().workers(null).stream().map(ClusterStorage.Node::image).toList());
|
||||
.get(0).queryEngine().workers(null).stream().map(ClusterStorage.Node::image).toList());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1355,14 +1357,15 @@ class EmrServiceContainerStepsTest {
|
||||
hive.setApplications("[{\"Name\": \"Hive\"}]");
|
||||
String hiveId = withTrino.runJobFlow(hive, REGION).getId();
|
||||
|
||||
assertEquals(Optional.of(new EmrService.TrinoCluster(ACCOUNT, REGION, trinoId, "WAITING", 8890)),
|
||||
withTrino.trinoCluster(trinoId));
|
||||
assertEquals(Optional.empty(), withTrino.trinoCluster(hiveId));
|
||||
assertEquals(Optional.empty(), withTrino.trinoCluster("j-NOSUCHCLUSTER"));
|
||||
assertEquals(Optional.of(new EmrService.QueryEngineCluster(ACCOUNT, REGION, trinoId, "WAITING",
|
||||
EmrTrino.ENGINE, 8890)),
|
||||
withTrino.queryEngineCluster(trinoId));
|
||||
assertEquals(Optional.empty(), withTrino.queryEngineCluster(hiveId));
|
||||
assertEquals(Optional.empty(), withTrino.queryEngineCluster("j-NOSUCHCLUSTER"));
|
||||
// With Floci's Trino off, or on a network its steps share, it runs none.
|
||||
assertEquals(Optional.empty(), service.trinoCluster(trinoId));
|
||||
assertEquals(Optional.empty(), service.queryEngineCluster(trinoId));
|
||||
fixture.clusterStorage.ownNetwork = false;
|
||||
assertEquals(Optional.empty(), withTrino.trinoCluster(trinoId));
|
||||
assertEquals(Optional.empty(), withTrino.queryEngineCluster(trinoId));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -213,7 +213,7 @@ final class EmrServiceFixture {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resizeTrino(String clusterId) {
|
||||
public void resizeQueryEngine(String clusterId) {
|
||||
trinoResizes.add(clusterId);
|
||||
}
|
||||
|
||||
@@ -271,7 +271,7 @@ final class EmrServiceFixture {
|
||||
|
||||
@Override
|
||||
public String image(String releaseLabel, String sparkImage, String hiveImage, boolean withHive,
|
||||
boolean withPig, String trinoImage) {
|
||||
boolean withPig, EmrQueryEngine engine, String trinoImage) {
|
||||
asked.add(List.of(releaseLabel, sparkImage, hiveImage, String.valueOf(withHive), String.valueOf(withPig)));
|
||||
trinoImages.add(trinoImage);
|
||||
if (failure != null) {
|
||||
|
||||
@@ -28,6 +28,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@ResourceLock(value = ParallelLocks.PORTS, mode = ResourceAccessMode.READ)
|
||||
class EmrSparkStepsTest {
|
||||
|
||||
private static final EmrQueryEngine TRINO = EmrTrino.ENGINE;
|
||||
|
||||
// A cluster's Applications, as RunJobFlow stores them, in a case of their own.
|
||||
private static final String HIVE_AND_SPARK = "[{\"Name\": \"Spark\"}, {\"Name\": \"hive\"}]";
|
||||
private static final String RELEASE = "emr-7.5.0";
|
||||
@@ -279,15 +281,17 @@ class EmrSparkStepsTest {
|
||||
"Configurations": [{"Classification": "export", "Properties": {"HADOOP_HEAPSIZE": "2048"}}]}]
|
||||
""";
|
||||
|
||||
assertEquals(Map.of("node.environment", "production"), EmrSparkSteps.trinoNode(configurations, objectMapper));
|
||||
assertEquals(Map.of("io.trino", "DEBUG"), EmrSparkSteps.trinoLog(configurations, objectMapper));
|
||||
// "If any classification ends in env, use the export sub-classification."
|
||||
assertEquals(Map.of("DB_PASSWORD", "s3cret"), EmrSparkSteps.trinoEnvironment(configurations, objectMapper));
|
||||
assertEquals(Map.of(), EmrSparkSteps.trinoEnvironment(null, objectMapper));
|
||||
// An exchange manager only where the cluster names one, one with no properties at EMR's defaults.
|
||||
assertNull(EmrSparkSteps.trinoExchangeManager(configurations, objectMapper));
|
||||
assertEquals(Map.of(), EmrSparkSteps.trinoExchangeManager("[{\"Classification\": \"trino-exchange-manager\"}]",
|
||||
assertEquals(Map.of("node.environment", "production"), EmrSparkSteps.engineNode(TRINO, configurations,
|
||||
objectMapper));
|
||||
assertEquals(Map.of("io.trino", "DEBUG"), EmrSparkSteps.engineLog(TRINO, configurations, objectMapper));
|
||||
// "If any classification ends in env, use the export sub-classification."
|
||||
assertEquals(Map.of("DB_PASSWORD", "s3cret"), EmrSparkSteps.engineEnvironment(TRINO, configurations,
|
||||
objectMapper));
|
||||
assertEquals(Map.of(), EmrSparkSteps.engineEnvironment(TRINO, null, objectMapper));
|
||||
// An exchange manager only where the cluster names one, one with no properties at EMR's defaults.
|
||||
assertNull(EmrSparkSteps.engineExchangeManager(TRINO, configurations, objectMapper));
|
||||
assertEquals(Map.of(), EmrSparkSteps.engineExchangeManager(TRINO,
|
||||
"[{\"Classification\": \"trino-exchange-manager\"}]", objectMapper));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -304,8 +308,8 @@ class EmrSparkStepsTest {
|
||||
assertEquals(Map.of("password-authenticator.name", "ldap", "ldap.url",
|
||||
"ldaps://ip-xxx-xxx-xxx-xxx.ec2.internal:636", "ldap.user-bind-pattern",
|
||||
"uid=${USER},ou=admins,dc=ec2,dc=internal"),
|
||||
EmrSparkSteps.trinoPasswordAuthenticator(configurations, objectMapper));
|
||||
assertEquals(Map.of(), EmrSparkSteps.trinoPasswordAuthenticator("[]", objectMapper));
|
||||
EmrSparkSteps.enginePasswordAuthenticator(TRINO, configurations, objectMapper));
|
||||
assertEquals(Map.of(), EmrSparkSteps.enginePasswordAuthenticator(TRINO, "[]", objectMapper));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -322,15 +326,16 @@ class EmrSparkStepsTest {
|
||||
{"Classification": "trino-config", "Properties": {"http-server.http.port": "8890"}}]
|
||||
""";
|
||||
|
||||
Map<String, Map<String, String>> connectors = EmrSparkSteps.trinoConnectors(configurations, objectMapper);
|
||||
Map<String, Map<String, String>> connectors = EmrSparkSteps.engineConnectors(TRINO, configurations,
|
||||
objectMapper);
|
||||
|
||||
assertEquals(List.of("hive", "iceberg", "tpch"), List.copyOf(connectors.keySet()));
|
||||
assertEquals(Map.of("hive.metastore", "glue", "hive.metastore.glue.catalogid", "444455556666"),
|
||||
connectors.get("hive"));
|
||||
assertEquals(Map.of(), connectors.get("tpch"));
|
||||
assertEquals(Map.of("http-server.http.port", "8890"), EmrSparkSteps.trinoConfig(configurations,
|
||||
assertEquals(Map.of("http-server.http.port", "8890"), EmrSparkSteps.engineConfig(TRINO, configurations,
|
||||
objectMapper));
|
||||
assertEquals(Map.of(), EmrSparkSteps.trinoConnectors(null, objectMapper));
|
||||
assertEquals(Map.of(), EmrSparkSteps.engineConnectors(TRINO, null, objectMapper));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -75,9 +75,9 @@ class EmrTrinoHttpsIntegrationTest {
|
||||
@BeforeEach
|
||||
void runningCluster() {
|
||||
EmrService clusters = mock(EmrService.class);
|
||||
when(clusters.trinoCluster(CLUSTER)).thenReturn(Optional.of(new EmrService.TrinoCluster("000000000000",
|
||||
"us-east-1", CLUSTER, EmrClusterLifecycle.WAITING, EmrTrino.PORT)));
|
||||
when(clusters.trinoInterface(CLUSTER, EmrTrino.PORT)).thenReturn(Optional.of(
|
||||
when(clusters.queryEngineCluster(CLUSTER)).thenReturn(Optional.of(new EmrService.QueryEngineCluster(
|
||||
"000000000000", "us-east-1", CLUSTER, EmrClusterLifecycle.WAITING, EmrTrino.ENGINE, EmrTrino.PORT)));
|
||||
when(clusters.queryEngineInterface(CLUSTER, EmrTrino.PORT)).thenReturn(Optional.of(
|
||||
new ContainerLifecycleManager.EndpointInfo("127.0.0.1", trino.getAddress().getPort())));
|
||||
QuarkusMock.installMockForType(clusters, EmrService.class);
|
||||
schemes.clear();
|
||||
|
||||
@@ -52,44 +52,45 @@ class EmrTrinoRoutesTest {
|
||||
|
||||
@Test
|
||||
void aClusterWithNoTrinoOfFlocisIsNotFound() {
|
||||
when(clusters.trinoCluster(CLUSTER)).thenReturn(Optional.empty());
|
||||
when(clusters.queryEngineCluster(CLUSTER)).thenReturn(Optional.empty());
|
||||
|
||||
AppUiRoute route = routes.route(HOST, "http");
|
||||
|
||||
assertEquals(404, route.status());
|
||||
assertEquals(String.format(EmrTrinoRoutes.NO_SUCH_CLUSTER, CLUSTER), route.refusal());
|
||||
assertEquals(String.format(EmrQueryEngineRoutes.NO_SUCH_CLUSTER, CLUSTER, "Trino"), route.refusal());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aClusterStillStartingIsAskedAgainAndOneThatHasEndedIsGone() {
|
||||
when(clusters.trinoCluster(CLUSTER)).thenReturn(Optional.of(cluster("STARTING")));
|
||||
when(clusters.queryEngineCluster(CLUSTER)).thenReturn(Optional.of(cluster("STARTING")));
|
||||
assertEquals(503, routes.route(HOST, "http").status());
|
||||
|
||||
when(clusters.trinoCluster(CLUSTER)).thenReturn(Optional.of(cluster("TERMINATED")));
|
||||
when(clusters.queryEngineCluster(CLUSTER)).thenReturn(Optional.of(cluster("TERMINATED")));
|
||||
assertEquals(404, routes.route(HOST, "http").status());
|
||||
when(clusters.trinoCluster(CLUSTER)).thenReturn(Optional.of(cluster("TERMINATING")));
|
||||
assertEquals(String.format(EmrTrinoRoutes.CLUSTER_ENDED, CLUSTER), routes.route(HOST, "http").refusal());
|
||||
when(clusters.queryEngineCluster(CLUSTER)).thenReturn(Optional.of(cluster("TERMINATING")));
|
||||
assertEquals(String.format(EmrQueryEngineRoutes.CLUSTER_ENDED, CLUSTER, "Trino"),
|
||||
routes.route(HOST, "http").refusal());
|
||||
|
||||
verify(clusters, never()).startPrimaryNode(anyString());
|
||||
verify(clusters, never()).trinoInterface(anyString(), anyInt());
|
||||
verify(clusters, never()).queryEngineInterface(anyString(), anyInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTrinoNotAnsweringYetHasItsPrimaryNodeStartedAndTheClientAskedAgain() {
|
||||
when(clusters.trinoCluster(CLUSTER)).thenReturn(Optional.of(cluster("WAITING")));
|
||||
when(clusters.trinoInterface(CLUSTER, 8890)).thenReturn(Optional.empty());
|
||||
when(clusters.queryEngineCluster(CLUSTER)).thenReturn(Optional.of(cluster("WAITING")));
|
||||
when(clusters.queryEngineInterface(CLUSTER, 8890)).thenReturn(Optional.empty());
|
||||
|
||||
AppUiRoute route = routes.route(HOST, "http");
|
||||
|
||||
assertEquals(503, route.status());
|
||||
assertEquals(String.format(EmrTrinoRoutes.NOT_READY, CLUSTER), route.refusal());
|
||||
assertEquals(String.format(EmrQueryEngineRoutes.NOT_READY, CLUSTER, "Trino"), route.refusal());
|
||||
verify(clusters).startPrimaryNode(CLUSTER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRunningTrinoIsReachedWithTheSchemeTheClientUsedItsPortFoundOnceInTenSeconds() {
|
||||
when(clusters.trinoCluster(CLUSTER)).thenReturn(Optional.of(cluster("RUNNING")));
|
||||
when(clusters.trinoInterface(CLUSTER, 8890)).thenReturn(Optional.of(ENDPOINT));
|
||||
when(clusters.queryEngineCluster(CLUSTER)).thenReturn(Optional.of(cluster("RUNNING")));
|
||||
when(clusters.queryEngineInterface(CLUSTER, 8890)).thenReturn(Optional.of(ENDPOINT));
|
||||
|
||||
// A host name is read without case.
|
||||
AppUiRoute route = routes.route(HOST.toUpperCase(), "https");
|
||||
@@ -101,20 +102,20 @@ class EmrTrinoRoutesTest {
|
||||
assertEquals(Map.of(), route.rewrites());
|
||||
assertEquals(503, route.unansweredStatus());
|
||||
assertEquals(Map.of("X-Forwarded-Proto", "http"), routes.route(HOST, "http").headers());
|
||||
verify(clusters, times(1)).trinoInterface(CLUSTER, 8890);
|
||||
verify(clusters, times(1)).queryEngineInterface(CLUSTER, 8890);
|
||||
|
||||
clock.advance(Duration.ofSeconds(10));
|
||||
routes.route(HOST, "http");
|
||||
verify(clusters, times(2)).trinoInterface(CLUSTER, 8890);
|
||||
verify(clusters, times(2)).queryEngineInterface(CLUSTER, 8890);
|
||||
|
||||
// One that does not answer is looked for again.
|
||||
routes.route(HOST, "http").unreachable().run();
|
||||
routes.route(HOST, "http");
|
||||
verify(clusters, times(3)).trinoInterface(CLUSTER, 8890);
|
||||
verify(clusters, times(3)).queryEngineInterface(CLUSTER, 8890);
|
||||
verify(clusters, never()).startPrimaryNode(anyString());
|
||||
}
|
||||
|
||||
private static EmrService.TrinoCluster cluster(String state) {
|
||||
return new EmrService.TrinoCluster("000000000000", "us-east-1", CLUSTER, state, 8890);
|
||||
private static EmrService.QueryEngineCluster cluster(String state) {
|
||||
return new EmrService.QueryEngineCluster("000000000000", "us-east-1", CLUSTER, state, EmrTrino.ENGINE, 8890);
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@ResourceLock(value = ParallelLocks.PORTS, mode = ResourceAccessMode.READ)
|
||||
class EmrTrinoTest {
|
||||
|
||||
private static final EmrQueryEngine TRINO = EmrTrino.ENGINE;
|
||||
|
||||
private static final String ENDPOINT = "http://floci:4566";
|
||||
private static final String SERVER = "http://ip-10-0-0-1.ec2.internal:8889";
|
||||
private static final String PRIMARY = "ip-10-0-0-1.ec2.internal";
|
||||
@@ -34,13 +36,13 @@ class EmrTrinoTest {
|
||||
|
||||
@Test
|
||||
void theImageIsOfTheTrinoTheReleaseShips() {
|
||||
assertEquals("trinodb/trino:446", EmrTrino.image("trinodb/trino:%s", "emr-7.5.0"));
|
||||
assertEquals("trinodb/trino:479", EmrTrino.image("trinodb/trino:%s", "emr-7.14.0"));
|
||||
assertEquals("trinodb/trino:446", TRINO.image("trinodb/trino:%s", "emr-7.5.0"));
|
||||
assertEquals("trinodb/trino:479", TRINO.image("trinodb/trino:%s", "emr-7.14.0"));
|
||||
// The AWS runtime for Apache Spark ships none, and a release Floci does not list has no version.
|
||||
assertNull(EmrTrino.image("trinodb/trino:%s", "emr-spark-8.0.0"));
|
||||
assertNull(EmrTrino.image("trinodb/trino:%s", "emr-9.9.9"));
|
||||
assertNull(TRINO.image("trinodb/trino:%s", "emr-spark-8.0.0"));
|
||||
assertNull(TRINO.image("trinodb/trino:%s", "emr-9.9.9"));
|
||||
// An image with no %s serves every release.
|
||||
assertEquals("registry.internal/trino:446", EmrTrino.image("registry.internal/trino:446", "emr-9.9.9"));
|
||||
assertEquals("registry.internal/trino:446", TRINO.image("registry.internal/trino:446", "emr-9.9.9"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -50,7 +52,7 @@ class EmrTrinoTest {
|
||||
assertEquals(List.of("connector.name=hive", "hive.metastore.uri=thrift://localhost:9083",
|
||||
"fs.native-s3.enabled=true", "fs.hadoop.enabled=true", "s3.endpoint=" + ENDPOINT,
|
||||
"s3.region=us-east-1", "s3.path-style-access=true"),
|
||||
List.of(EmrTrino.properties(catalog).split("\n")));
|
||||
List.of(EmrQueryEngine.properties(catalog).split("\n")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,7 +68,7 @@ class EmrTrinoTest {
|
||||
"hive.metastore.glue.endpoint-url=" + ENDPOINT, "fs.native-s3.enabled=true",
|
||||
"fs.hadoop.enabled=true", "s3.endpoint=" + ENDPOINT, "s3.region=eu-west-1",
|
||||
"s3.path-style-access=false", "hive.metastore.glue.catalogid=111122223333"),
|
||||
List.of(EmrTrino.properties(catalog).split("\n")));
|
||||
List.of(EmrQueryEngine.properties(catalog).split("\n")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,12 +125,12 @@ class EmrTrinoTest {
|
||||
connectors.put("tpch", Map.of());
|
||||
connectors.put("hive", Map.of("hive.metastore", "glue"));
|
||||
|
||||
Map<String, Map<String, String>> catalogs = EmrTrino.catalogs(connectors, "localhost", ENDPOINT, "us-east-1");
|
||||
Map<String, Map<String, String>> catalogs = TRINO.catalogs(connectors, "localhost", ENDPOINT, "us-east-1");
|
||||
|
||||
assertEquals(List.of("hive", "tpch"), List.copyOf(catalogs.keySet()));
|
||||
assertEquals("glue", catalogs.get("hive").get("hive.metastore"));
|
||||
assertEquals(List.of("hive"),
|
||||
List.copyOf(EmrTrino.catalogs(Map.of(), "localhost", ENDPOINT, "us-east-1").keySet()));
|
||||
List.copyOf(TRINO.catalogs(Map.of(), "localhost", ENDPOINT, "us-east-1").keySet()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,19 +140,19 @@ class EmrTrinoTest {
|
||||
assertEquals(List.of("coordinator=true", "node-scheduler.include-coordinator=true",
|
||||
"http-server.http.port=8889", "discovery.uri=http://localhost:8889",
|
||||
"http-server.process-forwarded=true", "internal-communication.shared-secret=s3cret"),
|
||||
List.of(EmrTrino.properties(EmrTrino.config(Map.of(), false, "s3cret")).split("\n")));
|
||||
List.of(EmrQueryEngine.properties(TRINO.config(Map.of(), false, "s3cret")).split("\n")));
|
||||
// "To change the port, use the presto-config configuration classification to set the http-server.http.port
|
||||
// property", trino-config for Trino: its discovery follows.
|
||||
Map<String, String> moved = EmrTrino.config(Map.of("http-server.http.port", "8890",
|
||||
Map<String, String> moved = TRINO.config(Map.of("http-server.http.port", "8890",
|
||||
"query.max-memory", "1GB"), false, "s3cret");
|
||||
assertEquals(List.of("coordinator=true", "node-scheduler.include-coordinator=true",
|
||||
"http-server.http.port=8890", "discovery.uri=http://localhost:8890",
|
||||
"http-server.process-forwarded=true", "internal-communication.shared-secret=s3cret",
|
||||
"query.max-memory=1GB"),
|
||||
List.of(EmrTrino.properties(moved).split("\n")));
|
||||
assertEquals(8890, EmrTrino.port(moved));
|
||||
assertEquals(8889, EmrTrino.port(Map.of("http-server.http.port", "eighty")));
|
||||
assertEquals("http://ip-10-0-0-1.ec2.internal:8890", EmrTrino.server("ip-10-0-0-1.ec2.internal", 8890));
|
||||
List.of(EmrQueryEngine.properties(moved).split("\n")));
|
||||
assertEquals(8890, EmrQueryEngine.port(moved));
|
||||
assertEquals(8889, EmrQueryEngine.port(Map.of("http-server.http.port", "eighty")));
|
||||
assertEquals("http://ip-10-0-0-1.ec2.internal:8890", EmrQueryEngine.server("ip-10-0-0-1.ec2.internal", 8890));
|
||||
// Its image's own health check, which asks the port config.properties names, without credentials.
|
||||
assertEquals(List.of("/usr/lib/trino/bin/health-check"), EmrTrino.READY_CHECK);
|
||||
}
|
||||
@@ -159,9 +161,9 @@ class EmrTrinoTest {
|
||||
void aCoordinatorWithWorkersLeavesTheQueriesToThem() {
|
||||
// Trino's deployment guide: a coordinator of a cluster with workers runs none of their work, as AWS's
|
||||
// "coordinator-worker model, where each component has a specialized role in query execution" has it.
|
||||
assertEquals("false", EmrTrino.config(Map.of(), true, "s3cret").get("node-scheduler.include-coordinator"));
|
||||
assertEquals("false", TRINO.config(Map.of(), true, "s3cret").get("node-scheduler.include-coordinator"));
|
||||
// The cluster's trino-config says otherwise, if it does.
|
||||
assertEquals("true", EmrTrino.config(Map.of("node-scheduler.include-coordinator", "true"), true, "s3cret")
|
||||
assertEquals("true", TRINO.config(Map.of("node-scheduler.include-coordinator", "true"), true, "s3cret")
|
||||
.get("node-scheduler.include-coordinator"));
|
||||
}
|
||||
|
||||
@@ -170,15 +172,15 @@ class EmrTrinoTest {
|
||||
// "you can override the configuration with your own secret key", on every node.
|
||||
Map<String, String> own = Map.of("internal-communication.shared-secret", "mine");
|
||||
|
||||
assertEquals("mine", EmrTrino.config(own, true, "s3cret").get(EmrTrino.SHARED_SECRET));
|
||||
assertEquals("mine", EmrTrino.workerConfig(own, PRIMARY, "s3cret").get(EmrTrino.SHARED_SECRET));
|
||||
assertEquals("mine", TRINO.config(own, true, "s3cret").get(EmrTrino.SHARED_SECRET));
|
||||
assertEquals("mine", TRINO.workerConfig(own, PRIMARY, "s3cret").get(EmrTrino.SHARED_SECRET));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aWorkerFindsTheCoordinatorOnThePrimaryNodeAndTakesTheClustersTrinoConfig() {
|
||||
assertEquals(List.of("coordinator=false", "http-server.http.port=8889",
|
||||
"discovery.uri=http://ip-10-0-0-1.ec2.internal:8889", "internal-communication.shared-secret=s3cret"),
|
||||
List.of(EmrTrino.properties(EmrTrino.workerConfig(Map.of(), PRIMARY, "s3cret")).split("\n")));
|
||||
List.of(EmrQueryEngine.properties(TRINO.workerConfig(Map.of(), PRIMARY, "s3cret")).split("\n")));
|
||||
// "configuration properties must be set on the coordinator and all worker nodes": a port of the cluster's own
|
||||
// is every node's, the coordinator's discovery with it.
|
||||
Map<String, String> classification = new LinkedHashMap<>();
|
||||
@@ -187,14 +189,14 @@ class EmrTrinoTest {
|
||||
assertEquals(List.of("coordinator=false", "http-server.http.port=8890",
|
||||
"discovery.uri=http://ip-10-0-0-1.ec2.internal:8890", "internal-communication.shared-secret=s3cret",
|
||||
"query.max-memory-per-node=512MB"),
|
||||
List.of(EmrTrino.properties(EmrTrino.workerConfig(classification, PRIMARY, "s3cret")).split("\n")));
|
||||
List.of(EmrQueryEngine.properties(TRINO.workerConfig(classification, PRIMARY, "s3cret")).split("\n")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aWorkerIsReachedAtItsNodesHostTheClustersTrinoNodeAfter() {
|
||||
// Not at whichever of the node's addresses Trino would pick, a link-local one among them.
|
||||
assertEquals(List.of("node.internal-address=ip-10-0-0-2.ec2.internal", "node.environment=production"),
|
||||
List.of(EmrTrino.properties(EmrTrino.workerNode(Map.of("node.environment", "production"),
|
||||
List.of(EmrQueryEngine.properties(TRINO.workerNode(Map.of("node.environment", "production"),
|
||||
"ip-10-0-0-2.ec2.internal")).split("\n")));
|
||||
}
|
||||
|
||||
@@ -206,14 +208,14 @@ class EmrTrinoTest {
|
||||
|
||||
// Each worker is then named after its node's host by the entrypoint, as a node given no id is.
|
||||
assertEquals(List.of("node.internal-address=ip-10-0-0-2.ec2.internal", "node.environment=production"),
|
||||
List.of(EmrTrino.properties(EmrTrino.workerNode(classification, "ip-10-0-0-2.ec2.internal"))
|
||||
List.of(EmrQueryEngine.properties(TRINO.workerNode(classification, "ip-10-0-0-2.ec2.internal"))
|
||||
.split("\n")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aWorkersCatalogsReachTheMetastoreOnThePrimaryNode() {
|
||||
assertEquals("thrift://ip-10-0-0-1.ec2.internal:9083",
|
||||
EmrTrino.catalogs(Map.of(), PRIMARY, ENDPOINT, "us-east-1").get("hive").get("hive.metastore.uri"));
|
||||
TRINO.catalogs(Map.of(), PRIMARY, ENDPOINT, "us-east-1").get("hive").get("hive.metastore.uri"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -226,10 +228,10 @@ class EmrTrinoTest {
|
||||
ldap.put("ldap.ssl.keystore.path", "keys/ldap-key.pem");
|
||||
|
||||
// The key store's path is relative, and the trust store named twice is one file.
|
||||
assertEquals(List.of("/etc/trino/ldap-truststore.pem"), EmrTrino.authenticatorFiles(ldap));
|
||||
assertEquals(List.of("/home/hadoop/password.db"), EmrTrino.authenticatorFiles(Map.of(
|
||||
assertEquals(List.of("/etc/trino/ldap-truststore.pem"), TRINO.authenticatorFiles(ldap));
|
||||
assertEquals(List.of("/home/hadoop/password.db"), TRINO.authenticatorFiles(Map.of(
|
||||
"password-authenticator.name", "file", "file.password-file", "/home/hadoop/password.db")));
|
||||
assertEquals(List.of(), EmrTrino.authenticatorFiles(Map.of()));
|
||||
assertEquals(List.of(), TRINO.authenticatorFiles(Map.of()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -239,7 +241,7 @@ class EmrTrinoTest {
|
||||
assertEquals(List.of("exchange-manager.name=hdfs",
|
||||
"exchange.base-directories=hdfs://ip-10-0-0-1.ec2.internal:8020/user/trino/trino-exchange/",
|
||||
"hdfs.config.resources=/etc/trino/exchange-core-site.xml"),
|
||||
List.of(EmrTrino.properties(EmrTrino.exchangeManager(Map.of(), NAMENODE, ENDPOINT, "us-east-1"))
|
||||
List.of(EmrQueryEngine.properties(EmrTrino.exchangeManager(Map.of(), NAMENODE, ENDPOINT, "us-east-1"))
|
||||
.split("\n")));
|
||||
// "Set exchange.use-local-hdfs to true. Set exchange.base-directories to the custom directory location in
|
||||
// HDFS", a property the Trino project's Trino does not take; the HDFS settings EMR lists go on.
|
||||
@@ -250,7 +252,7 @@ class EmrTrinoTest {
|
||||
assertEquals(List.of("exchange-manager.name=hdfs",
|
||||
"exchange.base-directories=hdfs://ip-10-0-0-1.ec2.internal:8020/exchange",
|
||||
"hdfs.config.resources=/etc/trino/exchange-core-site.xml", "exchange.hdfs.block-size=8MB"),
|
||||
List.of(EmrTrino.properties(EmrTrino.exchangeManager(custom, NAMENODE, ENDPOINT, "us-east-1"))
|
||||
List.of(EmrQueryEngine.properties(EmrTrino.exchangeManager(custom, NAMENODE, ENDPOINT, "us-east-1"))
|
||||
.split("\n")));
|
||||
}
|
||||
|
||||
@@ -265,22 +267,22 @@ class EmrTrinoTest {
|
||||
"exchange.base-directories=s3://spool-a/exchange,s3://spool-b/exchange",
|
||||
"exchange.s3.endpoint=" + ENDPOINT, "exchange.s3.region=eu-west-1",
|
||||
"exchange.s3.path-style-access=false", "exchange.sink-buffers-per-partition=4"),
|
||||
List.of(EmrTrino.properties(EmrTrino.exchangeManager(s3, NAMENODE, ENDPOINT, "eu-west-1"))
|
||||
List.of(EmrQueryEngine.properties(EmrTrino.exchangeManager(s3, NAMENODE, ENDPOINT, "eu-west-1"))
|
||||
.split("\n")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void clientsOutsideTheClusterReachItsTrinoOnAHostOfTheClustersOwnUnderFlocis() {
|
||||
assertEquals("http://j-2axxxxxxgaplf.emr-trino.localhost:4566",
|
||||
EmrTrino.address("http://localhost:4566", "j-2AXXXXXXGAPLF"));
|
||||
TRINO.address("http://localhost:4566", "j-2AXXXXXXGAPLF"));
|
||||
assertEquals("https://j-2axxxxxxgaplf.emr-trino.localhost.floci.io:4566",
|
||||
EmrTrino.address("https://localhost.floci.io:4566/", "j-2AXXXXXXGAPLF"));
|
||||
TRINO.address("https://localhost.floci.io:4566/", "j-2AXXXXXXGAPLF"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theEntrypointWritesTheConfigurationNodeLogAndCatalogsFlociGivesAloneAndANodeIdTrinoTakes(@TempDir Path etc)
|
||||
throws Exception {
|
||||
String config = EmrTrino.properties(EmrTrino.config(Map.of(), false, "s3cret"));
|
||||
String config = EmrQueryEngine.properties(TRINO.config(Map.of(), false, "s3cret"));
|
||||
Map<String, String> environment = new LinkedHashMap<>();
|
||||
environment.put(EmrTrino.CONFIG_VARIABLE, config);
|
||||
environment.put(EmrTrino.NODE_VARIABLE, "node.environment=production");
|
||||
@@ -331,7 +333,8 @@ class EmrTrinoTest {
|
||||
|
||||
@Test
|
||||
void theEntrypointWritesTheExchangeManagerTheClusterGives(@TempDir Path etc) throws Exception {
|
||||
String exchange = EmrTrino.properties(EmrTrino.exchangeManager(Map.of(), NAMENODE, ENDPOINT, "us-east-1"));
|
||||
String exchange = EmrQueryEngine.properties(EmrTrino.exchangeManager(Map.of(), NAMENODE, ENDPOINT,
|
||||
"us-east-1"));
|
||||
|
||||
runEntrypoint(etc, Map.of(EmrTrino.EXCHANGE_VARIABLE, exchange, EmrTrino.EXCHANGE_SITE_VARIABLE,
|
||||
EmrTrino.exchangeSite(NAMENODE)));
|
||||
|
||||
Reference in new issue
Block a user