提交 b536c2d8 编写于 作者: J Jason Song 提交者: GitHub

Merge pull request #330 from lepdou/bugfix_0718

初始化private app namespace的权限放在transaction里面
......@@ -82,7 +82,7 @@ public class AdminServiceAPI {
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,
getAdminServiceHost(env), appNamespace.getAppId()).getBody();
}
......@@ -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,
getAdminServiceHost(env), cluster.getAppId());
}
......
......@@ -13,7 +13,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.web.client.HttpStatusCodeException;
import java.util.List;
......@@ -38,7 +37,7 @@ public class CreationListener {
for (Env env : envs) {
try {
appAPI.createApp(env, appDTO);
} catch (HttpStatusCodeException e) {
} catch (Throwable e) {
logger.error("call appAPI.createApp error.[{app}, {env}]", appDTO.getAppId(), env, e);
}
}
......@@ -50,16 +49,11 @@ public class CreationListener {
List<Env> envs = portalSettings.getActiveEnvs();
for (Env env : envs) {
try {
namespaceAPI.createOrUpdateAppNamespace(env, dto);
} catch (HttpStatusCodeException e) {
logger.error("call namespaceAPI.createOrUpdateAppNamespace error. [{app}, {env}]", dto.getAppId(), env, e);
namespaceAPI.createAppNamespace(env, dto);
} catch (Throwable 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 {
private UserInfoHolder userInfoHolder;
@Autowired
private AppNamespaceRepository appNamespaceRepository;
@Autowired
private RoleInitializationService roleInitializationService;
/**
* 公共的app ns,能被其它项目关联到的app ns
......@@ -74,7 +75,14 @@ public class AppNamespaceService {
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 {
if (!clusterAPI.isClusterUnique(cluster.getAppId(), env, 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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册