Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
b1c4b7d8
Commit
b1c4b7d8
authored
Apr 12, 2016
by
Jason Song
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #78 from yiming187/item_update
Add update API for item/release
parents
4c2d7f44
46727c12
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
194 additions
and
22 deletions
+194
-22
ItemController.java
.../ctrip/apollo/adminservice/controller/ItemController.java
+28
-4
ItemSetController.java
...rip/apollo/adminservice/controller/ItemSetController.java
+25
-0
NamespaceController.java
...p/apollo/adminservice/controller/NamespaceController.java
+24
-4
ReleaseController.java
...rip/apollo/adminservice/controller/ReleaseController.java
+21
-10
ClusterService.java
...ain/java/com/ctrip/apollo/biz/service/ClusterService.java
+0
-1
ItemService.java
...c/main/java/com/ctrip/apollo/biz/service/ItemService.java
+15
-0
ItemSetService.java
...ain/java/com/ctrip/apollo/biz/service/ItemSetService.java
+36
-0
ReleaseService.java
...ain/java/com/ctrip/apollo/biz/service/ReleaseService.java
+44
-2
NamespaceDTO.java
...src/main/java/com/ctrip/apollo/core/dto/NamespaceDTO.java
+1
-1
No files found.
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemController.java
View file @
b1c4b7d8
...
@@ -3,6 +3,8 @@ package com.ctrip.apollo.adminservice.controller;
...
@@ -3,6 +3,8 @@ package com.ctrip.apollo.adminservice.controller;
import
java.util.List
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
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.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
@@ -13,8 +15,8 @@ import com.ctrip.apollo.biz.entity.Item;
...
@@ -13,8 +15,8 @@ import com.ctrip.apollo.biz.entity.Item;
import
com.ctrip.apollo.biz.service.ItemService
;
import
com.ctrip.apollo.biz.service.ItemService
;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
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.dto.ItemDTO
;
import
com.ctrip.apollo.core.exception.NotFoundException
;
@RestController
@RestController
public
class
ItemController
{
public
class
ItemController
{
...
@@ -25,18 +27,40 @@ public class ItemController {
...
@@ -25,18 +27,40 @@ public class ItemController {
@Autowired
@Autowired
private
ItemService
itemService
;
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"
)
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
)
public
List
<
ItemDTO
>
findItems
(
@PathVariable
(
"appId"
)
String
appId
,
public
List
<
ItemDTO
>
findItems
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
List
<
Item
>
items
=
viewService
.
findItems
(
appId
,
clusterName
,
namespaceName
);
List
<
Item
>
items
=
viewService
.
findItems
(
appId
,
clusterName
,
namespaceName
);
return
BeanUtils
.
batchTransform
(
ItemDTO
.
class
,
items
);
return
BeanUtils
.
batchTransform
(
ItemDTO
.
class
,
items
);
}
}
@RequestMapping
(
"/items/{itemId}"
)
@RequestMapping
(
"/items/{itemId}"
)
public
ItemDTO
findOne
(
@PathVariable
(
"itemId"
)
long
itemId
)
{
public
ItemDTO
get
(
@PathVariable
(
"itemId"
)
long
itemId
)
{
Item
item
=
itemService
.
findOne
(
itemId
);
Item
item
=
itemService
.
findOne
(
itemId
);
return
BeanUtils
.
transfrom
(
ItemDTO
.
class
,
item
);
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
View file @
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
View file @
b1c4b7d8
...
@@ -30,6 +30,14 @@ public class NamespaceController {
...
@@ -30,6 +30,14 @@ public class NamespaceController {
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
NamespaceDTO
>
create
(
@PathVariable
(
"appId"
)
String
appId
,
public
ResponseEntity
<
NamespaceDTO
>
create
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@RequestBody
NamespaceDTO
dto
)
{
@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
);
Namespace
entity
=
BeanUtils
.
transfrom
(
Namespace
.
class
,
dto
);
entity
=
namespaceService
.
save
(
entity
);
entity
=
namespaceService
.
save
(
entity
);
dto
=
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
entity
);
dto
=
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
entity
);
...
@@ -41,8 +49,8 @@ public class NamespaceController {
...
@@ -41,8 +49,8 @@ public class NamespaceController {
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
Namespace
entity
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
Namespace
entity
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
if
(
entity
==
null
)
if
(
entity
==
null
)
throw
new
NotFoundException
(
throw
new
NotFoundException
(
"namespace not found for namespaceName "
+
namespaceName
);
String
.
format
(
"namespace not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
)
);
namespaceService
.
delete
(
entity
.
getId
());
namespaceService
.
delete
(
entity
.
getId
());
}
}
...
@@ -56,6 +64,8 @@ public class NamespaceController {
...
@@ -56,6 +64,8 @@ public class NamespaceController {
@RequestMapping
(
"/namespaces/{namespaceId}"
)
@RequestMapping
(
"/namespaces/{namespaceId}"
)
public
NamespaceDTO
get
(
@PathVariable
(
"namespaceId"
)
Long
namespaceId
)
{
public
NamespaceDTO
get
(
@PathVariable
(
"namespaceId"
)
Long
namespaceId
)
{
Namespace
namespace
=
namespaceService
.
findOne
(
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
);
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
namespace
);
}
}
...
@@ -64,6 +74,8 @@ public class NamespaceController {
...
@@ -64,6 +74,8 @@ public class NamespaceController {
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
Namespace
namespace
=
namespaceService
.
findOne
(
appId
,
clusterName
,
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
);
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
namespace
);
}
}
...
@@ -71,14 +83,22 @@ public class NamespaceController {
...
@@ -71,14 +83,22 @@ public class NamespaceController {
public
NamespaceDTO
update
(
@PathVariable
(
"appId"
)
String
appId
,
public
NamespaceDTO
update
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
,
@RequestBody
NamespaceDTO
dto
)
{
@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
()))
{
if
(!
namespaceName
.
equals
(
dto
.
getNamespaceName
()))
{
throw
new
IllegalArgumentException
(
throw
new
IllegalArgumentException
(
String
.
format
(
"Path variable %s is not equals to object field %s"
,
namespaceName
,
String
.
format
(
"Path variable %s is not equals to object field %s"
,
namespaceName
,
dto
.
getNamespaceName
()));
dto
.
getNamespaceName
()));
}
}
Namespace
entity
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
Namespace
entity
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
if
(
entity
==
null
)
if
(
entity
==
null
)
throw
new
NotFoundException
(
throw
new
NotFoundException
(
"namespace not found for name "
+
namespaceName
);
String
.
format
(
"namespace not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
)
);
entity
=
namespaceService
.
update
(
BeanUtils
.
transfrom
(
Namespace
.
class
,
dto
));
entity
=
namespaceService
.
update
(
BeanUtils
.
transfrom
(
Namespace
.
class
,
dto
));
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
entity
);
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
entity
);
}
}
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ReleaseController.java
View file @
b1c4b7d8
...
@@ -5,6 +5,8 @@ import java.util.List;
...
@@ -5,6 +5,8 @@ import java.util.List;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
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
org.springframework.web.bind.annotation.RestController
;
import
com.ctrip.apollo.biz.entity.Release
;
import
com.ctrip.apollo.biz.entity.Release
;
...
@@ -13,7 +15,7 @@ import com.ctrip.apollo.biz.service.ReleaseService;
...
@@ -13,7 +15,7 @@ import com.ctrip.apollo.biz.service.ReleaseService;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.
utils.StringUtils
;
import
com.ctrip.apollo.core.
exception.NotFoundException
;
@RestController
@RestController
public
class
ReleaseController
{
public
class
ReleaseController
{
...
@@ -28,13 +30,15 @@ public class ReleaseController {
...
@@ -28,13 +30,15 @@ public class ReleaseController {
private
ConfigService
configService
;
private
ConfigService
configService
;
@RequestMapping
(
"/release/{releaseId}"
)
@RequestMapping
(
"/release/{releaseId}"
)
public
ReleaseDTO
findOne
(
@PathVariable
(
"releaseId"
)
long
releaseId
)
{
public
ReleaseDTO
get
(
@PathVariable
(
"releaseId"
)
long
releaseId
)
{
Release
release
=
releaseService
.
findOne
(
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
);
return
BeanUtils
.
transfrom
(
ReleaseDTO
.
class
,
release
);
}
}
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases"
)
@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
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
List
<
Release
>
releases
=
viewSerivce
.
findReleases
(
appId
,
clusterName
,
namespaceName
);
List
<
Release
>
releases
=
viewSerivce
.
findReleases
(
appId
,
clusterName
,
namespaceName
);
...
@@ -42,14 +46,21 @@ public class ReleaseController {
...
@@ -42,14 +46,21 @@ public class ReleaseController {
}
}
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/latest"
)
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/latest"
)
public
ReleaseDTO
findLatestRelease
(
@PathVariable
(
"appId"
)
String
appId
,
public
ReleaseDTO
getLatest
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
){
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
clusterName
,
namespaceName
)){
return
null
;
}
Release
release
=
configService
.
findRelease
(
appId
,
clusterName
,
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
);
return
BeanUtils
.
transfrom
(
ReleaseDTO
.
class
,
release
);
}
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ClusterService.java
View file @
b1c4b7d8
...
@@ -3,7 +3,6 @@ package com.ctrip.apollo.biz.service;
...
@@ -3,7 +3,6 @@ package com.ctrip.apollo.biz.service;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.biz.entity.App
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemService.java
View file @
b1c4b7d8
...
@@ -5,6 +5,7 @@ import org.springframework.stereotype.Service;
...
@@ -5,6 +5,7 @@ import org.springframework.stereotype.Service;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
@Service
@Service
public
class
ItemService
{
public
class
ItemService
{
...
@@ -12,9 +13,23 @@ public class ItemService {
...
@@ -12,9 +13,23 @@ public class ItemService {
@Autowired
@Autowired
private
ItemRepository
itemRepository
;
private
ItemRepository
itemRepository
;
public
void
delete
(
long
id
)
{
itemRepository
.
delete
(
id
);
}
public
Item
findOne
(
long
itemId
)
{
public
Item
findOne
(
long
itemId
)
{
Item
item
=
itemRepository
.
findOne
(
itemId
);
Item
item
=
itemRepository
.
findOne
(
itemId
);
return
item
;
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
View file @
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
View file @
b1c4b7d8
package
com
.
ctrip
.
apollo
.
biz
.
service
;
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.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
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.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.biz.repository.ReleaseRepository
;
import
com.ctrip.apollo.core.exception.NotFoundException
;
import
com.google.gson.Gson
;
/**
/**
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
*/
*/
@Service
@Service
public
class
ReleaseService
{
public
class
ReleaseService
{
@Autowired
@Autowired
private
ReleaseRepository
releaseRepository
;
private
ReleaseRepository
releaseRepository
;
@Autowired
private
NamespaceRepository
namespaceRepository
;
@Autowired
private
ItemRepository
itemRepository
;
private
Gson
gson
=
new
Gson
();
public
Release
findOne
(
long
releaseId
)
{
public
Release
findOne
(
long
releaseId
)
{
Release
release
=
releaseRepository
.
findOne
(
releaseId
);
Release
release
=
releaseRepository
.
findOne
(
releaseId
);
return
release
;
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
View file @
b1c4b7d8
...
@@ -14,7 +14,7 @@ public class NamespaceDTO {
...
@@ -14,7 +14,7 @@ public class NamespaceDTO {
return
appId
;
return
appId
;
}
}
public
String
getCluster
Id
()
{
public
String
getCluster
Name
()
{
return
clusterName
;
return
clusterName
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment