#2171 服务端部分
This commit is contained in:
parent
1c4927fd51
commit
6ee99aaf5a
@ -17,6 +17,7 @@ package com.alibaba.nacos.config.server.controller;
|
||||
|
||||
import com.alibaba.nacos.config.server.constant.Constants;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import com.alibaba.nacos.config.server.controller.parameters.SameNamespaceCloneConfigBean;
|
||||
import com.alibaba.nacos.config.server.model.*;
|
||||
import com.alibaba.nacos.config.server.result.ResultBuilder;
|
||||
import com.alibaba.nacos.config.server.result.code.ResultCodeEnum;
|
||||
@ -46,6 +47,7 @@ import java.io.IOException;
|
||||
import java.net.URLDecoder;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.alibaba.nacos.core.utils.SystemUtils.LOCAL_IP;
|
||||
|
||||
@ -525,14 +527,20 @@ public class ConfigController {
|
||||
return ResultBuilder.buildSuccessResult("导入成功", saveResult);
|
||||
}
|
||||
|
||||
@GetMapping(params = "clone=true")
|
||||
@PostMapping(params = "clone=true")
|
||||
public RestResult<Map<String, Object>> cloneConfig(HttpServletRequest request,
|
||||
@RequestParam(value = "src_user", required = false) String srcUser,
|
||||
@RequestParam(value = "tenant", required = true) String namespace,
|
||||
@RequestParam(value = "ids", required = true) List<Long> ids,
|
||||
@RequestBody(required = true)
|
||||
List<SameNamespaceCloneConfigBean> configBeansList,
|
||||
@RequestParam(value = "policy", defaultValue = "ABORT")
|
||||
SameConfigPolicy policy) throws NacosException {
|
||||
Map<String, Object> failedData = new HashMap<>(4);
|
||||
if(CollectionUtils.isEmpty(configBeansList)){
|
||||
failedData.put("succCount", 0);
|
||||
return ResultBuilder.buildResult(ResultCodeEnum.NO_SELECTED_CONFIG, failedData);
|
||||
}
|
||||
configBeansList.removeAll(Collections.singleton(null));
|
||||
|
||||
if (NAMESPACE_PUBLIC_KEY.equalsIgnoreCase(namespace)) {
|
||||
namespace = "";
|
||||
@ -541,8 +549,14 @@ public class ConfigController {
|
||||
return ResultBuilder.buildResult(ResultCodeEnum.NAMESPACE_NOT_EXIST, failedData);
|
||||
}
|
||||
|
||||
ids.removeAll(Collections.singleton(null));
|
||||
List<ConfigAllInfo> queryedDataList = persistService.findAllConfigInfo4Export(null, null, null, null, ids);
|
||||
List<Long> idList = new ArrayList<>(configBeansList.size());
|
||||
Map<Long, SameNamespaceCloneConfigBean> configBeansMap = configBeansList.stream()
|
||||
.collect(Collectors.toMap(SameNamespaceCloneConfigBean::getCfgId, cfg -> {
|
||||
idList.add(cfg.getCfgId());
|
||||
return cfg;
|
||||
},(k1, k2) -> k1));
|
||||
|
||||
List<ConfigAllInfo> queryedDataList = persistService.findAllConfigInfo4Export(null, null, null, null, idList);
|
||||
|
||||
if (queryedDataList == null || queryedDataList.isEmpty()) {
|
||||
failedData.put("succCount", 0);
|
||||
@ -552,11 +566,12 @@ public class ConfigController {
|
||||
List<ConfigAllInfo> configInfoList4Clone = new ArrayList<>(queryedDataList.size());
|
||||
|
||||
for (ConfigAllInfo ci : queryedDataList) {
|
||||
SameNamespaceCloneConfigBean prarmBean = configBeansMap.get(ci.getId());
|
||||
ConfigAllInfo ci4save = new ConfigAllInfo();
|
||||
ci4save.setTenant(namespace);
|
||||
ci4save.setType(ci.getType());
|
||||
ci4save.setGroup(ci.getGroup());
|
||||
ci4save.setDataId(ci.getDataId());
|
||||
ci4save.setGroup((prarmBean != null && StringUtils.isNotBlank(prarmBean.getGroup())) ? prarmBean.getGroup() : ci.getGroup());
|
||||
ci4save.setDataId((prarmBean != null && StringUtils.isNotBlank(prarmBean.getDataId())) ? prarmBean.getDataId() : ci.getDataId());
|
||||
ci4save.setContent(ci.getContent());
|
||||
if (StringUtils.isNotBlank(ci.getAppName())) {
|
||||
ci4save.setAppName(ci.getAppName());
|
||||
@ -580,7 +595,7 @@ public class ConfigController {
|
||||
configInfo.getTenant(), requestIpApp, time.getTime(),
|
||||
LOCAL_IP, ConfigTraceService.PERSISTENCE_EVENT_PUB, configInfo.getContent());
|
||||
}
|
||||
return ResultBuilder.buildSuccessResult("导入成功", saveResult);
|
||||
return ResultBuilder.buildSuccessResult("克隆成功", saveResult);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright 1999-2018 Alibaba Group Holding Ltd.
|
||||
*
|
||||
* Licensed 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 com.alibaba.nacos.config.server.controller.parameters;
|
||||
|
||||
/**
|
||||
* @author klw(213539 @ qq.com)
|
||||
* @ClassName: SameNamespaceCloneConfigBean
|
||||
* @Description: 同namespace克隆接口的配制bean
|
||||
* @date 2019/12/13 16:10
|
||||
*/
|
||||
public class SameNamespaceCloneConfigBean {
|
||||
|
||||
private Long cfgId;
|
||||
|
||||
private String dataId;
|
||||
|
||||
private String group;
|
||||
|
||||
public Long getCfgId() {
|
||||
return cfgId;
|
||||
}
|
||||
|
||||
public void setCfgId(Long cfgId) {
|
||||
this.cfgId = cfgId;
|
||||
}
|
||||
|
||||
public String getDataId() {
|
||||
return dataId;
|
||||
}
|
||||
|
||||
public void setDataId(String dataId) {
|
||||
this.dataId = dataId;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
}
|
@ -44,6 +44,8 @@ public enum ResultCodeEnum implements IResultCode {
|
||||
|
||||
DATA_EMPTY(100005, "导入的文件数据为空"),
|
||||
|
||||
NO_SELECTED_CONFIG(100006, "没有选择任何配制"),
|
||||
|
||||
|
||||
;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user