This is an automated email from the ASF dual-hosted git repository. hefengen 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 e3e7b619c1 [type:fix] configs import and export refactor (#5827) e3e7b619c1 is described below commit e3e7b619c10a46a5eff7b157612db314d787a1b5 Author: eye-gu <734164...@qq.com> AuthorDate: Fri Dec 27 12:07:26 2024 +0800 [type:fix] configs import and export refactor (#5827) Co-authored-by: aias00 <liuhon...@apache.org> --- .../controller/ConfigsExportImportController.java | 8 +- .../apache/shenyu/admin/mapper/MetaDataMapper.java | 3 +- .../shenyu/admin/service/DiscoveryService.java | 4 +- .../admin/service/DiscoveryUpstreamService.java | 5 +- .../admin/service/NamespacePluginService.java | 4 +- .../shenyu/admin/service/PluginHandleService.java | 6 +- .../apache/shenyu/admin/service/PluginService.java | 13 +- .../shenyu/admin/service/ProxySelectorService.java | 4 +- .../apache/shenyu/admin/service/RuleService.java | 4 +- .../shenyu/admin/service/SelectorService.java | 4 +- .../configs/AuthConfigsExportImportHandler.java | 68 ++++++ .../service/configs/ConfigsExportImportEnum.java | 101 +++++++++ .../ConfigsExportImportHandler.java} | 30 +-- .../service/configs/ConfigsImportContext.java | 70 +++++++ .../DictDataConfigsExportImportHandler.java | 69 ++++++ .../DiscoveryDataConfigsExportImportHandler.java | 67 ++++++ ...veryUpstreamDataConfigsExportImportHandler.java | 66 ++++++ .../MetadataConfigsExportImportHandler.java | 67 ++++++ ...espacePluginDataConfigsExportImportHandler.java | 67 ++++++ ...PluginHandleDataConfigsExportImportHandler.java | 66 ++++++ ...uginTemplateDataConfigsExportImportHandler.java | 66 ++++++ ...roxySelectorDataConfigsExportImportHandler.java | 66 ++++++ .../RuleDataConfigsExportImportHandler.java | 66 ++++++ .../SelectorDataConfigsExportImportHandler.java | 67 ++++++ .../admin/service/impl/AppAuthServiceImpl.java | 14 +- .../admin/service/impl/ConfigsServiceImpl.java | 233 +++------------------ .../admin/service/impl/DiscoveryServiceImpl.java | 16 +- .../service/impl/DiscoveryUpstreamServiceImpl.java | 6 +- .../admin/service/impl/MetaDataServiceImpl.java | 10 +- .../service/impl/NamespacePluginServiceImpl.java | 10 +- .../service/impl/PluginHandleServiceImpl.java | 18 +- .../admin/service/impl/PluginServiceImpl.java | 64 +----- .../service/impl/ProxySelectorServiceImpl.java | 21 +- .../shenyu/admin/service/impl/RuleServiceImpl.java | 26 ++- .../admin/service/impl/SelectorServiceImpl.java | 29 ++- .../admin/service/impl/SyncDataServiceImpl.java | 19 +- .../main/resources/mappers/meta-data-sqlmap.xml | 1 + .../shenyu/admin/service/AppAuthServiceTest.java | 4 +- .../shenyu/admin/service/ConfigsServiceTest.java | 7 +- .../shenyu/admin/service/MetaDataServiceTest.java | 6 +- .../shenyu/admin/service/PluginServiceTest.java | 2 +- .../shenyu/admin/service/SyncDataServiceTest.java | 2 + .../common/constant/ExportImportConstants.java | 22 +- 43 files changed, 1149 insertions(+), 352 deletions(-) diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigsExportImportController.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigsExportImportController.java index 0967be80be..752ba5a5bc 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigsExportImportController.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigsExportImportController.java @@ -99,7 +99,7 @@ public class ConfigsExportImportController { throw new ShenyuException(result.getMessage()); } HttpHeaders headers = new HttpHeaders(); - String fileName = generateFileName(); + String fileName = generateFileName(namespace); response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); headers.add("Content-Disposition", "attachment;filename=" + fileName); return new ResponseEntity<>((byte[]) result.getData(), headers, HttpStatus.OK); @@ -115,6 +115,12 @@ public class ConfigsExportImportController { + ExportImportConstants.EXPORT_CONFIG_FILE_NAME_EXT; } + private String generateFileName(final String namespace) { + return ExportImportConstants.EXPORT_CONFIG_FILE_NAME + namespace + "_" + DateFormatUtils.format(new Date(), ExportImportConstants.EXPORT_CONFIG_FILE_NAME_DATE_FORMAT) + + ExportImportConstants.EXPORT_CONFIG_FILE_NAME_EXT; + } + + /** * Import configs. * diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java index e4f33fa266..f5b63d4fbf 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/MetaDataMapper.java @@ -177,9 +177,10 @@ public interface MetaDataMapper extends ExistProvider { * the path is existed. * * @param path path + * @param namespaceId namespaceId * @return existed */ - Boolean pathExisted(@Param("path") Serializable path); + Boolean pathExisted(@Param("path") Serializable path, @Param("namespaceId") String namespaceId); /** * the path is existed. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/DiscoveryService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/DiscoveryService.java index 1ffec289e1..b57571e1ed 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/DiscoveryService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/DiscoveryService.java @@ -21,6 +21,7 @@ import org.apache.shenyu.admin.model.dto.DiscoveryDTO; import org.apache.shenyu.admin.model.dto.DiscoveryHandlerDTO; import org.apache.shenyu.admin.model.result.ConfigImportResult; import org.apache.shenyu.admin.model.vo.DiscoveryVO; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.register.common.dto.DiscoveryConfigRegisterDTO; import java.util.List; @@ -131,7 +132,8 @@ public interface DiscoveryService { * * @param namespace the namespace * @param discoveryList the discovery data + * @param context import context * @return config import result */ - ConfigImportResult importData(String namespace, List<DiscoveryDTO> discoveryList); + ConfigImportResult importData(String namespace, List<DiscoveryDTO> discoveryList, ConfigsImportContext context); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/DiscoveryUpstreamService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/DiscoveryUpstreamService.java index c9828c9627..d808c194b6 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/DiscoveryUpstreamService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/DiscoveryUpstreamService.java @@ -20,6 +20,7 @@ package org.apache.shenyu.admin.service; import org.apache.shenyu.admin.model.dto.DiscoveryUpstreamDTO; import org.apache.shenyu.admin.model.result.ConfigImportResult; import org.apache.shenyu.admin.model.vo.DiscoveryUpstreamVO; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.common.dto.DiscoverySyncData; import org.apache.shenyu.common.dto.DiscoveryUpstreamData; @@ -130,7 +131,9 @@ public interface DiscoveryUpstreamService { * * @param namespace the namespace * @param discoveryUpstreamList the discoveryUpstream data + * @param context import context * @return config import result */ - ConfigImportResult importData(String namespace, List<DiscoveryUpstreamDTO> discoveryUpstreamList); + ConfigImportResult importData(String namespace, List<DiscoveryUpstreamDTO> discoveryUpstreamList, + ConfigsImportContext context); } 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 09b2164d76..2af693d294 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 @@ -25,6 +25,7 @@ import org.apache.shenyu.admin.model.result.ConfigImportResult; import org.apache.shenyu.admin.model.vo.NamespacePluginVO; import org.apache.shenyu.admin.model.vo.PluginSnapshotVO; import org.apache.shenyu.admin.model.vo.PluginVO; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.common.dto.PluginData; import java.util.List; @@ -149,9 +150,10 @@ public interface NamespacePluginService extends PageService<NamespacePluginQuery * * @param namespace the namespace * @param pluginList the plugin data + * @param context the import context * @return config import result */ - ConfigImportResult importData(String namespace, List<NamespacePluginDTO> pluginList); + ConfigImportResult importData(String namespace, List<NamespacePluginDTO> pluginList, ConfigsImportContext context); /** * List by namespace. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginHandleService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginHandleService.java index 731809ee03..c7fae887bc 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginHandleService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/PluginHandleService.java @@ -21,8 +21,9 @@ import org.apache.commons.lang3.StringUtils; import org.apache.shenyu.admin.model.dto.PluginHandleDTO; import org.apache.shenyu.admin.model.page.CommonPager; import org.apache.shenyu.admin.model.query.PluginHandleQuery; -import org.apache.shenyu.admin.model.result.ShenyuAdminResult; +import org.apache.shenyu.admin.model.result.ConfigImportResult; import org.apache.shenyu.admin.model.vo.PluginHandleVO; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import java.util.Collection; import java.util.List; @@ -108,7 +109,8 @@ public interface PluginHandleService { /** * import plugin handle list. * @param pluginHandleList the plugin handle list + * @param context the import context * @return shenyu admin result */ - ShenyuAdminResult importData(List<PluginHandleDTO> pluginHandleList); + ConfigImportResult importData(List<PluginHandleDTO> pluginHandleList, ConfigsImportContext context); } 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 ba2df965b8..13105e1e70 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 @@ -25,6 +25,7 @@ import org.apache.shenyu.admin.model.query.PluginQueryCondition; import org.apache.shenyu.admin.model.result.ConfigImportResult; import org.apache.shenyu.admin.model.vo.PluginSnapshotVO; import org.apache.shenyu.admin.model.vo.PluginVO; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.common.dto.PluginData; import java.util.List; @@ -130,16 +131,8 @@ public interface PluginService extends PageService<PluginQueryCondition, PluginV * import plugin data. * * @param pluginList the plugin data + * @param context the import context * @return config import result */ - ConfigImportResult importData(List<PluginDTO> pluginList); - - /** - * import plugin data. - * - * @param namespace the namespace - * @param pluginList the plugin data - * @return config import result - */ - ConfigImportResult importData(String namespace, List<PluginDTO> pluginList); + ConfigImportResult importData(List<PluginDTO> pluginList, ConfigsImportContext context); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/ProxySelectorService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/ProxySelectorService.java index 3a08798112..d8105d235a 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/ProxySelectorService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/ProxySelectorService.java @@ -22,6 +22,7 @@ import org.apache.shenyu.admin.model.page.CommonPager; import org.apache.shenyu.admin.model.query.ProxySelectorQuery; import org.apache.shenyu.admin.model.result.ConfigImportResult; import org.apache.shenyu.admin.model.vo.ProxySelectorVO; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.common.dto.ProxySelectorData; import java.util.List; @@ -111,7 +112,8 @@ public interface ProxySelectorService { * * @param namespace namespace * @param proxySelectorList proxy selector data list + * @param context import context * @return config import result */ - ConfigImportResult importData(String namespace, List<ProxySelectorData> proxySelectorList); + ConfigImportResult importData(String namespace, List<ProxySelectorData> proxySelectorList, ConfigsImportContext context); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java index 298db53b0b..5c759f26e8 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/RuleService.java @@ -27,6 +27,7 @@ import org.apache.shenyu.admin.model.query.RuleQuery; import org.apache.shenyu.admin.model.query.RuleQueryCondition; import org.apache.shenyu.admin.model.result.ConfigImportResult; import org.apache.shenyu.admin.model.vo.RuleVO; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.common.dto.RuleData; import org.apache.shenyu.common.enums.OperatorEnum; import org.apache.shenyu.common.enums.ParamTypeEnum; @@ -188,9 +189,10 @@ public interface RuleService extends PageService<RuleQueryCondition, RuleVO> { * * @param namespace namespace * @param ruleList rule list + * @param context import context * @return config import result */ - ConfigImportResult importData(String namespace, List<RuleDTO> ruleList); + ConfigImportResult importData(String namespace, List<RuleDTO> ruleList, ConfigsImportContext context); /** * Enabled string by ids and namespaceId. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java index 7ef4186765..a0934f5426 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/SelectorService.java @@ -25,6 +25,7 @@ import org.apache.shenyu.admin.model.query.SelectorQuery; import org.apache.shenyu.admin.model.query.SelectorQueryCondition; import org.apache.shenyu.admin.model.result.ConfigImportResult; import org.apache.shenyu.admin.model.vo.SelectorVO; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.admin.utils.Assert; import org.apache.shenyu.common.dto.SelectorData; import org.apache.shenyu.common.enums.SelectorTypeEnum; @@ -260,9 +261,10 @@ public interface SelectorService extends PageService<SelectorQueryCondition, Sel * * @param namespace the namespace * @param selectorList the plugin selector list + * @param context import context * @return config import result */ - ConfigImportResult importData(String namespace, List<SelectorDTO> selectorList); + ConfigImportResult importData(String namespace, List<SelectorDTO> selectorList, ConfigsImportContext context); /** * Enabled by ids and namespaceId. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/AuthConfigsExportImportHandler.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/AuthConfigsExportImportHandler.java new file mode 100644 index 0000000000..251738c9e0 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/AuthConfigsExportImportHandler.java @@ -0,0 +1,68 @@ +/* + * 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.shenyu.admin.service.configs; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.dto.AppAuthDTO; +import org.apache.shenyu.admin.model.result.ConfigImportResult; +import org.apache.shenyu.admin.model.vo.AppAuthVO; +import org.apache.shenyu.admin.service.AppAuthService; +import org.apache.shenyu.common.constant.ExportImportConstants; +import org.apache.shenyu.common.utils.GsonUtils; +import org.apache.shenyu.common.utils.JsonUtils; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + + +@Component +public class AuthConfigsExportImportHandler implements ConfigsExportImportHandler { + + private final AppAuthService appAuthService; + + public AuthConfigsExportImportHandler(final AppAuthService appAuthService) { + this.appAuthService = appAuthService; + } + + @Override + public ConfigsExportImportEnum configsEnum() { + return ConfigsExportImportEnum.Auth; + } + + @Override + public Optional<String> configsExport(final String namespaceId) { + List<AppAuthVO> authDataList = appAuthService.listAllDataByNamespace(namespaceId); + if (CollectionUtils.isNotEmpty(authDataList)) { + authDataList.forEach(appAuthVO -> appAuthVO.setNamespaceId(null)); + return Optional.of(JsonUtils.toJson(authDataList)); + } + return Optional.empty(); + } + + @Override + public void configsImport(final String namespaceId, final String data, final ConfigsImportContext context) { + List<AppAuthDTO> authDataList = GsonUtils.getInstance().fromList(data, AppAuthDTO.class); + ConfigImportResult configImportResult = appAuthService.importData(namespaceId, authDataList); + context.getResult().put(ExportImportConstants.AUTH_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); + if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { + context.getResult().put(ExportImportConstants.AUTH_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/ConfigsExportImportEnum.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/ConfigsExportImportEnum.java new file mode 100644 index 0000000000..7928c64f63 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/ConfigsExportImportEnum.java @@ -0,0 +1,101 @@ +/* + * 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.shenyu.admin.service.configs; + +public enum ConfigsExportImportEnum { + + /** + * auth. + */ + Auth("auth.json", 0), + + /** + * meta. + */ + Meta("meta.json", 1), + + /** + * plugin template. + */ + PluginTemplate("plugin_template.json", 2), + + /** + * plugin handle. + */ + PluginHandle("plugin_handle.json", 3), + + /** + * namespace plugin. + */ + NamespacePlugin("namespace_plugin.json", 4), + + /** + * selector. + */ + Selector("selector.json", 5), + + /** + * rule. + */ + Rule("rule.json", 6), + + /** + * dict. + */ + Dict("dict.json", 7), + + /** + * proxy selector. + */ + ProxySelector("proxy_selector.json", 8), + + /** + * discovery. + */ + Discovery("discovery.json", 9), + + /** + * discovery upstream. + */ + DiscoveryUpstream("discovery_upstream.json", 10); + + /** + * zip item name. + */ + private String configName; + + /** + * the import order. + * + * @return The smaller, the earlier it will be executed + */ + private int importOrder; + + ConfigsExportImportEnum(final String configName, final int importOrder) { + this.configName = configName; + this.importOrder = importOrder; + } + + public String getConfigName() { + return configName; + } + + public int getImportOrder() { + return importOrder; + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/provider/MetaDataPathProvider.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/ConfigsExportImportHandler.java similarity index 55% rename from shenyu-admin/src/main/java/org/apache/shenyu/admin/service/provider/MetaDataPathProvider.java rename to shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/ConfigsExportImportHandler.java index 910c678327..103a0007f5 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/provider/MetaDataPathProvider.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/ConfigsExportImportHandler.java @@ -15,28 +15,16 @@ * limitations under the License. */ -package org.apache.shenyu.admin.service.provider; +package org.apache.shenyu.admin.service.configs; -import org.apache.shenyu.admin.mapper.MetaDataMapper; -import org.apache.shenyu.admin.validation.ExistProvider; -import org.springframework.stereotype.Component; -import java.io.Serializable; +import java.util.Optional; -/** - * MetaDataPathProvider. - */ -@Component -public class MetaDataPathProvider implements ExistProvider { - - private final MetaDataMapper metaDataMapper; - - public MetaDataPathProvider(final MetaDataMapper metaDataMapper) { - this.metaDataMapper = metaDataMapper; - } - - @Override - public Boolean existed(final Serializable key) { - return metaDataMapper.pathExisted(key); - } +public interface ConfigsExportImportHandler { + + ConfigsExportImportEnum configsEnum(); + + Optional<String> configsExport(String namespaceId); + + void configsImport(String namespaceId, String data, ConfigsImportContext context); } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/ConfigsImportContext.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/ConfigsImportContext.java new file mode 100644 index 0000000000..f722ac26ee --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/ConfigsImportContext.java @@ -0,0 +1,70 @@ +/* + * 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.shenyu.admin.service.configs; + +import com.google.common.collect.Maps; + +import java.util.Map; + +public class ConfigsImportContext { + + /** + * the import result. + */ + private final Map<String, Object> result = Maps.newHashMap(); + + /** + * export selector id -> new or exist selector id. + */ + private final Map<String, String> selectorIdMapping = Maps.newHashMap(); + + /** + * export proxy selector id -> new or exist proxy selector id. + */ + private final Map<String, String> proxySelectorIdMapping = Maps.newHashMap(); + + /** + * export discovery handler id -> new or exist discovery handler id. + */ + private final Map<String, String> discoveryHandlerIdMapping = Maps.newHashMap(); + + /** + * export plugin template id -> new or exist plugin template id. + */ + private final Map<String, String> pluginTemplateIdMapping = Maps.newHashMap(); + + public Map<String, Object> getResult() { + return result; + } + + public Map<String, String> getSelectorIdMapping() { + return selectorIdMapping; + } + + public Map<String, String> getProxySelectorIdMapping() { + return proxySelectorIdMapping; + } + + public Map<String, String> getDiscoveryHandlerIdMapping() { + return discoveryHandlerIdMapping; + } + + public Map<String, String> getPluginTemplateIdMapping() { + return pluginTemplateIdMapping; + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/DictDataConfigsExportImportHandler.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/DictDataConfigsExportImportHandler.java new file mode 100644 index 0000000000..bc901f81f0 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/DictDataConfigsExportImportHandler.java @@ -0,0 +1,69 @@ +/* + * 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.shenyu.admin.service.configs; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.dto.ShenyuDictDTO; +import org.apache.shenyu.admin.model.result.ConfigImportResult; +import org.apache.shenyu.admin.model.vo.ShenyuDictVO; +import org.apache.shenyu.admin.service.ShenyuDictService; +import org.apache.shenyu.common.constant.ExportImportConstants; +import org.apache.shenyu.common.utils.GsonUtils; +import org.apache.shenyu.common.utils.JsonUtils; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component +public class DictDataConfigsExportImportHandler implements ConfigsExportImportHandler { + + /** + * The Dict service. + */ + private final ShenyuDictService shenyuDictService; + + public DictDataConfigsExportImportHandler(final ShenyuDictService shenyuDictService) { + this.shenyuDictService = shenyuDictService; + } + + @Override + public ConfigsExportImportEnum configsEnum() { + return ConfigsExportImportEnum.Dict; + } + + @Override + public Optional<String> configsExport(final String namespaceId) { + List<ShenyuDictVO> dictDataList = shenyuDictService.listAllData(); + if (CollectionUtils.isNotEmpty(dictDataList)) { + return Optional.of(JsonUtils.toJson(dictDataList)); + } + return Optional.empty(); + } + + @Override + public void configsImport(final String namespaceId, final String data, final ConfigsImportContext context) { + List<ShenyuDictDTO> dictList = GsonUtils.getInstance().fromList(data, ShenyuDictDTO.class); + ConfigImportResult configImportResult = shenyuDictService.importData(dictList); + context.getResult().put(ExportImportConstants.DICT_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); + if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { + context.getResult().put(ExportImportConstants.DICT_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/DiscoveryDataConfigsExportImportHandler.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/DiscoveryDataConfigsExportImportHandler.java new file mode 100644 index 0000000000..254aeac5f5 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/DiscoveryDataConfigsExportImportHandler.java @@ -0,0 +1,67 @@ +/* + * 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.shenyu.admin.service.configs; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.dto.DiscoveryDTO; +import org.apache.shenyu.admin.model.result.ConfigImportResult; +import org.apache.shenyu.admin.model.vo.DiscoveryVO; +import org.apache.shenyu.admin.service.DiscoveryService; +import org.apache.shenyu.common.constant.ExportImportConstants; +import org.apache.shenyu.common.utils.GsonUtils; +import org.apache.shenyu.common.utils.JsonUtils; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component +public class DiscoveryDataConfigsExportImportHandler implements ConfigsExportImportHandler { + + private final DiscoveryService discoveryService; + + public DiscoveryDataConfigsExportImportHandler(final DiscoveryService discoveryService) { + this.discoveryService = discoveryService; + } + + @Override + public ConfigsExportImportEnum configsEnum() { + return ConfigsExportImportEnum.Discovery; + } + + @Override + public Optional<String> configsExport(final String namespaceId) { + List<DiscoveryVO> discoveryList = discoveryService.listAllDataByNamespaceId(namespaceId); + if (CollectionUtils.isNotEmpty(discoveryList)) { + discoveryList.forEach(discoveryVO -> discoveryVO.setNamespaceId(null)); + return Optional.of(JsonUtils.toJson(discoveryList)); + } + return Optional.empty(); + } + + @Override + public void configsImport(final String namespaceId, final String data, final ConfigsImportContext context) { + List<DiscoveryDTO> discoveryList = GsonUtils.getInstance().fromList(data, DiscoveryDTO.class); + ConfigImportResult configImportResult = discoveryService.importData(namespaceId, discoveryList, context); + context.getResult().put(ExportImportConstants.DISCOVERY_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); + if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { + context.getResult().put(ExportImportConstants.DISCOVERY_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/DiscoveryUpstreamDataConfigsExportImportHandler.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/DiscoveryUpstreamDataConfigsExportImportHandler.java new file mode 100644 index 0000000000..8e6e260343 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/DiscoveryUpstreamDataConfigsExportImportHandler.java @@ -0,0 +1,66 @@ +/* + * 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.shenyu.admin.service.configs; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.dto.DiscoveryUpstreamDTO; +import org.apache.shenyu.admin.model.result.ConfigImportResult; +import org.apache.shenyu.admin.model.vo.DiscoveryUpstreamVO; +import org.apache.shenyu.admin.service.DiscoveryUpstreamService; +import org.apache.shenyu.common.constant.ExportImportConstants; +import org.apache.shenyu.common.utils.GsonUtils; +import org.apache.shenyu.common.utils.JsonUtils; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component +public class DiscoveryUpstreamDataConfigsExportImportHandler implements ConfigsExportImportHandler { + + private final DiscoveryUpstreamService discoveryUpstreamService; + + public DiscoveryUpstreamDataConfigsExportImportHandler(final DiscoveryUpstreamService discoveryUpstreamService) { + this.discoveryUpstreamService = discoveryUpstreamService; + } + + @Override + public ConfigsExportImportEnum configsEnum() { + return ConfigsExportImportEnum.DiscoveryUpstream; + } + + @Override + public Optional<String> configsExport(final String namespaceId) { + List<DiscoveryUpstreamVO> discoveryUpstreamList = discoveryUpstreamService.listAllDataByNamespaceId(namespaceId); + if (CollectionUtils.isNotEmpty(discoveryUpstreamList)) { + return Optional.of(JsonUtils.toJson(discoveryUpstreamList)); + } + return Optional.empty(); + } + + @Override + public void configsImport(final String namespaceId, final String data, final ConfigsImportContext context) { + List<DiscoveryUpstreamDTO> discoveryUpstreamList = GsonUtils.getInstance().fromList(data, DiscoveryUpstreamDTO.class); + ConfigImportResult configImportResult = discoveryUpstreamService.importData(namespaceId, discoveryUpstreamList, context); + context.getResult().put(ExportImportConstants.DISCOVERY_UPSTREAM_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); + if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { + context.getResult().put(ExportImportConstants.DISCOVERY_UPSTREAM_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/MetadataConfigsExportImportHandler.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/MetadataConfigsExportImportHandler.java new file mode 100644 index 0000000000..450f979c83 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/MetadataConfigsExportImportHandler.java @@ -0,0 +1,67 @@ +/* + * 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.shenyu.admin.service.configs; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.dto.MetaDataDTO; +import org.apache.shenyu.admin.model.result.ConfigImportResult; +import org.apache.shenyu.admin.model.vo.MetaDataVO; +import org.apache.shenyu.admin.service.MetaDataService; +import org.apache.shenyu.common.constant.ExportImportConstants; +import org.apache.shenyu.common.utils.GsonUtils; +import org.apache.shenyu.common.utils.JsonUtils; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component +public class MetadataConfigsExportImportHandler implements ConfigsExportImportHandler { + + private final MetaDataService metaDataService; + + public MetadataConfigsExportImportHandler(final MetaDataService metaDataService) { + this.metaDataService = metaDataService; + } + + @Override + public ConfigsExportImportEnum configsEnum() { + return ConfigsExportImportEnum.Meta; + } + + @Override + public Optional<String> configsExport(final String namespaceId) { + List<MetaDataVO> metaDataList = metaDataService.listAllDataByNamespaceId(namespaceId); + if (CollectionUtils.isNotEmpty(metaDataList)) { + metaDataList.forEach(metaDataVO -> metaDataVO.setNamespaceId(null)); + return Optional.of(JsonUtils.toJson(metaDataList)); + } + return Optional.empty(); + } + + @Override + public void configsImport(final String namespaceId, final String data, final ConfigsImportContext context) { + List<MetaDataDTO> metaDataList = GsonUtils.getInstance().fromList(data, MetaDataDTO.class); + ConfigImportResult configImportResult = metaDataService.importData(namespaceId, metaDataList); + context.getResult().put(ExportImportConstants.META_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); + if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { + context.getResult().put(ExportImportConstants.META_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/NamespacePluginDataConfigsExportImportHandler.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/NamespacePluginDataConfigsExportImportHandler.java new file mode 100644 index 0000000000..0b036b6426 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/NamespacePluginDataConfigsExportImportHandler.java @@ -0,0 +1,67 @@ +/* + * 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.shenyu.admin.service.configs; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.dto.NamespacePluginDTO; +import org.apache.shenyu.admin.model.result.ConfigImportResult; +import org.apache.shenyu.admin.model.vo.NamespacePluginVO; +import org.apache.shenyu.admin.service.NamespacePluginService; +import org.apache.shenyu.common.constant.ExportImportConstants; +import org.apache.shenyu.common.utils.GsonUtils; +import org.apache.shenyu.common.utils.JsonUtils; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component +public class NamespacePluginDataConfigsExportImportHandler implements ConfigsExportImportHandler { + + private final NamespacePluginService namespacePluginService; + + public NamespacePluginDataConfigsExportImportHandler(final NamespacePluginService namespacePluginService) { + this.namespacePluginService = namespacePluginService; + } + + @Override + public ConfigsExportImportEnum configsEnum() { + return ConfigsExportImportEnum.NamespacePlugin; + } + + @Override + public Optional<String> configsExport(final String namespaceId) { + List<NamespacePluginVO> namespacePluginVOList = namespacePluginService.listAllData(namespaceId); + if (CollectionUtils.isNotEmpty(namespacePluginVOList)) { + namespacePluginVOList.forEach(plugin -> plugin.setNamespaceId(null)); + return Optional.of(JsonUtils.toJson(namespacePluginVOList)); + } + return Optional.empty(); + } + + @Override + public void configsImport(final String namespaceId, final String data, final ConfigsImportContext context) { + List<NamespacePluginDTO> pluginList = GsonUtils.getInstance().fromList(data, NamespacePluginDTO.class); + ConfigImportResult configImportResult = namespacePluginService.importData(namespaceId, pluginList, context); + context.getResult().put(ExportImportConstants.NAMESPACE_PLUGIN_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); + if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { + context.getResult().put(ExportImportConstants.NAMESPACE_PLUGIN_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/PluginHandleDataConfigsExportImportHandler.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/PluginHandleDataConfigsExportImportHandler.java new file mode 100644 index 0000000000..e47b955748 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/PluginHandleDataConfigsExportImportHandler.java @@ -0,0 +1,66 @@ +/* + * 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.shenyu.admin.service.configs; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.dto.PluginHandleDTO; +import org.apache.shenyu.admin.model.result.ConfigImportResult; +import org.apache.shenyu.admin.model.vo.PluginHandleVO; +import org.apache.shenyu.admin.service.PluginHandleService; +import org.apache.shenyu.common.constant.ExportImportConstants; +import org.apache.shenyu.common.utils.GsonUtils; +import org.apache.shenyu.common.utils.JsonUtils; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component +public class PluginHandleDataConfigsExportImportHandler implements ConfigsExportImportHandler { + + private final PluginHandleService pluginHandleService; + + public PluginHandleDataConfigsExportImportHandler(final PluginHandleService pluginHandleService) { + this.pluginHandleService = pluginHandleService; + } + + @Override + public ConfigsExportImportEnum configsEnum() { + return ConfigsExportImportEnum.PluginHandle; + } + + @Override + public Optional<String> configsExport(final String namespaceId) { + List<PluginHandleVO> pluginHandleList = pluginHandleService.listAllData(); + if (CollectionUtils.isNotEmpty(pluginHandleList)) { + return Optional.of(JsonUtils.toJson(pluginHandleList)); + } + return Optional.empty(); + } + + @Override + public void configsImport(final String namespaceId, final String data, final ConfigsImportContext context) { + List<PluginHandleDTO> pluginHandleList = GsonUtils.getInstance().fromList(data, PluginHandleDTO.class); + ConfigImportResult configImportResult = pluginHandleService.importData(pluginHandleList, context); + context.getResult().put(ExportImportConstants.PLUGIN_HANDLE_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); + if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { + context.getResult().put(ExportImportConstants.PLUGIN_HANDLE_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/PluginTemplateDataConfigsExportImportHandler.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/PluginTemplateDataConfigsExportImportHandler.java new file mode 100644 index 0000000000..459188cdf8 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/PluginTemplateDataConfigsExportImportHandler.java @@ -0,0 +1,66 @@ +/* + * 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.shenyu.admin.service.configs; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.dto.PluginDTO; +import org.apache.shenyu.admin.model.result.ConfigImportResult; +import org.apache.shenyu.admin.model.vo.PluginVO; +import org.apache.shenyu.admin.service.PluginService; +import org.apache.shenyu.common.constant.ExportImportConstants; +import org.apache.shenyu.common.utils.GsonUtils; +import org.apache.shenyu.common.utils.JsonUtils; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component +public class PluginTemplateDataConfigsExportImportHandler implements ConfigsExportImportHandler { + + private final PluginService pluginService; + + public PluginTemplateDataConfigsExportImportHandler(final PluginService pluginService) { + this.pluginService = pluginService; + } + + @Override + public ConfigsExportImportEnum configsEnum() { + return ConfigsExportImportEnum.PluginTemplate; + } + + @Override + public Optional<String> configsExport(final String namespaceId) { + List<PluginVO> pluginDataList = pluginService.listAllData(); + if (CollectionUtils.isNotEmpty(pluginDataList)) { + return Optional.of(JsonUtils.toJson(pluginDataList)); + } + return Optional.empty(); + } + + @Override + public void configsImport(final String namespaceId, final String data, final ConfigsImportContext context) { + List<PluginDTO> pluginList = GsonUtils.getInstance().fromList(data, PluginDTO.class); + ConfigImportResult configImportResult = pluginService.importData(pluginList, context); + context.getResult().put(ExportImportConstants.PLUGIN_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); + if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { + context.getResult().put(ExportImportConstants.PLUGIN_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/ProxySelectorDataConfigsExportImportHandler.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/ProxySelectorDataConfigsExportImportHandler.java new file mode 100644 index 0000000000..9eab060b41 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/ProxySelectorDataConfigsExportImportHandler.java @@ -0,0 +1,66 @@ +/* + * 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.shenyu.admin.service.configs; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.result.ConfigImportResult; +import org.apache.shenyu.admin.service.ProxySelectorService; +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.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component +public class ProxySelectorDataConfigsExportImportHandler implements ConfigsExportImportHandler { + + private final ProxySelectorService proxySelectorService; + + public ProxySelectorDataConfigsExportImportHandler(final ProxySelectorService proxySelectorService) { + this.proxySelectorService = proxySelectorService; + } + + @Override + public ConfigsExportImportEnum configsEnum() { + return ConfigsExportImportEnum.ProxySelector; + } + + @Override + public Optional<String> configsExport(final String namespaceId) { + List<ProxySelectorData> proxySelectorDataList = proxySelectorService.listAllByNamespaceId(namespaceId); + if (CollectionUtils.isNotEmpty(proxySelectorDataList)) { + proxySelectorDataList.forEach(proxySelectorData -> proxySelectorData.setNamespaceId(null)); + return Optional.of(JsonUtils.toJson(proxySelectorDataList)); + } + return Optional.empty(); + } + + @Override + public void configsImport(final String namespaceId, final String data, final ConfigsImportContext context) { + List<ProxySelectorData> proxySelectorList = GsonUtils.getInstance().fromList(data, ProxySelectorData.class); + ConfigImportResult configImportResult = proxySelectorService.importData(namespaceId, proxySelectorList, context); + context.getResult().put(ExportImportConstants.PROXY_SELECTOR_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); + if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { + context.getResult().put(ExportImportConstants.PROXY_SELECTOR_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/RuleDataConfigsExportImportHandler.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/RuleDataConfigsExportImportHandler.java new file mode 100644 index 0000000000..192982aa43 --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/RuleDataConfigsExportImportHandler.java @@ -0,0 +1,66 @@ +/* + * 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.shenyu.admin.service.configs; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.dto.RuleDTO; +import org.apache.shenyu.admin.model.result.ConfigImportResult; +import org.apache.shenyu.admin.model.vo.RuleVO; +import org.apache.shenyu.admin.service.RuleService; +import org.apache.shenyu.common.constant.ExportImportConstants; +import org.apache.shenyu.common.utils.GsonUtils; +import org.apache.shenyu.common.utils.JsonUtils; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component +public class RuleDataConfigsExportImportHandler implements ConfigsExportImportHandler { + + private final RuleService ruleService; + + public RuleDataConfigsExportImportHandler(final RuleService ruleService) { + this.ruleService = ruleService; + } + + @Override + public ConfigsExportImportEnum configsEnum() { + return ConfigsExportImportEnum.Rule; + } + + @Override + public Optional<String> configsExport(final String namespaceId) { + List<RuleVO> ruleDataList = ruleService.listAllDataByNamespaceId(namespaceId); + if (CollectionUtils.isNotEmpty(ruleDataList)) { + return Optional.of(JsonUtils.toJson(ruleDataList)); + } + return Optional.empty(); + } + + @Override + public void configsImport(final String namespaceId, final String data, final ConfigsImportContext context) { + List<RuleDTO> ruleList = GsonUtils.getInstance().fromList(data, RuleDTO.class); + ConfigImportResult configImportResult = ruleService.importData(namespaceId, ruleList, context); + context.getResult().put(ExportImportConstants.RULE_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); + if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { + context.getResult().put(ExportImportConstants.RULE_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/SelectorDataConfigsExportImportHandler.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/SelectorDataConfigsExportImportHandler.java new file mode 100644 index 0000000000..bbf33bec1e --- /dev/null +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/SelectorDataConfigsExportImportHandler.java @@ -0,0 +1,67 @@ +/* + * 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.shenyu.admin.service.configs; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.shenyu.admin.model.dto.SelectorDTO; +import org.apache.shenyu.admin.model.result.ConfigImportResult; +import org.apache.shenyu.admin.model.vo.SelectorVO; +import org.apache.shenyu.admin.service.SelectorService; +import org.apache.shenyu.common.constant.ExportImportConstants; +import org.apache.shenyu.common.utils.GsonUtils; +import org.apache.shenyu.common.utils.JsonUtils; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +@Component +public class SelectorDataConfigsExportImportHandler implements ConfigsExportImportHandler { + + private final SelectorService selectorService; + + public SelectorDataConfigsExportImportHandler(final SelectorService selectorService) { + this.selectorService = selectorService; + } + + @Override + public ConfigsExportImportEnum configsEnum() { + return ConfigsExportImportEnum.Selector; + } + + @Override + public Optional<String> configsExport(final String namespaceId) { + List<SelectorVO> selectorDataList = selectorService.listAllDataByNamespaceId(namespaceId); + if (CollectionUtils.isNotEmpty(selectorDataList)) { + selectorDataList.forEach(selectorVO -> selectorVO.setNamespaceId(null)); + return Optional.of(JsonUtils.toJson(selectorDataList)); + } + return Optional.empty(); + } + + @Override + public void configsImport(final String namespaceId, final String data, final ConfigsImportContext context) { + List<SelectorDTO> selectorList = GsonUtils.getInstance().fromList(data, SelectorDTO.class); + ConfigImportResult configImportResult = selectorService.importData(namespaceId, selectorList, context); + context.getResult().put(ExportImportConstants.SELECTOR_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); + if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { + context.getResult().put(ExportImportConstants.SELECTOR_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); + } + } +} diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java index ee5bcb6e08..39f13ee5cd 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AppAuthServiceImpl.java @@ -248,16 +248,18 @@ public class AppAuthServiceImpl implements AppAuthService { Map<String, List<AuthParamData>> paramMap = this.prepareAuthParamData(idList); Map<String, List<AuthPathData>> pathMap = this.prepareAuthPathData(idList); - List<AppAuthData> dataList = appAuthDOList.stream() + Map<String, List<AppAuthData>> namespaceDataList = appAuthDOList.stream() .filter(Objects::nonNull) .map(appAuthDO -> { String id = appAuthDO.getId(); return buildByEntityWithParamAndPath(appAuthDO, paramMap.get(id), pathMap.get(id)); }) - .collect(Collectors.toList()); - eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.APP_AUTH, - DataEventTypeEnum.REFRESH, - dataList)); + .collect(Collectors.groupingBy(AppAuthData::getNamespaceId)); + namespaceDataList.values().forEach(dataList -> { + eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.APP_AUTH, + DataEventTypeEnum.REFRESH, + dataList)); + }); return ShenyuAdminResult.success(); } @@ -330,6 +332,7 @@ public class AppAuthServiceImpl implements AppAuthService { } @Override + @Transactional(rollbackFor = Exception.class) public ConfigImportResult importData(final String namespace, final List<AppAuthDTO> authDataList) { if (CollectionUtils.isEmpty(authDataList)) { return ConfigImportResult.success(); @@ -359,6 +362,7 @@ public class AppAuthServiceImpl implements AppAuthService { // create String authId = UUIDUtils.getInstance().generateShortUuid(); appAuthDO.setId(authId); + appAuthDO.setNamespaceId(namespace); int inserted = appAuthMapper.insertSelective(appAuthDO); if (inserted > 0) { successCount++; 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 bc2ea0f906..99842dc26a 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,7 +25,6 @@ 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; @@ -54,19 +53,23 @@ 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.service.configs.ConfigsExportImportHandler; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; 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.apache.shenyu.common.utils.ListUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; +import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Objects; /** * Implementation of the {@link org.apache.shenyu.admin.service.ConfigsService}. @@ -131,6 +134,11 @@ public class ConfigsServiceImpl implements ConfigsService { */ private final DiscoveryUpstreamService discoveryUpstreamService; + /** + * The configs export import handlers. + */ + private final List<ConfigsExportImportHandler> configsExportImportHandlers; + public ConfigsServiceImpl(final AppAuthService appAuthService, final PluginService pluginService, final NamespacePluginService namespacePluginService, @@ -141,7 +149,8 @@ public class ConfigsServiceImpl implements ConfigsService { final ShenyuDictService shenyuDictService, final ProxySelectorService proxySelectorService, final DiscoveryService discoveryService, - final DiscoveryUpstreamService discoveryUpstreamService) { + final DiscoveryUpstreamService discoveryUpstreamService, + final List<ConfigsExportImportHandler> configsExportImportHandlers) { this.appAuthService = appAuthService; this.pluginService = pluginService; this.namespacePluginService = namespacePluginService; @@ -153,6 +162,8 @@ public class ConfigsServiceImpl implements ConfigsService { this.proxySelectorService = proxySelectorService; this.discoveryService = discoveryService; this.discoveryUpstreamService = discoveryUpstreamService; + this.configsExportImportHandlers = configsExportImportHandlers.stream() + .sorted(Comparator.comparingInt(c -> c.configsEnum().getImportOrder())).toList(); } @Override @@ -182,29 +193,12 @@ public class ConfigsServiceImpl implements ConfigsService { @Override public ShenyuAdminResult configsExport(final String namespace) { List<ZipUtil.ZipItem> zipItemList = Lists.newArrayList(); - - exportAuthData(namespace, zipItemList); - - exportMetadata(namespace, zipItemList); - - exportNamespacePluginData(namespace, zipItemList); - - exportSelectorData(namespace, zipItemList); - - exportRuleData(namespace, zipItemList); - - exportDictData(zipItemList); - - exportPluginTemplateData(zipItemList); - - exportPluginHandleData(zipItemList); - - exportProxySelectorData(namespace, zipItemList); - - exportDiscoveryData(namespace, zipItemList); - - exportDiscoveryUpstreamData(namespace, zipItemList); - + + for (ConfigsExportImportHandler configsExportImportHandler : configsExportImportHandlers) { + configsExportImportHandler.configsExport(namespace) + .ifPresent(data -> zipItemList.add(new ZipUtil.ZipItem(configsExportImportHandler.configsEnum().getConfigName(), data))); + } + return ShenyuAdminResult.success(ZipUtil.zip(zipItemList)); } @@ -399,44 +393,15 @@ public class ConfigsServiceImpl implements ConfigsService { LOG.info("import file is empty"); return ShenyuAdminResult.success(); } - Map<String, Object> result = Maps.newHashMap(); - for (ZipUtil.ZipItem zipItem : zipItemList) { - switch (zipItem.getItemName()) { - case ExportImportConstants.AUTH_JSON: - importAuthData(namespace, result, zipItem); - break; - case ExportImportConstants.META_JSON: - importMetaData(namespace, result, zipItem); - break; - 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); - break; - case ExportImportConstants.RULE_JSON: - importRuleData(namespace, result, zipItem); - break; - case ExportImportConstants.DICT_JSON: - importDictData(result, zipItem); - break; - case ExportImportConstants.PROXY_SELECTOR_JSON: - importProxySelectorData(namespace, result, zipItem); - break; - case ExportImportConstants.DISCOVERY_JSON: - importDiscoveryData(namespace, result, zipItem); - break; - case ExportImportConstants.DISCOVERY_UPSTREAM_JSON: - importDiscoveryUpstreamData(namespace, result, zipItem); - break; - default: - break; + ConfigsImportContext context = new ConfigsImportContext(); + Map<String, ZipUtil.ZipItem> zipItemNameMap = ListUtil.toMap(zipItemList, ZipUtil.ZipItem::getItemName); + for (ConfigsExportImportHandler configsExportImportHandler : configsExportImportHandlers) { + ZipUtil.ZipItem zipItem = zipItemNameMap.get(configsExportImportHandler.configsEnum().getConfigName()); + if (Objects.nonNull(zipItem) && StringUtils.isNoneBlank(zipItem.getItemData())) { + configsExportImportHandler.configsImport(namespace, zipItem.getItemData(), context); } } - return ShenyuAdminResult.success(result); + return ShenyuAdminResult.success(context.getResult()); } private void importDiscoveryUpstreamData(final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { @@ -450,20 +415,6 @@ public class ConfigsServiceImpl implements ConfigsService { } } } - - private void importDiscoveryUpstreamData(final String namespace, final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { - String discoveryUpstreamJson = zipItem.getItemData(); - if (StringUtils.isNotEmpty(discoveryUpstreamJson)) { - List<DiscoveryUpstreamDTO> discoveryUpstreamList = GsonUtils.getInstance().fromList(discoveryUpstreamJson, DiscoveryUpstreamDTO.class); - // set namespaceId - discoveryUpstreamList.forEach(discoveryUpstreamDTO -> discoveryUpstreamDTO.setNamespaceId(namespace)); - ConfigImportResult configImportResult = discoveryUpstreamService.importData(namespace, discoveryUpstreamList); - result.put(ExportImportConstants.DISCOVERY_UPSTREAM_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); - if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { - result.put(ExportImportConstants.DISCOVERY_UPSTREAM_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); - } - } - } private void importDiscoveryData(final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { String discoveryJson = zipItem.getItemData(); @@ -477,20 +428,6 @@ public class ConfigsServiceImpl implements ConfigsService { } } - private void importDiscoveryData(final String namespace, final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { - String discoveryJson = zipItem.getItemData(); - if (StringUtils.isNotEmpty(discoveryJson)) { - List<DiscoveryDTO> discoveryList = GsonUtils.getInstance().fromList(discoveryJson, DiscoveryDTO.class); - // set namespaceId - discoveryList.forEach(discoveryDTO -> discoveryDTO.setNamespaceId(namespace)); - ConfigImportResult configImportResult = discoveryService.importData(namespace, discoveryList); - result.put(ExportImportConstants.DISCOVERY_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); - if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { - result.put(ExportImportConstants.DISCOVERY_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); - } - } - } - private void importProxySelectorData(final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { String proxySelectorJson = zipItem.getItemData(); if (StringUtils.isNotEmpty(proxySelectorJson)) { @@ -503,20 +440,6 @@ public class ConfigsServiceImpl implements ConfigsService { } } - private void importProxySelectorData(final String namespace, final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { - String proxySelectorJson = zipItem.getItemData(); - if (StringUtils.isNotEmpty(proxySelectorJson)) { - List<ProxySelectorData> proxySelectorList = GsonUtils.getInstance().fromList(proxySelectorJson, ProxySelectorData.class); - // set namespaceId - proxySelectorList.forEach(proxySelectorData -> proxySelectorData.setNamespaceId(namespace)); - ConfigImportResult configImportResult = proxySelectorService.importData(namespace, proxySelectorList); - result.put(ExportImportConstants.PROXY_SELECTOR_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); - if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { - result.put(ExportImportConstants.PROXY_SELECTOR_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); - } - } - } - private void importDictData(final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { String dictJson = zipItem.getItemData(); if (StringUtils.isNotEmpty(dictJson)) { @@ -541,20 +464,6 @@ public class ConfigsServiceImpl implements ConfigsService { } } - private void importRuleData(final String namespace, final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { - String ruleJson = zipItem.getItemData(); - if (StringUtils.isNotEmpty(ruleJson)) { - List<RuleDTO> ruleList = GsonUtils.getInstance().fromList(ruleJson, RuleDTO.class); - // set namespaceId - ruleList.forEach(ruleDTO -> ruleDTO.setNamespaceId(namespace)); - ConfigImportResult configImportResult = ruleService.importData(namespace, ruleList); - result.put(ExportImportConstants.RULE_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); - if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { - result.put(ExportImportConstants.RULE_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); - } - } - } - private void importSelectorData(final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { String selectorJson = zipItem.getItemData(); if (StringUtils.isNotEmpty(selectorJson)) { @@ -567,69 +476,11 @@ public class ConfigsServiceImpl implements ConfigsService { } } - private void importSelectorData(final String namespace, final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { - String selectorJson = zipItem.getItemData(); - if (StringUtils.isNotEmpty(selectorJson)) { - List<SelectorDTO> selectorList = GsonUtils.getInstance().fromList(selectorJson, SelectorDTO.class); - // set namespaceId - selectorList.forEach(selectorDTO -> selectorDTO.setNamespaceId(namespace)); - ConfigImportResult configImportResult = selectorService.importData(namespace, selectorList); - result.put(ExportImportConstants.SELECTOR_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); - if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { - result.put(ExportImportConstants.SELECTOR_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); - } - } - } - private void importPluginData(final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { String pluginJson = zipItem.getItemData(); if (StringUtils.isNotEmpty(pluginJson)) { List<PluginDTO> pluginList = GsonUtils.getInstance().fromList(pluginJson, PluginDTO.class); - ConfigImportResult configImportResult = pluginService.importData(pluginList); - 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 importPluginData(final String namespace, final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { - String pluginJson = zipItem.getItemData(); - if (StringUtils.isNotEmpty(pluginJson)) { - List<PluginDTO> pluginList = GsonUtils.getInstance().fromList(pluginJson, PluginDTO.class); - // set namespaceId - pluginList.forEach(pluginDTO -> pluginDTO.setNamespaceId(namespace)); - ConfigImportResult configImportResult = pluginService.importData(pluginList); - 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 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); + ConfigImportResult configImportResult = pluginService.importData(pluginList, null); result.put(ExportImportConstants.PLUGIN_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { result.put(ExportImportConstants.PLUGIN_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); @@ -649,20 +500,6 @@ public class ConfigsServiceImpl implements ConfigsService { } } - private void importMetaData(final String namespace, final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { - String metaJson = zipItem.getItemData(); - if (StringUtils.isNotEmpty(metaJson)) { - List<MetaDataDTO> metaDataList = GsonUtils.getInstance().fromList(metaJson, MetaDataDTO.class); - // set namespaceId - metaDataList.forEach(metaDataDTO -> metaDataDTO.setNamespaceId(namespace)); - ConfigImportResult configImportResult = metaDataService.importData(namespace, metaDataList); - result.put(ExportImportConstants.META_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); - if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { - result.put(ExportImportConstants.META_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); - } - } - } - private void importAuthData(final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { String authJson = zipItem.getItemData(); if (StringUtils.isNotEmpty(authJson)) { @@ -674,18 +511,4 @@ public class ConfigsServiceImpl implements ConfigsService { } } } - - private void importAuthData(final String namespace, final Map<String, Object> result, final ZipUtil.ZipItem zipItem) { - String authJson = zipItem.getItemData(); - if (StringUtils.isNotEmpty(authJson)) { - List<AppAuthDTO> authDataList = GsonUtils.getInstance().fromList(authJson, AppAuthDTO.class); - // set namespaceId - authDataList.forEach(appAuthDTO -> appAuthDTO.setNamespaceId(namespace)); - ConfigImportResult configImportResult = appAuthService.importData(namespace, authDataList); - result.put(ExportImportConstants.AUTH_IMPORT_SUCCESS_COUNT, configImportResult.getSuccessCount()); - if (StringUtils.isNotEmpty(configImportResult.getFailMessage())) { - result.put(ExportImportConstants.AUTH_IMPORT_FAIL_MESSAGE, configImportResult.getFailMessage()); - } - } - } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java index 24cc2a7019..5f16c1b1ed 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java @@ -44,6 +44,7 @@ import org.apache.shenyu.admin.model.vo.DiscoveryRelVO; import org.apache.shenyu.admin.model.vo.DiscoveryVO; import org.apache.shenyu.admin.service.DiscoveryService; import org.apache.shenyu.admin.service.SelectorService; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.admin.transfer.DiscoveryTransfer; import org.apache.shenyu.admin.utils.ShenyuResultMessage; import org.apache.shenyu.common.exception.ShenyuException; @@ -451,11 +452,11 @@ public class DiscoveryServiceImpl implements DiscoveryService { } @Override - public ConfigImportResult importData(final String namespace, final List<DiscoveryDTO> discoveryList) { + public ConfigImportResult importData(final String namespace, final List<DiscoveryDTO> discoveryList, final ConfigsImportContext context) { if (CollectionUtils.isEmpty(discoveryList)) { return ConfigImportResult.success(); } - + Map<String, String> discoveryHandlerIdMapping = context.getDiscoveryHandlerIdMapping(); Map<String, List<DiscoveryDO>> pluginDiscoveryMap = discoveryMapper .selectAllByNamespaceId(namespace) .stream() @@ -478,15 +479,20 @@ public class DiscoveryServiceImpl implements DiscoveryService { } String discoveryId = UUIDUtils.getInstance().generateShortUuid(); discoveryDTO.setId(discoveryId); + discoveryDTO.setNamespaceId(namespace); create(discoveryDTO); successCount++; // import discovery handler data + String discoveryHandlerId = null; if (null != discoveryDTO.getDiscoveryHandler()) { DiscoveryHandlerDO discoveryHandlerDO = DiscoveryTransfer .INSTANCE .mapToDO(discoveryDTO.getDiscoveryHandler()); discoveryHandlerDO.setDiscoveryId(discoveryId); + discoveryHandlerId = UUIDUtils.getInstance().generateShortUuid(); + discoveryHandlerIdMapping.put(discoveryHandlerDO.getId(), discoveryHandlerId); + discoveryHandlerDO.setId(discoveryHandlerId); discoveryHandlerMapper.insertSelective(discoveryHandlerDO); } @@ -495,6 +501,12 @@ public class DiscoveryServiceImpl implements DiscoveryService { DiscoveryRelDO discoveryRelDO = DiscoveryTransfer .INSTANCE .mapToDO(discoveryDTO.getDiscoveryRel()); + discoveryRelDO.setDiscoveryHandlerId(discoveryHandlerId); + Optional.ofNullable(discoveryRelDO.getSelectorId()) + .ifPresent(selectorId -> discoveryRelDO.setSelectorId(context.getSelectorIdMapping().get(selectorId))); + Optional.ofNullable(discoveryRelDO.getProxySelectorId()) + .ifPresent(proxySelectorId -> discoveryRelDO.setProxySelectorId(context.getProxySelectorIdMapping().get(proxySelectorId))); + discoveryRelDO.setId(UUIDUtils.getInstance().generateShortUuid()); discoveryRelMapper.insertSelective(discoveryRelDO); } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java index 73789d9009..c31ae18023 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java @@ -39,6 +39,7 @@ import org.apache.shenyu.admin.model.entity.SelectorDO; import org.apache.shenyu.admin.model.result.ConfigImportResult; import org.apache.shenyu.admin.model.vo.DiscoveryUpstreamVO; import org.apache.shenyu.admin.service.DiscoveryUpstreamService; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.admin.transfer.DiscoveryTransfer; import org.apache.shenyu.admin.utils.ShenyuResultMessage; import org.apache.shenyu.common.dto.DiscoverySyncData; @@ -289,10 +290,11 @@ public class DiscoveryUpstreamServiceImpl implements DiscoveryUpstreamService { } @Override - public ConfigImportResult importData(final String namespace, final List<DiscoveryUpstreamDTO> discoveryUpstreamList) { + public ConfigImportResult importData(final String namespace, final List<DiscoveryUpstreamDTO> discoveryUpstreamList, final ConfigsImportContext context) { if (CollectionUtils.isEmpty(discoveryUpstreamList)) { return ConfigImportResult.success(); } + Map<String, String> discoveryHandlerIdMapping = context.getDiscoveryHandlerIdMapping(); int successCount = 0; StringBuilder errorMsgBuilder = new StringBuilder(); Map<String, List<DiscoveryUpstreamDO>> discoveryHandlerUpstreamMap = discoveryUpstreamMapper @@ -313,7 +315,9 @@ public class DiscoveryUpstreamServiceImpl implements DiscoveryUpstreamService { .append(","); continue; } + discoveryUpstreamDTO.setNamespaceId(namespace); discoveryUpstreamDTO.setId(null); + discoveryUpstreamDTO.setDiscoveryHandlerId(discoveryHandlerIdMapping.get(discoveryUpstreamDTO.getDiscoveryHandlerId())); DiscoveryUpstreamDO discoveryUpstreamDO = DiscoveryUpstreamDO.buildDiscoveryUpstreamDO(discoveryUpstreamDTO); discoveryUpstreamMapper.insert(discoveryUpstreamDO); successCount++; diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java index 39eab5f285..75f20af13b 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/MetaDataServiceImpl.java @@ -138,7 +138,10 @@ public class MetaDataServiceImpl implements MetaDataService { public void syncData() { List<MetaDataDO> all = metaDataMapper.findAll(); if (CollectionUtils.isNotEmpty(all)) { - eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.META_DATA, DataEventTypeEnum.REFRESH, MetaDataTransfer.INSTANCE.mapToDataAll(all))); + Map<String, List<MetaDataDO>> namespaceMetaDataList = all.stream().collect(Collectors.groupingBy(MetaDataDO::getNamespaceId)); + namespaceMetaDataList.values().forEach(m -> { + eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.META_DATA, DataEventTypeEnum.REFRESH, MetaDataTransfer.INSTANCE.mapToDataAll(m))); + }); } } @@ -241,6 +244,7 @@ public class MetaDataServiceImpl implements MetaDataService { } @Override + @Transactional(rollbackFor = Exception.class) public ConfigImportResult importData(final String namespace, final List<MetaDataDTO> metaDataList) { if (CollectionUtils.isEmpty(metaDataList)) { return ConfigImportResult.success(); @@ -263,10 +267,10 @@ public class MetaDataServiceImpl implements MetaDataService { .append(","); continue; } + metaDataDTO.setNamespaceId(namespace); create(metaDataDTO); successCount++; } - this.syncData(); if (StringUtils.isNotEmpty(errorMsgBuilder)) { errorMsgBuilder.setLength(errorMsgBuilder.length() - 1); return ConfigImportResult.fail(successCount, "import fail meta: " + errorMsgBuilder); @@ -275,7 +279,7 @@ public class MetaDataServiceImpl implements MetaDataService { } private String create(final MetaDataDTO metaDataDTO) { - Assert.isNull(metaDataMapper.pathExisted(metaDataDTO.getPath()), AdminConstants.DATA_PATH_IS_EXIST); + Assert.isNull(metaDataMapper.pathExisted(metaDataDTO.getPath(), metaDataDTO.getNamespaceId()), AdminConstants.DATA_PATH_IS_EXIST); MetaDataDO metaDataDO = MetaDataTransfer.INSTANCE.mapToEntity(metaDataDTO); metaDataDO.setId(UUIDUtils.getInstance().generateShortUuid()); metaDataDO.setPathDesc(Objects.isNull(metaDataDO.getPathDesc()) ? "" : metaDataDO.getPathDesc()); 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 da1473016b..09751e5f29 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 @@ -37,12 +37,14 @@ import org.apache.shenyu.admin.model.result.ConfigImportResult; import org.apache.shenyu.admin.model.vo.NamespacePluginVO; import org.apache.shenyu.admin.model.vo.PluginSnapshotVO; import org.apache.shenyu.admin.service.NamespacePluginService; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.admin.service.publish.NamespacePluginEventPublisher; import org.apache.shenyu.admin.transfer.PluginTransfer; import org.apache.shenyu.admin.utils.ShenyuResultMessage; import org.apache.shenyu.common.constant.AdminConstants; import org.apache.shenyu.common.dto.PluginData; import org.apache.shenyu.common.utils.ListUtil; +import org.apache.shenyu.common.utils.UUIDUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -232,7 +234,8 @@ public class NamespacePluginServiceImpl implements NamespacePluginService { } @Override - public ConfigImportResult importData(final String namespace, final List<NamespacePluginDTO> namespacePluginList) { + @Transactional(rollbackFor = Exception.class) + public ConfigImportResult importData(final String namespace, final List<NamespacePluginDTO> namespacePluginList, final ConfigsImportContext context) { if (CollectionUtils.isEmpty(namespacePluginList)) { return ConfigImportResult.success(); } @@ -243,13 +246,16 @@ public class NamespacePluginServiceImpl implements NamespacePluginService { StringBuilder errorMsgBuilder = new StringBuilder(); int successCount = 0; for (NamespacePluginDTO namespacePluginDTO : namespacePluginList) { - String pluginId = namespacePluginDTO.getPluginId(); + String pluginId = context.getPluginTemplateIdMapping().get(namespacePluginDTO.getPluginId()); // check plugin base info if (existPluginMap.containsKey(pluginId)) { errorMsgBuilder .append(pluginId) .append(","); } else { + namespacePluginDTO.setId(UUIDUtils.getInstance().generateShortUuid()); + namespacePluginDTO.setNamespaceId(namespace); + namespacePluginDTO.setPluginId(pluginId); NamespacePluginRelDO namespacePluginRelDO = NamespacePluginRelDO.buildNamespacePluginRelDO(namespacePluginDTO); if (namespacePluginRelMapper.insertSelective(namespacePluginRelDO) > 0) { // publish create event. init plugin data diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginHandleServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginHandleServiceImpl.java index d89cc87bec..004faf208e 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginHandleServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/PluginHandleServiceImpl.java @@ -29,10 +29,11 @@ import org.apache.shenyu.admin.model.event.plugin.BatchPluginDeletedEvent; import org.apache.shenyu.admin.model.page.CommonPager; import org.apache.shenyu.admin.model.page.PageResultUtils; import org.apache.shenyu.admin.model.query.PluginHandleQuery; -import org.apache.shenyu.admin.model.result.ShenyuAdminResult; +import org.apache.shenyu.admin.model.result.ConfigImportResult; import org.apache.shenyu.admin.model.vo.PluginHandleVO; import org.apache.shenyu.admin.model.vo.ShenyuDictVO; import org.apache.shenyu.admin.service.PluginHandleService; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.admin.service.publish.PluginHandleEventPublisher; import org.apache.shenyu.common.utils.ListUtil; import org.slf4j.Logger; @@ -145,10 +146,10 @@ public class PluginHandleServiceImpl implements PluginHandleService { } return buildPluginHandleVO(pluginHandleDOList); } - + @Override @Transactional(rollbackFor = Exception.class) - public ShenyuAdminResult importData(final List<PluginHandleDTO> pluginHandleList) { + public ConfigImportResult importData(final List<PluginHandleDTO> pluginHandleList, final ConfigsImportContext context) { Map<String, List<PluginHandleVO>> existHandleMap = listAllData() .stream() .filter(Objects::nonNull) @@ -158,9 +159,10 @@ public class PluginHandleServiceImpl implements PluginHandleService { .filter(Objects::nonNull) .collect(Collectors.groupingBy(PluginHandleDTO::getPluginId)); + int successCount = 0; for (Map.Entry<String, List<PluginHandleDTO>> pluginHandleEntry : importHandleMap.entrySet()) { // pluginId - String pluginId = pluginHandleEntry.getKey(); + String pluginId = context.getPluginTemplateIdMapping().get(pluginHandleEntry.getKey()); List<PluginHandleDTO> handles = pluginHandleEntry.getValue(); if (CollectionUtils.isNotEmpty(handles)) { if (existHandleMap.containsKey(pluginId)) { @@ -171,19 +173,23 @@ public class PluginHandleServiceImpl implements PluginHandleService { .collect(Collectors.toSet()); for (PluginHandleDTO handle : handles) { if (!handleFiledMap.contains(handle.getField())) { + handle.setPluginId(pluginId); create(handle); + successCount++; } } } else { for (PluginHandleDTO handle : handles) { + handle.setPluginId(pluginId); create(handle); + successCount++; } } } } - return ShenyuAdminResult.success(); + return ConfigImportResult.success(successCount); } - + /** * The associated Handle needs to be deleted synchronously. * 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 d11abe454d..b8675d3619 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,16 +17,12 @@ package org.apache.shenyu.admin.service.impl; -import com.google.common.collect.Maps; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.shenyu.admin.aspect.annotation.Pageable; import org.apache.shenyu.admin.mapper.NamespacePluginRelMapper; import org.apache.shenyu.admin.mapper.PluginMapper; import org.apache.shenyu.admin.model.dto.PluginDTO; -import org.apache.shenyu.admin.model.dto.PluginHandleDTO; -import org.apache.shenyu.admin.model.entity.NamespacePluginRelDO; import org.apache.shenyu.admin.model.entity.PluginDO; import org.apache.shenyu.admin.model.event.plugin.PluginCreatedEvent; import org.apache.shenyu.admin.model.page.CommonPager; @@ -38,6 +34,7 @@ import org.apache.shenyu.admin.model.vo.PluginSnapshotVO; import org.apache.shenyu.admin.model.vo.PluginVO; import org.apache.shenyu.admin.service.PluginHandleService; import org.apache.shenyu.admin.service.PluginService; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.admin.service.publish.PluginEventPublisher; import org.apache.shenyu.admin.transfer.PluginTransfer; import org.apache.shenyu.admin.utils.Assert; @@ -50,6 +47,7 @@ import org.apache.shenyu.common.exception.ShenyuException; import org.apache.shenyu.common.utils.JarDependencyUtils; import org.apache.shenyu.common.utils.ListUtil; import org.apache.shenyu.common.utils.LogUtils; +import org.apache.shenyu.common.utils.UUIDUtils; import org.opengauss.util.Base64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -251,7 +249,7 @@ public class PluginServiceImpl implements PluginService { @Override @Transactional(rollbackFor = Exception.class) - public ConfigImportResult importData(final List<PluginDTO> pluginList) { + public ConfigImportResult importData(final List<PluginDTO> pluginList, final ConfigsImportContext context) { if (CollectionUtils.isEmpty(pluginList)) { return ConfigImportResult.success(); } @@ -268,7 +266,11 @@ public class PluginServiceImpl implements PluginService { errorMsgBuilder .append(pluginName) .append(","); + Optional.ofNullable(context).ifPresent(c -> c.getPluginTemplateIdMapping().put(pluginDTO.getId(), existPluginMap.get(pluginName).getId())); } else { + String pluginId = UUIDUtils.getInstance().generateShortUuid(); + Optional.ofNullable(context).ifPresent(c -> c.getPluginTemplateIdMapping().put(pluginDTO.getId(), pluginId)); + pluginDTO.setId(pluginId); PluginDO pluginDO = PluginDO.buildPluginDO(pluginDTO); if (pluginMapper.insertSelective(pluginDO) > 0) { // publish create event. init plugin data @@ -284,58 +286,6 @@ public class PluginServiceImpl implements PluginService { return ConfigImportResult.success(successCount); } - @Override - public ConfigImportResult importData(final String namespace, final List<PluginDTO> pluginList) { - if (CollectionUtils.isEmpty(pluginList)) { - return ConfigImportResult.success(); - } - List<NamespacePluginRelDO> pluginRelDOList = namespacePluginRelMapper.listByNamespaceId(namespace); - Map<String, PluginDO> existPluginMap = Maps.newHashMap(); - if (CollectionUtils.isNotEmpty(pluginRelDOList)) { - List<String> pluginIds = pluginRelDOList.stream().map(NamespacePluginRelDO::getPluginId).distinct().collect(Collectors.toList()); - existPluginMap = pluginMapper.selectByIds(pluginIds) - .stream() - .filter(Objects::nonNull) - .collect(Collectors.toMap(PluginDO::getName, x -> x)); - } - StringBuilder errorMsgBuilder = new StringBuilder(); - int successCount = 0; - for (PluginDTO pluginDTO : pluginList) { - String pluginName = pluginDTO.getName(); - String pluginId; - // check plugin base info - if (MapUtils.isNotEmpty(existPluginMap) && 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); - return ConfigImportResult - .fail(successCount, "import fail plugin: " + errorMsgBuilder); - } - return ConfigImportResult.success(successCount); - } - /** * create plugin.<br> * insert plugin and insert plugin data. diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ProxySelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ProxySelectorServiceImpl.java index df7e5aaaf4..6272cc1480 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ProxySelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/ProxySelectorServiceImpl.java @@ -46,6 +46,7 @@ import org.apache.shenyu.admin.model.result.ConfigImportResult; import org.apache.shenyu.admin.model.vo.DiscoveryUpstreamVO; import org.apache.shenyu.admin.model.vo.ProxySelectorVO; import org.apache.shenyu.admin.service.ProxySelectorService; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.admin.transfer.DiscoveryTransfer; import org.apache.shenyu.admin.utils.ShenyuResultMessage; import org.apache.shenyu.common.dto.ProxySelectorData; @@ -498,13 +499,14 @@ public class ProxySelectorServiceImpl implements ProxySelectorService { } @Override - public ConfigImportResult importData(final String namespace, final List<ProxySelectorData> proxySelectorList) { + public ConfigImportResult importData(final String namespace, final List<ProxySelectorData> proxySelectorList, + final ConfigsImportContext context) { if (CollectionUtils.isEmpty(proxySelectorList)) { return ConfigImportResult.success(); } - // TODO namespace + Map<String, String> proxySelectorIdMapping = context.getProxySelectorIdMapping(); Map<String, List<ProxySelectorDO>> pluginProxySelectorMap = proxySelectorMapper - .selectAll() + .selectByNamespaceId(namespace) .stream() .collect(Collectors.groupingBy(ProxySelectorDO::getPluginName)); int successCount = 0; @@ -512,20 +514,25 @@ public class ProxySelectorServiceImpl implements ProxySelectorService { for (ProxySelectorData selectorData : proxySelectorList) { String pluginName = selectorData.getPluginName(); String proxySelectorName = selectorData.getName(); - Set<String> existProxySelectorNameSet = pluginProxySelectorMap + Map<String, String> existProxySelectorNameSet = pluginProxySelectorMap .getOrDefault(pluginName, Lists.newArrayList()) .stream() - .map(ProxySelectorDO::getName) - .collect(Collectors.toSet()); + .collect(Collectors.toMap(ProxySelectorDO::getName, ProxySelectorDO::getId)); - if (existProxySelectorNameSet.contains(proxySelectorName)) { + if (existProxySelectorNameSet.containsKey(proxySelectorName)) { errorMsgBuilder .append(proxySelectorName) .append(","); + proxySelectorIdMapping.put(selectorData.getId(), existProxySelectorNameSet.get(proxySelectorName)); continue; } + String oldProxySelectorId = selectorData.getId(); + String newProxySelectorId = UUIDUtils.getInstance().generateShortUuid(); + selectorData.setId(newProxySelectorId); + selectorData.setNamespaceId(namespace); ProxySelectorDO proxySelectorDO = ProxySelectorDO.buildProxySelectorDO(selectorData); if (proxySelectorMapper.insert(proxySelectorDO) > 0) { + proxySelectorIdMapping.put(oldProxySelectorId, newProxySelectorId); successCount++; } } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java index aa012c07e0..7426e17b95 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/RuleServiceImpl.java @@ -43,6 +43,7 @@ import org.apache.shenyu.admin.model.result.ConfigImportResult; import org.apache.shenyu.admin.model.vo.RuleConditionVO; import org.apache.shenyu.admin.model.vo.RuleVO; import org.apache.shenyu.admin.service.RuleService; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.admin.service.publish.RuleEventPublisher; import org.apache.shenyu.admin.transfer.ConditionTransfer; import org.apache.shenyu.admin.utils.Assert; @@ -53,6 +54,7 @@ import org.apache.shenyu.common.dto.RuleData; import org.apache.shenyu.common.enums.MatchModeEnum; import org.apache.shenyu.common.utils.JsonUtils; import org.apache.shenyu.common.utils.ListUtil; +import org.apache.shenyu.common.utils.UUIDUtils; import org.springframework.context.event.EventListener; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -302,11 +304,12 @@ public class RuleServiceImpl implements RuleService { } @Override - public ConfigImportResult importData(final String namespace, final List<RuleDTO> ruleList) { + @Transactional(rollbackFor = Exception.class) + public ConfigImportResult importData(final String namespace, final List<RuleDTO> ruleList, final ConfigsImportContext context) { if (CollectionUtils.isEmpty(ruleList)) { return ConfigImportResult.success(); } - + Map<String, String> selectorIdMapping = context.getSelectorIdMapping(); Map<String, List<RuleDO>> selectorRuleMap = ruleMapper .selectAllByNamespaceId(namespace) .stream() @@ -317,8 +320,16 @@ public class RuleServiceImpl implements RuleService { for (RuleDTO ruleDTO : ruleList) { String selectorId = ruleDTO.getSelectorId(); String ruleName = ruleDTO.getName(); + + String newSelectorId = selectorIdMapping.get(selectorId); + if (Objects.isNull(newSelectorId)) { + errorMsgBuilder + .append(ruleName) + .append(","); + continue; + } Set<String> existRuleNameSet = selectorRuleMap - .getOrDefault(selectorId, Lists.newArrayList()) + .getOrDefault(newSelectorId, Lists.newArrayList()) .stream() .map(RuleDO::getName) .collect(Collectors.toSet()); @@ -329,8 +340,17 @@ public class RuleServiceImpl implements RuleService { .append(","); continue; } + ruleDTO.setNamespaceId(namespace); + ruleDTO.setSelectorId(newSelectorId); + String ruleId = UUIDUtils.getInstance().generateShortUuid(); + ruleDTO.setId(ruleId); RuleDO ruleDO = RuleDO.buildRuleDO(ruleDTO); final int ruleCount = ruleMapper.insertSelective(ruleDO); + Optional.ofNullable(ruleDTO.getRuleConditions()) + .orElse(Collections.emptyList()).forEach(c -> { + c.setRuleId(ruleId); + c.setId(null); + }); addCondition(ruleDO, ruleDTO.getRuleConditions()); if (ruleCount > 0) { successCount++; diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java index e1a6bae006..11abc1a77b 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java @@ -58,6 +58,7 @@ import org.apache.shenyu.admin.model.vo.DiscoveryVO; import org.apache.shenyu.admin.model.vo.SelectorConditionVO; import org.apache.shenyu.admin.model.vo.SelectorVO; import org.apache.shenyu.admin.service.SelectorService; +import org.apache.shenyu.admin.service.configs.ConfigsImportContext; import org.apache.shenyu.admin.service.publish.SelectorEventPublisher; import org.apache.shenyu.admin.transfer.ConditionTransfer; import org.apache.shenyu.admin.transfer.DiscoveryTransfer; @@ -73,6 +74,7 @@ import org.apache.shenyu.common.enums.SelectorTypeEnum; import org.apache.shenyu.common.utils.ContextPathUtils; import org.apache.shenyu.common.utils.JsonUtils; import org.apache.shenyu.common.utils.ListUtil; +import org.apache.shenyu.common.utils.UUIDUtils; import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.event.EventListener; @@ -495,10 +497,12 @@ public class SelectorServiceImpl implements SelectorService { } @Override - public ConfigImportResult importData(final String namespace, final List<SelectorDTO> selectorList) { + @Transactional(rollbackFor = Exception.class) + public ConfigImportResult importData(final String namespace, final List<SelectorDTO> selectorList, final ConfigsImportContext context) { if (CollectionUtils.isEmpty(selectorList)) { return ConfigImportResult.success(); } + Map<String, String> selectorIdMapping = context.getSelectorIdMapping(); StringBuilder errorMsgBuilder = new StringBuilder(); int successCount = 0; Map<String, List<SelectorDO>> pluginSelectorMap = selectorMapper.selectAllByNamespaceId(namespace).stream() @@ -510,26 +514,37 @@ public class SelectorServiceImpl implements SelectorService { for (Map.Entry<String, List<SelectorDTO>> selectorEntry : importSelectorMap.entrySet()) { // the import selector's pluginId - String pluginId = selectorEntry.getKey(); + String pluginId = context.getPluginTemplateIdMapping().get(selectorEntry.getKey()); List<SelectorDTO> selectorDTOList = selectorEntry.getValue(); if (CollectionUtils.isNotEmpty(selectorDTOList)) { - Set<String> existSelectorSet = Optional + Map<String, String> existSelectorSet = Optional .ofNullable(pluginSelectorMap.get(pluginId)) .orElseGet(Lists::newArrayList) .stream() - .map(SelectorDO::getName) - .collect(Collectors.toSet()); + .collect(Collectors.toMap(SelectorDO::getName, SelectorDO::getId)); for (SelectorDTO selectorDTO : selectorDTOList) { // filter by selectorName String selectorName = selectorDTO.getName(); - if (CollectionUtils.isNotEmpty(existSelectorSet) - && existSelectorSet.contains(selectorName)) { + if (MapUtils.isNotEmpty(existSelectorSet) + && existSelectorSet.containsKey(selectorName)) { errorMsgBuilder .append(selectorName) .append(","); + selectorIdMapping.put(selectorDTO.getId(), existSelectorSet.get(selectorName)); } else { + // gen new id + String selectorId = UUIDUtils.getInstance().generateShortUuid(); + selectorIdMapping.put(selectorDTO.getId(), selectorId); + selectorDTO.setId(selectorId); + selectorDTO.setNamespaceId(namespace); + selectorDTO.setPluginId(pluginId); + Optional.ofNullable(selectorDTO.getSelectorConditions()) + .orElse(Collections.emptyList()).forEach(c -> { + c.setSelectorId(selectorId); + c.setId(null); + }); create(selectorDTO); successCount++; } diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java index f6d21a785b..44e7c4750c 100644 --- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java +++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SyncDataServiceImpl.java @@ -42,6 +42,7 @@ import org.springframework.stereotype.Service; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; @@ -108,13 +109,25 @@ public class SyncDataServiceImpl implements SyncDataService { appAuthService.syncData(); List<PluginData> pluginDataList = namespacePluginService.listAll(); - eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.PLUGIN, type, pluginDataList)); + Map<String, List<PluginData>> namespacePluginDataList = + pluginDataList.stream().collect(Collectors.groupingBy(PluginData::getNamespaceId)); + namespacePluginDataList.values().forEach(p -> { + eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.PLUGIN, type, p)); + }); List<SelectorData> selectorDataList = selectorService.listAll(); - eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.SELECTOR, type, selectorDataList)); + Map<String, List<SelectorData>> namespaceSelectorDataList = + selectorDataList.stream().collect(Collectors.groupingBy(SelectorData::getNamespaceId)); + namespaceSelectorDataList.values().forEach(s -> { + eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.SELECTOR, type, s)); + }); List<RuleData> ruleDataList = ruleService.listAll(); - eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.RULE, type, ruleDataList)); + Map<String, List<RuleData>> namespaceRuleDataList = + ruleDataList.stream().collect(Collectors.groupingBy(RuleData::getNamespaceId)); + namespaceRuleDataList.values().forEach(r -> { + eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.RULE, type, r)); + }); metaDataService.syncData(); discoveryService.syncData(); diff --git a/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml b/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml index 91a2fb6edb..6f73e725d7 100644 --- a/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml +++ b/shenyu-admin/src/main/resources/mappers/meta-data-sqlmap.xml @@ -148,6 +148,7 @@ SElECT true FROM meta_data WHERE path = #{path} + AND namespace_id = #{namespaceId} LIMIT 1 </select> diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/AppAuthServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/AppAuthServiceTest.java index a7465afc54..114126e1c4 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/AppAuthServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/AppAuthServiceTest.java @@ -258,7 +258,9 @@ public final class AppAuthServiceTest { @Test public void testSyncData() { - ArrayList<AppAuthDO> all = Lists.newArrayList(new AppAuthDO()); + AppAuthDO authDO = new AppAuthDO(); + authDO.setNamespaceId("test"); + ArrayList<AppAuthDO> all = Lists.newArrayList(authDO); when(appAuthMapper.selectAll()) .thenReturn(null) .thenReturn(Lists.newArrayList()) 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 7348ab7928..b8023af730 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 @@ -27,10 +27,10 @@ import org.apache.shenyu.common.exception.CommonErrorCode; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -45,7 +45,6 @@ import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) public final class ConfigsServiceTest { - @InjectMocks private ConfigsServiceImpl configsService; @Mock @@ -84,7 +83,7 @@ public final class ConfigsServiceTest { @BeforeEach public void setUp() { configsService = new ConfigsServiceImpl(appAuthService, pluginService, namespacePluginService, pluginHandleService, selectorService, ruleService, - metaDataService, shenyuDictService, proxySelectorService, discoveryService, discoveryUpstreamService); + metaDataService, shenyuDictService, proxySelectorService, discoveryService, discoveryUpstreamService, Collections.emptyList()); } @Test @@ -102,7 +101,7 @@ public final class ConfigsServiceTest { when(this.metaDataService.importData(any())).thenReturn( ConfigImportResult.success(1)); - when(this.pluginService.importData(any())).thenReturn( + when(this.pluginService.importData(any(), any())).thenReturn( ConfigImportResult.success(1)); when(this.selectorService.importData(any())).thenReturn( diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java index fe2fe759b2..0860090dff 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/MetaDataServiceTest.java @@ -158,7 +158,7 @@ public final class MetaDataServiceTest { */ @Test public void testSyncDate() { - ArrayList<MetaDataDO> all = Lists.newArrayList(MetaDataDO.builder().build()); + ArrayList<MetaDataDO> all = Lists.newArrayList(MetaDataDO.builder().namespaceId("test").build()); when(metaDataMapper.findAll()) .thenReturn(null) .thenReturn(Lists.newArrayList()) @@ -256,7 +256,7 @@ public final class MetaDataServiceTest { final List<MetaDataDTO> metaDataDTOList = getMetaDataDTOList(); given(this.metaDataMapper.insert(any())).willReturn(1); - given(this.metaDataMapper.pathExisted(any())).willReturn(null); + given(this.metaDataMapper.pathExisted(any(), any())).willReturn(null); ConfigImportResult configImportResult = this.metaDataService.importData(metaDataDTOList); @@ -324,7 +324,7 @@ public final class MetaDataServiceTest { private void testCreateOrUpdateForInsert() { when(metaDataDTO.getId()).thenReturn(null); when(metaDataMapper.insert(any())).thenReturn(1); - when(metaDataMapper.pathExisted(any())).thenReturn(null); + when(metaDataMapper.pathExisted(any(), any())).thenReturn(null); String msg = metaDataService.createOrUpdate(metaDataDTO); assertEquals(ShenyuResultMessage.CREATE_SUCCESS, msg); } diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginServiceTest.java index a1b9ec1081..531d779b7d 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/PluginServiceTest.java @@ -200,7 +200,7 @@ public final class PluginServiceTest { when(pluginMapper.nameExisted(pluginDTO.getName())).thenReturn(null); when(pluginMapper.insert(any())).thenReturn(1); - ConfigImportResult configImportResult = this.pluginService.importData(pluginDTOList); + ConfigImportResult configImportResult = this.pluginService.importData(pluginDTOList, null); assertNotNull(configImportResult); Assertions.assertEquals(configImportResult.getSuccessCount(), pluginDTOList.size()); diff --git a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SyncDataServiceTest.java b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SyncDataServiceTest.java index 351002c96f..60cafb9abe 100644 --- a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SyncDataServiceTest.java +++ b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/SyncDataServiceTest.java @@ -154,6 +154,7 @@ public final class SyncDataServiceTest { selectorData.setPluginName("divide"); selectorData.setSort(1); selectorData.setType(1); + selectorData.setNamespaceId("test"); ConditionData conditionData = new ConditionData(); conditionData.setParamType(ParamTypeEnum.POST.getName()); conditionData.setOperator(OperatorEnum.EQ.getAlias()); @@ -179,6 +180,7 @@ public final class SyncDataServiceTest { ruleData.setPluginName("divide"); ruleData.setSelectorId("1"); ruleData.setSort(1); + ruleData.setNamespaceId("test"); ConditionData conditionData = new ConditionData(); conditionData.setParamType(ParamTypeEnum.POST.getName()); conditionData.setOperator(OperatorEnum.EQ.getAlias()); 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 5d8022e93c..830cf02c4c 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 @@ -54,7 +54,7 @@ public final class ExportImportConstants { /** * plugin handle json config name. */ - public static final String PLUGIN_HANDLE_JSON = "proxy_handle.json"; + public static final String PLUGIN_HANDLE_JSON = "plugin_handle.json"; /** * selector json config name. @@ -101,11 +101,31 @@ public final class ExportImportConstants { */ public static final String PLUGIN_IMPORT_SUCCESS_COUNT = "pluginImportSuccessCount"; + /** + * plugin handle import success count. + */ + public static final String PLUGIN_HANDLE_IMPORT_SUCCESS_COUNT = "pluginHandleImportSuccessCount"; + + /** + * namespace plugin import success count. + */ + public static final String NAMESPACE_PLUGIN_IMPORT_SUCCESS_COUNT = "namespacePluginImportSuccessCount"; + /** * plugin import fail message. */ public static final String PLUGIN_IMPORT_FAIL_MESSAGE = "pluginImportFailMessage"; + /** + * plugin handle import fail message. + */ + public static final String PLUGIN_HANDLE_IMPORT_FAIL_MESSAGE = "pluginHandleImportFailMessage"; + + /** + * namespace plugin import fail message. + */ + public static final String NAMESPACE_PLUGIN_IMPORT_FAIL_MESSAGE = "pluginHandleImportFailMessage"; + /** * selector import success count. */