Skip to content

Commit f2267cb

Browse files
committed
Add Function Server executable and integrate docker.
1 parent 7dfc5a3 commit f2267cb

File tree

7 files changed

+101
-6
lines changed

7 files changed

+101
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ presto-native-execution/deps-install
6666
# Compiled executables used for docker build
6767
/docker/presto-cli-*-executable.jar
6868
/docker/presto-server-*.tar.gz
69+
/docker/presto-remote-function-server-executable.jar

docker/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ ENV PRESTO_HOME="/opt/presto-server"
99

1010
COPY $PRESTO_PKG .
1111
COPY $PRESTO_CLI_JAR /opt/presto-cli
12+
COPY $PRESTO_REMOTE_SERVER_JAR /opt/presto-remote-server
13+
1214

1315
RUN dnf install -y java-11-openjdk less procps python3 \
1416
&& ln -s $(which python3) /usr/bin/python \
@@ -19,6 +21,8 @@ RUN dnf install -y java-11-openjdk less procps python3 \
1921
&& rm -rf ./presto-server-$PRESTO_VERSION \
2022
&& chmod +x /opt/presto-cli \
2123
&& ln -s /opt/presto-cli /usr/local/bin/ \
24+
&& chmod +x /opt/presto-remote-server \
25+
2226
# clean cache jobs
2327
&& mv /etc/yum/protected.d/systemd.conf /etc/yum/protected.d/systemd.conf.bak \
2428
&& dnf clean all \

presto-main/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,26 @@
563563
</ignorePackages>
564564
</configuration>
565565
</plugin>
566+
<plugin>
567+
<groupId>org.apache.maven.plugins</groupId>
568+
<artifactId>maven-shade-plugin</artifactId>
569+
<executions>
570+
<execution>
571+
<phase>package</phase>
572+
<goals>
573+
<goal>shade</goal>
574+
</goals>
575+
<configuration>
576+
<finalName>presto-remote-function-server-executable</finalName>
577+
<transformers>
578+
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
579+
<mainClass>com.facebook.presto.server.FunctionServer</mainClass>
580+
</transformer>
581+
</transformers>
582+
</configuration>
583+
</execution>
584+
</executions>
585+
</plugin>
566586
<plugin>
567587
<groupId>org.apache.maven.plugins</groupId>
568588
<artifactId>maven-dependency-plugin</artifactId>

presto-main/src/main/java/com/facebook/presto/server/FunctionServer.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import com.google.inject.Injector;
2323
import com.google.inject.Module;
2424

25+
import java.util.HashMap;
2526
import java.util.List;
27+
import java.util.Map;
2628

2729
import static com.facebook.presto.server.PrestoSystemRequirements.verifyJvmRequirements;
2830
import static com.facebook.presto.server.PrestoSystemRequirements.verifySystemTimeIsReasonable;
@@ -47,21 +49,26 @@ public void run()
4749
verifyJvmRequirements();
4850
verifySystemTimeIsReasonable();
4951

50-
Logger log = Logger.get(FunctionServer.class);
52+
Map<String, String> configMap = new HashMap<>();
53+
configMap.put("http-server.http.enabled", "true");
54+
configMap.put("http-server.http.port", "8085");
5155

5256
List<Module> modules = ImmutableList.of(
5357
new FunctionServerModule(),
5458
new HttpServerModule(),
5559
new JaxrsModule());
5660

