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
05fb4738
Commit
05fb4738
authored
Jul 08, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update item call new api
parent
66ca68f3
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
32 additions
and
18 deletions
+32
-18
AdminServiceAPI.java
...om/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
+8
-2
ConfigController.java
.../framework/apollo/portal/controller/ConfigController.java
+3
-3
NamespaceController.java
...amework/apollo/portal/controller/NamespaceController.java
+1
-1
ServerConfigController.java
...work/apollo/portal/controller/ServerConfigController.java
+1
-1
ConfigService.java
.../ctrip/framework/apollo/portal/service/ConfigService.java
+15
-7
RoleInitializationService.java
...work/apollo/portal/service/RoleInitializationService.java
+2
-2
PropertyResolver.java
...k/apollo/portal/service/txtresolver/PropertyResolver.java
+2
-2
No files found.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
View file @
05fb4738
...
...
@@ -101,13 +101,19 @@ public class AdminServiceAPI {
return
Arrays
.
asList
(
itemDTOs
);
}
public
void
updateItems
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
public
void
updateItems
ByChangeSet
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
ItemChangeSets
changeSets
)
{
restTemplate
.
postForEntity
(
"{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset"
,
changeSets
,
Void
.
class
,
getAdminServiceHost
(
env
),
appId
,
clusterName
,
namespace
);
}
public
ItemDTO
createOrUpdateItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
ItemDTO
item
)
{
public
void
updateItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
ItemDTO
item
)
{
restTemplate
.
put
(
"{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
item
,
getAdminServiceHost
(
env
),
appId
,
clusterName
,
namespace
);
}
public
ItemDTO
createItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
ItemDTO
item
)
{
return
restTemplate
.
postForEntity
(
"{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
item
,
ItemDTO
.
class
,
getAdminServiceHost
(
env
),
appId
,
clusterName
,
namespace
)
.
getBody
();
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigController.java
View file @
05fb4738
...
...
@@ -61,17 +61,17 @@ public class ConfigController {
@RequestBody
ItemDTO
item
){
checkModel
(
isValidItem
(
item
));
return
configService
.
create
OrUpdate
Item
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
,
item
);
return
configService
.
createItem
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
,
item
);
}
@PreAuthorize
(
value
=
"@permissionValidator.hasModifyNamespacePermission(#appId, #namespaceName)"
)
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/item"
,
method
=
RequestMethod
.
PUT
)
public
ItemDTO
updateItem
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
public
void
updateItem
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
ItemDTO
item
){
checkModel
(
isValidItem
(
item
));
return
configService
.
createOrU
pdateItem
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
,
item
);
configService
.
u
pdateItem
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
,
item
);
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java
View file @
05fb4738
...
...
@@ -72,7 +72,7 @@ public class NamespaceController {
// TODO: 16/6/17 某些环境创建失败,统一处理这种场景
namespaceService
.
createNamespace
(
Env
.
valueOf
(
model
.
getEnv
()),
namespace
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"create namespace error."
,
e
);
logger
.
error
(
"create
Item
namespace error."
,
e
);
}
}
return
ResponseEntity
.
ok
().
build
();
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ServerConfigController.java
View file @
05fb4738
...
...
@@ -36,7 +36,7 @@ public class ServerConfigController {
ServerConfig
storedConfig
=
serverConfigRepository
.
findByKey
(
serverConfig
.
getKey
());
if
(
storedConfig
==
null
)
{
//create
if
(
storedConfig
==
null
)
{
//create
Item
serverConfig
.
setDataChangeCreatedBy
(
modifiedBy
);
serverConfig
.
setDataChangeLastModifiedBy
(
modifiedBy
);
return
serverConfigRepository
.
save
(
serverConfig
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigService.java
View file @
05fb4738
...
...
@@ -68,7 +68,9 @@ public class ConfigService {
long
namespaceId
=
model
.
getNamespaceId
();
String
configText
=
model
.
getConfigText
();
ConfigTextResolver
resolver
=
model
.
getFormat
()
==
ConfigFileFormat
.
Properties
?
propertyResolver
:
fileTextResolver
;
ConfigTextResolver
resolver
=
model
.
getFormat
()
==
ConfigFileFormat
.
Properties
?
propertyResolver
:
fileTextResolver
;
ItemChangeSets
changeSets
=
resolver
.
resolve
(
namespaceId
,
configText
,
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
));
if
(
changeSets
.
isEmpty
())
{
...
...
@@ -76,23 +78,29 @@ public class ConfigService {
}
changeSets
.
setDataChangeLastModifiedBy
(
userInfoHolder
.
getUser
().
getUserId
());
itemAPI
.
updateItems
(
appId
,
env
,
clusterName
,
namespaceName
,
changeSets
);
itemAPI
.
updateItems
ByChangeSet
(
appId
,
env
,
clusterName
,
namespaceName
,
changeSets
);
}
public
ItemDTO
create
OrUpdate
Item
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
ItemDTO
item
)
{
public
ItemDTO
createItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
ItemDTO
item
)
{
NamespaceDTO
namespace
=
namespaceAPI
.
loadNamespace
(
appId
,
env
,
clusterName
,
namespaceName
);
if
(
namespace
==
null
)
{
throw
new
BadRequestException
(
"namespace:"
+
namespaceName
+
" not exist in env:"
+
env
+
", cluster:"
+
clusterName
);
}
item
.
setNamespaceId
(
namespace
.
getId
());
String
username
=
userInfoHolder
.
getUser
().
getUserId
();
if
(
StringUtils
.
isEmpty
(
item
.
getDataChangeCreatedBy
()))
{
item
.
setDataChangeCreatedBy
(
username
);
item
.
setDataChangeLastModifiedBy
(
username
);
return
itemAPI
.
createItem
(
appId
,
env
,
clusterName
,
namespaceName
,
item
);
}
public
void
updateItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
ItemDTO
item
)
{
String
username
=
userInfoHolder
.
getUser
().
getUserId
();
item
.
setDataChangeLastModifiedBy
(
username
);
item
.
setNamespaceId
(
namespace
.
getId
());
return
itemAPI
.
createOrUpdateItem
(
appId
,
env
,
clusterName
,
namespaceName
,
item
);
itemAPI
.
updateItem
(
appId
,
env
,
clusterName
,
namespaceName
,
item
);
}
public
void
deleteItem
(
Env
env
,
long
itemId
)
{
...
...
@@ -120,7 +128,7 @@ public class ConfigService {
changeSets
.
setDataChangeLastModifiedBy
(
userInfoHolder
.
getUser
().
getUserId
());
try
{
itemAPI
.
updateItems
(
namespaceIdentifer
.
getAppId
(),
namespaceIdentifer
.
getEnv
(),
.
updateItems
ByChangeSet
(
namespaceIdentifer
.
getAppId
(),
namespaceIdentifer
.
getEnv
(),
namespaceIdentifer
.
getClusterName
(),
namespaceIdentifer
.
getNamespaceName
(),
changeSets
);
}
catch
(
HttpClientErrorException
e
)
{
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RoleInitializationService.java
View file @
05fb4738
...
...
@@ -37,7 +37,7 @@ public class RoleInitializationService {
return
;
}
String
operaterUserId
=
userInfoHolder
.
getUser
().
getUserId
();
//create app permissions
//create
Item
app permissions
createAppMasterRole
(
appId
);
//assign master role to user
...
...
@@ -75,7 +75,7 @@ public class RoleInitializationService {
appPermissionIds
=
FluentIterable
.
from
(
createdAppPermissions
).
transform
(
permission
->
permission
.
getId
()).
toSet
();
//create app master role
//create
Item
app master role
Role
appMasterRole
=
createRole
(
RoleUtils
.
buildAppMasterRoleName
(
appId
));
rolePermissionService
.
createRoleWithPermissions
(
appMasterRole
,
appPermissionIds
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/txtresolver/PropertyResolver.java
View file @
05fb4738
...
...
@@ -15,7 +15,7 @@ import java.util.Set;
/**
* normal property file resolver.
* update comment and blank item implement by create new item and delete old item.
* update comment and blank item implement by create
Item
new item and delete old item.
* update normal key/value item implement by update.
*/
@Component
(
"propertyResolver"
)
...
...
@@ -105,7 +105,7 @@ public class PropertyResolver implements ConfigTextResolver {
private
void
handleCommentLine
(
Long
namespaceId
,
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
//create
Item comment. implement update comment by delete old comment and createItem
new comment
if
(!(
isCommentItem
(
oldItemByLine
)
&&
newItem
.
equals
(
oldComment
)))
{
changeSets
.
addCreateItem
(
buildCommentItem
(
0
l
,
namespaceId
,
newItem
,
lineCounter
));
}
...
...
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