Commit 43db6322 by Jason Song Committed by GitHub

Merge pull request #297 from lepdou/0620_27

sync config
parents d77de842 7c456751
......@@ -13,6 +13,7 @@ import com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.dto.ItemChangeSets;
import com.ctrip.framework.apollo.core.dto.ItemDTO;
import com.ctrip.framework.apollo.core.utils.StringUtils;
@Service
......@@ -71,7 +72,11 @@ public class ItemSetService {
auditService.audit("ItemSet", null, Audit.OP.DELETE, operator);
}
createCommit(appId, clusterName, namespaceName, configChangeContentBuilder.build(), changeSet.getDataChangeLastModifiedBy());
String configChangeContent = configChangeContentBuilder.build();
if (!StringUtils.isEmpty(configChangeContent)){
createCommit(appId, clusterName, namespaceName, configChangeContentBuilder.build(), changeSet.getDataChangeLastModifiedBy());
}
return changeSet;
}
......
......@@ -5,6 +5,7 @@ import com.ctrip.framework.apollo.core.dto.ItemChangeSets;
public class ItemDiffs {
private NamespaceIdentifer namespace;
private ItemChangeSets diffs;
private String extInfo;
public ItemDiffs(NamespaceIdentifer namespace){
this.namespace = namespace;
......@@ -24,4 +25,12 @@ public class ItemDiffs {
public void setDiffs(ItemChangeSets diffs) {
this.diffs = diffs;
}
public String getExtInfo() {
return extInfo;
}
public void setExtInfo(String extInfo) {
this.extInfo = extInfo;
}
}
......@@ -4,6 +4,7 @@ package com.ctrip.framework.apollo.portal.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.HttpClientErrorException;
......@@ -135,7 +136,12 @@ public class ConfigService {
for (NamespaceIdentifer namespace : comparedNamespaces) {
ItemDiffs itemDiffs = new ItemDiffs(namespace);
itemDiffs.setDiffs(parseChangeSets(namespace, sourceItems));
try {
itemDiffs.setDiffs(parseChangeSets(namespace, sourceItems));
} catch (BadRequestException e) {
itemDiffs.setDiffs(new ItemChangeSets());
itemDiffs.setExtInfo("该集群下没有名为 " + namespace.getNamespaceName() + " 的namespace");
}
result.add(itemDiffs);
}
......@@ -150,12 +156,12 @@ public class ConfigService {
NamespaceDTO namespaceDTO = null;
try {
namespaceDTO = namespaceAPI.loadNamespace(appId, env, clusterName, namespaceName);
} catch (NotFoundException e) {
logger.warn("namespace not exist. appId:{}, env:{}, clusterName:{}, namespaceName:{}", appId, env, clusterName,
namespaceName);
throw new BadRequestException(String.format(
"namespace not exist. appId:%s, env:%s, clusterName:%s, namespaceName:%s", appId, env, clusterName,
namespaceName));
} catch (HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
throw new BadRequestException(String.format(
"namespace not exist. appId:%s, env:%s, clusterName:%s, namespaceName:%s", appId, env, clusterName,
namespaceName));
}
}
return namespaceDTO.getId();
}
......
......@@ -44,10 +44,20 @@
<div class="row" ng-show="syncItemStep == 1">
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">同步的Namespace</label>
<div class="col-sm-6">
<h4 ng-bind="pageContext.namespaceName"></h4>
</div>
</div>
</div>
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">同步到那个集群</label>
<div class="col-sm-6">
<apolloclusterselector apollo-app-id="pageContext.appId" apollo-default-all-checked="true"
apollo-select="collectSelectedClusters"></apolloclusterselector>
apollo-select="collectSelectedClusters"
apollo-not-checked-env="pageContext.env"
apollo-not-checked-cluster="pageContext.clusterName"></apolloclusterselector>
</div>
</div>
</div>
......@@ -96,11 +106,16 @@
<!--step 2-->
<div class="row" ng-show="syncItemStep == 2" ng-repeat="diff in diffs">
<h4 class="text-center">环境:<span ng-bind="diff.namespace.env"></span>
<h5 class="text-center">
环境:<span ng-bind="diff.namespace.env"></span>
集群:<span ng-bind="diff.namespace.clusterName"></span>
<em ng-show="diff.diffs.createItems.length == 0 && diff.diffs.updateItems.length == 0">没有更新的配置</em>
</h4>
<hr>
<span ng-show="!diff.extInfo">Namespace:{{pageContext.namespaceName}}</span>
</h5>
<div class="text-center" ng-show="diff.diffs.createItems.length + diff.diffs.updateItems.length == 0 || diff.extInfo">
<font ng-show="diff.diffs.createItems.length + diff.diffs.updateItems.length == 0 && !diff.extInfo">没有更新的配置</font>
<font ng-show="diff.extInfo" ng-bind="diff.extInfo"></font>
,忽略同步
</div>
<div class="row" style="margin-top: 10px;" ng-show="diff.diffs.createItems.length > 0">
<div class="form-horizontal">
......@@ -150,6 +165,7 @@
</div>
</div>
</div>
<hr>
</div>
......@@ -180,7 +196,6 @@
<script src="../vendor/angular/loading-bar.min.js"></script>
<!-- bootstrap.js -->
<script src="../vendor/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
......
......@@ -128,7 +128,9 @@ directive_module.directive('apolloclusterselector', function ($compile, $window,
defaultAllChecked: '=apolloDefaultAllChecked',
select: '=apolloSelect',
defaultCheckedEnv: '=apolloDefaultCheckedEnv',
defaultCheckedCluster: '=apolloDefaultCheckedCluster'
defaultCheckedCluster: '=apolloDefaultCheckedCluster',
notCheckedEnv:'=apolloNotCheckedEnv',
notCheckedCluster: '=apolloNotCheckedCluster'
},
link: function (scope, element, attrs) {
......@@ -146,9 +148,15 @@ directive_module.directive('apolloclusterselector', function ($compile, $window,
var env = node.env;
node.clusters.forEach(function (cluster) {
cluster.env = env;
//default checked
cluster.checked = scope.defaultAllChecked ||
(cluster.env == scope.defaultCheckedEnv && cluster.name
== scope.defaultCheckedCluster);
//not checked
if (cluster.env == scope.notCheckedEnv && cluster.name == scope.notCheckedCluster){
cluster.checked = false;
}
scope.clusters.push(cluster);
})
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment