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
71ffb8c6
Commit
71ffb8c6
authored
Mar 25, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
portal read config
parent
8d374626
Changes
54
Hide whitespace changes
Inline
Side-by-side
Showing
54 changed files
with
1930 additions
and
348 deletions
+1930
-348
apollo-adminservice/pom.xml
apollo-adminservice/pom.xml
+15
-37
apollo-adminservice/src/main/java/com/ctrip/apollo/AdminServiceApplication.java
...c/main/java/com/ctrip/apollo/AdminServiceApplication.java
+2
-2
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ClusterController.java
...rip/apollo/adminservice/controller/ClusterController.java
+23
-0
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ConfigController.java
...trip/apollo/adminservice/controller/ConfigController.java
+33
-0
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/VersionController.java
...rip/apollo/adminservice/controller/VersionController.java
+33
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Cluster.java
...iz/src/main/java/com/ctrip/apollo/biz/entity/Cluster.java
+14
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/ConfigItem.java
...src/main/java/com/ctrip/apollo/biz/entity/ConfigItem.java
+166
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/ReleaseSnapShot.java
...ain/java/com/ctrip/apollo/biz/entity/ReleaseSnapShot.java
+16
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Version.java
...iz/src/main/java/com/ctrip/apollo/biz/entity/Version.java
+16
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ClusterRepository.java
...va/com/ctrip/apollo/biz/repository/ClusterRepository.java
+13
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ConfigItemRepository.java
...com/ctrip/apollo/biz/repository/ConfigItemRepository.java
+12
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ReleaseSnapShotRepository.java
...trip/apollo/biz/repository/ReleaseSnapShotRepository.java
+4
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/VersionRepository.java
...va/com/ctrip/apollo/biz/repository/VersionRepository.java
+6
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AdminConfigService.java
...java/com/ctrip/apollo/biz/service/AdminConfigService.java
+22
-0
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/impl/AdminConfigServiceImpl.java
...ctrip/apollo/biz/service/impl/AdminConfigServiceImpl.java
+111
-0
apollo-biz/src/main/resources/import.sql
apollo-biz/src/main/resources/import.sql
+18
-1
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
+1
-2
apollo-core/src/main/java/com/ctrip/apollo/core/Constants.java
...o-core/src/main/java/com/ctrip/apollo/core/Constants.java
+9
-0
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ClusterDTO.java
...e/src/main/java/com/ctrip/apollo/core/dto/ClusterDTO.java
+34
-0
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ConfigItemDTO.java
...rc/main/java/com/ctrip/apollo/core/dto/ConfigItemDTO.java
+125
-0
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ReleaseSnapshotDTO.java
...in/java/com/ctrip/apollo/core/dto/ReleaseSnapshotDTO.java
+48
-0
apollo-core/src/main/java/com/ctrip/apollo/core/dto/VersionDTO.java
...e/src/main/java/com/ctrip/apollo/core/dto/VersionDTO.java
+58
-0
apollo-portal/pom.xml
apollo-portal/pom.xml
+1
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/RestUtils.java
...rtal/src/main/java/com/ctrip/apollo/portal/RestUtils.java
+17
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java
...ava/com/ctrip/apollo/portal/controller/AppController.java
+1
-1
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
.../com/ctrip/apollo/portal/controller/ConfigController.java
+34
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/VersionController.java
...com/ctrip/apollo/portal/controller/VersionController.java
+23
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/App.java
...tal/src/main/java/com/ctrip/apollo/portal/entity/App.java
+4
-3
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/AppConfigVO.java
...main/java/com/ctrip/apollo/portal/entity/AppConfigVO.java
+185
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/Privilege.java
...c/main/java/com/ctrip/apollo/portal/entity/Privilege.java
+3
-3
apollo-portal/src/main/java/com/ctrip/apollo/portal/enums/Env.java
...rtal/src/main/java/com/ctrip/apollo/portal/enums/Env.java
+32
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/repository/AppRepository.java
...ava/com/ctrip/apollo/portal/repository/AppRepository.java
+2
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/repository/PrivilegeRepository.java
...m/ctrip/apollo/portal/repository/PrivilegeRepository.java
+3
-3
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
...main/java/com/ctrip/apollo/portal/service/AppService.java
+2
-2
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+23
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/PrivilegeService.java
...ava/com/ctrip/apollo/portal/service/PrivilegeService.java
+4
-4
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/VersionService.java
.../java/com/ctrip/apollo/portal/service/VersionService.java
+15
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/impl/ConfigServiceImpl.java
...m/ctrip/apollo/portal/service/impl/ConfigServiceImpl.java
+253
-0
apollo-portal/src/main/resources/application.yml
apollo-portal/src/main/resources/application.yml
+3
-0
apollo-portal/src/main/resources/import.sql
apollo-portal/src/main/resources/import.sql
+1
-0
apollo-portal/src/main/resources/static/scripts/controller/app/AppConfigController.js
...rces/static/scripts/controller/app/AppConfigController.js
+61
-82
apollo-portal/src/main/resources/static/scripts/controller/app/AppInfoController.js
...ources/static/scripts/controller/app/AppInfoController.js
+5
-4
apollo-portal/src/main/resources/static/scripts/controller/app/AppPageController.js
...ources/static/scripts/controller/app/AppPageController.js
+16
-0
apollo-portal/src/main/resources/static/scripts/services/ConfigService.js
...c/main/resources/static/scripts/services/ConfigService.js
+25
-0
apollo-portal/src/main/resources/static/scripts/services/VersionService.js
.../main/resources/static/scripts/services/VersionService.js
+24
-0
apollo-portal/src/main/resources/static/styles/common-style.css
...-portal/src/main/resources/static/styles/common-style.css
+1
-1
apollo-portal/src/main/resources/static/views/app/config.html
...lo-portal/src/main/resources/static/views/app/config.html
+150
-185
apollo-portal/src/main/resources/static/views/app/index.html
apollo-portal/src/main/resources/static/views/app/index.html
+10
-8
apollo-portal/src/main/resources/static/views/app/info.html
apollo-portal/src/main/resources/static/views/app/info.html
+1
-1
apollo-portal/src/test/java/com/ctrip/apollo/portal/AllTests.java
...ortal/src/test/java/com/ctrip/apollo/portal/AllTests.java
+2
-2
apollo-portal/src/test/java/com/ctrip/apollo/portal/controller/AppControllerTest.java
...com/ctrip/apollo/portal/controller/AppControllerTest.java
+4
-4
apollo-portal/src/test/java/com/ctrip/apollo/portal/repository/AppRepositoryTest.java
...com/ctrip/apollo/portal/repository/AppRepositoryTest.java
+1
-1
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/ConfigServiceTest.java
...va/com/ctrip/apollo/portal/service/ConfigServiceTest.java
+243
-0
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/PrivilegeServiceTest.java
...com/ctrip/apollo/portal/service/PrivilegeServiceTest.java
+2
-2
No files found.
apollo-adminservice/pom.xml
View file @
71ffb8c6
...
@@ -11,50 +11,28 @@
...
@@ -11,50 +11,28 @@
<artifactId>
apollo-adminservice
</artifactId>
<artifactId>
apollo-adminservice
</artifactId>
<name>
Apollo AdminService
</name>
<name>
Apollo AdminService
</name>
<dependencies>
<dependencies>
<!-- apollo -->
<!-- apollo -->
<dependency>
<dependency>
<groupId>
com.ctrip.apollo
</groupId>
<groupId>
com.ctrip.apollo
</groupId>
<artifactId>
apollo-biz
</artifactId>
<artifactId>
apollo-biz
</artifactId>
</dependency>
</dependency>
<!-- end of apollo -->
<!-- end of apollo -->
<!-- web -->
<!-- redis -->
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-boot-starter-web
</artifactId>
<artifactId>
spring-data-redis
</artifactId>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<groupId>
redis.clients
</groupId>
<artifactId>
spring-boot-starter-tomcat
</artifactId>
<artifactId>
jedis
</artifactId>
<scope>
provided
</scope>
</dependency>
</dependency>
<!-- end of redis -->
<!-- end of web -->
<!-- eureka -->
<!-- redis -->
<dependency>
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-redis
</artifactId>
</dependency>
<dependency>
<groupId>
redis.clients
</groupId>
<artifactId>
jedis
</artifactId>
</dependency>
<!-- end of redis -->
<!-- eureka -->
<dependency>
<dependency>
<groupId>
org.springframework.cloud
</groupId>
<groupId>
org.springframework.cloud
</groupId>
<artifactId>
spring-cloud-starter-eureka
</artifactId>
<artifactId>
spring-cloud-starter-eureka
-server
</artifactId>
</dependency>
</dependency>
<!-- end of eureka -->
<!-- end of eureka -->
<!-- jsp -->
<dependency>
<groupId>
javax.servlet
</groupId>
<artifactId>
jstl
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.tomcat.embed
</groupId>
<artifactId>
tomcat-embed-jasper
</artifactId>
<scope>
provided
</scope>
</dependency>
<!-- end of jsp -->
</dependencies>
</dependencies>
<build>
<build>
<plugins>
<plugins>
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/
adminservice/
AdminServiceApplication.java
→
apollo-adminservice/src/main/java/com/ctrip/apollo/AdminServiceApplication.java
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
adminservice
;
package
com
.
ctrip
.
apollo
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
...
@@ -6,7 +6,7 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
...
@@ -6,7 +6,7 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@SpringBootApplication
@EnableEurekaClient
//
@EnableEurekaClient
public
class
AdminServiceApplication
{
public
class
AdminServiceApplication
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
AdminServiceApplication
.
class
).
web
(
true
).
run
(
args
);
new
SpringApplicationBuilder
(
AdminServiceApplication
.
class
).
web
(
true
).
run
(
args
);
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ClusterController.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
adminservice
.
controller
;
import
com.ctrip.apollo.biz.service.AdminConfigService
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
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.List
;
@RestController
@RequestMapping
(
"/cluster"
)
public
class
ClusterController
{
@Autowired
private
AdminConfigService
adminConfigService
;
@RequestMapping
(
"/app/{appId}"
)
public
List
<
ClusterDTO
>
findClustersByApp
(
@PathVariable
long
appId
){
return
adminConfigService
.
findClustersByApp
(
appId
);
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ConfigController.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
adminservice
.
controller
;
import
com.ctrip.apollo.biz.service.AdminConfigService
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/configs"
)
public
class
ConfigController
{
@Resource
(
name
=
"adminConfigService"
)
private
AdminConfigService
adminConfigService
;
@RequestMapping
(
"/release/{releaseId}"
)
public
List
<
ReleaseSnapshotDTO
>
getRelaseSnapshot
(
@PathVariable
long
releaseId
){
return
adminConfigService
.
findReleaseSnapshotByReleaseId
(
releaseId
);
}
@RequestMapping
(
"/latest"
)
public
List
<
ConfigItemDTO
>
findConfigItemsByClusters
(
@RequestParam
(
value
=
"clusterIds"
)
List
<
Long
>
clusterIds
){
return
adminConfigService
.
findConfigItemsByClusters
(
clusterIds
);
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/VersionController.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
adminservice
.
controller
;
import
com.ctrip.apollo.biz.service.AdminConfigService
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
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.List
;
@RestController
@RequestMapping
(
"/version"
)
public
class
VersionController
{
@Autowired
private
AdminConfigService
adminConfigService
;
@RequestMapping
(
"/app/{appId}"
)
public
List
<
VersionDTO
>
versions
(
@PathVariable
long
appId
){
return
adminConfigService
.
findVersionsByApp
(
appId
);
}
@RequestMapping
(
"/{versionId}"
)
public
VersionDTO
version
(
@PathVariable
long
versionId
){
return
adminConfigService
.
loadVersionById
(
versionId
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Cluster.java
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
biz
.
entity
;
package
com
.
ctrip
.
apollo
.
biz
.
entity
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
import
org.hibernate.annotations.Where
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Id
;
...
@@ -18,8 +20,12 @@ public class Cluster {
...
@@ -18,8 +20,12 @@ public class Cluster {
@GeneratedValue
@GeneratedValue
private
long
id
;
private
long
id
;
@Column
(
nullable
=
false
)
private
String
name
;
private
String
name
;
@Column
(
nullable
=
false
)
private
long
appId
;
private
long
appId
;
private
boolean
isDeleted
;
private
boolean
isDeleted
;
public
Cluster
()
{
public
Cluster
()
{
...
@@ -56,4 +62,12 @@ public class Cluster {
...
@@ -56,4 +62,12 @@ public class Cluster {
public
void
setDeleted
(
boolean
deleted
)
{
public
void
setDeleted
(
boolean
deleted
)
{
isDeleted
=
deleted
;
isDeleted
=
deleted
;
}
}
public
ClusterDTO
toDTO
(){
ClusterDTO
dto
=
new
ClusterDTO
();
dto
.
setAppId
(
appId
);
dto
.
setId
(
id
);
dto
.
setName
(
name
);
return
dto
;
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/ConfigItem.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
biz
.
entity
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
java.util.Date
;
@Entity
@Where
(
clause
=
"isDeleted = 0"
)
@SQLDelete
(
sql
=
"Update ConfigItem set isDeleted = 1 where id = ?"
)
public
class
ConfigItem
{
@Id
@GeneratedValue
private
long
id
;
@Column
(
nullable
=
false
)
private
long
clusterId
;
@Column
(
nullable
=
false
)
private
String
clusterName
;
@Column
(
nullable
=
false
)
private
long
appId
;
@Column
(
nullable
=
false
)
private
String
key
;
@Column
private
String
value
;
@Column
private
String
comment
;
@Column
private
String
dataChangeCreatedBy
;
@Column
private
Date
dataChangeCreatedTime
;
@Column
private
String
dataChangeLastModifiedBy
;
@Column
private
Date
dataChangeLastModifiedTime
;
@Column
private
boolean
IsDeleted
;
public
long
getId
()
{
return
id
;
}
public
void
setId
(
long
id
)
{
this
.
id
=
id
;
}
public
long
getClusterId
()
{
return
clusterId
;
}
public
void
setClusterId
(
long
clusterId
)
{
this
.
clusterId
=
clusterId
;
}
public
String
getClusterName
()
{
return
clusterName
;
}
public
void
setClusterName
(
String
clusterName
)
{
this
.
clusterName
=
clusterName
;
}
public
long
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
long
appId
)
{
this
.
appId
=
appId
;
}
public
String
getKey
()
{
return
key
;
}
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
}
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
public
String
getComment
()
{
return
comment
;
}
public
void
setComment
(
String
comment
)
{
this
.
comment
=
comment
;
}
public
String
getDataChangeCreatedBy
()
{
return
dataChangeCreatedBy
;
}
public
void
setDataChangeCreatedBy
(
String
dataChangeCreatedBy
)
{
this
.
dataChangeCreatedBy
=
dataChangeCreatedBy
;
}
public
Date
getDataChangeCreatedTime
()
{
return
dataChangeCreatedTime
;
}
public
void
setDataChangeCreatedTime
(
Date
dataChangeCreatedTime
)
{
this
.
dataChangeCreatedTime
=
dataChangeCreatedTime
;
}
public
String
getDataChangeLastModifiedBy
()
{
return
dataChangeLastModifiedBy
;
}
public
void
setDataChangeLastModifiedBy
(
String
dataChangeLastModifiedBy
)
{
this
.
dataChangeLastModifiedBy
=
dataChangeLastModifiedBy
;
}
public
boolean
isDeleted
()
{
return
IsDeleted
;
}
public
void
setDeleted
(
boolean
isDeleted
)
{
IsDeleted
=
isDeleted
;
}
public
Date
getDataChangeLastModifiedTime
()
{
return
dataChangeLastModifiedTime
;
}
public
void
setDataChangeLastModifiedTime
(
Date
dataChangeLastModifiedTime
)
{
this
.
dataChangeLastModifiedTime
=
dataChangeLastModifiedTime
;
}
public
ConfigItemDTO
toDTO
(){
ConfigItemDTO
dto
=
new
ConfigItemDTO
();
dto
.
setAppId
(
appId
);
dto
.
setId
(
id
);
dto
.
setClusterId
(
clusterId
);
dto
.
setClusterName
(
clusterName
);
dto
.
setDataChangeCreatedBy
(
dataChangeCreatedBy
);
dto
.
setDataChangeLastModifiedBy
(
dataChangeLastModifiedBy
);
dto
.
setDataChangeCreatedTime
(
dataChangeCreatedTime
);
dto
.
setDataChangeLastModifiedTime
(
dataChangeLastModifiedTime
);
dto
.
setKey
(
key
);
dto
.
setValue
(
value
);
dto
.
setComment
(
comment
);
return
dto
;
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/ReleaseSnapShot.java
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
biz
.
entity
;
package
com
.
ctrip
.
apollo
.
biz
.
entity
;
import
com.ctrip.apollo.core.dto.ReleaseSnapshotDTO
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
import
org.hibernate.annotations.Where
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Id
;
...
@@ -18,10 +20,15 @@ public class ReleaseSnapShot {
...
@@ -18,10 +20,15 @@ public class ReleaseSnapShot {
@GeneratedValue
@GeneratedValue
private
long
id
;
private
long
id
;
@Column
(
nullable
=
false
)
private
long
releaseId
;
private
long
releaseId
;
@Column
(
nullable
=
false
)
private
String
clusterName
;
private
String
clusterName
;
@Column
(
nullable
=
false
)
private
String
configurations
;
private
String
configurations
;
private
boolean
isDeleted
;
private
boolean
isDeleted
;
public
ReleaseSnapShot
()
{
public
ReleaseSnapShot
()
{
...
@@ -66,4 +73,13 @@ public class ReleaseSnapShot {
...
@@ -66,4 +73,13 @@ public class ReleaseSnapShot {
public
void
setDeleted
(
boolean
deleted
)
{
public
void
setDeleted
(
boolean
deleted
)
{
isDeleted
=
deleted
;
isDeleted
=
deleted
;
}
}
public
ReleaseSnapshotDTO
toDTO
(){
ReleaseSnapshotDTO
dto
=
new
ReleaseSnapshotDTO
();
dto
.
setId
(
id
);
dto
.
setClusterName
(
clusterName
);
dto
.
setConfigurations
(
configurations
);
dto
.
setReleaseId
(
releaseId
);
return
dto
;
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Version.java
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
biz
.
entity
;
package
com
.
ctrip
.
apollo
.
biz
.
entity
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.Where
;
import
org.hibernate.annotations.Where
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Id
;
...
@@ -18,9 +20,13 @@ public class Version {
...
@@ -18,9 +20,13 @@ public class Version {
@GeneratedValue
@GeneratedValue
private
long
id
;
private
long
id
;
@Column
(
nullable
=
false
)
private
String
name
;
private
String
name
;
@Column
(
nullable
=
false
)
private
long
appId
;
private
long
appId
;
@Column
(
nullable
=
false
)
private
long
releaseId
;
private
long
releaseId
;
//parent version could be null
//parent version could be null
private
Long
parentVersion
;
private
Long
parentVersion
;
...
@@ -76,4 +82,14 @@ public class Version {
...
@@ -76,4 +82,14 @@ public class Version {
public
void
setParentVersion
(
Long
parentVersion
)
{
public
void
setParentVersion
(
Long
parentVersion
)
{
this
.
parentVersion
=
parentVersion
;
this
.
parentVersion
=
parentVersion
;
}
}
public
VersionDTO
toDTO
()
{
VersionDTO
dto
=
new
VersionDTO
();
dto
.
setAppId
(
this
.
appId
);
dto
.
setId
(
this
.
id
);
dto
.
setName
(
this
.
name
);
dto
.
setParentVersion
(
this
.
parentVersion
);
dto
.
setReleaseId
(
this
.
releaseId
);
return
dto
;
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ClusterRepository.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.List
;
public
interface
ClusterRepository
extends
PagingAndSortingRepository
<
Cluster
,
Long
>
{
List
<
Cluster
>
findByAppId
(
long
appId
);
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ConfigItemRepository.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
biz
.
repository
;
import
com.ctrip.apollo.biz.entity.ConfigItem
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.List
;
public
interface
ConfigItemRepository
extends
PagingAndSortingRepository
<
ConfigItem
,
Long
>
{
List
<
ConfigItem
>
findByClusterIdIsIn
(
List
<
Long
>
clusterIds
);
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ReleaseSnapShotRepository.java
View file @
71ffb8c6
...
@@ -3,9 +3,13 @@ package com.ctrip.apollo.biz.repository;
...
@@ -3,9 +3,13 @@ package com.ctrip.apollo.biz.repository;
import
com.ctrip.apollo.biz.entity.ReleaseSnapShot
;
import
com.ctrip.apollo.biz.entity.ReleaseSnapShot
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.List
;
/**
/**
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
*/
*/
public
interface
ReleaseSnapShotRepository
extends
PagingAndSortingRepository
<
ReleaseSnapShot
,
Long
>
{
public
interface
ReleaseSnapShotRepository
extends
PagingAndSortingRepository
<
ReleaseSnapShot
,
Long
>
{
ReleaseSnapShot
findByReleaseIdAndClusterName
(
long
releaseId
,
String
clusterName
);
ReleaseSnapShot
findByReleaseIdAndClusterName
(
long
releaseId
,
String
clusterName
);
List
<
ReleaseSnapShot
>
findByReleaseId
(
long
releaseId
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/VersionRepository.java
View file @
71ffb8c6
...
@@ -3,9 +3,15 @@ package com.ctrip.apollo.biz.repository;
...
@@ -3,9 +3,15 @@ package com.ctrip.apollo.biz.repository;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.biz.entity.Version
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.List
;
/**
/**
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
*/
*/
public
interface
VersionRepository
extends
PagingAndSortingRepository
<
Version
,
Long
>
{
public
interface
VersionRepository
extends
PagingAndSortingRepository
<
Version
,
Long
>
{
Version
findByAppIdAndName
(
long
appId
,
String
name
);
Version
findByAppIdAndName
(
long
appId
,
String
name
);
Version
findById
(
long
id
);
List
<
Version
>
findByAppId
(
long
appId
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/AdminConfigService.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
biz
.
service
;
import
com.ctrip.apollo.core.dto.*
;
import
java.util.List
;
/**
* config service for admin
*/
public
interface
AdminConfigService
{
List
<
ReleaseSnapshotDTO
>
findReleaseSnapshotByReleaseId
(
long
releaseId
);
List
<
VersionDTO
>
findVersionsByApp
(
long
appId
);
VersionDTO
loadVersionById
(
long
versionId
);
List
<
ClusterDTO
>
findClustersByApp
(
long
appId
);
List
<
ConfigItemDTO
>
findConfigItemsByClusters
(
List
<
Long
>
clusterIds
);
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/impl/AdminConfigServiceImpl.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
biz
.
service
.
impl
;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.entity.ConfigItem
;
import
com.ctrip.apollo.biz.entity.ReleaseSnapShot
;
import
com.ctrip.apollo.biz.entity.Version
;
import
com.ctrip.apollo.biz.repository.ClusterRepository
;
import
com.ctrip.apollo.biz.repository.ConfigItemRepository
;
import
com.ctrip.apollo.biz.repository.ReleaseSnapShotRepository
;
import
com.ctrip.apollo.biz.repository.VersionRepository
;
import
com.ctrip.apollo.biz.service.AdminConfigService
;
import
com.ctrip.apollo.core.dto.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.*
;
@Service
(
"adminConfigService"
)
public
class
AdminConfigServiceImpl
implements
AdminConfigService
{
@Autowired
private
VersionRepository
versionRepository
;
@Autowired
private
ReleaseSnapShotRepository
releaseSnapShotRepository
;
@Autowired
private
ClusterRepository
clusterRepository
;
@Autowired
private
ConfigItemRepository
configItemRepository
;
@Override
public
List
<
ReleaseSnapshotDTO
>
findReleaseSnapshotByReleaseId
(
long
releaseId
)
{
if
(
releaseId
<=
0
){
return
Collections
.
EMPTY_LIST
;
}
List
<
ReleaseSnapShot
>
releaseSnapShots
=
releaseSnapShotRepository
.
findByReleaseId
(
releaseId
);
if
(
releaseSnapShots
==
null
||
releaseSnapShots
.
size
()
==
0
){
return
Collections
.
EMPTY_LIST
;
}
List
<
ReleaseSnapshotDTO
>
result
=
new
ArrayList
<>(
releaseSnapShots
.
size
());
for
(
ReleaseSnapShot
releaseSnapShot:
releaseSnapShots
){
result
.
add
(
releaseSnapShot
.
toDTO
());
}
return
result
;
}
@Override
public
List
<
VersionDTO
>
findVersionsByApp
(
long
appId
)
{
if
(
appId
<=
0
)
{
return
Collections
.
EMPTY_LIST
;
}
List
<
Version
>
versions
=
versionRepository
.
findByAppId
(
appId
);
if
(
versions
==
null
||
versions
.
size
()
==
0
)
{
return
Collections
.
EMPTY_LIST
;
}
List
<
VersionDTO
>
result
=
new
ArrayList
<>(
versions
.
size
());
for
(
Version
version
:
versions
)
{
result
.
add
(
version
.
toDTO
());
}
return
result
;
}
@Override
public
VersionDTO
loadVersionById
(
long
versionId
)
{
if
(
versionId
<=
0
){
return
null
;
}
Version
version
=
versionRepository
.
findById
(
versionId
);
return
version
.
toDTO
();
}
@Override
public
List
<
ClusterDTO
>
findClustersByApp
(
long
appId
)
{
if
(
appId
<=
0
){
return
Collections
.
EMPTY_LIST
;
}
List
<
Cluster
>
clusters
=
clusterRepository
.
findByAppId
(
appId
);
if
(
clusters
==
null
||
clusters
.
size
()
==
0
){
return
Collections
.
EMPTY_LIST
;
}
List
<
ClusterDTO
>
result
=
new
ArrayList
<>(
clusters
.
size
());
for
(
Cluster
cluster:
clusters
){
result
.
add
(
cluster
.
toDTO
());
}
return
result
;
}
@Override
public
List
<
ConfigItemDTO
>
findConfigItemsByClusters
(
List
<
Long
>
clusterIds
)
{
if
(
clusterIds
==
null
||
clusterIds
.
size
()
==
0
){
return
Collections
.
EMPTY_LIST
;
}
List
<
ConfigItem
>
configItems
=
configItemRepository
.
findByClusterIdIsIn
(
clusterIds
);
if
(
configItems
==
null
||
configItems
.
size
()
==
0
){
return
Collections
.
EMPTY_LIST
;
}
List
<
ConfigItemDTO
>
result
=
new
ArrayList
<>(
configItems
.
size
());
for
(
ConfigItem
configItem:
configItems
){
result
.
add
(
configItem
.
toDTO
());
}
return
result
;
}
}
apollo-biz/src/main/resources/import.sql
View file @
71ffb8c6
INSERT
INTO
Cluster
(
AppId
,
IsDeleted
,
Name
)
VALUES
(
100
,
0
,
'default'
);
INSERT
INTO
Cluster
(
AppId
,
IsDeleted
,
Name
)
VALUES
(
100
,
0
,
'default'
);
INSERT
INTO
Cluster
(
AppId
,
IsDeleted
,
Name
)
VALUES
(
101
,
0
,
'default'
);
INSERT
INTO
Cluster
(
ID
,
AppId
,
IsDeleted
,
Name
)
VALUES
(
100
,
6666
,
0
,
'default-cluster-name'
);
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
(
101
,
0
,
'1.0'
,
1
);
INSERT
INTO
Version
(
AppId
,
IsDeleted
,
Name
,
ReleaseId
)
VALUES
(
102
,
0
,
'1.0'
,
2
);
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
,
'{"apollo.foo":"bar", "apollo.bar":"foo"}'
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'default'
,
0
,
1
,
'{"apollo.foo":"bar", "apollo.bar":"foo"}'
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'default'
,
0
,
2
,
'{"demo.foo":"demo1", "demo.bar":"demo2"}'
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'default'
,
0
,
2
,
'{"demo.foo":"demo1", "demo.bar":"demo2"}'
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'default-cluster-name'
,
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-cluster-name'
,
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
,
dataChangeCreatedBy
,
dataChangeCreatedTime
,
dataChangeLastModifiedBy
,
dataChangeLastModifiedTime
,
IsDeleted
)
VALUES
(
100
,
'default-cluster-name'
,
6666
,
'6666.k1'
,
'6666.v1'
,
'comment1'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五'
,
NOW
(),
0
);
INSERT
INTO
ConfigItem
(
ClusterId
,
ClusterName
,
AppId
,
Key
,
Value
,
comment
,
dataChangeCreatedBy
,
dataChangeCreatedTime
,
dataChangeLastModifiedBy
,
dataChangeLastModifiedTime
,
IsDeleted
)
VALUES
(
100
,
'default-cluster-name'
,
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
,
dataChangeCreatedBy
,
dataChangeCreatedTime
,
dataChangeLastModifiedBy
,
dataChangeLastModifiedTime
,
IsDeleted
)
VALUES
(
100
,
'default-cluster-name'
,
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
,
dataChangeCreatedBy
,
dataChangeCreatedTime
,
dataChangeLastModifiedBy
,
dataChangeLastModifiedTime
,
IsDeleted
)
VALUES
(
100
,
'default-cluster-name'
,
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
,
dataChangeCreatedBy
,
dataChangeCreatedTime
,
dataChangeLastModifiedBy
,
dataChangeLastModifiedTime
,
IsDeleted
)
VALUES
(
101
,
'cluster1'
,
6666
,
'6666.k1'
,
'6666.v122'
,
'qqqqq'
,
'lepdou'
,
'2016-03-23 12:00:00'
,
'王五4'
,
NOW
(),
0
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'default'
,
0
,
3
,
'{"apollo.foo":"another bar", "apollo.bar_new":"foo"}'
);
INSERT
INTO
RELEASESNAPSHOT
(
ClusterName
,
IsDeleted
,
ReleaseId
,
Configurations
)
VALUES
(
'default'
,
0
,
3
,
'{"apollo.foo":"another bar", "apollo.bar_new":"foo"}'
);
apollo-biz/src/test/java/com/ctrip/apollo/biz/AllTests.java
View file @
71ffb8c6
...
@@ -7,8 +7,7 @@ import org.junit.runners.Suite.SuiteClasses;
...
@@ -7,8 +7,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith
(
Suite
.
class
)
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
@SuiteClasses
({
ConfigServiceImplTest
.
class
ConfigServiceImplTest
.
class
})
})
public
class
AllTests
{
public
class
AllTests
{
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/Constants.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
core
;
public
interface
Constants
{
String
DEFAULT_CLUSTER_NAME
=
"default-cluster-name"
;
long
LASTEST_VERSION_ID
=
-
1
;
}
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ClusterDTO.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
core
.
dto
;
public
class
ClusterDTO
{
private
long
id
;
private
String
name
;
private
long
appId
;
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
long
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
long
appId
)
{
this
.
appId
=
appId
;
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ConfigItemDTO.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
core
.
dto
;
import
java.util.Date
;
public
class
ConfigItemDTO
{
private
long
id
;
private
long
clusterId
;
private
String
clusterName
;
private
long
appId
;
private
String
key
;
private
String
value
;
private
String
comment
;
private
String
dataChangeCreatedBy
;
private
Date
dataChangeCreatedTime
;
private
String
DataChangeLastModifiedBy
;
private
Date
dataChangeLastModifiedTime
;
public
ConfigItemDTO
(){
}
public
ConfigItemDTO
(
String
key
,
String
value
){
this
.
key
=
key
;
this
.
value
=
value
;
}
public
long
getId
()
{
return
id
;
}
public
void
setId
(
long
id
)
{
this
.
id
=
id
;
}
public
long
getClusterId
()
{
return
clusterId
;
}
public
void
setClusterId
(
long
clusterId
)
{
this
.
clusterId
=
clusterId
;
}
public
String
getClusterName
()
{
return
clusterName
;
}
public
void
setClusterName
(
String
clusterName
)
{
this
.
clusterName
=
clusterName
;
}
public
long
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
long
appId
)
{
this
.
appId
=
appId
;
}
public
String
getKey
()
{
return
key
;
}
public
void
setKey
(
String
key
)
{
this
.
key
=
key
;
}
public
String
getValue
()
{
return
value
;
}
public
void
setValue
(
String
value
)
{
this
.
value
=
value
;
}
public
String
getDataChangeCreatedBy
()
{
return
dataChangeCreatedBy
;
}
public
void
setDataChangeCreatedBy
(
String
dataChangeCreatedBy
)
{
this
.
dataChangeCreatedBy
=
dataChangeCreatedBy
;
}
public
Date
getDataChangeCreatedTime
()
{
return
dataChangeCreatedTime
;
}
public
void
setDataChangeCreatedTime
(
Date
dataChangeCreatedTime
)
{
this
.
dataChangeCreatedTime
=
dataChangeCreatedTime
;
}
public
String
getDataChangeLastModifiedBy
()
{
return
DataChangeLastModifiedBy
;
}
public
void
setDataChangeLastModifiedBy
(
String
dataChangeLastModifiedBy
)
{
DataChangeLastModifiedBy
=
dataChangeLastModifiedBy
;
}
public
Date
getDataChangeLastModifiedTime
()
{
return
dataChangeLastModifiedTime
;
}
public
void
setDataChangeLastModifiedTime
(
Date
dataChangeLastModifiedTime
)
{
this
.
dataChangeLastModifiedTime
=
dataChangeLastModifiedTime
;
}
public
String
getComment
()
{
return
comment
;
}
public
void
setComment
(
String
comment
)
{
this
.
comment
=
comment
;
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ReleaseSnapshotDTO.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
core
.
dto
;
public
class
ReleaseSnapshotDTO
{
private
long
id
;
private
long
releaseId
;
private
String
clusterName
;
private
String
configurations
;
public
ReleaseSnapshotDTO
()
{
}
public
long
getId
()
{
return
id
;
}
public
void
setId
(
long
id
)
{
this
.
id
=
id
;
}
public
long
getReleaseId
()
{
return
releaseId
;
}
public
void
setReleaseId
(
long
releaseId
)
{
this
.
releaseId
=
releaseId
;
}
public
String
getClusterName
()
{
return
clusterName
;
}
public
void
setClusterName
(
String
clusterName
)
{
this
.
clusterName
=
clusterName
;
}
public
String
getConfigurations
()
{
return
configurations
;
}
public
void
setConfigurations
(
String
configurations
)
{
this
.
configurations
=
configurations
;
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/dto/VersionDTO.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
core
.
dto
;
public
class
VersionDTO
{
private
long
id
;
private
String
name
;
private
long
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
long
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
long
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/pom.xml
View file @
71ffb8c6
...
@@ -37,6 +37,7 @@
...
@@ -37,6 +37,7 @@
<artifactId>
mysql-connector-java
</artifactId>
<artifactId>
mysql-connector-java
</artifactId>
<scope>
runtime
</scope>
<scope>
runtime
</scope>
</dependency>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
<plugins>
<plugins>
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/RestUtils.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
portal
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.RestTemplate
;
public
class
RestUtils
{
private
static
RestTemplate
restTemplate
=
new
RestTemplate
();
public
static
<
T
>
T
exchangeInGET
(
String
url
,
Class
<
T
>
responseType
)
{
ResponseEntity
<
T
>
response
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
new
HttpEntity
<
Void
>((
Void
)
null
),
responseType
);
return
response
.
getBody
();
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java
View file @
71ffb8c6
...
@@ -28,7 +28,7 @@ public class AppController {
...
@@ -28,7 +28,7 @@ public class AppController {
}
}
@RequestMapping
(
"/{appid}"
)
@RequestMapping
(
"/{appid}"
)
public
App
detail
(
@PathVariable
Stri
ng
appid
)
{
public
App
detail
(
@PathVariable
lo
ng
appid
)
{
App
app
=
appService
.
detail
(
appid
);
App
app
=
appService
.
detail
(
appid
);
if
(
app
==
null
)
{
if
(
app
==
null
)
{
throw
new
NotFoundException
();
throw
new
NotFoundException
();
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
portal
.
controller
;
import
com.ctrip.apollo.core.Constants
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
com.ctrip.apollo.portal.exception.NotFoundException
;
import
com.ctrip.apollo.portal.service.ConfigService
;
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
;
@RestController
@RequestMapping
(
"/configs"
)
public
class
ConfigController
{
@Autowired
private
ConfigService
configService
;
@RequestMapping
(
"/{appId}/{env}/{versionId}"
)
public
AppConfigVO
detail
(
@PathVariable
long
appId
,
@PathVariable
String
env
,
@PathVariable
long
versionId
)
{
if
(
appId
<=
0
)
{
throw
new
NotFoundException
();
}
if
(
versionId
==
Constants
.
LASTEST_VERSION_ID
)
{
return
configService
.
loadLatestConfig
(
appId
);
}
else
if
(
versionId
>
0
)
{
return
configService
.
loadReleaseConfig
(
appId
,
versionId
);
}
else
{
throw
new
NotFoundException
();
}
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/VersionController.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
portal
.
controller
;
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.List
;
@RestController
@RequestMapping
(
"/version"
)
public
class
VersionController
{
@Autowired
private
VersionService
versionService
;
@RequestMapping
(
"/{appId}/{env}"
)
public
List
<
VersionDTO
>
versions
(
@PathVariable
long
appId
,
@PathVariable
String
env
){
return
versionService
.
findVersionsByApp
(
appId
,
env
);
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/App.java
View file @
71ffb8c6
...
@@ -16,7 +16,7 @@ public class App implements Serializable {
...
@@ -16,7 +16,7 @@ public class App implements Serializable {
private
static
final
long
serialVersionUID
=
7348554309210401557L
;
private
static
final
long
serialVersionUID
=
7348554309210401557L
;
@Id
@Id
private
Stri
ng
appId
;
private
lo
ng
appId
;
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
private
String
name
;
private
String
name
;
...
@@ -36,11 +36,12 @@ public class App implements Serializable {
...
@@ -36,11 +36,12 @@ public class App implements Serializable {
@Column
@Column
private
Date
lastUpdatedTimestamp
;
private
Date
lastUpdatedTimestamp
;
public
String
getAppId
()
{
public
long
getAppId
()
{
return
appId
;
return
appId
;
}
}
public
void
setAppId
(
Stri
ng
appId
)
{
public
void
setAppId
(
lo
ng
appId
)
{
this
.
appId
=
appId
;
this
.
appId
=
appId
;
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/AppConfigVO.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
portal
.
entity
;
import
com.ctrip.apollo.core.dto.ConfigItemDTO
;
import
com.ctrip.apollo.portal.enums.Env
;
import
java.util.LinkedList
;
import
java.util.List
;
public
class
AppConfigVO
{
private
long
appId
;
private
Env
env
;
/**
* latest version if version is zero, or is release version
*/
private
long
versionId
;
/**
* default cluster and app self’s configs
*/
private
List
<
ConfigItemDTO
>
defaultClusterConfigs
;
/**
* default cluster and override other app configs
*/
private
List
<
OverrideAppConfig
>
overrideAppConfigs
;
/**
* configs in different cluster maybe different.
* overrideClusterConfigs only save diff configs from default cluster.
* For example:
* default cluster has 3 configs:
* {a -> A, b -> B, c -> C}
*
* cluster1 has 1 config
* {b -> D}
*
* if client read cluster1 configs will return {a -> A, b -> D, c -> C}
*
*
*/
private
List
<
OverrideClusterConfig
>
overrideClusterConfigs
;
public
AppConfigVO
(){
}
public
static
AppConfigVO
newInstance
(
long
appId
,
long
versionId
){
AppConfigVO
instance
=
new
AppConfigVO
();
instance
.
setAppId
(
appId
);
instance
.
setVersionId
(
versionId
);
instance
.
setDefaultClusterConfigs
(
new
LinkedList
<>());
instance
.
setOverrideAppConfigs
(
new
LinkedList
<>());
instance
.
setOverrideClusterConfigs
(
new
LinkedList
<>());
return
instance
;
}
public
boolean
isLatestVersion
()
{
return
versionId
==
0
;
}
public
static
class
OverrideAppConfig
{
private
long
appId
;
private
List
<
ConfigItemDTO
>
configs
;
public
OverrideAppConfig
(){
}
public
long
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
long
appId
)
{
this
.
appId
=
appId
;
}
public
List
<
ConfigItemDTO
>
getConfigs
()
{
return
configs
;
}
public
void
setConfigs
(
List
<
ConfigItemDTO
>
configs
)
{
this
.
configs
=
configs
;
}
public
void
addConfig
(
ConfigItemDTO
config
){
if
(
configs
==
null
){
configs
=
new
LinkedList
<>();
}
configs
.
add
(
config
);
}
}
public
static
class
OverrideClusterConfig
{
private
String
clusterName
;
private
List
<
ConfigItemDTO
>
configs
;
public
OverrideClusterConfig
(){}
public
String
getClusterName
()
{
return
clusterName
;
}
public
void
setClusterName
(
String
clusterName
)
{
this
.
clusterName
=
clusterName
;
}
public
List
<
ConfigItemDTO
>
getConfigs
()
{
return
configs
;
}
public
void
setConfigs
(
List
<
ConfigItemDTO
>
configs
)
{
this
.
configs
=
configs
;
}
}
public
long
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
long
appId
)
{
this
.
appId
=
appId
;
}
public
Env
getEnv
()
{
return
env
;
}
public
void
setEnv
(
Env
env
)
{
this
.
env
=
env
;
}
public
long
getVersionId
()
{
return
versionId
;
}
public
void
setVersionId
(
long
versionId
)
{
this
.
versionId
=
versionId
;
}
public
List
<
ConfigItemDTO
>
getDefaultClusterConfigs
()
{
return
defaultClusterConfigs
;
}
public
void
setDefaultClusterConfigs
(
List
<
ConfigItemDTO
>
defaultClusterConfigs
)
{
this
.
defaultClusterConfigs
=
defaultClusterConfigs
;
}
public
List
<
OverrideAppConfig
>
getOverrideAppConfigs
()
{
return
overrideAppConfigs
;
}
public
void
setOverrideAppConfigs
(
List
<
OverrideAppConfig
>
overrideAppConfigs
)
{
this
.
overrideAppConfigs
=
overrideAppConfigs
;
}
public
List
<
OverrideClusterConfig
>
getOverrideClusterConfigs
()
{
return
overrideClusterConfigs
;
}
public
void
setOverrideClusterConfigs
(
List
<
OverrideClusterConfig
>
overrideClusterConfigs
)
{
this
.
overrideClusterConfigs
=
overrideClusterConfigs
;
}
@Override
public
String
toString
()
{
return
"Config4PortalDTO{"
+
"appId="
+
appId
+
", env="
+
env
+
", versionId="
+
versionId
+
", defaultClusterConfigs="
+
defaultClusterConfigs
+
", overrideAppConfigs="
+
overrideAppConfigs
+
", overrideClusterConfigs="
+
overrideClusterConfigs
+
'}'
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/Privilege.java
View file @
71ffb8c6
...
@@ -26,7 +26,7 @@ public class Privilege implements Serializable {
...
@@ -26,7 +26,7 @@ public class Privilege implements Serializable {
private
String
privilType
;
private
String
privilType
;
@Column
@Column
private
Stri
ng
appId
;
private
lo
ng
appId
;
public
long
getId
()
{
public
long
getId
()
{
return
id
;
return
id
;
...
@@ -52,11 +52,11 @@ public class Privilege implements Serializable {
...
@@ -52,11 +52,11 @@ public class Privilege implements Serializable {
this
.
privilType
=
privilType
;
this
.
privilType
=
privilType
;
}
}
public
Stri
ng
getAppId
()
{
public
lo
ng
getAppId
()
{
return
appId
;
return
appId
;
}
}
public
void
setAppId
(
Stri
ng
appId
)
{
public
void
setAppId
(
lo
ng
appId
)
{
this
.
appId
=
appId
;
this
.
appId
=
appId
;
}
}
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/enums/Env.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
portal
.
enums
;
public
enum
Env
{
DEV
(
"dev"
),
FWS
(
"fws"
),
FAT
(
"fat"
),
UAT
(
"uat"
),
LPT
(
"lpt"
),
PROD
(
"prod"
),
TOOLS
(
"tools"
),
UN_KNOW
(
""
);
private
String
value
;
Env
(
String
value
)
{
this
.
value
=
value
;
}
public
static
Env
valueFrom
(
String
env
)
{
if
(
env
==
null
||
""
.
equals
(
env
))
{
return
UN_KNOW
;
}
else
if
(
"dev"
.
equals
(
env
))
{
return
DEV
;
}
else
if
(
"fws"
.
equals
(
env
))
{
return
FWS
;
}
else
if
(
"fat"
.
equals
(
env
))
{
return
FAT
;
}
else
if
(
"uat"
.
equals
(
env
))
{
return
UAT
;
}
else
if
(
"prod"
.
equals
(
env
))
{
return
PROD
;
}
else
if
(
"tools"
.
equals
(
env
))
{
return
TOOLS
;
}
else
{
return
UN_KNOW
;
}
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/repository/AppRepository.java
View file @
71ffb8c6
...
@@ -9,4 +9,6 @@ import com.ctrip.apollo.portal.entity.App;
...
@@ -9,4 +9,6 @@ import com.ctrip.apollo.portal.entity.App;
public
interface
AppRepository
extends
PagingAndSortingRepository
<
App
,
String
>
{
public
interface
AppRepository
extends
PagingAndSortingRepository
<
App
,
String
>
{
Page
<
App
>
findAll
(
Pageable
pageable
);
Page
<
App
>
findAll
(
Pageable
pageable
);
App
findByAppId
(
long
appId
);
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/repository/PrivilegeRepository.java
View file @
71ffb8c6
...
@@ -8,9 +8,9 @@ import com.ctrip.apollo.portal.entity.Privilege;
...
@@ -8,9 +8,9 @@ import com.ctrip.apollo.portal.entity.Privilege;
public
interface
PrivilegeRepository
extends
PagingAndSortingRepository
<
Privilege
,
Long
>
{
public
interface
PrivilegeRepository
extends
PagingAndSortingRepository
<
Privilege
,
Long
>
{
List
<
Privilege
>
findByAppId
(
Stri
ng
appId
);
List
<
Privilege
>
findByAppId
(
lo
ng
appId
);
List
<
Privilege
>
findByAppIdAndPrivilType
(
Stri
ng
appId
,
String
privilType
);
List
<
Privilege
>
findByAppIdAndPrivilType
(
lo
ng
appId
,
String
privilType
);
Privilege
findByAppIdAndNameAndPrivilType
(
Stri
ng
appId
,
String
name
,
String
privilType
);
Privilege
findByAppIdAndNameAndPrivilType
(
lo
ng
appId
,
String
name
,
String
privilType
);
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/AppService.java
View file @
71ffb8c6
...
@@ -16,8 +16,8 @@ public class AppService {
...
@@ -16,8 +16,8 @@ public class AppService {
@Autowired
@Autowired
private
AppRepository
appRepository
;
private
AppRepository
appRepository
;
public
App
detail
(
Stri
ng
appId
)
{
public
App
detail
(
lo
ng
appId
)
{
return
appRepository
.
find
One
(
appId
);
return
appRepository
.
find
ByAppId
(
appId
);
}
}
public
Page
<
App
>
list
(
Pageable
pageable
)
{
public
Page
<
App
>
list
(
Pageable
pageable
)
{
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
portal
.
service
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
public
interface
ConfigService
{
/**
* load config info by appId and versionId
* @param appId
* @param versionId
* @return
*/
AppConfigVO
loadReleaseConfig
(
long
appId
,
long
versionId
);
/**
*
* @param appId
* @return
*/
AppConfigVO
loadLatestConfig
(
long
appId
);
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/PrivilegeService.java
View file @
71ffb8c6
...
@@ -19,7 +19,7 @@ public class PrivilegeService {
...
@@ -19,7 +19,7 @@ public class PrivilegeService {
@Autowired
@Autowired
private
PrivilegeRepository
privilRepo
;
private
PrivilegeRepository
privilRepo
;
public
Privilege
addPrivilege
(
Stri
ng
appId
,
String
name
,
PrivilType
privilType
)
{
public
Privilege
addPrivilege
(
lo
ng
appId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
if
(
privil
==
null
)
{
if
(
privil
==
null
)
{
privil
=
new
Privilege
();
privil
=
new
Privilege
();
...
@@ -31,16 +31,16 @@ public class PrivilegeService {
...
@@ -31,16 +31,16 @@ public class PrivilegeService {
return
privil
;
return
privil
;
}
}
public
boolean
hasPrivilege
(
Stri
ng
appId
,
String
name
,
PrivilType
privilType
)
{
public
boolean
hasPrivilege
(
lo
ng
appId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
return
(
privil
!=
null
)
?
true
:
false
;
return
(
privil
!=
null
)
?
true
:
false
;
}
}
public
List
<
Privilege
>
listPrivileges
(
Stri
ng
appId
)
{
public
List
<
Privilege
>
listPrivileges
(
lo
ng
appId
)
{
return
privilRepo
.
findByAppId
(
appId
);
return
privilRepo
.
findByAppId
(
appId
);
}
}
public
void
removePrivilege
(
Stri
ng
appId
,
String
name
,
PrivilType
privilType
)
{
public
void
removePrivilege
(
lo
ng
appId
,
String
name
,
PrivilType
privilType
)
{
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
Privilege
privil
=
privilRepo
.
findByAppIdAndNameAndPrivilType
(
appId
,
name
,
privilType
.
name
());
if
(
privil
==
null
)
{
if
(
privil
==
null
)
{
throw
new
NotFoundException
();
throw
new
NotFoundException
();
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/VersionService.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
portal
.
service
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.portal.RestUtils
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
public
class
VersionService
{
public
List
<
VersionDTO
>
findVersionsByApp
(
long
appId
,
String
env
){
return
RestUtils
.
exchangeInGET
(
"http://localhost:8090/version/app/"
+
appId
,
List
.
class
);
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/impl/ConfigServiceImpl.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
portal
.
service
.
impl
;
import
com.ctrip.apollo.core.Constants
;
import
com.ctrip.apollo.core.dto.*
;
import
com.ctrip.apollo.portal.RestUtils
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
com.ctrip.apollo.portal.service.ConfigService
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.google.common.collect.Maps
;
import
org.springframework.stereotype.Service
;
import
java.io.IOException
;
import
java.util.*
;
@Service
public
class
ConfigServiceImpl
implements
ConfigService
{
public
static
final
String
ADMIN_SERVICE_HOST
=
"http://localhost:8090"
;
private
ObjectMapper
objectMapper
=
new
ObjectMapper
();
@Override
public
AppConfigVO
loadReleaseConfig
(
long
appId
,
long
versionId
)
{
if
(
appId
<=
0
||
versionId
<=
0
)
{
return
null
;
}
long
releaseId
=
getReleaseIdFromVersionId
(
versionId
);
ReleaseSnapshotDTO
[]
releaseSnapShots
=
RestUtils
.
exchangeInGET
(
ADMIN_SERVICE_HOST
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
);
if
(
releaseSnapShots
==
null
||
releaseSnapShots
.
length
==
0
)
{
return
null
;
}
AppConfigVO
appConfigVO
=
AppConfigVO
.
newInstance
(
appId
,
versionId
);
for
(
ReleaseSnapshotDTO
snapShot
:
releaseSnapShots
)
{
//default cluster
if
(
Constants
.
DEFAULT_CLUSTER_NAME
.
equals
(
snapShot
.
getClusterName
()))
{
collectDefaultClusterConfigs
(
appId
,
snapShot
,
appConfigVO
);
}
else
{
//cluster special configs
collectSpecialClusterConfigs
(
appId
,
snapShot
,
appConfigVO
);
}
}
return
appConfigVO
;
}
private
long
getReleaseIdFromVersionId
(
long
versionId
)
{
VersionDTO
version
=
RestUtils
.
exchangeInGET
(
ADMIN_SERVICE_HOST
+
"/version/"
+
versionId
,
VersionDTO
.
class
);
if
(
version
==
null
)
{
return
-
1
;
}
return
version
.
getReleaseId
();
}
private
void
collectDefaultClusterConfigs
(
long
appId
,
ReleaseSnapshotDTO
snapShot
,
AppConfigVO
appConfigVO
)
{
Map
<
Long
,
List
<
ConfigItemDTO
>>
groupedConfigs
=
groupConfigsByApp
(
snapShot
.
getConfigurations
());
List
<
AppConfigVO
.
OverrideAppConfig
>
overrideAppConfigs
=
appConfigVO
.
getOverrideAppConfigs
();
for
(
Map
.
Entry
<
Long
,
List
<
ConfigItemDTO
>>
entry
:
groupedConfigs
.
entrySet
())
{
long
configAppId
=
entry
.
getKey
();
List
<
ConfigItemDTO
>
kvs
=
entry
.
getValue
();
if
(
configAppId
==
appId
)
{
appConfigVO
.
setDefaultClusterConfigs
(
kvs
);
}
else
{
AppConfigVO
.
OverrideAppConfig
overrideAppConfig
=
new
AppConfigVO
.
OverrideAppConfig
();
overrideAppConfig
.
setAppId
(
configAppId
);
overrideAppConfig
.
setConfigs
(
kvs
);
overrideAppConfigs
.
add
(
overrideAppConfig
);
}
}
}
/**
* appId -> List<KV>
*/
private
Map
<
Long
,
List
<
ConfigItemDTO
>>
groupConfigsByApp
(
String
configJson
)
{
if
(
configJson
==
null
||
""
.
equals
(
configJson
))
{
return
Maps
.
newHashMap
();
}
Map
<
Long
,
List
<
ConfigItemDTO
>>
appIdMapKVs
=
new
HashMap
<>();
String
key
;
Object
value
;
Map
<
String
,
String
>
kvMaps
=
null
;
try
{
kvMaps
=
objectMapper
.
readValue
(
configJson
,
Map
.
class
);
}
catch
(
IOException
e
)
{
//todo log
}
for
(
Map
.
Entry
<
String
,
String
>
entry
:
kvMaps
.
entrySet
())
{
key
=
entry
.
getKey
();
value
=
entry
.
getValue
();
Long
appId
=
getAppIdFromKey
(
key
);
List
<
ConfigItemDTO
>
kvs
=
appIdMapKVs
.
get
(
appId
);
if
(
kvs
==
null
)
{
kvs
=
new
LinkedList
<>();
appIdMapKVs
.
put
(
appId
,
kvs
);
}
kvs
.
add
(
new
ConfigItemDTO
(
key
,
value
.
toString
()));
}
return
appIdMapKVs
;
}
private
Long
getAppIdFromKey
(
String
key
)
{
return
Long
.
valueOf
(
key
.
substring
(
0
,
key
.
indexOf
(
"."
)));
}
private
void
collectSpecialClusterConfigs
(
long
appId
,
ReleaseSnapshotDTO
snapShot
,
AppConfigVO
appConfigVO
)
{
List
<
AppConfigVO
.
OverrideClusterConfig
>
overrideClusterConfigs
=
appConfigVO
.
getOverrideClusterConfigs
();
AppConfigVO
.
OverrideClusterConfig
overrideClusterConfig
=
new
AppConfigVO
.
OverrideClusterConfig
();
overrideClusterConfig
.
setClusterName
(
snapShot
.
getClusterName
());
//todo step1: cluster special config can't override other app config
overrideClusterConfig
.
setConfigs
(
groupConfigsByApp
(
snapShot
.
getConfigurations
()).
get
(
appId
));
overrideClusterConfigs
.
add
(
overrideClusterConfig
);
}
@Override
public
AppConfigVO
loadLatestConfig
(
long
appId
)
{
if
(
appId
<=
0
)
{
return
null
;
}
ClusterDTO
[]
clusters
=
RestUtils
.
exchangeInGET
(
ADMIN_SERVICE_HOST
+
"/cluster/app/"
+
appId
,
ClusterDTO
[].
class
);
if
(
clusters
==
null
||
clusters
.
length
==
0
)
{
return
null
;
}
StringBuilder
sb
=
new
StringBuilder
();
for
(
ClusterDTO
cluster
:
clusters
)
{
sb
.
append
(
cluster
.
getId
()).
append
(
","
);
}
ConfigItemDTO
[]
configItems
=
RestUtils
.
exchangeInGET
(
ADMIN_SERVICE_HOST
+
"/configs/latest?clusterIds="
+
sb
.
substring
(
0
,
sb
.
length
()
-
1
),
ConfigItemDTO
[].
class
);
return
buildAPPConfigVO
(
appId
,
Arrays
.
asList
(
configItems
));
}
private
AppConfigVO
buildAPPConfigVO
(
long
appId
,
List
<
ConfigItemDTO
>
configItems
)
{
if
(
configItems
==
null
||
configItems
.
size
()
==
0
)
{
return
null
;
}
Map
<
String
,
List
<
ConfigItemDTO
>>
groupedClusterConfigs
=
groupConfigByCluster
(
configItems
);
AppConfigVO
appConfigVO
=
AppConfigVO
.
newInstance
(
appId
,
Constants
.
LASTEST_VERSION_ID
);
groupConfigByAppAndEnrichDTO
(
groupedClusterConfigs
,
appConfigVO
);
return
appConfigVO
;
}
private
Map
<
String
,
List
<
ConfigItemDTO
>>
groupConfigByCluster
(
List
<
ConfigItemDTO
>
configItems
)
{
Map
<
String
,
List
<
ConfigItemDTO
>>
groupedClusterConfigs
=
new
HashMap
<>();
String
clusterName
;
for
(
ConfigItemDTO
configItem
:
configItems
)
{
clusterName
=
configItem
.
getClusterName
();
List
<
ConfigItemDTO
>
clusterConfigs
=
groupedClusterConfigs
.
get
(
clusterName
);
if
(
clusterConfigs
==
null
)
{
clusterConfigs
=
new
LinkedList
<>();
groupedClusterConfigs
.
put
(
clusterName
,
clusterConfigs
);
}
clusterConfigs
.
add
(
configItem
);
}
return
groupedClusterConfigs
;
}
private
void
groupConfigByAppAndEnrichDTO
(
Map
<
String
,
List
<
ConfigItemDTO
>>
groupedClusterConfigs
,
AppConfigVO
appConfigVO
)
{
long
appId
=
appConfigVO
.
getAppId
();
List
<
ConfigItemDTO
>
defaultClusterConfigs
=
appConfigVO
.
getDefaultClusterConfigs
();
List
<
AppConfigVO
.
OverrideAppConfig
>
overrideAppConfigs
=
appConfigVO
.
getOverrideAppConfigs
();
List
<
AppConfigVO
.
OverrideClusterConfig
>
overrideClusterConfigs
=
appConfigVO
.
getOverrideClusterConfigs
();
String
clusterName
;
List
<
ConfigItemDTO
>
clusterConfigs
;
for
(
Map
.
Entry
<
String
,
List
<
ConfigItemDTO
>>
entry
:
groupedClusterConfigs
.
entrySet
())
{
clusterName
=
entry
.
getKey
();
clusterConfigs
=
entry
.
getValue
();
if
(
Constants
.
DEFAULT_CLUSTER_NAME
.
equals
(
clusterName
))
{
//default cluster configs
collectDefaultClusterConfigs
(
appId
,
clusterConfigs
,
defaultClusterConfigs
,
overrideAppConfigs
);
}
else
{
//override cluster configs
collectSpecialClusterConfigs
(
clusterName
,
clusterConfigs
,
overrideClusterConfigs
);
}
}
}
private
void
collectDefaultClusterConfigs
(
long
appId
,
List
<
ConfigItemDTO
>
clusterConfigs
,
List
<
ConfigItemDTO
>
defaultClusterConfigs
,
List
<
AppConfigVO
.
OverrideAppConfig
>
overrideAppConfigs
)
{
Map
<
Long
,
AppConfigVO
.
OverrideAppConfig
>
appIdMapOverrideAppConfig
=
null
;
for
(
ConfigItemDTO
config
:
clusterConfigs
)
{
long
targetAppId
=
config
.
getAppId
();
if
(
appId
==
targetAppId
)
{
//app self's configs
defaultClusterConfigs
.
add
(
config
);
}
else
{
//override other app configs
if
(
appIdMapOverrideAppConfig
==
null
)
{
appIdMapOverrideAppConfig
=
new
HashMap
<>();
}
AppConfigVO
.
OverrideAppConfig
overrideAppConfig
=
appIdMapOverrideAppConfig
.
get
(
targetAppId
);
if
(
overrideAppConfig
==
null
)
{
overrideAppConfig
=
new
AppConfigVO
.
OverrideAppConfig
();
appIdMapOverrideAppConfig
.
put
(
targetAppId
,
overrideAppConfig
);
overrideAppConfigs
.
add
(
overrideAppConfig
);
}
overrideAppConfig
.
setAppId
(
targetAppId
);
overrideAppConfig
.
addConfig
(
config
);
}
}
}
private
void
collectSpecialClusterConfigs
(
String
clusterName
,
List
<
ConfigItemDTO
>
clusterConfigs
,
List
<
AppConfigVO
.
OverrideClusterConfig
>
overrideClusterConfigs
)
{
AppConfigVO
.
OverrideClusterConfig
overrideClusterConfig
=
new
AppConfigVO
.
OverrideClusterConfig
();
overrideClusterConfig
.
setClusterName
(
clusterName
);
overrideClusterConfig
.
setConfigs
(
clusterConfigs
);
overrideClusterConfigs
.
add
(
overrideClusterConfig
);
}
}
apollo-portal/src/main/resources/application.yml
View file @
71ffb8c6
...
@@ -6,6 +6,9 @@ spring:
...
@@ -6,6 +6,9 @@ spring:
name
:
apollo-portal
name
:
apollo-portal
datasource
:
datasource
:
url
:
jdbc:h2:mem:~/fxapolloportaldb
url
:
jdbc:h2:mem:~/fxapolloportaldb
jpa
:
hibernate
:
naming_strategy
:
org.hibernate.cfg.EJB3NamingStrategy
logging
:
logging
:
level
:
level
:
...
...
apollo-portal/src/main/resources/import.sql
0 → 100644
View file @
71ffb8c6
INSERT
INTO
App
(
appId
,
name
,
owner
,
ownerPhone
,
ownerMail
,
createTimestamp
,
lastUpdatedTimestamp
)
VALUES
(
6666
,
'apollo'
,
'lepdou'
,
'18722435754'
,
'zhanglea@ctrip.com'
,
NOW
(),
NOW
());
apollo-portal/src/main/resources/static/scripts/controller/app/AppConfigController.js
View file @
71ffb8c6
application_module
.
controller
(
"
AppConfigController
"
,
[
'
$scope
'
,
'
$rootScope
'
,
'
$state
'
,
'
$location
'
,
'
toastr
'
,
'
AppService
'
,
'
ConfigService
'
,
'
VersionService
'
,
function
(
$scope
,
$rootScope
,
$state
,
$location
,
toastr
,
AppService
,
ConfigService
,
VersionService
)
{
application_module
.
controller
(
"
AppConfigController
"
,
[
"
$scope
"
,
'
$state
'
,
'
$location
'
,
'
AppService
'
,
var
configLocation
=
{
function
(
$scope
,
$state
,
$location
,
AppService
)
{
appId
:
$rootScope
.
appId
,
env
:
'
uat
'
,
versionId
:
-
1
};
//model定义
$rootScope
.
breadcrumb
.
nav
=
'
配置
'
;
$scope
.
env
=
{
$rootScope
.
breadcrumb
.
env
=
configLocation
.
env
;
fat
:
false
,
uat
:
true
,
product
:
false
}
;
$scope
.
configLocation
=
configLocation
;
//mock data
/**env*/
$scope
.
config
=
{
$scope
.
envs
=
[
'
dev
'
,
'
fws
'
,
'
fat
'
,
'
uat
'
,
'
lpt
'
,
'
prod
'
,
'
tools
'
];
baseConfigs
:
[
{
key
:
'
pageSize
'
,
value
:
10
,
lastUpdateTime
:
'
2016-01-14
'
},
{
key
:
'
pageCount
'
,
value
:
20
,
lastUpdateTime
:
'
2016-01-14
'
}
],
overrideConfigs
:
[
{
project
:
'
cat
'
,
configs
:
[
{
key
:
'
pageSize
'
,
value
:
10
,
lastUpdateTime
:
'
2016-01-14
'
},
{
key
:
'
pageCount
'
,
value
:
20
,
lastUpdateTime
:
'
2016-01-14
'
}
]
},
{
project
:
'
hermas
'
,
configs
:
[
{
key
:
'
pageSize
'
,
value
:
20
,
lastUpdateTime
:
'
2016-01-14
'
},
{
key
:
'
pageCount
'
,
value
:
30
,
lastUpdateTime
:
'
2016-01-14
'
}
]
}
]
};
$scope
.
switchEnv
=
function
(
env
)
{
$scope
.
switchEnv
=
function
(
selectedEnv
)
{
clearEnvNav
();
configLocation
.
env
=
selectedEnv
;
if
(
'
fat
'
==
env
)
{
$rootScope
.
breadcrumb
.
env
=
configLocation
.
env
;
switchToFat
();
refreshConfigs
();
}
else
if
(
'
uat
'
==
env
)
{
switchToUat
();
}
else
if
(
'
product
'
==
env
)
{
switchToProduct
();
}
};
};
function
switchToFat
()
{
/**version*/
$scope
.
env
.
fat
=
true
;
$scope
.
releaseVersions
=
[]
;
}
$scope
.
currentVersionIsRelease
=
false
;
function
switchToUat
()
{
VersionService
.
load
(
configLocation
.
appId
,
configLocation
.
env
).
then
(
function
(
result
)
{
$scope
.
env
.
uat
=
true
;
$scope
.
releaseVersions
=
result
;
}
},
function
(
result
)
{
toastr
.
error
(
"
获取版本失败
"
,
result
);
});
function
switchToProduct
()
{
$scope
.
switchVersion
=
function
(
versionId
)
{
$scope
.
env
.
product
=
true
;
configLocation
.
versionId
=
versionId
;
}
$scope
.
currentVersionIsRelease
=
configLocation
.
versionId
>
0
;
refreshConfigs
();
};
function
clearEnvNav
()
{
/**config*/
$scope
.
env
=
{
refreshConfigs
();
fat
:
false
,
//refresh app config infomations
uat
:
false
,
function
refreshConfigs
()
{
product
:
false
ConfigService
.
load
(
configLocation
.
appId
,
configLocation
.
env
,
configLocation
.
versionId
).
then
(
function
(
result
)
{
$scope
.
config
=
result
;
};
$scope
.
showClusterConfigs
=
false
;
}
if
(
result
.
overrideClusterConfigs
&&
result
.
overrideClusterConfigs
[
0
])
{
$scope
.
showClusterConfigs
=
true
;
//default selected
$scope
.
config
.
selectedCluster
=
result
.
overrideClusterConfigs
[
0
];
$scope
.
config
.
selectedClusterKVs
=
result
.
overrideClusterConfigs
[
0
].
configs
;
//build map clusterName -> configs for switch cluster
$scope
.
config
.
overrideClusters
=
{};
$
.
each
(
result
.
overrideClusterConfigs
,
function
(
index
,
value
)
{
$scope
.
config
.
overrideClusters
[
value
.
clusterName
]
=
value
.
configs
;
});
}
},
function
(
result
)
{
toastr
.
error
(
"
加载配置出错
"
,
result
);
});
}
//switch cluster
$scope
.
selectCluster
=
function
()
{
$scope
.
config
.
selectedClusterKVs
=
$scope
.
config
.
overrideClusters
[
$scope
.
config
.
selectedCluster
.
clusterName
];
};
}]);
}]);
apollo-portal/src/main/resources/static/scripts/controller/app/AppInfoController.js
View file @
71ffb8c6
application_module
.
controller
(
"
AppInfoController
"
,
[
"
$scope
"
,
'
$state
'
,
'
$location
'
,
'
toastr
'
,
'
AppService
'
,
application_module
.
controller
(
"
AppInfoController
"
,
[
"
$scope
"
,
'
$rootScope
'
,
'
$state
'
,
'
$location
'
,
'
toastr
'
,
'
AppService
'
,
function
(
$scope
,
$state
,
$location
,
toastr
,
AppService
)
{
function
(
$scope
,
$rootScope
,
$state
,
$location
,
toastr
,
AppService
)
{
$scope
.
appId
=
$location
.
$$url
.
split
(
"
=
"
)[
1
];
$rootScope
.
breadcrumb
.
nav
=
'
应用信息
'
;
$rootScope
.
breadcrumb
.
env
=
''
;
AppService
.
load
(
$scope
.
appId
).
then
(
function
(
result
)
{
AppService
.
load
(
$scope
.
appId
).
then
(
function
(
result
)
{
$scope
.
app
=
result
;
$scope
.
app
=
result
;
},
function
(
result
)
{
},
function
(
result
)
{
toastr
.
error
(
"
加载出错
"
);
toastr
.
error
(
"
加载出错
"
);
});
});
...
...
apollo-portal/src/main/resources/static/scripts/controller/app/AppPageController.js
0 → 100644
View file @
71ffb8c6
//page context ctl
application_module
.
controller
(
"
AppPageController
"
,
[
'
$rootScope
'
,
'
$location
'
,
function
(
$rootScope
,
$location
)
{
$rootScope
.
appId
=
$location
.
$$url
.
split
(
"
=
"
)[
1
];
if
(
!
$rootScope
.
appId
){
$rootScope
.
appId
=
6666
;
}
$rootScope
.
breadcrumb
=
{
project
:
'
6666-apollo
'
,
nav
:
'
配置
'
,
env
:
'
uat
'
}
}]);
apollo-portal/src/main/resources/static/scripts/services/ConfigService.js
0 → 100644
View file @
71ffb8c6
appService
.
service
(
"
ConfigService
"
,
[
'
$resource
'
,
'
$q
'
,
function
(
$resource
,
$q
)
{
var
config_source
=
$resource
(
"
/configs/:appId/:env/:versionId
"
,
{},
{
load_config
:
{
method
:
'
GET
'
,
isArray
:
false
}
});
return
{
load
:
function
(
appId
,
env
,
versionId
)
{
var
d
=
$q
.
defer
();
config_source
.
load_config
({
appId
:
appId
,
env
:
env
,
versionId
:
versionId
},
function
(
result
)
{
d
.
resolve
(
result
);
},
function
(
result
)
{
de
.
reject
(
result
);
});
return
d
.
promise
;
}
}
}]);
apollo-portal/src/main/resources/static/scripts/services/VersionService.js
0 → 100644
View file @
71ffb8c6
appService
.
service
(
"
VersionService
"
,
[
'
$resource
'
,
'
$q
'
,
function
(
$resource
,
$q
)
{
var
config_source
=
$resource
(
"
/version/:appId/:env
"
,
{},
{
load_config
:
{
method
:
'
GET
'
,
isArray
:
true
}
});
return
{
load
:
function
(
appId
,
env
)
{
var
d
=
$q
.
defer
();
config_source
.
load_config
({
appId
:
appId
,
env
:
env
},
function
(
result
)
{
d
.
resolve
(
result
);
},
function
(
result
)
{
d
.
reject
(
result
);
});
return
d
.
promise
;
}
}
}]);
apollo-portal/src/main/resources/static/styles/common-style.css
View file @
71ffb8c6
...
@@ -28,7 +28,7 @@ body {
...
@@ -28,7 +28,7 @@ body {
/*sec-panel*/
/*sec-panel*/
.sec-panel
{
.sec-panel
{
padding-left
:
5%
;
/*padding-left: 5%;*/
}
}
.sec-panel
.panel-heading
{
.sec-panel
.panel-heading
{
...
...
apollo-portal/src/main/resources/static/views/app/config.html
View file @
71ffb8c6
...
@@ -2,12 +2,9 @@
...
@@ -2,12 +2,9 @@
<div
class=
"tab-pane active"
id=
"config-info"
style=
"min-height: 500px;"
>
<div
class=
"tab-pane active"
id=
"config-info"
style=
"min-height: 500px;"
>
<!--环境nav-->
<!--环境nav-->
<ul
class=
"nav nav-pills nav-justified"
>
<ul
class=
"nav nav-pills nav-justified"
>
<li
role=
"presentation"
ng-class=
"{active:env.fat}"
ng-click=
"switchEnv('fat')"
><a
href=
"#"
>
FAT
</a>
<li
ng-repeat=
"env in envs"
ng-class=
"{active:configLocation.env == env}"
>
<a
href=
"#"
ng-click=
"switchEnv(env)"
>
{{env}}
</a>
</li>
</li>
<li
role=
"presentation"
ng-class=
"{active:env.uat}"
ng-click=
"switchEnv('uat')"
><a
href=
"#"
>
UAT
</a>
</li>
<li
role=
"presentation"
ng-class=
"{active:env.product}"
ng-click=
"switchEnv('product')"
><a
href=
"#"
>
PRODUCT
</a></li>
</ul>
</ul>
<!--具体配置信息-->
<!--具体配置信息-->
...
@@ -16,11 +13,14 @@
...
@@ -16,11 +13,14 @@
<div
class=
"col-md-2"
>
<div
class=
"col-md-2"
>
<ul
class=
"nav nav-pills nav-stacked"
>
<ul
class=
"nav nav-pills nav-stacked"
>
<li
class=
"dropdown-header"
>
未发布
</li>
<li
class=
"dropdown-header"
>
未发布
</li>
<li
role=
"presentation"
class=
"active"
><a
href=
"#"
>
latest
</a></li>
<li
role=
"presentation"
ng-class=
"{active:configLocation.versionId == -1}"
ng-click=
"switchVersion(-1)"
><a
href=
"#"
>
latest
</a></li>
<li
role=
"separator"
class=
"divider"
></li>
<li
role=
"separator"
class=
"divider"
></li>
<li
class=
"dropdown-header"
>
已发布
</li>
<li
class=
"dropdown-header"
>
已发布
</li>
<li
role=
"presentation"
><a
href=
"#"
>
v1.0
</a></li>
<li
ng-repeat=
"version in releaseVersions"
<li
role=
"presentation"
><a
href=
"#"
>
v2.0
</a></li>
ng-class=
"{active:configLocation.versionId == version.id}"
>
<a
href=
"#"
ng-click=
"switchVersion(version.id)"
>
{{version.name}}
</a>
</li>
</ul>
</ul>
</div>
</div>
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
<header
class=
"panel-heading"
>
<header
class=
"panel-heading"
>
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-md-6"
>
项目的基本配置
</div>
<div
class=
"col-md-6"
>
项目的基本配置
</div>
<div
class=
"col-md-6"
>
<div
class=
"col-md-6"
ng-show=
"!currentVersionIsRelease"
>
<p
class=
"text-right"
>
<p
class=
"text-right"
>
<a
href=
"#"
data-toggle=
"tooltip"
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
title=
"下载配置"
>
data-placement=
"top"
title=
"下载配置"
>
...
@@ -58,16 +58,22 @@
...
@@ -58,16 +58,22 @@
<th>
<th>
value
value
</th>
</th>
<th>
<th
ng-show=
"!currentVersionIsRelease"
>
最后更新时间
备注
</th>
</th>
<th>
<th
ng-show=
"!currentVersionIsRelease"
>
最后修改人
</th>
<th
ng-show=
"!currentVersionIsRelease"
>
最后修改时间
</th>
<th
ng-show=
"!currentVersionIsRelease"
>
操作
操作
</th>
</th>
</tr>
</tr>
</thead>
</thead>
<tbody
ng-repeat=
"config in config.
base
Configs"
>
<tbody
ng-repeat=
"config in config.
defaultCluster
Configs"
>
<tr>
<tr>
<td>
<td>
...
@@ -76,11 +82,17 @@
...
@@ -76,11 +82,17 @@
<td>
<td>
{{config.value}}
{{config.value}}
</td>
</td>
<td>
<td
ng-show=
"!currentVersionIsRelease"
>
{{config.lastUpdateTime}}
{{config.comment}}
</td>
<td
ng-show=
"!currentVersionIsRelease"
>
{{config.dataChangeLastModifiedBy}}
</td>
<td
ng-show=
"!currentVersionIsRelease"
>
{{config.dataChangeLastModifiedTime | date: 'yyyy-MM-dd HH:mm:ss'}}
</td>
</td>
<td>
<td
ng-show=
"!currentVersionIsRelease"
>
<a
href=
"#"
data-toggle=
"tooltip"
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
title=
"修改"
>
data-placement=
"top"
title=
"修改"
>
<span
class=
"glyphicon glyphicon-edit"
<span
class=
"glyphicon glyphicon-edit"
...
@@ -114,109 +126,126 @@
...
@@ -114,109 +126,126 @@
</li>
</li>
</ul>
</ul>
</nav>
</nav>
<div
ng-repeat=
"overrideConfig in config.overrideConfigs"
>
</div>
<div
class=
"panel sec-panel"
>
</div>
<header
class=
"panel-heading"
>
<div
class=
"row"
>
<!--重写框架的配置-->
<div
class=
"col-md-6"
>
重写
<a
<div
ng-repeat=
"overrideAppConfig in config.overrideAppConfigs"
>
href=
"#"
>
{{overrideConfig.project}}
</a>
的配置
<div
class=
"panel sec-panel"
>
</div>
<header
class=
"panel-heading"
>
<div
class=
"col-md-6"
>
<div
class=
"row"
>
<p
class=
"text-right"
>
<div
class=
"col-md-6"
>
重写
<a
<a
href=
"#"
data-toggle=
"tooltip"
href=
"#"
>
{{overrideAppConfig.appId}}
</a>
的配置
data-placement=
"top"
</div>
title=
"下载配置"
>
<div
class=
"col-md-6"
ng-show=
"!currentVersionIsRelease"
>
<p
class=
"text-right"
>
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
title=
"下载配置"
>
<span
class=
"glyphicon glyphicon-save"
<span
class=
"glyphicon glyphicon-save"
aria-hidden=
"true"
></span>
aria-hidden=
"true"
></span>
</a>
</a>
<a
href=
"#"
data-toggle=
"tooltip"
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
data-placement=
"top"
title=
"添加配置"
>
title=
"添加配置"
>
<span
class=
"glyphicon glyphicon-plus"
<span
class=
"glyphicon glyphicon-plus"
aria-hidden=
"true"
></span>
aria-hidden=
"true"
></span>
</a>
</a>
</p>
</p>
</div>
</div>
</div>
</div>
</header>
</header>
<!--配置列表-->
<!--配置列表-->
<div
class=
"panel-body"
>
<div
class=
"panel-body"
>
<table
class=
"table table-bordered text-center"
>
<table
class=
"table table-bordered text-center"
>
<thead>
<thead>
<tr>
<tr>
<th>
<th>
Key
Key
</th>
</th>
<th>
<th>
value
value
</th>
</th>
<th>
<th
ng-show=
"!currentVersionIsRelease"
>
最后更新时间
备注
</th>
</th>
<th>
<th
ng-show=
"!currentVersionIsRelease"
>
操作
最后修改人
</th>
</th>
<th
ng-show=
"!currentVersionIsRelease"
>
最后修改时间
</th>
<th
ng-show=
"!currentVersionIsRelease"
>
操作
</th>
</tr>
</tr>
</thead>
</thead>
<tbody
ng-repeat=
"config in overrideConfig.configs"
>
<tbody
ng-repeat=
"config in overrideAppConfig.configs"
>
<tr>
<tr>
<td>
<td>
{{config.key}}
{{config.key}}
</td>
</td>
<td>
<td>
{{config.value}}
{{config.value}}
</td>
</td>
<td>
<td
ng-show=
"!currentVersionIsRelease"
>
{{config.lastUpdateTime}}
{{config.comment}}
</td>
</td>
<td
ng-show=
"!currentVersionIsRelease"
>
{{config.dataChangeLastModifiedBy}}
</td>
<td
ng-show=
"!currentVersionIsRelease"
>
{{config.dataChangeLastModifiedTime | date: 'yyyy-MM-dd HH:mm:ss'}}
</td>
<td
>
<td
ng-show=
"!currentVersionIsRelease"
>
<a
href=
"#"
data-toggle=
"tooltip"
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
data-placement=
"top"
title=
"修改"
>
title=
"修改"
>
<span
class=
"glyphicon glyphicon-edit"
<span
class=
"glyphicon glyphicon-edit"
aria-hidden=
"true"
></span>
aria-hidden=
"true"
></span>
</a>
</a>
<a
href=
"#"
data-toggle=
"tooltip"
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
data-placement=
"top"
title=
"删除"
>
title=
"删除"
>
<span
class=
"glyphicon glyphicon-remove"
<span
class=
"glyphicon glyphicon-remove"
aria-hidden=
"true"
></span>
aria-hidden=
"true"
></span>
</a>
</a>
</td>
</td>
</tr>
</tbody>
</table>
<br>
</div>
</div>
</tr>
</tbody>
</table>
<br>
</div>
</div>
</div>
</div>
</div>
</div>
<div
class=
"panel"
>
<!--集群特有的配置-->
<div
class=
"panel"
ng-show=
"showClusterConfigs"
>
<header
class=
"panel-heading"
>
<header
class=
"panel-heading"
>
<div
class=
"row"
>
<div
class=
"row"
>
<div
class=
"col-md-
3
"
>
<div
class=
"col-md-
1 text-right
"
>
集群
特有的配置
集群
</div>
</div>
<div
class=
"col-md-3"
>
<div
class=
"col-md-3"
>
<select
class=
"form-control"
>
<select
class=
"form-control"
<option>
欧阳
</option>
ng-model=
"config.selectedCluster"
<option>
2
</option>
ng-change=
"selectCluster()"
<option>
3
</option>
ng-options=
"item as item.clusterName for item in config.overrideClusterConfigs track by item.clusterName"
>
<option>
4
</option>
<option>
5
</option>
</select>
</select>
</div>
<div
class=
"col-md-2 text-left"
>
</div>
</div>
<div
class=
"col-md-6"
>
<div
class=
"col-md-6"
ng-show=
"!currentVersionIsRelease"
>
<p
class=
"text-right"
>
<p
class=
"text-right"
>
<a
href=
"#"
data-toggle=
"tooltip"
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
title=
"下载配置"
>
data-placement=
"top"
title=
"下载配置"
>
...
@@ -245,119 +274,55 @@
...
@@ -245,119 +274,55 @@
<th>
<th>
value
value
</th>
</th>
<th>
<th
ng-show=
"!currentVersionIsRelease"
>
最后更新时间
备注
</th>
</th>
<th>
<th
ng-show=
"!currentVersionIsRelease"
>
最后修改人
</th>
<th
ng-show=
"!currentVersionIsRelease"
>
最后修改时间
</th>
<th
ng-show=
"!currentVersionIsRelease"
>
操作
操作
</th>
</th>
</tr>
</tr>
</thead>
</thead>
<tbody>
<tbody
ng-repeat=
"config in config.selectedClusterKVs"
>
<tr>
<td>
pagesize
</td>
<td>
10
</td>
<td>
2016-01-14
</td>
<td>
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
title=
"修改"
>
<span
class=
"glyphicon glyphicon-edit"
aria-hidden=
"true"
></span>
</a>
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
title=
"删除"
>
<span
class=
"glyphicon glyphicon-remove"
aria-hidden=
"true"
></span>
</a>
</td>
</tr>
<tr>
<tr>
<td>
<td>
pagesize
{{config.key}}
</td>
<td>
10
</td>
<td>
2016-01-14
</td>
<td>
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
title=
"修改"
>
<span
class=
"glyphicon glyphicon-edit"
aria-hidden=
"true"
></span>
</a>
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
title=
"删除"
>
<span
class=
"glyphicon glyphicon-remove"
aria-hidden=
"true"
></span>
</a>
</td>
</tr>
<tr>
<td>
pagesize
</td>
<td>
10
</td>
<td>
2016-01-14
</td>
</td>
<td>
<td>
<a
href=
"#"
data-toggle=
"tooltip"
{{config.value}}
data-placement=
"top"
title=
"修改"
>
<span
class=
"glyphicon glyphicon-edit"
aria-hidden=
"true"
></span>
</a>
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
title=
"删除"
>
<span
class=
"glyphicon glyphicon-remove"
aria-hidden=
"true"
></span>
</a>
</td>
</td>
</tr>
<td
ng-show=
"!currentVersionIsRelease"
>
<tr>
{{config.comment}}
<td>
pagesize
</td>
</td>
<td>
<td
ng-show=
"!currentVersionIsRelease"
>
10
{{config.dataChangeLastModifiedBy}}
</td>
</td>
<td>
<td
ng-show=
"!currentVersionIsRelease"
>
2016-01-14
{{config.dataChangeLastModifiedTime | date: 'yyyy-MM-dd HH:mm:ss'}}
</td>
</td>
<td>
<td
ng-show=
"!currentVersionIsRelease"
>
<a
href=
"#"
data-toggle=
"tooltip"
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
data-placement=
"top"
title=
"修改"
>
title=
"修改"
>
<span
class=
"glyphicon glyphicon-edit"
<span
class=
"glyphicon glyphicon-edit"
aria-hidden=
"true"
></span>
aria-hidden=
"true"
></span>
</a>
</a>
<a
href=
"#"
data-toggle=
"tooltip"
<a
href=
"#"
data-toggle=
"tooltip"
data-placement=
"top"
data-placement=
"top"
title=
"删除"
>
title=
"删除"
>
<span
class=
"glyphicon glyphicon-remove"
<span
class=
"glyphicon glyphicon-remove"
aria-hidden=
"true"
></span>
aria-hidden=
"true"
></span>
</a>
</a>
</td>
</td>
</tr>
</tr>
</tbody>
</tbody>
</table>
</table>
<br>
<br>
...
...
apollo-portal/src/main/resources/static/views/app/index.html
View file @
71ffb8c6
...
@@ -15,9 +15,11 @@
...
@@ -15,9 +15,11 @@
<div
ng-include=
"'../common/nav.html'"
></div>
<div
ng-include=
"'../common/nav.html'"
></div>
<div
class=
"container"
>
<div
class=
"container"
>
<div
class=
"container-fluid"
>
<div
class=
"container-fluid"
>
<div
class=
"app"
>
<div
class=
"app"
ng-controller=
"AppPageController"
>
<ol
class=
"breadcrumb"
>
<ol
class=
"breadcrumb"
>
<li>
10024-hotel.service
</li>
<li
>
{{breadcrumb.project}}
</li>
<li>
{{breadcrumb.nav}}
</li>
<li
ng-show=
"breadcrumb.env"
>
{{breadcrumb.env}}
</li>
<!--<li>1.0</li>-->
<!--<li>1.0</li>-->
<!--<li>default</li>-->
<!--<li>default</li>-->
</ol>
</ol>
...
@@ -57,12 +59,12 @@
...
@@ -57,12 +59,12 @@
<!--biz script-->
<!--biz script-->
<script
type=
"application/javascript"
src=
"../../scripts/app.js"
></script>
<script
type=
"application/javascript"
src=
"../../scripts/app.js"
></script>
<script
type=
"application/javascript"
<script
type=
"application/javascript"
src=
"../../scripts/services/AppService.js"
></script>
src=
"../../scripts/services/App
Service.js"
></script>
<script
type=
"application/javascript"
src=
"../../scripts/services/Config
Service.js"
></script>
<script
type=
"application/javascript"
<script
type=
"application/javascript"
src=
"../../scripts/services/VersionService.js"
></script>
src=
"../../scripts/controller/app/AppConfigController.js"
></script>
<script
type=
"application/javascript"
src=
"../../scripts/controller/app/AppConfigController.js"
></script>
<script
type=
"application/javascript"
<script
type=
"application/javascript"
src=
"../../scripts/controller/app/AppInfoController.js"
></script>
src=
"../../scripts/controller/app/AppInfo
Controller.js"
></script>
<script
type=
"application/javascript"
src=
"../../scripts/controller/app/AppPage
Controller.js"
></script>
</body>
</body>
</html>
</html>
apollo-portal/src/main/resources/static/views/app/info.html
View file @
71ffb8c6
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
<div
class=
"panel"
>
<div
class=
"panel"
>
<div
class=
"panel-body"
>
<div
class=
"panel-body"
>
<form
class=
"form-horizontal"
ng-controller=
"AppInfoController"
>
<form
class=
"form-horizontal"
>
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<label
class=
"col-sm-2 control-label"
>
应用ID:
</label>
<label
class=
"col-sm-2 control-label"
>
应用ID:
</label>
<label
class=
"col-sm-3 control-label text-left"
>
<label
class=
"col-sm-3 control-label text-left"
>
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/AllTests.java
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
portal
;
package
com
.
ctrip
.
apollo
.
portal
;
import
com.ctrip.apollo.portal.service.ConfigServiceTest
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite
;
import
org.junit.runners.Suite.SuiteClasses
;
import
org.junit.runners.Suite.SuiteClasses
;
...
@@ -9,8 +10,7 @@ import com.ctrip.apollo.portal.repository.AppRepositoryTest;
...
@@ -9,8 +10,7 @@ import com.ctrip.apollo.portal.repository.AppRepositoryTest;
import
com.ctrip.apollo.portal.service.PrivilegeServiceTest
;
import
com.ctrip.apollo.portal.service.PrivilegeServiceTest
;
@RunWith
(
Suite
.
class
)
@RunWith
(
Suite
.
class
)
@SuiteClasses
({
AppControllerTest
.
class
,
AppRepositoryTest
.
class
,
PrivilegeServiceTest
.
class
,
@SuiteClasses
({
AppControllerTest
.
class
,
AppRepositoryTest
.
class
,
PrivilegeServiceTest
.
class
,
ConfigServiceTest
.
class
})
})
public
class
AllTests
{
public
class
AllTests
{
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/controller/AppControllerTest.java
View file @
71ffb8c6
...
@@ -32,7 +32,7 @@ public class AppControllerTest extends AbstractPortalTest {
...
@@ -32,7 +32,7 @@ public class AppControllerTest extends AbstractPortalTest {
@Test
@Test
public
void
testCreate
()
throws
URISyntaxException
{
public
void
testCreate
()
throws
URISyntaxException
{
App
newApp
=
new
App
();
App
newApp
=
new
App
();
newApp
.
setAppId
(
S
tring
.
valueOf
(
System
.
currentTimeMillis
()
));
newApp
.
setAppId
(
S
ystem
.
currentTimeMillis
(
));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
...
@@ -43,7 +43,7 @@ public class AppControllerTest extends AbstractPortalTest {
...
@@ -43,7 +43,7 @@ public class AppControllerTest extends AbstractPortalTest {
Assert
.
assertNull
(
newApp
.
getCreateTimestamp
());
Assert
.
assertNull
(
newApp
.
getCreateTimestamp
());
Assert
.
assertNotNull
(
createdApp
.
getCreateTimestamp
());
Assert
.
assertNotNull
(
createdApp
.
getCreateTimestamp
());
App
foundApp
=
appRepository
.
find
One
(
newApp
.
getAppId
());
App
foundApp
=
appRepository
.
find
ByAppId
(
newApp
.
getAppId
());
Assert
.
assertEquals
(
newApp
.
getAppId
(),
foundApp
.
getAppId
());
Assert
.
assertEquals
(
newApp
.
getAppId
(),
foundApp
.
getAppId
());
}
}
...
@@ -51,7 +51,7 @@ public class AppControllerTest extends AbstractPortalTest {
...
@@ -51,7 +51,7 @@ public class AppControllerTest extends AbstractPortalTest {
@Test
@Test
public
void
testList
()
throws
URISyntaxException
{
public
void
testList
()
throws
URISyntaxException
{
App
newApp
=
new
App
();
App
newApp
=
new
App
();
newApp
.
setAppId
(
S
tring
.
valueOf
(
System
.
currentTimeMillis
()
));
newApp
.
setAppId
(
S
ystem
.
currentTimeMillis
(
));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appRepository
.
save
(
newApp
);
appRepository
.
save
(
newApp
);
...
@@ -66,7 +66,7 @@ public class AppControllerTest extends AbstractPortalTest {
...
@@ -66,7 +66,7 @@ public class AppControllerTest extends AbstractPortalTest {
@Test
@Test
public
void
testListOutOfRange
()
throws
URISyntaxException
{
public
void
testListOutOfRange
()
throws
URISyntaxException
{
App
newApp
=
new
App
();
App
newApp
=
new
App
();
newApp
.
setAppId
(
S
tring
.
valueOf
(
System
.
currentTimeMillis
()
));
newApp
.
setAppId
(
S
ystem
.
currentTimeMillis
(
));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appRepository
.
save
(
newApp
);
appRepository
.
save
(
newApp
);
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/repository/AppRepositoryTest.java
View file @
71ffb8c6
...
@@ -18,7 +18,7 @@ public class AppRepositoryTest extends AbstractPortalTest{
...
@@ -18,7 +18,7 @@ public class AppRepositoryTest extends AbstractPortalTest{
Assert
.
assertEquals
(
0
,
repository
.
count
());
Assert
.
assertEquals
(
0
,
repository
.
count
());
App
ramdomApp
=
new
App
();
App
ramdomApp
=
new
App
();
ramdomApp
.
setAppId
(
S
tring
.
valueOf
(
System
.
currentTimeMillis
()
));
ramdomApp
.
setAppId
(
S
ystem
.
currentTimeMillis
(
));
ramdomApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
ramdomApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
ramdomApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
ramdomApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
repository
.
save
(
ramdomApp
);
repository
.
save
(
ramdomApp
);
...
...
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/ConfigServiceTest.java
0 → 100644
View file @
71ffb8c6
package
com
.
ctrip
.
apollo
.
portal
.
service
;
import
com.ctrip.apollo.core.Constants
;
import
com.ctrip.apollo.core.dto.*
;
import
com.ctrip.apollo.portal.RestUtils
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
com.ctrip.apollo.portal.service.impl.ConfigServiceImpl
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.test.util.ReflectionTestUtils
;
import
org.springframework.web.client.RestTemplate
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
mockito
.
Matchers
.*;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
ConfigServiceTest
{
@Mock
private
RestTemplate
restTemplate
;
@Mock
private
ResponseEntity
releaseSnapShotResponse
;
@Mock
private
ResponseEntity
versionResponse
;
@Mock
private
ResponseEntity
clusterResponse
;
@Mock
private
ResponseEntity
configItemResponse
;
private
ConfigServiceImpl
configService
;
@Before
public
void
setUp
()
{
ReflectionTestUtils
.
setField
(
RestUtils
.
class
,
"restTemplate"
,
restTemplate
);
configService
=
new
ConfigServiceImpl
();
}
@Test
public
void
testLoadReleaseConfig
()
{
long
appId
=
6666
;
long
versionId
=
100
;
long
releaseId
=
11111
;
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
someReleaseSnapShots
=
assembleReleaseSnapShots
();
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
someReleaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
assertEquals
(
appConfigVO
.
getAppId
(),
appId
);
assertEquals
(
appConfigVO
.
getVersionId
(),
versionId
);
assertEquals
(
appConfigVO
.
getDefaultClusterConfigs
().
size
(),
2
);
assertEquals
(
appConfigVO
.
getOverrideAppConfigs
().
size
(),
2
);
assertEquals
(
appConfigVO
.
getOverrideClusterConfigs
().
size
(),
2
);
}
@Test
public
void
testLoadReleaseConfigOnlyDefaultConfigs
()
{
long
appId
=
6666
;
long
versionId
=
100
;
long
releaseId
=
11111
;
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
assertEquals
(
appConfigVO
.
getAppId
(),
appId
);
assertEquals
(
appConfigVO
.
getVersionId
(),
versionId
);
assertEquals
(
appConfigVO
.
getDefaultClusterConfigs
().
size
(),
2
);
assertEquals
(
appConfigVO
.
getOverrideAppConfigs
().
size
(),
0
);
assertEquals
(
appConfigVO
.
getOverrideClusterConfigs
().
size
(),
0
);
}
@Test
public
void
testLoadReleaseConfigDefaultConfigsAndOverrideApp
()
{
long
appId
=
6666
;
long
versionId
=
100
;
long
releaseId
=
11111
;
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
1
];
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\", \"5555.bar\":\"demo2\", \"22.bar\":\"demo2\"}"
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
assertEquals
(
appConfigVO
.
getAppId
(),
appId
);
assertEquals
(
appConfigVO
.
getVersionId
(),
versionId
);
assertEquals
(
appConfigVO
.
getDefaultClusterConfigs
().
size
(),
2
);
assertEquals
(
2
,
appConfigVO
.
getOverrideAppConfigs
().
size
());
assertEquals
(
appConfigVO
.
getOverrideClusterConfigs
().
size
(),
0
);
}
@Test
public
void
testLoadReleaseConfigDefaultConfigsAndOverrideCluster
()
{
long
appId
=
6666
;
long
versionId
=
100
;
long
releaseId
=
11111
;
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
2
];
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
releaseSnapShots
[
1
]
=
assembleReleaseSnapShot
(
11112
,
"cluster1"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
assertEquals
(
appConfigVO
.
getAppId
(),
appId
);
assertEquals
(
appConfigVO
.
getVersionId
(),
versionId
);
assertEquals
(
appConfigVO
.
getDefaultClusterConfigs
().
size
(),
2
);
assertEquals
(
0
,
appConfigVO
.
getOverrideAppConfigs
().
size
());
assertEquals
(
1
,
appConfigVO
.
getOverrideClusterConfigs
().
size
());
}
@Test
public
void
testLoadLastestConfig
()
{
long
appId
=
6666
;
ClusterDTO
[]
someClusters
=
assembleClusters
();
ConfigItemDTO
[]
someConfigItem
=
assembleConfigItems
();
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/cluster/app/"
+
appId
,
ClusterDTO
[].
class
,
someClusters
,
clusterResponse
);
restInvoke
(
ConfigServiceImpl
.
ADMIN_SERVICE_HOST
+
"/configs/latest?clusterIds=100,101"
,
ConfigItemDTO
[].
class
,
someConfigItem
,
configItemResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadLatestConfig
(
appId
);
assertEquals
(
appConfigVO
.
getAppId
(),
6666
);
assertEquals
(
appConfigVO
.
getVersionId
(),
Constants
.
LASTEST_VERSION_ID
);
assertEquals
(
appConfigVO
.
getDefaultClusterConfigs
().
size
(),
3
);
assertEquals
(
appConfigVO
.
getOverrideAppConfigs
().
size
(),
1
);
assertEquals
(
appConfigVO
.
getOverrideClusterConfigs
().
size
(),
1
);
}
private
<
T
>
void
restInvoke
(
String
url
,
Class
<
T
>
responseType
,
T
result
,
ResponseEntity
someResponse
)
{
when
(
restTemplate
.
exchange
(
eq
(
url
),
eq
(
HttpMethod
.
GET
),
any
(
HttpEntity
.
class
),
eq
(
responseType
))).
thenReturn
(
someResponse
);
when
(
someResponse
.
getStatusCode
()).
thenReturn
(
HttpStatus
.
OK
);
when
(
someResponse
.
getBody
()).
thenReturn
(
result
);
}
private
VersionDTO
assembleVersion
(
long
appId
,
String
versionName
,
long
releaseId
)
{
VersionDTO
version
=
new
VersionDTO
();
version
.
setAppId
(
appId
);
version
.
setName
(
versionName
);
version
.
setReleaseId
(
releaseId
);
return
version
;
}
private
ReleaseSnapshotDTO
[]
assembleReleaseSnapShots
()
{
ReleaseSnapshotDTO
[]
releaseSnapShots
=
new
ReleaseSnapshotDTO
[
3
];
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\",\"3333.foo\":\"1008\",\"4444.bar\":\"99901\"}"
);
releaseSnapShots
[
1
]
=
assembleReleaseSnapShot
(
11111
,
"cluster1"
,
"{\"6666.foo\":\"demo1\"}"
);
releaseSnapShots
[
2
]
=
assembleReleaseSnapShot
(
11111
,
"cluster2"
,
"{\"6666.bar\":\"bar2222\"}"
);
return
releaseSnapShots
;
}
private
ReleaseSnapshotDTO
assembleReleaseSnapShot
(
long
releaseId
,
String
clusterName
,
String
configurations
)
{
ReleaseSnapshotDTO
releaseSnapShot
=
new
ReleaseSnapshotDTO
();
releaseSnapShot
.
setReleaseId
(
releaseId
);
releaseSnapShot
.
setClusterName
(
clusterName
);
releaseSnapShot
.
setConfigurations
(
configurations
);
return
releaseSnapShot
;
}
private
ClusterDTO
[]
assembleClusters
()
{
ClusterDTO
[]
clusters
=
new
ClusterDTO
[
2
];
clusters
[
0
]
=
assembleCluster
(
100
,
6666
,
"default-cluster-name"
);
clusters
[
1
]
=
assembleCluster
(
101
,
6666
,
"cluster1"
);
return
clusters
;
}
private
ClusterDTO
assembleCluster
(
long
id
,
long
appId
,
String
name
)
{
ClusterDTO
cluster
=
new
ClusterDTO
();
cluster
.
setAppId
(
appId
);
cluster
.
setId
(
id
);
cluster
.
setName
(
name
);
return
cluster
;
}
private
ConfigItemDTO
[]
assembleConfigItems
()
{
ConfigItemDTO
[]
configItems
=
new
ConfigItemDTO
[
5
];
configItems
[
0
]
=
assembleConfigItem
(
100
,
"default-cluster-name"
,
6666
,
"6666.k1"
,
"6666.v1"
);
configItems
[
1
]
=
assembleConfigItem
(
100
,
"default-cluster-name"
,
6666
,
"6666.k2"
,
"6666.v2"
);
configItems
[
2
]
=
assembleConfigItem
(
100
,
"default-cluster-name"
,
6666
,
"6666.k3"
,
"6666.v3"
);
configItems
[
3
]
=
assembleConfigItem
(
100
,
"default-cluster-name"
,
5555
,
"5555.k1"
,
"5555.v1"
);
configItems
[
4
]
=
assembleConfigItem
(
101
,
"cluster1"
,
6666
,
"6666.k1"
,
"6666.v1"
);
return
configItems
;
}
private
ConfigItemDTO
assembleConfigItem
(
long
clusterId
,
String
clusterName
,
int
appId
,
String
key
,
String
value
)
{
ConfigItemDTO
configItem
=
new
ConfigItemDTO
();
configItem
.
setClusterName
(
clusterName
);
configItem
.
setClusterId
(
clusterId
);
configItem
.
setAppId
(
appId
);
configItem
.
setKey
(
key
);
configItem
.
setValue
(
value
);
return
configItem
;
}
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/PrivilegeServiceTest.java
View file @
71ffb8c6
...
@@ -21,7 +21,7 @@ public class PrivilegeServiceTest extends AbstractPortalTest {
...
@@ -21,7 +21,7 @@ public class PrivilegeServiceTest extends AbstractPortalTest {
@Test
@Test
public
void
testAddAndRemovePrivilege
()
{
public
void
testAddAndRemovePrivilege
()
{
App
newApp
=
new
App
();
App
newApp
=
new
App
();
newApp
.
setAppId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
setAppId
((
System
.
currentTimeMillis
()));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appService
.
save
(
newApp
);
appService
.
save
(
newApp
);
...
@@ -42,7 +42,7 @@ public class PrivilegeServiceTest extends AbstractPortalTest {
...
@@ -42,7 +42,7 @@ public class PrivilegeServiceTest extends AbstractPortalTest {
@Test
@Test
public
void
testCheckPrivilege
()
{
public
void
testCheckPrivilege
()
{
App
newApp
=
new
App
();
App
newApp
=
new
App
();
newApp
.
setAppId
(
String
.
valueOf
(
System
.
currentTimeMillis
()));
newApp
.
setAppId
((
System
.
currentTimeMillis
()));
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setName
(
"new app "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
newApp
.
setOwner
(
"owner "
+
System
.
currentTimeMillis
());
appService
.
save
(
newApp
);
appService
.
save
(
newApp
);
...
...
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