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
48c2474b
Commit
48c2474b
authored
Apr 11, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add CRUD for Cluster and Namespace Entity
parent
24ab7fb2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
137 additions
and
29 deletions
+137
-29
AppController.java
...m/ctrip/apollo/adminservice/controller/AppController.java
+17
-17
ClusterController.java
...rip/apollo/adminservice/controller/ClusterController.java
+39
-2
NamespaceController.java
...p/apollo/adminservice/controller/NamespaceController.java
+47
-8
ClusterService.java
...ain/java/com/ctrip/apollo/biz/service/ClusterService.java
+17
-0
NamespaceService.java
...n/java/com/ctrip/apollo/biz/service/NamespaceService.java
+17
-2
No files found.
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppController.java
View file @
48c2474b
...
...
@@ -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
View file @
48c2474b
...
...
@@ -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
View file @
48c2474b
...
...
@@ -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
View file @
48c2474b
...
...
@@ -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
View file @
48c2474b
...
...
@@ -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
);
}
}
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