Skip to content

Commit

Permalink
[type:feature] namespace config import (#5771)
Browse files Browse the repository at this point in the history
* [type:feature] namespace config import

* [type:feature] namespace config import export

* [type:feature] namespace config import export

* [type:feature] namespace config import export

* [type:feature] namespace config import export

* [type:feature] namespace import\export

* [type:feature] namespace import\export

* [type:feature] namespace import\export
  • Loading branch information
Aias00 authored Nov 25, 2024
1 parent a290e73 commit 841d142
Show file tree
Hide file tree
Showing 32 changed files with 1,056 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.shenyu.admin.controller;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.shenyu.admin.aspect.annotation.RestApi;
import org.apache.shenyu.admin.model.result.ShenyuAdminResult;
Expand Down Expand Up @@ -83,6 +84,27 @@ public ResponseEntity<byte[]> exportConfigs(final HttpServletResponse response)
return new ResponseEntity<>((byte[]) result.getData(), headers, HttpStatus.OK);
}

/**
* Export all configs.
*
* @param namespace namespaceId
* @param response response
* @return the shenyu result
*/
@GetMapping("/exportByNamespace")
@RequiresPermissions("system:manager:exportConfig")
public ResponseEntity<byte[]> exportConfigsByNamespace(final String namespace, final HttpServletResponse response) {
ShenyuAdminResult result = configsService.configsExport(namespace);
if (!Objects.equals(CommonErrorCode.SUCCESSFUL, result.getCode())) {
throw new ShenyuException(result.getMessage());
}
HttpHeaders headers = new HttpHeaders();
String fileName = generateFileName();
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
headers.add("Content-Disposition", "attachment;filename=" + fileName);
return new ResponseEntity<>((byte[]) result.getData(), headers, HttpStatus.OK);
}

