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
Expand all
Hide 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;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ctrip.apollo.biz.entity.
Group
;
import
com.ctrip.apollo.biz.service.
Group
Service
;
import
com.ctrip.apollo.biz.entity.
Namespace
;
import
com.ctrip.apollo.biz.service.
Namespace
Service
;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.
Group
DTO
;
import
com.ctrip.apollo.core.dto.
Namespace
DTO
;
@RestController
public
class
GroupController
{
...
...
@@ -20,18 +20,18 @@ public class GroupController {
private
ViewService
viewService
;
@Autowired
private
Group
Service
groupService
;
private
Namespace
Service
groupService
;
@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
)
{
List
<
Group
>
groups
=
viewService
.
findGroup
s
(
appId
,
clusterName
);
return
BeanUtils
.
batchTransform
(
Group
DTO
.
class
,
groups
);
List
<
Namespace
>
groups
=
viewService
.
findNamespace
s
(
appId
,
clusterName
);
return
BeanUtils
.
batchTransform
(
Namespace
DTO
.
class
,
groups
);
}
@RequestMapping
(
"/groups/{groupId}"
)
public
Group
DTO
findOne
(
@PathVariable
(
"groupId"
)
Long
groupId
)
{
Group
group
=
groupService
.
findOne
(
groupId
);
return
BeanUtils
.
transfrom
(
Group
DTO
.
class
,
group
);
public
Namespace
DTO
findOne
(
@PathVariable
(
"groupId"
)
Long
groupId
)
{
Namespace
group
=
groupService
.
findOne
(
groupId
);
return
BeanUtils
.
transfrom
(
Namespace
DTO
.
class
,
group
);
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemController.java
View file @
6da1ec5a
...
...
@@ -21,15 +21,15 @@ public class ItemController {
@Autowired
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
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"
groupName"
)
String
group
Name
)
{
List
<
Item
>
items
=
viewService
.
findItems
(
appId
,
clusterName
,
group
Name
);
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"
namespaceName"
)
String
namespace
Name
)
{
List
<
Item
>
items
=
viewService
.
findItems
(
appId
,
clusterName
,
namespace
Name
);
return
BeanUtils
.
batchTransform
(
ItemDTO
.
class
,
items
);
}
@RequestMapping
(
"/items/{itemId}"
)
public
ItemDTO
findOne
(
@PathVariable
(
"itemId"
)
long
itemId
)
{
Item
item
=
itemService
.
findOne
(
itemId
);
...
...
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.RestController
;
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ReleaseController.java
View file @
6da1ec5a
...
...
@@ -18,19 +18,21 @@ public class ReleaseController {
@Autowired
private
ViewService
viewSerivce
;
@Autowired
private
ReleaseService
releaseService
;
@RequestMapping
(
"/release/{releaseId}"
)
public
ReleaseDTO
findOne
(
@PathVariable
(
"releaseId"
)
long
releaseId
)
{
Release
release
=
releaseService
.
findOne
(
releaseId
);
return
BeanUtils
.
transfrom
(
ReleaseDTO
.
class
,
release
);
}
@RequestMapping
(
"/apps/{appId}/clusters/{clusterId}/groups/{groupId}/releases"
)
public
List
<
ReleaseDTO
>
findReleases
(
@PathVariable
(
"groupId"
)
Long
groupId
){
List
<
Release
>
releases
=
viewSerivce
.
findReleases
(
groupId
);
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases"
)
public
List
<
ReleaseDTO
>
findReleases
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
List
<
Release
>
releases
=
viewSerivce
.
findReleases
(
appId
,
clusterName
,
namespaceName
);
return
BeanUtils
.
batchTransform
(
ReleaseDTO
.
class
,
releases
);
}
}
apollo-biz/pom.xml
View file @
6da1ec5a
...
...
@@ -30,6 +30,9 @@
<profiles>
<profile>
<id>
local
</id>
<activation>
<activeByDefault>
true
</activeByDefault>
</activation>
<dependencies>
<dependency>
<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;
import
javax.persistence.Entity
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
@Entity
@SQLDelete
(
sql
=
"Update App set isDeleted = 1 where id = ?"
)
@Where
(
clause
=
"isDeleted = 0"
)
public
class
App
extends
BaseEntity
{
@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;
import
javax.persistence.Entity
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
@Entity
@SQLDelete
(
sql
=
"Update Group set isDeleted = 1 where id = ?"
)
public
class
Group
extends
BaseEntity
{
@SQLDelete
(
sql
=
"Update AppNamespace set isDeleted = 1 where id = ?"
)
@Where
(
clause
=
"isDeleted = 0"
)
public
class
AppNamespace
extends
BaseEntity
{
@Column
(
nullable
=
false
)
private
String
name
;
...
...
@@ -15,53 +17,31 @@ public class Group extends BaseEntity {
@Column
(
nullable
=
false
)
private
String
appId
;
@Column
(
nullable
=
false
)
private
long
clusterId
;
@Column
(
nullable
=
false
)
private
String
clusterName
;
@Column
(
nullable
=
false
)
private
long
namespaceId
;
@Column
private
String
comment
;
public
String
getAppId
()
{
return
appId
;
}
public
long
getClusterId
()
{
return
clusterId
;
}
public
String
getClusterName
()
{
return
clusterName
;
public
String
getComment
()
{
return
comment
;
}
public
String
getName
()
{
return
name
;
}
public
long
getNamespaceId
()
{
return
namespaceId
;
}
public
void
setAppId
(
String
appId
)
{
this
.
appId
=
appId
;
}
public
void
setClusterId
(
long
clusterId
)
{
this
.
clusterId
=
clusterId
;
}
public
void
setClusterName
(
String
clusterName
)
{
this
.
clusterName
=
clusterName
;
public
void
setComment
(
String
comment
)
{
this
.
comment
=
comment
;
}
public
void
setName
(
String
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;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Inheritance
;
import
javax.persistence.InheritanceType
;
import
javax.persistence.MappedSuperclass
;
import
org.hibernate.annotations.Where
;
@Where
(
clause
=
"isDeleted = 0"
)
@MappedSuperclass
@Inheritance
(
strategy
=
InheritanceType
.
TABLE_PER_CLASS
)
public
abstract
class
BaseEntity
{
@Id
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Cluster.java
View file @
6da1ec5a
...
...
@@ -4,12 +4,14 @@ import javax.persistence.Column;
import
javax.persistence.Entity
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Entity
@SQLDelete
(
sql
=
"Update Cluster set isDeleted = 1 where id = ?"
)
@Where
(
clause
=
"isDeleted = 0"
)
public
class
Cluster
extends
BaseEntity
{
@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;
import
javax.persistence.Entity
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
@Entity
@SQLDelete
(
sql
=
"Update Item set isDeleted = 1 where id = ?"
)
@Where
(
clause
=
"isDeleted = 0"
)
public
class
Item
extends
BaseEntity
{
@Column
(
nullable
=
false
)
private
long
group
Id
;
private
long
namespace
Id
;
@Column
(
nullable
=
false
)
private
String
key
;
...
...
@@ -21,36 +23,36 @@ public class Item extends BaseEntity {
@Column
private
String
comment
;
public
long
getGroupId
()
{
return
groupId
;
}
public
void
setGroupId
(
long
groupId
)
{
this
.
groupId
=
groupId
;
public
String
getComment
()
{
return
comment
;
}
public
String
getKey
()
{
return
key
;
}
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
public
long
getNamespaceId
(
)
{
return
namespaceId
;
}
public
String
getValue
()
{
return
value
;
}
public
void
set
Value
(
String
value
)
{
this
.
value
=
value
;
public
void
set
Comment
(
String
comment
)
{
this
.
comment
=
comment
;
}
public
String
getComment
(
)
{
return
comment
;
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
}
public
void
setComment
(
String
comment
)
{
this
.
comment
=
comment
;
public
void
setNamespaceId
(
long
namespaceId
)
{
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;
import
javax.persistence.Entity
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
@Entity
@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
)
private
String
name
;
private
String
appId
;
@Column
(
nullable
=
false
)
private
String
appId
;
private
String
clusterName
;
@Column
private
String
comment
;
@Column
(
nullable
=
false
)
private
String
namespaceName
;
public
String
getAppId
()
{
return
appId
;
}
public
String
getC
omment
()
{
return
c
omment
;
public
String
getC
lusterName
()
{
return
c
lusterName
;
}
public
String
getName
()
{
return
name
;
public
String
getName
spaceName
()
{
return
name
spaceName
;
}
public
void
setAppId
(
String
appId
)
{
this
.
appId
=
appId
;
}
public
void
setC
omment
(
String
comment
)
{
this
.
c
omment
=
comment
;
public
void
setC
lusterName
(
String
clusterName
)
{
this
.
c
lusterName
=
clusterName
;
}
public
void
setName
(
String
n
ame
)
{
this
.
name
=
n
ame
;
public
void
setName
spaceName
(
String
namespaceN
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
;
import
java.io.Serializable
;
package
com
.
ctrip
.
apollo
.
biz
.
entity
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
@Entity
public
class
Privilege
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
430087307622435118L
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
@Id
@GeneratedValue
private
long
id
;
@Entity
@SQLDelete
(
sql
=
"Update Privilege set isDeleted = 1 where id = ?"
)
@Where
(
clause
=
"isDeleted = 0"
)
public
class
Privilege
extends
BaseEntity
{
@Column
private
String
name
;
...
...
@@ -26,37 +18,29 @@ public class Privilege implements Serializable {
private
String
privilType
;
@Column
private
String
appId
;
public
long
getId
()
{
return
id
;
}
public
void
setId
(
long
id
)
{
this
.
id
=
id
;
}
private
long
namespaceId
;
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
public
long
getNamespaceId
(
)
{
return
namespaceId
;
}
public
String
getPrivilType
()
{
return
privilType
;
}
public
void
set
PrivilType
(
String
privilTyp
e
)
{
this
.
privilType
=
privilTyp
e
;
public
void
set
Name
(
String
nam
e
)
{
this
.
name
=
nam
e
;
}
public
String
getAppId
(
)
{
return
app
Id
;
public
void
setNamespaceId
(
long
namespaceId
)
{
this
.
namespaceId
=
namespace
Id
;
}
public
void
set
AppId
(
String
appId
)
{
this
.
appId
=
appId
;
public
void
set
PrivilType
(
String
privilType
)
{
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;
import
javax.persistence.Lob
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Entity
@SQLDelete
(
sql
=
"Update Release set isDeleted = 1 where id = ?"
)
@Where
(
clause
=
"isDeleted = 0"
)
public
class
Release
extends
BaseEntity
{
@Column
(
nullable
=
false
)
...
...
@@ -23,7 +25,7 @@ public class Release extends BaseEntity {
private
String
clusterName
;
@Column
private
String
group
Name
;
private
String
namespace
Name
;
@Column
(
nullable
=
false
)
@Lob
...
...
@@ -48,8 +50,8 @@ public class Release extends BaseEntity {
return
configurations
;
}
public
String
get
Group
Name
()
{
return
group
Name
;
public
String
get
Namespace
Name
()
{
return
namespace
Name
;
}
public
String
getName
()
{
...
...
@@ -72,8 +74,8 @@ public class Release extends BaseEntity {
this
.
configurations
=
configurations
;
}
public
void
set
GroupName
(
String
group
Name
)
{
this
.
groupName
=
group
Name
;
public
void
set
NamespaceName
(
String
namespace
Name
)
{
this
.
namespaceName
=
namespace
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;
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
);
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
;
import
com.ctrip.apollo.biz.entity.Item
;
import
java.util.List
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.List
;
import
com.ctrip.apollo.biz.entity.Item
;
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
;
import
java.util.List
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
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
;
import
com.ctrip.apollo.portal.entity.Privilege
;
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
com.ctrip.apollo.biz.entity.Privilege
;
import
java.util.List
;
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;
*/
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
,
@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 {
@Autowired
private
ReleaseRepository
releaseRepository
;
@Autowired
private
ObjectMapper
objectMapper
;
private
ObjectMapper
objectMapper
=
new
ObjectMapper
();
private
TypeReference
<
Map
<
String
,
Object
>>
configurationTypeReference
=
new
TypeReference
<
Map
<
String
,
Object
>>()
{};
public
Release
findRelease
(
String
appId
,
String
clusterName
,
String
group
Name
)
{
Release
release
=
releaseRepository
.
findLatest
(
appId
,
clusterName
,
group
Name
);
public
Release
findRelease
(
String
appId
,
String
clusterName
,
String
namespace
Name
)
{
Release
release
=
releaseRepository
.
findLatest
(
appId
,
clusterName
,
namespace
Name
);
return
release
;
}
/**
* 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
)
{
return
null
;
}
ApolloConfig
config
=
new
ApolloConfig
(
release
.
getAppId
(),
release
.
getClusterName
(),
groupName
,
versionName
,
release
.
getId
());
ApolloConfig
config
=
new
ApolloConfig
(
release
.
getAppId
(),
release
.
getClusterName
(),
namespaceName
,
versionName
,
release
.
getId
());
config
.
setConfigurations
(
transformConfigurationToMap
(
release
.
getConfigurations
()));
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;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.biz.entity.
Group
;
import
com.ctrip.apollo.biz.repository.
Group
Repository
;
import
com.ctrip.apollo.biz.entity.
Namespace
;
import
com.ctrip.apollo.biz.repository.
Namespace
Repository
;
@Service
public
class
Group
Service
{
public
class
Namespace
Service
{
@Autowired
private
GroupRepository
group
Repository
;
private
NamespaceRepository
namespace
Repository
;
public
Group
findOne
(
Long
group
Id
){
return
groupRepository
.
findOne
(
group
Id
);
public
Namespace
findOne
(
Long
namespace
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.portal.exception.NotFoundException
;
import
com.ctrip.apollo.portal.repository.PrivilegeRepository
;
import
com.ctrip.apollo.biz.entity.Privilege
;
import
com.ctrip.apollo.biz.repository.PrivilegeRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -19,11 +18,12 @@ public class PrivilegeService {
@Autowired
private
PrivilegeRepository
privilRepo
;
public
Privilege
addPrivilege
(
String
appId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
public
Privilege
addPrivilege
(
long
namespaceId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByNamespaceIdAndNameAndPrivilType
(
namespaceId
,
name
,
privilType
.
name
());
if
(
privil
==
null
)
{
privil
=
new
Privilege
();
privil
.
set
AppId
(
app
Id
);
privil
.
set
NamespaceId
(
namespace
Id
);
privil
.
setPrivilType
(
privilType
.
name
());
privil
.
setName
(
name
);
privilRepo
.
save
(
privil
);
...
...
@@ -31,20 +31,19 @@ public class PrivilegeService {
return
privil
;
}
public
boolean
hasPrivilege
(
String
appId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
public
boolean
hasPrivilege
(
long
namespaceId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByNamespaceIdAndNameAndPrivilType
(
namespaceId
,
name
,
privilType
.
name
());
return
(
privil
!=
null
)
?
true
:
false
;
}
public
List
<
Privilege
>
listPrivileges
(
String
app
Id
)
{
return
privilRepo
.
findBy
AppId
(
app
Id
);
public
List
<
Privilege
>
listPrivileges
(
long
namespace
Id
)
{
return
privilRepo
.
findBy
NamespaceId
(
namespace
Id
);
}
public
void
removePrivilege
(
String
appId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
if
(
privil
==
null
)
{
throw
new
NotFoundException
();
}
privilRepo
.
delete
(
privil
);
public
void
removePrivilege
(
long
namespaceId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByNamespaceIdAndNameAndPrivilType
(
namespaceId
,
name
,
privilType
.
name
());
if
(
privil
!=
null
)
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;
import
org.springframework.stereotype.Service
;
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.Release
;
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.ReleaseRepository
;
import
com.google.common.base.Strings
;
...
...
@@ -26,7 +26,7 @@ public class ViewService {
private
ClusterRepository
clusterRepository
;
@Autowired
private
GroupRepository
group
Repository
;
private
NamespaceRepository
namespace
Repository
;
@Autowired
private
ItemRepository
itemRepository
;
...
...
@@ -46,17 +46,17 @@ public class ViewService {
return
clusters
;
}
public
List
<
Group
>
findGroup
s
(
String
appId
,
String
clusterName
)
{
List
<
Group
>
groups
=
group
Repository
.
findByAppIdAndClusterName
(
appId
,
clusterName
);
public
List
<
Namespace
>
findNamespace
s
(
String
appId
,
String
clusterName
)
{
List
<
Namespace
>
groups
=
namespace
Repository
.
findByAppIdAndClusterName
(
appId
,
clusterName
);
if
(
groups
==
null
)
{
return
Collections
.
EMPTY_LIST
;
}
return
groups
;
}
public
List
<
Item
>
findItems
(
String
appId
,
String
clusterName
,
String
group
Name
)
{
Group
group
=
groupRepository
.
findByAppIdAndClusterNameAndGroupName
(
appId
,
clusterName
,
group
Name
);
public
List
<
Item
>
findItems
(
String
appId
,
String
clusterName
,
String
namespace
Name
)
{
Namespace
group
=
namespaceRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
namespace
Name
);
if
(
group
!=
null
)
{
return
findItems
(
group
.
getId
());
}
else
{
...
...
@@ -64,16 +64,17 @@ public class ViewService {
}
}
public
List
<
Item
>
findItems
(
Long
group
Id
)
{
List
<
Item
>
items
=
itemRepository
.
findBy
GroupId
(
group
Id
);
public
List
<
Item
>
findItems
(
Long
namespace
Id
)
{
List
<
Item
>
items
=
itemRepository
.
findBy
NamespaceId
(
namespace
Id
);
if
(
items
==
null
)
{
return
Collections
.
EMPTY_LIST
;
}
return
items
;
}
public
List
<
Release
>
findReleases
(
Long
groupId
)
{
List
<
Release
>
releases
=
releaseRepository
.
findByGroupId
(
groupId
);
public
List
<
Release
>
findReleases
(
String
appId
,
String
clusterName
,
String
namespaceName
)
{
List
<
Release
>
releases
=
releaseRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
namespaceName
);
if
(
releases
==
null
)
{
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 {
Release
release
=
new
Release
();
release
.
setId
(
releaseId
);
release
.
setClusterName
(
clusterName
);
release
.
set
Group
Name
(
groupName
);
release
.
set
Namespace
Name
(
groupName
);
release
.
setConfigurations
(
configurations
);
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;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
ConfigControllerTest
.
class
//
ConfigControllerTest.class
})
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.core.dto.ItemDTO
;
import
java.util.LinkedList
;
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
;
import
java.util.Date
;
public
class
ItemDTO
{
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
;
public
class
Group
DTO
{
public
class
Namespace
DTO
{
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;
import
com.google.common.base.Strings
;
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.ItemDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
org.springframework.stereotype.Service
;
...
...
@@ -15,6 +15,15 @@ import java.util.List;
@Service
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
public
static
class
ConfigAPI
extends
API
{
public
static
String
CONFIG_RELEASE_API
=
"/configs/release/"
;
...
...
@@ -25,7 +34,7 @@ public class AdminServiceAPI {
}
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
CONFIG_RELEASE_API
+
releaseId
,
ReleaseDTO
[].
class
);
ReleaseDTO
[].
class
);
}
public
ItemDTO
[]
getLatestConfigItemsByClusters
(
Apollo
.
Env
env
,
List
<
Long
>
clusterIds
)
{
...
...
@@ -37,8 +46,8 @@ public class AdminServiceAPI {
sb
.
append
(
clusterId
).
append
(
","
);
}
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
"/configs/latest?clusterIds="
+
sb
.
substring
(
0
,
sb
.
length
()
-
1
),
ItemDTO
[].
class
);
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
"/configs/latest?clusterIds="
+
sb
.
substring
(
0
,
sb
.
length
()
-
1
),
ItemDTO
[].
class
);
}
}
...
...
@@ -52,30 +61,8 @@ public class AdminServiceAPI {
return
null
;
}
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
CLUSTER_APP_API
+
appId
,
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
);
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
CLUSTER_APP_API
+
appId
,
ClusterDTO
[].
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;
import
com.google.common.base.Strings
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.dto.AppConfigVO
;
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.service.ConfigService
;
...
...
@@ -35,11 +35,12 @@ public class ConfigController {
return
configService
.
loadLatestConfig
(
e
,
appId
);
}
else
if
(
versionId
>
0
)
{
return
configService
.
loadReleaseConfig
(
e
,
appId
,
versionId
);
}
else
{
// } else if (versionId > 0) {
//
// return configService.loadReleaseConfig(e, appId, versionId);
//
}
else
{
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;
import
com.ctrip.apollo.Apollo.Env
;
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.ItemDTO
;
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.constants.PortalConstants
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.google.common.base.Strings
;
...
...
@@ -36,50 +35,34 @@ public class ConfigService {
private
AdminServiceAPI
.
ConfigAPI
configAPI
;
@Autowired
private
AdminServiceAPI
.
ClusterAPI
clusterAPI
;
@Autowired
private
AdminServiceAPI
.
VersionAPI
versionAPI
;
private
ObjectMapper
objectMapper
=
new
ObjectMapper
();
public
AppConfigVO
loadReleaseConfig
(
Env
env
,
String
appId
,
long
versionId
)
{
if
(
Strings
.
isNullOrEmpty
(
appId
)
||
versionId
<=
0
)
{
return
null
;
}
long
releaseId
=
getReleaseIdFromVersionId
(
env
,
versionId
);
if
(
releaseId
==
-
1
)
{
logger
.
warn
(
"get release id error env:{}, app id:{}, version id:{}"
,
env
,
appId
,
versionId
);
return
null
;
}
ReleaseDTO
[]
releaseSnapShots
=
configAPI
.
getConfigByReleaseId
(
env
,
releaseId
);
if
(
releaseSnapShots
==
null
||
releaseSnapShots
.
length
==
0
)
{
return
null
;
}
AppConfigVO
appConfigVO
=
AppConfigVO
.
newInstance
(
appId
,
versionId
);
for
(
ReleaseDTO
snapShot
:
releaseSnapShots
)
{
// default cluster
if
(
ConfigConsts
.
DEFAULT_CLUSTER_NAME
.
equals
(
snapShot
.
getClusterName
()))
{
collectDefaultClusterConfigs
(
appId
,
snapShot
,
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
();
}
// public AppConfigVO loadReleaseConfig(Env env, String appId, String cluster, String namespace) {
//
// if (Strings.isNullOrEmpty(appId) || Strings.isNullOrEmpty(cluster) || Strings.isNullOrEmpty(namespace)) {
// return null;
// }
//
// ReleaseDTO[] releaseSnapShots = configAPI.getConfigByReleaseId(env, releaseId);
// if (releaseSnapShots == null || releaseSnapShots.length == 0) {
// return null;
// }
//
// AppConfigVO appConfigVO = AppConfigVO.newInstance(appId, versionId);
//
// for (ReleaseDTO snapShot : releaseSnapShots) {
// // default cluster
// if (ConfigConsts.DEFAULT_CLUSTER_NAME.equals(snapShot.getClusterName())) {
//
// collectDefaultClusterConfigs(appId, snapShot, appConfigVO);
//
// } else {// cluster special configs
// collectSpecialClusterConfigs(appId, snapShot, appConfigVO);
// }
// }
// return appConfigVO;
// }
private
void
collectDefaultClusterConfigs
(
String
appId
,
ReleaseDTO
snapShot
,
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;
import
com.ctrip.apollo.portal.service.ConfigServiceTest
;
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
ConfigServiceTest
.
class
})
@SuiteClasses
({
//ConfigServiceTest.class
})
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
This diff is collapsed.
Click to expand it.
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 @@
</plugins>
</build>
</profile>
<profile>
<id>
local
</id>
<activation>
<activeByDefault>
true
</activeByDefault>
</activation>
</profile>
<profile>
<id>
ctrip
</id>
<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