sijie closed pull request #2588: Preserve filename of the original function 
submission
URL: https://github.com/apache/incubator-pulsar/pull/2588
 
 
   

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-functions/proto/src/main/proto/Function.proto 
b/pulsar-functions/proto/src/main/proto/Function.proto
index 6e969ae077..a76cf8d5ed 100644
--- a/pulsar-functions/proto/src/main/proto/Function.proto
+++ b/pulsar-functions/proto/src/main/proto/Function.proto
@@ -116,6 +116,7 @@ message SinkSpec {
 
 message PackageLocationMetaData {
     string packagePath = 1;
+    string originalFileName = 2;
 }
 
 message FunctionMetaData {
diff --git 
a/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionDetailsUtils.java
 
b/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionDetailsUtils.java
index 5ecdd4f347..a9787ba9cb 100644
--- 
a/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionDetailsUtils.java
+++ 
b/pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionDetailsUtils.java
@@ -19,6 +19,8 @@
 
 package org.apache.pulsar.functions.utils;
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.pulsar.functions.proto.Function;
 import org.apache.pulsar.functions.proto.Function.FunctionDetails;
 
 public class FunctionDetailsUtils {
@@ -43,7 +45,11 @@ public static String extractFunctionNameFromFQN(String 
fullyQualifiedName) {
         return fullyQualifiedName.split("/")[2];
     }
 
-    public static String getDownloadFileName(FunctionDetails FunctionDetails) {
+    public static String getDownloadFileName(FunctionDetails FunctionDetails,
+                                             Function.PackageLocationMetaData 
packageLocation) {
+        if (!StringUtils.isEmpty(packageLocation.getOriginalFileName())) {
+            return packageLocation.getOriginalFileName();
+        }
         String[] hierarchy = FunctionDetails.getClassName().split("\\.");
         String fileName;
         if (hierarchy.length <= 0) {
diff --git 
a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionActioner.java
 
b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionActioner.java
index f5a7e969be..724d80c58e 100644
--- 
a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionActioner.java
+++ 
b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionActioner.java
@@ -156,7 +156,7 @@ public void startFunction(FunctionRuntimeInfo 
functionRuntimeInfo) throws Except
 
             pkgFile = new File(
                     pkgDir,
-                    new 
File(FunctionDetailsUtils.getDownloadFileName(functionMetaData.getFunctionDetails())).getName());
+                    new 
File(FunctionDetailsUtils.getDownloadFileName(functionMetaData.getFunctionDetails(),
 functionMetaData.getPackageLocation())).getName());
             downloadFile(pkgFile, isPkgUrlProvided, functionMetaData, 
instanceId);
         }
 
diff --git 
a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java
 
b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java
index df82c0d25c..8bb91946a1 100644
--- 
a/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java
+++ 
b/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java
@@ -170,6 +170,9 @@ public Response registerFunction(final String tenant, final 
String namespace, fi
         } else {
             packageLocationMetaDataBuilder.setPackagePath(isPkgUrlProvided ? 
functionPkgUrl
                     : createPackagePath(tenant, namespace, functionName, 
fileDetail.getFileName()));
+            if (!isPkgUrlProvided) {
+                
packageLocationMetaDataBuilder.setOriginalFileName(fileDetail.getFileName());
+            }
         }
 
         
functionMetaDataBuilder.setPackageLocation(packageLocationMetaDataBuilder);
@@ -234,6 +237,9 @@ public Response updateFunction(final String tenant, final 
String namespace, fina
         } else {
             packageLocationMetaDataBuilder.setPackagePath(isPkgUrlProvided ? 
functionPkgUrl
                     : createPackagePath(tenant, namespace, functionName, 
fileDetail.getFileName()));
+            if (!isPkgUrlProvided) {
+                
packageLocationMetaDataBuilder.setOriginalFileName(fileDetail.getFileName());
+            }
         }
 
         
functionMetaDataBuilder.setPackageLocation(packageLocationMetaDataBuilder);


 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to