Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
apollo
Commits
6da1ec5a
Commit
6da1ec5a
authored
Apr 06, 2016
by
Jason Song
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #60 from yiming187/refactor
Update entity model & service
parents
85f2ff01
6f850772
Changes
54
Show whitespace changes
Inline
Side-by-side
Showing
54 changed files
with
723 additions
and
830 deletions
+723
-830
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/GroupController.java
...ctrip/apollo/adminservice/controller/GroupController.java
+10
-10
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemController.java
.../ctrip/apollo/adminservice/controller/ItemController.java
+6
-6
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/PrivilegeController.java
...p/apollo/adminservice/controller/PrivilegeController.java
+1
-1
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ReleaseController.java
...rip/apollo/adminservice/controller/ReleaseController.java
+8
-6
apollo-biz/pom.xml
apollo-biz/pom.xml
+3
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/App.java
...lo-biz/src/main/java/com/ctrip/apollo/biz/entity/App.java
+2
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/AppNamespace.java
...c/main/java/com/ctrip/apollo/biz/entity/AppNamespace.java
+47
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/BaseEntity.java
...src/main/java/com/ctrip/apollo/biz/entity/BaseEntity.java
+5
-3
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Cluster.java
...iz/src/main/java/com/ctrip/apollo/biz/entity/Cluster.java
+2
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Item.java
...o-biz/src/main/java/com/ctrip/apollo/biz/entity/Item.java
+17
-15
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Namespace.java
.../src/main/java/com/ctrip/apollo/biz/entity/Namespace.java
+15
-13
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Privilege.java
.../src/main/java/com/ctrip/apollo/biz/entity/Privilege.java
+46
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Release.java
...iz/src/main/java/com/ctrip/apollo/biz/entity/Release.java
+7
-5
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/AppNamespaceRepository.java
...m/ctrip/apollo/biz/repository/AppNamespaceRepository.java
+9
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/AppRepository.java
...n/java/com/ctrip/apollo/biz/repository/AppRepository.java
+1
-1
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/GroupRepository.java
...java/com/ctrip/apollo/biz/repository/GroupRepository.java
+0
-14
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ItemRepository.java
.../java/com/ctrip/apollo/biz/repository/ItemRepository.java
+4
-4
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/NamespaceRepository.java
.../com/ctrip/apollo/biz/repository/NamespaceRepository.java
+6
-1
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/PrivilegeRepository.java
.../com/ctrip/apollo/biz/repository/PrivilegeRepository.java
+16
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ReleaseRepository.java
...va/com/ctrip/apollo/biz/repository/ReleaseRepository.java
+4
-3
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AdminService.java
.../main/java/com/ctrip/apollo/biz/service/AdminService.java
+57
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ConfigService.java
...main/java/com/ctrip/apollo/biz/service/ConfigService.java
+6
-7
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/NamespaceService.java
...n/java/com/ctrip/apollo/biz/service/NamespaceService.java
+18
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/PrivilegeService.java
...n/java/com/ctrip/apollo/biz/service/PrivilegeService.java
+49
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ViewService.java
...c/main/java/com/ctrip/apollo/biz/service/ViewService.java
+13
-12
apollo-biz/src/main/resources/import.sql
apollo-biz/src/main/resources/import.sql
+0
-26
apollo-biz/src/test/java/com/ctrip/apollo/biz/SpringTestConfiguration.java
...st/java/com/ctrip/apollo/biz/SpringTestConfiguration.java
+12
-0
apollo-biz/src/test/java/com/ctrip/apollo/biz/repository/AppRepositoryTest.java
...va/com/ctrip/apollo/biz/repository/AppRepositoryTest.java
+24
-0
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/AdminServiceTest.java
...t/java/com/ctrip/apollo/biz/service/AdminServiceTest.java
+46
-0
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/ConfigServiceTest.java
.../java/com/ctrip/apollo/biz/service/ConfigServiceTest.java
+1
-1
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/PrivilegeServiceTest.java
...va/com/ctrip/apollo/biz/service/PrivilegeServiceTest.java
+87
-0
apollo-biz/src/test/resources/application.properties
apollo-biz/src/test/resources/application.properties
+0
-0
apollo-biz/src/test/resources/import.sql
apollo-biz/src/test/resources/import.sql
+31
-0
apollo-configservice/src/test/java/com/ctrip/apollo/configservice/AllTests.java
...rc/test/java/com/ctrip/apollo/configservice/AllTests.java
+1
-1
apollo-core/src/main/java/com/ctrip/apollo/core/dto/AppConfigVO.java
.../src/main/java/com/ctrip/apollo/core/dto/AppConfigVO.java
+1
-2
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ItemDTO.java
...core/src/main/java/com/ctrip/apollo/core/dto/ItemDTO.java
+0
-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-core/src/main/java/com/ctrip/apollo/core/dto/VersionDTO.java
...e/src/main/java/com/ctrip/apollo/core/dto/VersionDTO.java
+0
-58
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
...ain/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
+15
-28
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java
...ava/com/ctrip/apollo/portal/controller/AppController.java
+0
-47
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
.../com/ctrip/apollo/portal/controller/ConfigController.java
+7
-6
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/VersionController.java
...com/ctrip/apollo/portal/controller/VersionController.java
+0
-34
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/App.java
...tal/src/main/java/com/ctrip/apollo/portal/entity/App.java
+0
-95
apollo-portal/src/main/java/com/ctrip/apollo/portal/repository/AppRepository.java
...ava/com/ctrip/apollo/portal/repository/AppRepository.java
+0
-14
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
...main/java/com/ctrip/apollo/portal/service/AppService.java
+0
-35
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+26
-43
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/VersionService.java
.../java/com/ctrip/apollo/portal/service/VersionService.java
+0
-29
apollo-portal/src/main/resources/import.sql
apollo-portal/src/main/resources/import.sql
+0
-1
apollo-portal/src/test/java/com/ctrip/apollo/portal/AllTests.java
...ortal/src/test/java/com/ctrip/apollo/portal/AllTests.java
+3
-1
apollo-portal/src/test/java/com/ctrip/apollo/portal/controller/AppControllerTest.java
...com/ctrip/apollo/portal/controller/AppControllerTest.java
+0
-80
apollo-portal/src/test/java/com/ctrip/apollo/portal/repository/AppRepositoryTest.java
...com/ctrip/apollo/portal/repository/AppRepositoryTest.java
+0
-28
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/ConfigServiceTest.java
...va/com/ctrip/apollo/portal/service/ConfigServiceTest.java
+116
-122
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/PrivilegeServiceTest.java
...com/ctrip/apollo/portal/service/PrivilegeServiceTest.java
+0
-69
pom.xml
pom.xml
+0
-6
No files found.
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/GroupController.java
View file @
6da1ec5a
...
@@ -7,11 +7,11 @@ import org.springframework.web.bind.annotation.PathVariable;
...
@@ -7,11 +7,11 @@ 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.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ctrip.apollo.biz.entity.
Group
;
import
com.ctrip.apollo.biz.entity.
Namespace
;
import
com.ctrip.apollo.biz.service.
Group
Service
;
import
com.ctrip.apollo.biz.service.
Namespace
Service
;
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.
Group
DTO
;
import
com.ctrip.apollo.core.dto.
Namespace
DTO
;
@RestController
@RestController
public
class
GroupController
{
public
class
GroupController
{
...
@@ -20,18 +20,18 @@ public class GroupController {
...
@@ -20,18 +20,18 @@ public class GroupController {
private
ViewService
viewService
;
private
ViewService
viewService
;
@Autowired
@Autowired
private
Group
Service
groupService
;
private
Namespace
Service
groupService
;
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/groups"
)
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/groups"
)
public
List
<
Group
DTO
>
findGroups
(
@PathVariable
(
"appId"
)
String
appId
,
public
List
<
Namespace
DTO
>
findGroups
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
)
{
@PathVariable
(
"clusterName"
)
String
clusterName
)
{
List
<
Group
>
groups
=
viewService
.
findGroup
s
(
appId
,
clusterName
);
List
<
Namespace
>
groups
=
viewService
.
findNamespace
s
(
appId
,
clusterName
);
return
BeanUtils
.
batchTransform
(
Group
DTO
.
class
,
groups
);
return
BeanUtils
.
batchTransform
(
Namespace
DTO
.
class
,
groups
);
}
}
@RequestMapping
(
"/groups/{groupId}"
)
@RequestMapping
(
"/groups/{groupId}"
)
public
Group
DTO
findOne
(
@PathVariable
(
"groupId"
)
Long
groupId
)
{
public
Namespace
DTO
findOne
(
@PathVariable
(
"groupId"
)
Long
groupId
)
{
Group
group
=
groupService
.
findOne
(
groupId
);
Namespace
group
=
groupService
.
findOne
(
groupId
);
return
BeanUtils
.
transfrom
(
Group
DTO
.
class
,
group
);
return
BeanUtils
.
transfrom
(
Namespace
DTO
.
class
,
group
);
}
}
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemController.java
View file @
6da1ec5a
...
@@ -22,11 +22,11 @@ public class ItemController {
...
@@ -22,11 +22,11 @@ public class ItemController {
@Autowired
@Autowired
private
ItemService
itemService
;
private
ItemService
itemService
;
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/
groups/{group
Name}/items"
)
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/
namespaces/{namespace
Name}/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
(
"
groupName"
)
String
group
Name
)
{
@PathVariable
(
"
namespaceName"
)
String
namespace
Name
)
{
List
<
Item
>
items
=
viewService
.
findItems
(
appId
,
clusterName
,
group
Name
);
List
<
Item
>
items
=
viewService
.
findItems
(
appId
,
clusterName
,
namespace
Name
);
return
BeanUtils
.
batchTransform
(
ItemDTO
.
class
,
items
);
return
BeanUtils
.
batchTransform
(
ItemDTO
.
class
,
items
);
}
}
...
...
apollo-
portal/src/main/java/com/ctrip/apollo/portal
/controller/PrivilegeController.java
→
apollo-
adminservice/src/main/java/com/ctrip/apollo/adminservice
/controller/PrivilegeController.java
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
portal
.
controller
;
package
com
.
ctrip
.
apollo
.
adminservice
.
controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ReleaseController.java
View file @
6da1ec5a
...
@@ -28,9 +28,11 @@ public class ReleaseController {
...
@@ -28,9 +28,11 @@ public class ReleaseController {
return
BeanUtils
.
transfrom
(
ReleaseDTO
.
class
,
release
);
return
BeanUtils
.
transfrom
(
ReleaseDTO
.
class
,
release
);
}
}
@RequestMapping
(
"/apps/{appId}/clusters/{clusterId}/groups/{groupId}/releases"
)
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases"
)
public
List
<
ReleaseDTO
>
findReleases
(
@PathVariable
(
"groupId"
)
Long
groupId
){
public
List
<
ReleaseDTO
>
findReleases
(
@PathVariable
(
"appId"
)
String
appId
,
List
<
Release
>
releases
=
viewSerivce
.
findReleases
(
groupId
);
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
List
<
Release
>
releases
=
viewSerivce
.
findReleases
(
appId
,
clusterName
,
namespaceName
);
return
BeanUtils
.
batchTransform
(
ReleaseDTO
.
class
,
releases
);
return
BeanUtils
.
batchTransform
(
ReleaseDTO
.
class
,
releases
);
}
}
}
}
apollo-biz/pom.xml
View file @
6da1ec5a
...
@@ -30,6 +30,9 @@
...
@@ -30,6 +30,9 @@
<profiles>
<profiles>
<profile>
<profile>
<id>
local
</id>
<id>
local
</id>
<activation>
<activeByDefault>
true
</activeByDefault>
</activation>
<dependencies>
<dependencies>
<dependency>
<dependency>
<groupId>
com.h2database
</groupId>
<groupId>
com.h2database
</groupId>
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/App.java
View file @
6da1ec5a
...
@@ -4,9 +4,11 @@ import javax.persistence.Column;
...
@@ -4,9 +4,11 @@ import javax.persistence.Column;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
@Entity
@Entity
@SQLDelete
(
sql
=
"Update App set isDeleted = 1 where id = ?"
)
@SQLDelete
(
sql
=
"Update App set isDeleted = 1 where id = ?"
)
@Where
(
clause
=
"isDeleted = 0"
)
public
class
App
extends
BaseEntity
{
public
class
App
extends
BaseEntity
{
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/
Group
.java
→
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/
AppNamespace
.java
View file @
6da1ec5a
...
@@ -4,10 +4,12 @@ import javax.persistence.Column;
...
@@ -4,10 +4,12 @@ import javax.persistence.Column;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
@Entity
@Entity
@SQLDelete
(
sql
=
"Update Group set isDeleted = 1 where id = ?"
)
@SQLDelete
(
sql
=
"Update AppNamespace set isDeleted = 1 where id = ?"
)
public
class
Group
extends
BaseEntity
{
@Where
(
clause
=
"isDeleted = 0"
)
public
class
AppNamespace
extends
BaseEntity
{
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
private
String
name
;
private
String
name
;
...
@@ -15,53 +17,31 @@ public class Group extends BaseEntity {
...
@@ -15,53 +17,31 @@ public class Group extends BaseEntity {
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
private
String
appId
;
private
String
appId
;
@Column
(
nullable
=
false
)
@Column
private
long
clusterId
;
private
String
comment
;
@Column
(
nullable
=
false
)
private
String
clusterName
;
@Column
(
nullable
=
false
)
private
long
namespaceId
;
public
String
getAppId
()
{
public
String
getAppId
()
{
return
appId
;
return
appId
;
}
}
public
long
getClusterId
()
{
public
String
getComment
()
{
return
clusterId
;
return
comment
;
}
public
String
getClusterName
()
{
return
clusterName
;
}
}
public
String
getName
()
{
public
String
getName
()
{
return
name
;
return
name
;
}
}
public
long
getNamespaceId
()
{
return
namespaceId
;
}
public
void
setAppId
(
String
appId
)
{
public
void
setAppId
(
String
appId
)
{
this
.
appId
=
appId
;
this
.
appId
=
appId
;
}
}
public
void
setClusterId
(
long
clusterId
)
{
public
void
setComment
(
String
comment
)
{
this
.
clusterId
=
clusterId
;
this
.
comment
=
comment
;
}
public
void
setClusterName
(
String
clusterName
)
{
this
.
clusterName
=
clusterName
;
}
}
public
void
setName
(
String
name
)
{
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
this
.
name
=
name
;
}
}
public
void
setNamespaceId
(
long
namespaceId
)
{
this
.
namespaceId
=
namespaceId
;
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/BaseEntity.java
View file @
6da1ec5a
...
@@ -5,10 +5,12 @@ import java.util.Date;
...
@@ -5,10 +5,12 @@ import java.util.Date;
import
javax.persistence.Column
;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Id
;
import
javax.persistence.Inheritance
;
import
javax.persistence.InheritanceType
;
import
javax.persistence.MappedSuperclass
;
import
org.hibernate.annotations.Where
;
@MappedSuperclass
@Inheritance
(
strategy
=
InheritanceType
.
TABLE_PER_CLASS
)
@Where
(
clause
=
"isDeleted = 0"
)
public
abstract
class
BaseEntity
{
public
abstract
class
BaseEntity
{
@Id
@Id
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Cluster.java
View file @
6da1ec5a
...
@@ -4,12 +4,14 @@ import javax.persistence.Column;
...
@@ -4,12 +4,14 @@ import javax.persistence.Column;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
/**
/**
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
*/
*/
@Entity
@Entity
@SQLDelete
(
sql
=
"Update Cluster set isDeleted = 1 where id = ?"
)
@SQLDelete
(
sql
=
"Update Cluster set isDeleted = 1 where id = ?"
)
@Where
(
clause
=
"isDeleted = 0"
)
public
class
Cluster
extends
BaseEntity
{
public
class
Cluster
extends
BaseEntity
{
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Item.java
View file @
6da1ec5a
...
@@ -4,13 +4,15 @@ import javax.persistence.Column;
...
@@ -4,13 +4,15 @@ import javax.persistence.Column;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
@Entity
@Entity
@SQLDelete
(
sql
=
"Update Item set isDeleted = 1 where id = ?"
)
@SQLDelete
(
sql
=
"Update Item set isDeleted = 1 where id = ?"
)
@Where
(
clause
=
"isDeleted = 0"
)
public
class
Item
extends
BaseEntity
{
public
class
Item
extends
BaseEntity
{
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
private
long
group
Id
;
private
long
namespace
Id
;
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
private
String
key
;
private
String
key
;
...
@@ -21,36 +23,36 @@ public class Item extends BaseEntity {
...
@@ -21,36 +23,36 @@ public class Item extends BaseEntity {
@Column
@Column
private
String
comment
;
private
String
comment
;
public
long
getGroupId
()
{
public
String
getComment
()
{
return
groupId
;
return
comment
;
}
public
void
setGroupId
(
long
groupId
)
{
this
.
groupId
=
groupId
;
}
}
public
String
getKey
()
{
public
String
getKey
()
{
return
key
;
return
key
;
}
}
public
void
setKey
(
String
key
)
{
public
long
getNamespaceId
(
)
{
this
.
key
=
key
;
return
namespaceId
;
}
}
public
String
getValue
()
{
public
String
getValue
()
{
return
value
;
return
value
;
}
}
public
void
set
Value
(
String
value
)
{
public
void
set
Comment
(
String
comment
)
{
this
.
value
=
value
;
this
.
comment
=
comment
;
}
}
public
String
getComment
(
)
{
public
void
setKey
(
String
key
)
{
return
comment
;
this
.
key
=
key
;
}
}
public
void
setComment
(
String
comment
)
{
public
void
setNamespaceId
(
long
namespaceId
)
{
this
.
comment
=
comment
;
this
.
namespaceId
=
namespaceId
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Namespace.java
View file @
6da1ec5a
...
@@ -4,42 +4,44 @@ import javax.persistence.Column;
...
@@ -4,42 +4,44 @@ import javax.persistence.Column;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
@Entity
@Entity
@SQLDelete
(
sql
=
"Update Namespace set isDeleted = 1 where id = ?"
)
@SQLDelete
(
sql
=
"Update Namespace set isDeleted = 1 where id = ?"
)
public
class
Namespace
extends
BaseEntity
{
@Where
(
clause
=
"isDeleted = 0"
)
public
class
Namespace
extends
BaseEntity
{
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
private
String
name
;
private
String
appId
;
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
private
String
appId
;
private
String
clusterName
;
@Column
@Column
(
nullable
=
false
)
private
String
comment
;
private
String
namespaceName
;
public
String
getAppId
()
{
public
String
getAppId
()
{
return
appId
;
return
appId
;
}
}
public
String
getC
omment
()
{
public
String
getC
lusterName
()
{
return
c
omment
;
return
c
lusterName
;
}
}
public
String
getName
()
{
public
String
getName
spaceName
()
{
return
name
;
return
name
spaceName
;
}
}
public
void
setAppId
(
String
appId
)
{
public
void
setAppId
(
String
appId
)
{
this
.
appId
=
appId
;
this
.
appId
=
appId
;
}
}
public
void
setC
omment
(
String
comment
)
{
public
void
setC
lusterName
(
String
clusterName
)
{
this
.
c
omment
=
comment
;
this
.
c
lusterName
=
clusterName
;
}
}
public
void
setName
(
String
n
ame
)
{
public
void
setName
spaceName
(
String
namespaceN
ame
)
{
this
.
name
=
n
ame
;
this
.
name
spaceName
=
namespaceN
ame
;
}
}
}
}
apollo-
portal/src/main/java/com/ctrip/apollo/portal
/entity/Privilege.java
→
apollo-
biz/src/main/java/com/ctrip/apollo/biz
/entity/Privilege.java
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
portal
.
entity
;
package
com
.
ctrip
.
apollo
.
biz
.
entity
;
import
java.io.Serializable
;
import
javax.persistence.Column
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
@Entity
public
class
Privilege
implements
Serializable
{
/**
import
org.hibernate.annotations.SQLDelete
;
*
import
org.hibernate.annotations.Where
;
*/
private
static
final
long
serialVersionUID
=
-
430087307622435118L
;
@Id
@Entity
@GeneratedValue
@SQLDelete
(
sql
=
"Update Privilege set isDeleted = 1 where id = ?"
)
private
long
id
;
@Where
(
clause
=
"isDeleted = 0"
)
public
class
Privilege
extends
BaseEntity
{
@Column
@Column
private
String
name
;
private
String
name
;
...
@@ -26,37 +18,29 @@ public class Privilege implements Serializable {
...
@@ -26,37 +18,29 @@ public class Privilege implements Serializable {
private
String
privilType
;
private
String
privilType
;
@Column
@Column
private
String
appId
;
private
long
namespaceId
;
public
long
getId
()
{
return
id
;
}
public
void
setId
(
long
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
public
String
getName
()
{
return
name
;
return
name
;
}
}
public
void
setName
(
String
name
)
{
public
long
getNamespaceId
(
)
{
this
.
name
=
name
;
return
namespaceId
;
}
}
public
String
getPrivilType
()
{
public
String
getPrivilType
()
{
return
privilType
;
return
privilType
;
}
}
public
void
set
PrivilType
(
String
privilTyp
e
)
{
public
void
set
Name
(
String
nam
e
)
{
this
.
privilType
=
privilTyp
e
;
this
.
name
=
nam
e
;
}
}
public
String
getAppId
(
)
{
public
void
setNamespaceId
(
long
namespaceId
)
{
return
app
Id
;
this
.
namespaceId
=
namespace
Id
;
}
}
public
void
set
AppId
(
String
appId
)
{
public
void
set
PrivilType
(
String
privilType
)
{
this
.
appId
=
appId
;
this
.
privilType
=
privilType
;
}
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Release.java
View file @
6da1ec5a
...
@@ -5,12 +5,14 @@ import javax.persistence.Entity;
...
@@ -5,12 +5,14 @@ import javax.persistence.Entity;
import
javax.persistence.Lob
;
import
javax.persistence.Lob
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
/**
/**
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
*/
*/
@Entity
@Entity
@SQLDelete
(
sql
=
"Update Release set isDeleted = 1 where id = ?"
)
@SQLDelete
(
sql
=
"Update Release set isDeleted = 1 where id = ?"
)
@Where
(
clause
=
"isDeleted = 0"
)
public
class
Release
extends
BaseEntity
{
public
class
Release
extends
BaseEntity
{
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
...
@@ -23,7 +25,7 @@ public class Release extends BaseEntity {
...
@@ -23,7 +25,7 @@ public class Release extends BaseEntity {
private
String
clusterName
;
private
String
clusterName
;
@Column
@Column
private
String
group
Name
;
private
String
namespace
Name
;
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
@Lob
@Lob
...
@@ -48,8 +50,8 @@ public class Release extends BaseEntity {
...
@@ -48,8 +50,8 @@ public class Release extends BaseEntity {
return
configurations
;
return
configurations
;
}
}
public
String
get
Group
Name
()
{
public
String
get
Namespace
Name
()
{
return
group
Name
;
return
namespace
Name
;
}
}
public
String
getName
()
{
public
String
getName
()
{
...
@@ -72,8 +74,8 @@ public class Release extends BaseEntity {
...
@@ -72,8 +74,8 @@ public class Release extends BaseEntity {
this
.
configurations
=
configurations
;
this
.
configurations
=
configurations
;
}
}
public
void
set
GroupName
(
String
group
Name
)
{
public
void
set
NamespaceName
(
String
namespace
Name
)
{
this
.
groupName
=
group
Name
;
this
.
namespaceName
=
namespace
Name
;
}
}
public
void
setName
(
String
name
)
{
public
void
setName
(
String
name
)
{
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/AppNamespaceRepository.java
0 → 100644
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
com.ctrip.apollo.biz.entity.AppNamespace
;
public
interface
AppNamespaceRepository
extends
PagingAndSortingRepository
<
AppNamespace
,
Long
>{
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/AppRepository.java
View file @
6da1ec5a
...
@@ -10,7 +10,7 @@ import com.ctrip.apollo.biz.entity.App;
...
@@ -10,7 +10,7 @@ import com.ctrip.apollo.biz.entity.App;
public
interface
AppRepository
extends
PagingAndSortingRepository
<
App
,
Long
>
{
public
interface
AppRepository
extends
PagingAndSortingRepository
<
App
,
Long
>
{
@Query
(
"SELECT a from App a WHERE a.name LIKE %
':name'
%"
)
@Query
(
"SELECT a from App a WHERE a.name LIKE %
:name
%"
)
List
<
App
>
findByName
(
@Param
(
"name"
)
String
name
);
List
<
App
>
findByName
(
@Param
(
"name"
)
String
name
);
App
findByAppId
(
String
appId
);
App
findByAppId
(
String
appId
);
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/GroupRepository.java
deleted
100644 → 0
View file @
85f2ff01
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
import
java.util.List
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
com.ctrip.apollo.biz.entity.Group
;
public
interface
GroupRepository
extends
PagingAndSortingRepository
<
Group
,
Long
>
{
List
<
Group
>
findByAppIdAndClusterName
(
String
appId
,
String
clusterName
);
Group
findByAppIdAndClusterNameAndGroupName
(
String
appId
,
String
clusterName
,
String
groupName
);
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ItemRepository.java
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
import
com.ctrip.apollo.biz.entity.Item
;
import
java.util.List
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.List
;
import
com.ctrip.apollo.biz.entity.Item
;
public
interface
ItemRepository
extends
PagingAndSortingRepository
<
Item
,
Long
>
{
public
interface
ItemRepository
extends
PagingAndSortingRepository
<
Item
,
Long
>
{
List
<
Item
>
findBy
GroupIdIsIn
(
List
<
Long
>
group
Ids
);
List
<
Item
>
findBy
NamespaceIdIsIn
(
List
<
Long
>
namespace
Ids
);
List
<
Item
>
findBy
GroupId
(
Long
group
Id
);
List
<
Item
>
findBy
NamespaceId
(
Long
namespace
Id
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/NamespaceRepository.java
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
import
java.util.List
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.entity.Namespace
;
public
interface
NamespaceRepository
extends
PagingAndSortingRepository
<
Namespace
,
Long
>{
public
interface
NamespaceRepository
extends
PagingAndSortingRepository
<
Namespace
,
Long
>
{
List
<
Namespace
>
findByAppIdAndClusterName
(
String
appId
,
String
clusterName
);
Namespace
findByAppIdAndClusterNameAndNamespaceName
(
String
appId
,
String
clusterName
,
String
namespaceName
);
}
}
apollo-
portal/src/main/java/com/ctrip/apollo/portal
/repository/PrivilegeRepository.java
→
apollo-
biz/src/main/java/com/ctrip/apollo/biz
/repository/PrivilegeRepository.java
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
portal
.
repository
;
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
import
com.ctrip.apollo.portal.entity.Privilege
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
com.ctrip.apollo.biz.entity.Privilege
;
import
java.util.List
;
import
java.util.List
;
public
interface
PrivilegeRepository
extends
PagingAndSortingRepository
<
Privilege
,
Long
>
{
public
interface
PrivilegeRepository
extends
PagingAndSortingRepository
<
Privilege
,
Long
>
{
List
<
Privilege
>
findBy
AppId
(
String
app
Id
);
List
<
Privilege
>
findBy
NamespaceId
(
long
namespace
Id
);
List
<
Privilege
>
findBy
AppIdAndPrivilType
(
String
app
Id
,
String
privilType
);
List
<
Privilege
>
findBy
NamespaceIdAndPrivilType
(
long
namespace
Id
,
String
privilType
);
Privilege
findBy
AppIdAndNameAndPrivilType
(
String
app
Id
,
String
name
,
String
privilType
);
Privilege
findBy
NamespaceIdAndNameAndPrivilType
(
long
namespace
Id
,
String
name
,
String
privilType
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ReleaseRepository.java
View file @
6da1ec5a
...
@@ -13,9 +13,10 @@ import com.ctrip.apollo.biz.entity.Release;
...
@@ -13,9 +13,10 @@ import com.ctrip.apollo.biz.entity.Release;
*/
*/
public
interface
ReleaseRepository
extends
PagingAndSortingRepository
<
Release
,
Long
>
{
public
interface
ReleaseRepository
extends
PagingAndSortingRepository
<
Release
,
Long
>
{
@Query
(
"SELECT r FROM Release r WHERE r.appId = :appId AND r.clusterName = :clusterName AND r.
groupName = :groupName order by id desc litmit 1
"
)
@Query
(
"SELECT r FROM Release r WHERE r.appId = :appId AND r.clusterName = :clusterName AND r.
namespaceName = :namespaceName order by r.id desc
"
)
Release
findLatest
(
@Param
(
"appId"
)
String
appId
,
@Param
(
"clusterName"
)
String
clusterName
,
Release
findLatest
(
@Param
(
"appId"
)
String
appId
,
@Param
(
"clusterName"
)
String
clusterName
,
@Param
(
"
groupName"
)
String
group
Name
);
@Param
(
"
namespaceName"
)
String
namespace
Name
);
List
<
Release
>
findByGroupId
(
Long
groupId
);
List
<
Release
>
findByAppIdAndClusterNameAndNamespaceName
(
String
appId
,
String
clusterName
,
String
namespaceName
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AdminService.java
0 → 100644
View file @
6da1ec5a
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.AppNamespace
;
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
;
@Service
public
class
AdminService
{
@Autowired
private
AppRepository
appRepository
;
@Autowired
private
AppNamespaceRepository
appNamespaceRepository
;
@Autowired
private
NamespaceRepository
namespaceRepository
;
@Autowired
private
ClusterRepository
clusterRepository
;
public
App
createNewApp
(
String
appId
,
String
appName
,
String
ownerName
,
String
ownerEmail
,
String
namespace
)
{
App
app
=
new
App
();
app
.
setAppId
(
appId
);
app
.
setName
(
appName
);
app
.
setOwnerName
(
ownerName
);
app
.
setOwnerEmail
(
ownerEmail
);
appRepository
.
save
(
app
);
AppNamespace
appNs
=
new
AppNamespace
();
appNs
.
setAppId
(
appId
);
appNs
.
setName
(
namespace
);
appNamespaceRepository
.
save
(
appNs
);
Cluster
cluster
=
new
Cluster
();
cluster
.
setName
(
"default"
);
cluster
.
setAppId
(
appId
);
clusterRepository
.
save
(
cluster
);
Namespace
ns
=
new
Namespace
();
ns
.
setAppId
(
appId
);
ns
.
setClusterName
(
cluster
.
getName
());
ns
.
setNamespaceName
(
namespace
);
namespaceRepository
.
save
(
ns
);
return
app
;
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ConfigService.java
View file @
6da1ec5a
...
@@ -24,26 +24,25 @@ public class ConfigService {
...
@@ -24,26 +24,25 @@ public class ConfigService {
@Autowired
@Autowired
private
ReleaseRepository
releaseRepository
;
private
ReleaseRepository
releaseRepository
;
@Autowired
private
ObjectMapper
objectMapper
=
new
ObjectMapper
();
private
ObjectMapper
objectMapper
;
private
TypeReference
<
Map
<
String
,
Object
>>
configurationTypeReference
=
private
TypeReference
<
Map
<
String
,
Object
>>
configurationTypeReference
=
new
TypeReference
<
Map
<
String
,
Object
>>()
{};
new
TypeReference
<
Map
<
String
,
Object
>>()
{};
public
Release
findRelease
(
String
appId
,
String
clusterName
,
String
group
Name
)
{
public
Release
findRelease
(
String
appId
,
String
clusterName
,
String
namespace
Name
)
{
Release
release
=
releaseRepository
.
findLatest
(
appId
,
clusterName
,
group
Name
);
Release
release
=
releaseRepository
.
findLatest
(
appId
,
clusterName
,
namespace
Name
);
return
release
;
return
release
;
}
}
/**
/**
* Load configuration from database
* Load configuration from database
*/
*/
public
ApolloConfig
loadConfig
(
Release
release
,
String
group
Name
,
String
versionName
)
{
public
ApolloConfig
loadConfig
(
Release
release
,
String
namespace
Name
,
String
versionName
)
{
if
(
release
==
null
)
{
if
(
release
==
null
)
{
return
null
;
return
null
;
}
}
ApolloConfig
config
=
new
ApolloConfig
(
release
.
getAppId
(),
release
.
getClusterName
(),
groupName
,
ApolloConfig
config
=
new
ApolloConfig
(
release
.
getAppId
(),
release
.
getClusterName
(),
versionName
,
release
.
getId
());
namespaceName
,
versionName
,
release
.
getId
());
config
.
setConfigurations
(
transformConfigurationToMap
(
release
.
getConfigurations
()));
config
.
setConfigurations
(
transformConfigurationToMap
(
release
.
getConfigurations
()));
return
config
;
return
config
;
}
}
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/
Group
Service.java
→
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/
Namespace
Service.java
View file @
6da1ec5a
...
@@ -3,16 +3,16 @@ package com.ctrip.apollo.biz.service;
...
@@ -3,16 +3,16 @@ 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.
Group
;
import
com.ctrip.apollo.biz.entity.
Namespace
;
import
com.ctrip.apollo.biz.repository.
Group
Repository
;
import
com.ctrip.apollo.biz.repository.
Namespace
Repository
;
@Service
@Service
public
class
Group
Service
{
public
class
Namespace
Service
{
@Autowired
@Autowired
private
GroupRepository
group
Repository
;
private
NamespaceRepository
namespace
Repository
;
public
Group
findOne
(
Long
group
Id
){
public
Namespace
findOne
(
Long
namespace
Id
){
return
groupRepository
.
findOne
(
group
Id
);
return
namespaceRepository
.
findOne
(
namespace
Id
);
}
}
}
}
apollo-
portal/src/main/java/com/ctrip/apollo/portal
/service/PrivilegeService.java
→
apollo-
biz/src/main/java/com/ctrip/apollo/biz
/service/PrivilegeService.java
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
portal
.
service
;
package
com
.
ctrip
.
apollo
.
biz
.
service
;
import
com.ctrip.apollo.portal.entity.Privilege
;
import
com.ctrip.apollo.biz.entity.Privilege
;
import
com.ctrip.apollo.portal.exception.NotFoundException
;
import
com.ctrip.apollo.biz.repository.PrivilegeRepository
;
import
com.ctrip.apollo.portal.repository.PrivilegeRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -19,11 +18,12 @@ public class PrivilegeService {
...
@@ -19,11 +18,12 @@ public class PrivilegeService {
@Autowired
@Autowired
private
PrivilegeRepository
privilRepo
;
private
PrivilegeRepository
privilRepo
;
public
Privilege
addPrivilege
(
String
appId
,
String
name
,
PrivilType
privilType
)
{
public
Privilege
addPrivilege
(
long
namespaceId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
Privilege
privil
=
privilRepo
.
findByNamespaceIdAndNameAndPrivilType
(
namespaceId
,
name
,
privilType
.
name
());
if
(
privil
==
null
)
{
if
(
privil
==
null
)
{
privil
=
new
Privilege
();
privil
=
new
Privilege
();
privil
.
set
AppId
(
app
Id
);
privil
.
set
NamespaceId
(
namespace
Id
);
privil
.
setPrivilType
(
privilType
.
name
());
privil
.
setPrivilType
(
privilType
.
name
());
privil
.
setName
(
name
);
privil
.
setName
(
name
);
privilRepo
.
save
(
privil
);
privilRepo
.
save
(
privil
);
...
@@ -31,20 +31,19 @@ public class PrivilegeService {
...
@@ -31,20 +31,19 @@ public class PrivilegeService {
return
privil
;
return
privil
;
}
}
public
boolean
hasPrivilege
(
String
appId
,
String
name
,
PrivilType
privilType
)
{
public
boolean
hasPrivilege
(
long
namespaceId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
Privilege
privil
=
privilRepo
.
findByNamespaceIdAndNameAndPrivilType
(
namespaceId
,
name
,
privilType
.
name
());
return
(
privil
!=
null
)
?
true
:
false
;
return
(
privil
!=
null
)
?
true
:
false
;
}
}
public
List
<
Privilege
>
listPrivileges
(
String
app
Id
)
{
public
List
<
Privilege
>
listPrivileges
(
long
namespace
Id
)
{
return
privilRepo
.
findBy
AppId
(
app
Id
);
return
privilRepo
.
findBy
NamespaceId
(
namespace
Id
);
}
}
public
void
removePrivilege
(
String
appId
,
String
name
,
PrivilType
privilType
)
{
public
void
removePrivilege
(
long
namespaceId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
Privilege
privil
=
if
(
privil
==
null
)
{
privilRepo
.
findByNamespaceIdAndNameAndPrivilType
(
namespaceId
,
name
,
privilType
.
name
());
throw
new
NotFoundException
();
if
(
privil
!=
null
)
privilRepo
.
delete
(
privil
);
}
privilRepo
.
delete
(
privil
);
}
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ViewService.java
View file @
6da1ec5a
...
@@ -7,11 +7,11 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -7,11 +7,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.
Group
;
import
com.ctrip.apollo.biz.entity.
Namespace
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.entity.Release
;
import
com.ctrip.apollo.biz.entity.Release
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
import
com.ctrip.apollo.biz.repository.
Group
Repository
;
import
com.ctrip.apollo.biz.repository.
Namespace
Repository
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.biz.repository.ReleaseRepository
;
import
com.ctrip.apollo.biz.repository.ReleaseRepository
;
import
com.google.common.base.Strings
;
import
com.google.common.base.Strings
;
...
@@ -26,7 +26,7 @@ public class ViewService {
...
@@ -26,7 +26,7 @@ public class ViewService {
private
ClusterRepository
clusterRepository
;
private
ClusterRepository
clusterRepository
;
@Autowired
@Autowired
private
GroupRepository
group
Repository
;
private
NamespaceRepository
namespace
Repository
;
@Autowired
@Autowired
private
ItemRepository
itemRepository
;
private
ItemRepository
itemRepository
;
...
@@ -46,17 +46,17 @@ public class ViewService {
...
@@ -46,17 +46,17 @@ public class ViewService {
return
clusters
;
return
clusters
;
}
}
public
List
<
Group
>
findGroup
s
(
String
appId
,
String
clusterName
)
{
public
List
<
Namespace
>
findNamespace
s
(
String
appId
,
String
clusterName
)
{
List
<
Group
>
groups
=
group
Repository
.
findByAppIdAndClusterName
(
appId
,
clusterName
);
List
<
Namespace
>
groups
=
namespace
Repository
.
findByAppIdAndClusterName
(
appId
,
clusterName
);
if
(
groups
==
null
)
{
if
(
groups
==
null
)
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
EMPTY_LIST
;
}
}
return
groups
;
return
groups
;
}
}
public
List
<
Item
>
findItems
(
String
appId
,
String
clusterName
,
String
group
Name
)
{
public
List
<
Item
>
findItems
(
String
appId
,
String
clusterName
,
String
namespace
Name
)
{
Group
group
=
Namespace
group
=
namespaceRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
groupRepository
.
findByAppIdAndClusterNameAndGroupName
(
appId
,
clusterName
,
group
Name
);
namespace
Name
);
if
(
group
!=
null
)
{
if
(
group
!=
null
)
{
return
findItems
(
group
.
getId
());
return
findItems
(
group
.
getId
());
}
else
{
}
else
{
...
@@ -64,16 +64,17 @@ public class ViewService {
...
@@ -64,16 +64,17 @@ public class ViewService {
}
}
}
}
public
List
<
Item
>
findItems
(
Long
group
Id
)
{
public
List
<
Item
>
findItems
(
Long
namespace
Id
)
{
List
<
Item
>
items
=
itemRepository
.
findBy
GroupId
(
group
Id
);
List
<
Item
>
items
=
itemRepository
.
findBy
NamespaceId
(
namespace
Id
);
if
(
items
==
null
)
{
if
(
items
==
null
)
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
EMPTY_LIST
;
}
}
return
items
;
return
items
;
}
}
public
List
<
Release
>
findReleases
(
Long
groupId
)
{
public
List
<
Release
>
findReleases
(
String
appId
,
String
clusterName
,
String
namespaceName
)
{
List
<
Release
>
releases
=
releaseRepository
.
findByGroupId
(
groupId
);
List
<
Release
>
releases
=
releaseRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
namespaceName
);
if
(
releases
==
null
)
{
if
(
releases
==
null
)
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
EMPTY_LIST
;
}
}
...
...
apollo-biz/src/main/resources/import.sql
deleted
100644 → 0
View file @
85f2ff01
INSERT
INTO
Cluster
(
AppId
,
IsDeleted
,
Name
)
VALUES
(
100
,
0
,
'default'
);
INSERT
INTO
Cluster
(
ID
,
AppId
,
IsDeleted
,
Name
)
VALUES
(
100
,
6666
,
0
,
'default'
);
INSERT
INTO
Cluster
(
ID
,
AppId
,
IsDeleted
,
Name
)
VALUES
(
101
,
6666
,
0
,
'cluster1'
);
INSERT
INTO
Version
(
AppId
,
IsDeleted
,
Name
,
ReleaseId
)
VALUES
(
101
,
0
,
'1.0'
,
1
);
INSERT
INTO
Version
(
AppId
,
IsDeleted
,
Name
,
ReleaseId
)
VALUES
(
102
,
0
,
'1.0'
,
2
);
INSERT
INTO
Version
(
ID
,
AppId
,
IsDeleted
,
Name
,
ReleaseId
)
VALUES
(
100
,
6666
,
0
,
'1.0'
,
11111
);
INSERT
INTO
Version
(
ID
,
AppId
,
IsDeleted
,
Name
,
ReleaseId
)
VALUES
(
101
,
6666
,
0
,
'2.0'
,
11112
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'default'
,
0
,
1
,
'{"101.foo":"bar", "101.bar":"foo"}'
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'default'
,
0
,
2
,
'{"102.foo":"demo1", "102.bar":"demo2"}'
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'default'
,
0
,
3
,
'{"101.foo":"another bar", "101.bar_new":"foo"}'
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'default'
,
0
,
11111
,
'{"6666.foo":"demo1", "6666.bar":"demo2","3333.foo":"1008","4444.bar":"99901"}'
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'cluster1'
,
0
,
11111
,
'{"6666.foo":"demo1"}'
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'cluster2'
,
0
,
11111
,
'{"6666.bar":"bar2222"}'
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'default'
,
0
,
11112
,
'{"6666.foo":"verson2.0", "6666.bar":"verson2.0","3333.foo":"1008","4444.bar":"99901"}'
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_LastTime
,
IsDeleted
)
VALUES
(
100
,
'default'
,
6666
,
'6666.k1'
,
'6666.v1'
,
'comment1'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_LastTime
,
IsDeleted
)
VALUES
(
100
,
'default'
,
6666
,
'6666.k2'
,
'6666.v2'
,
'xxxx'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五1'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_LastTime
,
IsDeleted
)
VALUES
(
100
,
'default'
,
6666
,
'6666.k3'
,
'6666.v3'
,
'yyyy'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五2'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_LastTime
,
IsDeleted
)
VALUES
(
100
,
'default'
,
5555
,
'5555.k1'
,
'5555.v11'
,
'zzzz'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五3'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
DataChange_CreatedBy
,
DataChange_CreatedTime
,
DataChange_LastModifiedBy
,
DataChange_LastTime
,
IsDeleted
)
VALUES
(
101
,
'cluster1'
,
6666
,
'6666.k1'
,
'6666.v122'
,
'qqqqq'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五4'
,
NOW
(),
0
);
apollo-biz/src/test/java/com/ctrip/apollo/biz/SpringTestConfiguration.java
0 → 100644
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
biz
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
@Configuration
@EnableAutoConfiguration
@ComponentScan
(
basePackages
=
"com.ctrip.apollo.biz"
)
public
class
SpringTestConfiguration
{
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/repository/AppRepositoryTest.java
0 → 100644
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
import
org.junit.Assert
;
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.context.junit4.SpringJUnit4ClassRunner
;
import
com.ctrip.apollo.biz.SpringTestConfiguration
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
SpringTestConfiguration
.
class
)
public
class
AppRepositoryTest
{
@Autowired
private
AppRepository
appRepository
;
@Test
public
void
testListExists
()
{
Assert
.
assertTrue
(
appRepository
.
count
()
>
0
);
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/AdminServiceTest.java
0 → 100644
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
biz
.
service
;
import
java.util.List
;
import
org.junit.Assert
;
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.context.junit4.SpringJUnit4ClassRunner
;
import
com.ctrip.apollo.biz.SpringTestConfiguration
;
import
com.ctrip.apollo.biz.entity.App
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.Namespace
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
SpringTestConfiguration
.
class
)
public
class
AdminServiceTest
{
@Autowired
private
AdminService
adminService
;
@Autowired
private
ViewService
viewService
;
@Test
public
void
testCreateNewApp
()
{
String
appId
=
"someAppId"
;
String
appName
=
"someAppName"
;
String
ownerName
=
"someOwnerName"
;
String
ownerEmail
=
"someOwnerName@ctrip.com"
;
String
namespace
=
"someNamespace"
;
App
app
=
adminService
.
createNewApp
(
appId
,
appName
,
ownerName
,
ownerEmail
,
namespace
);
Assert
.
assertEquals
(
appId
,
app
.
getAppId
());
List
<
Cluster
>
clusters
=
viewService
.
findClusters
(
app
.
getAppId
());
Assert
.
assertEquals
(
1
,
clusters
.
size
());
Assert
.
assertEquals
(
"default"
,
clusters
.
get
(
0
).
getName
());
List
<
Namespace
>
namespaces
=
viewService
.
findNamespaces
(
appId
,
clusters
.
get
(
0
).
getName
());
Assert
.
assertEquals
(
1
,
namespaces
.
size
());
Assert
.
assertEquals
(
namespace
,
namespaces
.
get
(
0
).
getNamespaceName
());
}
}
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/ConfigServiceTest.java
View file @
6da1ec5a
...
@@ -121,7 +121,7 @@ public class ConfigServiceTest {
...
@@ -121,7 +121,7 @@ public class ConfigServiceTest {
Release
release
=
new
Release
();
Release
release
=
new
Release
();
release
.
setId
(
releaseId
);
release
.
setId
(
releaseId
);
release
.
setClusterName
(
clusterName
);
release
.
setClusterName
(
clusterName
);
release
.
set
Group
Name
(
groupName
);
release
.
set
Namespace
Name
(
groupName
);
release
.
setConfigurations
(
configurations
);
release
.
setConfigurations
(
configurations
);
return
release
;
return
release
;
}
}
...
...
apollo-biz/src/test/java/com/ctrip/apollo/biz/service/PrivilegeServiceTest.java
0 → 100644
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
biz
.
service
;
import
java.util.List
;
import
org.junit.Assert
;
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.context.junit4.SpringJUnit4ClassRunner
;
import
com.ctrip.apollo.biz.SpringTestConfiguration
;
import
com.ctrip.apollo.biz.entity.App
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.entity.Privilege
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
SpringTestConfiguration
.
class
)
public
class
PrivilegeServiceTest
{
@Autowired
private
AdminService
adminService
;
@Autowired
private
ViewService
viewService
;
@Autowired
private
PrivilegeService
privilService
;
@Test
public
void
testAddAndRemovePrivilege
()
{
App
newApp
=
adminService
.
createNewApp
(
String
.
valueOf
(
System
.
currentTimeMillis
()),
"new app "
+
System
.
currentTimeMillis
(),
"owner "
+
System
.
currentTimeMillis
(),
"owner "
+
System
.
currentTimeMillis
()
+
"@ctrip.com"
,
"namespace "
+
System
.
currentTimeMillis
());
List
<
Cluster
>
clusters
=
viewService
.
findClusters
(
newApp
.
getAppId
());
List
<
Namespace
>
namespaces
=
viewService
.
findNamespaces
(
newApp
.
getAppId
(),
clusters
.
get
(
0
).
getName
());
Namespace
namespace
=
namespaces
.
get
(
0
);
privilService
.
addPrivilege
(
namespace
.
getId
(),
newApp
.
getOwnerName
(),
PrivilegeService
.
PrivilType
.
EDIT
);
List
<
Privilege
>
privileges
=
privilService
.
listPrivileges
(
namespace
.
getId
());
Assert
.
assertEquals
(
1
,
privileges
.
size
());
Assert
.
assertEquals
(
PrivilegeService
.
PrivilType
.
EDIT
.
name
(),
privileges
.
get
(
0
).
getPrivilType
());
Assert
.
assertEquals
(
newApp
.
getOwnerName
(),
privileges
.
get
(
0
).
getName
());
privilService
.
removePrivilege
(
namespace
.
getId
(),
newApp
.
getOwnerName
(),
PrivilegeService
.
PrivilType
.
EDIT
);
privileges
=
privilService
.
listPrivileges
(
namespace
.
getId
());
Assert
.
assertEquals
(
0
,
privileges
.
size
());
}
@Test
public
void
testCheckPrivilege
()
{
App
newApp
=
adminService
.
createNewApp
(
String
.
valueOf
(
System
.
currentTimeMillis
()),
"new app "
+
System
.
currentTimeMillis
(),
"owner "
+
System
.
currentTimeMillis
(),
"owner "
+
System
.
currentTimeMillis
()
+
"@ctrip.com"
,
"namespace "
+
System
.
currentTimeMillis
());
List
<
Cluster
>
clusters
=
viewService
.
findClusters
(
newApp
.
getAppId
());
List
<
Namespace
>
namespaces
=
viewService
.
findNamespaces
(
newApp
.
getAppId
(),
clusters
.
get
(
0
).
getName
());
Namespace
namespace
=
namespaces
.
get
(
0
);
privilService
.
addPrivilege
(
namespace
.
getId
(),
newApp
.
getOwnerName
(),
PrivilegeService
.
PrivilType
.
EDIT
);
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
namespace
.
getId
(),
newApp
.
getOwnerName
(),
PrivilegeService
.
PrivilType
.
EDIT
));
Assert
.
assertFalse
(
privilService
.
hasPrivilege
(
namespace
.
getId
(),
newApp
.
getOwnerName
(),
PrivilegeService
.
PrivilType
.
REVIEW
));
Assert
.
assertFalse
(
privilService
.
hasPrivilege
(
namespace
.
getId
(),
newApp
.
getOwnerName
(),
PrivilegeService
.
PrivilType
.
RELEASE
));
privilService
.
addPrivilege
(
namespace
.
getId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
EDIT
);
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
namespace
.
getId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
EDIT
));
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
namespace
.
getId
(),
newApp
.
getOwnerName
(),
PrivilegeService
.
PrivilType
.
EDIT
));
privilService
.
addPrivilege
(
namespace
.
getId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
RELEASE
);
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
namespace
.
getId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
RELEASE
));
}
}
apollo-biz/src/
main
/resources/application.properties
→
apollo-biz/src/
test
/resources/application.properties
View file @
6da1ec5a
File moved
apollo-biz/src/test/resources/import.sql
0 → 100644
View file @
6da1ec5a
INSERT
INTO
App
(
AppId
,
Name
,
OwnerName
,
OwnerEmail
)
VALUES
(
'100003171'
,
'apollo-config-service'
,
'刘一鸣'
,
'liuym@ctrip.com'
);
INSERT
INTO
App
(
AppId
,
Name
,
OwnerName
,
OwnerEmail
)
VALUES
(
'100003172'
,
'apollo-admin-service'
,
'宋顺'
,
'song_s@ctrip.com'
);
INSERT
INTO
App
(
AppId
,
Name
,
OwnerName
,
OwnerEmail
)
VALUES
(
'100003173'
,
'apollo-portal'
,
'张乐'
,
'zhanglea@ctrip.com'
);
INSERT
INTO
App
(
AppId
,
Name
,
OwnerName
,
OwnerEmail
)
VALUES
(
'fxhermesproducer'
,
'fx-hermes-producer'
,
'梁锦华'
,
'jhliang@ctrip.com'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'100003171'
,
'default'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'100003171'
,
'cluster1'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'100003172'
,
'default'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'100003172'
,
'cluster2'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'100003173'
,
'default'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'100003173'
,
'cluster3'
);
INSERT
INTO
Cluster
(
AppId
,
Name
)
VALUES
(
'fxhermesproducer'
,
'default'
);
INSERT
INTO
AppNamespace
(
AppId
,
Name
)
VALUES
(
'100003171'
,
'apollo-config-service'
);
INSERT
INTO
AppNamespace
(
AppId
,
Name
)
VALUES
(
'100003172'
,
'apollo-admin-service'
);
INSERT
INTO
AppNamespace
(
AppId
,
Name
)
VALUES
(
'100003173'
,
'apollo-portal-service'
);
INSERT
INTO
AppNamespace
(
AppID
,
Name
)
VALUES
(
'fxhermesproducer'
,
'fx-hermes-producer'
);
INSERT
INTO
Namespace
(
Id
,
AppId
,
ClusterName
,
NamespaceName
)
VALUES
(
1
,
'100003171'
,
'default'
,
'apollo-config-service'
);
INSERT
INTO
Namespace
(
Id
,
AppId
,
ClusterName
,
NamespaceName
)
VALUES
(
2
,
'fxhermesproducer'
,
'default'
,
'fx-hermes-producer'
);
INSERT
INTO
Namespace
(
Id
,
AppId
,
ClusterName
,
NamespaceName
)
VALUES
(
3
,
'100003172'
,
'default'
,
'apollo-admin-service'
);
INSERT
INTO
Namespace
(
Id
,
AppId
,
ClusterName
,
NamespaceName
)
VALUES
(
4
,
'100003173'
,
'default'
,
'apollo-portal'
);
INSERT
INTO
Namespace
(
Id
,
AppId
,
ClusterName
,
NamespaceName
)
VALUES
(
5
,
'100003171'
,
'default'
,
'fx-hermes-producer'
);
INSERT
INTO
Item
(
GroupId
,
`Key`
,
Value
,
Comment
)
VALUES
(
1
,
'k1'
,
'v1'
,
'comment1'
);
INSERT
INTO
Item
(
GroupId
,
`Key`
,
Value
,
Comment
)
VALUES
(
1
,
'k2'
,
'v2'
,
'comment2'
);
INSERT
INTO
Item
(
GroupId
,
`Key`
,
Value
,
Comment
)
VALUES
(
2
,
'k3'
,
'v3'
,
'comment3'
);
INSERT
INTO
Item
(
GroupId
,
`Key`
,
Value
,
Comment
)
VALUES
(
5
,
'k3'
,
'v4'
,
'comment4'
);
INSERT
INTO
`RELEASE`
(
Name
,
Comment
,
AppId
,
ClusterName
,
GroupName
,
Configurations
)
VALUES
(
'REV1'
,
'First Release'
,
'100003171'
,
'default'
,
'apollo-config-service'
,
'{"k1":"v1"}'
);
apollo-configservice/src/test/java/com/ctrip/apollo/configservice/AllTests.java
View file @
6da1ec5a
...
@@ -8,7 +8,7 @@ import org.junit.runners.Suite.SuiteClasses;
...
@@ -8,7 +8,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
@SuiteClasses
({
ConfigControllerTest
.
class
//
ConfigControllerTest.class
})
})
public
class
AllTests
{
public
class
AllTests
{
...
...
apollo-
portal/src/main/java/com/ctrip/apollo/portal/entity
/AppConfigVO.java
→
apollo-
core/src/main/java/com/ctrip/apollo/core/dto
/AppConfigVO.java
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
portal
.
entity
;
package
com
.
ctrip
.
apollo
.
core
.
dto
;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ItemDTO.java
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
core
.
dto
;
package
com
.
ctrip
.
apollo
.
core
.
dto
;
import
java.util.Date
;
public
class
ItemDTO
{
public
class
ItemDTO
{
private
long
id
;
private
long
id
;
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/dto/
Group
DTO.java
→
apollo-core/src/main/java/com/ctrip/apollo/core/dto/
Namespace
DTO.java
View file @
6da1ec5a
package
com
.
ctrip
.
apollo
.
core
.
dto
;
package
com
.
ctrip
.
apollo
.
core
.
dto
;
public
class
Group
DTO
{
public
class
Namespace
DTO
{
private
long
id
;
private
long
id
;
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/dto/VersionDTO.java
deleted
100644 → 0
View file @
85f2ff01
package
com
.
ctrip
.
apollo
.
core
.
dto
;
public
class
VersionDTO
{
private
long
id
;
private
String
name
;
private
String
appId
;
private
long
releaseId
;
private
Long
parentVersion
;
public
VersionDTO
()
{
}
public
long
getId
()
{
return
id
;
}
public
void
setId
(
long
id
)
{
this
.
id
=
id
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
String
appId
)
{
this
.
appId
=
appId
;
}
public
long
getReleaseId
()
{
return
releaseId
;
}
public
void
setReleaseId
(
long
releaseId
)
{
this
.
releaseId
=
releaseId
;
}
public
Long
getParentVersion
()
{
return
parentVersion
;
}
public
void
setParentVersion
(
Long
parentVersion
)
{
this
.
parentVersion
=
parentVersion
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
View file @
6da1ec5a
...
@@ -3,10 +3,10 @@ package com.ctrip.apollo.portal.api;
...
@@ -3,10 +3,10 @@ package com.ctrip.apollo.portal.api;
import
com.google.common.base.Strings
;
import
com.google.common.base.Strings
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.dto.AppDTO
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -15,6 +15,15 @@ import java.util.List;
...
@@ -15,6 +15,15 @@ import java.util.List;
@Service
@Service
public
class
AdminServiceAPI
{
public
class
AdminServiceAPI
{
@Service
public
static
class
AppAPI
extends
API
{
public
static
String
APP_API
=
"/apps"
;
public
AppDTO
[]
getApps
(
Apollo
.
Env
env
)
{
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
APP_API
,
AppDTO
[].
class
);
}
}
@Service
@Service
public
static
class
ConfigAPI
extends
API
{
public
static
class
ConfigAPI
extends
API
{
public
static
String
CONFIG_RELEASE_API
=
"/configs/release/"
;
public
static
String
CONFIG_RELEASE_API
=
"/configs/release/"
;
...
@@ -37,8 +46,8 @@ public class AdminServiceAPI {
...
@@ -37,8 +46,8 @@ public class AdminServiceAPI {
sb
.
append
(
clusterId
).
append
(
","
);
sb
.
append
(
clusterId
).
append
(
","
);
}
}
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
"/configs/latest?clusterIds="
+
sb
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
"/configs/latest?clusterIds="
.
substring
(
0
,
sb
.
length
()
-
1
),
ItemDTO
[].
class
);
+
sb
.
substring
(
0
,
sb
.
length
()
-
1
),
ItemDTO
[].
class
);
}
}
}
}
...
@@ -52,30 +61,8 @@ public class AdminServiceAPI {
...
@@ -52,30 +61,8 @@ public class AdminServiceAPI {
return
null
;
return
null
;
}
}
return
restTemplate
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
CLUSTER_APP_API
+
appId
,
.
getForObject
(
getAdminServiceHost
(
env
)
+
CLUSTER_APP_API
+
appId
,
ClusterDTO
[].
class
);
ClusterDTO
[].
class
);
}
}
@Service
public
static
class
VersionAPI
extends
API
{
public
static
String
VERSION_API
=
"/version/"
;
public
static
String
VERSION_APP_API
=
"/version/app/"
;
public
VersionDTO
getVersionById
(
Apollo
.
Env
env
,
long
versionId
){
if
(
versionId
<=
0
){
return
null
;
}
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
VERSION_API
+
versionId
,
VersionDTO
.
class
);
}
public
VersionDTO
[]
getVersionsByApp
(
Apollo
.
Env
env
,
String
appId
){
if
(
Strings
.
isNullOrEmpty
(
appId
)){
return
null
;
}
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
VERSION_APP_API
+
appId
,
VersionDTO
[].
class
);
}
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java
deleted
100644 → 0
View file @
85f2ff01
package
com
.
ctrip
.
apollo
.
portal
.
controller
;
import
com.ctrip.apollo.portal.entity.App
;
import
com.ctrip.apollo.portal.exception.NotFoundException
;
import
com.ctrip.apollo.portal.service.AppService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
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
java.util.List
;
@RestController
@RequestMapping
(
"/apps"
)
public
class
AppController
{
@Autowired
private
AppService
appService
;
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
POST
,
consumes
=
{
"application/json"
})
public
App
create
(
@RequestBody
App
app
)
{
return
appService
.
save
(
app
);
}
@RequestMapping
(
"/{appid}"
)
public
App
detail
(
@PathVariable
String
appid
)
{
App
app
=
appService
.
detail
(
appid
);
if
(
app
==
null
)
{
throw
new
NotFoundException
();
}
return
app
;
}
@RequestMapping
(
""
)
public
List
<
App
>
list
(
Pageable
pageable
)
{
Page
<
App
>
page
=
appService
.
list
(
pageable
);
if
(
pageable
.
getPageNumber
()
>
page
.
getTotalPages
())
{
throw
new
NotFoundException
();
}
return
page
.
getContent
();
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
View file @
6da1ec5a
...
@@ -3,8 +3,8 @@ package com.ctrip.apollo.portal.controller;
...
@@ -3,8 +3,8 @@ package com.ctrip.apollo.portal.controller;
import
com.google.common.base.Strings
;
import
com.google.common.base.Strings
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.dto.AppConfigVO
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
com.ctrip.apollo.portal.exception.NotFoundException
;
import
com.ctrip.apollo.portal.exception.NotFoundException
;
import
com.ctrip.apollo.portal.service.ConfigService
;
import
com.ctrip.apollo.portal.service.ConfigService
;
...
@@ -35,11 +35,12 @@ public class ConfigController {
...
@@ -35,11 +35,12 @@ public class ConfigController {
return
configService
.
loadLatestConfig
(
e
,
appId
);
return
configService
.
loadLatestConfig
(
e
,
appId
);
}
else
if
(
versionId
>
0
)
{
// } else if (versionId > 0) {
//
return
configService
.
loadReleaseConfig
(
e
,
appId
,
versionId
);
// return configService.loadReleaseConfig(e, appId, versionId);
//
}
else
{
}
else
{
throw
new
NotFoundException
();
throw
new
NotFoundException
();
}
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/VersionController.java
deleted
100644 → 0
View file @
85f2ff01
package
com
.
ctrip
.
apollo
.
portal
.
controller
;
import
com.google.common.base.Strings
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.portal.service.VersionService
;
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
java.util.Collections
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/version"
)
public
class
VersionController
{
@Autowired
private
VersionService
versionService
;
@RequestMapping
(
"/{appId}/{env}"
)
public
List
<
VersionDTO
>
versions
(
@PathVariable
String
appId
,
@PathVariable
String
env
)
{
if
(
Strings
.
isNullOrEmpty
(
appId
)
||
Strings
.
isNullOrEmpty
(
env
))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"app id and env can not be empty. app id:%s , env:%s"
,
appId
,
env
));
}
return
versionService
.
findVersionsByApp
(
Apollo
.
Env
.
valueOf
(
env
),
appId
);
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/App.java
deleted
100644 → 0
View file @
85f2ff01
package
com
.
ctrip
.
apollo
.
portal
.
entity
;
import
java.io.Serializable
;
import
java.util.Date
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Id
;
@Entity
public
class
App
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
7348554309210401557L
;
@Id
private
String
appId
;
@Column
(
nullable
=
false
)
private
String
name
;
@Column
(
nullable
=
false
)
private
String
owner
;
@Column
private
String
ownerPhone
;
@Column
private
String
ownerMail
;
@Column
private
Date
createTimestamp
;
@Column
private
Date
lastUpdatedTimestamp
;
public
String
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
String
appId
)
{
this
.
appId
=
appId
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getOwner
()
{
return
owner
;
}
public
void
setOwner
(
String
owner
)
{
this
.
owner
=
owner
;
}
public
String
getOwnerPhone
()
{
return
ownerPhone
;
}
public
void
setOwnerPhone
(
String
ownerPhone
)
{
this
.
ownerPhone
=
ownerPhone
;
}
public
String
getOwnerMail
()
{
return
ownerMail
;
}
public
void
setOwnerMail
(
String
ownerMail
)
{
this
.
ownerMail
=
ownerMail
;
}
public
Date
getCreateTimestamp
()
{
return
createTimestamp
;
}
public
void
setCreateTimestamp
(
Date
createTimestamp
)
{
this
.
createTimestamp
=
createTimestamp
;
}
public
Date
getLastUpdatedTimestamp
()
{
return
lastUpdatedTimestamp
;
}
public
void
setLastUpdatedTimestamp
(
Date
lastUpdatedTimestamp
)
{
this
.
lastUpdatedTimestamp
=
lastUpdatedTimestamp
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/repository/AppRepository.java
deleted
100644 → 0
View file @
85f2ff01
package
com
.
ctrip
.
apollo
.
portal
.
repository
;
import
com.ctrip.apollo.portal.entity.App
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
public
interface
AppRepository
extends
PagingAndSortingRepository
<
App
,
String
>
{
Page
<
App
>
findAll
(
Pageable
pageable
);
App
findByAppId
(
String
appId
);
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
deleted
100644 → 0
View file @
85f2ff01
package
com
.
ctrip
.
apollo
.
portal
.
service
;
import
com.ctrip.apollo.portal.entity.App
;
import
com.ctrip.apollo.portal.repository.AppRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
java.util.Date
;
@Service
public
class
AppService
{
@Autowired
private
AppRepository
appRepository
;
public
App
detail
(
String
appId
)
{
return
appRepository
.
findByAppId
(
appId
);
}
public
Page
<
App
>
list
(
Pageable
pageable
)
{
return
appRepository
.
findAll
(
pageable
);
}
public
Iterable
<
App
>
list
()
{
return
appRepository
.
findAll
();
}
public
App
save
(
App
app
)
{
app
.
setCreateTimestamp
(
new
Date
());
return
appRepository
.
save
(
app
);
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
View file @
6da1ec5a
...
@@ -15,13 +15,12 @@ import org.springframework.stereotype.Service;
...
@@ -15,13 +15,12 @@ import org.springframework.stereotype.Service;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.dto.AppConfigVO
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.google.common.base.Strings
;
import
com.google.common.base.Strings
;
...
@@ -36,50 +35,34 @@ public class ConfigService {
...
@@ -36,50 +35,34 @@ public class ConfigService {
private
AdminServiceAPI
.
ConfigAPI
configAPI
;
private
AdminServiceAPI
.
ConfigAPI
configAPI
;
@Autowired
@Autowired
private
AdminServiceAPI
.
ClusterAPI
clusterAPI
;
private
AdminServiceAPI
.
ClusterAPI
clusterAPI
;
@Autowired
private
AdminServiceAPI
.
VersionAPI
versionAPI
;
private
ObjectMapper
objectMapper
=
new
ObjectMapper
();
private
ObjectMapper
objectMapper
=
new
ObjectMapper
();
public
AppConfigVO
loadReleaseConfig
(
Env
env
,
String
appId
,
long
versionId
)
{
// public AppConfigVO loadReleaseConfig(Env env, String appId, String cluster, String namespace) {
//
if
(
Strings
.
isNullOrEmpty
(
appId
)
||
versionId
<=
0
)
{
// if (Strings.isNullOrEmpty(appId) || Strings.isNullOrEmpty(cluster) || Strings.isNullOrEmpty(namespace)) {
return
null
;
// return null;
}
// }
//
long
releaseId
=
getReleaseIdFromVersionId
(
env
,
versionId
);
// ReleaseDTO[] releaseSnapShots = configAPI.getConfigByReleaseId(env, releaseId);
if
(
releaseId
==
-
1
)
{
// if (releaseSnapShots == null || releaseSnapShots.length == 0) {
logger
.
warn
(
"get release id error env:{}, app id:{}, version id:{}"
,
env
,
appId
,
versionId
);
// return null;
return
null
;
// }
}
//
// AppConfigVO appConfigVO = AppConfigVO.newInstance(appId, versionId);
ReleaseDTO
[]
releaseSnapShots
=
configAPI
.
getConfigByReleaseId
(
env
,
releaseId
);
//
if
(
releaseSnapShots
==
null
||
releaseSnapShots
.
length
==
0
)
{
// for (ReleaseDTO snapShot : releaseSnapShots) {
return
null
;
// // default cluster
}
// if (ConfigConsts.DEFAULT_CLUSTER_NAME.equals(snapShot.getClusterName())) {
//
AppConfigVO
appConfigVO
=
AppConfigVO
.
newInstance
(
appId
,
versionId
);
// collectDefaultClusterConfigs(appId, snapShot, appConfigVO);
//
for
(
ReleaseDTO
snapShot
:
releaseSnapShots
)
{
// } else {// cluster special configs
// default cluster
// collectSpecialClusterConfigs(appId, snapShot, appConfigVO);
if
(
ConfigConsts
.
DEFAULT_CLUSTER_NAME
.
equals
(
snapShot
.
getClusterName
()))
{
// }
// }
collectDefaultClusterConfigs
(
appId
,
snapShot
,
appConfigVO
);
// return appConfigVO;
// }
}
else
{
// cluster special configs
collectSpecialClusterConfigs
(
appId
,
snapShot
,
appConfigVO
);
}
}
return
appConfigVO
;
}
private
long
getReleaseIdFromVersionId
(
Env
env
,
long
versionId
)
{
VersionDTO
version
=
versionAPI
.
getVersionById
(
env
,
versionId
);
if
(
version
==
null
)
{
return
-
1
;
}
return
version
.
getReleaseId
();
}
private
void
collectDefaultClusterConfigs
(
String
appId
,
ReleaseDTO
snapShot
,
private
void
collectDefaultClusterConfigs
(
String
appId
,
ReleaseDTO
snapShot
,
AppConfigVO
appConfigVO
)
{
AppConfigVO
appConfigVO
)
{
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/VersionService.java
deleted
100644 → 0
View file @
85f2ff01
package
com
.
ctrip
.
apollo
.
portal
.
service
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
@Service
public
class
VersionService
{
@Autowired
private
AdminServiceAPI
.
VersionAPI
versionAPI
;
public
List
<
VersionDTO
>
findVersionsByApp
(
Apollo
.
Env
env
,
String
appId
)
{
VersionDTO
[]
versions
=
versionAPI
.
getVersionsByApp
(
env
,
appId
);
if
(
versions
==
null
||
versions
.
length
==
0
){
return
Collections
.
EMPTY_LIST
;
}
return
Arrays
.
asList
(
versions
);
}
}
apollo-portal/src/main/resources/import.sql
deleted
100644 → 0
View file @
85f2ff01
INSERT
INTO
App
(
appId
,
name
,
owner
,
ownerPhone
,
ownerMail
,
createTimestamp
,
lastUpdatedTimestamp
)
VALUES
(
6666
,
'apollo'
,
'lepdou'
,
'18722435754'
,
'zhanglea@ctrip.com'
,
NOW
(),
NOW
());
apollo-portal/src/test/java/com/ctrip/apollo/portal/AllTests.java
View file @
6da1ec5a
...
@@ -7,7 +7,9 @@ import org.junit.runners.Suite.SuiteClasses;
...
@@ -7,7 +7,9 @@ import org.junit.runners.Suite.SuiteClasses;
import
com.ctrip.apollo.portal.service.ConfigServiceTest
;
import
com.ctrip.apollo.portal.service.ConfigServiceTest
;
@RunWith
(
Suite
.
class
)
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
ConfigServiceTest
.
class
})
@SuiteClasses
({
//ConfigServiceTest.class
})
public
class
AllTests
{
public
class
AllTests
{
}
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/controller/AppControllerTest.java
deleted
100644 → 0
View file @
85f2ff01
package
com
.
ctrip
.
apollo
.
portal
.
controller
;
import
com.ctrip.apollo.portal.AbstractPortalTest
;
import
com.ctrip.apollo.portal.entity.App
;
import
com.ctrip.apollo.portal.repository.AppRepository
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestTemplate
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
@WebIntegrationTest
public
class
AppControllerTest
extends
AbstractPortalTest
{
RestTemplate
restTemplate
=
new
TestRestTemplate
();
@Autowired
AppRepository
appRepository
;
@Value
(
"${local.server.port}"
)
String
serverPort
;
@Test
public
void
testCreate
()
throws
URISyntaxException
{
App
newApp
=
new
App
();
newApp
.
setAppId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
URI
uri
=
new
URI
(
"http://localhost:"
+
serverPort
+
"/apps"
);
App
createdApp
=
restTemplate
.
postForObject
(
uri
,
newApp
,
App
.
class
);
Assert
.
assertEquals
(
newApp
.
getAppId
(),
createdApp
.
getAppId
());
Assert
.
assertNull
(
newApp
.
getCreateTimestamp
());
Assert
.
assertNotNull
(
createdApp
.
getCreateTimestamp
());
App
foundApp
=
appRepository
.
findByAppId
(
newApp
.
getAppId
());
Assert
.
assertEquals
(
newApp
.
getAppId
(),
foundApp
.
getAppId
());
}
@Test
public
void
testList
()
throws
URISyntaxException
{
App
newApp
=
new
App
();
newApp
.
setAppId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appRepository
.
save
(
newApp
);
URI
uri
=
new
URI
(
"http://localhost:"
+
serverPort
+
"/apps"
);
App
[]
apps
=
restTemplate
.
getForObject
(
uri
,
App
[].
class
);
Assert
.
assertEquals
(
1
,
apps
.
length
);
Assert
.
assertEquals
(
newApp
.
getAppId
(),
apps
[
0
].
getAppId
());
}
@Test
public
void
testListOutOfRange
()
throws
URISyntaxException
{
App
newApp
=
new
App
();
newApp
.
setAppId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appRepository
.
save
(
newApp
);
URI
uri
=
new
URI
(
"http://localhost:"
+
serverPort
+
"/apps?page=2"
);
ResponseEntity
<
App
[]>
entity
=
restTemplate
.
getForEntity
(
uri
,
App
[].
class
);
Assert
.
assertEquals
(
HttpStatus
.
NOT_FOUND
,
entity
.
getStatusCode
());
Assert
.
assertNull
(
entity
.
getBody
());
}
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/repository/AppRepositoryTest.java
deleted
100644 → 0
View file @
85f2ff01
package
com
.
ctrip
.
apollo
.
portal
.
repository
;
import
com.ctrip.apollo.portal.AbstractPortalTest
;
import
com.ctrip.apollo.portal.entity.App
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
public
class
AppRepositoryTest
extends
AbstractPortalTest
{
@Autowired
AppRepository
repository
;
@Test
public
void
testCreate
()
{
Assert
.
assertEquals
(
0
,
repository
.
count
());
App
ramdomApp
=
new
App
();
ramdomApp
.
setAppId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
ramdomApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
ramdomApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
repository
.
save
(
ramdomApp
);
Assert
.
assertEquals
(
1
,
repository
.
count
());
}
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/ConfigServiceTest.java
View file @
6da1ec5a
...
@@ -16,15 +16,14 @@ import org.springframework.web.client.RestTemplate;
...
@@ -16,15 +16,14 @@ import org.springframework.web.client.RestTemplate;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.Apollo.Env
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.ConfigConsts
;
import
com.ctrip.apollo.core.dto.AppConfigVO
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.dto.ServiceDTO
;
import
com.ctrip.apollo.core.dto.ServiceDTO
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
java.util.Arrays
;
import
java.util.Arrays
;
...
@@ -40,8 +39,6 @@ public class ConfigServiceTest {
...
@@ -40,8 +39,6 @@ public class ConfigServiceTest {
@Mock
@Mock
private
ServiceLocator
serviceLocator
;
private
ServiceLocator
serviceLocator
;
@Spy
@Spy
private
AdminServiceAPI
.
VersionAPI
versionAPI
;
@Spy
private
AdminServiceAPI
.
ClusterAPI
clusterAPI
;
private
AdminServiceAPI
.
ClusterAPI
clusterAPI
;
@Spy
@Spy
private
AdminServiceAPI
.
ConfigAPI
configAPI
;
private
AdminServiceAPI
.
ConfigAPI
configAPI
;
...
@@ -50,11 +47,9 @@ public class ConfigServiceTest {
...
@@ -50,11 +47,9 @@ public class ConfigServiceTest {
@Before
@Before
public
void
setUp
()
throws
ServiceException
{
public
void
setUp
()
throws
ServiceException
{
ReflectionTestUtils
.
setField
(
versionAPI
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
clusterAPI
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
clusterAPI
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
configAPI
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
configAPI
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
versionAPI
,
"serviceLocator"
,
serviceLocator
);
ReflectionTestUtils
.
setField
(
clusterAPI
,
"serviceLocator"
,
serviceLocator
);
ReflectionTestUtils
.
setField
(
clusterAPI
,
"serviceLocator"
,
serviceLocator
);
ReflectionTestUtils
.
setField
(
configAPI
,
"serviceLocator"
,
serviceLocator
);
ReflectionTestUtils
.
setField
(
configAPI
,
"serviceLocator"
,
serviceLocator
);
...
@@ -64,122 +59,121 @@ public class ConfigServiceTest {
...
@@ -64,122 +59,121 @@ public class ConfigServiceTest {
Mockito
.
doReturn
(
service
).
when
(
serviceLocator
).
getAdminService
(
Env
.
DEV
);
Mockito
.
doReturn
(
service
).
when
(
serviceLocator
).
getAdminService
(
Env
.
DEV
);
}
}
@Test
// @Test
public
void
testLoadReleaseConfig
()
{
// public void testLoadReleaseConfig() {
String
appId
=
"6666"
;
// String appId = "6666";
long
versionId
=
100
;
// long versionId = 100;
long
releaseId
=
11111
;
// long releaseId = 11111;
//
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
// VersionDTO someVersion = assembleVersion(appId, "1.0", releaseId);
ReleaseDTO
[]
someReleaseSnapShots
=
assembleReleaseSnapShots
();
// ReleaseDTO[] someReleaseSnapShots = assembleReleaseSnapShots();
//
when
(
versionAPI
.
getVersionById
(
Env
.
DEV
,
versionId
)).
thenReturn
(
someVersion
);
// when(versionAPI.getVersionById(Env.DEV, versionId)).thenReturn(someVersion);
when
(
configAPI
.
getConfigByReleaseId
(
Env
.
DEV
,
releaseId
)).
thenReturn
(
someReleaseSnapShots
);
// when(configAPI.getConfigByReleaseId(Env.DEV, releaseId)).thenReturn(someReleaseSnapShots);
//
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
Env
.
DEV
,
appId
,
versionId
);
// AppConfigVO appConfigVO = configService.loadReleaseConfig(Env.DEV, appId, versionId);
//
assertEquals
(
appConfigVO
.
getAppId
(),
appId
);
// assertEquals(appConfigVO.getAppId(), appId);
assertEquals
(
appConfigVO
.
getVersionId
(),
versionId
);
// assertEquals(appConfigVO.getVersionId(), versionId);
assertEquals
(
appConfigVO
.
getDefaultClusterConfigs
().
size
(),
2
);
// assertEquals(appConfigVO.getDefaultClusterConfigs().size(), 2);
assertEquals
(
appConfigVO
.
getOverrideAppConfigs
().
size
(),
2
);
// assertEquals(appConfigVO.getOverrideAppConfigs().size(), 2);
assertEquals
(
appConfigVO
.
getOverrideClusterConfigs
().
size
(),
2
);
// assertEquals(appConfigVO.getOverrideClusterConfigs().size(), 2);
}
// }
//
@Test
// @Test
public
void
testLoadReleaseConfigOnlyDefaultConfigs
()
{
// public void testLoadReleaseConfigOnlyDefaultConfigs() {
String
appId
=
"6666"
;
// String appId = "6666";
long
versionId
=
100
;
// long versionId = 100;
long
releaseId
=
11111
;
// long releaseId = 11111;
//
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
// ReleaseDTO[] someReleaseSnapShots = new ReleaseDTO[1];
ReleaseDTO
[]
someReleaseSnapShots
=
new
ReleaseDTO
[
1
];
// someReleaseSnapShots[0] = assembleReleaseSnapShot(11111, ConfigConsts.DEFAULT_CLUSTER_NAME,
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
ConfigConsts
.
DEFAULT_CLUSTER_NAME
,
// "{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}");
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
//
// when(versionAPI.getVersionById(Env.DEV, versionId)).thenReturn(someVersion);
when
(
versionAPI
.
getVersionById
(
Env
.
DEV
,
versionId
)).
thenReturn
(
someVersion
);
// when(configAPI.getConfigByReleaseId(Env.DEV, releaseId)).thenReturn(someReleaseSnapShots);
when
(
configAPI
.
getConfigByReleaseId
(
Env
.
DEV
,
releaseId
)).
thenReturn
(
someReleaseSnapShots
);
//
// AppConfigVO appConfigVO = configService.loadReleaseConfig(Env.DEV, appId, versionId);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
Env
.
DEV
,
appId
,
versionId
);
//
// assertEquals(appConfigVO.getAppId(), appId);
assertEquals
(
appConfigVO
.
getAppId
(),
appId
);
// assertEquals(appConfigVO.getVersionId(), versionId);
assertEquals
(
appConfigVO
.
getVersionId
(),
versionId
);
// assertEquals(appConfigVO.getDefaultClusterConfigs().size(), 2);
assertEquals
(
appConfigVO
.
getDefaultClusterConfigs
().
size
(),
2
);
// assertEquals(appConfigVO.getOverrideAppConfigs().size(), 0);
assertEquals
(
appConfigVO
.
getOverrideAppConfigs
().
size
(),
0
);
// assertEquals(appConfigVO.getOverrideClusterConfigs().size(), 0);
assertEquals
(
appConfigVO
.
getOverrideClusterConfigs
().
size
(),
0
);
// }
}
//
// @Test
@Test
// public void testLoadReleaseConfigDefaultConfigsAndOverrideApp() {
public
void
testLoadReleaseConfigDefaultConfigsAndOverrideApp
()
{
// String appId = "6666";
String
appId
=
"6666"
;
// long versionId = 100;
long
versionId
=
100
;
// long releaseId = 11111;
long
releaseId
=
11111
;
// VersionDTO someVersion = assembleVersion(appId, "1.0", releaseId);
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
// ReleaseDTO[] someReleaseSnapShots = new ReleaseDTO[1];
ReleaseDTO
[]
someReleaseSnapShots
=
new
ReleaseDTO
[
1
];
// someReleaseSnapShots[0] = assembleReleaseSnapShot(11111, ConfigConsts.DEFAULT_CLUSTER_NAME,
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
ConfigConsts
.
DEFAULT_CLUSTER_NAME
,
// "{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\", \"5555.bar\":\"demo2\", \"22.bar\":\"demo2\"}");
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\", \"5555.bar\":\"demo2\", \"22.bar\":\"demo2\"}"
);
//
// when(versionAPI.getVersionById(Env.DEV, versionId)).thenReturn(someVersion);
when
(
versionAPI
.
getVersionById
(
Env
.
DEV
,
versionId
)).
thenReturn
(
someVersion
);
// when(configAPI.getConfigByReleaseId(Env.DEV, releaseId)).thenReturn(someReleaseSnapShots);
when
(
configAPI
.
getConfigByReleaseId
(
Env
.
DEV
,
releaseId
)).
thenReturn
(
someReleaseSnapShots
);
//
// AppConfigVO appConfigVO = configService.loadReleaseConfig(Env.DEV, appId, versionId);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
Env
.
DEV
,
appId
,
versionId
);
//
// assertEquals(appConfigVO.getAppId(), appId);
assertEquals
(
appConfigVO
.
getAppId
(),
appId
);
// assertEquals(appConfigVO.getVersionId(), versionId);
assertEquals
(
appConfigVO
.
getVersionId
(),
versionId
);
// assertEquals(appConfigVO.getDefaultClusterConfigs().size(), 2);
assertEquals
(
appConfigVO
.
getDefaultClusterConfigs
().
size
(),
2
);
// assertEquals(2, appConfigVO.getOverrideAppConfigs().size());
assertEquals
(
2
,
appConfigVO
.
getOverrideAppConfigs
().
size
());
// assertEquals(appConfigVO.getOverrideClusterConfigs().size(), 0);
assertEquals
(
appConfigVO
.
getOverrideClusterConfigs
().
size
(),
0
);
// }
}
//
// @Test
@Test
// public void testLoadReleaseConfigDefaultConfigsAndOverrideCluster() {
public
void
testLoadReleaseConfigDefaultConfigsAndOverrideCluster
()
{
// String appId = "6666";
String
appId
=
"6666"
;
// long versionId = 100;
long
versionId
=
100
;
// long releaseId = 11111;
long
releaseId
=
11111
;
// VersionDTO someVersion = assembleVersion(appId, "1.0", releaseId);
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
// ReleaseDTO[] someReleaseSnapShots = new ReleaseDTO[2];
ReleaseDTO
[]
someReleaseSnapShots
=
new
ReleaseDTO
[
2
];
// someReleaseSnapShots[0] = assembleReleaseSnapShot(11111, ConfigConsts.DEFAULT_CLUSTER_NAME,
someReleaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
ConfigConsts
.
DEFAULT_CLUSTER_NAME
,
// "{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}");
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
// someReleaseSnapShots[1] = assembleReleaseSnapShot(11112, "cluster1",
someReleaseSnapShots
[
1
]
=
assembleReleaseSnapShot
(
11112
,
"cluster1"
,
// "{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}");
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
//
// when(versionAPI.getVersionById(Env.DEV, versionId)).thenReturn(someVersion);
when
(
versionAPI
.
getVersionById
(
Env
.
DEV
,
versionId
)).
thenReturn
(
someVersion
);
// when(configAPI.getConfigByReleaseId(Env.DEV, releaseId)).thenReturn(someReleaseSnapShots);
when
(
configAPI
.
getConfigByReleaseId
(
Env
.
DEV
,
releaseId
)).
thenReturn
(
someReleaseSnapShots
);
//
// AppConfigVO appConfigVO = configService.loadReleaseConfig(Env.DEV, appId, versionId);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
Env
.
DEV
,
appId
,
versionId
);
//
// assertEquals(appConfigVO.getAppId(), appId);
assertEquals
(
appConfigVO
.
getAppId
(),
appId
);
// assertEquals(appConfigVO.getVersionId(), versionId);
assertEquals
(
appConfigVO
.
getVersionId
(),
versionId
);
// assertEquals(appConfigVO.getDefaultClusterConfigs().size(), 2);
assertEquals
(
appConfigVO
.
getDefaultClusterConfigs
().
size
(),
2
);
// assertEquals(0, appConfigVO.getOverrideAppConfigs().size());
assertEquals
(
0
,
appConfigVO
.
getOverrideAppConfigs
().
size
());
// assertEquals(1, appConfigVO.getOverrideClusterConfigs().size());
assertEquals
(
1
,
appConfigVO
.
getOverrideClusterConfigs
().
size
());
// }
}
//
// @Test
@Test
// public void testLoadLastestConfig() {
public
void
testLoadLastestConfig
()
{
// String appId = "6666";
String
appId
=
"6666"
;
// ClusterDTO[] someClusters = assembleClusters();
ClusterDTO
[]
someClusters
=
assembleClusters
();
// ItemDTO[] someConfigItem = assembleConfigItems();
ItemDTO
[]
someConfigItem
=
assembleConfigItems
();
//
// when(clusterAPI.getClustersByApp(Env.DEV, appId)).thenReturn(someClusters);
when
(
clusterAPI
.
getClustersByApp
(
Env
.
DEV
,
appId
)).
thenReturn
(
someClusters
);
// when(configAPI.getLatestConfigItemsByClusters(Env.DEV, Arrays
when
(
configAPI
.
getLatestConfigItemsByClusters
(
Env
.
DEV
,
Arrays
// .asList(Long.valueOf(100), Long.valueOf(101)))).thenReturn(someConfigItem);
.
asList
(
Long
.
valueOf
(
100
),
Long
.
valueOf
(
101
)))).
thenReturn
(
someConfigItem
);
//
// AppConfigVO appConfigVO = configService.loadLatestConfig(Env.DEV, appId);
AppConfigVO
appConfigVO
=
configService
.
loadLatestConfig
(
Env
.
DEV
,
appId
);
//
// assertEquals(appConfigVO.getAppId(), "6666");
assertEquals
(
appConfigVO
.
getAppId
(),
"6666"
);
// assertEquals(appConfigVO.getVersionId(), PortalConstants.LASTEST_VERSION_ID);
assertEquals
(
appConfigVO
.
getVersionId
(),
PortalConstants
.
LASTEST_VERSION_ID
);
// assertEquals(appConfigVO.getDefaultClusterConfigs().size(), 3);
assertEquals
(
appConfigVO
.
getDefaultClusterConfigs
().
size
(),
3
);
// assertEquals(appConfigVO.getOverrideAppConfigs().size(), 1);
assertEquals
(
appConfigVO
.
getOverrideAppConfigs
().
size
(),
1
);
// assertEquals(appConfigVO.getOverrideClusterConfigs().size(), 1);
assertEquals
(
appConfigVO
.
getOverrideClusterConfigs
().
size
(),
1
);
// }
}
//
// private VersionDTO assembleVersion(String appId, String versionName, long releaseId) {
private
VersionDTO
assembleVersion
(
String
appId
,
String
versionName
,
long
releaseId
)
{
// VersionDTO version = new VersionDTO();
VersionDTO
version
=
new
VersionDTO
();
// version.setAppId(appId);
version
.
setAppId
(
appId
);
// version.setName(versionName);
version
.
setName
(
versionName
);
// version.setReleaseId(releaseId);
version
.
setReleaseId
(
releaseId
);
// return version;
return
version
;
// }
}
private
ReleaseDTO
[]
assembleReleaseSnapShots
()
{
private
ReleaseDTO
[]
assembleReleaseSnapShots
()
{
ReleaseDTO
[]
releaseSnapShots
=
new
ReleaseDTO
[
3
];
ReleaseDTO
[]
releaseSnapShots
=
new
ReleaseDTO
[
3
];
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/PrivilegeServiceTest.java
deleted
100644 → 0
View file @
85f2ff01
package
com
.
ctrip
.
apollo
.
portal
.
service
;
import
com.ctrip.apollo.portal.AbstractPortalTest
;
import
com.ctrip.apollo.portal.entity.App
;
import
com.ctrip.apollo.portal.entity.Privilege
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
java.util.List
;
public
class
PrivilegeServiceTest
extends
AbstractPortalTest
{
@Autowired
AppService
appService
;
@Autowired
PrivilegeService
privilService
;
@Test
public
void
testAddAndRemovePrivilege
()
{
App
newApp
=
new
App
();
newApp
.
setAppId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appService
.
save
(
newApp
);
privilService
.
addPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
);
List
<
Privilege
>
privileges
=
privilService
.
listPrivileges
(
newApp
.
getAppId
());
Assert
.
assertEquals
(
1
,
privileges
.
size
());
Assert
.
assertEquals
(
PrivilegeService
.
PrivilType
.
EDIT
.
name
(),
privileges
.
get
(
0
).
getPrivilType
());
Assert
.
assertEquals
(
newApp
.
getOwner
(),
privileges
.
get
(
0
).
getName
());
privilService
.
removePrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
);
privileges
=
privilService
.
listPrivileges
(
newApp
.
getAppId
());
Assert
.
assertEquals
(
0
,
privileges
.
size
());
}
@Test
public
void
testCheckPrivilege
()
{
App
newApp
=
new
App
();
newApp
.
setAppId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appService
.
save
(
newApp
);
privilService
.
addPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
);
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
));
Assert
.
assertFalse
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
REVIEW
));
Assert
.
assertFalse
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
RELEASE
));
privilService
.
addPrivilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
EDIT
);
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
EDIT
));
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
newApp
.
getOwner
(),
PrivilegeService
.
PrivilType
.
EDIT
));
privilService
.
addPrivilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
RELEASE
);
Assert
.
assertTrue
(
privilService
.
hasPrivilege
(
newApp
.
getAppId
(),
"nobody"
,
PrivilegeService
.
PrivilType
.
RELEASE
));
}
}
pom.xml
View file @
6da1ec5a
...
@@ -274,12 +274,6 @@
...
@@ -274,12 +274,6 @@
</plugins>
</plugins>
</build>
</build>
</profile>
</profile>
<profile>
<id>
local
</id>
<activation>
<activeByDefault>
true
</activeByDefault>
</activation>
</profile>
<profile>
<profile>
<id>
ctrip
</id>
<id>
ctrip
</id>
<dependencies>
<dependencies>
...
...
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