Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhangjian1949
apollo
提交
953b1ff1
apollo
项目概览
zhangjian1949
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
953b1ff1
编写于
6月 16, 2016
作者:
L
lepdou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
create app namespace
上级
0db06584
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
64 addition
and
30 deletion
+64
-30
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
...om/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
+1
-8
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java
...amework/apollo/portal/controller/NamespaceController.java
+19
-4
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/AppCreationEvent.java
...ip/framework/apollo/portal/listener/AppCreationEvent.java
+0
-5
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/AppNamespaceCreationEvent.java
...ork/apollo/portal/listener/AppNamespaceCreationEvent.java
+19
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/CreationListener.java
...ip/framework/apollo/portal/listener/CreationListener.java
+16
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
...rip/framework/apollo/portal/service/NamespaceService.java
+9
-13
未找到文件。
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
浏览文件 @
953b1ff1
...
@@ -71,13 +71,6 @@ public class AdminServiceAPI {
...
@@ -71,13 +71,6 @@ public class AdminServiceAPI {
return
dto
;
return
dto
;
}
}
public
List
<
AppNamespaceDTO
>
findPublicAppNamespaces
(
Env
env
)
{
AppNamespaceDTO
[]
appNamespaceDTOs
=
restTemplate
.
getForObject
(
"{host}/appnamespaces/public"
,
AppNamespaceDTO
[].
class
,
getAdminServiceHost
(
env
));
return
Arrays
.
asList
(
appNamespaceDTOs
);
}
public
NamespaceDTO
createNamespace
(
Env
env
,
NamespaceDTO
namespace
)
{
public
NamespaceDTO
createNamespace
(
Env
env
,
NamespaceDTO
namespace
)
{
return
restTemplate
return
restTemplate
...
@@ -85,7 +78,7 @@ public class AdminServiceAPI {
...
@@ -85,7 +78,7 @@ public class AdminServiceAPI {
getAdminServiceHost
(
env
),
namespace
.
getAppId
(),
namespace
.
getClusterName
()).
getBody
();
getAdminServiceHost
(
env
),
namespace
.
getAppId
(),
namespace
.
getClusterName
()).
getBody
();
}
}
public
AppNamespaceDTO
createOrUpdate
(
Env
env
,
AppNamespaceDTO
appNamespace
)
{
public
AppNamespaceDTO
createOrUpdate
AppNamespace
(
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
();
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java
浏览文件 @
953b1ff1
package
com.ctrip.framework.apollo.portal.controller
;
package
com.ctrip.framework.apollo.portal.controller
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.core.dto.AppNamespaceDTO
;
import
com.ctrip.framework.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.core.dto.NamespaceDTO
;
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.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.entity.vo.NamespaceVO
;
import
com.ctrip.framework.apollo.portal.entity.vo.NamespaceVO
;
import
com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent
;
import
com.ctrip.framework.apollo.portal.service.NamespaceService
;
import
com.ctrip.framework.apollo.portal.service.NamespaceService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
@@ -22,6 +25,10 @@ import static com.ctrip.framework.apollo.portal.util.RequestPrecondition.checkAr
...
@@ -22,6 +25,10 @@ import static com.ctrip.framework.apollo.portal.util.RequestPrecondition.checkAr
@RestController
@RestController
public
class
NamespaceController
{
public
class
NamespaceController
{
@Autowired
private
ApplicationEventPublisher
publisher
;
@Autowired
private
UserInfoHolder
userInfoHolder
;
@Autowired
@Autowired
private
NamespaceService
namespaceService
;
private
NamespaceService
namespaceService
;
...
@@ -30,7 +37,7 @@ public class NamespaceController {
...
@@ -30,7 +37,7 @@ public class NamespaceController {
return
namespaceService
.
findPublicAppNamespaces
();
return
namespaceService
.
findPublicAppNamespaces
();
}
}
@PreAuthorize
(
value
=
"@permissionValidator.hasCreateNamespacePermission(#appId)"
)
@PreAuthorize
(
value
=
"@permissionValidator.hasCreateNamespacePermission(#
namespace.
appId)"
)
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces"
,
method
=
RequestMethod
.
POST
)
public
NamespaceDTO
createNamespace
(
@PathVariable
String
env
,
@RequestBody
NamespaceDTO
namespace
)
{
public
NamespaceDTO
createNamespace
(
@PathVariable
String
env
,
@RequestBody
NamespaceDTO
namespace
)
{
...
@@ -40,11 +47,19 @@ public class NamespaceController {
...
@@ -40,11 +47,19 @@ public class NamespaceController {
}
}
@RequestMapping
(
value
=
"/apps/{appId}/appnamespaces"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/apps/{appId}/appnamespaces"
,
method
=
RequestMethod
.
POST
)
public
void
createAppNamespace
(
@PathVariable
String
appId
,
@RequestBody
AppNamespace
DTO
appNamespace
)
{
public
void
createAppNamespace
(
@PathVariable
String
appId
,
@RequestBody
AppNamespace
appNamespace
)
{
checkArgument
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
());
checkArgument
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
());
namespaceService
.
createRemoteAppNamespace
(
appNamespace
);
String
operator
=
userInfoHolder
.
getUser
().
getUserId
();
if
(
StringUtils
.
isEmpty
(
appNamespace
.
getDataChangeCreatedBy
()))
{
appNamespace
.
setDataChangeCreatedBy
(
operator
);
}
appNamespace
.
setDataChangeLastModifiedBy
(
operator
);
AppNamespace
createdAppNamespace
=
namespaceService
.
createAppNamespaceInLocal
(
appNamespace
);
publisher
.
publishEvent
(
new
AppNamespaceCreationEvent
(
createdAppNamespace
));
}
}
@RequestMapping
(
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces"
)
@RequestMapping
(
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces"
)
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/AppCreationEvent.java
浏览文件 @
953b1ff1
...
@@ -8,11 +8,6 @@ import org.springframework.context.ApplicationEvent;
...
@@ -8,11 +8,6 @@ import org.springframework.context.ApplicationEvent;
public
class
AppCreationEvent
extends
ApplicationEvent
{
public
class
AppCreationEvent
extends
ApplicationEvent
{
/**
* Create a new ApplicationEvent.
*
* @param source the object on which the event initially occurred (never {@code null})
*/
public
AppCreationEvent
(
Object
source
)
{
public
AppCreationEvent
(
Object
source
)
{
super
(
source
);
super
(
source
);
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/AppNamespaceCreationEvent.java
0 → 100644
浏览文件 @
953b1ff1
package
com.ctrip.framework.apollo.portal.listener
;
import
com.google.common.base.Preconditions
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
org.springframework.context.ApplicationEvent
;
public
class
AppNamespaceCreationEvent
extends
ApplicationEvent
{
public
AppNamespaceCreationEvent
(
Object
source
)
{
super
(
source
);
}
public
AppNamespace
getAppNamespace
()
{
Preconditions
.
checkState
(
source
!=
null
);
return
(
AppNamespace
)
this
.
source
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/CreationListener.java
浏览文件 @
953b1ff1
...
@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.portal.listener;
...
@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.portal.listener;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.ExceptionUtils
;
import
com.ctrip.framework.apollo.common.utils.ExceptionUtils
;
import
com.ctrip.framework.apollo.core.dto.AppDTO
;
import
com.ctrip.framework.apollo.core.dto.AppDTO
;
import
com.ctrip.framework.apollo.core.dto.AppNamespaceDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
...
@@ -25,6 +26,8 @@ public class CreationListener {
...
@@ -25,6 +26,8 @@ public class CreationListener {
private
PortalSettings
portalSettings
;
private
PortalSettings
portalSettings
;
@Autowired
@Autowired
private
AdminServiceAPI
.
AppAPI
appAPI
;
private
AdminServiceAPI
.
AppAPI
appAPI
;
@Autowired
private
AdminServiceAPI
.
NamespaceAPI
namespaceAPI
;
@EventListener
@EventListener
public
void
onAppCreationEvent
(
AppCreationEvent
event
)
{
public
void
onAppCreationEvent
(
AppCreationEvent
event
)
{
...
@@ -39,4 +42,17 @@ public class CreationListener {
...
@@ -39,4 +42,17 @@ public class CreationListener {
}
}
}
}
@EventListener
public
void
onAppNamespaceCreationEvent
(
AppNamespaceCreationEvent
event
){
AppNamespaceDTO
dto
=
BeanUtils
.
transfrom
(
AppNamespaceDTO
.
class
,
event
.
getAppNamespace
());
List
<
Env
>
envs
=
portalSettings
.
getActiveEnvs
();
for
(
Env
env
:
envs
)
{
try
{
namespaceAPI
.
createOrUpdateAppNamespace
(
env
,
dto
);
}
catch
(
HttpStatusCodeException
e
)
{
logger
.
error
(
ExceptionUtils
.
toString
(
e
));
}
}
}
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
浏览文件 @
953b1ff1
...
@@ -95,19 +95,15 @@ public class NamespaceService {
...
@@ -95,19 +95,15 @@ public class NamespaceService {
return
Objects
.
isNull
(
appNamespaceRepository
.
findByAppIdAndName
(
appId
,
namespaceName
));
return
Objects
.
isNull
(
appNamespaceRepository
.
findByAppIdAndName
(
appId
,
namespaceName
));
}
}
public
void
createRemoteAppNamespace
(
AppNamespaceDTO
appNamespace
)
{
@Transactional
String
operator
=
userInfoHolder
.
getUser
().
getUserId
();
public
AppNamespace
createAppNamespaceInLocal
(
AppNamespace
appNamespace
)
{
if
(
StringUtils
.
isEmpty
(
appNamespace
.
getDataChangeCreatedBy
()))
{
AppNamespace
managedAppNamespace
=
appNamespaceRepository
.
findByAppIdAndName
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
());
appNamespace
.
setDataChangeCreatedBy
(
operator
);
//update
}
if
(
managedAppNamespace
!=
null
){
appNamespace
.
setDataChangeLastModifiedBy
(
operator
);
BeanUtils
.
copyEntityProperties
(
appNamespace
,
managedAppNamespace
);
for
(
Env
env
:
portalSettings
.
getActiveEnvs
())
{
return
appNamespaceRepository
.
save
(
managedAppNamespace
);
try
{
}
else
{
namespaceAPI
.
createOrUpdate
(
env
,
appNamespace
);
return
appNamespaceRepository
.
save
(
appNamespace
);
}
catch
(
HttpStatusCodeException
e
)
{
logger
.
error
(
ExceptionUtils
.
toString
(
e
));
throw
e
;
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录