Commit b536c2d8 by Jason Song Committed by GitHub

Merge pull request #330 from lepdou/bugfix_0718

初始化private app namespace的权限放在transaction里面
parents 4c64de67 10d17f87
...@@ -82,7 +82,7 @@ public class AdminServiceAPI { ...@@ -82,7 +82,7 @@ public class AdminServiceAPI {
getAdminServiceHost(env), namespace.getAppId(), namespace.getClusterName()).getBody(); getAdminServiceHost(env), namespace.getAppId(), namespace.getClusterName()).getBody();
} }
public AppNamespaceDTO createOrUpdateAppNamespace(Env env, AppNamespaceDTO appNamespace) { public AppNamespaceDTO createAppNamespace(Env env, AppNamespaceDTO appNamespace) {
return restTemplate.postForEntity("{host}/apps/{appId}/appnamespaces", appNamespace, AppNamespaceDTO.class, return restTemplate.postForEntity("{host}/apps/{appId}/appnamespaces", appNamespace, AppNamespaceDTO.class,
getAdminServiceHost(env), appNamespace.getAppId()).getBody(); getAdminServiceHost(env), appNamespace.getAppId()).getBody();
} }
...@@ -146,7 +146,7 @@ public class AdminServiceAPI { ...@@ -146,7 +146,7 @@ public class AdminServiceAPI {
} }
public ClusterDTO createOrUpdate(Env env, ClusterDTO cluster) { public ClusterDTO create(Env env, ClusterDTO cluster) {
return restTemplate.postForObject("{host}/apps/{appId}/clusters", cluster, ClusterDTO.class, return restTemplate.postForObject("{host}/apps/{appId}/clusters", cluster, ClusterDTO.class,
getAdminServiceHost(env), cluster.getAppId()); getAdminServiceHost(env), cluster.getAppId());
} }
......
...@@ -13,7 +13,6 @@ import org.slf4j.LoggerFactory; ...@@ -13,7 +13,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.client.HttpStatusCodeException;
import java.util.List; import java.util.List;
...@@ -38,7 +37,7 @@ public class CreationListener { ...@@ -38,7 +37,7 @@ public class CreationListener {
for (Env env : envs) { for (Env env : envs) {
try { try {
appAPI.createApp(env, appDTO); appAPI.createApp(env, appDTO);
} catch (HttpStatusCodeException e) { } catch (Throwable e) {
logger.error("call appAPI.createApp error.[{app}, {env}]", appDTO.getAppId(), env, e); logger.error("call appAPI.createApp error.[{app}, {env}]", appDTO.getAppId(), env, e);
} }
} }
...@@ -50,16 +49,11 @@ public class CreationListener { ...@@ -50,16 +49,11 @@ public class CreationListener {
List<Env> envs = portalSettings.getActiveEnvs(); List<Env> envs = portalSettings.getActiveEnvs();
for (Env env : envs) { for (Env env : envs) {
try { try {
namespaceAPI.createOrUpdateAppNamespace(env, dto); namespaceAPI.createAppNamespace(env, dto);
} catch (HttpStatusCodeException e) { } catch (Throwable e) {
logger.error("call namespaceAPI.createOrUpdateAppNamespace error. [{app}, {env}]", dto.getAppId(), env, e); logger.error("call namespaceAPI.createAppNamespace error. [{app}, {env}]", dto.getAppId(), env, e);
} }
} }
//如果是私有的app namespace 要默认初始化权限
if (!dto.isPublic()) {
roleInitializationService.initNamespaceRoles(dto.getAppId(), dto.getName());
}
} }
} }
...@@ -22,7 +22,8 @@ public class AppNamespaceService { ...@@ -22,7 +22,8 @@ public class AppNamespaceService {
private UserInfoHolder userInfoHolder; private UserInfoHolder userInfoHolder;
@Autowired @Autowired
private AppNamespaceRepository appNamespaceRepository; private AppNamespaceRepository appNamespaceRepository;
@Autowired
private RoleInitializationService roleInitializationService;
/** /**
* 公共的app ns,能被其它项目关联到的app ns * 公共的app ns,能被其它项目关联到的app ns
...@@ -74,7 +75,14 @@ public class AppNamespaceService { ...@@ -74,7 +75,14 @@ public class AppNamespaceService {
throw new BadRequestException(appNamespace.getName() + "已存在"); throw new BadRequestException(appNamespace.getName() + "已存在");
} }
return appNamespaceRepository.save(appNamespace); AppNamespace createdAppNamespace = appNamespaceRepository.save(appNamespace);
//如果是私有的app namespace 要默认初始化权限,如果是公共的,则在关联此namespace的时候初始化权限
if (!createdAppNamespace.isPublic()) {
roleInitializationService.initNamespaceRoles(appNamespace.getAppId(), appNamespace.getName());
}
return createdAppNamespace;
} }
} }
...@@ -24,7 +24,7 @@ public class ClusterService { ...@@ -24,7 +24,7 @@ public class ClusterService {
if (!clusterAPI.isClusterUnique(cluster.getAppId(), env, cluster.getName())){ if (!clusterAPI.isClusterUnique(cluster.getAppId(), env, cluster.getName())){
throw new BadRequestException(String.format("cluster %s already exists.", cluster.getName())); throw new BadRequestException(String.format("cluster %s already exists.", cluster.getName()));
} }
return clusterAPI.createOrUpdate(env, cluster); return clusterAPI.create(env, 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