You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by pe...@apache.org on 2023/03/14 13:19:22 UTC

[linkis] branch dev-1.3.2 updated: [1.3.2] add ecm shell clear (#4103)

This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev-1.3.2
in repository https://gitbox.apache.org/repos/asf/linkis.git


The following commit(s) were added to refs/heads/dev-1.3.2 by this push:
     new e2b44ebb7 [1.3.2] add ecm shell clear (#4103)
e2b44ebb7 is described below

commit e2b44ebb7600c494a2d214ae72d310d4333894fa
Author: huangKai-2323 <62...@users.noreply.github.com>
AuthorDate: Tue Mar 14 21:19:15 2023 +0800

    [1.3.2] add ecm shell clear (#4103)
---
 .../apache/linkis/ecm/scheduled/EcmClearTask.java  | 65 ++++++++++++++++++++++
 linkis-dist/bin/install.sh                         |  4 ++
 linkis-dist/package/admin/linkis-ec-clear.sh       | 40 +++++++++++++
 3 files changed, 109 insertions(+)

diff --git a/linkis-computation-governance/linkis-engineconn-manager/linkis-engineconn-manager-server/src/main/java/org/apache/linkis/ecm/scheduled/EcmClearTask.java b/linkis-computation-governance/linkis-engineconn-manager/linkis-engineconn-manager-server/src/main/java/org/apache/linkis/ecm/scheduled/EcmClearTask.java
new file mode 100644
index 000000000..111ad896e
--- /dev/null
+++ b/linkis-computation-governance/linkis-engineconn-manager/linkis-engineconn-manager-server/src/main/java/org/apache/linkis/ecm/scheduled/EcmClearTask.java
@@ -0,0 +1,65 @@
+/*
+ * 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.linkis.ecm.scheduled;
+
+import org.apache.linkis.common.conf.Configuration;
+import org.apache.linkis.common.utils.Utils;
+
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component
+public class EcmClearTask {
+
+  private Logger logger = LoggerFactory.getLogger(EcmClearTask.class);
+
+  public static final String shellPath = Configuration.getLinkisHome() + "/admin/";
+
+  private class CleanExpiredThread implements Runnable {
+    @Override
+    public void run() {
+      logger.info("Start to linkis-ec-clear shell");
+      List<String> cmdlist = new ArrayList<>();
+      cmdlist.add("sh");
+      cmdlist.add(shellPath + "linkis-ec-clear.sh");
+      try {
+        Utils.exec(cmdlist.toArray(new String[0]), 3000L);
+      } catch (Exception e) {
+        logger.warn("Shell linkis-ec-clear.sh execution failed, msg:" + e.getMessage());
+      }
+      logger.info("End to linkis-ec-clear shell");
+    }
+  }
+
+  @PostConstruct
+  public void init() {
+    logger.info("Schedule Task is init");
+    CleanExpiredThread cleanExpiredThread = new CleanExpiredThread();
+    // Once a day
+    Utils.defaultScheduler()
+        .scheduleAtFixedRate(cleanExpiredThread, 10, 24 * 60 * 60, TimeUnit.SECONDS);
+  }
+}
diff --git a/linkis-dist/bin/install.sh b/linkis-dist/bin/install.sh
index 038d27846..934d1d0a7 100644
--- a/linkis-dist/bin/install.sh
+++ b/linkis-dist/bin/install.sh
@@ -395,6 +395,10 @@ if [ ! -d $ENGINECONN_ROOT_PATH ] ;then
     mkdir -p $ENGINECONN_ROOT_PATH
 fi
 sudo chmod -R 777 $ENGINECONN_ROOT_PATH
+sed -i "/.*ENGINECONN_ROOT_PATH=*/c\ENGINECONN_ROOT_PATH=$ENGINECONN_ROOT_PATH" $LINKIS_HOME/admin/linkis-ec-clear.sh
+
+
+
 
 if [ "$ENGINECONNMANAGER_PORT" != "" ]
 then
diff --git a/linkis-dist/package/admin/linkis-ec-clear.sh b/linkis-dist/package/admin/linkis-ec-clear.sh
new file mode 100644
index 000000000..684c23338
--- /dev/null
+++ b/linkis-dist/package/admin/linkis-ec-clear.sh
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+#
+# 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.
+#
+
+#The cleaning date must be passed in. And ecm will print the actual effective date log.
+
+end_date=`date -d '-90 days'`
+end_date_t=`date -d '-90 days' +%s`
+echo "Clean up data before this date:$end_date"
+#Directory read ecm engine cache variables
+ENGINECONN_ROOT_PATH=
+for userdir in `sudo ls $ENGINECONN_ROOT_PATH -F | grep '/$'`
+do
+#EngineConPublicckDir cannot be cleaned up. Clean it up in the ecm stop script
+  if [ "$userdir" != "engineConnPublickDir/" ];then
+    for ecdir in `sudo ls $ENGINECONN_ROOT_PATH$userdir -F | grep '/$'`
+    do
+       ecdirpath=$ENGINECONN_ROOT_PATH$userdir$ecdir
+        #Get the last modification time of the folder, and get the time of the latest modified file under the folder
+       modify_time=`sudo find $ecdirpath  -printf "%TY-%Tm-%Td\n" | sort -nr | head -n 1`
+       modify_time_t=`date -d "$modify_time" +%s`
+       if [ $modify_time_t -lt $end_date_t ]; then
+         echo "Delete directory:$ecdirpath Last update time$modify_time"
+         sudo rm -rf $ecdirpath
+       fi
+    done
+  fi
+done


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org