Skip to content

Commit

Permalink
Add e2e test for remote functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe-Abraham committed Nov 28, 2024
1 parent 0ee4687 commit 26886d1
Show file tree
Hide file tree
Showing 11 changed files with 478 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ presto-native-execution/deps-install
# Compiled executables used for docker build
/docker/presto-cli-*-executable.jar
/docker/presto-server-*.tar.gz
/docker/presto-remote-function-server-executable.jar
4 changes: 4 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ FROM quay.io/centos/centos:stream9
ARG PRESTO_VERSION
ARG PRESTO_PKG=presto-server-$PRESTO_VERSION.tar.gz
ARG PRESTO_CLI_JAR=presto-cli-$PRESTO_VERSION-executable.jar
ARG PRESTO_REMOTE_SERVER_JAR=presto-remote-function-server-executable.jar
ARG JMX_PROMETHEUS_JAVAAGENT_VERSION=0.20.0

ENV PRESTO_HOME="/opt/presto-server"

COPY $PRESTO_PKG .
COPY $PRESTO_CLI_JAR /opt/presto-cli
COPY $PRESTO_REMOTE_SERVER_JAR /opt/presto-remote-server


RUN dnf install -y java-11-openjdk less procps python3 \
&& ln -s $(which python3) /usr/bin/python \
Expand All @@ -19,6 +22,7 @@ RUN dnf install -y java-11-openjdk less procps python3 \
&& rm -rf ./presto-server-$PRESTO_VERSION \
&& chmod +x /opt/presto-cli \
&& ln -s /opt/presto-cli /usr/local/bin/ \
&& chmod +x /opt/presto-remote-server \
# clean cache jobs
&& mv /etc/yum/protected.d/systemd.conf /etc/yum/protected.d/systemd.conf.bak \
&& dnf clean all \
Expand Down
2 changes: 2 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

set -e

java -Dconfig=/opt/function-server/etc/config.properties -jar /opt/presto-remote-server >> log1.txt 2>&1

$PRESTO_HOME/bin/launcher run
20 changes: 20 additions & 0 deletions presto-main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,26 @@
</ignorePackages>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>presto-remote-function-server-executable</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.facebook.presto.server.FunctionServer</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
Expand Down
8 changes: 7 additions & 1 deletion presto-native-execution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,12 @@
<include>presto-cli-*-executable.jar</include>
</includes>
</resource>
<resource>
<directory>${project.parent.basedir}/presto-main/target</directory>
<includes>
<include>presto-remote-function-server-executable.jar</include>
</includes>
</resource>
<resource>
<directory>${project.parent.basedir}/presto-server/target</directory>
<includes>
Expand Down Expand Up @@ -433,7 +439,7 @@
<args>
<BUILD_TYPE>Release</BUILD_TYPE>
<DEPENDENCY_IMAGE>presto-native-dependency:latest</DEPENDENCY_IMAGE>
<EXTRA_CMAKE_FLAGS>-DPRESTO_ENABLE_TESTING=OFF</EXTRA_CMAKE_FLAGS>
<EXTRA_CMAKE_FLAGS>-DPRESTO_ENABLE_REMOTE_FUNCTIONS=ON</EXTRA_CMAKE_FLAGS>
<NUM_THREADS>2</NUM_THREADS>
<BASE_IMAGE>ubuntu:22.04</BASE_IMAGE>
<OSNAME>ubuntu</OSNAME>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,5 +314,5 @@ JavaClasses:
- presto-main/src/main/java/com/facebook/presto/connector/system/SystemTableLayoutHandle.java
- presto-main/src/main/java/com/facebook/presto/connector/system/SystemTransactionHandle.java
- presto-spi/src/main/java/com/facebook/presto/spi/function/AggregationFunctionMetadata.java
- presto-function-namespace-managers/src/main/java/com/facebook/presto/functionNamespace/json/JsonBasedUdfFunctionMetadata.java
- presto-function-namespace-managers/src/main/java/com/facebook/presto/functionNamespace/JsonBasedUdfFunctionMetadata.java
- presto-spi/src/main/java/com/facebook/presto/spi/plan/ExchangeEncoding.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,4 +364,4 @@ JavaClasses:
- presto-main/src/main/java/com/facebook/presto/connector/system/SystemTableLayoutHandle.java
- presto-main/src/main/java/com/facebook/presto/connector/system/SystemTransactionHandle.java
- presto-spi/src/main/java/com/facebook/presto/spi/function/AggregationFunctionMetadata.java
- presto-function-namespace-managers/src/main/java/com/facebook/presto/functionNamespace/json/JsonBasedUdfFunctionMetadata.java
- presto-function-namespace-managers/src/main/java/com/facebook/presto/functionNamespace/JsonBasedUdfFunctionMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.Duration;
Expand All @@ -50,6 +50,7 @@
import java.util.logging.Logger;

import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
import static java.sql.DriverManager.getConnection;

public class ContainerQueryRunner
implements QueryRunner
Expand All @@ -72,7 +73,6 @@ public class ContainerQueryRunner
private final String schema;
private final int numberOfWorkers;
private Connection connection;
private Statement statement;

public ContainerQueryRunner()
throws InterruptedException, IOException
Expand Down Expand Up @@ -108,8 +108,7 @@ public ContainerQueryRunner(int coordinatorPort, String catalog, String schema,
"timeZoneId=UTC");