5761
try {
58-
Bootstrap app = new Bootstrap(modules);
62+
Bootstrap app = new Bootstrap(modules)
63+
.setRequiredConfigurationProperties(configMap); // Set the configuration map
5964
Injector injector = app.initialize();
6065

6166
HttpServerInfo serverInfo = injector.getInstance(HttpServerInfo.class);
67+
String httpUrl = serverInfo.getHttpUri().toString(); // This will give you the HTTP URL
68+
System.out.println(httpUrl);
6269
log.info("======== REMOTE FUNCTION SERVER STARTED at: " + serverInfo.getHttpUri() + " =========");
6370

64-
Thread.currentThread().join();
71+
Thread.currentThread().join(); // Keep the server running
6572
}
6673
catch (Throwable e) {
6774
log.error(e);

presto-native-execution/src/test/java/com/facebook/presto/nativeworker/ContainerQueryRunner.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.io.IOException;
3939
import java.sql.Connection;
4040
import java.sql.DriverManager;
41+
import java.sql.ResultSet;
4142
import java.sql.SQLException;
4243
import java.sql.Statement;
4344
import java.time.Duration;
@@ -58,7 +59,7 @@ public class ContainerQueryRunner
5859
private static final String PRESTO_COORDINATOR_IMAGE = System.getProperty("coordinatorImage", "presto-coordinator:latest");
5960
private static final String PRESTO_WORKER_IMAGE = System.getProperty("workerImage", "presto-worker:latest");
6061
private static final String CONTAINER_TIMEOUT = System.getProperty("containerTimeout", "120");
61-
private static final String CLUSTER_SHUTDOWN_TIMEOUT = System.getProperty("clusterShutDownTimeout", "10");
62+
private static final String CLUSTER_SHUTDOWN_TIMEOUT = System.getProperty("clusterShutDownTimeout", "10000");
6263
private static final String BASE_DIR = System.getProperty("user.dir");
6364
private static final int DEFAULT_COORDINATOR_PORT = 8080;
6465
private static final String TPCH_CATALOG = "tpch";
@@ -110,6 +111,7 @@ public ContainerQueryRunner(int coordinatorPort, String catalog, String schema,
110111
try {
111112
Connection connection = DriverManager.getConnection(url, "test", null);
112113
statement = connection.createStatement();
114+
statement.execute("set session remote_functions_enabled=true");
113115
}
114116
catch (Exception e) {
115117
e.printStackTrace();
@@ -131,6 +133,7 @@ private GenericContainer<?> createCoordinator()
131133
ContainerQueryRunnerUtils.createCoordinatorLogProperties();
132134
ContainerQueryRunnerUtils.createCoordinatorNodeProperties();
133135
ContainerQueryRunnerUtils.createCoordinatorEntryPointScript();
136+
ContainerQueryRunnerUtils.createFunctionNamespaceRemoteProperties();
134137

135138
return new GenericContainer<>(PRESTO_COORDINATOR_IMAGE)
136139
.withExposedPorts(coordinatorPort)
@@ -297,9 +300,9 @@ public Session getDefaultSession()
297300
public MaterializedResult execute(Session session, String sql)
298301
{
299302
try {
303+
ResultSet resultSet = statement.executeQuery(sql);
300304
return ContainerQueryRunnerUtils
301-
.toMaterializedResult(
302-
statement.executeQuery(sql));
305+
.toMaterializedResult(resultSet);
303306
}
304307
catch (SQLException e) {
305308
e.printStackTrace();

presto-native-execution/src/test/java/com/facebook/presto/nativeworker/ContainerQueryRunnerUtils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public static void createCoordinatorConfigProperties(int port)
8787
properties.setProperty("http-server.http.port", Integer.toString(port));
8888
properties.setProperty("discovery-server.enabled", "true");
8989
properties.setProperty("discovery.uri", "http://presto-coordinator:" + port);
90+
properties.setProperty("list-built-in-functions-only", "false");
91+
properties.setProperty("native-execution-enabled", "false");
9092

9193
// Get native worker system properties and add them to the coordinator properties
9294
Map<String, String> nativeWorkerProperties = NativeQueryRunnerUtils.getNativeWorkerSystemProperties();
@@ -97,6 +99,24 @@ public static void createCoordinatorConfigProperties(int port)
9799
createPropertiesFile("testcontainers/coordinator/etc/config.properties", properties);
98100
}
99101

102+
public static void createFunctionNamespaceRemoteProperties()
103+
throws IOException
104+
{
105+
Properties properties = new Properties();
106+
properties.setProperty("function-namespace-manager.name", "rest");
107+
properties.setProperty("supported-function-languages", "Java");
108+
properties.setProperty("function-implementation-type", "REST");
109+
properties.setProperty("rest-based-function-manager.rest.url", "http://localhost:8085");
110+
111+
String directoryPath = "testcontainers/function-namespace";
112+
File directory = new File(directoryPath);
113+
if (!directory.exists()) {
114+
directory.mkdirs();
115+
}
116+
117+
createPropertiesFile("testcontainers/coordinator/etc/function-namespace/remote.properties", properties);
118+
}
119+
100120
public static void createCoordinatorJvmConfig()
101121
throws IOException
102122

@@ -155,6 +175,7 @@ public static void createCoordinatorEntryPointScript()
155175
{
156176
String scriptContent = "#!/bin/sh\n" +
157177
"set -e\n" +
178+
"java -jar /opt/presto-remote-server >> log1.txt 2>&1 &\n" +
158179
"$PRESTO_HOME/bin/launcher run\n";
159180
createScriptFile("testcontainers/coordinator/entrypoint.sh", scriptContent);
160181
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.nativeworker;
15+
16+
import com.facebook.presto.tests.AbstractTestQueryFramework;
17+
import org.testng.annotations.Test;
18+
19+
import static org.testng.Assert.assertEquals;
20+
21+
public class TestPrestoContainerRemoteFunction
22+
extends AbstractTestQueryFramework
23+
{
24+
private ContainerQueryRunner queryRunner;
25+
26+
@Override
27+
protected ContainerQueryRunner createQueryRunner()
28+
throws Exception
29+
{
30+
queryRunner = new ContainerQueryRunner();
31+
return queryRunner;
32+
}
33+
34+
@Test
35+
public void testPresenceAndBasicFunctionality()
36+
{
37+
assertEquals(computeActual("select remote.default.abs(-10)").getMaterializedRows().get(0).getField(0).toString(), "10");
38+
}
39+
}

0 commit comments

Comments
 (0)