pan3793 commented on code in PR #4746:
URL: https://github.com/apache/zeppelin/pull/4746#discussion_r1560350070


##########
zeppelin-test/src/main/java/org/apache/zeppelin/test/DownloadUtils.java:
##########
@@ -0,0 +1,537 @@
+/*
+ * 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.zeppelin.test;
+
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import me.tongfei.progressbar.DelegatingProgressBarConsumer;
+import me.tongfei.progressbar.ProgressBar;
+import me.tongfei.progressbar.ProgressBarBuilder;
+import me.tongfei.progressbar.ProgressBarStyle;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.Optional;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+/**
+ * Utility class for downloading spark/flink/livy. This is used for 
spark/flink integration test.
+ */
+public class DownloadUtils {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(DownloadUtils.class);
+
+  private static final String MIRROR_URL = 
"https://www.apache.org/dyn/closer.lua?preferred=true";;
+  private static final String ARCHIVE_URL = "https://archive.apache.org/dist/";;
+
+  private static String downloadFolder = System.getProperty("user.home") + 
"/.cache";
+  public static final String DEFAULT_SPARK_VERSION = "3.4.2";
+  public static final String DEFAULT_SPARK_HADOOP_VERSION = "3";
+
+  private DownloadUtils() {
+    throw new IllegalStateException("Utility class");
+  }
+
+  static {
+    try {
+      FileUtils.forceMkdir(new File(downloadFolder));
+    } catch (IOException e) {
+      throw new RuntimeException("Fail to create download folder: " + 
downloadFolder, e);
+    }
+  }
+
+  /**
+   * Download Spark with default versions
+   *
+   * @return home of Spark installation
+   */
+  public static String downloadSpark() {
+    return downloadSpark(DEFAULT_SPARK_VERSION, DEFAULT_SPARK_HADOOP_VERSION);
+  }
+
+  /**
+   * Download of a Spark distribution
+   *
+   * @param sparkVersion
+   * @param hadoopVersion
+   * @return home of Spark installation
+   */
+  public static String downloadSpark(String sparkVersion, String 
hadoopVersion) {
+    File sparkFolder = new File(downloadFolder, "spark");
+    File targetSparkHomeFolder =
+        new File(sparkFolder, "spark-" + sparkVersion + "-bin-hadoop" + 
hadoopVersion);
+    return downloadSpark(sparkVersion, hadoopVersion, targetSparkHomeFolder);
+  }
+
+  /**
+   * Download of a Spark distribution
+   *
+   * @param sparkVersion
+   * @param hadoopVersion
+   * @param targetSparkHomeFolder - where should the spark archive be extracted
+   * @return home of Spark installation
+   */
+  public static String downloadSpark(String sparkVersion, String hadoopVersion,
+      File targetSparkHomeFolder) {
+    File sparkFolder = new File(downloadFolder, "spark");
+    sparkFolder.mkdir();
+    if (targetSparkHomeFolder.exists()) {
+      LOGGER.info("Skip to download Spark {}-{} as it is already downloaded.", 
sparkVersion,
+          hadoopVersion);
+      return targetSparkHomeFolder.getAbsolutePath();
+    }
+    File sparkTarGZ =
+        new File(sparkFolder, "spark-" + sparkVersion + "-bin-hadoop" + 
hadoopVersion + ".tgz");
+    try {
+      URL mirrorURL = new URL(
+          IOUtils.toString(new URL(MIRROR_URL), StandardCharsets.UTF_8) + 
generateDownloadURL(
+              "spark", sparkVersion, "-bin-hadoop" + hadoopVersion + ".tgz", 
"spark"));
+      URL archiveURL = new URL(ARCHIVE_URL + generateDownloadURL(
+              "spark", sparkVersion, "-bin-hadoop" + hadoopVersion + ".tgz", 
"spark"));
+      LOGGER.info("Download Spark {}-{}", sparkVersion, hadoopVersion);
+      download(new DownloadRequest(mirrorURL, archiveURL), sparkTarGZ);
+      ProgressBarBuilder pbb = new ProgressBarBuilder()
+          .setTaskName("Unarchiv")
+          .setUnit("MiB", 1048576) // setting the progress bar to use MiB as 
the unit
+          .setStyle(ProgressBarStyle.ASCII)
+          .setUpdateIntervalMillis(1000)

Review Comment:
   we may want to use a large interval in CI console to avoid too many logs. 
suggest making it configurable via env var



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to