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
f6071f4f
Commit
f6071f4f
authored
Jul 08, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:ctripcorp/apollo
parents
7e1355d1
29f2ad94
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
45 additions
and
22 deletions
+45
-22
AppNamespaceController.java
...pollo/adminservice/controller/AppNamespaceController.java
+7
-1
ItemController.java
...mework/apollo/adminservice/controller/ItemController.java
+5
-3
AppNamespaceService.java
...rip/framework/apollo/biz/service/AppNamespaceService.java
+2
-1
AdminServiceAPI.java
...om/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
+9
-3
ConfigController.java
.../framework/apollo/portal/controller/ConfigController.java
+3
-3
ConfigService.java
.../ctrip/framework/apollo/portal/service/ConfigService.java
+19
-11
No files found.
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/AppNamespaceController.java
View file @
f6071f4f
...
...
@@ -11,7 +11,9 @@ import com.ctrip.framework.apollo.common.entity.AppNamespace;
import
com.ctrip.framework.apollo.biz.service.AppNamespaceService
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.core.dto.AppNamespaceDTO
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
import
java.util.List
;
...
...
@@ -31,7 +33,11 @@ public class AppNamespaceController {
throw
new
BadRequestException
(
"app namespaces already exist."
);
}
entity
=
appNamespaceService
.
createAppNamespace
(
entity
,
entity
.
getDataChangeCreatedBy
());
if
(
StringUtils
.
isEmpty
(
appNamespace
.
getFormat
())){
appNamespace
.
setFormat
(
ConfigFileFormat
.
Properties
.
getValue
());
}
entity
=
appNamespaceService
.
createAppNamespace
(
entity
);
return
BeanUtils
.
transfrom
(
AppNamespaceDTO
.
class
,
entity
);
...
...
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ItemController.java
View file @
f6071f4f
...
...
@@ -74,16 +74,18 @@ public class ItemController {
}
@PreAcquireNamespaceLock
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
method
=
RequestMethod
.
PUT
)
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items
/{itemId}
"
,
method
=
RequestMethod
.
PUT
)
public
ItemDTO
update
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
,
@RequestBody
ItemDTO
itemDTO
)
{
@PathVariable
(
"namespaceName"
)
String
namespaceName
,
@PathVariable
(
"itemId"
)
long
itemId
,
@RequestBody
ItemDTO
itemDTO
)
{
Item
entity
=
BeanUtils
.
transfrom
(
Item
.
class
,
itemDTO
);
ConfigChangeContentBuilder
builder
=
new
ConfigChangeContentBuilder
();
Item
managedEntity
=
itemService
.
findOne
(
appId
,
clusterName
,
namespaceName
,
entity
.
getKey
()
);
Item
managedEntity
=
itemService
.
findOne
(
itemId
);
if
(
managedEntity
==
null
)
{
throw
new
BadRequestException
(
"item not exist"
);
}
...
...
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/AppNamespaceService.java
View file @
f6071f4f
...
...
@@ -71,7 +71,8 @@ public class AppNamespaceService {
}
@Transactional
public
AppNamespace
createAppNamespace
(
AppNamespace
appNamespace
,
String
createBy
){
public
AppNamespace
createAppNamespace
(
AppNamespace
appNamespace
){
String
createBy
=
appNamespace
.
getDataChangeCreatedBy
();
if
(!
isAppNamespaceNameUnique
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
()))
{
throw
new
ServiceException
(
"appnamespace not unique"
);
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
View file @
f6071f4f
...
...
@@ -101,13 +101,19 @@ public class AdminServiceAPI {
return
Arrays
.
asList
(
itemDTOs
);
}
public
void
updateItems
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
ItemChangeSets
changeSets
)
{
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
,
long
itemId
,
ItemDTO
item
)
{
restTemplate
.
put
(
"{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{itemId}"
,
item
,
getAdminServiceHost
(
env
),
appId
,
clusterName
,
namespace
,
itemId
);
}
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 @
f6071f4f
...
...
@@ -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/service/ConfigService.java
View file @
f6071f4f
...
...
@@ -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
.
setDataChangeCreatedBy
(
username
);
item
.
setDataChangeLastModifiedBy
(
username
);
item
.
setNamespaceId
(
namespace
.
getId
());
return
itemAPI
.
createOrUpdateItem
(
appId
,
env
,
clusterName
,
namespaceName
,
item
);
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
);
itemAPI
.
updateItem
(
appId
,
env
,
clusterName
,
namespaceName
,
item
.
getId
(),
item
);
}
public
void
deleteItem
(
Env
env
,
long
itemId
)
{
...
...
@@ -120,9 +128,9 @@ public class ConfigService {
changeSets
.
setDataChangeLastModifiedBy
(
userInfoHolder
.
getUser
().
getUserId
());
try
{
itemAPI
.
updateItems
(
namespaceIdentifer
.
getAppId
(),
namespaceIdentifer
.
getEnv
(),
namespaceIdentifer
.
getClusterName
(),
namespaceIdentifer
.
getNamespaceName
(),
changeSets
);
.
updateItems
ByChangeSet
(
namespaceIdentifer
.
getAppId
(),
namespaceIdentifer
.
getEnv
(),
namespaceIdentifer
.
getClusterName
(),
namespaceIdentifer
.
getNamespaceName
(),
changeSets
);
}
catch
(
HttpClientErrorException
e
)
{
logger
.
error
(
"sync items error. namespace:{}"
,
namespaceIdentifer
);
throw
new
ServiceException
(
String
.
format
(
"sync item error. env:%s, clusterName:%s"
,
namespaceIdentifer
.
getEnv
(),
...
...
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