You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampark.apache.org by be...@apache.org on 2023/05/01 03:10:17 UTC

[incubator-streampark] branch release-2.0.1 updated: [Improve] start script improvement (#2713)

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

benjobs pushed a commit to branch release-2.0.1
in repository https://gitbox.apache.org/repos/asf/incubator-streampark.git


The following commit(s) were added to refs/heads/release-2.0.1 by this push:
     new c0d9b944d [Improve] start script improvement (#2713)
c0d9b944d is described below

commit c0d9b944d8da6bf3a2945fc2ea8831d2aea31340
Author: benjobs <be...@apache.org>
AuthorDate: Mon May 1 11:10:11 2023 +0800

    [Improve] start script improvement (#2713)
    
    * [Improve] remove user/types api in UserController (#2709)
    * [Improve] Support dependency-check-maven plugin (#2667)
    * [Improve] start-script improvement
---
 deploy/docker/.env                                 |   2 +-
 pom.xml                                            |  27 +++
 .../src/main/assembly/bin/streampark.sh            | 253 +++++++++------------
 .../console/system/controller/UserController.java  |   8 -
 .../src/api/system/user.ts                         |  12 -
 .../src/views/system/user/user.data.ts             |  15 +-
 6 files changed, 142 insertions(+), 175 deletions(-)

diff --git a/deploy/docker/.env b/deploy/docker/.env
index fe9dec2d7..800c55d9c 100644
--- a/deploy/docker/.env
+++ b/deploy/docker/.env
@@ -28,6 +28,6 @@ SPRING_PROFILES_ACTIVE=h2 #mysql, pgsql
 FLINK=flink1.14.5
 FLINK_IMAGE=flink:1.14.5-scala_2.12
 
-RUN_COMMAND='/bin/sh -c "wget -P lib https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/8.0.31/mysql-connector-j-8.0.31.jar && bash bin/streampark.sh startDocker "'
+RUN_COMMAND='/bin/sh -c "wget -P lib https://repo1.maven.org/maven2/com/mysql/mysql-connector-j/8.0.31/mysql-connector-j-8.0.31.jar && bash bin/streampark.sh start_docker "'
 
 JOB_MANAGER_RPC_ADDRESS=flink-jobmanager
diff --git a/pom.xml b/pom.xml
index a86101412..3a0f3e3c3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -132,6 +132,7 @@
         <maven-spotless-plugin.version>2.27.2</maven-spotless-plugin.version>
         <spotless.scalafmt.version>3.4.3</spotless.scalafmt.version>
         <maven-checkstyle-plugin.version>3.2.0</maven-checkstyle-plugin.version>
+        <owasp-dependency-check-maven.version>8.2.1</owasp-dependency-check-maven.version>
         <build-helper-maven-plugin.version>3.3.0</build-helper-maven-plugin.version>
         <streampark.shaded.package>org.apache.streampark.shaded</streampark.shaded.package>
         <flink.table.uber.artifact.id>flink-table-uber_${scala.binary.version}</flink.table.uber.artifact.id>
@@ -145,6 +146,7 @@
         <MaxPermGen>512m</MaxPermGen>
         <CodeCacheSize>512m</CodeCacheSize>
         <MaxMetaspace>512m</MaxMetaspace>
+        <skipDependencyCheck>true</skipDependencyCheck>
     </properties>
 
     <dependencyManagement>
@@ -718,6 +720,26 @@
                     <artifactId>maven-deploy-plugin</artifactId>
                     <version>${maven-deploy-plugin.version}</version>
                 </plugin>
+
+                <plugin>
+                    <!-- run via "mvn -Pscala-2.12 -DskipDependencyCheck=false org.owasp:dependency-check-maven:aggregate" -->
+                    <groupId>org.owasp</groupId>
+                    <artifactId>dependency-check-maven</artifactId>
+                    <version>${owasp-dependency-check-maven.version}</version>
+                    <configuration>
+                        <skip>${skipDependencyCheck}</skip>
+                        <format>ALL</format>
+                        <skipProvidedScope>true</skipProvidedScope>
+                        <skipSystemScope>true</skipSystemScope>
+                    </configuration>
+                    <executions>
+                        <execution>
+                            <goals>
+                                <goal>aggregate</goal>
+                            </goals>
+                        </execution>
+                    </executions>
+                </plugin>
             </plugins>
         </pluginManagement>
 
@@ -746,6 +768,11 @@
                 <groupId>com.diffplug.spotless</groupId>
                 <artifactId>spotless-maven-plugin</artifactId>
             </plugin>
+
+            <plugin>
+                <groupId>org.owasp</groupId>
+                <artifactId>dependency-check-maven</artifactId>
+            </plugin>
         </plugins>
 
     </build>
diff --git a/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh b/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh
index 02ae8a2ba..e44aebb08 100755
--- a/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh
+++ b/streampark-console/streampark-console-service/src/main/assembly/bin/streampark.sh
@@ -210,7 +210,7 @@ fi
 
 # Add on extra jar files to CLASSPATH
 # shellcheck disable=SC2236
-if [[ ! -z "$CLASSPATH" ]] ; then
+if [ ! -z "$CLASSPATH" ]; then
   CLASSPATH="$CLASSPATH":
 fi
 CLASSPATH="$CLASSPATH"
@@ -259,6 +259,8 @@ DEFAULT_OPTS="""
   -Xloggc:${APP_HOME}/logs/gc.log
   """
 
+DEBUG_OPTS=""
+
 # ----- Execute The Requested Command -----------------------------------------
 
 print_logo() {
@@ -293,34 +295,60 @@ parse_yaml() {
 }
 
 # shellcheck disable=SC2120
-running() {
+get_pid() {
   if [ -f "$APP_PID" ]; then
     if [ -s "$APP_PID" ]; then
-        # shellcheck disable=SC2046
-        # shellcheck disable=SC2006
-        kill -0 `cat "$APP_PID"` >/dev/null 2>&1
-        # shellcheck disable=SC2181
-        if [ $? -eq 0 ]; then
-          return 1
-        else
-          rm -f "$APP_PID" >/dev/null 2>&1
-          return 0
-        fi
+      # shellcheck disable=SC2155
+      # shellcheck disable=SC2006
+      local PID=`cat "$APP_PID"`
+      kill -0 $PID >/dev/null 2>&1
+      # shellcheck disable=SC2181
+      if [ $? -eq 0 ]; then
+        echo $PID
+        exit 0
+      fi
+    else
+      rm -f "$APP_PID" >/dev/null 2>&1
+    fi
+  fi
+
+  # shellcheck disable=SC2006
+  local PROPER="${APP_CONF}/application.yml"
+  if [[ ! -f "$PROPER" ]] ; then
+    echo_r "ERROR: config file application.yml invalid or not found! ";
+    exit 1;
+  fi
+
+  # shellcheck disable=SC2046
+  eval $(parse_yaml "${PROPER}" "conf_")
+  # shellcheck disable=SC2154
+  # shellcheck disable=SC2155
+  # shellcheck disable=SC2116
+  local serverPort=$(echo "$conf_server_port")
+  # shellcheck disable=SC2006
+  # shellcheck disable=SC2155
+  local used=`lsof -i:"$serverPort" | wc -l`
+  if [ "$used" -gt 0 ]; then
+    # shellcheck disable=SC2006
+    local PID=`jps -l | grep "$APP_MAIN" | awk '{print $1}'`
+    if [ ! -z $PID ]; then
+      echo $PID
     else
-      return 0
+      echo 0
     fi
   else
-    return 0
+    echo 0
   fi
 }
 
 # shellcheck disable=SC2120
 start() {
-  running
-  # shellcheck disable=SC2181
-  if [ $? -eq "1" ]; then
+  # shellcheck disable=SC2006
+  local PID=$(get_pid)
+
+  if [ $PID -gt 0 ]; then
     # shellcheck disable=SC2006
-    echo_r "StreamPark is already running pid: `cat "$APP_PID"`"
+    echo_r "StreamPark is already running pid: $PID , start aborted!"
     exit 1
   fi
 
@@ -336,7 +364,7 @@ start() {
     echo_w "Using APP_PID:   $APP_PID"
   fi
 
-  PROPER="${APP_CONF}/application.yml"
+  local PROPER="${APP_CONF}/application.yml"
   if [[ ! -f "$PROPER" ]] ; then
     echo_r "ERROR: config file application.yml invalid or not found! ";
     exit 1;
@@ -372,10 +400,10 @@ start() {
   # 2): StreamPark
   # 3): hadoop conf
   # shellcheck disable=SC2091
-  APP_CLASSPATH=".:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib"
+  local APP_CLASSPATH=".:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib"
   # shellcheck disable=SC2206
   # shellcheck disable=SC2010
-  JARS=$(ls "$APP_LIB"/*.jar | grep -v "$APP_LIB/streampark-flink-shims_.*.jar$")
+  local JARS=$(ls "$APP_LIB"/*.jar | grep -v "$APP_LIB/streampark-flink-shims_.*.jar$")
   # shellcheck disable=SC2128
   for jar in $JARS;do
     APP_CLASSPATH=$APP_CLASSPATH:$jar
@@ -390,9 +418,9 @@ start() {
 
   # shellcheck disable=SC2034
   # shellcheck disable=SC2006
-  vmOption=`$_RUNJAVA -cp "$APP_CLASSPATH" $PARAM_CLI --vmopt`
+  local vmOption=`$_RUNJAVA -cp "$APP_CLASSPATH" $PARAM_CLI --vmopt`
 
-  JAVA_OPTS="""
+  local JAVA_OPTS="""
   $vmOption
   $DEFAULT_OPTS
   $DEBUG_OPTS
@@ -412,7 +440,8 @@ start() {
     # Add to pid file if successful start
     if [[ ${PID} =~ ${IS_NUMBER} ]] && kill -0 $PID > /dev/null 2>&1 ; then
         echo $PID > "$APP_PID"
-        echo_g "StreamPark start successful. pid: `cat "$APP_PID"`"
+        # shellcheck disable=SC2006
+        echo_g "StreamPark start successful. pid: $PID"
     else
         echo_r "StreamPark start failed."
         exit 1
@@ -420,7 +449,7 @@ start() {
 }
 
 # shellcheck disable=SC2120
-startDocker() {
+start_docker() {
   # Bugzilla 37848: only output this if we have a TTY
   if [[ ${have_tty} -eq 1 ]]; then
     echo_w "Using APP_BASE:   $APP_BASE"
@@ -433,7 +462,7 @@ startDocker() {
     echo_w "Using APP_PID:   $APP_PID"
   fi
 
-  PROPER="${APP_CONF}/application.yml"
+  local PROPER="${APP_CONF}/application.yml"
   if [[ ! -f "$PROPER" ]] ; then
     echo_r "ERROR: config file application.yml invalid or not found! ";
     exit 1;
@@ -452,10 +481,10 @@ startDocker() {
   # 2): StreamPark
   # 3): hadoop conf
   # shellcheck disable=SC2091
-  APP_CLASSPATH=".:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib"
+  local APP_CLASSPATH=".:${JAVA_HOME}/lib:${JAVA_HOME}/jre/lib"
   # shellcheck disable=SC2206
   # shellcheck disable=SC2010
-  JARS=$(ls "$APP_LIB"/*.jar | grep -v "$APP_LIB/streampark-flink-shims_.*.jar$")
+  local JARS=$(ls "$APP_LIB"/*.jar | grep -v "$APP_LIB/streampark-flink-shims_.*.jar$")
   # shellcheck disable=SC2128
   for jar in $JARS;do
     APP_CLASSPATH=$APP_CLASSPATH:$jar
@@ -470,9 +499,9 @@ startDocker() {
 
   # shellcheck disable=SC2034
   # shellcheck disable=SC2006
-  vmOption=`$_RUNJAVA -cp "$APP_CLASSPATH" $PARAM_CLI --vmopt`
+  local vmOption=`$_RUNJAVA -cp "$APP_CLASSPATH" $PARAM_CLI --vmopt`
 
-  JAVA_OPTS="""
+  local JAVA_OPTS="""
     $vmOption
     $DEFAULT_OPTS
     $DEBUG_OPTS
@@ -501,141 +530,63 @@ debug() {
 
 # shellcheck disable=SC2120
 stop() {
-  running
-  # shellcheck disable=SC2181
-  if [ $? -eq "0" ]; then
-    echo_r "StreamPark is not running."
+  # shellcheck disable=SC2155
+  # shellcheck disable=SC2006
+  local PID=$(get_pid)
+
+  if [[ $PID -eq 0 ]]; then
+    echo_r "StreamPark is not running. stop aborted."
     exit 1
   fi
 
   shift
 
-  local SLEEP=5
-  if [ ! -z "$1" ]; then
-    echo $1 | grep "[^0-9]" >/dev/null 2>&1
-    if [ $? -gt 0 ]; then
-      SLEEP=$1
-      shift
-    fi
-  fi
+  local SLEEP=3
 
-  local FORCE=0
-  if [ "$1" = "-force" ]; then
-    shift
-    FORCE=1
-  fi
+  # shellcheck disable=SC2006
+  echo_g "StreamPark stopping with the PID: $PID"
 
-  local STOPPED=0
-  # shellcheck disable=SC2236
-  if [ -f "$APP_PID" ]; then
-    if [ -s "$APP_PID" ]; then
-      # shellcheck disable=SC2046
-      # shellcheck disable=SC2006
-      kill -0 `cat "$APP_PID"` >/dev/null 2>&1
-      # shellcheck disable=SC2181
-      if [ $? -gt 0 ]; then
-        echo "PID file found but either no matching process was found or the current user does not have permission to stop the process. Stop aborted."
-        exit 1
-      else
-        # shellcheck disable=SC2046
-        # shellcheck disable=SC2006
-        kill -15 `cat "$APP_PID"` >/dev/null 2>&1
-        if [ -f "$APP_PID" ]; then
-          while [ $SLEEP -ge 0 ]; do
-             if [ -f "$APP_PID" ]; then
-               # shellcheck disable=SC2046
-               # shellcheck disable=SC2006
-               kill -0 `cat "$APP_PID"` >/dev/null 2>&1
-               if [ $? -gt 0 ]; then
-                 rm -f "$APP_PID" >/dev/null 2>&1
-                 if [ $? != 0 ]; then
-                   if [ -w "$APP_PID" ]; then
-                     cat /dev/null > "$APP_PID"
-                     # If StreamPark has stopped don't try and force a stop with an empty PID file
-                     FORCE=0
-                   else
-                     echo "The PID file could not be removed or cleared."
-                   fi
-                 fi
-                 STOPPED=1
-                 break
-               fi
-             else
-               STOPPED=1
-               break
-             fi
-             SLEEP=`expr $SLEEP - 1 `
-          done
-
-          #stop failed.normal kill failed? Try a force kill.
-          if [ -f "$APP_PID" ]; then
-            if [ -s "$APP_PID" ]; then
-              # shellcheck disable=SC2046
-              kill -0 `cat "$APP_PID"` >/dev/null 2>&1
-              if [ $? -eq 0 ]; then
-                FORCE=1
-              fi
-            fi
-          fi
-
-          if [ $FORCE -eq 1 ]; then
-            KILL_SLEEP_INTERVAL=5
-            if [ -f "$APP_PID" ]; then
-              # shellcheck disable=SC2006
-              PID=`cat "$APP_PID"`
-              echo_y "Killing StreamPark with the PID: $PID"
-              kill -9 "$PID" >/dev/null 2>&1
-              while [ $KILL_SLEEP_INTERVAL -ge 0 ]; do
-                kill -0 `cat "$APP_PID"` >/dev/null 2>&1
-                if [ $? -gt 0 ]; then
-                  rm -f "$APP_PID" >/dev/null 2>&1
-                  if [ $? != 0 ]; then
-                    if [ -w "$APP_PID" ]; then
-                      cat /dev/null > "$APP_PID"
-                    else
-                      echo_r "The PID file could not be removed."
-                    fi
-                  fi
-                  echo_y "The StreamPark process has been killed."
-                  break
-                fi
-                if [ $KILL_SLEEP_INTERVAL -gt 0 ]; then
-                  sleep 1
-                fi
-                KILL_SLEEP_INTERVAL=`expr $KILL_SLEEP_INTERVAL - 1 `
-              done
-              if [ $KILL_SLEEP_INTERVAL -lt 0 ]; then
-                echo "StreamPark has not been killed completely yet. The process might be waiting on some system call or might be UNINTERRUPTIBLE."
-              fi
-            fi
-          fi
+  kill -9 $PID
+
+  while [ $SLEEP -ge 0 ]; do
+    # shellcheck disable=SC2046
+    # shellcheck disable=SC2006
+    kill -0 $PID >/dev/null 2>&1
+    # shellcheck disable=SC2181
+    if [ $? -gt 0 ]; then
+      rm -f "$APP_PID" >/dev/null 2>&1
+      if [ $? != 0 ]; then
+        if [ -w "$APP_PID" ]; then
+          cat /dev/null > "$APP_PID"
         else
-          STOPPED=1
+          echo_r "The PID file could not be removed."
         fi
       fi
-    else
-      echo "PID file is empty and has been ignored."
-      exit 1
+      echo_g "StreamPark stopped."
+      break
     fi
-  else
-    echo "\$APP_PID was set but the specified file does not exist. Is StreamPark running? Stop aborted."
-    exit 1
-  fi
 
-  if [ $STOPPED -eq 1 ]; then
-     echo_r "StreamPark stopped."
-  fi
+    if [ $SLEEP -gt 0 ]; then
+       sleep 1
+    fi
+    # shellcheck disable=SC2006
+    # shellcheck disable=SC2003
+    SLEEP=`expr $SLEEP - 1 `
+  done
 
+  if [ "$SLEEP" -lt 0 ]; then
+     echo_r "StreamPark has not been killed completely yet. The process might be waiting on some system call or might be UNINTERRUPTIBLE."
+  fi
 }
 
 status() {
-  running
-  # shellcheck disable=SC2181
-  if [ $? -eq "1" ]; then
-    # shellcheck disable=SC2006
-    echo_g "StreamPark is running pid is: `cat "$APP_PID"`"
-  else
+  # shellcheck disable=SC2155
+  # shellcheck disable=SC2006
+  local PID=$(get_pid)
+  if [ $PID -eq 0 ]; then
     echo_r "StreamPark is not running"
+  else
+    echo_g "StreamPark is running pid is: $PID"
   fi
 }
 
@@ -656,8 +607,8 @@ main() {
     "start")
         start
         ;;
-    "startDocker")
-        startDocker
+    "start_docker")
+        start_docker
         ;;
     "stop")
         stop
@@ -673,7 +624,7 @@ main() {
         echo_w "Usage: streampark.sh ( commands ... )"
         echo_w "commands:"
         echo_w "  start \$conf               Start StreamPark with application config."
-        echo_w "  stop n -force             Stop StreamPark, wait up to n seconds and then use kill -KILL if still running"
+        echo_w "  stop                      Stop StreamPark, wait up to 3 seconds and then use kill -KILL if still running"
         echo_w "  status                    StreamPark status"
         echo_w "  debug                     StreamPark start with debug mode,start debug mode, like: bash streampark.sh debug 10002"
         echo_w "  restart \$conf             restart StreamPark with application config."
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/UserController.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/UserController.java
index 92709df51..13fafed17 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/UserController.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/system/controller/UserController.java
@@ -24,7 +24,6 @@ import org.apache.streampark.console.base.exception.ApiAlertException;
 import org.apache.streampark.console.core.annotation.PermissionAction;
 import org.apache.streampark.console.core.enums.LoginType;
 import org.apache.streampark.console.core.enums.PermissionType;
-import org.apache.streampark.console.core.enums.UserType;
 import org.apache.streampark.console.core.service.CommonService;
 import org.apache.streampark.console.system.entity.Team;
 import org.apache.streampark.console.system.entity.User;
@@ -131,13 +130,6 @@ public class UserController {
     return RestResponse.success(newPass);
   }
 
-  @Operation(summary = "List user types")
-  @PostMapping("types")
-  @RequiresPermissions("user:types")
-  public RestResponse userTypes() {
-    return RestResponse.success(UserType.values());
-  }
-
   @Operation(summary = "Init the user teams")
   @PostMapping("initTeam")
   public RestResponse initTeam(Long teamId, Long userId) {
diff --git a/streampark-console/streampark-console-webapp/src/api/system/user.ts b/streampark-console/streampark-console-webapp/src/api/system/user.ts
index f5273a073..b5767df01 100644
--- a/streampark-console/streampark-console-webapp/src/api/system/user.ts
+++ b/streampark-console/streampark-console-webapp/src/api/system/user.ts
@@ -41,7 +41,6 @@ enum Api {
   ResetPassword = '/user/password/reset',
   Password = '/user/password',
   CheckName = '/user/check/name',
-  TYPES = '/user/types',
   SET_TEAM = '/user/setTeam',
   INIT_TEAM = '/user/initTeam',
   APP_OWNERS = '/user/appOwners',
@@ -116,17 +115,6 @@ export function checkUserName(data) {
   });
 }
 
-export function fetchUserTypes() {
-  return defHttp
-    .post({
-      url: Api.TYPES,
-      data: {},
-    })
-    .then((res) => {
-      return res.map((t: string) => ({ label: t, value: t }));
-    });
-}
-
 /**
  * User change password
  * @param data
diff --git a/streampark-console/streampark-console-webapp/src/views/system/user/user.data.ts b/streampark-console/streampark-console-webapp/src/views/system/user/user.data.ts
index c62eb8b70..57ab342b1 100644
--- a/streampark-console/streampark-console-webapp/src/views/system/user/user.data.ts
+++ b/streampark-console/streampark-console-webapp/src/views/system/user/user.data.ts
@@ -17,7 +17,7 @@
 import { BasicColumn, FormSchema } from '/@/components/Table';
 import { h } from 'vue';
 import { Tag } from 'ant-design-vue';
-import { checkUserName, fetchUserTypes } from '/@/api/system/user';
+import { checkUserName } from '/@/api/system/user';
 import { FormTypeEnum } from '/@/enums/formEnum';
 import { useI18n } from '/@/hooks/web/useI18n';
 const { t } = useI18n();
@@ -34,6 +34,12 @@ export const enum GenderEnum {
   Other = '2',
 }
 
+// user type
+export const enum UserTypeEnum {
+  ADMIN = 'ADMIN',
+  USER = 'USER',
+}
+
 export const columns: BasicColumn[] = [
   { title: t('system.user.form.userName'), dataIndex: 'username', sorter: true },
   { title: t('system.user.form.nickName'), dataIndex: 'nickName' },
@@ -142,10 +148,13 @@ export const formSchema = (formType: string): FormSchema[] => {
     {
       label: t('system.user.form.userType'),
       field: 'userType',
-      component: 'ApiSelect',
+      component: 'Select',
       componentProps: {
         disabled: isView,
-        api: fetchUserTypes,
+        options:  [
+          { label: t('ADMIN'), value: UserTypeEnum.ADMIN },
+          { label: t('USER'), value: UserTypeEnum.USER },
+        ]
       },
       rules: [{ required: true }],
     },