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 2022/12/11 08:27:02 UTC

[incubator-streampark] branch config created (now 78f2930d3)

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

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


      at 78f2930d3 [Improve] config file type improvement

This branch includes the following new commits:

     new 78f2930d3 [Improve] config file type improvement

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-streampark] 01/01: [Improve] config file type improvement

Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 78f2930d34967f6ff55c71ec50a0539609ce1b06
Author: benjobs <be...@apache.org>
AuthorDate: Sun Dec 11 16:26:39 2022 +0800

    [Improve] config file type improvement
---
 .../console/core/entity/ApplicationConfig.java     | 35 +++++---------
 .../console/core/enums/ConfigFileType.java         | 55 ++++++++++++++++++++++
 .../service/impl/ApplicationConfigServiceImpl.java | 12 ++++-
 .../core/service/impl/ApplicationServiceImpl.java  |  8 +++-
 .../src/enums/flinkEnum.ts                         |  9 ++++
 .../src/views/flink/app/Add.vue                    |  4 +-
 .../src/views/flink/app/EditStreamPark.vue         |  6 +--
 .../src/views/flink/app/hooks/useCreateSchema.ts   |  8 ++--
 .../src/views/flink/app/utils/index.ts             | 17 +++++++
 9 files changed, 119 insertions(+), 35 deletions(-)

diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity/ApplicationConfig.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity/ApplicationConfig.java
index db660043f..2b41bd3a0 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity/ApplicationConfig.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/entity/ApplicationConfig.java
@@ -19,6 +19,7 @@ package org.apache.streampark.console.core.entity;
 
 import org.apache.streampark.common.util.DeflaterUtils;
 import org.apache.streampark.common.util.PropertiesUtils;
+import org.apache.streampark.console.core.enums.ConfigFileType;
 
 import com.baomidou.mybatisplus.annotation.FieldStrategy;
 import com.baomidou.mybatisplus.annotation.IdType;
@@ -75,30 +76,20 @@ public class ApplicationConfig {
     }
 
     public Map<String, String> readConfig() {
-        switch (this.format) {
-            case 1:
-                return PropertiesUtils.fromYamlTextAsJava(DeflaterUtils.unzipString(this.content));
-            case 2:
-                return PropertiesUtils.fromPropertiesTextAsJava(DeflaterUtils.unzipString(this.content));
-            case 3:
-                return PropertiesUtils.fromHoconTextAsJava(DeflaterUtils.unzipString(this.content));
-            default:
-                break;
+        ConfigFileType fileType = ConfigFileType.of(this.format);
+        if (fileType != null) {
+            switch (fileType) {
+                case YAML:
+                    return PropertiesUtils.fromYamlTextAsJava(DeflaterUtils.unzipString(this.content));
+                case PROPERTIES:
+                    return PropertiesUtils.fromPropertiesTextAsJava(DeflaterUtils.unzipString(this.content));
+                case HOCON:
+                    return PropertiesUtils.fromHoconTextAsJava(DeflaterUtils.unzipString(this.content));
+                default:
+                    break;
+            }
         }
         return null;
     }
 
-    public String configType() {
-        switch (this.format) {
-            case 1:
-                return "yaml";
-            case 2:
-                return "prop";
-            case 3:
-                return "conf";
-            default:
-                throw new IllegalArgumentException("getConfigType error, format must be (1|2|3), detail: 1:yaml, 2:properties, 3:hocon");
-        }
-    }
-
 }
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/enums/ConfigFileType.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/enums/ConfigFileType.java
new file mode 100644
index 000000000..abf298dc6
--- /dev/null
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/enums/ConfigFileType.java
@@ -0,0 +1,55 @@
+/*
+ * 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.streampark.console.core.enums;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+/**
+ * configFile Type enum
+ */
+public enum ConfigFileType implements Serializable {
+
+    YAML(1, "yaml"),
+
+    PROPERTIES(2, "prop"),
+
+    HOCON(3, "conf"),
+
+    UNKNOWN(0, null);
+
+    private final int value;
+    private final String typeName;
+
+    ConfigFileType(int value, String name) {
+        this.value = value;
+        this.typeName = name;
+    }
+
+    public int getValue() {
+        return value;
+    }
+
+    public String getTypeName() {
+        return typeName;
+    }
+
+    public static ConfigFileType of(Integer value) {
+        return Arrays.stream(values()).filter((x) -> x.value == value).findFirst().orElse(null);
+    }
+}
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationConfigServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationConfigServiceImpl.java
index dc23e192a..d0cf3ce66 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationConfigServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationConfigServiceImpl.java
@@ -21,9 +21,11 @@ import org.apache.streampark.common.util.DeflaterUtils;
 import org.apache.streampark.common.util.Utils;
 import org.apache.streampark.console.base.domain.Constant;
 import org.apache.streampark.console.base.domain.RestRequest;
