You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/09/05 17:37:55 UTC

[GitHub] rdhabalia closed pull request #2519: Delete temp file after submitting function

rdhabalia closed pull request #2519: Delete temp file after submitting function
URL: https://github.com/apache/incubator-pulsar/pull/2519
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java
index 7f2f52122e..5322576b14 100644
--- a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java
+++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdFunctions.java
@@ -501,8 +501,7 @@ protected void validateFunctionConfigs(FunctionConfig functionConfig) {
                     // download jar file if url is http or file is downloadable
                     File tempPkgFile = null;
                     try {
-                        tempPkgFile = File.createTempFile(functionConfig.getName(), "function");
-                        downloadFromHttpUrl(functionConfig.getJar(), new FileOutputStream(tempPkgFile));
+                        tempPkgFile = downloadFromHttpUrl(functionConfig.getJar(), functionConfig.getName());
                         jarFilePath = tempPkgFile.getAbsolutePath();
                     } catch (Exception e) {
                         if (tempPkgFile != null) {
diff --git a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSinks.java b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSinks.java
index 3e49600c10..38a55bf47c 100644
--- a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSinks.java
+++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSinks.java
@@ -431,8 +431,7 @@ protected void validateSinkConfigs(SinkConfig sinkConfig) {
                 if(sinkConfig.getArchive().startsWith(Utils.HTTP)) {
                     File tempPkgFile = null;
                     try {
-                        tempPkgFile = File.createTempFile(sinkConfig.getName(), "sink");
-                        downloadFromHttpUrl(sinkConfig.getArchive(), new FileOutputStream(tempPkgFile));
+                        tempPkgFile = downloadFromHttpUrl(sinkConfig.getArchive(), sinkConfig.getName());
                         archivePath = tempPkgFile.getAbsolutePath();
                     } catch(Exception e) {
                         if(tempPkgFile!=null ) {
diff --git a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSources.java b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSources.java
index db00b9fd97..fb32a6a02e 100644
--- a/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSources.java
+++ b/pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdSources.java
@@ -388,8 +388,7 @@ protected void validateSourceConfigs(SourceConfig sourceConfig) {
                 if(sourceConfig.getArchive().startsWith(Utils.HTTP)) {
                     File tempPkgFile = null;
                     try {
-                        tempPkgFile = File.createTempFile(sourceConfig.getName(), "source");
-                        downloadFromHttpUrl(sourceConfig.getArchive(), new FileOutputStream(tempPkgFile));
+                        tempPkgFile = downloadFromHttpUrl(sourceConfig.getArchive(), sourceConfig.getName());
                         archivePath = tempPkgFile.getAbsolutePath();
                     } catch(Exception e) {
                         if(tempPkgFile!=null ) {
diff --git a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/Utils.java b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/Utils.java
index ec99b001e0..6487dcfed2 100644
--- a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/Utils.java
+++ b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/Utils.java
@@ -51,6 +51,7 @@
 import org.apache.zookeeper.KeeperException.Code;
 import org.apache.pulsar.functions.proto.Function;
 import static org.apache.pulsar.functions.utils.Utils.FILE;
+import static org.apache.pulsar.functions.worker.Utils.downloadFromHttpUrl;
 
 @Slf4j
 public final class Utils {
@@ -159,7 +160,14 @@ public static void downloadFromHttpUrl(String destPkgUrl, FileOutputStream outpu
         ReadableByteChannel rbc = Channels.newChannel(website.openStream());
         outputStream.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
     }
-    
+
+    public static File downloadFromHttpUrl(String destPkgUrl, String fileName) throws IOException {
+        File tempPkgFile = File.createTempFile(fileName, "function");
+        tempPkgFile.deleteOnExit();
+        downloadFromHttpUrl(destPkgUrl, new FileOutputStream(tempPkgFile));
+        return tempPkgFile;
+    }
+
     public static void downloadFromBookkeeper(Namespace namespace,
                                                  OutputStream outputStream,
                                                  String packagePath) throws IOException {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services