Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
d4ed153f
Commit
d4ed153f
authored
Jun 23, 2016
by
Jason Song
Committed by
GitHub
Jun 23, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #286 from lepdou/0620_27
commit history & bugfix empty value
parents
57ddd524
4c0a7548
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
454 additions
and
87 deletions
+454
-87
CommitController.java
...work/apollo/adminservice/controller/CommitController.java
+31
-0
ItemController.java
...mework/apollo/adminservice/controller/ItemController.java
+35
-1
ItemSetController.java
...ork/apollo/adminservice/controller/ItemSetController.java
+8
-2
Commit.java
...in/java/com/ctrip/framework/apollo/biz/entity/Commit.java
+1
-1
CommitRepository.java
...rip/framework/apollo/biz/repository/CommitRepository.java
+3
-2
CommitService.java
...com/ctrip/framework/apollo/biz/service/CommitService.java
+10
-6
ItemSetService.java
...om/ctrip/framework/apollo/biz/service/ItemSetService.java
+36
-4
ConfigChangeContentBuilder.java
...ramework/apollo/biz/utils/ConfigChangeContentBuilder.java
+68
-0
RequestPrecondition.java
...ip/framework/apollo/common/utils/RequestPrecondition.java
+11
-1
BaseDTO.java
...ain/java/com/ctrip/framework/apollo/core/dto/BaseDTO.java
+22
-0
CommitDTO.java
...n/java/com/ctrip/framework/apollo/core/dto/CommitDTO.java
+54
-0
AdminServiceAPI.java
...om/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
+20
-2
AppController.java
...rip/framework/apollo/portal/controller/AppController.java
+2
-1
CommitController.java
.../framework/apollo/portal/controller/CommitController.java
+35
-0
ConfigController.java
.../framework/apollo/portal/controller/ConfigController.java
+2
-2
NamespaceController.java
...amework/apollo/portal/controller/NamespaceController.java
+2
-2
PermissionController.java
...mework/apollo/portal/controller/PermissionController.java
+1
-1
ServerConfigController.java
...work/apollo/portal/controller/ServerConfigController.java
+2
-2
NamespaceTextModel.java
...amework/apollo/portal/entity/form/NamespaceTextModel.java
+0
-8
CommitService.java
.../ctrip/framework/apollo/portal/service/CommitService.java
+23
-0
config.html
apollo-portal/src/main/resources/static/config.html
+0
-0
plus.png
apollo-portal/src/main/resources/static/img/plus.png
+0
-0
release.png
apollo-portal/src/main/resources/static/img/release.png
+0
-0
ConfigNamespaceController.js
...tatic/scripts/controller/app/ConfigNamespaceController.js
+45
-21
CommitService.js
...c/main/resources/static/scripts/services/CommitService.js
+27
-0
common-style.css
...-portal/src/main/resources/static/styles/common-style.css
+16
-31
No files found.
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/CommitController.java
0 → 100644
View file @
d4ed153f
package
com
.
ctrip
.
framework
.
apollo
.
adminservice
.
controller
;
import
com.ctrip.framework.apollo.biz.entity.Commit
;
import
com.ctrip.framework.apollo.biz.service.CommitService
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.core.dto.CommitDTO
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
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
public
class
CommitController
{
@Autowired
private
CommitService
commitService
;
@RequestMapping
(
value
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit"
)
public
List
<
CommitDTO
>
find
(
@PathVariable
String
appId
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
Pageable
pageable
){
List
<
Commit
>
commits
=
commitService
.
find
(
appId
,
clusterName
,
namespaceName
,
pageable
);
return
BeanUtils
.
batchTransform
(
CommitDTO
.
class
,
commits
);
}
}
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ItemController.java
View file @
d4ed153f
...
...
@@ -11,8 +11,13 @@ import org.springframework.web.bind.annotation.RequestMethod;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ctrip.framework.apollo.biz.entity.Commit
;
import
com.ctrip.framework.apollo.biz.entity.Item
;
import
com.ctrip.framework.apollo.biz.entity.Namespace
;
import
com.ctrip.framework.apollo.biz.service.CommitService
;
import
com.ctrip.framework.apollo.biz.service.ItemService
;
import
com.ctrip.framework.apollo.biz.service.NamespaceService
;
import
com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.core.dto.ItemDTO
;
import
com.ctrip.framework.apollo.core.exception.NotFoundException
;
...
...
@@ -22,16 +27,24 @@ public class ItemController {
@Autowired
private
ItemService
itemService
;
@Autowired
private
NamespaceService
namespaceService
;
@Autowired
private
CommitService
commitService
;
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
method
=
RequestMethod
.
POST
)
public
ItemDTO
createOrUpdate
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
,
@RequestBody
ItemDTO
dto
)
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
dto
);
ConfigChangeContentBuilder
builder
=
new
ConfigChangeContentBuilder
();
Item
managedEntity
=
itemService
.
findOne
(
appId
,
clusterName
,
namespaceName
,
entity
.
getKey
());
if
(
managedEntity
!=
null
)
{
Item
beforeUpdateItem
=
BeanUtils
.
transfrom
(
Item
.
class
,
managedEntity
);
BeanUtils
.
copyEntityProperties
(
entity
,
managedEntity
);
entity
=
itemService
.
update
(
managedEntity
);
builder
.
updateItem
(
beforeUpdateItem
,
entity
);
}
else
{
Item
lastItem
=
itemService
.
findLastOne
(
appId
,
clusterName
,
namespaceName
);
int
lineNum
=
1
;
...
...
@@ -41,9 +54,19 @@ public class ItemController {
}
entity
.
setLineNum
(
lineNum
);
entity
=
itemService
.
save
(
entity
);
builder
.
createItem
(
entity
);
}
dto
=
BeanUtils
.
transfrom
(
ItemDTO
.
class
,
entity
);
Commit
commit
=
new
Commit
();
commit
.
setAppId
(
appId
);
commit
.
setClusterName
(
clusterName
);
commit
.
setNamespaceName
(
namespaceName
);
commit
.
setChangeSets
(
builder
.
build
());
commit
.
setDataChangeCreatedBy
(
dto
.
getDataChangeLastModifiedBy
());
commit
.
setDataChangeLastModifiedBy
(
dto
.
getDataChangeLastModifiedBy
());
commitService
.
save
(
commit
);
return
dto
;
}
...
...
@@ -54,6 +77,17 @@ public class ItemController {
throw
new
NotFoundException
(
"item not found for itemId "
+
itemId
);
}
itemService
.
delete
(
entity
.
getId
(),
operator
);
Namespace
namespace
=
namespaceService
.
findOne
(
entity
.
getNamespaceId
());
Commit
commit
=
new
Commit
();
commit
.
setAppId
(
namespace
.
getAppId
());
commit
.
setClusterName
(
namespace
.
getClusterName
());
commit
.
setNamespaceName
(
namespace
.
getNamespaceName
());
commit
.
setChangeSets
(
new
ConfigChangeContentBuilder
().
deleteItem
(
entity
).
build
());
commit
.
setDataChangeCreatedBy
(
operator
);
commit
.
setDataChangeLastModifiedBy
(
operator
);
commitService
.
save
(
commit
);
}
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
)
...
...
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ItemSetController.java
View file @
d4ed153f
...
...
@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.adminservice.controller;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
...
...
@@ -18,8 +19,13 @@ public class ItemSetController {
private
ItemSetService
itemSetService
;
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
Void
>
create
(
@RequestBody
ItemChangeSets
changeSet
)
{
itemSetService
.
updateSet
(
changeSet
);
public
ResponseEntity
<
Void
>
create
(
@PathVariable
String
appId
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
ItemChangeSets
changeSet
)
{
itemSetService
.
updateSet
(
appId
,
clusterName
,
namespaceName
,
changeSet
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
build
();
}
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/entity/Commit.java
View file @
d4ed153f
...
...
@@ -15,7 +15,7 @@ import javax.persistence.Table;
@Where
(
clause
=
"isDeleted = 0"
)
public
class
Commit
extends
BaseEntity
{
@Column
(
name
=
"ChangeSets"
,
nullable
=
false
)
@Column
(
name
=
"ChangeSets"
,
length
=
4048
,
nullable
=
false
)
private
String
changeSets
;
@Column
(
name
=
"AppId"
,
nullable
=
false
)
...
...
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/repository/CommitRepository.java
View file @
d4ed153f
...
...
@@ -2,13 +2,14 @@ package com.ctrip.framework.apollo.biz.repository;
import
com.ctrip.framework.apollo.biz.entity.Commit
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.repository.PagingAndSortingRepository
;
import
java.util.List
;
public
interface
CommitRepository
extends
PagingAndSortingRepository
<
Commit
,
Long
>
{
List
<
Commit
>
findByAppIdAndClusterNameAndNamespaceName
(
String
appId
,
String
clusterName
,
String
namespaceName
);
List
<
Commit
>
findByAppIdAndClusterNameAndNamespaceName
OrderByIdDesc
(
String
appId
,
String
clusterName
,
String
namespaceName
,
Pageable
pageable
);
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/CommitService.java
View file @
d4ed153f
...
...
@@ -4,9 +4,11 @@ import com.ctrip.framework.apollo.biz.entity.Commit;
import
com.ctrip.framework.apollo.biz.repository.CommitRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.
Date
;
import
java.util.
List
;
@Service
public
class
CommitService
{
...
...
@@ -14,12 +16,14 @@ public class CommitService {
@Autowired
private
CommitRepository
commitRepository
;
public
void
save
(
Commit
commit
,
String
user
){
@Transactional
public
Commit
save
(
Commit
commit
){
commit
.
setId
(
0
);
//protection
commit
.
setDataChangeCreatedBy
(
user
);
commit
.
setDataChangeCreatedTime
(
new
Date
());
commitRepository
.
save
(
commit
);
return
commitRepository
.
save
(
commit
);
}
public
List
<
Commit
>
find
(
String
appId
,
String
clusterName
,
String
namespaceName
,
Pageable
page
){
return
commitRepository
.
findByAppIdAndClusterNameAndNamespaceNameOrderByIdDesc
(
appId
,
clusterName
,
namespaceName
,
page
);
}
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemSetService.java
View file @
d4ed153f
...
...
@@ -6,12 +6,15 @@ import org.springframework.transaction.annotation.Transactional;
import
org.springframework.util.CollectionUtils
;
import
com.ctrip.framework.apollo.biz.entity.Audit
;
import
com.ctrip.framework.apollo.biz.entity.Commit
;
import
com.ctrip.framework.apollo.biz.entity.Item
;
import
com.ctrip.framework.apollo.biz.repository.ItemRepository
;
import
com.ctrip.framework.apollo.biz.utils.ConfigChangeContentBuilder
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.framework.apollo.core.dto.ItemDTO
;
@Service
public
class
ItemSetService
{
...
...
@@ -21,16 +24,24 @@ public class ItemSetService {
@Autowired
private
AuditService
auditService
;
@Autowired
private
CommitService
commitService
;
@Transactional
public
void
updateSet
(
ItemChangeSets
changeSet
)
{
public
ItemChangeSets
updateSet
(
String
appId
,
String
clusterName
,
String
namespaceName
,
ItemChangeSets
changeSet
)
{
String
operator
=
changeSet
.
getDataChangeLastModifiedBy
();
ConfigChangeContentBuilder
configChangeContentBuilder
=
new
ConfigChangeContentBuilder
();
if
(!
CollectionUtils
.
isEmpty
(
changeSet
.
getCreateItems
()))
{
for
(
ItemDTO
item
:
changeSet
.
getCreateItems
())
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
entity
.
setId
(
0
);
//protection
entity
.
setDataChangeCreatedBy
(
operator
);
entity
.
setDataChangeLastModifiedBy
(
operator
);
itemRepository
.
save
(
entity
);
Item
createdItem
=
itemRepository
.
save
(
entity
);
configChangeContentBuilder
.
createItem
(
createdItem
);
}
auditService
.
audit
(
"ItemSet"
,
null
,
Audit
.
OP
.
INSERT
,
operator
);
}
...
...
@@ -39,9 +50,12 @@ public class ItemSetService {
for
(
ItemDTO
item
:
changeSet
.
getUpdateItems
())
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
Item
managedItem
=
itemRepository
.
findOne
(
entity
.
getId
());
Item
beforeUpdateItem
=
BeanUtils
.
transfrom
(
Item
.
class
,
managedItem
);
BeanUtils
.
copyEntityProperties
(
entity
,
managedItem
);
managedItem
.
setDataChangeLastModifiedBy
(
operator
);
itemRepository
.
save
(
managedItem
);
Item
updatedItem
=
itemRepository
.
save
(
managedItem
);
configChangeContentBuilder
.
updateItem
(
beforeUpdateItem
,
updatedItem
);
}
auditService
.
audit
(
"ItemSet"
,
null
,
Audit
.
OP
.
UPDATE
,
operator
);
}
...
...
@@ -51,9 +65,27 @@ public class ItemSetService {
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
entity
.
setDeleted
(
true
);
entity
.
setDataChangeLastModifiedBy
(
operator
);
itemRepository
.
save
(
entity
);
Item
deletedItem
=
itemRepository
.
save
(
entity
);
configChangeContentBuilder
.
deleteItem
(
deletedItem
);
}
auditService
.
audit
(
"ItemSet"
,
null
,
Audit
.
OP
.
DELETE
,
operator
);
}
createCommit
(
appId
,
clusterName
,
namespaceName
,
configChangeContentBuilder
.
build
(),
changeSet
.
getDataChangeLastModifiedBy
());
return
changeSet
;
}
private
void
createCommit
(
String
appId
,
String
clusterName
,
String
namespaceName
,
String
configChangeContent
,
String
operator
){
Commit
commit
=
new
Commit
();
commit
.
setAppId
(
appId
);
commit
.
setClusterName
(
clusterName
);
commit
.
setNamespaceName
(
namespaceName
);
commit
.
setChangeSets
(
configChangeContent
);
commit
.
setDataChangeCreatedBy
(
operator
);
commit
.
setDataChangeLastModifiedBy
(
operator
);
commitService
.
save
(
commit
);
}
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/utils/ConfigChangeContentBuilder.java
0 → 100644
View file @
d4ed153f
package
com
.
ctrip
.
framework
.
apollo
.
biz
.
utils
;
import
com.google.gson.Gson
;
import
com.google.gson.GsonBuilder
;
import
com.ctrip.framework.apollo.biz.entity.Item
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.framework.apollo.core.dto.ItemDTO
;
import
java.util.Date
;
import
java.util.LinkedList
;
import
java.util.List
;
public
class
ConfigChangeContentBuilder
{
private
static
final
Gson
gson
=
new
GsonBuilder
().
setDateFormat
(
"yyyy-MM-dd HH:mm:ss"
).
create
();
private
List
<
Item
>
createItems
=
new
LinkedList
<>();
private
List
<
ItemPair
>
updateItems
=
new
LinkedList
<>();
private
List
<
Item
>
deleteItems
=
new
LinkedList
<>();
public
ConfigChangeContentBuilder
createItem
(
Item
item
)
{
createItems
.
add
(
item
);
return
this
;
}
public
ConfigChangeContentBuilder
updateItem
(
Item
oldItem
,
Item
newItem
)
{
ItemPair
itemPair
=
new
ItemPair
(
oldItem
,
newItem
);
updateItems
.
add
(
itemPair
);
return
this
;
}
public
ConfigChangeContentBuilder
deleteItem
(
Item
item
)
{
deleteItems
.
add
(
item
);
return
this
;
}
public
String
build
()
{
//因为事务第一段提交并没有更新时间,所以build时统一更新
for
(
Item
item
:
createItems
)
{
item
.
setDataChangeLastModifiedTime
(
new
Date
());
}
for
(
ItemPair
item
:
updateItems
)
{
item
.
newItem
.
setDataChangeLastModifiedTime
(
new
Date
());
}
for
(
Item
item
:
deleteItems
)
{
item
.
setDataChangeLastModifiedTime
(
new
Date
());
}
return
gson
.
toJson
(
this
);
}
class
ItemPair
{
Item
oldItem
;
Item
newItem
;
public
ItemPair
(
Item
oldItem
,
Item
newItem
)
{
this
.
oldItem
=
oldItem
;
this
.
newItem
=
newItem
;
}
}
}
apollo-
portal/src/main/java/com/ctrip/framework/apollo/portal/util
/RequestPrecondition.java
→
apollo-
common/src/main/java/com/ctrip/framework/apollo/common/utils
/RequestPrecondition.java
View file @
d4ed153f
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
;
package
com
.
ctrip
.
framework
.
apollo
.
common
.
utils
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
...
...
@@ -10,6 +10,8 @@ public class RequestPrecondition {
private
static
String
ILLEGAL_MODEL
=
"request model is invalid"
;
private
static
String
ILLEGAL_NUMBER
=
"number should be positive"
;
public
static
void
checkArgument
(
String
...
args
)
{
checkArgument
(!
StringUtils
.
isContainEmpty
(
args
),
CONTAIN_EMPTY_ARGUMENT
);
}
...
...
@@ -24,6 +26,14 @@ public class RequestPrecondition {
}
}
public
static
void
checkNumberPositive
(
int
...
args
){
for
(
int
num:
args
){
if
(
num
<=
0
){
throw
new
BadRequestException
(
ILLEGAL_NUMBER
);
}
}
}
}
apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/BaseDTO.java
View file @
d4ed153f
package
com
.
ctrip
.
framework
.
apollo
.
core
.
dto
;
import
java.util.Date
;
public
class
BaseDTO
{
protected
String
dataChangeCreatedBy
;
protected
String
dataChangeLastModifiedBy
;
protected
Date
dataChangeCreatedTime
;
protected
Date
dataChangeLastModifiedTime
;
public
String
getDataChangeCreatedBy
()
{
return
dataChangeCreatedBy
;
}
...
...
@@ -22,4 +28,20 @@ public class BaseDTO {
public
void
setDataChangeLastModifiedBy
(
String
dataChangeLastModifiedBy
)
{
this
.
dataChangeLastModifiedBy
=
dataChangeLastModifiedBy
;
}
public
Date
getDataChangeCreatedTime
()
{
return
dataChangeCreatedTime
;
}
public
void
setDataChangeCreatedTime
(
Date
dataChangeCreatedTime
)
{
this
.
dataChangeCreatedTime
=
dataChangeCreatedTime
;
}
public
Date
getDataChangeLastModifiedTime
()
{
return
dataChangeLastModifiedTime
;
}
public
void
setDataChangeLastModifiedTime
(
Date
dataChangeLastModifiedTime
)
{
this
.
dataChangeLastModifiedTime
=
dataChangeLastModifiedTime
;
}
}
apollo-core/src/main/java/com/ctrip/framework/apollo/core/dto/CommitDTO.java
0 → 100644
View file @
d4ed153f
package
com
.
ctrip
.
framework
.
apollo
.
core
.
dto
;
public
class
CommitDTO
extends
BaseDTO
{
private
String
changeSets
;
private
String
appId
;
private
String
clusterName
;
private
String
namespaceName
;
private
String
comment
;
public
String
getChangeSets
()
{
return
changeSets
;
}
public
void
setChangeSets
(
String
changeSets
)
{
this
.
changeSets
=
changeSets
;
}
public
String
getAppId
()
{
return
appId
;
}
public
void
setAppId
(
String
appId
)
{
this
.
appId
=
appId
;
}
public
String
getClusterName
()
{
return
clusterName
;
}
public
void
setClusterName
(
String
clusterName
)
{
this
.
clusterName
=
clusterName
;
}
public
String
getNamespaceName
()
{
return
namespaceName
;
}
public
void
setNamespaceName
(
String
namespaceName
)
{
this
.
namespaceName
=
namespaceName
;
}
public
String
getComment
()
{
return
comment
;
}
public
void
setComment
(
String
comment
)
{
this
.
comment
=
comment
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
View file @
d4ed153f
...
...
@@ -2,6 +2,7 @@ package com.ctrip.framework.apollo.portal.api;
import
com.ctrip.framework.apollo.core.dto.AppNamespaceDTO
;
import
com.ctrip.framework.apollo.core.dto.CommitDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.dto.AppDTO
;
import
com.ctrip.framework.apollo.core.dto.ClusterDTO
;
...
...
@@ -66,8 +67,10 @@ public class AdminServiceAPI {
public
NamespaceDTO
loadNamespace
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
NamespaceDTO
dto
=
restTemplate
.
getForObject
(
"{host}/apps/{appId}/clusters/{clusterName}/namespaces/"
+
namespaceName
,
NamespaceDTO
.
class
,
getAdminServiceHost
(
env
),
appId
,
clusterName
);
NamespaceDTO
dto
=
restTemplate
.
getForObject
(
"{host}/apps/{appId}/clusters/{clusterName}/namespaces/"
+
namespaceName
,
NamespaceDTO
.
class
,
getAdminServiceHost
(
env
),
appId
,
clusterName
);
return
dto
;
}
...
...
@@ -157,4 +160,19 @@ public class AdminServiceAPI {
}
}
@Service
public
static
class
CommitAPI
extends
API
{
public
List
<
CommitDTO
>
find
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
int
page
,
int
size
)
{
CommitDTO
[]
commitDTOs
=
restTemplate
.
getForObject
(
"{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit?page={page}&size={size}"
,
CommitDTO
[].
class
,
getAdminServiceHost
(
env
),
appId
,
clusterName
,
namespaceName
,
page
,
size
);
return
Arrays
.
asList
(
commitDTOs
);
}
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java
View file @
d4ed153f
...
...
@@ -25,7 +25,7 @@ import org.springframework.web.client.HttpClientErrorException;
import
java.util.List
;
import
static
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
.
RequestPrecondition
.
checkArgument
;
import
static
com
.
ctrip
.
framework
.
apollo
.
common
.
utils
.
RequestPrecondition
.
checkArgument
;
@RestController
@RequestMapping
(
"/apps"
)
...
...
@@ -40,6 +40,7 @@ public class AppController {
@Autowired
private
ApplicationEventPublisher
publisher
;
@RequestMapping
(
""
)
public
List
<
App
>
findAllApp
()
{
return
appService
.
findAll
();
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/CommitController.java
0 → 100644
View file @
d4ed153f
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
controller
;
import
com.ctrip.framework.apollo.core.dto.CommitDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.service.CommitService
;
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.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@RestController
public
class
CommitController
{
@Autowired
private
CommitService
commitService
;
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/commits"
)
public
List
<
CommitDTO
>
find
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestParam
(
defaultValue
=
"0"
)
int
page
,
@RequestParam
(
defaultValue
=
"10"
)
int
size
){
if
(
page
<
0
){
page
=
0
;
}
return
commitService
.
find
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
,
page
,
size
);
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigController.java
View file @
d4ed153f
...
...
@@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
import
java.util.List
;
import
static
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
.
RequestPrecondition
.
checkModel
;
import
static
com
.
ctrip
.
framework
.
apollo
.
common
.
utils
.
RequestPrecondition
.
checkModel
;
@RestController
@RequestMapping
(
""
)
...
...
@@ -128,7 +128,7 @@ public class ConfigController {
}
private
boolean
isValidItem
(
ItemDTO
item
){
return
item
!=
null
&&
!
StringUtils
.
isContainEmpty
(
item
.
getKey
()
,
item
.
getValue
()
);
return
item
!=
null
&&
!
StringUtils
.
isContainEmpty
(
item
.
getKey
());
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java
View file @
d4ed153f
...
...
@@ -29,8 +29,8 @@ import org.springframework.web.bind.annotation.RestController;
import
java.util.List
;
import
static
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
.
RequestPrecondition
.
checkArgument
;
import
static
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
.
RequestPrecondition
.
checkModel
;
import
static
com
.
ctrip
.
framework
.
apollo
.
common
.
utils
.
RequestPrecondition
.
checkArgument
;
import
static
com
.
ctrip
.
framework
.
apollo
.
common
.
utils
.
RequestPrecondition
.
checkModel
;
@RestController
public
class
NamespaceController
{
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PermissionController.java
View file @
d4ed153f
...
...
@@ -24,7 +24,7 @@ import org.springframework.web.bind.annotation.RestController;
import
java.util.Set
;
import
static
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
.
RequestPrecondition
.
checkArgument
;
import
static
com
.
ctrip
.
framework
.
apollo
.
common
.
utils
.
RequestPrecondition
.
checkArgument
;
@RestController
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ServerConfigController.java
View file @
d4ed153f
...
...
@@ -12,8 +12,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
static
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
.
RequestPrecondition
.
checkArgument
;
import
static
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
.
RequestPrecondition
.
checkModel
;
import
static
com
.
ctrip
.
framework
.
apollo
.
common
.
utils
.
RequestPrecondition
.
checkArgument
;
import
static
com
.
ctrip
.
framework
.
apollo
.
common
.
utils
.
RequestPrecondition
.
checkModel
;
/**
* 配置中心本身需要一些配置,这些配置放在数据库里面
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/form/NamespaceTextModel.java
View file @
d4ed153f
...
...
@@ -12,7 +12,6 @@ public class NamespaceTextModel implements Verifiable {
private
String
namespaceName
;
private
int
namespaceId
;
private
String
configText
;
private
String
comment
;
@Override
public
boolean
isInvalid
(){
...
...
@@ -66,11 +65,4 @@ public class NamespaceTextModel implements Verifiable {
this
.
configText
=
configText
;
}
public
String
getComment
()
{
return
comment
;
}
public
void
setComment
(
String
comment
)
{
this
.
comment
=
comment
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/CommitService.java
0 → 100644
View file @
d4ed153f
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
service
;
import
com.ctrip.framework.apollo.core.dto.CommitDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
@Service
public
class
CommitService
{
@Autowired
private
AdminServiceAPI
.
CommitAPI
commitAPI
;
public
List
<
CommitDTO
>
find
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
int
page
,
int
size
){
return
commitAPI
.
find
(
appId
,
env
,
clusterName
,
namespaceName
,
page
,
size
);
}
}
apollo-portal/src/main/resources/static/config.html
View file @
d4ed153f
This diff is collapsed.
Click to expand it.
apollo-portal/src/main/resources/static/img/plus.png
View replaced file @
57ddd524
View file @
d4ed153f
2.07 KB
|
W:
|
H:
1.78 KB
|
W:
|
H:
2-up
Swipe
Onion skin
apollo-portal/src/main/resources/static/img/release.png
View replaced file @
57ddd524
View file @
d4ed153f
4.24 KB
|
W:
|
H:
4.24 KB
|
W:
|
H:
2-up
Swipe
Onion skin
apollo-portal/src/main/resources/static/scripts/controller/app/ConfigNamespaceController.js
View file @
d4ed153f
application_module
.
controller
(
"ConfigNamespaceController"
,
[
'$rootScope'
,
'$scope'
,
'$location'
,
'toastr'
,
'AppUtil'
,
'ConfigService'
,
'PermissionService'
,
function
(
$rootScope
,
$scope
,
$location
,
toastr
,
AppUtil
,
ConfigService
,
PermissionService
)
{
'CommitService'
,
function
(
$rootScope
,
$scope
,
$location
,
toastr
,
AppUtil
,
ConfigService
,
PermissionService
,
CommitService
)
{
var
namespace_view_type
=
{
TEXT
:
'text'
,
...
...
@@ -78,14 +79,41 @@ application_module.controller("ConfigNamespaceController",
});
$scope
.
switchView
=
function
(
namespace
,
viewType
)
{
namespace
.
viewType
=
viewType
;
if
(
namespace_view_type
.
TEXT
==
viewType
)
{
namespace
.
text
=
parseModel2Text
(
namespace
);
}
else
if
(
namespace_view_type
.
TABLE
==
viewType
)
{
}
else
{
$scope
.
loadCommitHistory
(
namespace
);
}
namespace
.
viewType
=
viewType
;
};
$scope
.
loadCommitHistory
=
function
(
namespace
)
{
if
(
!
namespace
.
commits
){
namespace
.
commits
=
[];
namespace
.
commitPage
=
0
;
}
CommitService
.
find_commits
(
$rootScope
.
pageContext
.
appId
,
$rootScope
.
pageContext
.
env
,
$rootScope
.
pageContext
.
clusterName
,
namespace
.
namespace
.
namespaceName
,
namespace
.
commitPage
)
.
then
(
function
(
result
)
{
if
(
result
.
length
==
0
){
namespace
.
hasLoadAllCommit
=
true
;
}
for
(
var
i
=
0
;
i
<
result
.
length
;
i
++
)
{
//to json
result
[
i
].
changeSets
=
JSON
.
parse
(
result
[
i
].
changeSets
);
namespace
.
commits
.
push
(
result
[
i
]);
}
namespace
.
commitPage
+=
1
;
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"加载修改历史记录出错"
);
});
}
var
MAX_ROW_SIZE
=
30
;
var
APPEND_ROW_SIZE
=
8
;
//把表格内容解析成文本
...
...
@@ -118,28 +146,20 @@ application_module.controller("ConfigNamespaceController",
return
result
;
}
$scope
.
toCommitNamespace
=
{};
$scope
.
setCommitNamespace
=
function
(
namespace
)
{
$scope
.
toCommitNamespace
=
namespace
;
};
$scope
.
commitComment
=
''
;
//更新配置
$scope
.
commitChange
=
function
()
{
$scope
.
commitChange
=
function
(
namespace
)
{
ConfigService
.
modify_items
(
$scope
.
pageContext
.
appId
,
$scope
.
pageContext
.
env
,
$scope
.
pageContext
.
clusterName
,
$scope
.
toCommitNamespace
.
namespace
.
namespaceName
,
$scope
.
toCommitNamespace
.
editText
,
$scope
.
toCommitNamespace
.
namespace
.
id
,
$scope
.
commitComment
).
then
(
namespace
.
namespace
.
namespaceName
,
namespace
.
editText
,
namespace
.
namespace
.
id
).
then
(
function
(
result
)
{
toastr
.
success
(
"更新成功"
);
//refresh all namespace items
$rootScope
.
refreshNamespaces
();
$scope
.
toCommitN
amespace
.
commited
=
true
;
$scope
.
toggleTextEditStatus
(
$scope
.
toCommitN
amespace
);
n
amespace
.
commited
=
true
;
$scope
.
toggleTextEditStatus
(
n
amespace
);
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"更新失败"
);
...
...
@@ -151,12 +171,12 @@ application_module.controller("ConfigNamespaceController",
$scope
.
toggleTextEditStatus
=
function
(
namespace
)
{
namespace
.
isTextEditing
=
!
namespace
.
isTextEditing
;
if
(
namespace
.
isTextEditing
)
{
//切换为编辑状态
$scope
.
toCommitN
amespace
.
commited
=
false
;
n
amespace
.
commited
=
false
;
namespace
.
backupText
=
namespace
.
text
;
namespace
.
editText
=
parseModel2Text
(
namespace
,
'edit'
);
}
else
{
if
(
!
$scope
.
toCommitN
amespace
.
commited
)
{
//取消编辑,则复原
if
(
!
n
amespace
.
commited
)
{
//取消编辑,则复原
namespace
.
text
=
namespace
.
backupText
;
}
}
...
...
@@ -286,15 +306,19 @@ application_module.controller("ConfigNamespaceController",
});
}
else
if
(
$scope
.
tableViewOperType
==
TABLE_VIEW_OPER_TYPE
.
UPDATE
)
{
if
(
!
$scope
.
item
.
value
){
$scope
.
item
.
value
=
""
;
}
if
(
!
$scope
.
item
.
comment
){
$scope
.
item
.
comment
=
""
;
}
ConfigService
.
update_item
(
$rootScope
.
pageContext
.
appId
,
cluster
.
env
,
cluster
.
name
,
toOperationNamespaceName
,
$scope
.
item
).
then
(
function
(
result
)
{
toastr
.
success
(
"["
+
cluster
.
env
+
","
+
cluster
.
name
+
"]"
,
"更新成功"
);
toastr
.
success
(
"更新成功, 如需生效请发布"
);
itemModal
.
modal
(
'hide'
);
$rootScope
.
refreshNamespaces
(
namespace_view_type
.
TABLE
);
},
function
(
result
)
{
...
...
apollo-portal/src/main/resources/static/scripts/services/CommitService.js
0 → 100644
View file @
d4ed153f
appService
.
service
(
'CommitService'
,
[
'$resource'
,
'$q'
,
function
(
$resource
,
$q
)
{
var
commit_resource
=
$resource
(
''
,
{},
{
find_commits
:
{
method
:
'GET'
,
isArray
:
true
,
url
:
'/apps/:appId/envs/:env/clusters/:clusterName/namespaces/:namespaceName/commits?page=:page'
}
});
return
{
find_commits
:
function
(
appId
,
env
,
clusterName
,
namespaceName
,
page
)
{
var
d
=
$q
.
defer
();
commit_resource
.
find_commits
({
appId
:
appId
,
env
:
env
,
clusterName
:
clusterName
,
namespaceName
:
namespaceName
,
page
:
page
},
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 @
d4ed153f
...
...
@@ -174,7 +174,6 @@ table th {
border-bottom
:
1px
solid
#ddd
;
}
.tocify-header
{
font-size
:
14px
;
}
...
...
@@ -206,12 +205,12 @@ table th {
border
:
0px
;
}
.config-item-container
.second-panel-heading
.ns_btn
{
.config-item-container
.second-panel-heading
.ns_btn
{
width
:
25px
;
height
:
25px
;
}
.config-item-container
.second-panel-heading
.nav-tabs
.node_active
{
.config-item-container
.second-panel-heading
.nav-tabs
.node_active
{
border-bottom
:
3px
#1b6d85
solid
;
}
...
...
@@ -221,26 +220,26 @@ table th {
overflow
:
scroll
;
}
.config-item-container
.panel-heading
button
img
{
.config-item-container
.panel-heading
button
img
{
width
:
12px
;
height
:
12px
;
}
.config-item-container
.panel-heading
a
img
{
.config-item-container
.panel-heading
a
img
{
width
:
12px
;
height
:
12px
;
}
.config-item-container
.panel-heading
li
img
{
.config-item-container
.panel-heading
li
img
{
width
:
12px
;
height
:
12px
;
}
.config-item-container
.second-panel-heading
{
.config-item-container
.second-panel-heading
{
height
:
45px
;
}
.config-item-container
.second-panel-heading
a
{
.config-item-container
.second-panel-heading
a
{
height
:
35px
;
color
:
#555
;
font-size
:
13px
;
...
...
@@ -248,11 +247,11 @@ table th {
}
.second-panel-heading
.nav-tabs
{
.second-panel-heading
.nav-tabs
{
border-bottom
:
0px
;
}
.namespace-view-table
td
img
{
.namespace-view-table
td
img
{
cursor
:
pointer
;
width
:
23px
;
height
:
23px
;
...
...
@@ -272,27 +271,8 @@ table th {
}
.history-view
{
padding
:
50px
20px
;
}
.history-view
.commit
{
padding
:
5px
15px
;
border
:
1px
solid
#ddd
;
}
.history-view
img
{
position
:
absolute
;
left
:
-28px
;
}
padding
:
10px
20px
;
.history-view
.media
.row
{
padding-left
:
35px
;
}
.history-view
.list
{
position
:
relative
;
border-left
:
3px
solid
#ddd
;
}
.line
{
...
...
@@ -380,7 +360,12 @@ table th {
padding
:
20px
15px
}
.user-container
.user-info
{
.user-container
.user-info
{
margin-left
:
5px
;
}
.change-type-mark
{
width
:
5px
;
height
:
5px
;
}
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