World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#554] improvement(CI-Hive): improve Hadoop access permission (#1194)
mchades9dddd0c26433
diff --git a/dev/docker/build-docker.sh b/dev/docker/build-docker.shindex 3ee6206f1a..c2d99ce612 100755--- a/dev/docker/build-docker.sh+++ b/dev/docker/build-docker.sh@@ -64,7 +64,7 @@ fiif [[ "${component_type}" == "hive" ]]; then. ${script_dir}/hive/hive-dependency.sh- build_args="--build-arg HADOOP_PACKAGE_NAME=${HADOOP_PACKAGE_NAME} --build-arg HIVE_PACKAGE_NAME=${HIVE_PACKAGE_NAME}"+ build_args="--build-arg HADOOP_PACKAGE_NAME=${HADOOP_PACKAGE_NAME} --build-arg HIVE_PACKAGE_NAME=${HIVE_PACKAGE_NAME} --build-arg JDBC_DIVER_PACKAGE_NAME=${JDBC_DIVER_PACKAGE_NAME}"elif [ "${component_type}" == "trino" ]; then. ${script_dir}/trino/trino-dependency.shelif [ "${component_type}" == "gravitino" ]; thendiff --git a/dev/docker/hive/Dockerfile b/dev/docker/hive/Dockerfileindex e1ddfbc3be..d2eded16d7 100644--- a/dev/docker/hive/Dockerfile+++ b/dev/docker/hive/Dockerfile@@ -8,6 +8,7 @@ LABEL maintainer="[email protected]"ARG HADOOP_PACKAGE_NAMEARG HIVE_PACKAGE_NAME+ARG JDBC_DIVER_PACKAGE_NAMEWORKDIR /@@ -129,10 +130,7 @@ RUN sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/################################################################################# add mysql jdbc driver-RUN wget https://downloads.mysql.com/archives/get/p/3/file/mysql-connector-java-8.0.15.tar.gz-RUN tar -xzf mysql-connector-java-8.0.15.tar.gz-RUN cp mysql-connector-java-8.0.15/mysql-connector-java-8.0.15.jar ${HIVE_HOME}/lib-RUN rm -rf mysql-connector-java-8.0.15 mysql-connector-java-8.0.15.tar.gz+RUN tar -xz -C ${HIVE_HOME}/lib --strip-components 1 -f /tmp/packages/${JDBC_DIVER_PACKAGE_NAME}################################################################################# add users and groupsdiff --git a/dev/docker/hive/hdfs-site.xml b/dev/docker/hive/hdfs-site.xmlindex 0fcae90b05..ae15b096f4 100644--- a/dev/docker/hive/hdfs-site.xml+++ b/dev/docker/hive/hdfs-site.xml@@ -13,4 +13,9 @@<name>dfs.datanode.address</name><value>0.0.0.0:50010</value></property>++ <property>+ <name>dfs.permissions.superusergroup</name>+ <value>hdfs</value>+ </property></configuration>diff --git a/dev/docker/hive/hive-dependency.sh b/dev/docker/hive/hive-dependency.shindex 7d1341d620..7397068642 100755--- a/dev/docker/hive/hive-dependency.sh+++ b/dev/docker/hive/hive-dependency.sh@@ -10,6 +10,7 @@ hive_dir="$(cd "${hive_dir}">/dev/null; pwd)"# Environment variables definitionHADOOP_VERSION="2.7.3"HIVE_VERSION="2.3.9"+MYSQL_JDBC_DRIVER_VERSION="8.0.15"HADOOP_PACKAGE_NAME="hadoop-${HADOOP_VERSION}.tar.gz" # Must export this variable for DockerfileHADOOP_DOWNLOAD_URL="http://archive.apache.org/dist/hadoop/core/hadoop-${HADOOP_VERSION}/${HADOOP_PACKAGE_NAME}"@@ -17,6 +18,9 @@ HADOOP_DOWNLOAD_URL="http://archive.apache.org/dist/hadoop/core/hadoop-${HADOOP_HIVE_PACKAGE_NAME="apache-hive-${HIVE_VERSION}-bin.tar.gz" # Must export this variable for DockerfileHIVE_DOWNLOAD_URL="https://archive.apache.org/dist/hive/hive-${HIVE_VERSION}/${HIVE_PACKAGE_NAME}"+JDBC_DIVER_PACKAGE_NAME="mysql-connector-java-${MYSQL_JDBC_DRIVER_VERSION}.tar.gz" # Must export this variable for Dockerfile+JDBC_DIVER_DOWNLOAD_URL="https://downloads.mysql.com/archives/get/p/3/file/${JDBC_DIVER_PACKAGE_NAME}"+# Prepare download packagesif [[ ! -d "${hive_dir}/packages" ]]; thenmkdir -p "${hive_dir}/packages"@@ -29,3 +33,7 @@ fiif [ ! -f "${hive_dir}/packages/${HIVE_PACKAGE_NAME}" ]; thencurl -s -o "${hive_dir}/packages/${HIVE_PACKAGE_NAME}" ${HIVE_DOWNLOAD_URL}fi++if [ ! -f "${hive_dir}/packages/${JDBC_DIVER_PACKAGE_NAME}" ]; then+ curl -L -s -o "${hive_dir}/packages/${JDBC_DIVER_PACKAGE_NAME}" ${JDBC_DIVER_DOWNLOAD_URL}+fidiff --git a/dev/docker/hive/start.sh b/dev/docker/hive/start.shindex b96874e581..a80e3a45e0 100644--- a/dev/docker/hive/start.sh+++ b/dev/docker/hive/start.sh@@ -12,16 +12,6 @@ ssh-keyscan 0.0.0.0 >> /root/.ssh/known_hosts# start hdfs${HADOOP_HOME}/sbin/start-dfs.sh-${HADOOP_HOME}/bin/hdfs dfs -mkdir /tmp-${HADOOP_HOME}/bin/hdfs dfs -chmod 1777 /tmp-${HADOOP_HOME}/bin/hdfs dfs -mkdir -p /user/hive/warehouse-${HADOOP_HOME}/bin/hdfs dfs -chown -R hive:hive /user/hive-${HADOOP_HOME}/bin/hdfs dfs -chmod -R 775 /user/hive-${HADOOP_HOME}/bin/hdfs dfs -mkdir -p /user/datastrato-${HADOOP_HOME}/bin/hdfs dfs -chown -R datastrato:hdfs /user/datastrato-${HADOOP_HOME}/bin/hdfs dfs -chmod 755 /user/datastrato-${HADOOP_HOME}/bin/hdfs dfs -chmod -R 777 /user/hive/tmp-# start mysql and create databases/users for hivechown -R mysql:mysql /var/lib/mysqlusermod -d /var/lib/mysql/ mysqldiff --git a/docs/docker-image-details.md b/docs/docker-image-details.mdindex c12bdd9b86..35487963f9 100644--- a/docs/docker-image-details.md+++ b/docs/docker-image-details.md@@ -68,8 +68,12 @@ You can use this kind of images to test the catalog of Apache Hive.Changelog+- gravitino-ci-hive:0.1.7+ - Download MySQL JDBC driver before building the Docker image+ - Set `hdfs` as HDFS superuser group+- gravitino-ci-hive:0.1.6- - No start YARN when container startup+ - No starting YARN when container startup- Removed expose ports:- `22` SSH- `8088` YARN Servicediff --git a/integration-test/build.gradle.kts b/integration-test/build.gradle.ktsindex e4284fad01..245e862ad2 100644--- a/integration-test/build.gradle.kts+++ b/integration-test/build.gradle.kts@@ -265,14 +265,13 @@ tasks.test {// Default use MiniGravitino to run integration testsenvironment("GRAVITINO_ROOT_DIR", rootDir.path)- // TODO: use hive user instead after we fix the permission issue #554- environment("HADOOP_USER_NAME", "root")+ environment("HADOOP_USER_NAME", "datastrato")environment("HADOOP_HOME", "/tmp")environment("PROJECT_VERSION", version)environment("TRINO_CONF_DIR", buildDir.path + "/trino-conf")// Gravitino CI Docker image- environment("GRAVITINO_CI_HIVE_DOCKER_IMAGE", "datastrato/gravitino-ci-hive:0.1.6")+ environment("GRAVITINO_CI_HIVE_DOCKER_IMAGE", "datastrato/gravitino-ci-hive:0.1.7")environment("GRAVITINO_CI_TRINO_DOCKER_IMAGE", "datastrato/gravitino-ci-trino:0.1.2")val testMode = project.properties["testMode"] as? String ?: "embedded"diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/hive/CatalogHiveIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/hive/CatalogHiveIT.javaindex e0041d4edb..62aad9d179 100644--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/hive/CatalogHiveIT.java+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/catalog/hive/CatalogHiveIT.java@@ -62,12 +62,17 @@ import com.datastrato.gravitino.rel.expressions.transforms.Transform;import com.datastrato.gravitino.rel.types.Types;import com.google.common.collect.ImmutableMap;import com.google.common.collect.Maps;+import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;import java.util.List;import java.util.Map;import java.util.stream.Collectors;+import org.apache.hadoop.conf.Configuration;+import org.apache.hadoop.fs.FileStatus;+import org.apache.hadoop.fs.FileSystem;+import org.apache.hadoop.fs.Path;import org.apache.hadoop.hive.conf.HiveConf;import org.apache.hadoop.hive.metastore.TableType;import org.apache.hadoop.hive.metastore.api.Database;@@ -106,6 +111,7 @@ public class CatalogHiveIT extends AbstractIT {private static GravitinoMetaLake metalake;private static Catalog catalog;private static SparkSession sparkSession;+ private static FileSystem hdfs;private static final String SELECT_ALL_TEMPLATE = "SELECT * FROM %s.%s";private static final String INSERT_WITHOUT_PARTITION_TEMPLATE = "INSERT INTO %s.%s VALUES (%s)";private static final String INSERT_WITH_PARTITION_TEMPLATE =@@ -155,13 +161,23 @@ public class CatalogHiveIT extends AbstractIT {.config("mapreduce.input.fileinputformat.input.dir.recursive", "true").enableHiveSupport().getOrCreate();++ Configuration conf = new Configuration();+ conf.set(+ "fs.defaultFS",+ String.format(+ "hdfs://%s:%d",+ containerSuite.getHiveContainer().getContainerIpAddress(),+ HiveContainer.HDFS_DEFAULTFS_PORT));+ hdfs = FileSystem.get(conf);+createMetalake();createCatalog();createSchema();}@AfterAll- public static void stop() {+ public static void stop() throws IOException {client.dropMetalake(NameIdentifier.of(metalakeName));if (hiveClientPool != null) {hiveClientPool.close();@@ -170,6 +186,10 @@ public class CatalogHiveIT extends AbstractIT {if (sparkSession != null) {sparkSession.close();}++ if (hdfs != null) {+ hdfs.close();+ }try {closer.close();} catch (Exception e) {@@ -286,6 +306,19 @@ public class CatalogHiveIT extends AbstractIT {}Assertions.assertEquals(count + 1, sparkSession.sql(String.format(SELECT_ALL_TEMPLATE, dbName, tableName)).count());+ // Assert HDFS owner+ Path tableDirectory = new Path(table.getSd().getLocation());+ FileStatus[] fileStatuses;+ try {+ fileStatuses = hdfs.listStatus(tableDirectory);+ } catch (IOException e) {+ LOG.warn("Failed to list status of table directory", e);+ throw new RuntimeException(e);+ }+ Assertions.assertTrue(fileStatuses.length > 0);+ for (FileStatus fileStatus : fileStatuses) {+ Assertions.assertEquals("datastrato", fileStatus.getOwner());+ }}private Map<String, String> createProperties() {diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/container/ContainerSuite.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/container/ContainerSuite.javaindex d69d146f56..7ee9d2a406 100644--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/container/ContainerSuite.java+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/container/ContainerSuite.java@@ -68,7 +68,9 @@ public class ContainerSuite implements Closeable {HiveContainer.builder().withHostName("gravitino-ci-hive").withEnvVars(- ImmutableMap.<String, String>builder().put("HADOOP_USER_NAME", "root").build())+ ImmutableMap.<String, String>builder()+ .put("HADOOP_USER_NAME", "datastrato")+ .build()).withNetwork(network);hiveContainer = closer.register(hiveBuilder.build());hiveContainer.start();