+import org.apache.streampark.console.base.exception.ApiAlertException;
 import org.apache.streampark.console.base.mybatis.pager.MybatisPager;
 import org.apache.streampark.console.core.entity.Application;
 import org.apache.streampark.console.core.entity.ApplicationConfig;
+import org.apache.streampark.console.core.enums.ConfigFileType;
 import org.apache.streampark.console.core.enums.EffectiveType;
 import org.apache.streampark.console.core.mapper.ApplicationConfigMapper;
 import org.apache.streampark.console.core.service.ApplicationConfigService;
@@ -71,7 +73,15 @@ public class ApplicationConfigServiceImpl
 
         ApplicationConfig applicationConfig = new ApplicationConfig();
         applicationConfig.setAppId(application.getId());
-        applicationConfig.setFormat(application.getFormat());
+
+        if (application.getFormat() != null) {
+            ConfigFileType fileType = ConfigFileType.of(application.getFormat());
+            if (fileType == null || ConfigFileType.UNKNOWN.equals(fileType)) {
+                throw new ApiAlertException("application' config error. must be (.properties|.yaml|.yml |.conf)");
+            }
+            applicationConfig.setFormat(fileType.getValue());
+        }
+
         applicationConfig.setContent(config);
         applicationConfig.setCreateTime(new Date());
         Integer version = this.baseMapper.getLastVersion(application.getId());
diff --git a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationServiceImpl.java b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationServiceImpl.java
index 84fa8693b..5ca685639 100644
--- a/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationServiceImpl.java
+++ b/streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/ApplicationServiceImpl.java
@@ -62,6 +62,7 @@ import org.apache.streampark.console.core.enums.AppExistsState;
 import org.apache.streampark.console.core.enums.CandidateType;
 import org.apache.streampark.console.core.enums.ChangedType;
 import org.apache.streampark.console.core.enums.CheckPointType;
+import org.apache.streampark.console.core.enums.ConfigFileType;
 import org.apache.streampark.console.core.enums.FlinkAppState;
 import org.apache.streampark.console.core.enums.LaunchState;
 import org.apache.streampark.console.core.enums.OptionState;
