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/03/15 03:34:49 UTC

[GitHub] merlimat closed pull request #1385: remove function package on function delete

merlimat closed pull request #1385: remove function package on function delete
URL: https://github.com/apache/incubator-pulsar/pull/1385
 
 
   

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/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 cc77e47ea..296e7d0f6 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
@@ -18,11 +18,14 @@
  */
 package org.apache.pulsar.functions.worker;
 
+import java.io.IOException;
 import java.nio.file.FileAlreadyExistsException;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+
 import lombok.*;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.distributedlog.api.namespace.Namespace;
 import org.apache.pulsar.functions.proto.Function;
@@ -112,13 +115,7 @@ private void startFunction(FunctionRuntimeInfo functionRuntimeInfo) throws Excep
                 functionMetaData.getFunctionConfig().getName(), instance.getInstanceId());
         File pkgDir = new File(
                 workerConfig.getDownloadDirectory(),
-                StringUtils.join(
-                        new String[]{
-                                functionMetaData.getFunctionConfig().getTenant(),
-                                functionMetaData.getFunctionConfig().getNamespace(),
-                                functionMetaData.getFunctionConfig().getName(),
-                        },
-                        File.separatorChar));
+                getDownloadPackagePath(functionMetaData));
         pkgDir.mkdirs();
 
         int instanceId = functionRuntimeInfo.getFunctionInstance().getInstanceId();
@@ -178,7 +175,7 @@ private void startFunction(FunctionRuntimeInfo functionRuntimeInfo) throws Excep
         runtimeSpawner.start();
     }
 
-    private boolean stopFunction(FunctionRuntimeInfo functionRuntimeInfo) {
+    private void stopFunction(FunctionRuntimeInfo functionRuntimeInfo) {
         Function.Instance instance = functionRuntimeInfo.getFunctionInstance();
         FunctionMetaData functionMetaData = instance.getFunctionMetaData();
         log.info("Stopping function {} - {}...",
@@ -186,8 +183,30 @@ private boolean stopFunction(FunctionRuntimeInfo functionRuntimeInfo) {
         if (functionRuntimeInfo.getRuntimeSpawner() != null) {
             functionRuntimeInfo.getRuntimeSpawner().close();
             functionRuntimeInfo.setRuntimeSpawner(null);
-            return true;
         }
-        return false;
+
+        // clean up function package
+        File pkgDir = new File(
+                workerConfig.getDownloadDirectory(),
+                getDownloadPackagePath(functionMetaData));
+
+        if (pkgDir.exists()) {
+            try {
+                FileUtils.deleteDirectory(pkgDir);
+            } catch (IOException e) {
+                log.warn("Failed to delete package for function: {}",
+                        FunctionConfigUtils.getFullyQualifiedName(functionMetaData.getFunctionConfig()), e);
+            }
+        }
+    }
+
+    private String getDownloadPackagePath(FunctionMetaData functionMetaData) {
+        return StringUtils.join(
+                new String[]{
+                        functionMetaData.getFunctionConfig().getTenant(),
+                        functionMetaData.getFunctionConfig().getNamespace(),
+                        functionMetaData.getFunctionConfig().getName(),
+                },
+                File.separatorChar);
     }
 }


 

----------------------------------------------------------------
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