Commit b9057d27 by Jason Song Committed by GitHub

Merge pull request #499 from lepdou/1221

return default cluster's namespace when custom cluster's namespace ne…
parents bae4505f 33ad4945
...@@ -79,10 +79,11 @@ public class NamespaceController { ...@@ -79,10 +79,11 @@ public class NamespaceController {
return BeanUtils.transfrom(NamespaceDTO.class, namespace); return BeanUtils.transfrom(NamespaceDTO.class, namespace);
} }
@RequestMapping("/clusters/{clusterName}/namespaces/{namespaceName}/public") @RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/associated-public-namespace")
public NamespaceDTO findPublicNamespace(@PathVariable String clusterName, public NamespaceDTO findPublicNamespaceForAssociatedNamespace(@PathVariable String appId,
@PathVariable String clusterName,
@PathVariable String namespaceName) { @PathVariable String namespaceName) {
Namespace namespace = namespaceService.findPublicNamespace(clusterName, namespaceName); Namespace namespace = namespaceService.findPublicNamespaceForAssociatedNamespace(clusterName, namespaceName);
if (namespace == null) { if (namespace == null) {
throw new NotFoundException(String.format("public namespace not found. namespace:%s", namespaceName)); throw new NotFoundException(String.format("public namespace not found. namespace:%s", namespaceName));
...@@ -95,7 +96,7 @@ public class NamespaceController { ...@@ -95,7 +96,7 @@ public class NamespaceController {
* cluster -> cluster has not published namespaces? * cluster -> cluster has not published namespaces?
*/ */
@RequestMapping("/apps/{appId}/namespaces/publish_info") @RequestMapping("/apps/{appId}/namespaces/publish_info")
public Map<String, Boolean> namespacePublishInfo(@PathVariable String appId){ public Map<String, Boolean> namespacePublishInfo(@PathVariable String appId) {
return namespaceService.namespacePublishInfo(appId); return namespaceService.namespacePublishInfo(appId);
} }
......
...@@ -59,7 +59,6 @@ public class NamespaceService { ...@@ -59,7 +59,6 @@ public class NamespaceService {
private InstanceService instanceService; private InstanceService instanceService;
public Namespace findOne(Long namespaceId) { public Namespace findOne(Long namespaceId) {
return namespaceRepository.findOne(namespaceId); return namespaceRepository.findOne(namespaceId);
} }
...@@ -69,7 +68,7 @@ public class NamespaceService { ...@@ -69,7 +68,7 @@ public class NamespaceService {
namespaceName); namespaceName);
} }
public Namespace findPublicNamespace(String clusterName, String namespaceName) { public Namespace findPublicNamespaceForAssociatedNamespace(String clusterName, String namespaceName) {
AppNamespace appNamespace = appNamespaceService.findPublicNamespaceByName(namespaceName); AppNamespace appNamespace = appNamespaceService.findPublicNamespaceByName(namespaceName);
if (appNamespace == null) { if (appNamespace == null) {
throw new BadRequestException("namespace not exist"); throw new BadRequestException("namespace not exist");
...@@ -79,13 +78,48 @@ public class NamespaceService { ...@@ -79,13 +78,48 @@ public class NamespaceService {
Namespace namespace = findOne(appId, clusterName, namespaceName); Namespace namespace = findOne(appId, clusterName, namespaceName);
//default cluster's namespace
if (Objects.equals(clusterName, ConfigConsts.CLUSTER_NAME_DEFAULT)) {
return namespace;
}
//custom cluster's namespace not exist.
//return default cluster's namespace
if (namespace == null) { if (namespace == null) {
namespace = findOne(appId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespaceName); return findOne(appId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespaceName);
} }
//custom cluster's namespace exist and has published.
//return custom cluster's namespace
Release latestActiveRelease = releaseService.findLatestActiveRelease(namespace);
if (latestActiveRelease != null) {
return namespace;
}
Namespace defaultNamespace = findOne(appId, ConfigConsts.CLUSTER_NAME_DEFAULT, namespaceName);
//custom cluster's namespace exist but never published.
//and default cluster's namespace not exist.
//return custom cluster's namespace
if (defaultNamespace == null) {
return namespace; return namespace;
} }
//custom cluster's namespace exist but never published.
//and default cluster's namespace exist and has published.
//return default cluster's namespace
Release defaultNamespaceLatestActiveRelease = releaseService.findLatestActiveRelease(defaultNamespace);
if (defaultNamespaceLatestActiveRelease != null) {
return defaultNamespace;
}
//custom cluster's namespace exist but never published.
//and default cluster's namespace exist but never published.
//return custom cluster's namespace
return namespace;
}
public List<Namespace> findNamespaces(String appId, String clusterName) { public List<Namespace> findNamespaces(String appId, String clusterName) {
List<Namespace> namespaces = namespaceRepository.findByAppIdAndClusterNameOrderByIdAsc(appId, clusterName); List<Namespace> namespaces = namespaceRepository.findByAppIdAndClusterNameOrderByIdAsc(appId, clusterName);
if (namespaces == null) { if (namespaces == null) {
...@@ -129,7 +163,7 @@ public class NamespaceService { ...@@ -129,7 +163,7 @@ public class NamespaceService {
} }
public Namespace findParentNamespace(String appId, String clusterName, String namespaceName){ public Namespace findParentNamespace(String appId, String clusterName, String namespaceName) {
return findParentNamespace(new Namespace(appId, clusterName, namespaceName)); return findParentNamespace(new Namespace(appId, clusterName, namespaceName));
} }
...@@ -146,7 +180,7 @@ public class NamespaceService { ...@@ -146,7 +180,7 @@ public class NamespaceService {
return null; return null;
} }
public boolean isChildNamespace(String appId, String clusterName, String namespaceName){ public boolean isChildNamespace(String appId, String clusterName, String namespaceName) {
return isChildNamespace(new Namespace(appId, clusterName, namespaceName)); return isChildNamespace(new Namespace(appId, clusterName, namespaceName));
} }
...@@ -268,10 +302,10 @@ public class NamespaceService { ...@@ -268,10 +302,10 @@ public class NamespaceService {
String clusterName = cluster.getName(); String clusterName = cluster.getName();
List<Namespace> namespaces = findNamespaces(appId, clusterName); List<Namespace> namespaces = findNamespaces(appId, clusterName);
for (Namespace namespace: namespaces) { for (Namespace namespace : namespaces) {
boolean isNamespaceNotPublished = isNamespaceNotPublished(namespace); boolean isNamespaceNotPublished = isNamespaceNotPublished(namespace);
if (isNamespaceNotPublished){ if (isNamespaceNotPublished) {
clusterHasNotPublishedItems.put(clusterName, true); clusterHasNotPublishedItems.put(clusterName, true);
break; break;
} }
...@@ -301,8 +335,8 @@ public class NamespaceService { ...@@ -301,8 +335,8 @@ public class NamespaceService {
} }
Map<String, String> publishedConfiguration = gson.fromJson(latestRelease.getConfigurations(), GsonType.CONFIG); Map<String, String> publishedConfiguration = gson.fromJson(latestRelease.getConfigurations(), GsonType.CONFIG);
for (Item item: itemsModifiedAfterLastPublish) { for (Item item : itemsModifiedAfterLastPublish) {
if (!Objects.equals(item.getValue(), publishedConfiguration.get(item.getKey()))){ if (!Objects.equals(item.getValue(), publishedConfiguration.get(item.getKey()))) {
return true; return true;
} }
} }
......
...@@ -81,10 +81,10 @@ public class AdminServiceAPI { ...@@ -81,10 +81,10 @@ public class AdminServiceAPI {
NamespaceDTO.class, appId, clusterName, namespaceName); NamespaceDTO.class, appId, clusterName, namespaceName);
} }
public NamespaceDTO loadPublicNamespace(Env env, String clusterName, String namespaceName) { public NamespaceDTO findPublicNamespaceForAssociatedNamespace(Env env, String appId, String clusterName, String namespaceName) {
return return
restTemplate.get(env, "/clusters/{clusterName}/namespaces/{namespaceName}/public", restTemplate.get(env, "apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/associated-public-namespace",
NamespaceDTO.class, clusterName, namespaceName); NamespaceDTO.class, appId, clusterName, namespaceName);
} }
public NamespaceDTO createNamespace(Env env, NamespaceDTO namespace) { public NamespaceDTO createNamespace(Env env, NamespaceDTO namespace) {
......
...@@ -58,7 +58,7 @@ public abstract class ConfigPublishEmailBuilder { ...@@ -58,7 +58,7 @@ public abstract class ConfigPublishEmailBuilder {
//set config's value max length to protect email. //set config's value max length to protect email.
protected static final int VALUE_MAX_LENGTH = 100; protected static final int VALUE_MAX_LENGTH = 100;
private FastDateFormat dateFormat = FastDateFormat.getInstance("yyyy-MM-dd hh:mm:ss"); protected FastDateFormat dateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
@Autowired @Autowired
......
...@@ -81,12 +81,13 @@ public class NamespaceController { ...@@ -81,12 +81,13 @@ public class NamespaceController {
return namespaceService.loadNamespaceBO(appId, Env.valueOf(env), clusterName, namespaceName); return namespaceService.loadNamespaceBO(appId, Env.valueOf(env), clusterName, namespaceName);
} }
@RequestMapping("/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/public") @RequestMapping("/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/associated-public-namespace")
public NamespaceBO findPublicNamespace(@PathVariable String env, public NamespaceBO findPublicNamespaceForAssociatedNamespace(@PathVariable String env,
@PathVariable String appId,
@PathVariable String namespaceName, @PathVariable String namespaceName,
@PathVariable String clusterName) { @PathVariable String clusterName) {
return namespaceService.loadPublicNamespaceBO(Env.valueOf(env), clusterName, namespaceName); return namespaceService.findPublicNamespaceForAssociatedNamespace(Env.valueOf(env), appId, clusterName, namespaceName);
} }
@PreAuthorize(value = "@permissionValidator.hasCreateNamespacePermission(#appId)") @PreAuthorize(value = "@permissionValidator.hasCreateNamespacePermission(#appId)")
...@@ -176,7 +177,6 @@ public class NamespaceController { ...@@ -176,7 +177,6 @@ public class NamespaceController {
* dev -> * dev ->
* default -> true (default cluster has not published namespace) * default -> true (default cluster has not published namespace)
* customCluster -> false (customCluster cluster's all namespaces had published) * customCluster -> false (customCluster cluster's all namespaces had published)
*
*/ */
@RequestMapping("/apps/{appId}/namespaces/publish_info") @RequestMapping("/apps/{appId}/namespaces/publish_info")
public Map<String, Map<String, Boolean>> getNamespacesPublishInfo(@PathVariable String appId) { public Map<String, Map<String, Boolean>> getNamespacesPublishInfo(@PathVariable String appId) {
......
...@@ -11,7 +11,6 @@ import com.ctrip.framework.apollo.common.dto.ReleaseDTO; ...@@ -11,7 +11,6 @@ import com.ctrip.framework.apollo.common.dto.ReleaseDTO;
import com.ctrip.framework.apollo.common.entity.AppNamespace; import com.ctrip.framework.apollo.common.entity.AppNamespace;
import com.ctrip.framework.apollo.common.exception.BadRequestException; import com.ctrip.framework.apollo.common.exception.BadRequestException;
import com.ctrip.framework.apollo.common.utils.BeanUtils; import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat; import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.core.enums.Env; import com.ctrip.framework.apollo.core.enums.Env;
import com.ctrip.framework.apollo.core.utils.StringUtils; import com.ctrip.framework.apollo.core.utils.StringUtils;
...@@ -26,10 +25,8 @@ import com.ctrip.framework.apollo.tracer.Tracer; ...@@ -26,10 +25,8 @@ import com.ctrip.framework.apollo.tracer.Tracer;
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.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.HttpClientErrorException;
import java.util.*; import java.util.*;
...@@ -104,9 +101,9 @@ public class NamespaceService { ...@@ -104,9 +101,9 @@ public class NamespaceService {
List<NamespaceBO> namespaceBOs = new LinkedList<>(); List<NamespaceBO> namespaceBOs = new LinkedList<>();
for (NamespaceDTO namespace : namespaces) { for (NamespaceDTO namespace : namespaces) {
NamespaceBO namespaceBO = null; NamespaceBO namespaceBO;
try { try {
namespaceBO = transformNamespace2BO(appId, env, clusterName, namespace); namespaceBO = transformNamespace2BO(env, namespace);
namespaceBOs.add(namespaceBO); namespaceBOs.add(namespaceBO);
} catch (Exception e) { } catch (Exception e) {
logger.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}", logger.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}",
...@@ -123,16 +120,15 @@ public class NamespaceService { ...@@ -123,16 +120,15 @@ public class NamespaceService {
if (namespace == null) { if (namespace == null) {
throw new BadRequestException("namespaces not exist"); throw new BadRequestException("namespaces not exist");
} }
return transformNamespace2BO(appId, env, clusterName, namespace); return transformNamespace2BO(env, namespace);
} }
public NamespaceBO loadPublicNamespaceBO(Env env, String clusterName, String namespaceName) { public NamespaceBO findPublicNamespaceForAssociatedNamespace(Env env, String appId,
NamespaceDTO namespace = namespaceAPI.loadPublicNamespace(env, clusterName, namespaceName); String clusterName, String namespaceName) {
NamespaceDTO namespace = namespaceAPI.findPublicNamespaceForAssociatedNamespace(env, appId, clusterName, namespaceName);
String appId = namespace.getAppId();
String actualClusterName = namespace.getClusterName();
return transformNamespace2BO(appId, env, actualClusterName, namespace); return transformNamespace2BO(env, namespace);
} }
public Map<String, Map<String, Boolean>> getNamespacesPublishInfo(String appId) { public Map<String, Map<String, Boolean>> getNamespacesPublishInfo(String appId) {
...@@ -148,19 +144,21 @@ public class NamespaceService { ...@@ -148,19 +144,21 @@ public class NamespaceService {
return result; return result;
} }
private NamespaceBO transformNamespace2BO(String appId, Env env, String clusterName, NamespaceDTO namespace) { private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace) {
NamespaceBO namespaceBO = new NamespaceBO(); NamespaceBO namespaceBO = new NamespaceBO();
namespaceBO.setBaseInfo(namespace); namespaceBO.setBaseInfo(namespace);
String appId = namespace.getAppId();
String clusterName = namespace.getClusterName();
String namespaceName = namespace.getNamespaceName();
fillAppNamespaceProperties(namespaceBO); fillAppNamespaceProperties(namespaceBO);
List<ItemBO> itemBOs = new LinkedList<>(); List<ItemBO> itemBOs = new LinkedList<>();
namespaceBO.setItems(itemBOs); namespaceBO.setItems(itemBOs);
String namespaceName = namespace.getNamespaceName();
//latest Release //latest Release
ReleaseDTO latestRelease = null; ReleaseDTO latestRelease;
Map<String, String> releaseItems = new HashMap<>(); Map<String, String> releaseItems = new HashMap<>();
latestRelease = releaseService.loadLatestRelease(appId, env, clusterName, namespaceName); latestRelease = releaseService.loadLatestRelease(appId, env, clusterName, namespaceName);
if (latestRelease != null) { if (latestRelease != null) {
......
...@@ -227,7 +227,8 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na ...@@ -227,7 +227,8 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
return; return;
} }
//load public namespace //load public namespace
ConfigService.load_public_namespace(scope.env, scope.cluster, namespace.baseInfo.namespaceName) ConfigService.load_public_namespace_for_associated_namespace(scope.env, scope.appId, scope.cluster,
namespace.baseInfo.namespaceName)
.then(function (result) { .then(function (result) {
var publicNamespace = result; var publicNamespace = result;
namespace.publicNamespace = publicNamespace; namespace.publicNamespace = publicNamespace;
...@@ -429,6 +430,8 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na ...@@ -429,6 +430,8 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
namespace.latestReleaseInstances = result; namespace.latestReleaseInstances = result;
namespace.latestReleaseInstancesPage++; namespace.latestReleaseInstancesPage++;
}) })
namespace.isLatestReleaseLoaded = true;
}); });
} else { } else {
InstanceService.findInstancesByRelease(scope.env, InstanceService.findInstancesByRelease(scope.env,
......
...@@ -5,10 +5,10 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q) ...@@ -5,10 +5,10 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
isArray: false, isArray: false,
url: '/apps/:appId/envs/:env/clusters/:clusterName/namespaces/:namespaceName' url: '/apps/:appId/envs/:env/clusters/:clusterName/namespaces/:namespaceName'
}, },
load_public_namespace: { load_public_namespace_for_associated_namespace: {
method: 'GET', method: 'GET',
isArray: false, isArray: false,
url: '/envs/:env/clusters/:clusterName/namespaces/:namespaceName/public' url: '/envs/:env/apps/:appId/clusters/:clusterName/namespaces/:namespaceName/associated-public-namespace'
}, },
load_all_namespaces: { load_all_namespaces: {
method: 'GET', method: 'GET',
...@@ -63,10 +63,11 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q) ...@@ -63,10 +63,11 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
}); });
return d.promise; return d.promise;
}, },
load_public_namespace: function (env, clusterName, namespaceName) { load_public_namespace_for_associated_namespace: function (env, appId, clusterName, namespaceName) {
var d = $q.defer(); var d = $q.defer();
config_source.load_public_namespace({ config_source.load_public_namespace_for_associated_namespace({
env: env, env: env,
appId: appId,
clusterName: clusterName, clusterName: clusterName,
namespaceName: namespaceName namespaceName: namespaceName
}, function (result) { }, function (result) {
......
...@@ -163,7 +163,8 @@ ...@@ -163,7 +163,8 @@
<!--table view--> <!--table view-->
<div class="namespace-view-table" ng-show="namespace.viewType == 'table'"> <div class="namespace-view-table" ng-show="namespace.viewType == 'table'">
<div class="well well-sm no-radius text-center" ng-show="!namespace.isLinkedNamespace && !namespace.latestRelease"> <div class="J_namespace-release-tip well well-sm no-radius text-center"
ng-show="namespace.isLatestReleaseLoaded && !namespace.isLinkedNamespace && !namespace.latestRelease">
<span style="color: red"> Tips: 此namespace从来没有发布过,Apollo客户端将获取不到配置并记录404日志信息,请及时发布。</span> <span style="color: red"> Tips: 此namespace从来没有发布过,Apollo客户端将获取不到配置并记录404日志信息,请及时发布。</span>
</div> </div>
<!--not link namespace--> <!--not link namespace-->
......
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