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
08c4768c
Commit
08c4768c
authored
Jun 16, 2016
by
Jason Song
Committed by
GitHub
Jun 16, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #270 from lepdou/0613_17
create app namespace
parents
0db06584
38f02745
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
65 additions
and
31 deletions
+65
-31
AdminServiceAPI.java
...om/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
+1
-8
NamespaceController.java
...amework/apollo/portal/controller/NamespaceController.java
+19
-4
AppCreationEvent.java
...ip/framework/apollo/portal/listener/AppCreationEvent.java
+0
-5
AppNamespaceCreationEvent.java
...ork/apollo/portal/listener/AppNamespaceCreationEvent.java
+19
-0
CreationListener.java
...ip/framework/apollo/portal/listener/CreationListener.java
+17
-1
NamespaceService.java
...rip/framework/apollo/portal/service/NamespaceService.java
+9
-13
No files found.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
View file @
08c4768c
...
...
@@ -71,13 +71,6 @@ public class AdminServiceAPI {
return
dto
;
}
public
List
<
AppNamespaceDTO
>
findPublicAppNamespaces
(
Env
env
)
{
AppNamespaceDTO
[]
appNamespaceDTOs
=
restTemplate
.
getForObject
(
"{host}/appnamespaces/public"
,
AppNamespaceDTO
[].
class
,
getAdminServiceHost
(
env
));
return
Arrays
.
asList
(
appNamespaceDTOs
);
}
public
NamespaceDTO
createNamespace
(
Env
env
,
NamespaceDTO
namespace
)
{
return
restTemplate
...
...
@@ -85,7 +78,7 @@ public class AdminServiceAPI {
getAdminServiceHost
(
env
),
namespace
.
getAppId
(),
namespace
.
getClusterName
()).
getBody
();
}
public
AppNamespaceDTO
createOrUpdate
(
Env
env
,
AppNamespaceDTO
appNamespace
)
{
public
AppNamespaceDTO
createOrUpdate
AppNamespace
(
Env
env
,
AppNamespaceDTO
appNamespace
)
{
return
restTemplate
.
postForEntity
(
"{host}/apps/{appId}/appnamespaces"
,
appNamespace
,
AppNamespaceDTO
.
class
,
getAdminServiceHost
(
env
),
appNamespace
.
getAppId
()).
getBody
();
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java
View file @
08c4768c
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
controller
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.core.dto.AppNamespaceDTO
;
import
com.ctrip.framework.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.entity.vo.NamespaceVO
;
import
com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent
;
import
com.ctrip.framework.apollo.portal.service.NamespaceService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
...
@@ -23,6 +26,10 @@ import static com.ctrip.framework.apollo.portal.util.RequestPrecondition.checkAr
public
class
NamespaceController
{
@Autowired
private
ApplicationEventPublisher
publisher
;
@Autowired
private
UserInfoHolder
userInfoHolder
;
@Autowired
private
NamespaceService
namespaceService
;
@RequestMapping
(
"/appnamespaces/public"
)
...
...
@@ -30,7 +37,7 @@ public class NamespaceController {
return
namespaceService
.
findPublicAppNamespaces
();
}
@PreAuthorize
(
value
=
"@permissionValidator.hasCreateNamespacePermission(#appId)"
)
@PreAuthorize
(
value
=
"@permissionValidator.hasCreateNamespacePermission(#
namespace.
appId)"
)
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces"
,
method
=
RequestMethod
.
POST
)
public
NamespaceDTO
createNamespace
(
@PathVariable
String
env
,
@RequestBody
NamespaceDTO
namespace
)
{
...
...
@@ -40,11 +47,19 @@ public class NamespaceController {
}
@RequestMapping
(
value
=
"/apps/{appId}/appnamespaces"
,
method
=
RequestMethod
.
POST
)
public
void
createAppNamespace
(
@PathVariable
String
appId
,
@RequestBody
AppNamespace
DTO
appNamespace
)
{
public
void
createAppNamespace
(
@PathVariable
String
appId
,
@RequestBody
AppNamespace
appNamespace
)
{
checkArgument
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
());
namespaceService
.
createRemoteAppNamespace
(
appNamespace
);
String
operator
=
userInfoHolder
.
getUser
().
getUserId
();
if
(
StringUtils
.
isEmpty
(
appNamespace
.
getDataChangeCreatedBy
()))
{
appNamespace
.
setDataChangeCreatedBy
(
operator
);
}
appNamespace
.
setDataChangeLastModifiedBy
(
operator
);
AppNamespace
createdAppNamespace
=
namespaceService
.
createAppNamespaceInLocal
(
appNamespace
);
publisher
.
publishEvent
(
new
AppNamespaceCreationEvent
(
createdAppNamespace
));
}
@RequestMapping
(
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces"
)
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/AppCreationEvent.java
View file @
08c4768c
...
...
@@ -8,11 +8,6 @@ import org.springframework.context.ApplicationEvent;
public
class
AppCreationEvent
extends
ApplicationEvent
{
/**
* Create a new ApplicationEvent.
*
* @param source the object on which the event initially occurred (never {@code null})
*/
public
AppCreationEvent
(
Object
source
)
{
super
(
source
);
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/AppNamespaceCreationEvent.java
0 → 100644
View file @
08c4768c
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
listener
;
import
com.google.common.base.Preconditions
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
org.springframework.context.ApplicationEvent
;
public
class
AppNamespaceCreationEvent
extends
ApplicationEvent
{
public
AppNamespaceCreationEvent
(
Object
source
)
{
super
(
source
);
}
public
AppNamespace
getAppNamespace
()
{
Preconditions
.
checkState
(
source
!=
null
);
return
(
AppNamespace
)
this
.
source
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/CreationListener.java
View file @
08c4768c
...
...
@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.portal.listener;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.ExceptionUtils
;
import
com.ctrip.framework.apollo.core.dto.AppDTO
;
import
com.ctrip.framework.apollo.core.dto.AppNamespaceDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
...
...
@@ -25,6 +26,8 @@ public class CreationListener {
private
PortalSettings
portalSettings
;
@Autowired
private
AdminServiceAPI
.
AppAPI
appAPI
;
@Autowired
private
AdminServiceAPI
.
NamespaceAPI
namespaceAPI
;
@EventListener
public
void
onAppCreationEvent
(
AppCreationEvent
event
)
{
...
...
@@ -34,7 +37,20 @@ public class CreationListener {
try
{
appAPI
.
createApp
(
env
,
appDTO
);
}
catch
(
HttpStatusCodeException
e
)
{
logger
.
error
(
ExceptionUtils
.
toString
(
e
));
logger
.
error
(
"call appAPI.createApp error.[{app}, {env}]"
,
appDTO
.
getAppId
(),
env
,
e
);
}
}
}
@EventListener
public
void
onAppNamespaceCreationEvent
(
AppNamespaceCreationEvent
event
){
AppNamespaceDTO
dto
=
BeanUtils
.
transfrom
(
AppNamespaceDTO
.
class
,
event
.
getAppNamespace
());
List
<
Env
>
envs
=
portalSettings
.
getActiveEnvs
();
for
(
Env
env
:
envs
)
{
try
{
namespaceAPI
.
createOrUpdateAppNamespace
(
env
,
dto
);
}
catch
(
HttpStatusCodeException
e
)
{
logger
.
error
(
"call namespaceAPI.createOrUpdateAppNamespace error. [{app}, {env}]"
,
dto
.
getAppId
(),
env
,
e
);
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
View file @
08c4768c
...
...
@@ -95,19 +95,15 @@ public class NamespaceService {
return
Objects
.
isNull
(
appNamespaceRepository
.
findByAppIdAndName
(
appId
,
namespaceName
));
}
public
void
createRemoteAppNamespace
(
AppNamespaceDTO
appNamespace
)
{
String
operator
=
userInfoHolder
.
getUser
().
getUserId
();
if
(
StringUtils
.
isEmpty
(
appNamespace
.
getDataChangeCreatedBy
()))
{
appNamespace
.
setDataChangeCreatedBy
(
operator
);
}
appNamespace
.
setDataChangeLastModifiedBy
(
operator
);
for
(
Env
env
:
portalSettings
.
getActiveEnvs
())
{
try
{
namespaceAPI
.
createOrUpdate
(
env
,
appNamespace
);
}
catch
(
HttpStatusCodeException
e
)
{
logger
.
error
(
ExceptionUtils
.
toString
(
e
));
throw
e
;
}
@Transactional
public
AppNamespace
createAppNamespaceInLocal
(
AppNamespace
appNamespace
)
{
AppNamespace
managedAppNamespace
=
appNamespaceRepository
.
findByAppIdAndName
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
());
//update
if
(
managedAppNamespace
!=
null
){
BeanUtils
.
copyEntityProperties
(
appNamespace
,
managedAppNamespace
);
return
appNamespaceRepository
.
save
(
managedAppNamespace
);
}
else
{
return
appNamespaceRepository
.
save
(
appNamespace
);
}
}
...
...
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