forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-27770][sql-gateway] Introduce the script to start/stop/stop-al…
…l gateway
- Loading branch information
Showing
11 changed files
with
304 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>flink-end-to-end-tests</artifactId> | ||
<groupId>org.apache.flink</groupId> | ||
<version>1.16-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>flink-sql-gateway-test</artifactId> | ||
<name>Flink : E2E Tests : SQL Gateway</name> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-end-to-end-tests-common</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-sql-connector-hive-${hive.version}_${scala.binary.version}</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.hive</groupId> | ||
<artifactId>hive-jdbc</artifactId> | ||
<version>${hive.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-test-utils-junit</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>copy</id> | ||
<phase>pre-integration-test</phase> | ||
<goals> | ||
<goal>copy</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<artifactItems> | ||
<artifactItem> | ||
<groupId>org.apache.flink</groupId> | ||
<artifactId>flink-sql-connector-hive-2.3.9_${scala.binary.version}</artifactId> | ||
<version>${project.version}</version> | ||
<destFileName>flink-sql-connector-hive-2.3.9_${scala.binary.version}-${project.version}.jar</destFileName> | ||
<type>jar</type> | ||
<outputDirectory>${project.build.directory}/dependencies</outputDirectory> | ||
</artifactItem> | ||
</artifactItems> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
71 changes: 71 additions & 0 deletions
71
...flink-sql-gateway-test/src/test/java/org/apache/flink/table/gateway/SQLGatewayITCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.table.gateway; | ||
|
||
import org.apache.flink.tests.util.TestUtils; | ||
import org.apache.flink.tests.util.flink.ClusterController; | ||
import org.apache.flink.tests.util.flink.FlinkResource; | ||
import org.apache.flink.tests.util.flink.FlinkResourceSetup; | ||
import org.apache.flink.tests.util.flink.JarLocation; | ||
import org.apache.flink.tests.util.flink.LocalStandaloneFlinkResource; | ||
import org.apache.flink.tests.util.flink.LocalStandaloneFlinkResourceFactory; | ||
import org.apache.flink.util.TestLogger; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import java.nio.file.Path; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class SQLGatewayITCase extends TestLogger { | ||
|
||
private static String JDBC_URL = "jdbc:hive2://localhost:8084/default;auth=noSasl"; | ||
private static String DRIVER_NAME = "org.apache.hive.jdbc.HiveDriver"; | ||
|
||
private static final Path HIVE_SQL_CONNECOTR_JAR = | ||
TestUtils.getResource(".*dependencies/flink-sql-connector-hive-.*.jar"); | ||
|
||
@Rule | ||
public final FlinkResource flink = | ||
new LocalStandaloneFlinkResourceFactory() | ||
.create( | ||
FlinkResourceSetup.builder() | ||
.addJar(HIVE_SQL_CONNECOTR_JAR, JarLocation.LIB) | ||
.build()); | ||
|
||
@Test | ||
public void testGateway() throws Exception { | ||
try (ClusterController clusterController = flink.startCluster(1)) { | ||
((LocalStandaloneFlinkResource) flink) | ||
.startSQLGateway("-Dsql-gateway.endpoint.type=hiveserver2"); | ||
Thread.sleep(2000); | ||
Class.forName(DRIVER_NAME); | ||
try { | ||
DriverManager.getConnection(JDBC_URL); | ||
} catch (SQLException e) { | ||
assertThat(e.getMessage()) | ||
.contains( | ||
"Embedded metastore is not allowed. Make sure you have set a valid value for hive.metastore.uris"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# Start/stop a Flink SQL Gateway. | ||
|
||
function usage() { | ||
echo "Usage: bin/sql-gateway.sh command" | ||
echo " commands:" | ||
echo " start - Run a SQL Gateway as a daemon" | ||
echo " start-foreground - Run a SQL Gateway as a console application" | ||
echo " stop - Stop the SQL Gateway daemon" | ||
echo " stop-all - Stop all the SQL Gateway daemons" | ||
echo " -h | --help - Show this help message" | ||
} | ||
|
||
if [[ "$*" = *--help ]] || [[ "$*" = *-h ]]; then | ||
usage | ||
exit 0 | ||
fi | ||
|
||
STARTSTOP=$1 | ||
|
||
if [ -z "$STARTSTOP" ]; then | ||
STARTSTOP="start" | ||
fi | ||
|
||
if [[ $STARTSTOP != "start" ]] && [[ $STARTSTOP != "start-foreground" ]] && [[ $STARTSTOP != "stop" ]] && [[ $STARTSTOP != "stop-all" ]]; then | ||
usage | ||
exit 1 | ||
fi | ||
|
||
################################################################################ | ||
# Adopted from "flink" bash script | ||
################################################################################ | ||
|
||
target="$0" | ||
# For the case, the executable has been directly symlinked, figure out | ||
# the correct bin path by following its symlink up to an upper bound. | ||
# Note: we can't use the readlink utility here if we want to be POSIX | ||
# compatible. | ||
iteration=0 | ||
while [ -L "$target" ]; do | ||
if [ "$iteration" -gt 100 ]; then | ||
echo "Cannot resolve path: You have a cyclic symlink in $target." | ||
break | ||
fi | ||
ls=`ls -ld -- "$target"` | ||
target=`expr "$ls" : '.* -> \(.*\)$'` | ||
iteration=$((iteration + 1)) | ||
done | ||
|
||
# Convert relative path to absolute path | ||
bin=`dirname "$target"` | ||
|
||
# get flink config | ||
. "$bin"/config.sh | ||
|
||
if [ "$FLINK_IDENT_STRING" = "" ]; then | ||
FLINK_IDENT_STRING="$USER" | ||
fi | ||
|
||
ENTRYPOINT=sqlgateway | ||
|
||
if [[ $STARTSTOP == "start-foreground" ]]; then | ||
exec "${FLINK_BIN_DIR}"/flink-console.sh $ENTRYPOINT "${@:2}" | ||
else | ||
"${FLINK_BIN_DIR}"/flink-daemon.sh $STARTSTOP $ENTRYPOINT "${@:2}" | ||
fi |