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

xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 481d6ec0f8 [type:feature] namespace export operation (#5857)
481d6ec0f8 is described below

commit 481d6ec0f89ad240198ac253a7a13be694d2f343
Author: aias00 <liuhon...@apache.org>
AuthorDate: Thu Dec 19 15:39:27 2024 +0800

    [type:feature] namespace export operation (#5857)
    
    * [type:feature] config export support plugin template data
    
    * [type:feature] config export support plugin template data
    
    * [type:feature] config export support plugin template data
    
    * [type:feature] config export support plugin template data
    
    * [type:feature] namespace config export
    
    * [type:feature] namespace config export
    
    * [type:feature] namespace config export
    
    * [type:feature] namespace config export
    
    * [type:feature] namespace config export
---
 .../admin/service/NamespacePluginService.java      | 14 ++--
 .../apache/shenyu/admin/service/PluginService.java |  8 ---
 .../admin/service/impl/ConfigsServiceImpl.java     | 77 ++++++++++++++++++++--
 .../service/impl/NamespacePluginServiceImpl.java   | 54 ++++++++++-----
 .../admin/service/impl/PluginServiceImpl.java      | 51 --------------
 .../shenyu/admin/service/ConfigsServiceTest.java   |  8 ++-
 .../common/constant/ExportImportConstants.java     | 10 +++
 7 files changed, 133 insertions(+), 89 deletions(-)

diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/NamespacePluginService.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/NamespacePluginService.java
index b3de7bf277..09b2164d76 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/NamespacePluginService.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/NamespacePluginService.java
@@ -17,7 +17,6 @@
 
 package org.apache.shenyu.admin.service;
 
-import org.apache.shenyu.admin.model.dto.PluginDTO;
 import org.apache.shenyu.admin.model.dto.NamespacePluginDTO;
 import org.apache.shenyu.admin.model.page.CommonPager;
 import org.apache.shenyu.admin.model.query.NamespacePluginQuery;
@@ -108,11 +107,11 @@ public interface NamespacePluginService extends 
PageService<NamespacePluginQuery
      * @return the list
      */
     List<NamespacePluginVO> listByNamespaceId(String namespaceId);
-
+    
     /**
      * List all vo list.
      *
-     * @param namespaceId the namespaceId
+     * @param namespaceId the namespace id
      * @return the vo list
      */
     List<NamespacePluginVO> listAllData(String namespaceId);
@@ -148,10 +147,17 @@ public interface NamespacePluginService extends 
PageService<NamespacePluginQuery
     /**
      * import plugin data.
      *
+     * @param namespace  the namespace
      * @param pluginList the plugin data
      * @return config import result
      */
-    ConfigImportResult importData(List<PluginDTO> pluginList);
+    ConfigImportResult importData(String namespace, List<NamespacePluginDTO> 
pluginList);
     
+    /**
+     * List by namespace.
+     *
+     * @param namespace the namespace
+     * @return the list
+     */
     List<PluginData> listByNamespace(String namespace);
 }
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java
index 73cf6f6fb5..ba2df965b8 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginService.java
@@ -86,14 +86,6 @@ public interface PluginService extends 
PageService<PluginQueryCondition, PluginV
      * @return the vo list
      */
     List<PluginVO> listAllData();
-
-    /**
-     * List all vo list.
-     *
-     * @param namespaceId the namespace id
-     * @return the vo list
-     */
-    List<PluginVO> listAllDataByNamespaceId(String namespaceId);
     
     /**
      * list all not in resource.
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ConfigsServiceImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ConfigsServiceImpl.java
index 2b6d8a2d62..bc2ea0f906 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ConfigsServiceImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ConfigsServiceImpl.java
@@ -25,6 +25,7 @@ import org.apache.shenyu.admin.model.dto.AppAuthDTO;
 import org.apache.shenyu.admin.model.dto.DiscoveryDTO;
 import org.apache.shenyu.admin.model.dto.DiscoveryUpstreamDTO;
 import org.apache.shenyu.admin.model.dto.MetaDataDTO;
+import org.apache.shenyu.admin.model.dto.NamespacePluginDTO;
 import org.apache.shenyu.admin.model.dto.PluginDTO;
 import org.apache.shenyu.admin.model.dto.RuleDTO;
 import org.apache.shenyu.admin.model.dto.SelectorDTO;
@@ -35,6 +36,8 @@ import org.apache.shenyu.admin.model.vo.AppAuthVO;
 import org.apache.shenyu.admin.model.vo.DiscoveryUpstreamVO;
 import org.apache.shenyu.admin.model.vo.DiscoveryVO;
 import org.apache.shenyu.admin.model.vo.MetaDataVO;
+import org.apache.shenyu.admin.model.vo.NamespacePluginVO;
+import org.apache.shenyu.admin.model.vo.PluginHandleVO;
 import org.apache.shenyu.admin.model.vo.PluginVO;
 import org.apache.shenyu.admin.model.vo.RuleVO;
 import org.apache.shenyu.admin.model.vo.SelectorVO;
@@ -44,16 +47,20 @@ import org.apache.shenyu.admin.service.ConfigsService;
 import org.apache.shenyu.admin.service.DiscoveryService;
 import org.apache.shenyu.admin.service.DiscoveryUpstreamService;
 import org.apache.shenyu.admin.service.MetaDataService;
+import org.apache.shenyu.admin.service.NamespacePluginService;
+import org.apache.shenyu.admin.service.PluginHandleService;
 import org.apache.shenyu.admin.service.PluginService;
 import org.apache.shenyu.admin.service.ProxySelectorService;
 import org.apache.shenyu.admin.service.RuleService;
 import org.apache.shenyu.admin.service.SelectorService;
 import org.apache.shenyu.admin.service.ShenyuDictService;
 import org.apache.shenyu.admin.utils.ZipUtil;
+import org.apache.shenyu.admin.utils.ZipUtil.ZipItem;
 import org.apache.shenyu.common.constant.ExportImportConstants;
 import org.apache.shenyu.common.dto.ProxySelectorData;
 import org.apache.shenyu.common.utils.GsonUtils;
 import org.apache.shenyu.common.utils.JsonUtils;
+import org.apache.shenyu.common.utils.UUIDUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
@@ -79,6 +86,16 @@ public class ConfigsServiceImpl implements ConfigsService {
      */
     private final PluginService pluginService;
 
+    /**
+     * The Namespace Plugin service.
+     */
+    private final NamespacePluginService namespacePluginService;
+
+    /**
+     * The Plugin Handle service.
+     */
+    private final PluginHandleService pluginHandleService;
+
     /**
      * The Selector service.
      */
@@ -116,6 +133,8 @@ public class ConfigsServiceImpl implements ConfigsService {
 
     public ConfigsServiceImpl(final AppAuthService appAuthService,
                                          final PluginService pluginService,
+                                         final NamespacePluginService 
namespacePluginService,
+                                         final PluginHandleService 
pluginHandleService,
                                          final SelectorService selectorService,
                                          final RuleService ruleService,
                                          final MetaDataService metaDataService,
@@ -125,6 +144,8 @@ public class ConfigsServiceImpl implements ConfigsService {
                                          final DiscoveryUpstreamService 
discoveryUpstreamService) {
         this.appAuthService = appAuthService;
         this.pluginService = pluginService;
+        this.namespacePluginService = namespacePluginService;
+        this.pluginHandleService = pluginHandleService;
         this.selectorService = selectorService;
         this.ruleService = ruleService;
         this.metaDataService = metaDataService;
@@ -166,7 +187,7 @@ public class ConfigsServiceImpl implements ConfigsService {
         
         exportMetadata(namespace, zipItemList);
         
-        exportPluginData(namespace, zipItemList);
+        exportNamespacePluginData(namespace, zipItemList);
         
         exportSelectorData(namespace, zipItemList);
         
@@ -176,6 +197,8 @@ public class ConfigsServiceImpl implements ConfigsService {
         
         exportPluginTemplateData(zipItemList);
         
+        exportPluginHandleData(zipItemList);
+        
         exportProxySelectorData(namespace, zipItemList);
         
         exportDiscoveryData(namespace, zipItemList);
@@ -185,6 +208,13 @@ public class ConfigsServiceImpl implements ConfigsService {
         return ShenyuAdminResult.success(ZipUtil.zip(zipItemList));
     }
     
+    private void exportPluginHandleData(final List<ZipItem> zipItemList) {
+        List<PluginHandleVO> pluginHandleDataList = 
pluginHandleService.listAllData();
+        if (CollectionUtils.isNotEmpty(pluginHandleDataList)) {
+            zipItemList.add(new 
ZipItem(ExportImportConstants.PLUGIN_HANDLE_JSON, 
JsonUtils.toJson(pluginHandleDataList)));
+        }
+    }
+    
     private void exportDiscoveryUpstreamData(final List<ZipUtil.ZipItem> 
zipItemList) {
         List<DiscoveryUpstreamVO> discoveryUpstreamList = 
discoveryUpstreamService.listAllData();
         if (CollectionUtils.isNotEmpty(discoveryUpstreamList)) {
@@ -272,10 +302,10 @@ public class ConfigsServiceImpl implements ConfigsService 
{
         }
     }
 
-    private void exportPluginData(final String namespace, final 
List<ZipUtil.ZipItem> zipItemList) {
-        List<PluginVO> pluginDataList = 
pluginService.listAllDataByNamespaceId(namespace);
-        if (CollectionUtils.isNotEmpty(pluginDataList)) {
-            zipItemList.add(new 
ZipUtil.ZipItem(ExportImportConstants.PLUGIN_JSON, 
JsonUtils.toJson(pluginDataList)));
+    private void exportNamespacePluginData(final String namespace, final 
List<ZipUtil.ZipItem> zipItemList) {
+        List<NamespacePluginVO> namespacePluginVOList = 
namespacePluginService.listAllData(namespace);
+        if (CollectionUtils.isNotEmpty(namespacePluginVOList)) {
+            zipItemList.add(new 
ZipUtil.ZipItem(ExportImportConstants.NAMESPACE_PLUGIN_JSON, 
JsonUtils.toJson(namespacePluginVOList)));
         }
     }
     
@@ -378,8 +408,11 @@ public class ConfigsServiceImpl implements ConfigsService {
                 case ExportImportConstants.META_JSON:
                     importMetaData(namespace, result, zipItem);
                     break;
-                case ExportImportConstants.PLUGIN_JSON:
-                    importPluginData(namespace, result, zipItem);
+                case ExportImportConstants.PLUGIN_TEMPLATE_JSON:
+                    importPluginTemplateData(result, zipItem);
+                    break;
+                case ExportImportConstants.NAMESPACE_PLUGIN_JSON:
+                    importNamespacePluginData(namespace, result, zipItem);
                     break;
                 case ExportImportConstants.SELECTOR_JSON:
                     importSelectorData(namespace, result, zipItem);
@@ -574,6 +607,36 @@ public class ConfigsServiceImpl implements ConfigsService {
         }
     }
 
+    private void importNamespacePluginData(final String namespace, final 
Map<String, Object> result, final ZipUtil.ZipItem zipItem) {
+        String pluginJson = zipItem.getItemData();
+        if (StringUtils.isNotEmpty(pluginJson)) {
+            List<NamespacePluginDTO> namespacePluginDTOS = 
GsonUtils.getInstance().fromList(pluginJson, NamespacePluginDTO.class);
+            // set namespaceId
+            namespacePluginDTOS.forEach(namespacePluginDTO -> {
+                namespacePluginDTO.setNamespaceId(namespace);
+                // change id
+                
namespacePluginDTO.setId(UUIDUtils.getInstance().generateShortUuid());
+            });
+            ConfigImportResult configImportResult = 
namespacePluginService.importData(namespace, namespacePluginDTOS);
+            result.put(ExportImportConstants.PLUGIN_IMPORT_SUCCESS_COUNT, 
configImportResult.getSuccessCount());
+            if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) {
+                result.put(ExportImportConstants.PLUGIN_IMPORT_FAIL_MESSAGE, 
configImportResult.getFailMessage());
+            }
+        }
+    }
+    
+    private void importPluginTemplateData(final Map<String, Object> result, 
final ZipUtil.ZipItem zipItem) {
+        String pluginTemplateJson = zipItem.getItemData();
+        if (StringUtils.isNotEmpty(pluginTemplateJson)) {
+            List<PluginDTO> pluginTemplateList = 
GsonUtils.getInstance().fromList(pluginTemplateJson, PluginDTO.class);
+            ConfigImportResult configImportResult = 
pluginService.importData(pluginTemplateList);
+            result.put(ExportImportConstants.PLUGIN_IMPORT_SUCCESS_COUNT, 
configImportResult.getSuccessCount());
+            if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) {
+                result.put(ExportImportConstants.PLUGIN_IMPORT_FAIL_MESSAGE, 
configImportResult.getFailMessage());
+            }
+        }
+    }
+
     private void importMetaData(final Map<String, Object> result, final 
ZipUtil.ZipItem zipItem) {
         String metaJson = zipItem.getItemData();
         if (StringUtils.isNotEmpty(metaJson)) {
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespacePluginServiceImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespacePluginServiceImpl.java
index 95903af87f..da1473016b 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespacePluginServiceImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespacePluginServiceImpl.java
@@ -26,7 +26,6 @@ import org.apache.shenyu.admin.mapper.PluginHandleMapper;
 import org.apache.shenyu.admin.mapper.PluginMapper;
 import org.apache.shenyu.admin.mapper.SelectorMapper;
 import org.apache.shenyu.admin.model.dto.NamespacePluginDTO;
-import org.apache.shenyu.admin.model.dto.PluginDTO;
 import org.apache.shenyu.admin.model.entity.NamespacePluginRelDO;
 import org.apache.shenyu.admin.model.entity.PluginDO;
 import org.apache.shenyu.admin.model.entity.PluginHandleDO;
@@ -36,10 +35,8 @@ import org.apache.shenyu.admin.model.page.PageResultUtils;
 import org.apache.shenyu.admin.model.query.NamespacePluginQuery;
 import org.apache.shenyu.admin.model.result.ConfigImportResult;
 import org.apache.shenyu.admin.model.vo.NamespacePluginVO;
-import org.apache.shenyu.admin.model.vo.PluginHandleVO;
 import org.apache.shenyu.admin.model.vo.PluginSnapshotVO;
 import org.apache.shenyu.admin.service.NamespacePluginService;
-import org.apache.shenyu.admin.service.PluginHandleService;
 import org.apache.shenyu.admin.service.publish.NamespacePluginEventPublisher;
 import org.apache.shenyu.admin.transfer.PluginTransfer;
 import org.apache.shenyu.admin.utils.ShenyuResultMessage;
@@ -52,7 +49,6 @@ import 
org.springframework.transaction.annotation.Transactional;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
-import java.util.Optional;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
@@ -61,8 +57,6 @@ public class NamespacePluginServiceImpl implements 
NamespacePluginService {
     
     private final NamespacePluginRelMapper namespacePluginRelMapper;
     
-    private final PluginHandleService pluginHandleService;
-    
     private final NamespacePluginEventPublisher namespacePluginEventPublisher;
     
     private final PluginMapper pluginMapper;
@@ -72,13 +66,11 @@ public class NamespacePluginServiceImpl implements 
NamespacePluginService {
     private final PluginHandleMapper pluginHandleMapper;
     
     public NamespacePluginServiceImpl(final NamespacePluginRelMapper 
namespacePluginRelMapper,
-                                      final PluginHandleService 
pluginHandleService,
                                       final NamespacePluginEventPublisher 
namespacePluginEventPublisher,
                                       final PluginMapper pluginMapper,
                                       final SelectorMapper selectorMapper,
                                       final PluginHandleMapper 
pluginHandleMapper) {
         this.namespacePluginRelMapper = namespacePluginRelMapper;
-        this.pluginHandleService = pluginHandleService;
         this.namespacePluginEventPublisher = namespacePluginEventPublisher;
         this.pluginMapper = pluginMapper;
         this.selectorMapper = selectorMapper;
@@ -158,14 +150,11 @@ public class NamespacePluginServiceImpl implements 
NamespacePluginService {
     
     @Override
     public List<NamespacePluginVO> listAllData(final String namespaceId) {
-        Map<String, List<PluginHandleVO>> pluginHandleMap = 
pluginHandleService.listAllData().stream().collect(Collectors.groupingBy(PluginHandleVO::getPluginId));
-        
-        return 
namespacePluginRelMapper.selectAllByNamespaceId(namespaceId).stream().filter(Objects::nonNull).peek(namespacePluginVO
 -> {
-            List<PluginHandleVO> pluginHandleList = 
Optional.ofNullable(pluginHandleMap.get(namespacePluginVO.getPluginId())).orElse(Lists.newArrayList()).stream()
-                    // to make less volume of export data
-                    .peek(x -> 
x.setDictOptions(null)).collect(Collectors.toList());
-            namespacePluginVO.setPluginHandleList(pluginHandleList);
-        }).collect(Collectors.toList());
+        List<NamespacePluginVO> namespacePluginVOList = 
namespacePluginRelMapper.selectByNamespaceId(namespaceId);
+        if (CollectionUtils.isEmpty(namespacePluginVOList)) {
+            return Lists.newArrayList();
+        }
+        return namespacePluginVOList;
     }
     
     @Override
@@ -243,8 +232,37 @@ public class NamespacePluginServiceImpl implements 
NamespacePluginService {
     }
     
     @Override
-    public ConfigImportResult importData(final List<PluginDTO> pluginList) {
-        return null;
+    public ConfigImportResult importData(final String namespace, final 
List<NamespacePluginDTO> namespacePluginList) {
+        if (CollectionUtils.isEmpty(namespacePluginList)) {
+            return ConfigImportResult.success();
+        }
+        Map<String, NamespacePluginRelDO> existPluginMap = 
namespacePluginRelMapper.listByNamespaceId(namespace)
+                .stream()
+                .filter(Objects::nonNull)
+                .collect(Collectors.toMap(NamespacePluginRelDO::getPluginId, x 
-> x));
+        StringBuilder errorMsgBuilder = new StringBuilder();
+        int successCount = 0;
+        for (NamespacePluginDTO namespacePluginDTO : namespacePluginList) {
+            String pluginId = namespacePluginDTO.getPluginId();
+            // check plugin base info
+            if (existPluginMap.containsKey(pluginId)) {
+                errorMsgBuilder
+                        .append(pluginId)
+                        .append(",");
+            } else {
+                NamespacePluginRelDO namespacePluginRelDO = 
NamespacePluginRelDO.buildNamespacePluginRelDO(namespacePluginDTO);
+                if 
(namespacePluginRelMapper.insertSelective(namespacePluginRelDO) > 0) {
+                    // publish create event. init plugin data
+                    successCount++;
+                }
+            }
+        }
+        if (StringUtils.isNotEmpty(errorMsgBuilder)) {
+            errorMsgBuilder.setLength(errorMsgBuilder.length() - 1);
+            return ConfigImportResult
+                    .fail(successCount, "import fail plugin: " + 
errorMsgBuilder);
+        }
+        return ConfigImportResult.success(successCount);
     }
     
     @Override
diff --git 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java
 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java
index 034662438a..d11abe454d 100644
--- 
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java
+++ 
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginServiceImpl.java
@@ -17,7 +17,6 @@
 
 package org.apache.shenyu.admin.service.impl;
 
-import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.MapUtils;
@@ -35,7 +34,6 @@ import org.apache.shenyu.admin.model.page.PageResultUtils;
 import org.apache.shenyu.admin.model.query.PluginQuery;
 import org.apache.shenyu.admin.model.query.PluginQueryCondition;
 import org.apache.shenyu.admin.model.result.ConfigImportResult;
-import org.apache.shenyu.admin.model.vo.PluginHandleVO;
 import org.apache.shenyu.admin.model.vo.PluginSnapshotVO;
 import org.apache.shenyu.admin.model.vo.PluginVO;
 import org.apache.shenyu.admin.service.PluginHandleService;
@@ -212,43 +210,7 @@ public class PluginServiceImpl implements PluginService {
     
     @Override
     public List<PluginVO> listAllData() {
-        // plugin handle
-        Map<String, List<PluginHandleVO>> pluginHandleMap = 
pluginHandleService.listAllData()
-                .stream()
-                .collect(Collectors.groupingBy(PluginHandleVO::getPluginId));
-
         return pluginMapper.selectAll()
-                .stream()
-                .filter(Objects::nonNull)
-                .map(pluginDO -> {
-                    PluginVO exportVO = PluginVO.buildPluginVO(pluginDO);
-                    List<PluginHandleVO> pluginHandleList = Optional
-                            
.ofNullable(pluginHandleMap.getOrDefault(exportVO.getId(), 
Lists.newArrayList()))
-                            .orElse(Lists.newArrayList())
-                            .stream()
-                            // to make less volume of export data
-                            .peek(x -> x.setDictOptions(null))
-                            .collect(Collectors.toList());
-                    exportVO.setPluginHandleList(pluginHandleList);
-                    return exportVO;
-                }).collect(Collectors.toList());
-    }
-    
-    @Override
-    public List<PluginVO> listAllDataByNamespaceId(final String namespaceId) {
-        List<NamespacePluginRelDO> pluginRelDOList = 
namespacePluginRelMapper.listByNamespaceId(namespaceId);
-        if (CollectionUtils.isEmpty(pluginRelDOList)) {
-            return Lists.newArrayList();
-        }
-        Set<String> pluginIdSet = 
pluginRelDOList.stream().map(NamespacePluginRelDO::getPluginId).collect(Collectors.toSet());
-        
-        List<PluginDO> pluginDOList = 
pluginMapper.selectByIds(Lists.newArrayList(pluginIdSet));
-        
-        if (CollectionUtils.isEmpty(pluginDOList)) {
-            return Lists.newArrayList();
-        }
-        
-        return pluginDOList
                 .stream()
                 .filter(Objects::nonNull)
                 .map(PluginVO::buildPluginVO).collect(Collectors.toList());
@@ -301,31 +263,18 @@ public class PluginServiceImpl implements PluginService {
         int successCount = 0;
         for (PluginDTO pluginDTO : pluginList) {
             String pluginName = pluginDTO.getName();
-            String pluginId;
             // check plugin base info
             if (existPluginMap.containsKey(pluginName)) {
-                PluginDO existPlugin = existPluginMap.get(pluginName);
-                pluginId = existPlugin.getId();
                 errorMsgBuilder
                         .append(pluginName)
                         .append(",");
             } else {
                 PluginDO pluginDO = PluginDO.buildPluginDO(pluginDTO);
-                pluginId = pluginDO.getId();
                 if (pluginMapper.insertSelective(pluginDO) > 0) {
                     // publish create event. init plugin data
                     successCount++;
                 }
             }
-            // check and import plugin handle
-            List<PluginHandleDTO> pluginHandleList = 
pluginDTO.getPluginHandleList();
-            if (CollectionUtils.isNotEmpty(pluginHandleList)) {
-                pluginHandleService
-                        .importData(pluginHandleList
-                                .stream()
-                                .peek(x -> x.setPluginId(pluginId))
-                                .collect(Collectors.toList()));
-            }
         }
         if (StringUtils.isNotEmpty(errorMsgBuilder)) {
             errorMsgBuilder.setLength(errorMsgBuilder.length() - 1);
diff --git 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/ConfigsServiceTest.java
 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/ConfigsServiceTest.java
index 87a3090f83..7348ab7928 100644
--- 
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/ConfigsServiceTest.java
+++ 
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/ConfigsServiceTest.java
@@ -54,6 +54,12 @@ public final class ConfigsServiceTest {
     @Mock
     private PluginService pluginService;
 
+    @Mock
+    private NamespacePluginService namespacePluginService;
+
+    @Mock
+    private PluginHandleService pluginHandleService;
+
     @Mock
     private RuleService ruleService;
 
@@ -77,7 +83,7 @@ public final class ConfigsServiceTest {
 
     @BeforeEach
     public void setUp() {
-        configsService = new ConfigsServiceImpl(appAuthService, pluginService, 
selectorService, ruleService,
+        configsService = new ConfigsServiceImpl(appAuthService, pluginService, 
namespacePluginService, pluginHandleService, selectorService, ruleService,
                 metaDataService, shenyuDictService, proxySelectorService, 
discoveryService, discoveryUpstreamService);
     }
 
diff --git 
a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/ExportImportConstants.java
 
b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/ExportImportConstants.java
index b396005fec..5d8022e93c 100644
--- 
a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/ExportImportConstants.java
+++ 
b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/ExportImportConstants.java
@@ -41,10 +41,20 @@ public final class ExportImportConstants {
      */
     public static final String PLUGIN_JSON = "plugin.json";
 
+    /**
+     * namespace plugin json config name.
+     */
+    public static final String NAMESPACE_PLUGIN_JSON = "namespace_plugin.json";
+
     /**
      * plugin template json config name.
      */
     public static final String PLUGIN_TEMPLATE_JSON = "plugin_template.json";
+    
+    /**
+     * plugin handle json config name.
+     */
+    public static final String PLUGIN_HANDLE_JSON = "proxy_handle.json";
 
     /**
      * selector json config name.

Reply via email to