Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
a3ba41c0
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
a3ba41c0
编写于
4月 12, 2016
作者:
J
Jason Song
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #76 from yiming187/cluster_update
Add CRUD for Cluster and Namespace Entity
上级
24ab7fb2
48c2474b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
137 addition
and
29 deletion
+137
-29
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppController.java
...m/ctrip/apollo/adminservice/controller/AppController.java
+17
-17
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ClusterController.java
...rip/apollo/adminservice/controller/ClusterController.java
+39
-2
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/NamespaceController.java
...p/apollo/adminservice/controller/NamespaceController.java
+47
-8
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ClusterService.java
...ain/java/com/ctrip/apollo/biz/service/ClusterService.java
+17
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/NamespaceService.java
...n/java/com/ctrip/apollo/biz/service/NamespaceService.java
+17
-2
未找到文件。
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppController.java
浏览文件 @
a3ba41c0
...
...
@@ -27,22 +27,22 @@ public class AppController {
private
AppService
appService
;
@RequestMapping
(
path
=
"/apps/"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
AppDTO
>
create
App
(
@RequestBody
AppDTO
appDTO
)
{
App
app
=
BeanUtils
.
transfrom
(
App
.
class
,
appDTO
);
app
=
appService
.
save
(
app
);
AppDTO
dto
=
BeanUtils
.
transfrom
(
AppDTO
.
class
,
app
);
public
ResponseEntity
<
AppDTO
>
create
(
@RequestBody
AppDTO
dto
)
{
App
entity
=
BeanUtils
.
transfrom
(
App
.
class
,
dto
);
entity
=
appService
.
save
(
entity
);
dto
=
BeanUtils
.
transfrom
(
AppDTO
.
class
,
entity
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
dto
);
}
@RequestMapping
(
path
=
"/apps/{appId}"
,
method
=
RequestMethod
.
DELETE
)
public
void
delete
App
(
@PathVariable
(
"appId"
)
String
appId
)
{
App
app
=
appService
.
findOne
(
appId
);
if
(
app
==
null
)
throw
new
NotFoundException
(
"app not found for appId "
+
appId
);
appService
.
delete
(
app
.
getId
());
public
void
delete
(
@PathVariable
(
"appId"
)
String
appId
)
{
App
entity
=
appService
.
findOne
(
appId
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
"app not found for appId "
+
appId
);
appService
.
delete
(
entity
.
getId
());
}
@RequestMapping
(
"/apps"
)
public
List
<
AppDTO
>
find
Apps
(
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
public
List
<
AppDTO
>
find
(
@RequestParam
(
value
=
"name"
,
required
=
false
)
String
name
,
Pageable
pageable
)
{
List
<
App
>
app
=
null
;
if
(
StringUtils
.
isBlank
(
name
))
{
...
...
@@ -54,22 +54,22 @@ public class AppController {
}
@RequestMapping
(
"/apps/{appId}"
)
public
AppDTO
get
App
(
@PathVariable
(
"appId"
)
String
appId
)
{
public
AppDTO
get
(
@PathVariable
(
"appId"
)
String
appId
)
{
App
app
=
appService
.
findOne
(
appId
);
if
(
app
==
null
)
throw
new
NotFoundException
(
"app not found for appId "
+
appId
);
return
BeanUtils
.
transfrom
(
AppDTO
.
class
,
app
);
}
@RequestMapping
(
path
=
"/apps/{appId}"
,
method
=
RequestMethod
.
PUT
)
public
AppDTO
update
App
(
@PathVariable
(
"appId"
)
String
appId
,
@RequestBody
AppDTO
appDTO
)
{
if
(!
appId
.
equals
(
appDTO
.
getAppId
()))
{
public
AppDTO
update
(
@PathVariable
(
"appId"
)
String
appId
,
@RequestBody
AppDTO
dto
)
{
if
(!
appId
.
equals
(
dto
.
getAppId
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
appId
,
appDTO
.
getAppId
()));
.
format
(
"Path variable %s is not equals to object field %s"
,
appId
,
dto
.
getAppId
()));
}
App
app
=
appService
.
findOne
(
appId
);
if
(
app
==
null
)
throw
new
NotFoundException
(
"app not found for appId "
+
appId
);
app
=
appService
.
update
(
BeanUtils
.
transfrom
(
App
.
class
,
appDTO
));
return
BeanUtils
.
transfrom
(
AppDTO
.
class
,
app
);
App
entity
=
appService
.
findOne
(
appId
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
"app not found for appId "
+
appId
);
entity
=
appService
.
update
(
BeanUtils
.
transfrom
(
App
.
class
,
dto
));
return
BeanUtils
.
transfrom
(
AppDTO
.
class
,
entity
);
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ClusterController.java
浏览文件 @
a3ba41c0
...
...
@@ -3,8 +3,12 @@ package com.ctrip.apollo.adminservice.controller;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
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.Cluster
;
...
...
@@ -12,6 +16,7 @@ import com.ctrip.apollo.biz.service.ClusterService;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.exception.NotFoundException
;
@RestController
public
class
ClusterController
{
...
...
@@ -22,16 +27,48 @@ public class ClusterController {
@Autowired
private
ClusterService
clusterService
;
@RequestMapping
(
path
=
"/apps/{appId}/clusters"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
ClusterDTO
>
create
(
@PathVariable
(
"appId"
)
String
appId
,
@RequestBody
ClusterDTO
dto
)
{
Cluster
entity
=
BeanUtils
.
transfrom
(
Cluster
.
class
,
dto
);
entity
=
clusterService
.
save
(
entity
);
dto
=
BeanUtils
.
transfrom
(
ClusterDTO
.
class
,
entity
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
dto
);
}
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}"
,
method
=
RequestMethod
.
DELETE
)
public
void
delete
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
)
{
Cluster
entity
=
clusterService
.
findOne
(
appId
,
clusterName
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
"cluster not found for clusterName "
+
clusterName
);
clusterService
.
delete
(
entity
.
getId
());
}
@RequestMapping
(
"/apps/{appId}/clusters"
)
public
List
<
ClusterDTO
>
find
Clusters
(
@PathVariable
(
"appId"
)
String
appId
)
{
public
List
<
ClusterDTO
>
find
(
@PathVariable
(
"appId"
)
String
appId
)
{
List
<
Cluster
>
clusters
=
viewService
.
findClusters
(
appId
);
return
BeanUtils
.
batchTransform
(
ClusterDTO
.
class
,
clusters
);
}
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}"
)
public
ClusterDTO
get
Cluster
(
@PathVariable
(
"appId"
)
String
appId
,
public
ClusterDTO
get
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
)
{
Cluster
cluster
=
clusterService
.
findOne
(
appId
,
clusterName
);
return
BeanUtils
.
transfrom
(
ClusterDTO
.
class
,
cluster
);
}
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}"
,
method
=
RequestMethod
.
PUT
)
public
ClusterDTO
update
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@RequestBody
ClusterDTO
dto
)
{
if
(!
clusterName
.
equals
(
dto
.
getName
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
clusterName
,
dto
.
getName
()));
}
Cluster
entity
=
clusterService
.
findOne
(
appId
,
clusterName
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
"cluster not found for name "
+
clusterName
);
entity
=
clusterService
.
update
(
BeanUtils
.
transfrom
(
Cluster
.
class
,
dto
));
return
BeanUtils
.
transfrom
(
ClusterDTO
.
class
,
entity
);
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/NamespaceController.java
浏览文件 @
a3ba41c0
...
...
@@ -3,8 +3,12 @@ package com.ctrip.apollo.adminservice.controller;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
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.Namespace
;
...
...
@@ -12,6 +16,7 @@ import com.ctrip.apollo.biz.service.NamespaceService;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.exception.NotFoundException
;
@RestController
public
class
NamespaceController
{
...
...
@@ -22,25 +27,59 @@ public class NamespaceController {
@Autowired
private
NamespaceService
namespaceService
;
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
NamespaceDTO
>
create
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@RequestBody
NamespaceDTO
dto
)
{
Namespace
entity
=
BeanUtils
.
transfrom
(
Namespace
.
class
,
dto
);
entity
=
namespaceService
.
save
(
entity
);
dto
=
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
entity
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
dto
);
}
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}"
,
method
=
RequestMethod
.
DELETE
)
public
void
delete
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
Namespace
entity
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
"namespace not found for namespaceName "
+
namespaceName
);
namespaceService
.
delete
(
entity
.
getId
());
}
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces"
)
public
List
<
NamespaceDTO
>
find
Namespaces
(
@PathVariable
(
"appId"
)
String
appId
,
public
List
<
NamespaceDTO
>
find
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
)
{
List
<
Namespace
>
groups
=
viewService
.
findNamespaces
(
appId
,
clusterName
);
return
BeanUtils
.
batchTransform
(
NamespaceDTO
.
class
,
groups
);
}
@RequestMapping
(
"/namespaces/{namespaceId}"
)
public
NamespaceDTO
get
(
@PathVariable
(
"namespaceId"
)
Long
namespaceId
)
{
Namespace
namespace
=
namespaceService
.
findOne
(
namespaceId
);
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
namespace
);
}
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}"
)
public
NamespaceDTO
get
Namespace
(
@PathVariable
(
"appId"
)
String
appId
,
public
NamespaceDTO
get
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
Namespace
namespace
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
Namespace
namespace
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
namespace
);
}
@RequestMapping
(
"/namespaces/{namespaceId}"
)
public
NamespaceDTO
getNamespace
(
@PathVariable
(
"namespaceId"
)
Long
namespaceId
)
{
Namespace
namespace
=
namespaceService
.
findOne
(
namespaceId
);
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
namespace
);
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}"
,
method
=
RequestMethod
.
PUT
)
public
NamespaceDTO
update
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
,
@RequestBody
NamespaceDTO
dto
)
{
if
(!
namespaceName
.
equals
(
dto
.
getNamespaceName
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
namespaceName
,
dto
.
getNamespaceName
()));
}
Namespace
entity
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
"namespace not found for name "
+
namespaceName
);
entity
=
namespaceService
.
update
(
BeanUtils
.
transfrom
(
Namespace
.
class
,
dto
));
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
entity
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ClusterService.java
浏览文件 @
a3ba41c0
...
...
@@ -3,8 +3,10 @@ package com.ctrip.apollo.biz.service;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.biz.entity.App
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
@Service
public
class
ClusterService
{
...
...
@@ -15,4 +17,19 @@ public class ClusterService {
public
Cluster
findOne
(
String
appId
,
String
name
)
{
return
clusterRepository
.
findByAppIdAndName
(
appId
,
name
);
}
public
Cluster
save
(
Cluster
entity
)
{
return
clusterRepository
.
save
(
entity
);
}
public
void
delete
(
long
id
)
{
clusterRepository
.
delete
(
id
);
}
public
Cluster
update
(
Cluster
cluster
)
{
Cluster
managedCluster
=
clusterRepository
.
findByAppIdAndName
(
cluster
.
getAppId
(),
cluster
.
getName
());
BeanUtils
.
copyEntityProperties
(
cluster
,
managedCluster
);
return
clusterRepository
.
save
(
managedCluster
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/NamespaceService.java
浏览文件 @
a3ba41c0
...
...
@@ -5,6 +5,7 @@ import org.springframework.stereotype.Service;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.repository.NamespaceRepository
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
@Service
public
class
NamespaceService
{
...
...
@@ -12,13 +13,27 @@ public class NamespaceService {
@Autowired
private
NamespaceRepository
namespaceRepository
;
public
void
delete
(
long
id
)
{
namespaceRepository
.
delete
(
id
);
}
public
Namespace
findOne
(
Long
namespaceId
)
{
return
namespaceRepository
.
findOne
(
namespaceId
);
}
public
Namespace
findOne
(
String
appId
,
String
clusterName
,
String
namespaceName
)
{
public
Namespace
findOne
(
String
appId
,
String
clusterName
,
String
namespaceName
)
{
return
namespaceRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
namespaceName
);
}
public
Namespace
save
(
Namespace
entity
)
{
return
namespaceRepository
.
save
(
entity
);
}
public
Namespace
update
(
Namespace
namespace
)
{
Namespace
managedNamespace
=
namespaceRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
namespace
.
getAppId
(),
namespace
.
getClusterName
(),
namespace
.
getNamespaceName
());
BeanUtils
.
copyEntityProperties
(
namespace
,
managedNamespace
);
return
namespaceRepository
.
save
(
managedNamespace
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录