-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[type:fix] configs import and export refactor
- Loading branch information
Showing
33 changed files
with
934 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...src/main/java/org/apache/shenyu/admin/service/configs/AuthConfigsExportImportHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...-admin/src/main/java/org/apache/shenyu/admin/service/configs/ConfigsExportImportEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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. | ||
*/ | ||
Plugin("plugin.json", 2), | ||
|
||
/** | ||
* selector. | ||
*/ | ||
Selector("selector.json", 3), | ||
|
||
/** | ||
* rule. | ||
*/ | ||
Rule("rule.json", 4), | ||
|
||
/** | ||
* dict. | ||
*/ | ||
Dict("dict.json", 5), | ||
|
||
/** | ||
* proxy selector. | ||
*/ | ||
ProxySelector("proxy_selector.json", 6), | ||
|
||
/** | ||
* discovery. | ||
*/ | ||
Discovery("discovery.json", 7), | ||
|
||
/** | ||
* discovery upstream. | ||
*/ | ||
DiscoveryUpstream("discovery_upstream.json", 8); | ||
|
||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/ConfigsImportContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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(); | ||
|
||
/** | ||
* old selector id -> new selector id. | ||
*/ | ||
private final Map<String, String> selectorIdMapping = Maps.newHashMap(); | ||
|
||
/** | ||
* old proxy selector id -> new proxy selector id. | ||
*/ | ||
private final Map<String, String> proxySelectorIdMapping = Maps.newHashMap(); | ||
|
||
/** | ||
* old discovery handler id -> new discovery handler id. | ||
*/ | ||
private final Map<String, String> discoveryHandlerIdMapping = 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; | ||
} | ||
} |
Oops, something went wrong.