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
c99fd43f
Commit
c99fd43f
authored
Apr 13, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #82 from lepdou/v2
portal can edit config
parents
719d67d0
7b596e07
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
32 changed files
with
477 additions
and
422 deletions
+477
-422
ItemSetController.java
...rip/apollo/adminservice/controller/ItemSetController.java
+4
-2
ReleaseController.java
...rip/apollo/adminservice/controller/ReleaseController.java
+8
-5
BaseEntity.java
...src/main/java/com/ctrip/apollo/biz/entity/BaseEntity.java
+1
-0
Item.java
...o-biz/src/main/java/com/ctrip/apollo/biz/entity/Item.java
+10
-0
ItemRepository.java
.../java/com/ctrip/apollo/biz/repository/ItemRepository.java
+1
-1
ReleaseRepository.java
...va/com/ctrip/apollo/biz/repository/ReleaseRepository.java
+1
-1
ItemSetService.java
...ain/java/com/ctrip/apollo/biz/service/ItemSetService.java
+20
-2
ReleaseService.java
...ain/java/com/ctrip/apollo/biz/service/ReleaseService.java
+1
-1
ViewService.java
...c/main/java/com/ctrip/apollo/biz/service/ViewService.java
+1
-1
BeanUtils.java
...z/src/main/java/com/ctrip/apollo/biz/utils/BeanUtils.java
+2
-2
ItemChangeSets.java
...c/main/java/com/ctrip/apollo/core/dto/ItemChangeSets.java
+4
-13
ItemDTO.java
...core/src/main/java/com/ctrip/apollo/core/dto/ItemDTO.java
+13
-1
SimpleRestfulResponse.java
...a/com/ctrip/apollo/core/entity/SimpleRestfulResponse.java
+0
-31
AdminServiceAPI.java
...ain/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
+58
-34
AppController.java
...ava/com/ctrip/apollo/portal/controller/AppController.java
+2
-0
ConfigController.java
.../com/ctrip/apollo/portal/controller/ConfigController.java
+8
-13
NamespaceVO.java
...main/java/com/ctrip/apollo/portal/entity/NamespaceVO.java
+1
-0
SimpleMsg.java
...c/main/java/com/ctrip/apollo/portal/entity/SimpleMsg.java
+2
-12
ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+40
-7
PropertyResolver.java
...p/apollo/portal/service/txtresolver/PropertyResolver.java
+181
-0
SimpleKVCResolver.java
.../apollo/portal/service/txtresolver/SimpleKVCResolver.java
+0
-89
TextResolverResult.java
...apollo/portal/service/txtresolver/TextResolverResult.java
+11
-40
CreateAppController.js
...esources/static/scripts/controller/CreateAppController.js
+1
-1
AppConfigController.js
...rces/static/scripts/controller/app/AppConfigController.js
+47
-17
AppInfoController.js
...ources/static/scripts/controller/app/AppInfoController.js
+0
-12
AppPageController.js
...ources/static/scripts/controller/app/AppPageController.js
+0
-16
EnvService.js
.../src/main/resources/static/scripts/services/EnvService.js
+0
-19
VersionService.js
.../main/resources/static/scripts/services/VersionService.js
+0
-24
app.html
apollo-portal/src/main/resources/static/views/app.html
+60
-34
config.html
...lo-portal/src/main/resources/static/views/app/config.html
+0
-0
info.html
apollo-portal/src/main/resources/static/views/app/info.html
+0
-43
setting.html
...o-portal/src/main/resources/static/views/app/setting.html
+0
-1
No files found.
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemSetController.java
View file @
c99fd43f
...
@@ -3,6 +3,7 @@ package com.ctrip.apollo.adminservice.controller;
...
@@ -3,6 +3,7 @@ package com.ctrip.apollo.adminservice.controller;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
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.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
...
@@ -18,8 +19,9 @@ public class ItemSetController {
...
@@ -18,8 +19,9 @@ public class ItemSetController {
private
ItemSetService
itemSetService
;
private
ItemSetService
itemSetService
;
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
Void
>
create
(
@RequestBody
ItemChangeSets
changeSet
)
{
public
ResponseEntity
<
Void
>
create
(
@PathVariable
String
appId
,
@PathVariable
String
clusterName
,
itemSetService
.
updateSet
(
changeSet
);
@PathVariable
String
namespaceName
,
@RequestBody
ItemChangeSets
changeSet
)
{
itemSetService
.
updateSet
(
appId
,
clusterName
,
namespaceName
,
changeSet
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
build
();
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
build
();
}
}
}
}
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ReleaseController.java
View file @
c99fd43f
...
@@ -47,12 +47,15 @@ public class ReleaseController {
...
@@ -47,12 +47,15 @@ public class ReleaseController {
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/latest"
)
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/latest"
)
public
ReleaseDTO
getLatest
(
@PathVariable
(
"appId"
)
String
appId
,
public
ReleaseDTO
getLatest
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
Release
release
=
configService
.
findRelease
(
appId
,
clusterName
,
namespaceName
);
Release
release
=
configService
.
findRelease
(
appId
,
clusterName
,
namespaceName
);
if
(
release
==
null
)
throw
new
NotFoundException
(
if
(
release
==
null
)
{
String
.
format
(
"latest release not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
));
throw
new
NotFoundException
(
return
BeanUtils
.
transfrom
(
ReleaseDTO
.
class
,
release
);
String
.
format
(
"latest release not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
));
}
else
{
return
BeanUtils
.
transfrom
(
ReleaseDTO
.
class
,
release
);
}
}
}
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases"
,
method
=
RequestMethod
.
POST
)
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/BaseEntity.java
View file @
c99fd43f
...
@@ -97,4 +97,5 @@ public abstract class BaseEntity {
...
@@ -97,4 +97,5 @@ public abstract class BaseEntity {
private
void
preRemove
()
{
private
void
preRemove
()
{
this
.
dataChangeLastModifiedTime
=
new
Date
();
this
.
dataChangeLastModifiedTime
=
new
Date
();
}
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/entity/Item.java
View file @
c99fd43f
...
@@ -23,6 +23,9 @@ public class Item extends BaseEntity {
...
@@ -23,6 +23,9 @@ public class Item extends BaseEntity {
@Column
@Column
private
String
comment
;
private
String
comment
;
@Column
private
int
lineNum
;
public
String
getComment
()
{
public
String
getComment
()
{
return
comment
;
return
comment
;
}
}
...
@@ -55,4 +58,11 @@ public class Item extends BaseEntity {
...
@@ -55,4 +58,11 @@ public class Item extends BaseEntity {
this
.
value
=
value
;
this
.
value
=
value
;
}
}
public
int
getLineNum
()
{
return
lineNum
;
}
public
void
setLineNum
(
int
lineNum
)
{
this
.
lineNum
=
lineNum
;
}
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ItemRepository.java
View file @
c99fd43f
...
@@ -10,6 +10,6 @@ public interface ItemRepository extends PagingAndSortingRepository<Item, Long> {
...
@@ -10,6 +10,6 @@ public interface ItemRepository extends PagingAndSortingRepository<Item, Long> {
List
<
Item
>
findByNamespaceIdIsIn
(
List
<
Long
>
namespaceIds
);
List
<
Item
>
findByNamespaceIdIsIn
(
List
<
Long
>
namespaceIds
);
List
<
Item
>
findByNamespaceId
(
Long
namespaceId
);
List
<
Item
>
findByNamespaceId
OrderByLineNumAsc
(
Long
namespaceId
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/repository/ReleaseRepository.java
View file @
c99fd43f
...
@@ -17,5 +17,5 @@ public interface ReleaseRepository extends PagingAndSortingRepository<Release, L
...
@@ -17,5 +17,5 @@ public interface ReleaseRepository extends PagingAndSortingRepository<Release, L
@Param
(
"namespaceName"
)
String
namespaceName
);
@Param
(
"namespaceName"
)
String
namespaceName
);
List
<
Release
>
findByAppIdAndClusterNameAndNamespaceName
(
String
appId
,
String
clusterName
,
List
<
Release
>
findByAppIdAndClusterNameAndNamespaceName
(
String
appId
,
String
clusterName
,
String
namespaceName
);
String
namespaceName
);
}
}
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ItemSetService.java
View file @
c99fd43f
...
@@ -4,32 +4,50 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -4,32 +4,50 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.biz.repository.ItemRepository
;
import
com.ctrip.apollo.biz.repository.NamespaceRepository
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.biz.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
java.util.Date
;
@Service
@Service
public
class
ItemSetService
{
public
class
ItemSetService
{
@Autowired
@Autowired
private
ItemRepository
itemRepository
;
private
ItemRepository
itemRepository
;
@Autowired
private
NamespaceRepository
namespaceRepository
;
public
void
updateSet
(
ItemChangeSets
changeSet
)
{
public
void
updateSet
(
String
appId
,
String
clusterName
,
String
namespaceName
,
ItemChangeSets
changeSet
)
{
Namespace
namespace
=
namespaceRepository
.
findByAppIdAndClusterNameAndNamespaceName
(
appId
,
clusterName
,
namespaceName
);
String
modifyBy
=
changeSet
.
getModifyBy
();
for
(
ItemDTO
item
:
changeSet
.
getCreateItems
())
{
for
(
ItemDTO
item
:
changeSet
.
getCreateItems
())
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
entity
.
setNamespaceId
(
namespace
.
getId
());
entity
.
setDataChangeCreatedBy
(
modifyBy
);
entity
.
setDataChangeCreatedTime
(
new
Date
());
entity
.
setDataChangeLastModifiedBy
(
modifyBy
);
itemRepository
.
save
(
entity
);
itemRepository
.
save
(
entity
);
}
}
for
(
ItemDTO
item
:
changeSet
.
getUpdateItems
())
{
for
(
ItemDTO
item
:
changeSet
.
getUpdateItems
())
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
Item
managedItem
=
itemRepository
.
findOne
(
entity
.
getId
());
Item
managedItem
=
itemRepository
.
findOne
(
entity
.
getId
());
BeanUtils
.
copyEntityProperties
(
entity
,
managedItem
);
if
(
managedItem
!=
null
){
BeanUtils
.
copyEntityProperties
(
entity
,
managedItem
,
"id"
,
"namespaceId"
,
"key"
,
"dataChangeCreatedBy"
,
"dataChangeCreatedTime"
);
managedItem
.
setDataChangeLastModifiedBy
(
modifyBy
);
}
itemRepository
.
save
(
managedItem
);
itemRepository
.
save
(
managedItem
);
}
}
for
(
ItemDTO
item
:
changeSet
.
getDeletedItems
())
{
for
(
ItemDTO
item
:
changeSet
.
getDeletedItems
())
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
item
);
entity
.
setDataChangeLastModifiedBy
(
modifyBy
);
itemRepository
.
delete
(
entity
.
getId
());
itemRepository
.
delete
(
entity
.
getId
());
}
}
}
}
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ReleaseService.java
View file @
c99fd43f
...
@@ -46,7 +46,7 @@ public class ReleaseService {
...
@@ -46,7 +46,7 @@ public class ReleaseService {
throw
new
NotFoundException
(
String
.
format
(
"Could not find namespace for %s %s %s"
,
appId
,
throw
new
NotFoundException
(
String
.
format
(
"Could not find namespace for %s %s %s"
,
appId
,
clusterName
,
namespaceName
));
clusterName
,
namespaceName
));
}
}
List
<
Item
>
items
=
itemRepository
.
findByNamespaceId
(
namespace
.
getId
());
List
<
Item
>
items
=
itemRepository
.
findByNamespaceId
OrderByLineNumAsc
(
namespace
.
getId
());
Map
<
String
,
String
>
configurations
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
configurations
=
new
HashMap
<
String
,
String
>();
for
(
Item
item
:
items
)
{
for
(
Item
item
:
items
)
{
configurations
.
put
(
item
.
getKey
(),
item
.
getValue
());
configurations
.
put
(
item
.
getKey
(),
item
.
getValue
());
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/service/ViewService.java
View file @
c99fd43f
...
@@ -65,7 +65,7 @@ public class ViewService {
...
@@ -65,7 +65,7 @@ public class ViewService {
}
}
public
List
<
Item
>
findItems
(
Long
namespaceId
)
{
public
List
<
Item
>
findItems
(
Long
namespaceId
)
{
List
<
Item
>
items
=
itemRepository
.
findByNamespaceId
(
namespaceId
);
List
<
Item
>
items
=
itemRepository
.
findByNamespaceId
OrderByLineNumAsc
(
namespaceId
);
if
(
items
==
null
)
{
if
(
items
==
null
)
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
EMPTY_LIST
;
}
}
...
...
apollo-biz/src/main/java/com/ctrip/apollo/biz/utils/BeanUtils.java
View file @
c99fd43f
...
@@ -214,7 +214,7 @@ public class BeanUtils {
...
@@ -214,7 +214,7 @@ public class BeanUtils {
* @param source
* @param source
* @param target
* @param target
*/
*/
public
static
void
copyEntityProperties
(
Object
source
,
Object
target
)
{
public
static
void
copyEntityProperties
(
Object
source
,
Object
target
,
String
...
ignoreProperties
)
{
org
.
springframework
.
beans
.
BeanUtils
.
copyProperties
(
source
,
target
,
"id"
);
org
.
springframework
.
beans
.
BeanUtils
.
copyProperties
(
source
,
target
,
ignoreProperties
);
}
}
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ItemChangeSets.java
View file @
c99fd43f
...
@@ -9,28 +9,19 @@ import java.util.List;
...
@@ -9,28 +9,19 @@ import java.util.List;
public
class
ItemChangeSets
{
public
class
ItemChangeSets
{
private
String
modifyBy
;
private
String
modifyBy
;
private
List
<
ItemDTO
>
createItems
;
private
List
<
ItemDTO
>
createItems
=
new
LinkedList
<>()
;
private
List
<
ItemDTO
>
updateItems
;
private
List
<
ItemDTO
>
updateItems
=
new
LinkedList
<>()
;
private
List
<
ItemDTO
>
deletedItems
;
private
List
<
ItemDTO
>
deletedItems
=
new
LinkedList
<>()
;
public
void
addCreatedItem
(
ItemDTO
item
)
{
public
void
addCreatedItem
(
ItemDTO
item
)
{
if
(
createItems
==
null
)
{
createItems
=
new
LinkedList
<>();
}
createItems
.
add
(
item
);
createItems
.
add
(
item
);
}
}
public
void
addupdateItem
(
ItemDTO
item
)
{
public
void
addUpdateItem
(
ItemDTO
item
)
{
if
(
updateItems
==
null
)
{
updateItems
=
new
LinkedList
<>();
}
updateItems
.
add
(
item
);
updateItems
.
add
(
item
);
}
}
public
void
addDeletedItem
(
ItemDTO
item
)
{
public
void
addDeletedItem
(
ItemDTO
item
)
{
if
(
deletedItems
==
null
)
{
deletedItems
=
new
LinkedList
<>();
}
deletedItems
.
add
(
item
);
deletedItems
.
add
(
item
);
}
}
...
...
apollo-core/src/main/java/com/ctrip/apollo/core/dto/ItemDTO.java
View file @
c99fd43f
...
@@ -2,7 +2,7 @@ package com.ctrip.apollo.core.dto;
...
@@ -2,7 +2,7 @@ package com.ctrip.apollo.core.dto;
import
java.util.Date
;
import
java.util.Date
;
public
class
ItemDTO
{
public
class
ItemDTO
{
private
long
id
;
private
long
id
;
...
@@ -14,6 +14,8 @@ public class ItemDTO {
...
@@ -14,6 +14,8 @@ public class ItemDTO {
private
String
comment
;
private
String
comment
;
private
int
lineNum
;
private
String
dataChangeLastModifiedBy
;
private
String
dataChangeLastModifiedBy
;
private
Date
dataChangeLastModifiedTime
;
private
Date
dataChangeLastModifiedTime
;
...
@@ -67,6 +69,14 @@ public class ItemDTO {
...
@@ -67,6 +69,14 @@ public class ItemDTO {
this
.
value
=
value
;
this
.
value
=
value
;
}
}
public
int
getLineNum
()
{
return
lineNum
;
}
public
void
setLineNum
(
int
lineNum
)
{
this
.
lineNum
=
lineNum
;
}
public
String
getDataChangeLastModifiedBy
()
{
public
String
getDataChangeLastModifiedBy
()
{
return
dataChangeLastModifiedBy
;
return
dataChangeLastModifiedBy
;
}
}
...
@@ -91,8 +101,10 @@ public class ItemDTO {
...
@@ -91,8 +101,10 @@ public class ItemDTO {
", key='"
+
key
+
'\''
+
", key='"
+
key
+
'\''
+
", value='"
+
value
+
'\''
+
", value='"
+
value
+
'\''
+
", comment='"
+
comment
+
'\''
+
", comment='"
+
comment
+
'\''
+
", lineNum="
+
lineNum
+
", dataChangeLastModifiedBy='"
+
dataChangeLastModifiedBy
+
'\''
+
", dataChangeLastModifiedBy='"
+
dataChangeLastModifiedBy
+
'\''
+
", dataChangeLastModifiedTime="
+
dataChangeLastModifiedTime
+
", dataChangeLastModifiedTime="
+
dataChangeLastModifiedTime
+
'}'
;
'}'
;
}
}
}
}
apollo-core/src/main/java/com/ctrip/apollo/core/entity/SimpleRestfulResponse.java
deleted
100644 → 0
View file @
719d67d0
package
com
.
ctrip
.
apollo
.
core
.
entity
;
/**
* declare biz code and simple msg. maybe http response code is 200.
*/
public
class
SimpleRestfulResponse
{
private
int
code
;
private
String
msg
;
public
SimpleRestfulResponse
(
int
code
,
String
msg
){
this
.
code
=
code
;
this
.
msg
=
msg
;
}
public
int
getCode
()
{
return
code
;
}
public
void
setCode
(
int
code
)
{
this
.
code
=
code
;
}
public
String
getMsg
()
{
return
msg
;
}
public
void
setMsg
(
String
msg
)
{
this
.
msg
=
msg
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/AdminServiceAPI.java
View file @
c99fd43f
...
@@ -4,12 +4,17 @@ package com.ctrip.apollo.portal.api;
...
@@ -4,12 +4,17 @@ package com.ctrip.apollo.portal.api;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.dto.AppDTO
;
import
com.ctrip.apollo.core.dto.AppDTO
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.HttpClientErrorException
;
import
org.springframework.web.client.HttpServerErrorException
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
...
@@ -17,6 +22,7 @@ import java.util.List;
...
@@ -17,6 +22,7 @@ import java.util.List;
@Service
@Service
public
class
AdminServiceAPI
{
public
class
AdminServiceAPI
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
AdminServiceAPI
.
class
);
@Service
@Service
public
static
class
AppAPI
extends
API
{
public
static
class
AppAPI
extends
API
{
...
@@ -33,7 +39,7 @@ public class AdminServiceAPI {
...
@@ -33,7 +39,7 @@ public class AdminServiceAPI {
public
static
class
NamespaceAPI
extends
API
{
public
static
class
NamespaceAPI
extends
API
{
public
List
<
NamespaceDTO
>
findGroupsByAppAndCluster
(
String
appId
,
Apollo
.
Env
env
,
public
List
<
NamespaceDTO
>
findGroupsByAppAndCluster
(
String
appId
,
Apollo
.
Env
env
,
String
clusterName
)
{
String
clusterName
)
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
clusterName
))
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
clusterName
))
{
return
null
;
return
null
;
}
}
...
@@ -48,52 +54,70 @@ public class AdminServiceAPI {
...
@@ -48,52 +54,70 @@ public class AdminServiceAPI {
if
(
StringUtils
.
isContainEmpty
(
appId
,
clusterName
,
namespaceName
))
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
clusterName
,
namespaceName
))
{
return
null
;
return
null
;
}
}
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
String
.
format
(
"apps/%s/clusters/%s/namespaces/%s"
,
appId
,
clusterName
,
String
.
format
(
"apps/%s/clusters/%s/namespaces/%s"
,
appId
,
clusterName
,
namespaceName
),
NamespaceDTO
.
class
);
namespaceName
),
NamespaceDTO
.
class
);
}
}
}
}
@Service
@Service
public
static
class
ItemAPI
extends
API
{
public
static
class
ItemAPI
extends
API
{
public
List
<
ItemDTO
>
findItems
(
String
appId
,
Apollo
.
Env
env
,
String
clusterName
,
String
namespace
)
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
clusterName
,
namespace
))
{
return
null
;
}
return
Arrays
.
asList
(
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
String
public
List
<
ItemDTO
>
findItems
(
String
appId
,
Apollo
.
Env
env
,
String
clusterName
,
String
namespace
)
{
.
format
(
"apps/%s/clusters/%s/namespaces/%s/items"
,
appId
,
if
(
StringUtils
.
isContainEmpty
(
appId
,
clusterName
,
namespace
))
{
clusterName
,
namespace
),
return
null
;
ItemDTO
[].
class
));
}
}
return
Arrays
.
asList
(
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
String
.
format
(
"apps/%s/clusters/%s/namespaces/%s/items"
,
appId
,
clusterName
,
namespace
),
ItemDTO
[].
class
));
}
}
@Service
public
void
updateItems
(
String
appId
,
Apollo
.
Env
env
,
String
clusterName
,
String
namespace
,
public
static
class
ClusterAPI
extends
API
{
ItemChangeSets
changeSets
)
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
clusterName
,
namespace
)){
return
;
}
restTemplate
.
postForEntity
(
getAdminServiceHost
(
env
)
+
String
.
format
(
"apps/%s/clusters/%s/namespaces/%s/itemset"
,
appId
,
clusterName
,
namespace
),
changeSets
,
Void
.
class
);
}
}
public
List
<
ClusterDTO
>
findClustersByApp
(
String
appId
,
Apollo
.
Env
env
)
{
@Service
if
(
StringUtils
.
isContainEmpty
(
appId
))
{
public
static
class
ClusterAPI
extends
API
{
return
null
;
}
return
Arrays
.
asList
(
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
String
.
format
(
"apps/%s/clusters"
,
appId
),
public
List
<
ClusterDTO
>
findClustersByApp
(
String
appId
,
Apollo
.
Env
env
)
{
ClusterDTO
[].
class
));
if
(
StringUtils
.
isContainEmpty
(
appId
))
{
return
null
;
}
}
return
Arrays
.
asList
(
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
String
.
format
(
"apps/%s/clusters"
,
appId
),
ClusterDTO
[].
class
));
}
}
}
@Service
@Service
public
static
class
ReleaseAPI
extends
API
{
public
static
class
ReleaseAPI
extends
API
{
public
ReleaseDTO
loadLatestRelease
(
String
appId
,
Apollo
.
Env
env
,
String
clusterName
,
String
namespace
)
{
public
ReleaseDTO
loadLatestRelease
(
String
appId
,
Apollo
.
Env
env
,
String
clusterName
,
String
namespace
)
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
clusterName
,
namespace
))
{
if
(
StringUtils
.
isContainEmpty
(
appId
,
clusterName
,
namespace
))
{
return
null
;
return
null
;
}
}
return
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
String
try
{
.
format
(
"apps/%s/clusters/%s/namespaces/%s/releases/latest"
,
appId
,
ReleaseDTO
releaseDTO
=
restTemplate
.
getForObject
(
getAdminServiceHost
(
env
)
+
String
clusterName
,
namespace
),
ReleaseDTO
.
class
);
.
format
(
"apps/%s/clusters/%s/namespaces/%s/releases/latest"
,
appId
,
clusterName
,
namespace
),
ReleaseDTO
.
class
);
return
releaseDTO
;
}
catch
(
HttpClientErrorException
e
){
logger
.
warn
(
" call [ReleaseAPI.loadLatestRelease] and return not fount exception.app id:{}, env:{}, clusterName:{}, namespace:{}"
,
appId
,
env
,
clusterName
,
namespace
);
return
null
;
}
}
}
}
}
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/AppController.java
View file @
c99fd43f
...
@@ -26,5 +26,7 @@ public class AppController {
...
@@ -26,5 +26,7 @@ public class AppController {
return
appService
.
buildClusterNavTree
(
appId
);
return
appService
.
buildClusterNavTree
(
appId
);
}
}
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
View file @
c99fd43f
...
@@ -2,15 +2,13 @@ package com.ctrip.apollo.portal.controller;
...
@@ -2,15 +2,13 @@ package com.ctrip.apollo.portal.controller;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.entity.SimpleRestfulResponse
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
import
com.ctrip.apollo.portal.entity.NamespaceVO
;
import
com.ctrip.apollo.portal.entity.Simple
Response
;
import
com.ctrip.apollo.portal.entity.Simple
Msg
;
import
com.ctrip.apollo.portal.service.ConfigService
;
import
com.ctrip.apollo.portal.service.ConfigService
;
import
com.ctrip.apollo.portal.service.txtresolver.TextResolverResult
;
import
com.ctrip.apollo.portal.service.txtresolver.TextResolverResult
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
@@ -37,19 +35,16 @@ public class ConfigController {
...
@@ -37,19 +35,16 @@ public class ConfigController {
}
}
@RequestMapping
(
value
=
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/modify"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/modify"
,
method
=
RequestMethod
.
GET
)
public
ResponseEntity
<
Simple
RestfulResponse
>
modifyConfigs
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
public
ResponseEntity
<
Simple
Msg
>
modifyConfigs
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@PathVariable
String
namespaceName
,
String
configText
)
{
String
configText
)
{
TextResolverResult
result
=
TextResolverResult
result
=
configService
.
resolve
(
appId
,
Apollo
.
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
,
configText
);
configService
.
resolve
(
appId
,
Apollo
.
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
,
configText
);
TextResolverResult
.
Code
code
=
result
.
getCode
();
if
(
result
.
isResolveSuccess
())
{
return
ResponseEntity
.
ok
().
body
(
new
SimpleMsg
(
"success"
));
if
(
code
==
TextResolverResult
.
Code
.
OK
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
new
SimpleRestfulResponse
(
code
.
getValue
(),
"success"
));
}
else
{
}
else
{
return
ResponseEntity
.
status
(
HttpStatus
.
OK
)
return
ResponseEntity
.
badRequest
().
body
(
new
SimpleMsg
(
result
.
getMsg
()));
.
body
(
new
SimpleRestfulResponse
(
code
.
getValue
(),
code
.
getBaseMsg
()
+
result
.
getExtensionMsg
()));
}
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/NamespaceVO.java
View file @
c99fd43f
...
@@ -71,6 +71,7 @@ public class NamespaceVO {
...
@@ -71,6 +71,7 @@ public class NamespaceVO {
public
void
setNewValue
(
String
newValue
)
{
public
void
setNewValue
(
String
newValue
)
{
this
.
newValue
=
newValue
;
this
.
newValue
=
newValue
;
}
}
}
}
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/Simple
Response
.java
→
apollo-portal/src/main/java/com/ctrip/apollo/portal/entity/Simple
Msg
.java
View file @
c99fd43f
package
com
.
ctrip
.
apollo
.
portal
.
entity
;
package
com
.
ctrip
.
apollo
.
portal
.
entity
;
public
class
Simple
Response
{
public
class
Simple
Msg
{
private
int
code
;
private
String
msg
;
private
String
msg
;
public
SimpleResponse
(
int
code
,
String
msg
){
public
SimpleMsg
(
String
msg
){
this
.
code
=
code
;
this
.
msg
=
msg
;
this
.
msg
=
msg
;
}
}
public
int
getCode
()
{
return
code
;
}
public
void
setCode
(
int
code
)
{
this
.
code
=
code
;
}
public
String
getMsg
()
{
public
String
getMsg
()
{
return
msg
;
return
msg
;
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
View file @
c99fd43f
...
@@ -50,19 +50,51 @@ public class ConfigService {
...
@@ -50,19 +50,51 @@ public class ConfigService {
List
<
NamespaceVO
>
namespaceVOs
=
new
LinkedList
<>();
List
<
NamespaceVO
>
namespaceVOs
=
new
LinkedList
<>();
for
(
NamespaceDTO
namespace
:
namespaces
)
{
for
(
NamespaceDTO
namespace
:
namespaces
)
{
namespaceVOs
.
add
(
parseNamespace
(
appId
,
env
,
clusterName
,
namespace
));
NamespaceVO
namespaceVO
=
null
;
try
{
namespaceVO
=
parseNamespace
(
appId
,
env
,
clusterName
,
namespace
);
namespaceVOs
.
add
(
namespaceVO
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}"
,
appId
,
env
,
clusterName
,
namespace
.
getNamespaceName
(),
e
);
return
namespaceVOs
;
}
}
}
return
namespaceVOs
;
return
namespaceVOs
;
}
}
public
TextResolverResult
resolve
(
String
appId
,
Apollo
.
Env
env
,
String
clusterName
,
String
namespaceName
,
public
TextResolverResult
resolve
(
String
appId
,
Apollo
.
Env
env
,
String
clusterName
,
String
namespaceName
,
String
configText
)
{
String
configText
)
{
TextResolverResult
result
=
resolver
.
resolve
(
configText
,
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
));
TextResolverResult
result
=
new
TextResolverResult
();
if
(
result
.
getCode
()
==
TextResolverResult
.
Code
.
OK
)
{
try
{
ItemChangeSets
changeSets
=
result
.
getChangeSets
();
result
=
resolver
.
resolve
(
configText
,
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
));
//invoke admin service
}
catch
(
Exception
e
)
{
logger
.
error
(
"resolve config text error. app id:{}, env:{}, clusterName:{}, namespace:{}"
,
appId
,
env
,
clusterName
,
namespaceName
,
e
);
result
.
setResolveSuccess
(
false
);
result
.
setMsg
(
"oops! server resolve config text error."
);
return
result
;
}
}
if
(
result
.
isResolveSuccess
())
{
try
{
// TODO: 16/4/13
result
.
getChangeSets
().
setModifyBy
(
"lepdou"
);
itemAPI
.
updateItems
(
appId
,
env
,
clusterName
,
namespaceName
,
result
.
getChangeSets
());
}
catch
(
Exception
e
)
{
logger
.
error
(
"resolve config text error. app id:{}, env:{}, clusterName:{}, namespace:{}"
,
appId
,
env
,
clusterName
,
namespaceName
,
e
);
result
.
setResolveSuccess
(
false
);
result
.
setMsg
(
"oops! server update config error."
);
return
result
;
}
}
else
{
logger
.
warn
(
"resolve config text error by format error. app id:{}, env:{}, clusterName:{}, namespace:{},cause:{}"
,
appId
,
env
,
clusterName
,
namespaceName
,
result
.
getMsg
());
}
return
result
;
return
result
;
}
}
...
@@ -72,6 +104,7 @@ public class ConfigService {
...
@@ -72,6 +104,7 @@ public class ConfigService {
namespaceVO
.
setNamespace
(
namespace
);
namespaceVO
.
setNamespace
(
namespace
);
List
<
NamespaceVO
.
ItemVO
>
itemVos
=
new
LinkedList
<>();
List
<
NamespaceVO
.
ItemVO
>
itemVos
=
new
LinkedList
<>();
namespaceVO
.
setItems
(
itemVos
);
String
namespaceName
=
namespace
.
getNamespaceName
();
String
namespaceName
=
namespace
.
getNamespaceName
();
...
@@ -84,6 +117,7 @@ public class ConfigService {
...
@@ -84,6 +117,7 @@ public class ConfigService {
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
logger
.
error
(
"parse release json error. appId:{},env:{},clusterName:{},namespace:{}"
,
appId
,
logger
.
error
(
"parse release json error. appId:{},env:{},clusterName:{},namespace:{}"
,
appId
,
env
,
clusterName
,
namespaceName
);
env
,
clusterName
,
namespaceName
);
return
namespaceVO
;
}
}
}
}
...
@@ -101,7 +135,6 @@ public class ConfigService {
...
@@ -101,7 +135,6 @@ public class ConfigService {
itemVos
.
add
(
itemVO
);
itemVos
.
add
(
itemVO
);
}
}
namespaceVO
.
setItemModifiedCnt
(
modifiedItemCnt
);
namespaceVO
.
setItemModifiedCnt
(
modifiedItemCnt
);
namespaceVO
.
setItems
(
itemVos
);
return
namespaceVO
;
return
namespaceVO
;
}
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/txtresolver/PropertyResolver.java
0 → 100644
View file @
c99fd43f
package
com
.
ctrip
.
apollo
.
portal
.
service
.
txtresolver
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.util.BeanUtils
;
import
com.sun.tools.javac.util.Assert
;
import
org.apache.commons.collections.map.HashedMap
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.Map
;
/**
* normal property file resolver.
* update comment and blank item implement by create new item and delete old item.
* update normal key/value item implement by update.
*/
@Component
public
class
PropertyResolver
implements
ConfigTextResolver
{
private
static
final
String
KV_SEPARATOR
=
"="
;
private
static
final
String
ITEM_SEPARATOR
=
"\n"
;
@Override
public
TextResolverResult
resolve
(
String
configText
,
List
<
ItemDTO
>
baseItems
)
{
TextResolverResult
result
=
new
TextResolverResult
();
if
(
StringUtils
.
isEmpty
(
configText
)){
result
.
setResolveSuccess
(
false
);
result
.
setMsg
(
"config text can not be empty"
);
return
result
;
}
Map
<
Integer
,
ItemDTO
>
oldLineNumMapItem
=
BeanUtils
.
mapByKey
(
"lineNum"
,
baseItems
);
Map
<
String
,
ItemDTO
>
oldKeyMapItem
=
BeanUtils
.
mapByKey
(
"key"
,
baseItems
);
//remove comment and blank item map.
oldKeyMapItem
.
remove
(
""
);
String
[]
newItems
=
configText
.
split
(
ITEM_SEPARATOR
);
ItemChangeSets
changeSets
=
new
ItemChangeSets
();
result
.
setChangeSets
(
changeSets
);
Map
<
Integer
,
String
>
newLineNumMapItem
=
new
HashedMap
();
//use for delete blank and comment item
int
lineCounter
=
1
;
for
(
String
newItem
:
newItems
)
{
newItem
=
newItem
.
trim
();
newLineNumMapItem
.
put
(
lineCounter
,
newItem
);
ItemDTO
oldItemByLine
=
oldLineNumMapItem
.
get
(
lineCounter
);
//comment item
if
(
isCommentItem
(
newItem
))
{
handleCommentLine
(
oldItemByLine
,
newItem
,
lineCounter
,
changeSets
);
//blank item
}
else
if
(
isBlankItem
(
newItem
))
{
handleBlankLine
(
oldItemByLine
,
lineCounter
,
changeSets
);
//normal line
}
else
{
if
(!
handleNormalLine
(
oldKeyMapItem
,
newItem
,
lineCounter
,
result
))
{
return
result
;
}
}
lineCounter
++;
}
deleteCommentAndBlankItem
(
oldLineNumMapItem
,
newLineNumMapItem
,
changeSets
);
deleteNormalKVItem
(
oldKeyMapItem
,
changeSets
);
result
.
setResolveSuccess
(
true
);
return
result
;
}
private
void
handleCommentLine
(
ItemDTO
oldItemByLine
,
String
newItem
,
int
lineCounter
,
ItemChangeSets
changeSets
)
{
String
oldComment
=
oldItemByLine
==
null
?
""
:
oldItemByLine
.
getComment
();
//create comment. implement update comment by delete old comment and create new comment
if
(!(
isCommentItem
(
oldItemByLine
)
&&
newItem
.
equals
(
oldComment
)))
{
changeSets
.
addCreatedItem
(
buildCommentItem
(
0
l
,
newItem
,
lineCounter
));
}
}
private
void
handleBlankLine
(
ItemDTO
oldItem
,
int
lineCounter
,
ItemChangeSets
changeSets
)
{
if
(!
isBlankItem
(
oldItem
))
{
changeSets
.
addCreatedItem
(
buildBlankItem
(
0
l
,
lineCounter
));
}
}
private
boolean
handleNormalLine
(
Map
<
String
,
ItemDTO
>
keyMapOldItem
,
String
newItem
,
int
lineCounter
,
TextResolverResult
result
)
{
ItemChangeSets
changeSets
=
result
.
getChangeSets
();
int
kvSeparator
=
newItem
.
indexOf
(
KV_SEPARATOR
);
if
(
kvSeparator
==
-
1
)
{
result
.
setResolveSuccess
(
false
);
result
.
setMsg
(
" line:"
+
lineCounter
+
" key value must separate by '='"
);
return
false
;
}
String
newKey
=
newItem
.
substring
(
0
,
kvSeparator
).
trim
();
String
newValue
=
newItem
.
substring
(
kvSeparator
+
1
,
newItem
.
length
()).
trim
();
ItemDTO
oldItem
=
keyMapOldItem
.
get
(
newKey
);
if
(
oldItem
==
null
)
{
//new item
changeSets
.
addCreatedItem
(
buildNormalItem
(
0
l
,
newKey
,
newValue
,
""
,
lineCounter
));
}
else
if
(!
newValue
.
equals
(
oldItem
.
getValue
())){
//update item
changeSets
.
addUpdateItem
(
buildNormalItem
(
oldItem
.
getId
(),
newKey
,
newValue
,
oldItem
.
getComment
(),
lineCounter
));
}
keyMapOldItem
.
remove
(
newKey
);
return
true
;
}
private
boolean
isCommentItem
(
ItemDTO
item
)
{
return
item
!=
null
&&
""
.
equals
(
item
.
getKey
())
&&
item
.
getComment
().
startsWith
(
"#"
);
}
private
boolean
isCommentItem
(
String
line
)
{
return
line
!=
null
&&
line
.
startsWith
(
"#"
);
}
private
boolean
isBlankItem
(
ItemDTO
item
)
{
return
item
!=
null
&&
""
.
equals
(
item
.
getKey
())
&&
""
.
equals
(
item
.
getComment
());
}
private
boolean
isBlankItem
(
String
line
)
{
return
""
.
equals
(
line
);
}
private
void
deleteNormalKVItem
(
Map
<
String
,
ItemDTO
>
baseKeyMapItem
,
ItemChangeSets
changeSets
)
{
//surplus item is to be deleted
for
(
Map
.
Entry
<
String
,
ItemDTO
>
entry
:
baseKeyMapItem
.
entrySet
())
{
changeSets
.
addDeletedItem
(
entry
.
getValue
());
}
}
private
void
deleteCommentAndBlankItem
(
Map
<
Integer
,
ItemDTO
>
oldLineNumMapItem
,
Map
<
Integer
,
String
>
newLineNumMapItem
,
ItemChangeSets
changeSets
)
{
for
(
Map
.
Entry
<
Integer
,
ItemDTO
>
entry
:
oldLineNumMapItem
.
entrySet
())
{
int
lineNum
=
entry
.
getKey
();
ItemDTO
oldItem
=
entry
.
getValue
();
String
newItem
=
newLineNumMapItem
.
get
(
lineNum
);
//1. old is blank by now is not
//2.old is comment by now is not exist or modified
if
((
isBlankItem
(
oldItem
)
&&
!
isBlankItem
(
newItem
))
||
isCommentItem
(
oldItem
)
&&
(
newItem
==
null
||
!
newItem
.
equals
(
oldItem
)))
{
changeSets
.
addDeletedItem
(
oldItem
);
}
}
}
private
ItemDTO
buildCommentItem
(
Long
id
,
String
comment
,
int
lineNum
)
{
return
buildNormalItem
(
id
,
""
,
""
,
comment
,
lineNum
);
}
private
ItemDTO
buildBlankItem
(
Long
id
,
int
lineNum
)
{
return
buildNormalItem
(
id
,
""
,
""
,
""
,
lineNum
);
}
private
ItemDTO
buildNormalItem
(
Long
id
,
String
key
,
String
value
,
String
comment
,
int
lineNum
)
{
ItemDTO
item
=
new
ItemDTO
();
item
.
setId
(
id
);
item
.
setKey
(
key
);
item
.
setValue
(
value
);
item
.
setComment
(
comment
);
item
.
setLineNum
(
lineNum
);
return
item
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/txtresolver/SimpleKVCResolver.java
deleted
100644 → 0
View file @
719d67d0
package
com
.
ctrip
.
apollo
.
portal
.
service
.
txtresolver
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.utils.StringUtils
;
import
com.ctrip.apollo.portal.util.BeanUtils
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.Map
;
/**
* config item format is K:V##C
*
* @Autor lepdou
*/
@Component
public
class
SimpleKVCResolver
implements
ConfigTextResolver
{
private
static
final
String
KV_SEPARATOR
=
":"
;
private
static
final
String
VC_SEPARATOR
=
"##"
;
private
static
final
String
ITEM_SEPARATOR
=
"\n"
;
@Override
public
TextResolverResult
resolve
(
String
configText
,
List
<
ItemDTO
>
baseItems
)
{
TextResolverResult
result
=
new
TextResolverResult
();
if
(
StringUtils
.
isEmpty
(
configText
))
{
result
.
setCode
(
TextResolverResult
.
Code
.
SIMPLE_KVC_TEXT_EMPTY
);
return
result
;
}
Map
<
String
,
ItemDTO
>
baseKeyMapItem
=
BeanUtils
.
mapByKey
(
"key"
,
baseItems
);
String
[]
items
=
configText
.
split
(
ITEM_SEPARATOR
);
ItemChangeSets
changeSets
=
new
ItemChangeSets
();
int
lineCounter
=
1
;
int
kvSeparator
,
vcSeparator
;
String
key
,
value
,
comment
;
for
(
String
item
:
items
)
{
kvSeparator
=
item
.
indexOf
(
KV_SEPARATOR
);
vcSeparator
=
item
.
indexOf
(
VC_SEPARATOR
);
if
(
kvSeparator
==
-
1
||
vcSeparator
==
-
1
)
{
result
.
setCode
(
TextResolverResult
.
Code
.
SIMPLTE_KVC_INVALID_FORMAT
);
result
.
setExtensionMsg
(
" line:"
+
lineCounter
);
return
result
;
}
key
=
item
.
substring
(
0
,
kvSeparator
).
trim
();
value
=
item
.
substring
(
kvSeparator
+
1
,
vcSeparator
).
trim
();
comment
=
item
.
substring
(
vcSeparator
+
2
,
item
.
length
()).
trim
();
ItemDTO
baseItem
=
baseKeyMapItem
.
get
(
key
);
if
(
baseItem
==
null
)
{
//new item
changeSets
.
addCreatedItem
(
buildItem
(
key
,
value
,
comment
));
}
else
if
(!
value
.
equals
(
baseItem
.
getValue
())
||
!
comment
.
equals
(
baseItem
.
getComment
()))
{
//update item
changeSets
.
addupdateItem
(
buildItem
(
key
,
value
,
comment
));
}
//deleted items:items in baseItems but not in configText
baseKeyMapItem
.
remove
(
key
);
lineCounter
++;
}
//deleted items
for
(
Map
.
Entry
<
String
,
ItemDTO
>
entry
:
baseKeyMapItem
.
entrySet
())
{
changeSets
.
addDeletedItem
(
entry
.
getValue
());
}
result
.
setCode
(
TextResolverResult
.
Code
.
OK
);
result
.
setChangeSets
(
changeSets
);
return
result
;
}
private
ItemDTO
buildItem
(
String
key
,
String
value
,
String
comment
)
{
ItemDTO
item
=
new
ItemDTO
();
item
.
setKey
(
key
);
item
.
setValue
(
value
);
item
.
setComment
(
comment
);
return
item
;
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/txtresolver/TextResolverResult.java
View file @
c99fd43f
...
@@ -4,28 +4,27 @@ import com.ctrip.apollo.core.dto.ItemChangeSets;
...
@@ -4,28 +4,27 @@ import com.ctrip.apollo.core.dto.ItemChangeSets;
public
class
TextResolverResult
{
public
class
TextResolverResult
{
private
Code
code
;
private
boolean
isResolveSuccess
;
/**
/**
* e
xtension msg. for example line number.
* e
rror msg
*/
*/
private
String
extensionM
sg
=
""
;
private
String
m
sg
=
""
;
private
ItemChangeSets
changeSets
;
private
ItemChangeSets
changeSets
;
public
boolean
isResolveSuccess
()
{
public
Code
getCode
()
{
return
isResolveSuccess
;
return
code
;
}
}
public
void
set
Code
(
Code
code
)
{
public
void
set
ResolveSuccess
(
boolean
resolveSuccess
)
{
this
.
code
=
code
;
isResolveSuccess
=
resolveSuccess
;
}
}
public
String
get
Extension
Msg
()
{
public
String
getMsg
()
{
return
extensionM
sg
;
return
m
sg
;
}
}
public
void
set
ExtensionMsg
(
String
extensionM
sg
)
{
public
void
set
Msg
(
String
m
sg
)
{
this
.
extensionMsg
=
extensionM
sg
;
this
.
msg
=
m
sg
;
}
}
public
ItemChangeSets
getChangeSets
()
{
public
ItemChangeSets
getChangeSets
()
{
...
@@ -36,32 +35,4 @@ public class TextResolverResult {
...
@@ -36,32 +35,4 @@ public class TextResolverResult {
this
.
changeSets
=
changeSets
;
this
.
changeSets
=
changeSets
;
}
}
public
enum
Code
{
OK
(
200
,
"success"
),
SIMPLTE_KVC_INVALID_FORMAT
(
40001
,
"item pattern must key:value##comment.pelease check!"
),
SIMPLE_KVC_TEXT_EMPTY
(
40002
,
"config text empty"
);
private
int
value
;
private
String
baseMsg
;
Code
(
int
value
,
String
msg
)
{
this
.
value
=
value
;
this
.
baseMsg
=
msg
;
}
public
int
getValue
()
{
return
value
;
}
public
void
setValue
(
int
value
)
{
this
.
value
=
value
;
}
public
String
getBaseMsg
()
{
return
baseMsg
;
}
public
void
setBaseMsg
(
String
baseMsg
)
{
this
.
baseMsg
=
baseMsg
;
}
}
}
}
apollo-portal/src/main/resources/static/scripts/controller/CreateAppController.js
View file @
c99fd43f
...
@@ -14,7 +14,7 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
...
@@ -14,7 +14,7 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
AppService
.
add
(
$scope
.
app
).
then
(
function
(
result
)
{
AppService
.
add
(
$scope
.
app
).
then
(
function
(
result
)
{
toastr
.
success
(
'添加成功!'
);
toastr
.
success
(
'添加成功!'
);
setInterval
(
function
()
{
setInterval
(
function
()
{
$window
.
location
.
href
=
'/views/app
/index
.html?#appid='
+
result
.
appId
;
$window
.
location
.
href
=
'/views/app.html?#appid='
+
result
.
appId
;
},
1000
);
},
1000
);
},
function
(
result
)
{
},
function
(
result
)
{
toastr
.
error
(
'添加失败!'
);
toastr
.
error
(
'添加失败!'
);
...
...
apollo-portal/src/main/resources/static/scripts/controller/app/AppConfigController.js
View file @
c99fd43f
...
@@ -2,11 +2,18 @@ application_module.controller("AppConfigController",
...
@@ -2,11 +2,18 @@ application_module.controller("AppConfigController",
[
'$scope'
,
'$location'
,
'toastr'
,
'AppService'
,
'ConfigService'
,
[
'$scope'
,
'$location'
,
'toastr'
,
'AppService'
,
'ConfigService'
,
function
(
$scope
,
$location
,
toastr
,
AppService
,
ConfigService
)
{
function
(
$scope
,
$location
,
toastr
,
AppService
,
ConfigService
)
{
$scope
.
appId
=
$location
.
$$url
.
split
(
"="
)[
1
];
var
appId
=
$location
.
$$url
.
split
(
"="
)[
1
];
var
pageContext
=
{
appId
:
appId
,
env
:
'LOCAL'
,
clusterName
:
'default'
};
$scope
.
pageEnv
=
pageContext
;
/////////////
/////////////
AppService
.
load_nav_tree
(
$scope
.
appId
).
then
(
function
(
result
)
{
AppService
.
load_nav_tree
(
$scope
.
pageEnv
.
appId
).
then
(
function
(
result
)
{
var
navTree
=
[];
var
navTree
=
[];
var
nodes
=
result
.
nodes
;
var
nodes
=
result
.
nodes
;
nodes
.
forEach
(
function
(
item
)
{
nodes
.
forEach
(
function
(
item
)
{
...
@@ -37,9 +44,8 @@ application_module.controller("AppConfigController",
...
@@ -37,9 +44,8 @@ application_module.controller("AppConfigController",
///////////
///////////
$scope
.
env
=
'LOCAL'
;
ConfigService
.
load_all_namespaces
(
$scope
.
pageEnv
.
appId
,
$scope
.
pageEnv
.
env
,
$scope
.
clusterName
=
'default'
;
$scope
.
pageEnv
.
clusterName
).
then
(
ConfigService
.
load_all_namespaces
(
$scope
.
appId
,
$scope
.
env
,
$scope
.
clusterName
).
then
(
function
(
result
)
{
function
(
result
)
{
$scope
.
namespaces
=
result
;
$scope
.
namespaces
=
result
;
...
@@ -48,30 +54,49 @@ application_module.controller("AppConfigController",
...
@@ -48,30 +54,49 @@ application_module.controller("AppConfigController",
$scope
.
namespaces
.
forEach
(
function
(
item
)
{
$scope
.
namespaces
.
forEach
(
function
(
item
)
{
item
.
isModify
=
false
;
item
.
isModify
=
false
;
item
.
viewType
=
'table'
;
item
.
viewType
=
'table'
;
item
.
isTextEditing
=
false
;
})
})
}
}
},
function
(
result
)
{
},
function
(
result
)
{
toastr
.
error
(
"加载配置信息出错
:"
+
result
);
toastr
.
error
(
"加载配置信息出错
"
);
});
});
$scope
.
draft
=
{};
//保存草稿
$scope
.
saveDraft
=
function
(
namespace
)
{
$scope
.
draft
=
namespace
;
};
//更新配置
//更新配置
$scope
.
modifyItems
=
function
(
namespace
)
{
$scope
.
commitChange
=
function
(
)
{
ConfigService
.
modify_items
(
$scope
.
appId
,
$scope
.
env
,
$scope
.
clusterName
,
ConfigService
.
modify_items
(
$scope
.
pageEnv
.
appId
,
$scope
.
pageEnv
.
env
,
$scope
.
pageEnv
.
clusterName
,
namespace
.
namespace
.
namespaceName
,
namespace
.
text
).
then
(
$scope
.
draft
.
namespace
.
namespaceName
,
$scope
.
draft
.
text
).
then
(
function
(
result
)
{
function
(
result
)
{
if
(
result
.
code
==
200
){
toastr
.
success
(
"更新成功"
);
toastr
.
success
(
"更新成功"
);
$scope
.
draft
.
backupText
=
''
;
//清空备份文本
}
else
{
$scope
.
toggleTextEditStatus
(
$scope
.
draft
);
toastr
.
error
(
"更新失败. code:"
+
result
.
code
+
" msg:"
+
result
.
msg
);
},
function
(
result
)
{
}
toastr
.
error
(
result
.
data
.
msg
,
"更新失败"
);
},
function
(
result
)
{
}
}
);
);
};
};
/////////
/////////
//文本编辑框状态切换
$scope
.
toggleTextEditStatus
=
function
(
namespace
)
{
namespace
.
isTextEditing
=
!
namespace
.
isTextEditing
;
if
(
namespace
.
isTextEditing
){
//切换为编辑状态,保存一下原来值
$scope
.
draft
.
backupText
=
namespace
.
text
;
}
else
{
if
(
$scope
.
draft
.
backupText
){
//取消编辑,则复原
namespace
.
text
=
$scope
.
draft
.
backupText
;
}
}
};
$scope
.
queryOldValue
=
function
(
key
,
oldValue
)
{
$scope
.
queryOldValue
=
function
(
key
,
oldValue
)
{
$scope
.
queryKey
=
key
;
$scope
.
queryKey
=
key
;
if
(
oldValue
==
''
)
{
if
(
oldValue
==
''
)
{
...
@@ -101,8 +126,13 @@ application_module.controller("AppConfigController",
...
@@ -101,8 +126,13 @@ application_module.controller("AppConfigController",
// if (item.modified) {
// if (item.modified) {
// result += "**";
// result += "**";
// }
// }
result
+=
if
(
item
.
item
.
key
)
{
item
.
item
.
key
+
":"
+
item
.
item
.
value
+
" ##"
+
item
.
item
.
comment
+
"
\
n"
;
result
+=
item
.
item
.
key
+
" = "
+
item
.
item
.
value
+
"
\
n"
;
}
else
{
result
+=
item
.
item
.
comment
+
"
\
n"
;
}
});
});
return
result
;
return
result
;
...
...
apollo-portal/src/main/resources/static/scripts/controller/app/AppInfoController.js
deleted
100644 → 0
View file @
719d67d0
application_module
.
controller
(
"AppInfoController"
,
[
"$scope"
,
'$rootScope'
,
'$state'
,
'$location'
,
'toastr'
,
'AppService'
,
function
(
$scope
,
$rootScope
,
$state
,
$location
,
toastr
,
AppService
)
{
$rootScope
.
breadcrumb
.
nav
=
'应用信息'
;
$rootScope
.
breadcrumb
.
env
=
''
;
AppService
.
load
(
$scope
.
appId
).
then
(
function
(
result
)
{
$scope
.
app
=
result
;
},
function
(
result
)
{
toastr
.
error
(
"加载出错"
);
});
}]);
apollo-portal/src/main/resources/static/scripts/controller/app/AppPageController.js
deleted
100644 → 0
View file @
719d67d0
//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/EnvService.js
deleted
100644 → 0
View file @
719d67d0
appService
.
service
(
'EnvService'
,
[
'$resource'
,
'$q'
,
function
(
$resource
,
$q
)
{
var
env_resource
=
$resource
(
'/envs'
,
{},
{
all
:
{
method
:
'GET'
,
isArray
:
true
}
});
return
{
getAllEnvs
:
function
getAllEnvs
()
{
var
d
=
$q
.
defer
();
env_resource
.
all
({},
function
(
result
)
{
d
.
resolve
(
result
);
},
function
(
result
)
{
d
.
reject
(
result
);
});
return
d
.
promise
;
}
}
}]);
apollo-portal/src/main/resources/static/scripts/services/VersionService.js
deleted
100644 → 0
View file @
719d67d0
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/views/app
/index
.html
→
apollo-portal/src/main/resources/static/views/app.html
View file @
c99fd43f
This diff is collapsed.
Click to expand it.
apollo-portal/src/main/resources/static/views/app/config.html
deleted
100644 → 0
View file @
719d67d0
This diff is collapsed.
Click to expand it.
apollo-portal/src/main/resources/static/views/app/info.html
deleted
100644 → 0
View file @
719d67d0
<div
class=
"row"
>
<div
class=
"col-md-8 col-md-offset-2"
>
<div
class=
"panel"
>
<div
class=
"panel-body"
>
<form
class=
"form-horizontal"
>
<div
class=
"form-group"
>
<label
class=
"col-sm-2 control-label"
>
应用ID:
</label>
<label
class=
"col-sm-3 control-label text-left"
>
{{app.appId}}
</label>
</div>
<div
class=
"form-group"
>
<label
class=
"col-sm-2 control-label"
>
应用名称:
</label>
<label
class=
"col-sm-3 control-label text-left"
>
{{app.name}}
</label>
</div>
<div
class=
"form-group"
>
<label
class=
"col-sm-2 control-label"
>
Owner:
</label>
<label
class=
"col-sm-3 control-label text-left"
>
{{app.owner}}
</label>
</div>
<div
class=
"form-group"
>
<label
class=
"col-sm-2 control-label"
>
手机号:
</label>
<label
class=
"col-sm-3 control-label text-left"
>
{{app.ownerPhone}}
</label>
</div>
<div
class=
"form-group"
>
<label
class=
"col-sm-2 control-label"
>
邮箱地址:
</label>
<label
class=
"col-sm-3 control-label text-left"
>
{{app.ownerMail}}
</label>
</div>
</form>
</div>
</div>
</div>
</div>
apollo-portal/src/main/resources/static/views/app/setting.html
deleted
100644 → 0
View file @
719d67d0
app setting
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