Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
b1c4b7d8
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,发现更多精彩内容 >>
提交
b1c4b7d8
编写于
4月 12, 2016
作者:
J
Jason Song
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #78 from yiming187/item_update
Add update API for item/release
上级
4c2d7f44
46727c12
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
194 addition
and
22 deletion
+194
-22
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemController.java
.../ctrip/apollo/adminservice/controller/ItemController.java
+28
-4
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemSetController.java
...rip/apollo/adminservice/controller/ItemSetController.java
+25
-0
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/NamespaceController.java
...p/apollo/adminservice/controller/NamespaceController.java
+24
-4
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ReleaseController.java
...rip/apollo/adminservice/controller/ReleaseController.java
+21
-10
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ClusterService.java
...ain/java/com/ctrip/apollo/biz/service/ClusterService.java
+0
-1
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemService.java
...c/main/java/com/ctrip/apollo/biz/service/ItemService.java
+15
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemSetService.java
...ain/java/com/ctrip/apollo/biz/service/ItemSetService.java
+36
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ReleaseService.java
...ain/java/com/ctrip/apollo/biz/service/ReleaseService.java
+44
-2
apollo-core/src/main/java/com/ctrip/apollo/core/dto/NamespaceDTO.java
...src/main/java/com/ctrip/apollo/core/dto/NamespaceDTO.java
+1
-1
未找到文件。
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemController.java
浏览文件 @
b1c4b7d8
...
...
@@ -3,6 +3,8 @@ 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
;
...
...
@@ -13,8 +15,8 @@ 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.biz.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.exception.NotFoundException
;
@RestController
public
class
ItemController
{
...
...
@@ -25,18 +27,40 @@ public class ItemController {
@Autowired
private
ItemService
itemService
;
@RequestMapping
(
path
=
"/items/"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
ItemDTO
>
create
(
@RequestBody
ItemDTO
dto
)
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
dto
);
entity
=
itemService
.
save
(
entity
);
dto
=
BeanUtils
.
transfrom
(
ItemDTO
.
class
,
entity
);
return
ResponseEntity
.
status
(
HttpStatus
.
CREATED
).
body
(
dto
);
}
@RequestMapping
(
path
=
"/items/{itemId}"
,
method
=
RequestMethod
.
DELETE
)
public
void
delete
(
@PathVariable
(
"itemId"
)
long
itemId
)
{
Item
entity
=
itemService
.
findOne
(
itemId
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
"item not found for itemId "
+
itemId
);
itemService
.
delete
(
entity
.
getId
());
}
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
)
public
List
<
ItemDTO
>
findItems
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
List
<
Item
>
items
=
viewService
.
findItems
(
appId
,
clusterName
,
namespaceName
);
return
BeanUtils
.
batchTransform
(
ItemDTO
.
class
,
items
);
}
@RequestMapping
(
"/items/{itemId}"
)
public
ItemDTO
findOne
(
@PathVariable
(
"itemId"
)
long
itemId
)
{
public
ItemDTO
get
(
@PathVariable
(
"itemId"
)
long
itemId
)
{
Item
item
=
itemService
.
findOne
(
itemId
);
return
BeanUtils
.
transfrom
(
ItemDTO
.
class
,
item
);
}
@RequestMapping
(
path
=
"/item/{itemId}"
,
method
=
RequestMethod
.
PUT
)
public
ItemDTO
update
(
@PathVariable
(
"itemId"
)
long
itemId
,
@RequestBody
ItemDTO
dto
)
{
Item
entity
=
itemService
.
findOne
(
itemId
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
"item not found for itemId "
+
itemId
);
entity
=
itemService
.
update
(
BeanUtils
.
transfrom
(
Item
.
class
,
dto
));
return
BeanUtils
.
transfrom
(
ItemDTO
.
class
,
entity
);
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemSetController.java
0 → 100644
浏览文件 @
b1c4b7d8
package
com.ctrip.apollo.adminservice.controller
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
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.service.ItemSetService
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
@RestController
public
class
ItemSetController
{
@Autowired
private
ItemSetService
itemSetService
;
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
Void
>
create
(
@RequestBody
ItemChangeSets
changeSet
)
{
itemSetService
.
updateSet
(
changeSet
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
build
();
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/NamespaceController.java
浏览文件 @
b1c4b7d8
...
...
@@ -30,6 +30,14 @@ public class NamespaceController {
@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
)
{
if
(!
appId
.
equals
(
dto
.
getAppId
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
appId
,
dto
.
getAppId
()));
}
if
(!
clusterName
.
equals
(
dto
.
getClusterName
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
clusterName
,
dto
.
getClusterName
()));
}
Namespace
entity
=
BeanUtils
.
transfrom
(
Namespace
.
class
,
dto
);
entity
=
namespaceService
.
save
(
entity
);
dto
=
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
entity
);
...
...
@@ -41,8 +49,8 @@ public class NamespaceController {
@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
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
String
.
format
(
"namespace not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
)
);
namespaceService
.
delete
(
entity
.
getId
());
}
...
...
@@ -56,6 +64,8 @@ public class NamespaceController {
@RequestMapping
(
"/namespaces/{namespaceId}"
)
public
NamespaceDTO
get
(
@PathVariable
(
"namespaceId"
)
Long
namespaceId
)
{
Namespace
namespace
=
namespaceService
.
findOne
(
namespaceId
);
if
(
namespace
==
null
)
throw
new
NotFoundException
(
String
.
format
(
"namespace not found for %s"
,
namespaceId
));
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
namespace
);
}
...
...
@@ -64,6 +74,8 @@ public class NamespaceController {
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
Namespace
namespace
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
if
(
namespace
==
null
)
throw
new
NotFoundException
(
String
.
format
(
"namespace not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
));
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
namespace
);
}
...
...
@@ -71,14 +83,22 @@ public class NamespaceController {
public
NamespaceDTO
update
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
,
@RequestBody
NamespaceDTO
dto
)
{
if
(!
appId
.
equals
(
dto
.
getAppId
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
appId
,
dto
.
getAppId
()));
}
if
(!
clusterName
.
equals
(
dto
.
getClusterName
()))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
clusterName
,
dto
.
getClusterName
()));
}
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
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
String
.
format
(
"namespace not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
)
);
entity
=
namespaceService
.
update
(
BeanUtils
.
transfrom
(
Namespace
.
class
,
dto
));
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
entity
);
}
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ReleaseController.java
浏览文件 @
b1c4b7d8
...
...
@@ -5,6 +5,8 @@ import java.util.List;
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.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ctrip.apollo.biz.entity.Release
;
...
...
@@ -13,7 +15,7 @@ import com.ctrip.apollo.biz.service.ReleaseService;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.
utils.StringUtils
;
import
com.ctrip.apollo.core.
exception.NotFoundException
;
@RestController
public
class
ReleaseController
{
...
...
@@ -28,13 +30,15 @@ public class ReleaseController {
private
ConfigService
configService
;
@RequestMapping
(
"/release/{releaseId}"
)
public
ReleaseDTO
findOne
(
@PathVariable
(
"releaseId"
)
long
releaseId
)
{
public
ReleaseDTO
get
(
@PathVariable
(
"releaseId"
)
long
releaseId
)
{
Release
release
=
releaseService
.
findOne
(
releaseId
);
if
(
release
==
null
)
throw
new
NotFoundException
(
String
.
format
(
"release not found for %s"
,
releaseId
));
return
BeanUtils
.
transfrom
(
ReleaseDTO
.
class
,
release
);
}
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases"
)
public
List
<
ReleaseDTO
>
find
Releases
(
@PathVariable
(
"appId"
)
String
appId
,
public
List
<
ReleaseDTO
>
find
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
List
<
Release
>
releases
=
viewSerivce
.
findReleases
(
appId
,
clusterName
,
namespaceName
);
...
...
@@ -42,14 +46,21 @@ public class ReleaseController {
}
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/latest"
)
public
ReleaseDTO
findLatestRelease
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
){
if
(
StringUtils
.
isContainEmpty
(
appId
,
clusterName
,
namespaceName
)){
return
null
;
}
public
ReleaseDTO
getLatest
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
Release
release
=
configService
.
findRelease
(
appId
,
clusterName
,
namespaceName
);
if
(
release
==
null
)
throw
new
NotFoundException
(
String
.
format
(
"latest release not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
));
return
BeanUtils
.
transfrom
(
ReleaseDTO
.
class
,
release
);
}
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases"
,
method
=
RequestMethod
.
POST
)
public
ReleaseDTO
buildRelease
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
,
@RequestParam
(
"name"
)
String
name
,
@RequestParam
(
name
=
"comment"
,
required
=
false
)
String
comment
)
{
Release
release
=
releaseService
.
buildRelease
(
name
,
comment
,
appId
,
clusterName
,
namespaceName
);
return
BeanUtils
.
transfrom
(
ReleaseDTO
.
class
,
release
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ClusterService.java
浏览文件 @
b1c4b7d8
...
...
@@ -3,7 +3,6 @@ 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
;
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemService.java
浏览文件 @
b1c4b7d8
...
...
@@ -5,6 +5,7 @@ import org.springframework.stereotype.Service;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
@Service
public
class
ItemService
{
...
...
@@ -12,9 +13,23 @@ public class ItemService {
@Autowired
private
ItemRepository
itemRepository
;
public
void
delete
(
long
id
)
{
itemRepository
.
delete
(
id
);
}
public
Item
findOne
(
long
itemId
)
{
Item
item
=
itemRepository
.
findOne
(
itemId
);
return
item
;
}
public
Item
save
(
Item
item
)
{
return
itemRepository
.
save
(
item
);
}
public
Item
update
(
Item
item
)
{
Item
managedItem
=
itemRepository
.
findOne
(
item
.
getId
());
BeanUtils
.
copyEntityProperties
(
item
,
managedItem
);
return
itemRepository
.
save
(
managedItem
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemSetService.java
0 → 100644
浏览文件 @
b1c4b7d8
package
com.ctrip.apollo.biz.service
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
@Service
public
class
ItemSetService
{
@Autowired
private
ItemRepository
itemRepository
;
public
void
updateSet
(
ItemChangeSets
changeSet
)
{
for
(
ItemDTO
item
:
changeSet
.
getCreateItems
())
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
itemRepository
.
save
(
entity
);
}
for
(
ItemDTO
item
:
changeSet
.
getUpdateItems
())
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
Item
managedItem
=
itemRepository
.
findOne
(
entity
.
getId
());
BeanUtils
.
copyEntityProperties
(
entity
,
managedItem
);
itemRepository
.
save
(
managedItem
);
}
for
(
ItemDTO
item
:
changeSet
.
getDeletedItems
())
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
itemRepository
.
delete
(
entity
.
getId
());
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ReleaseService.java
浏览文件 @
b1c4b7d8
package
com.ctrip.apollo.biz.service
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.entity.Release
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.biz.repository.NamespaceRepository
;
import
com.ctrip.apollo.biz.repository.ReleaseRepository
;
import
com.ctrip.apollo.core.exception.NotFoundException
;
import
com.google.gson.Gson
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Service
public
class
ReleaseService
{
@Autowired
private
ReleaseRepository
releaseRepository
;
@Autowired
private
NamespaceRepository
namespaceRepository
;
@Autowired
private
ItemRepository
itemRepository
;
private
Gson
gson
=
new
Gson
();
public
Release
findOne
(
long
releaseId
)
{
Release
release
=
releaseRepository
.
findOne
(
releaseId
);
return
release
;
}
public
Release
buildRelease
(
String
name
,
String
comment
,
String
appId
,
String
clusterName
,
String
namespaceName
)
{
Namespace
namespace
=
namespaceRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
namespaceName
);
if
(
namespace
==
null
)
{
throw
new
NotFoundException
(
String
.
format
(
"Could not find namespace for %s %s %s"
,
appId
,
clusterName
,
namespaceName
));
}
List
<
Item
>
items
=
itemRepository
.
findByNamespaceId
(
namespace
.
getId
());
Map
<
String
,
String
>
configurations
=
new
HashMap
<
String
,
String
>();
for
(
Item
item
:
items
)
{
configurations
.
put
(
item
.
getKey
(),
item
.
getValue
());
}
Release
release
=
new
Release
();
release
.
setName
(
name
);
release
.
setComment
(
comment
);
release
.
setAppId
(
appId
);
release
.
setClusterName
(
clusterName
);
release
.
setNamespaceName
(
namespaceName
);
release
.
setConfigurations
(
gson
.
toJson
(
configurations
));
return
releaseRepository
.
save
(
release
);
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/dto/NamespaceDTO.java
浏览文件 @
b1c4b7d8
...
...
@@ -14,7 +14,7 @@ public class NamespaceDTO {
return
appId
;
}
public
String
getCluster
Id
()
{
public
String
getCluster
Name
()
{
return
clusterName
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录