Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
d521b24f
apollo
项目概览
superrain51
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
d521b24f
编写于
4月 21, 2016
作者:
Y
Yiming Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add unique check for app/cluster/namespace
上级
cf7feb30
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
319 addition
and
171 deletion
+319
-171
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppController.java
...m/ctrip/apollo/adminservice/controller/AppController.java
+5
-0
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppNamespaceController.java
...pollo/adminservice/controller/AppNamespaceController.java
+21
-0
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ClusterController.java
...rip/apollo/adminservice/controller/ClusterController.java
+6
-5
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemController.java
.../ctrip/apollo/adminservice/controller/ItemController.java
+1
-5
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/NamespaceController.java
...p/apollo/adminservice/controller/NamespaceController.java
+1
-5
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ReleaseController.java
...rip/apollo/adminservice/controller/ReleaseController.java
+1
-5
apollo-adminservice/src/test/java/com/ctrip/apollo/adminservice/controller/AppControllerTest.java
...rip/apollo/adminservice/controller/AppControllerTest.java
+18
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/AppNamespaceRepository.java
...m/ctrip/apollo/biz/repository/AppNamespaceRepository.java
+2
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AdminService.java
.../main/java/com/ctrip/apollo/biz/service/AdminService.java
+8
-57
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AppNamespaceService.java
...ava/com/ctrip/apollo/biz/service/AppNamespaceService.java
+45
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AppService.java
...rc/main/java/com/ctrip/apollo/biz/service/AppService.java
+10
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ClusterService.java
...ain/java/com/ctrip/apollo/biz/service/ClusterService.java
+43
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemService.java
...c/main/java/com/ctrip/apollo/biz/service/ItemService.java
+21
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/NamespaceService.java
...n/java/com/ctrip/apollo/biz/service/NamespaceService.java
+43
-1
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ReleaseService.java
...ain/java/com/ctrip/apollo/biz/service/ReleaseService.java
+10
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ViewService.java
...c/main/java/com/ctrip/apollo/biz/service/ViewService.java
+0
-84
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/AdminServiceTest.java
...t/java/com/ctrip/apollo/biz/service/AdminServiceTest.java
+30
-4
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/ClusterServiceTest.java
...java/com/ctrip/apollo/biz/service/ClusterServiceTest.java
+46
-0
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/PrivilegeServiceTest.java
...va/com/ctrip/apollo/biz/service/PrivilegeServiceTest.java
+8
-5
未找到文件。
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppController.java
浏览文件 @
d521b24f
...
...
@@ -73,4 +73,9 @@ public class AppController {
return
BeanUtils
.
transfrom
(
AppDTO
.
class
,
app
);
}
@RequestMapping
(
"/apps/{appId}/unique"
)
public
boolean
isAppIdUnique
(
@PathVariable
(
"appId"
)
String
appId
)
{
return
appService
.
isAppIdUnique
(
appId
);
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppNamespaceController.java
0 → 100644
浏览文件 @
d521b24f
package
com.ctrip.apollo.adminservice.controller
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ctrip.apollo.biz.service.AppNamespaceService
;
@RestController
public
class
AppNamespaceController
{
@Autowired
private
AppNamespaceService
appNamespaceService
;
@RequestMapping
(
"/apps/{appId}/appnamespace/{appnamespace}/unique"
)
public
boolean
isAppNamespaceUnique
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"appnamespace"
)
String
appnamespace
)
{
return
appNamespaceService
.
isAppNamespaceNameUnique
(
appId
,
appnamespace
);
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ClusterController.java
浏览文件 @
d521b24f
...
...
@@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.RestController;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.service.ClusterService
;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.common.auth.ActiveUser
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
...
...
@@ -21,9 +20,6 @@ import com.ctrip.apollo.core.exception.NotFoundException;
@RestController
public
class
ClusterController
{
@Autowired
private
ViewService
viewService
;
@Autowired
private
ClusterService
clusterService
;
...
...
@@ -56,7 +52,7 @@ public class ClusterController {
@RequestMapping
(
"/apps/{appId}/clusters"
)
public
List
<
ClusterDTO
>
find
(
@PathVariable
(
"appId"
)
String
appId
)
{
List
<
Cluster
>
clusters
=
view
Service
.
findClusters
(
appId
);
List
<
Cluster
>
clusters
=
cluster
Service
.
findClusters
(
appId
);
return
BeanUtils
.
batchTransform
(
ClusterDTO
.
class
,
clusters
);
}
...
...
@@ -68,4 +64,9 @@ public class ClusterController {
return
BeanUtils
.
transfrom
(
ClusterDTO
.
class
,
cluster
);
}
@RequestMapping
(
"/apps/{appId}/cluster/{clusterName}/unique"
)
public
boolean
isAppIdUnique
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
)
{
return
clusterService
.
isClusterNameUnique
(
appId
,
clusterName
);
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemController.java
浏览文件 @
d521b24f
...
...
@@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.RestController;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.service.ItemService
;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.common.auth.ActiveUser
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
...
...
@@ -22,9 +21,6 @@ import com.ctrip.apollo.core.exception.NotFoundException;
@RestController
public
class
ItemController
{
@Autowired
private
ViewService
viewService
;
@Autowired
private
ItemService
itemService
;
...
...
@@ -59,7 +55,7 @@ public class ItemController {
public
List
<
ItemDTO
>
findItems
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
List
<
Item
>
items
=
view
Service
.
findItems
(
appId
,
clusterName
,
namespaceName
);
List
<
Item
>
items
=
item
Service
.
findItems
(
appId
,
clusterName
,
namespaceName
);
List
<
ItemDTO
>
itemDTOs
=
new
LinkedList
<>();
for
(
Item
item:
items
){
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/NamespaceController.java
浏览文件 @
d521b24f
...
...
@@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.RestController;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.service.NamespaceService
;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.common.auth.ActiveUser
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
...
...
@@ -21,9 +20,6 @@ import com.ctrip.apollo.core.exception.NotFoundException;
@RestController
public
class
NamespaceController
{
@Autowired
private
ViewService
viewService
;
@Autowired
private
NamespaceService
namespaceService
;
...
...
@@ -59,7 +55,7 @@ public class NamespaceController {
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces"
)
public
List
<
NamespaceDTO
>
find
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
)
{
List
<
Namespace
>
groups
=
view
Service
.
findNamespaces
(
appId
,
clusterName
);
List
<
Namespace
>
groups
=
namespace
Service
.
findNamespaces
(
appId
,
clusterName
);
return
BeanUtils
.
batchTransform
(
NamespaceDTO
.
class
,
groups
);
}
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ReleaseController.java
浏览文件 @
d521b24f
...
...
@@ -15,7 +15,6 @@ import com.ctrip.apollo.biz.entity.Release;
import
com.ctrip.apollo.biz.service.ConfigService
;
import
com.ctrip.apollo.biz.service.NamespaceService
;
import
com.ctrip.apollo.biz.service.ReleaseService
;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.common.auth.ActiveUser
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
...
...
@@ -24,9 +23,6 @@ import com.ctrip.apollo.core.exception.NotFoundException;
@RestController
public
class
ReleaseController
{
@Autowired
private
ViewService
viewSerivce
;
@Autowired
private
ReleaseService
releaseService
;
...
...
@@ -48,7 +44,7 @@ public class ReleaseController {
public
List
<
ReleaseDTO
>
find
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
List
<
Release
>
releases
=
viewSeriv
ce
.
findReleases
(
appId
,
clusterName
,
namespaceName
);
List
<
Release
>
releases
=
releaseServi
ce
.
findReleases
(
appId
,
clusterName
,
namespaceName
);
return
BeanUtils
.
batchTransform
(
ReleaseDTO
.
class
,
releases
);
}
...
...
apollo-adminservice/src/test/java/com/ctrip/apollo/adminservice/controller/AppControllerTest.java
浏览文件 @
d521b24f
...
...
@@ -23,6 +23,24 @@ public class AppControllerTest extends AbstractControllerTest {
return
"http://localhost:"
+
port
+
"/apps/"
;
}
@Test
public
void
testCheckIfAppIdUnique
()
{
AppDTO
dto
=
generateSampleDTOData
();
ResponseEntity
<
AppDTO
>
response
=
restTemplate
.
postForEntity
(
getBaseAppUrl
(),
dto
,
AppDTO
.
class
);
AppDTO
result
=
response
.
getBody
();
Assert
.
assertEquals
(
HttpStatus
.
OK
,
response
.
getStatusCode
());
Assert
.
assertEquals
(
dto
.
getAppId
(),
result
.
getAppId
());
Assert
.
assertTrue
(
result
.
getId
()
>
0
);
Boolean
falseUnique
=
restTemplate
.
getForObject
(
getBaseAppUrl
()
+
dto
.
getAppId
()
+
"/unique"
,
Boolean
.
class
);
Assert
.
assertFalse
(
falseUnique
);
Boolean
trueUnique
=
restTemplate
.
getForObject
(
getBaseAppUrl
()
+
dto
.
getAppId
()
+
"true"
+
"/unique"
,
Boolean
.
class
);
Assert
.
assertTrue
(
trueUnique
);
}
@Test
@Sql
(
scripts
=
"/controller/cleanup.sql"
,
executionPhase
=
ExecutionPhase
.
AFTER_TEST_METHOD
)
public
void
testCreate
()
{
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/AppNamespaceRepository.java
浏览文件 @
d521b24f
...
...
@@ -6,4 +6,6 @@ import com.ctrip.apollo.biz.entity.AppNamespace;
public
interface
AppNamespaceRepository
extends
PagingAndSortingRepository
<
AppNamespace
,
Long
>{
AppNamespace
findByAppIdAndName
(
String
appId
,
String
namespaceName
);
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AdminService.java
浏览文件 @
d521b24f
...
...
@@ -5,85 +5,36 @@ import org.springframework.stereotype.Service;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.apollo.biz.entity.App
;
import
com.ctrip.apollo.biz.entity.AppNamespace
;
import
com.ctrip.apollo.biz.entity.Audit
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.repository.AppNamespaceRepository
;
import
com.ctrip.apollo.biz.repository.AppRepository
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
import
com.ctrip.apollo.biz.repository.NamespaceRepository
;
import
com.ctrip.apollo.core.ConfigConsts
;
@Service
public
class
AdminService
{
@Autowired
private
App
Repository
appRepository
;
private
App
Service
appService
;
@Autowired
private
AppNamespace
Repository
appNamespaceRepository
;
private
AppNamespace
Service
appNamespaceService
;
@Autowired
private
NamespaceRepository
namespaceRepository
;
private
ClusterService
clusterService
;
@Autowired
private
ClusterRepository
clusterRepository
;
@Autowired
private
AuditService
auditService
;
private
NamespaceService
namespaceService
;
@Transactional
public
App
createNewApp
(
App
app
)
{
String
createBy
=
app
.
getDataChangeCreatedBy
();
App
createdApp
=
appRepository
.
save
(
app
);
auditService
.
audit
(
App
.
class
.
getSimpleName
(),
createdApp
.
getId
(),
Audit
.
OP
.
INSERT
,
createBy
);
App
createdApp
=
appService
.
save
(
app
);
String
appId
=
createdApp
.
getAppId
();
createDefaultAppNamespace
(
appId
,
createBy
);
appNamespaceService
.
createDefaultAppNamespace
(
appId
,
createBy
);
createDefaultCluster
(
appId
,
createBy
);
c
lusterService
.
c
reateDefaultCluster
(
appId
,
createBy
);
createDefaultNamespace
(
appId
,
createBy
);
namespaceService
.
createDefaultNamespace
(
appId
,
createBy
);
return
app
;
}
private
void
createDefaultAppNamespace
(
String
appId
,
String
createBy
)
{
AppNamespace
appNs
=
new
AppNamespace
();
appNs
.
setAppId
(
appId
);
appNs
.
setName
(
appId
);
appNs
.
setComment
(
"default app namespace"
);
appNs
.
setDataChangeCreatedBy
(
createBy
);
appNs
.
setDataChangeLastModifiedBy
(
createBy
);
appNamespaceRepository
.
save
(
appNs
);
auditService
.
audit
(
AppNamespace
.
class
.
getSimpleName
(),
appNs
.
getId
(),
Audit
.
OP
.
INSERT
,
createBy
);
}
private
void
createDefaultCluster
(
String
appId
,
String
createBy
)
{
Cluster
cluster
=
new
Cluster
();
cluster
.
setName
(
ConfigConsts
.
CLUSTER_NAME_DEFAULT
);
cluster
.
setAppId
(
appId
);
cluster
.
setDataChangeCreatedBy
(
createBy
);
cluster
.
setDataChangeLastModifiedBy
(
createBy
);
clusterRepository
.
save
(
cluster
);
auditService
.
audit
(
Cluster
.
class
.
getSimpleName
(),
cluster
.
getId
(),
Audit
.
OP
.
INSERT
,
createBy
);
}
private
void
createDefaultNamespace
(
String
appId
,
String
createBy
)
{
Namespace
ns
=
new
Namespace
();
ns
.
setAppId
(
appId
);
ns
.
setClusterName
(
ConfigConsts
.
CLUSTER_NAME_DEFAULT
);
ns
.
setNamespaceName
(
appId
);
ns
.
setDataChangeCreatedBy
(
createBy
);
ns
.
setDataChangeLastModifiedBy
(
createBy
);
namespaceRepository
.
save
(
ns
);
auditService
.
audit
(
Namespace
.
class
.
getSimpleName
(),
ns
.
getId
(),
Audit
.
OP
.
INSERT
,
createBy
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AppNamespaceService.java
0 → 100644
浏览文件 @
d521b24f
package
com.ctrip.apollo.biz.service
;
import
java.util.Objects
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
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.core.exception.ServiceException
;
@Service
public
class
AppNamespaceService
{
@Autowired
private
AppNamespaceRepository
appNamespaceRepository
;
@Autowired
private
AuditService
auditService
;
public
boolean
isAppNamespaceNameUnique
(
String
appId
,
String
namespaceName
)
{
Objects
.
requireNonNull
(
appId
,
"AppId must not be null"
);
Objects
.
requireNonNull
(
namespaceName
,
"Namespace must not be null"
);
return
Objects
.
isNull
(
appNamespaceRepository
.
findByAppIdAndName
(
appId
,
namespaceName
));
}
@Transactional
public
void
createDefaultAppNamespace
(
String
appId
,
String
createBy
)
{
if
(!
isAppNamespaceNameUnique
(
appId
,
appId
))
{
throw
new
ServiceException
(
"appnamespace not unique"
);
}
AppNamespace
appNs
=
new
AppNamespace
();
appNs
.
setAppId
(
appId
);
appNs
.
setName
(
appId
);
appNs
.
setComment
(
"default app namespace"
);
appNs
.
setDataChangeCreatedBy
(
createBy
);
appNs
.
setDataChangeLastModifiedBy
(
createBy
);
appNamespaceRepository
.
save
(
appNs
);
auditService
.
audit
(
AppNamespace
.
class
.
getSimpleName
(),
appNs
.
getId
(),
Audit
.
OP
.
INSERT
,
createBy
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AppService.java
浏览文件 @
d521b24f
package
com.ctrip.apollo.biz.service
;
import
java.util.List
;
import
java.util.Objects
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
...
...
@@ -12,6 +13,7 @@ import com.ctrip.apollo.biz.entity.App;
import
com.ctrip.apollo.biz.entity.Audit
;
import
com.ctrip.apollo.biz.repository.AppRepository
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.exception.ServiceException
;
@Service
public
class
AppService
{
...
...
@@ -22,6 +24,11 @@ public class AppService {
@Autowired
private
AuditService
auditService
;
public
boolean
isAppIdUnique
(
String
appId
)
{
Objects
.
requireNonNull
(
appId
,
"AppId must not be null"
);
return
Objects
.
isNull
(
appRepository
.
findByAppId
(
appId
));
}
@Transactional
public
void
delete
(
long
id
,
String
owner
)
{
appRepository
.
delete
(
id
);
...
...
@@ -44,6 +51,9 @@ public class AppService {
@Transactional
public
App
save
(
App
entity
)
{
if
(!
isAppIdUnique
(
entity
.
getAppId
()))
{
throw
new
ServiceException
(
"appId not unique"
);
}
App
app
=
appRepository
.
save
(
entity
);
auditService
.
audit
(
App
.
class
.
getSimpleName
(),
app
.
getId
(),
Audit
.
OP
.
INSERT
,
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ClusterService.java
浏览文件 @
d521b24f
package
com.ctrip.apollo.biz.service
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Objects
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -8,6 +12,9 @@ import com.ctrip.apollo.biz.entity.Audit;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.google.common.base.Strings
;
@Service
public
class
ClusterService
{
...
...
@@ -18,12 +25,33 @@ public class ClusterService {
@Autowired
private
AuditService
auditService
;
public
boolean
isClusterNameUnique
(
String
appId
,
String
clusterName
)
{
Objects
.
requireNonNull
(
appId
,
"AppId must not be null"
);
Objects
.
requireNonNull
(
clusterName
,
"ClusterName must not be null"
);
return
Objects
.
isNull
(
clusterRepository
.
findByAppIdAndName
(
appId
,
clusterName
));
}
public
Cluster
findOne
(
String
appId
,
String
name
)
{
return
clusterRepository
.
findByAppIdAndName
(
appId
,
name
);
}
public
List
<
Cluster
>
findClusters
(
String
appId
)
{
if
(
Strings
.
isNullOrEmpty
(
appId
))
{
return
Collections
.
emptyList
();
}
List
<
Cluster
>
clusters
=
clusterRepository
.
findByAppId
(
appId
);
if
(
clusters
==
null
)
{
return
Collections
.
emptyList
();
}
return
clusters
;
}
@Transactional
public
Cluster
save
(
Cluster
entity
)
{
if
(!
isClusterNameUnique
(
entity
.
getAppId
(),
entity
.
getName
()))
{
throw
new
ServiceException
(
"cluster not unique"
);
}
Cluster
cluster
=
clusterRepository
.
save
(
entity
);
auditService
.
audit
(
Cluster
.
class
.
getSimpleName
(),
cluster
.
getId
(),
Audit
.
OP
.
INSERT
,
...
...
@@ -51,4 +79,19 @@ public class ClusterService {
return
managedCluster
;
}
@Transactional
public
void
createDefaultCluster
(
String
appId
,
String
createBy
)
{
if
(!
isClusterNameUnique
(
appId
,
ConfigConsts
.
CLUSTER_NAME_DEFAULT
))
{
throw
new
ServiceException
(
"cluster not unique"
);
}
Cluster
cluster
=
new
Cluster
();
cluster
.
setName
(
ConfigConsts
.
CLUSTER_NAME_DEFAULT
);
cluster
.
setAppId
(
appId
);
cluster
.
setDataChangeCreatedBy
(
createBy
);
cluster
.
setDataChangeLastModifiedBy
(
createBy
);
clusterRepository
.
save
(
cluster
);
auditService
.
audit
(
Cluster
.
class
.
getSimpleName
(),
cluster
.
getId
(),
Audit
.
OP
.
INSERT
,
createBy
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemService.java
浏览文件 @
d521b24f
package
com.ctrip.apollo.biz.service
;
import
java.util.Collections
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -47,6 +50,24 @@ public class ItemService {
return
item
;
}
public
List
<
Item
>
findItems
(
Long
namespaceId
)
{
List
<
Item
>
items
=
itemRepository
.
findByNamespaceIdOrderByLineNumAsc
(
namespaceId
);
if
(
items
==
null
)
{
return
Collections
.
emptyList
();
}
return
items
;
}
public
List
<
Item
>
findItems
(
String
appId
,
String
clusterName
,
String
namespaceName
)
{
Namespace
group
=
namespaceRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
namespaceName
);
if
(
group
!=
null
)
{
return
findItems
(
group
.
getId
());
}
else
{
return
Collections
.
emptyList
();
}
}
@Transactional
public
Item
save
(
Item
entity
)
{
Item
item
=
itemRepository
.
save
(
entity
);
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/NamespaceService.java
浏览文件 @
d521b24f
package
com.ctrip.apollo.biz.service
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.Objects
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
...
...
@@ -8,6 +12,8 @@ import com.ctrip.apollo.biz.entity.Audit;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.repository.NamespaceRepository
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.exception.ServiceException
;
@Service
public
class
NamespaceService
{
...
...
@@ -18,6 +24,14 @@ public class NamespaceService {
@Autowired
private
AuditService
auditService
;
public
boolean
isNamespaceUnique
(
String
appId
,
String
cluster
,
String
namespace
)
{
Objects
.
requireNonNull
(
appId
,
"AppId must not be null"
);
Objects
.
requireNonNull
(
cluster
,
"Cluster must not be null"
);
Objects
.
requireNonNull
(
namespace
,
"Namespace must not be null"
);
return
Objects
.
isNull
(
namespaceRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
cluster
,
namespace
));
}
@Transactional
public
void
delete
(
long
id
,
String
owner
)
{
namespaceRepository
.
delete
(
id
);
...
...
@@ -34,8 +48,19 @@ public class NamespaceService {
namespaceName
);
}
public
List
<
Namespace
>
findNamespaces
(
String
appId
,
String
clusterName
)
{
List
<
Namespace
>
groups
=
namespaceRepository
.
findByAppIdAndClusterName
(
appId
,
clusterName
);
if
(
groups
==
null
)
{
return
Collections
.
emptyList
();
}
return
groups
;
}
@Transactional
public
Namespace
save
(
Namespace
entity
)
{
if
(!
isNamespaceUnique
(
entity
.
getAppId
(),
entity
.
getClusterName
(),
entity
.
getNamespaceName
()))
{
throw
new
ServiceException
(
"namespace not unique"
);
}
Namespace
namespace
=
namespaceRepository
.
save
(
entity
);
auditService
.
audit
(
Namespace
.
class
.
getSimpleName
(),
namespace
.
getId
(),
Audit
.
OP
.
INSERT
,
...
...
@@ -53,7 +78,24 @@ public class NamespaceService {
auditService
.
audit
(
Namespace
.
class
.
getSimpleName
(),
managedNamespace
.
getId
(),
Audit
.
OP
.
UPDATE
,
managedNamespace
.
getDataChangeLastModifiedBy
());
return
managedNamespace
;
}
@Transactional
public
void
createDefaultNamespace
(
String
appId
,
String
createBy
)
{
if
(!
isNamespaceUnique
(
appId
,
ConfigConsts
.
CLUSTER_NAME_DEFAULT
,
appId
))
{
throw
new
ServiceException
(
"namespace not unique"
);
}
Namespace
ns
=
new
Namespace
();
ns
.
setAppId
(
appId
);
ns
.
setClusterName
(
ConfigConsts
.
CLUSTER_NAME_DEFAULT
);
ns
.
setNamespaceName
(
appId
);
ns
.
setDataChangeCreatedBy
(
createBy
);
ns
.
setDataChangeLastModifiedBy
(
createBy
);
namespaceRepository
.
save
(
ns
);
auditService
.
audit
(
Namespace
.
class
.
getSimpleName
(),
ns
.
getId
(),
Audit
.
OP
.
INSERT
,
createBy
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ReleaseService.java
浏览文件 @
d521b24f
package
com.ctrip.apollo.biz.service
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.List
;
...
...
@@ -40,6 +41,15 @@ public class ReleaseService {
return
release
;
}
public
List
<
Release
>
findReleases
(
String
appId
,
String
clusterName
,
String
namespaceName
)
{
List
<
Release
>
releases
=
releaseRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
namespaceName
);
if
(
releases
==
null
)
{
return
Collections
.
emptyList
();
}
return
releases
;
}
@Transactional
public
Release
buildRelease
(
String
name
,
String
comment
,
Namespace
namespace
,
String
owner
)
{
List
<
Item
>
items
=
itemRepository
.
findByNamespaceIdOrderByLineNumAsc
(
namespace
.
getId
());
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ViewService.java
已删除
100644 → 0
浏览文件 @
cf7feb30
package
com.ctrip.apollo.biz.service
;
import
java.util.Collections
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.entity.Release
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
import
com.ctrip.apollo.biz.repository.NamespaceRepository
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.biz.repository.ReleaseRepository
;
import
com.google.common.base.Strings
;
/**
* config service for admin
*/
@Service
public
class
ViewService
{
@Autowired
private
ClusterRepository
clusterRepository
;
@Autowired
private
NamespaceRepository
namespaceRepository
;
@Autowired
private
ItemRepository
itemRepository
;
@Autowired
private
ReleaseRepository
releaseRepository
;
public
List
<
Cluster
>
findClusters
(
String
appId
)
{
if
(
Strings
.
isNullOrEmpty
(
appId
))
{
return
Collections
.
emptyList
();
}
List
<
Cluster
>
clusters
=
clusterRepository
.
findByAppId
(
appId
);
if
(
clusters
==
null
)
{
return
Collections
.
emptyList
();
}
return
clusters
;
}
public
List
<
Namespace
>
findNamespaces
(
String
appId
,
String
clusterName
)
{
List
<
Namespace
>
groups
=
namespaceRepository
.
findByAppIdAndClusterName
(
appId
,
clusterName
);
if
(
groups
==
null
)
{
return
Collections
.
emptyList
();
}
return
groups
;
}
public
List
<
Item
>
findItems
(
String
appId
,
String
clusterName
,
String
namespaceName
)
{
Namespace
group
=
namespaceRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
namespaceName
);
if
(
group
!=
null
)
{
return
findItems
(
group
.
getId
());
}
else
{
return
Collections
.
emptyList
();
}
}
public
List
<
Item
>
findItems
(
Long
namespaceId
)
{
List
<
Item
>
items
=
itemRepository
.
findByNamespaceIdOrderByLineNumAsc
(
namespaceId
);
if
(
items
==
null
)
{
return
Collections
.
emptyList
();
}
return
items
;
}
public
List
<
Release
>
findReleases
(
String
appId
,
String
clusterName
,
String
namespaceName
)
{
List
<
Release
>
releases
=
releaseRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
namespaceName
);
if
(
releases
==
null
)
{
return
Collections
.
emptyList
();
}
return
releases
;
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/AdminServiceTest.java
浏览文件 @
d521b24f
...
...
@@ -17,7 +17,9 @@ import com.ctrip.apollo.biz.entity.App;
import
com.ctrip.apollo.biz.entity.Audit
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.repository.AppRepository
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.exception.ServiceException
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
BizTestConfiguration
.
class
)
...
...
@@ -29,10 +31,16 @@ public class AdminServiceTest {
private
AdminService
adminService
;
@Autowired
private
ViewService
view
Service
;
private
AuditService
audit
Service
;
@Autowired
private
AuditService
auditService
;
private
AppRepository
appRepository
;
@Autowired
private
ClusterService
clsuterService
;
@Autowired
private
NamespaceService
namespaceService
;
@Test
public
void
testCreateNewApp
()
{
...
...
@@ -50,11 +58,11 @@ public class AdminServiceTest {
app
=
adminService
.
createNewApp
(
app
);
Assert
.
assertEquals
(
appId
,
app
.
getAppId
());
List
<
Cluster
>
clusters
=
view
Service
.
findClusters
(
app
.
getAppId
());
List
<
Cluster
>
clusters
=
clsuter
Service
.
findClusters
(
app
.
getAppId
());
Assert
.
assertEquals
(
1
,
clusters
.
size
());
Assert
.
assertEquals
(
ConfigConsts
.
CLUSTER_NAME_DEFAULT
,
clusters
.
get
(
0
).
getName
());
List
<
Namespace
>
namespaces
=
view
Service
.
findNamespaces
(
appId
,
clusters
.
get
(
0
).
getName
());
List
<
Namespace
>
namespaces
=
namespace
Service
.
findNamespaces
(
appId
,
clusters
.
get
(
0
).
getName
());
Assert
.
assertEquals
(
1
,
namespaces
.
size
());
Assert
.
assertEquals
(
appId
,
namespaces
.
get
(
0
).
getNamespaceName
());
...
...
@@ -62,4 +70,22 @@ public class AdminServiceTest {
Assert
.
assertEquals
(
4
,
audits
.
size
());
}
@Test
(
expected
=
ServiceException
.
class
)
public
void
testCreateDuplicateApp
()
{
String
appId
=
"someAppId"
;
App
app
=
new
App
();
app
.
setAppId
(
appId
);
app
.
setName
(
"someAppName"
);
String
owner
=
"someOwnerName"
;
app
.
setOwnerName
(
owner
);
app
.
setOwnerEmail
(
"someOwnerName@ctrip.com"
);
app
.
setDataChangeCreatedBy
(
owner
);
app
.
setDataChangeLastModifiedBy
(
owner
);
app
.
setDataChangeCreatedTime
(
new
Date
());
appRepository
.
save
(
app
);
adminService
.
createNewApp
(
app
);
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/ClusterServiceTest.java
0 → 100644
浏览文件 @
d521b24f
package
com.ctrip.apollo.biz.service
;
import
java.util.Date
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.annotation.Rollback
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.transaction.annotation.Transactional
;
import
com.ctrip.apollo.biz.BizTestConfiguration
;
import
com.ctrip.apollo.biz.entity.App
;
import
com.ctrip.apollo.core.exception.ServiceException
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
BizTestConfiguration
.
class
)
@Transactional
@Rollback
public
class
ClusterServiceTest
{
@Autowired
private
AdminService
adminService
;
@Autowired
private
ClusterService
clusterService
;
@Test
(
expected
=
ServiceException
.
class
)
public
void
testCreateDuplicateCluster
()
{
String
appId
=
"someAppId"
;
App
app
=
new
App
();
app
.
setAppId
(
appId
);
app
.
setName
(
"someAppName"
);
String
owner
=
"someOwnerName"
;
app
.
setOwnerName
(
owner
);
app
.
setOwnerEmail
(
"someOwnerName@ctrip.com"
);
app
.
setDataChangeCreatedBy
(
owner
);
app
.
setDataChangeLastModifiedBy
(
owner
);
app
.
setDataChangeCreatedTime
(
new
Date
());
adminService
.
createNewApp
(
app
);
clusterService
.
createDefaultCluster
(
appId
,
owner
);
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/PrivilegeServiceTest.java
浏览文件 @
d521b24f
...
...
@@ -28,8 +28,11 @@ public class PrivilegeServiceTest {
private
AdminService
adminService
;
@Autowired
private
ViewService
view
Service
;
private
ClusterService
cluster
Service
;
@Autowired
private
NamespaceService
namespaceService
;
@Autowired
private
PrivilegeService
privilService
;
...
...
@@ -46,9 +49,9 @@ public class PrivilegeServiceTest {
app
.
setDataChangeCreatedTime
(
new
Date
());
App
newApp
=
adminService
.
createNewApp
(
app
);
List
<
Cluster
>
clusters
=
view
Service
.
findClusters
(
newApp
.
getAppId
());
List
<
Cluster
>
clusters
=
cluster
Service
.
findClusters
(
newApp
.
getAppId
());
List
<
Namespace
>
namespaces
=
view
Service
.
findNamespaces
(
newApp
.
getAppId
(),
clusters
.
get
(
0
).
getName
());
namespace
Service
.
findNamespaces
(
newApp
.
getAppId
(),
clusters
.
get
(
0
).
getName
());
Namespace
namespace
=
namespaces
.
get
(
0
);
privilService
.
addPrivilege
(
namespace
.
getId
(),
newApp
.
getOwnerName
(),
...
...
@@ -76,9 +79,9 @@ public class PrivilegeServiceTest {
app
.
setDataChangeLastModifiedBy
(
owner
);
app
.
setDataChangeCreatedTime
(
new
Date
());
App
newApp
=
adminService
.
createNewApp
(
app
);
List
<
Cluster
>
clusters
=
view
Service
.
findClusters
(
newApp
.
getAppId
());
List
<
Cluster
>
clusters
=
cluster
Service
.
findClusters
(
newApp
.
getAppId
());
List
<
Namespace
>
namespaces
=
view
Service
.
findNamespaces
(
newApp
.
getAppId
(),
clusters
.
get
(
0
).
getName
());
namespace
Service
.
findNamespaces
(
newApp
.
getAppId
(),
clusters
.
get
(
0
).
getName
());
Namespace
namespace
=
namespaces
.
get
(
0
);
privilService
.
addPrivilege
(
namespace
.
getId
(),
newApp
.
getOwnerName
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录