Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhangjian1949
apollo
提交
5b7bcc20
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,发现更多精彩内容 >>
提交
5b7bcc20
编写于
5月 06, 2016
作者:
L
lepdou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
save appnamespace service
上级
633eb438
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
143 addition
and
6 deletion
+143
-6
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppController.java
...m/ctrip/apollo/adminservice/controller/AppController.java
+1
-0
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppNamespaceController.java
...pollo/adminservice/controller/AppNamespaceController.java
+25
-0
apollo-adminservice/src/test/java/com/ctrip/apollo/adminservice/controller/AppNamespaceControllerTest.java
...o/adminservice/controller/AppNamespaceControllerTest.java
+45
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AppNamespaceService.java
...ava/com/ctrip/apollo/biz/service/AppNamespaceService.java
+32
-1
apollo-core/src/main/java/com/ctrip/apollo/core/dto/AppNamespaceDTO.java
.../main/java/com/ctrip/apollo/core/dto/AppNamespaceDTO.java
+9
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
...ain/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
+7
-1
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/NamespaceController.java
...m/ctrip/apollo/portal/controller/NamespaceController.java
+10
-2
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/NamespaceService.java
...ava/com/ctrip/apollo/portal/service/NamespaceService.java
+14
-2
未找到文件。
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppController.java
浏览文件 @
5b7bcc20
...
...
@@ -40,6 +40,7 @@ public class AppController {
entity
=
appService
.
update
(
managedEntity
);
}
else
{
entity
.
setDataChangeCreatedBy
(
user
.
getUsername
());
entity
.
setDataChangeLastModifiedBy
(
user
.
getUsername
());
entity
=
adminService
.
createNewApp
(
entity
);
}
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppNamespaceController.java
浏览文件 @
5b7bcc20
...
...
@@ -2,12 +2,16 @@ package com.ctrip.apollo.adminservice.controller;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ctrip.apollo.biz.entity.AppNamespace
;
import
com.ctrip.apollo.biz.service.AppNamespaceService
;
import
com.ctrip.apollo.common.auth.ActiveUser
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.AppNamespaceDTO
;
...
...
@@ -31,4 +35,25 @@ public class AppNamespaceController {
return
BeanUtils
.
batchTransform
(
AppNamespaceDTO
.
class
,
appNamespaces
);
}
@RequestMapping
(
value
=
"/apps/{appId}/appnamespaces"
,
method
=
RequestMethod
.
POST
)
public
AppNamespaceDTO
createOrUpdate
(
@RequestBody
AppNamespaceDTO
appNamespace
,
@ActiveUser
UserDetails
user
){
AppNamespace
entity
=
BeanUtils
.
transfrom
(
AppNamespace
.
class
,
appNamespace
);
AppNamespace
managedEntity
=
appNamespaceService
.
findOne
(
entity
.
getAppId
(),
entity
.
getName
());
String
userName
=
user
.
getUsername
();
if
(
managedEntity
!=
null
){
managedEntity
.
setDataChangeLastModifiedBy
(
userName
);
BeanUtils
.
copyEntityProperties
(
entity
,
managedEntity
);
entity
=
appNamespaceService
.
update
(
managedEntity
);
}
else
{
entity
.
setDataChangeLastModifiedBy
(
userName
);
entity
.
setDataChangeCreatedBy
(
userName
);
entity
=
appNamespaceService
.
createAppNamespace
(
entity
,
userName
);
}
return
BeanUtils
.
transfrom
(
AppNamespaceDTO
.
class
,
entity
);
}
}
apollo-adminservice/src/test/java/com/ctrip/apollo/adminservice/controller/AppNamespaceControllerTest.java
0 → 100644
浏览文件 @
5b7bcc20
package
com.ctrip.apollo.adminservice.controller
;
import
com.ctrip.apollo.biz.entity.AppNamespace
;
import
com.ctrip.apollo.biz.repository.AppNamespaceRepository
;
import
com.ctrip.apollo.core.dto.AppNamespaceDTO
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.test.context.jdbc.Sql
;
public
class
AppNamespaceControllerTest
extends
AbstractControllerTest
{
@Autowired
private
AppNamespaceRepository
namespaceRepository
;
@Test
@Sql
(
scripts
=
"/controller/cleanup.sql"
,
executionPhase
=
Sql
.
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testCreate
(){
String
appId
=
"6666"
;
String
name
=
"testnamespace"
;
String
comment
=
"comment"
;
AppNamespaceDTO
dto
=
new
AppNamespaceDTO
();
dto
.
setAppId
(
appId
);
dto
.
setName
(
name
);
dto
.
setComment
(
comment
);
AppNamespaceDTO
resultDto
=
restTemplate
.
postForEntity
(
String
.
format
(
"http://localhost:%d/apps/%s/appnamespaces"
,
port
,
appId
),
dto
,
AppNamespaceDTO
.
class
).
getBody
();
Assert
.
assertEquals
(
appId
,
resultDto
.
getAppId
());
Assert
.
assertTrue
(
resultDto
.
getId
()
>
0
);
AppNamespace
savedAppNs
=
namespaceRepository
.
findByAppIdAndName
(
appId
,
name
);
Assert
.
assertNotNull
(
savedAppNs
);
Assert
.
assertNotNull
(
savedAppNs
.
getDataChangeCreatedTime
());
Assert
.
assertNotNull
(
savedAppNs
.
getDataChangeLastModifiedTime
());
Assert
.
assertNotNull
(
savedAppNs
.
getDataChangeLastModifiedBy
());
Assert
.
assertNotNull
(
savedAppNs
.
getDataChangeCreatedBy
());
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AppNamespaceService.java
浏览文件 @
5b7bcc20
...
...
@@ -14,8 +14,10 @@ import org.springframework.transaction.annotation.Transactional;
import
com.ctrip.apollo.biz.entity.AppNamespace
;
import
com.ctrip.apollo.biz.entity.Audit
;
import
com.ctrip.apollo.biz.repository.AppNamespaceRepository
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.ctrip.apollo.core.utils.StringUtils
;
@Service
public
class
AppNamespaceService
{
...
...
@@ -37,6 +39,11 @@ public class AppNamespaceService {
return
appNamespaceRepository
.
findByName
(
namespaceName
);
}
public
AppNamespace
findOne
(
String
appId
,
String
namespaceName
){
Preconditions
.
checkArgument
(!
StringUtils
.
isContainEmpty
(
appId
,
namespaceName
),
"appId or Namespace must not be null"
);
return
appNamespaceRepository
.
findByAppIdAndName
(
appId
,
namespaceName
);
}
@Transactional
public
void
createDefaultAppNamespace
(
String
appId
,
String
createBy
)
{
if
(!
isAppNamespaceNameUnique
(
appId
,
appId
))
{
...
...
@@ -51,10 +58,34 @@ public class AppNamespaceService {
appNamespaceRepository
.
save
(
appNs
);
auditService
.
audit
(
AppNamespace
.
class
.
getSimpleName
(),
appNs
.
getId
(),
Audit
.
OP
.
INSERT
,
createBy
);
createBy
);
}
@Transactional
public
AppNamespace
createAppNamespace
(
AppNamespace
appNamespace
,
String
createBy
){
if
(!
isAppNamespaceNameUnique
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
()))
{
throw
new
ServiceException
(
"appnamespace not unique"
);
}
appNamespace
.
setDataChangeCreatedBy
(
createBy
);
appNamespace
.
setDataChangeLastModifiedBy
(
createBy
);
appNamespace
=
appNamespaceRepository
.
save
(
appNamespace
);
auditService
.
audit
(
AppNamespace
.
class
.
getSimpleName
(),
appNamespace
.
getId
(),
Audit
.
OP
.
INSERT
,
createBy
);
return
appNamespace
;
}
public
List
<
AppNamespace
>
findPublicAppNamespaces
(){
return
appNamespaceRepository
.
findByNameNot
(
ConfigConsts
.
NAMESPACE_DEFAULT
);
}
public
AppNamespace
update
(
AppNamespace
appNamespace
){
AppNamespace
managedNs
=
appNamespaceRepository
.
findByAppIdAndName
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
());
BeanUtils
.
copyEntityProperties
(
appNamespace
,
managedNs
);
managedNs
=
appNamespaceRepository
.
save
(
managedNs
);
auditService
.
audit
(
AppNamespace
.
class
.
getSimpleName
(),
managedNs
.
getId
(),
Audit
.
OP
.
UPDATE
,
managedNs
.
getDataChangeLastModifiedBy
());
return
managedNs
;
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/dto/AppNamespaceDTO.java
浏览文件 @
5b7bcc20
package
com.ctrip.apollo.core.dto
;
public
class
AppNamespaceDTO
{
private
long
id
;
private
String
name
;
...
...
@@ -8,6 +9,14 @@ public class AppNamespaceDTO {
private
String
comment
;
public
long
getId
()
{
return
id
;
}
public
void
setId
(
long
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
浏览文件 @
5b7bcc20
...
...
@@ -70,13 +70,19 @@ public class AdminServiceAPI {
return
Arrays
.
asList
(
appNamespaceDTOs
);
}
public
NamespaceDTO
save
(
Env
env
,
NamespaceDTO
namespace
)
{
public
NamespaceDTO
save
Namespace
(
Env
env
,
NamespaceDTO
namespace
)
{
return
restTemplate
.
postForEntity
(
getAdminServiceHost
(
env
)
+
String
.
format
(
"/apps/%s/clusters/%s/namespaces"
,
namespace
.
getAppId
(),
namespace
.
getClusterName
()),
namespace
,
NamespaceDTO
.
class
)
.
getBody
();
}
public
AppNamespaceDTO
saveAppNamespace
(
Env
env
,
AppNamespaceDTO
appNamespace
)
{
return
restTemplate
.
postForEntity
(
getAdminServiceHost
(
env
)
+
String
.
format
(
"/apps/%s/appnamespaces"
,
appNamespace
.
getAppId
()),
appNamespace
,
AppNamespaceDTO
.
class
)
.
getBody
();
}
}
@Service
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/NamespaceController.java
浏览文件 @
5b7bcc20
...
...
@@ -29,12 +29,20 @@ public class NamespaceController {
}
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces"
,
method
=
RequestMethod
.
POST
)
public
NamespaceDTO
save
(
@PathVariable
String
env
,
@RequestBody
NamespaceDTO
namespace
){
public
NamespaceDTO
save
Namespace
(
@PathVariable
String
env
,
@RequestBody
NamespaceDTO
namespace
){
if
(
StringUtils
.
isContainEmpty
(
env
,
namespace
.
getAppId
(),
namespace
.
getClusterName
(),
namespace
.
getNamespaceName
())){
throw
new
BadRequestException
(
"request payload contains empty"
);
}
return
namespaceService
.
save
(
Env
.
valueOf
(
env
),
namespace
);
return
namespaceService
.
saveNamespace
(
Env
.
valueOf
(
env
),
namespace
);
}
@RequestMapping
(
value
=
"/apps/{appId}/appnamespaces"
,
method
=
RequestMethod
.
POST
)
public
void
saveAppNamespace
(
@PathVariable
String
appId
,
@RequestBody
AppNamespaceDTO
appNamespace
){
if
(
StringUtils
.
isContainEmpty
(
appId
,
appNamespace
.
getAppId
(),
appNamespace
.
getName
())){
throw
new
BadRequestException
(
"request payload contains empty"
);
}
namespaceService
.
saveAppNamespace
(
appNamespace
);
}
@RequestMapping
(
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces"
)
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/NamespaceService.java
浏览文件 @
5b7bcc20
...
...
@@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.HttpClientErrorException
;
import
org.springframework.web.client.HttpStatusCodeException
;
import
java.util.Collections
;
import
java.util.HashMap
;
...
...
@@ -50,8 +51,19 @@ public class NamespaceService {
return
namespaceAPI
.
findPublicAppNamespaces
(
portalSettings
.
getFirstEnv
());
}
public
NamespaceDTO
save
(
Env
env
,
NamespaceDTO
namespace
){
return
namespaceAPI
.
save
(
env
,
namespace
);
public
NamespaceDTO
saveNamespace
(
Env
env
,
NamespaceDTO
namespace
){
return
namespaceAPI
.
saveNamespace
(
env
,
namespace
);
}
public
void
saveAppNamespace
(
AppNamespaceDTO
appNamespace
)
{
for
(
Env
env
:
portalSettings
.
getEnvs
())
{
try
{
namespaceAPI
.
saveAppNamespace
(
env
,
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录