try {
Connection connection = DriverManager.getConnection(url, "test", null);
statement = connection.createStatement();
connection = getConnection(url, "test", null);
}
catch (SQLException e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -297,12 +296,12 @@ public Session getDefaultSession()
public MaterializedResult execute(Session session, String sql)
{
try {
return ContainerQueryRunnerUtils
.toMaterializedResult(
statement.executeQuery(sql));
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
return ContainerQueryRunnerUtils.toMaterializedResult(resultSet);
}
catch (SQLException e) {
throw new RuntimeException(e);
throw new RuntimeException("Error executing query: " + sql, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ public static void createNativeWorkerConfigProperties(int coordinatorPort, Strin
createPropertiesFile("testcontainers/" + nodeId + "/etc/config.properties", properties);
}

public static void createNativeWorkerConfigPropertiesWithFunctionServer(int coordinatorPort, int functionServerPort, String nodeId)
throws IOException
{
Properties properties = new Properties();
properties.setProperty("presto.version", "testversion");
properties.setProperty("http-server.http.port", "7777");
properties.setProperty("discovery.uri", "http://presto-coordinator:" + coordinatorPort);
properties.setProperty("system-memory-gb", "2");
properties.setProperty("native.sidecar", "false");
properties.setProperty("remote-function-server.rest.url", "http://presto-coordinator:" + functionServerPort);
createPropertiesFile("testcontainers/" + nodeId + "/etc/config.properties", properties);
}

public static void createCoordinatorConfigProperties(int port)
throws IOException
{
Expand All @@ -93,6 +106,8 @@ public static void createCoordinatorConfigProperties(int port)
properties.setProperty("http-server.http.port", Integer.toString(port));
properties.setProperty("discovery-server.enabled", "true");
properties.setProperty("discovery.uri", "http://presto-coordinator:" + port);
properties.setProperty("list-built-in-functions-only", "false");
properties.setProperty("native-execution-enabled", "false");

// Get native worker system properties and add them to the coordinator properties
Map<String, String> nativeWorkerProperties = NativeQueryRunnerUtils.getNativeWorkerSystemProperties();
Expand All @@ -103,6 +118,52 @@ public static void createCoordinatorConfigProperties(int port)
createPropertiesFile("testcontainers/coordinator/etc/config.properties", properties);
}

public static void createFunctionNamespaceRemoteProperties()
throws IOException
{
Properties properties = new Properties();
properties.setProperty("function-namespace-manager.name", "rest");
properties.setProperty("supported-function-languages", "Java");
properties.setProperty("function-implementation-type", "REST");

String directoryPath = "testcontainers/function-namespace";
File directory = new File(directoryPath);
if (!directory.exists()) {
directory.mkdirs();
}

createPropertiesFile("testcontainers/coordinator/etc/function-namespace/remote.properties", properties);
}

public static void createFunctionNamespaceRemotePropertiesWithFunctionServer(int functionServerPort)
throws IOException
{
Properties properties = new Properties();
properties.setProperty("function-namespace-manager.name", "rest");
properties.setProperty("supported-function-languages", "Java");
properties.setProperty("function-implementation-type", "REST");
properties.setProperty("rest-based-function-manager.rest.url", "http://localhost:" + functionServerPort);

String directoryPath = "testcontainers/function-namespace";
File directory = new File(directoryPath);
if (!directory.exists()) {
directory.mkdirs();
}

createPropertiesFile("testcontainers/coordinator/etc/function-namespace/remote.properties", properties);
}

public static void createFunctionServerConfigProperties(int functionServerPort)
throws IOException
{
Properties properties = new Properties();
properties.setProperty("http-server.http.port", String.valueOf(functionServerPort));
properties.setProperty("regex-library", "RE2J");
properties.setProperty("parse-decimal-literals-as-double", "true");

createPropertiesFile("testcontainers/coordinator/etc/function-server/config.properties", properties);
}

public static void createCoordinatorJvmConfig()
throws IOException

Expand Down Expand Up @@ -161,6 +222,11 @@ public static void createCoordinatorEntryPointScript()
{
String scriptContent = "#!/bin/sh\n" +
"set -e\n" +
"java " +
// "-Dplugin.dir=/opt/presto-remote-server/function-server-plugin " +
// "-Dconfig=/opt/presto-remote-server/function-server-etc/config.properties " +
// "-jar /opt/presto-remote-server >> log1.txt 2>&1 & \n" +
"-Dconfig=/opt/function-server/etc/config.properties -jar /opt/presto-remote-server >> log1.txt 2>&1 & \n" +
"$PRESTO_HOME/bin/launcher run\n";
createScriptFile("testcontainers/coordinator/entrypoint.sh", scriptContent);
}
Expand Down Expand Up @@ -204,10 +270,6 @@ public static void createPropertiesFile(String filePath, Properties properties)
parentDir.mkdirs();
}

if (file.exists()) {
throw new IOException("File exists: " + filePath);
}

try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
for (String key : properties.stringPropertyNames()) {
writer.write(key + "=" + properties.getProperty(key) + "\n");
Expand All @@ -224,10 +286,6 @@ public static void createScriptFile(String filePath, String scriptContent)
parentDir.mkdirs();
}

if (file.exists()) {
throw new IOException("File exists: " + filePath);
}

try (OutputStream output = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(output, StandardCharsets.UTF_8)) {
writer.write(scriptContent);
Expand Down
Loading

0 comments on commit 26886d1

Please sign in to comment.