Commit 4da40f9b by lepdou

sync config

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