@@ -1357,7 +1358,12 @@ public class ApplicationServiceImpl extends ServiceImpl<ApplicationMapper, Appli
             } else {
                 switch (application.getApplicationType()) {
                     case STREAMPARK_FLINK:
-                        appConf = String.format("%s://%s", applicationConfig.configType(), applicationConfig.getContent());
+                        ConfigFileType fileType = ConfigFileType.of(applicationConfig.getFormat());
+                        if (fileType != null && !fileType.equals(ConfigFileType.UNKNOWN)) {
+                            appConf = String.format("%s://%s", fileType.getTypeName(), applicationConfig.getContent());
+                        } else {
+                            throw new IllegalArgumentException("application' config type error,must be ( yaml| properties| hocon )");
+                        }
                         break;
                     case APACHE_FLINK:
                         appConf = String.format("json://{\"%s\":\"%s\"}", ConfigConst.KEY_FLINK_APPLICATION_MAIN_CLASS(),
diff --git a/streampark-console/streampark-console-webapp/src/enums/flinkEnum.ts b/streampark-console/streampark-console-webapp/src/enums/flinkEnum.ts
index 2fb05ea34..5b38c0d83 100644
--- a/streampark-console/streampark-console-webapp/src/enums/flinkEnum.ts
+++ b/streampark-console/streampark-console-webapp/src/enums/flinkEnum.ts
@@ -152,6 +152,15 @@ export enum JobTypeEnum {
   SQL = 2,
 }
 
+export enum ConfigTypeEnum {
+  /** yaml type */
+  YAML = 1,
+  /** properties type */
+  PROPERTIES = 2,
+  /** HOCON config type */
+  HOCON = 3,
+}
+
 export enum CandidateTypeEnum {
   /** non candidate */
   NONE = 0,
diff --git a/streampark-console/streampark-console-webapp/src/views/flink/app/Add.vue b/streampark-console/streampark-console-webapp/src/views/flink/app/Add.vue
index 0682c30c8..e8365b602 100644
--- a/streampark-console/streampark-console-webapp/src/views/flink/app/Add.vue
+++ b/streampark-console/streampark-console-webapp/src/views/flink/app/Add.vue
@@ -36,7 +36,7 @@
   import { fetchAppConf, fetchCreate, fetchMain, fetchUpload } from '/@/api/flink/app/app';
   import options from './data/option';
   import { useCreateSchema } from './hooks/useCreateSchema';
-  import { handleSubmitParams } from './utils';
+  import { getAppConfType, handleSubmitParams } from './utils';
   import { useMessage } from '/@/hooks/web/useMessage';
   import { createLocalStorage } from '/@/utils/cache';
   import { buildUUID } from '/@/utils/uuid';
@@ -181,7 +181,7 @@
         //streampark flink
         if (values.appType == AppTypeEnum.STREAMPARK_FLINK) {
           const configVal = values['config'];
-          params['format'] = configVal.endsWith('.properties') ? 2 : 1;
+          params['format'] = getAppConfType(configVal);
           if (values.configOverride == null) {
             const res = await fetchAppConf({
               config: configVal,
diff --git a/streampark-console/streampark-console-webapp/src/views/flink/app/EditStreamPark.vue b/streampark-console/streampark-console-webapp/src/views/flink/app/EditStreamPark.vue
index 520167d53..46a98f46c 100644
--- a/streampark-console/streampark-console-webapp/src/views/flink/app/EditStreamPark.vue
+++ b/streampark-console/streampark-console-webapp/src/views/flink/app/EditStreamPark.vue
@@ -27,7 +27,7 @@
   import configOptions from './data/option';
   import { fetchMain, fetchUpload, fetchUpdate, fetchGet } from '/@/api/flink/app/app';
   import { useRoute } from 'vue-router';
-  import { handleSubmitParams } from './utils';
+  import { getAppConfType, handleSubmitParams } from './utils';
   import { fetchFlinkHistory } from '/@/api/flink/app/flinkSql';
   import { decodeByBase64, encryptByBase64 } from '/@/utils/cipher';
   import PomTemplateTab from './components/PodTemplate/PomTemplateTab.vue';
@@ -223,9 +223,7 @@
       const format =
         values.strategy == UseStrategyEnum.USE_EXIST
           ? app.format
-          : (values.config || '').endsWith('.properties')
-          ? 2
-          : 1;
+          : getAppConfType(values.config || '');
       let config = values.configOverride || app.config;
       if (config != null && config.trim() !== '') {
         config = encryptByBase64(config);
diff --git a/streampark-console/streampark-console-webapp/src/views/flink/app/hooks/useCreateSchema.ts b/streampark-console/streampark-console-webapp/src/views/flink/app/hooks/useCreateSchema.ts
index 2e2a90da2..85109b861 100644
--- a/streampark-console/streampark-console-webapp/src/views/flink/app/hooks/useCreateSchema.ts
+++ b/streampark-console/streampark-console-webapp/src/views/flink/app/hooks/useCreateSchema.ts
@@ -27,7 +27,7 @@ import { modules, fetchListConf, fetchListJars } from '/@/api/flink/project';
 import { RuleObject } from 'ant-design-vue/lib/form';
 import { StoreValue } from 'ant-design-vue/lib/form/interface';
 import { renderResourceFrom } from './useFlinkRender';
-import { filterOption } from '../utils';
+import { checkAppConfType, filterOption, getAppConfType } from '../utils';
 import { useI18n } from '/@/hooks/web/useI18n';
 import { AppTypeEnum } from '/@/enums/flinkEnum';
 const { t } = useI18n();
@@ -75,10 +75,8 @@ export const useCreateSchema = (dependencyRef: Ref) => {
   // }
   function handleCheckConfig(_rule: RuleObject, value: StoreValue) {
     if (value) {
-      const isProp = value.endsWith('.properties');
-      const isYaml = value.endsWith('.yaml') || value.endsWith('.yml');
-      const isConf = value.endsWith('.conf');
-      if (!isProp && !isYaml && !isConf) {
+      const confType = getAppConfType(value);
+      if (!checkAppConfType(confType)) {
         return Promise.reject('The configuration file must be (.properties|.yaml|.yml |.conf)');
       } else {
         return Promise.resolve();
diff --git a/streampark-console/streampark-console-webapp/src/views/flink/app/utils/index.ts b/streampark-console/streampark-console-webapp/src/views/flink/app/utils/index.ts
index 8da9eb826..6b4b42916 100644
--- a/streampark-console/streampark-console-webapp/src/views/flink/app/utils/index.ts
+++ b/streampark-console/streampark-console-webapp/src/views/flink/app/utils/index.ts
@@ -20,6 +20,7 @@ import { AppListRecord } from '/@/api/flink/app/app.type';
 import { fetchRemoteURL } from '/@/api/flink/setting/flinkCluster';
 import {
   AppStateEnum,
+  ConfigTypeEnum,
   ExecModeEnum,
   LaunchStateEnum,
   OptionStateEnum,
@@ -202,6 +203,22 @@ export function handleFormValue(values: Recordable) {
   return options;
 }
 
+export function getAppConfType(configFile: string): number {
+  const config = configFile || '';
+  if (config.endsWith('.yaml') || config.endsWith('.yml')) {
+    return ConfigTypeEnum.YAML;
+  } else if (config.endsWith('.properties')) {
+    return ConfigTypeEnum.PROPERTIES;
+  } else if (config.endsWith('.conf')) {
+    return ConfigTypeEnum.HOCON;
+  }
+  return 0;
+}
+
+export function checkAppConfType(confType: number): boolean {
+  return [ConfigTypeEnum.YAML, ConfigTypeEnum.PROPERTIES, ConfigTypeEnum.HOCON].includes(confType);
+}
+
 export function handleDependencyJsonToPom(json, pomMap, jarMap) {
   if (json != null && json.trim() !== '') {
     const deps = JSON.parse(json);