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
953b1ff1
Commit
953b1ff1
authored
Jun 16, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create app namespace
parent
0db06584
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
64 additions
and
30 deletions
+64
-30
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
+16
-0
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 @
953b1ff1
...
@@ -71,13 +71,6 @@ public class AdminServiceAPI {
...
@@ -71,13 +71,6 @@ public class AdminServiceAPI {
return
dto
;
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
)
{
public
NamespaceDTO
createNamespace
(
Env
env
,
NamespaceDTO
namespace
)
{
return
restTemplate
return
restTemplate
...
@@ -85,7 +78,7 @@ public class AdminServiceAPI {
...
@@ -85,7 +78,7 @@ public class AdminServiceAPI {
getAdminServiceHost
(
env
),
namespace
.
getAppId
(),
namespace
.
getClusterName
()).
getBody
();
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
,
return
restTemplate
.
postForEntity
(
"{host}/apps/{appId}/appnamespaces"
,
appNamespace
,
AppNamespaceDTO
.
class
,
getAdminServiceHost
(
env
),
appNamespace
.
getAppId
()).
getBody
();
getAdminServiceHost
(
env
),
appNamespace
.
getAppId
()).
getBody
();
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java
View file @
953b1ff1
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
controller
;
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
controller
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
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.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
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.entity.vo.NamespaceVO
;
import
com.ctrip.framework.apollo.portal.listener.AppNamespaceCreationEvent
;
import
com.ctrip.framework.apollo.portal.service.NamespaceService
;
import
com.ctrip.framework.apollo.portal.service.NamespaceService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
...
@@ -23,6 +26,10 @@ import static com.ctrip.framework.apollo.portal.util.RequestPrecondition.checkAr
...
@@ -23,6 +26,10 @@ import static com.ctrip.framework.apollo.portal.util.RequestPrecondition.checkAr
public
class
NamespaceController
{
public
class
NamespaceController
{
@Autowired
@Autowired
private
ApplicationEventPublisher
publisher
;
@Autowired
private
UserInfoHolder
userInfoHolder
;
@Autowired
private
NamespaceService
namespaceService
;
private
NamespaceService
namespaceService
;
@RequestMapping
(
"/appnamespaces/public"
)
@RequestMapping
(
"/appnamespaces/public"
)
...
@@ -30,7 +37,7 @@ public class NamespaceController {
...
@@ -30,7 +37,7 @@ public class NamespaceController {
return
namespaceService
.
findPublicAppNamespaces
();
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
)
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces"
,
method
=
RequestMethod
.
POST
)
public
NamespaceDTO
createNamespace
(
@PathVariable
String
env
,
@RequestBody
NamespaceDTO
namespace
)
{
public
NamespaceDTO
createNamespace
(
@PathVariable
String
env
,
@RequestBody
NamespaceDTO
namespace
)
{
...
@@ -40,11 +47,19 @@ public class NamespaceController {
...
@@ -40,11 +47,19 @@ public class NamespaceController {
}
}
@RequestMapping
(
value
=
"/apps/{appId}/appnamespaces"
,
method
=
RequestMethod
.
POST
)
@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
());
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"
)
@RequestMapping
(
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces"
)
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/AppCreationEvent.java
View file @
953b1ff1
...
@@ -8,11 +8,6 @@ import org.springframework.context.ApplicationEvent;
...
@@ -8,11 +8,6 @@ import org.springframework.context.ApplicationEvent;
public
class
AppCreationEvent
extends
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
)
{
public
AppCreationEvent
(
Object
source
)
{
super
(
source
);
super
(
source
);
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/AppNamespaceCreationEvent.java
0 → 100644
View file @
953b1ff1
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 @
953b1ff1
...
@@ -3,6 +3,7 @@ package com.ctrip.framework.apollo.portal.listener;
...
@@ -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.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.ExceptionUtils
;
import
com.ctrip.framework.apollo.common.utils.ExceptionUtils
;
import
com.ctrip.framework.apollo.core.dto.AppDTO
;
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.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
...
@@ -25,6 +26,8 @@ public class CreationListener {
...
@@ -25,6 +26,8 @@ public class CreationListener {
private
PortalSettings
portalSettings
;
private
PortalSettings
portalSettings
;
@Autowired
@Autowired
private
AdminServiceAPI
.
AppAPI
appAPI
;
private
AdminServiceAPI
.
AppAPI
appAPI
;
@Autowired
private
AdminServiceAPI
.
NamespaceAPI
namespaceAPI
;
@EventListener
@EventListener
public
void
onAppCreationEvent
(
AppCreationEvent
event
)
{
public
void
onAppCreationEvent
(
AppCreationEvent
event
)
{
...
@@ -39,4 +42,17 @@ public class CreationListener {
...
@@ -39,4 +42,17 @@ public class CreationListener {
}
}
}
}
@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
(
ExceptionUtils
.
toString
(
e
));
}
}
}
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
View file @
953b1ff1
...
@@ -95,19 +95,15 @@ public class NamespaceService {
...
@@ -95,19 +95,15 @@ public class NamespaceService {
return
Objects
.
isNull
(
appNamespaceRepository
.
findByAppIdAndName
(
appId
,
namespaceName
));
return
Objects
.
isNull
(
appNamespaceRepository
.
findByAppIdAndName
(
appId
,
namespaceName
));
}
}
public
void
createRemoteAppNamespace
(
AppNamespaceDTO
appNamespace
)
{
@Transactional
String
operator
=
userInfoHolder
.
getUser
().
getUserId
();
public
AppNamespace
createAppNamespaceInLocal
(
AppNamespace
appNamespace
)
{
if
(
StringUtils
.
isEmpty
(
appNamespace
.
getDataChangeCreatedBy
()))
{
AppNamespace
managedAppNamespace
=
appNamespaceRepository
.
findByAppIdAndName
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
());
appNamespace
.
setDataChangeCreatedBy
(
operator
);
//update
}
if
(
managedAppNamespace
!=
null
){
appNamespace
.
setDataChangeLastModifiedBy
(
operator
);
BeanUtils
.
copyEntityProperties
(
appNamespace
,
managedAppNamespace
);
for
(
Env
env
:
portalSettings
.
getActiveEnvs
())
{
return
appNamespaceRepository
.
save
(
managedAppNamespace
);
try
{
}
else
{
namespaceAPI
.
createOrUpdate
(
env
,
appNamespace
);
return
appNamespaceRepository
.
save
(
appNamespace
);
}
catch
(
HttpStatusCodeException
e
)
{
logger
.
error
(
ExceptionUtils
.
toString
(
e
));
throw
e
;
}
}
}
}
}
...
...
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