/**
* generate export file name.
*
Expand All @@ -96,17 +118,18 @@ private String generateFileName() {
/**
* Import configs.
*
* @param namespace namespace
* @param file config file
* @return shenyu admin result
*/
@PostMapping("/import")
@RequiresPermissions("system:manager:importConfig")
public ShenyuAdminResult importConfigs(final MultipartFile file) {
if (Objects.isNull(file)) {
public ShenyuAdminResult importConfigs(final String namespace, final MultipartFile file) {
if (StringUtils.isBlank(namespace) || Objects.isNull(file)) {
return ShenyuAdminResult.error(ShenyuResultMessage.PARAMETER_ERROR);
}
try {
ShenyuAdminResult importResult = configsService.configsImport(file.getBytes());
ShenyuAdminResult importResult = configsService.configsImport(namespace, file.getBytes());
if (Objects.equals(CommonErrorCode.SUCCESSFUL, importResult.getCode())) {
// sync data
syncDataService.syncAll(DataEventTypeEnum.REFRESH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.shenyu.admin.validation.ExistProvider;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
Expand Down Expand Up @@ -111,6 +112,14 @@ public interface DiscoveryHandlerMapper extends ExistProvider {
*/
List<DiscoveryHandlerDO> selectByDiscoveryId(@Param("discoveryId")String discoveryId);

/**
* selectByDiscoveryIds.
*
* @param discoveryIds discoveryIds
* @return DiscoveryHandlerDO list
*/
List<DiscoveryHandlerDO> selectByDiscoveryIds(@Param("discoveryIds")Collection<String> discoveryIds);

/**
* selectBySelectorId.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ public interface DiscoveryUpstreamMapper extends ExistProvider {
*/
List<DiscoveryUpstreamDO> selectBySelectorId(@Param("selectorId") String selectorId);


/**
* selectByNamespaceId.
*
* @param namespaceId namespaceId
* @return DiscoveryUpstreamDO list
*/
List<DiscoveryUpstreamDO> selectByNamespaceId(String namespaceId);

/**
* selectByDiscoveryHandlerId.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public interface NamespacePluginRelMapper extends ExistProvider {
* @return {@linkplain List}
*/
List<NamespacePluginVO> selectAllByNamespaceId(String namespaceId);

/**
* select all by namespaceId list.
* select all by namespaceIds.
*
* @param namespaceIds namespaceIds.
* @return {@linkplain List}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.shenyu.admin.validation.ExistProvider;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
Expand Down Expand Up @@ -139,6 +140,15 @@ public interface PluginHandleMapper extends ExistProvider {
*/
List<PluginHandleDO> selectByPluginIdList(@Param("pluginIds") List<String> pluginId);


/**
* bach delete by idList.
*
* @param pluginIds a list of ids
* @return plugin handle list
*/
List<PluginHandleDO> selectByPluginIds(@Param("pluginIds") Collection<String> pluginIds);

/**
* delete string id.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,12 @@ public interface ProxySelectorMapper extends ExistProvider {
*/
List<ProxySelectorDO> selectAll();

/**
* selectAllByNamespaceId.
*
* @param namespaceId namespaceId
* @return ProxySelectorDOList
*/
List<ProxySelectorDO> selectByNamespaceId(String namespaceId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ public interface AppAuthService extends PageService<AppAuthQuery, AppAuthVO> {
*/
List<AppAuthVO> listAllData();

/**
* List all vo list.
*
* @param namespace the namespace
* @return the vo list
*/
List<AppAuthVO> listAllDataByNamespace(String namespace);

/**
* Update app secret by app key shenyu result.
*
Expand Down Expand Up @@ -182,9 +190,20 @@ public interface AppAuthService extends PageService<AppAuthQuery, AppAuthVO> {

/**
* Import shenyu auth data.
*
* @param authDataList app auth list
* @return the config import result
*/
ConfigImportResult importData(List<AppAuthDTO> authDataList);


/**
* Import shenyu auth data.
*
* @param namespace the namespace
* @param authDataList app auth list
* @return the config import result
*/
ConfigImportResult importData(String namespace, List<AppAuthDTO> authDataList);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,34 @@ public interface ConfigsService {

/**
* Export all configs.
*
* @return shenyu admin result
*/
ShenyuAdminResult configsExport();

/**
* Export all configs.
*
* @param namespace namespace
* @return shenyu admin result
*/
ShenyuAdminResult configsExport(String namespace);

/**
* Import configs.
*
* @param source configs
* @return shenyu admin result
*/
ShenyuAdminResult configsImport(byte[] source);

/**
* Import configs.
*
* @param namespace namespace
* @param source configs
* @return shenyu admin result
*/
ShenyuAdminResult configsImport(String namespace, byte[] source);

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,19 @@ public interface DiscoveryService {

/**
* list all vo.
*
* @return discovery vo
*/
List<DiscoveryVO> listAllData();

/**
* list all vo.
*
* @param namespaceId namespaceId
* @return discovery vo
*/
List<DiscoveryVO> listAllDataByNamespaceId(String namespaceId);

/**
* findDiscoveryHandlerBySelectorId.
*
Expand All @@ -111,8 +120,18 @@ public interface DiscoveryService {

/**
* Import discovery data list.
*
* @param discoveryList the discovery data
* @return config import result
*/
ConfigImportResult importData(List<DiscoveryDTO> discoveryList);

/**
* Import discovery data list.
*
* @param namespace the namespace
* @param discoveryList the discovery data
* @return config import result
*/
ConfigImportResult importData(String namespace, List<DiscoveryDTO> discoveryList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public interface DiscoveryUpstreamService {
*/
List<DiscoveryUpstreamVO> listAllData();

/**
* list all data.
*
* @param namespaceId namespaceId
* @return DiscoveryUpstreamVO
*/
List<DiscoveryUpstreamVO> listAllDataByNamespaceId(String namespaceId);

/**
* refresh and push event.
*
Expand Down Expand Up @@ -111,8 +119,18 @@ public interface DiscoveryUpstreamService {

/**
* Import the discoveryUpstream data list.
*
* @param discoveryUpstreamList the discoveryUpstream data
* @return config import result
*/
ConfigImportResult importData(List<DiscoveryUpstreamDTO> discoveryUpstreamList);

/**
* Import the discoveryUpstream data list.
*
* @param namespace the namespace
* @param discoveryUpstreamList the discoveryUpstream data
* @return config import result
*/
ConfigImportResult importData(String namespace, List<DiscoveryUpstreamDTO> discoveryUpstreamList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ public interface MetaDataService {
*/
List<MetaDataVO> listAllData();

/**
* List all vo list.
*
* @param namespaceId the namespaceId
* @return the vo list
*/
List<MetaDataVO> listAllDataByNamespaceId(String namespaceId);

/**
* Enabled by ids and namespaceId.
*
Expand Down Expand Up @@ -160,4 +168,13 @@ public interface MetaDataService {
* @return the config import result
*/
ConfigImportResult importData(List<MetaDataDTO> metaDataList);

/**
* Import shenyu meta data.
*
* @param namespace the namespace
* @param metaDataList meta data list
* @return the config import result
*/
ConfigImportResult importData(String namespace, List<MetaDataDTO> metaDataList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.shenyu.admin.model.result.ShenyuAdminResult;
import org.apache.shenyu.admin.model.vo.PluginHandleVO;

import java.util.Collection;
import java.util.List;

/**
Expand Down Expand Up @@ -95,6 +96,14 @@ default Integer createOrUpdate(PluginHandleDTO pluginHandleDTO) {
* @return plugin handle list.
*/
List<PluginHandleVO> listAllData();

/**
* find all plugin handle list by plugin ids.
*
* @param pluginIds the plugin ids
* @return plugin handle list.
*/
List<PluginHandleVO> listAllDataByPluginIds(Collection<String> pluginIds);

/**
* import plugin handle list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ public interface PluginService extends PageService<PluginQueryCondition, PluginV
* @return the vo list
*/
List<PluginVO> listAllData();

/**
* List all vo list.
*
* @param namespaceId the namespace id
* @return the vo list
*/
List<PluginVO> listAllDataByNamespaceId(String namespaceId);

/**
* list all not in resource.
Expand Down Expand Up @@ -136,8 +144,18 @@ public interface PluginService extends PageService<PluginQueryCondition, PluginV

/**
* import plugin data.
*
* @param pluginList the plugin data
* @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);
}
Loading

0 comments on commit 841d142

Please sign in to comment.