diff --git a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java index bcfa220ecd3ca37b396d9b26069213e8aa011565..0590e02ed3dfed703631db39122b024c9313c8c3 100644 --- a/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java +++ b/apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java @@ -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; } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/ItemDiffs.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/ItemDiffs.java index 6d19e7e078ef0c97e21d67cd32c59c4261159627..6a3656352698d3ff18d2bbb37469c0bb15e4320a 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/ItemDiffs.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/ItemDiffs.java @@ -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; + } } diff --git a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigService.java b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigService.java index e9fd2a9d35a6faeba429c6f1d52572b87e11fce6..4b7c3c9cd65d136657fd56f43c4bf8f8f56bc90c 100644 --- a/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigService.java +++ b/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigService.java @@ -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(); } diff --git a/apollo-portal/src/main/resources/static/config/sync.html b/apollo-portal/src/main/resources/static/config/sync.html index 033f0936f13e9dc424d397e8a122853a81e12e12..1f86ec11859e1e7def171c88ae33d0f9c38e577c 100644 --- a/apollo-portal/src/main/resources/static/config/sync.html +++ b/apollo-portal/src/main/resources/static/config/sync.html @@ -42,12 +42,22 @@
+
+
+ +
+

+
+
+
+ apollo-select="collectSelectedClusters" + apollo-not-checked-env="pageContext.env" + apollo-not-checked-cluster="pageContext.clusterName">
@@ -96,9 +106,12 @@
-

环境: +

+ 环境: 集群: - 没有更新的配置 + Namespace:{{pageContext.namespaceName}} + +


@@ -180,7 +193,6 @@ - diff --git a/apollo-portal/src/main/resources/static/scripts/directive.js b/apollo-portal/src/main/resources/static/scripts/directive.js index a8aed71b91f4c2b9f9548685c22dea90810408d7..6e98407b850f1c0fd2aef47a0148597558e39abf 100644 --- a/apollo-portal/src/main/resources/static/scripts/directive.js +++ b/apollo-portal/src/main/resources/static/scripts/directive.js @@ -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); }) });