Skip to content

Commit

Permalink
初始化private app namespace的权限放在transaction里面
Browse files Browse the repository at this point in the history
  • Loading branch information
lepdou committed Jul 18, 2016
1 parent 4c64de6 commit 10d17f8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Expand Up @@ -82,7 +82,7 @@ public NamespaceDTO createNamespace(Env env, NamespaceDTO namespace) {
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();
}
Expand Down Expand Up @@ -146,7 +146,7 @@ public boolean isClusterUnique(String appId, Env env, String clusterName) {

}

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());
}
Expand Down
Expand Up @@ -13,7 +13,6 @@
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;

Expand All @@ -38,7 +37,7 @@ public void onAppCreationEvent(AppCreationEvent event) {
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);
}
}
Expand All @@ -50,16 +49,11 @@ public void onAppNamespaceCreationEvent(AppNamespaceCreationEvent event){
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());
}
}

}
Expand Up @@ -22,7 +22,8 @@ public class AppNamespaceService {
private UserInfoHolder userInfoHolder;
@Autowired
private AppNamespaceRepository appNamespaceRepository;

@Autowired
private RoleInitializationService roleInitializationService;

/**
* 公共的app ns,能被其它项目关联到的app ns
Expand Down Expand Up @@ -74,7 +75,14 @@ public AppNamespace createAppNamespaceInLocal(AppNamespace appNamespace) {
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;
}

}
Expand Up @@ -24,7 +24,7 @@ public ClusterDTO createCluster(Env env, ClusterDTO cluster){
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);
}

}

0 comments on commit 10d17f8

Please sign in to comment.