Commit 33ad4945 by lepdou

return default cluster's namespace when custom cluster's namespace never published

parent 10e54f16
......@@ -27,7 +27,7 @@ public class NamespaceController {
@RequestMapping(path = "/apps/{appId}/clusters/{clusterName}/namespaces", method = RequestMethod.POST)
public NamespaceDTO create(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName, @RequestBody NamespaceDTO dto) {
@PathVariable("clusterName") String clusterName, @RequestBody NamespaceDTO dto) {
if (!InputValidator.isValidClusterNamespace(dto.getNamespaceName())) {
throw new BadRequestException(String.format("Namespace格式错误: %s", InputValidator.INVALID_CLUSTER_NAMESPACE_MESSAGE));
}
......@@ -45,18 +45,18 @@ public class NamespaceController {
@RequestMapping(path = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}", method = RequestMethod.DELETE)
public void delete(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName,
@PathVariable("namespaceName") String namespaceName, @RequestParam String operator) {
@PathVariable("clusterName") String clusterName,
@PathVariable("namespaceName") String namespaceName, @RequestParam String operator) {
Namespace entity = namespaceService.findOne(appId, clusterName, namespaceName);
if (entity == null) throw new NotFoundException(
String.format("namespace not found for %s %s %s", appId, clusterName, namespaceName));
String.format("namespace not found for %s %s %s", appId, clusterName, namespaceName));
namespaceService.deleteNamespace(entity, operator);
}
@RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces")
public List<NamespaceDTO> find(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName) {
@PathVariable("clusterName") String clusterName) {
List<Namespace> groups = namespaceService.findNamespaces(appId, clusterName);
return BeanUtils.batchTransform(NamespaceDTO.class, groups);
}
......@@ -71,18 +71,19 @@ public class NamespaceController {
@RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}")
public NamespaceDTO get(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName,
@PathVariable("namespaceName") String namespaceName) {
@PathVariable("clusterName") String clusterName,
@PathVariable("namespaceName") String namespaceName) {
Namespace namespace = namespaceService.findOne(appId, clusterName, namespaceName);
if (namespace == null) throw new NotFoundException(
String.format("namespace not found for %s %s %s", appId, clusterName, namespaceName));
String.format("namespace not found for %s %s %s", appId, clusterName, namespaceName));
return BeanUtils.transfrom(NamespaceDTO.class, namespace);
}
@RequestMapping("/clusters/{clusterName}/namespaces/{namespaceName}/public")
public NamespaceDTO findPublicNamespace(@PathVariable String clusterName,
@PathVariable String namespaceName) {
Namespace namespace = namespaceService.findPublicNamespace(clusterName, namespaceName);
@RequestMapping("/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/associated-public-namespace")
public NamespaceDTO findPublicNamespaceForAssociatedNamespace(@PathVariable String appId,
@PathVariable String clusterName,
@PathVariable String namespaceName) {
Namespace namespace = namespaceService.findPublicNamespaceForAssociatedNamespace(clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException(String.format("public namespace not found. namespace:%s", namespaceName));
......@@ -95,7 +96,7 @@ public class NamespaceController {
* cluster -> cluster has not published namespaces?
*/
@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);
}
......
......@@ -59,7 +59,6 @@ public class NamespaceService {
private InstanceService instanceService;
public Namespace findOne(Long namespaceId) {
return namespaceRepository.findOne(namespaceId);
}
......@@ -69,7 +68,7 @@ public class NamespaceService {
namespaceName);
}
public Namespace findPublicNamespace(String clusterName, String namespaceName) {
public Namespace findPublicNamespaceForAssociatedNamespace(String clusterName, String namespaceName) {
AppNamespace appNamespace = appNamespaceService.findPublicNamespaceByName(namespaceName);
if (appNamespace == null) {
throw new BadRequestException("namespace not exist");
......@@ -79,11 +78,46 @@ public class NamespaceService {
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) {
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;
}
//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) {
......@@ -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));
}
......@@ -146,7 +180,7 @@ public class NamespaceService {
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));
}
......@@ -268,10 +302,10 @@ public class NamespaceService {
String clusterName = cluster.getName();
List<Namespace> namespaces = findNamespaces(appId, clusterName);
for (Namespace namespace: namespaces) {
for (Namespace namespace : namespaces) {
boolean isNamespaceNotPublished = isNamespaceNotPublished(namespace);
if (isNamespaceNotPublished){
if (isNamespaceNotPublished) {
clusterHasNotPublishedItems.put(clusterName, true);
break;
}
......@@ -301,8 +335,8 @@ public class NamespaceService {
}
Map<String, String> publishedConfiguration = gson.fromJson(latestRelease.getConfigurations(), GsonType.CONFIG);
for (Item item: itemsModifiedAfterLastPublish) {
if (!Objects.equals(item.getValue(), publishedConfiguration.get(item.getKey()))){
for (Item item : itemsModifiedAfterLastPublish) {
if (!Objects.equals(item.getValue(), publishedConfiguration.get(item.getKey()))) {
return true;
}
}
......
......@@ -81,10 +81,10 @@ public class AdminServiceAPI {
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
restTemplate.get(env, "/clusters/{clusterName}/namespaces/{namespaceName}/public",
NamespaceDTO.class, clusterName, namespaceName);
restTemplate.get(env, "apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/associated-public-namespace",
NamespaceDTO.class, appId, clusterName, namespaceName);
}
public NamespaceDTO createNamespace(Env env, NamespaceDTO namespace) {
......
......@@ -58,7 +58,7 @@ public abstract class ConfigPublishEmailBuilder {
//set config's value max length to protect email.
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
......
......@@ -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.exception.BadRequestException;
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.Env;
import com.ctrip.framework.apollo.core.utils.StringUtils;
......@@ -26,10 +25,8 @@ import com.ctrip.framework.apollo.tracer.Tracer;
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.transaction.annotation.Transactional;
import org.springframework.web.client.HttpClientErrorException;
import java.util.*;
......@@ -104,9 +101,9 @@ public class NamespaceService {
List<NamespaceBO> namespaceBOs = new LinkedList<>();
for (NamespaceDTO namespace : namespaces) {
NamespaceBO namespaceBO = null;
NamespaceBO namespaceBO;
try {
namespaceBO = transformNamespace2BO(appId, env, clusterName, namespace);
namespaceBO = transformNamespace2BO(env, namespace);
namespaceBOs.add(namespaceBO);
} catch (Exception e) {
logger.error("parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}",
......@@ -123,16 +120,15 @@ public class NamespaceService {
if (namespace == null) {
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) {
NamespaceDTO namespace = namespaceAPI.loadPublicNamespace(env, clusterName, namespaceName);
public NamespaceBO findPublicNamespaceForAssociatedNamespace(Env env, String appId,
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) {
......@@ -148,19 +144,21 @@ public class NamespaceService {
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.setBaseInfo(namespace);
String appId = namespace.getAppId();
String clusterName = namespace.getClusterName();
String namespaceName = namespace.getNamespaceName();
fillAppNamespaceProperties(namespaceBO);
List<ItemBO> itemBOs = new LinkedList<>();
namespaceBO.setItems(itemBOs);
String namespaceName = namespace.getNamespaceName();
//latest Release
ReleaseDTO latestRelease = null;
ReleaseDTO latestRelease;
Map<String, String> releaseItems = new HashMap<>();
latestRelease = releaseService.loadLatestRelease(appId, env, clusterName, namespaceName);
if (latestRelease != null) {
......
......@@ -227,7 +227,8 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
return;
}
//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) {
var publicNamespace = result;
namespace.publicNamespace = publicNamespace;
......@@ -429,6 +430,8 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
namespace.latestReleaseInstances = result;
namespace.latestReleaseInstancesPage++;
})
namespace.isLatestReleaseLoaded = true;
});
} else {
InstanceService.findInstancesByRelease(scope.env,
......
......@@ -5,10 +5,10 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
isArray: false,
url: '/apps/:appId/envs/:env/clusters/:clusterName/namespaces/:namespaceName'
},
load_public_namespace: {
load_public_namespace_for_associated_namespace: {
method: 'GET',
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: {
method: 'GET',
......@@ -52,24 +52,25 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
load_namespace: function (appId, env, clusterName, namespaceName) {
var d = $q.defer();
config_source.load_namespace({
appId: appId,
env: env,
clusterName: clusterName,
namespaceName: namespaceName
}, function (result) {
appId: appId,
env: env,
clusterName: clusterName,
namespaceName: namespaceName
}, function (result) {
d.resolve(result);
}, function (result) {
d.reject(result);
});
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();
config_source.load_public_namespace({
env: env,
clusterName: clusterName,
namespaceName: namespaceName
}, function (result) {
config_source.load_public_namespace_for_associated_namespace({
env: env,
appId: appId,
clusterName: clusterName,
namespaceName: namespaceName
}, function (result) {
d.resolve(result);
}, function (result) {
d.reject(result);
......
......@@ -163,7 +163,8 @@
<!--table view-->
<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>
</div>
<!--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