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
b9057d27
Commit
b9057d27
authored
Dec 26, 2016
by
Jason Song
Committed by
GitHub
Dec 26, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #499 from lepdou/1221
return default cluster's namespace when custom cluster's namespace ne…
parents
bae4505f
33ad4945
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
220 additions
and
182 deletions
+220
-182
NamespaceController.java
...k/apollo/adminservice/controller/NamespaceController.java
+14
-13
NamespaceService.java
.../ctrip/framework/apollo/biz/service/NamespaceService.java
+43
-9
AdminServiceAPI.java
...om/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
+3
-3
ConfigPublishEmailBuilder.java
...al/components/emailbuilder/ConfigPublishEmailBuilder.java
+1
-1
NamespaceController.java
...amework/apollo/portal/controller/NamespaceController.java
+126
-126
NamespaceService.java
...rip/framework/apollo/portal/service/NamespaceService.java
+13
-15
namespace-panel-directive.js
...ces/static/scripts/directive/namespace-panel-directive.js
+4
-1
ConfigService.js
...c/main/resources/static/scripts/services/ConfigService.js
+14
-13
namespace-panel-master-tab.html
...es/static/views/component/namespace-panel-master-tab.html
+2
-1
No files found.
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/NamespaceController.java
View file @
b9057d27
...
@@ -27,7 +27,7 @@ public class NamespaceController {
...
@@ -27,7 +27,7 @@ public class NamespaceController {
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces"
,
method
=
RequestMethod
.
POST
)
public
NamespaceDTO
create
(
@PathVariable
(
"appId"
)
String
appId
,
public
NamespaceDTO
create
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@RequestBody
NamespaceDTO
dto
)
{
@PathVariable
(
"clusterName"
)
String
clusterName
,
@RequestBody
NamespaceDTO
dto
)
{
if
(!
InputValidator
.
isValidClusterNamespace
(
dto
.
getNamespaceName
()))
{
if
(!
InputValidator
.
isValidClusterNamespace
(
dto
.
getNamespaceName
()))
{
throw
new
BadRequestException
(
String
.
format
(
"Namespace格式错误: %s"
,
InputValidator
.
INVALID_CLUSTER_NAMESPACE_MESSAGE
));
throw
new
BadRequestException
(
String
.
format
(
"Namespace格式错误: %s"
,
InputValidator
.
INVALID_CLUSTER_NAMESPACE_MESSAGE
));
}
}
...
@@ -45,18 +45,18 @@ public class NamespaceController {
...
@@ -45,18 +45,18 @@ public class NamespaceController {
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}"
,
method
=
RequestMethod
.
DELETE
)
@RequestMapping
(
path
=
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}"
,
method
=
RequestMethod
.
DELETE
)
public
void
delete
(
@PathVariable
(
"appId"
)
String
appId
,
public
void
delete
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
,
@RequestParam
String
operator
)
{
@PathVariable
(
"namespaceName"
)
String
namespaceName
,
@RequestParam
String
operator
)
{
Namespace
entity
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
Namespace
entity
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
if
(
entity
==
null
)
throw
new
NotFoundException
(
if
(
entity
==
null
)
throw
new
NotFoundException
(
String
.
format
(
"namespace not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
));
String
.
format
(
"namespace not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
));
namespaceService
.
deleteNamespace
(
entity
,
operator
);
namespaceService
.
deleteNamespace
(
entity
,
operator
);
}
}
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces"
)
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces"
)
public
List
<
NamespaceDTO
>
find
(
@PathVariable
(
"appId"
)
String
appId
,
public
List
<
NamespaceDTO
>
find
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
)
{
@PathVariable
(
"clusterName"
)
String
clusterName
)
{
List
<
Namespace
>
groups
=
namespaceService
.
findNamespaces
(
appId
,
clusterName
);
List
<
Namespace
>
groups
=
namespaceService
.
findNamespaces
(
appId
,
clusterName
);
return
BeanUtils
.
batchTransform
(
NamespaceDTO
.
class
,
groups
);
return
BeanUtils
.
batchTransform
(
NamespaceDTO
.
class
,
groups
);
}
}
...
@@ -71,18 +71,19 @@ public class NamespaceController {
...
@@ -71,18 +71,19 @@ public class NamespaceController {
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}"
)
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName:.+}"
)
public
NamespaceDTO
get
(
@PathVariable
(
"appId"
)
String
appId
,
public
NamespaceDTO
get
(
@PathVariable
(
"appId"
)
String
appId
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"clusterName"
)
String
clusterName
,
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
Namespace
namespace
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
Namespace
namespace
=
namespaceService
.
findOne
(
appId
,
clusterName
,
namespaceName
);
if
(
namespace
==
null
)
throw
new
NotFoundException
(
if
(
namespace
==
null
)
throw
new
NotFoundException
(
String
.
format
(
"namespace not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
));
String
.
format
(
"namespace not found for %s %s %s"
,
appId
,
clusterName
,
namespaceName
));
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
namespace
);
return
BeanUtils
.
transfrom
(
NamespaceDTO
.
class
,
namespace
);
}
}
@RequestMapping
(
"/clusters/{clusterName}/namespaces/{namespaceName}/public"
)
@RequestMapping
(
"/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/associated-public-namespace"
)
public
NamespaceDTO
findPublicNamespace
(
@PathVariable
String
clusterName
,
public
NamespaceDTO
findPublicNamespaceForAssociatedNamespace
(
@PathVariable
String
appId
,
@PathVariable
String
namespaceName
)
{
@PathVariable
String
clusterName
,
Namespace
namespace
=
namespaceService
.
findPublicNamespace
(
clusterName
,
namespaceName
);
@PathVariable
String
namespaceName
)
{
Namespace
namespace
=
namespaceService
.
findPublicNamespaceForAssociatedNamespace
(
clusterName
,
namespaceName
);
if
(
namespace
==
null
)
{
if
(
namespace
==
null
)
{
throw
new
NotFoundException
(
String
.
format
(
"public namespace not found. namespace:%s"
,
namespaceName
));
throw
new
NotFoundException
(
String
.
format
(
"public namespace not found. namespace:%s"
,
namespaceName
));
...
@@ -95,7 +96,7 @@ public class NamespaceController {
...
@@ -95,7 +96,7 @@ public class NamespaceController {
* cluster -> cluster has not published namespaces?
* cluster -> cluster has not published namespaces?
*/
*/
@RequestMapping
(
"/apps/{appId}/namespaces/publish_info"
)
@RequestMapping
(
"/apps/{appId}/namespaces/publish_info"
)
public
Map
<
String
,
Boolean
>
namespacePublishInfo
(
@PathVariable
String
appId
){
public
Map
<
String
,
Boolean
>
namespacePublishInfo
(
@PathVariable
String
appId
)
{
return
namespaceService
.
namespacePublishInfo
(
appId
);
return
namespaceService
.
namespacePublishInfo
(
appId
);
}
}
...
...
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/NamespaceService.java
View file @
b9057d27
...
@@ -59,7 +59,6 @@ public class NamespaceService {
...
@@ -59,7 +59,6 @@ public class NamespaceService {
private
InstanceService
instanceService
;
private
InstanceService
instanceService
;
public
Namespace
findOne
(
Long
namespaceId
)
{
public
Namespace
findOne
(
Long
namespaceId
)
{
return
namespaceRepository
.
findOne
(
namespaceId
);
return
namespaceRepository
.
findOne
(
namespaceId
);
}
}
...
@@ -69,7 +68,7 @@ public class NamespaceService {
...
@@ -69,7 +68,7 @@ public class NamespaceService {
namespaceName
);
namespaceName
);
}
}
public
Namespace
findPublicNamespace
(
String
clusterName
,
String
namespaceName
)
{
public
Namespace
findPublicNamespace
ForAssociatedNamespace
(
String
clusterName
,
String
namespaceName
)
{
AppNamespace
appNamespace
=
appNamespaceService
.
findPublicNamespaceByName
(
namespaceName
);
AppNamespace
appNamespace
=
appNamespaceService
.
findPublicNamespaceByName
(
namespaceName
);
if
(
appNamespace
==
null
)
{
if
(
appNamespace
==
null
)
{
throw
new
BadRequestException
(
"namespace not exist"
);
throw
new
BadRequestException
(
"namespace not exist"
);
...
@@ -79,11 +78,46 @@ public class NamespaceService {
...
@@ -79,11 +78,46 @@ public class NamespaceService {
Namespace
namespace
=
findOne
(
appId
,
clusterName
,
namespaceName
);
Namespace
namespace
=
findOne
(
appId
,
clusterName
,
namespaceName
);
//default cluster's namespace
if
(
Objects
.
equals
(
clusterName
,
ConfigConsts
.
CLUSTER_NAME_DEFAULT
))
{
return
namespace
;
}
//custom cluster's namespace not exist.
//return default cluster's namespace
if
(
namespace
==
null
)
{
if
(
namespace
==
null
)
{
namespace
=
findOne
(
appId
,
ConfigConsts
.
CLUSTER_NAME_DEFAULT
,
namespaceName
);
return
findOne
(
appId
,
ConfigConsts
.
CLUSTER_NAME_DEFAULT
,
namespaceName
);
}
}
//custom cluster's namespace exist and has published.
//return custom cluster's namespace
Release
latestActiveRelease
=
releaseService
.
findLatestActiveRelease
(
namespace
);
if
(
latestActiveRelease
!=
null
)
{
return
namespace
;
}
Namespace
defaultNamespace
=
findOne
(
appId
,
ConfigConsts
.
CLUSTER_NAME_DEFAULT
,
namespaceName
);
//custom cluster's namespace exist but never published.
//and default cluster's namespace not exist.
//return custom cluster's namespace
if
(
defaultNamespace
==
null
)
{
return
namespace
;
}
//custom cluster's namespace exist but never published.
//and default cluster's namespace exist and has published.
//return default cluster's namespace
Release
defaultNamespaceLatestActiveRelease
=
releaseService
.
findLatestActiveRelease
(
defaultNamespace
);
if
(
defaultNamespaceLatestActiveRelease
!=
null
)
{
return
defaultNamespace
;
}
//custom cluster's namespace exist but never published.
//and default cluster's namespace exist but never published.
//return custom cluster's namespace
return
namespace
;
return
namespace
;
}
}
public
List
<
Namespace
>
findNamespaces
(
String
appId
,
String
clusterName
)
{
public
List
<
Namespace
>
findNamespaces
(
String
appId
,
String
clusterName
)
{
...
@@ -129,7 +163,7 @@ public class NamespaceService {
...
@@ -129,7 +163,7 @@ public class NamespaceService {
}
}
public
Namespace
findParentNamespace
(
String
appId
,
String
clusterName
,
String
namespaceName
){
public
Namespace
findParentNamespace
(
String
appId
,
String
clusterName
,
String
namespaceName
)
{
return
findParentNamespace
(
new
Namespace
(
appId
,
clusterName
,
namespaceName
));
return
findParentNamespace
(
new
Namespace
(
appId
,
clusterName
,
namespaceName
));
}
}
...
@@ -146,7 +180,7 @@ public class NamespaceService {
...
@@ -146,7 +180,7 @@ public class NamespaceService {
return
null
;
return
null
;
}
}
public
boolean
isChildNamespace
(
String
appId
,
String
clusterName
,
String
namespaceName
){
public
boolean
isChildNamespace
(
String
appId
,
String
clusterName
,
String
namespaceName
)
{
return
isChildNamespace
(
new
Namespace
(
appId
,
clusterName
,
namespaceName
));
return
isChildNamespace
(
new
Namespace
(
appId
,
clusterName
,
namespaceName
));
}
}
...
@@ -268,10 +302,10 @@ public class NamespaceService {
...
@@ -268,10 +302,10 @@ public class NamespaceService {
String
clusterName
=
cluster
.
getName
();
String
clusterName
=
cluster
.
getName
();
List
<
Namespace
>
namespaces
=
findNamespaces
(
appId
,
clusterName
);
List
<
Namespace
>
namespaces
=
findNamespaces
(
appId
,
clusterName
);
for
(
Namespace
namespace:
namespaces
)
{
for
(
Namespace
namespace
:
namespaces
)
{
boolean
isNamespaceNotPublished
=
isNamespaceNotPublished
(
namespace
);
boolean
isNamespaceNotPublished
=
isNamespaceNotPublished
(
namespace
);
if
(
isNamespaceNotPublished
){
if
(
isNamespaceNotPublished
)
{
clusterHasNotPublishedItems
.
put
(
clusterName
,
true
);
clusterHasNotPublishedItems
.
put
(
clusterName
,
true
);
break
;
break
;
}
}
...
@@ -301,8 +335,8 @@ public class NamespaceService {
...
@@ -301,8 +335,8 @@ public class NamespaceService {
}
}
Map
<
String
,
String
>
publishedConfiguration
=
gson
.
fromJson
(
latestRelease
.
getConfigurations
(),
GsonType
.
CONFIG
);
Map
<
String
,
String
>
publishedConfiguration
=
gson
.
fromJson
(
latestRelease
.
getConfigurations
(),
GsonType
.
CONFIG
);
for
(
Item
item:
itemsModifiedAfterLastPublish
)
{
for
(
Item
item
:
itemsModifiedAfterLastPublish
)
{
if
(!
Objects
.
equals
(
item
.
getValue
(),
publishedConfiguration
.
get
(
item
.
getKey
()))){
if
(!
Objects
.
equals
(
item
.
getValue
(),
publishedConfiguration
.
get
(
item
.
getKey
())))
{
return
true
;
return
true
;
}
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
View file @
b9057d27
...
@@ -81,10 +81,10 @@ public class AdminServiceAPI {
...
@@ -81,10 +81,10 @@ public class AdminServiceAPI {
NamespaceDTO
.
class
,
appId
,
clusterName
,
namespaceName
);
NamespaceDTO
.
class
,
appId
,
clusterName
,
namespaceName
);
}
}
public
NamespaceDTO
loadPublicNamespace
(
Env
env
,
String
clusterName
,
String
namespaceName
)
{
public
NamespaceDTO
findPublicNamespaceForAssociatedNamespace
(
Env
env
,
String
appId
,
String
clusterName
,
String
namespaceName
)
{
return
return
restTemplate
.
get
(
env
,
"
/clusters/{clusterName}/namespaces/{namespaceName}/public
"
,
restTemplate
.
get
(
env
,
"
apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/associated-public-namespace
"
,
NamespaceDTO
.
class
,
clusterName
,
namespaceName
);
NamespaceDTO
.
class
,
appId
,
clusterName
,
namespaceName
);
}
}
public
NamespaceDTO
createNamespace
(
Env
env
,
NamespaceDTO
namespace
)
{
public
NamespaceDTO
createNamespace
(
Env
env
,
NamespaceDTO
namespace
)
{
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/components/emailbuilder/ConfigPublishEmailBuilder.java
View file @
b9057d27
...
@@ -58,7 +58,7 @@ public abstract class ConfigPublishEmailBuilder {
...
@@ -58,7 +58,7 @@ public abstract class ConfigPublishEmailBuilder {
//set config's value max length to protect email.
//set config's value max length to protect email.
protected
static
final
int
VALUE_MAX_LENGTH
=
100
;
protected
static
final
int
VALUE_MAX_LENGTH
=
100
;
pr
ivate
FastDateFormat
dateFormat
=
FastDateFormat
.
getInstance
(
"yyyy-MM-dd hh
:mm:ss"
);
pr
otected
FastDateFormat
dateFormat
=
FastDateFormat
.
getInstance
(
"yyyy-MM-dd HH
:mm:ss"
);
@Autowired
@Autowired
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java
View file @
b9057d27
...
@@ -45,142 +45,142 @@ import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkM
...
@@ -45,142 +45,142 @@ import static com.ctrip.framework.apollo.common.utils.RequestPrecondition.checkM
@RestController
@RestController
public
class
NamespaceController
{
public
class
NamespaceController
{
Logger
logger
=
LoggerFactory
.
getLogger
(
NamespaceController
.
class
);
Logger
logger
=
LoggerFactory
.
getLogger
(
NamespaceController
.
class
);
@Autowired
@Autowired
private
AppService
appService
;
private
AppService
appService
;
@Autowired
@Autowired
private
ApplicationEventPublisher
publisher
;
private
ApplicationEventPublisher
publisher
;
@Autowired
@Autowired
private
UserInfoHolder
userInfoHolder
;
private
UserInfoHolder
userInfoHolder
;
@Autowired
@Autowired
private
NamespaceService
namespaceService
;
private
NamespaceService
namespaceService
;
@Autowired
@Autowired
private
AppNamespaceService
appNamespaceService
;
private
AppNamespaceService
appNamespaceService
;
@Autowired
@Autowired
private
RoleInitializationService
roleInitializationService
;
private
RoleInitializationService
roleInitializationService
;
@Autowired
@Autowired
private
RolePermissionService
rolePermissionService
;
private
RolePermissionService
rolePermissionService
;
@RequestMapping
(
"/appnamespaces/public"
)
@RequestMapping
(
"/appnamespaces/public"
)
public
List
<
AppNamespace
>
findPublicAppNamespaces
()
{
public
List
<
AppNamespace
>
findPublicAppNamespaces
()
{
return
appNamespaceService
.
findPublicAppNamespaces
();
return
appNamespaceService
.
findPublicAppNamespaces
();
}
@RequestMapping
(
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces"
)
public
List
<
NamespaceBO
>
findNamespaces
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
)
{
return
namespaceService
.
findNamespaceBOs
(
appId
,
Env
.
valueOf
(
env
),
clusterName
);
}
@RequestMapping
(
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName:.+}"
)
public
NamespaceBO
findNamespace
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
)
{
return
namespaceService
.
loadNamespaceBO
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
);
}
@RequestMapping
(
"/envs/{env}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/associated-public-namespace"
)
public
NamespaceBO
findPublicNamespaceForAssociatedNamespace
(
@PathVariable
String
env
,
@PathVariable
String
appId
,
@PathVariable
String
namespaceName
,
@PathVariable
String
clusterName
)
{
return
namespaceService
.
findPublicNamespaceForAssociatedNamespace
(
Env
.
valueOf
(
env
),
appId
,
clusterName
,
namespaceName
);
}
@PreAuthorize
(
value
=
"@permissionValidator.hasCreateNamespacePermission(#appId)"
)
@RequestMapping
(
value
=
"/apps/{appId}/namespaces"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
Void
>
createNamespace
(
@PathVariable
String
appId
,
@RequestBody
List
<
NamespaceCreationModel
>
models
)
{
checkModel
(!
CollectionUtils
.
isEmpty
(
models
));
roleInitializationService
.
initNamespaceRoles
(
appId
,
models
.
get
(
0
).
getNamespace
().
getNamespaceName
());
String
namespaceName
=
null
;
for
(
NamespaceCreationModel
model
:
models
)
{
NamespaceDTO
namespace
=
model
.
getNamespace
();
namespaceName
=
namespace
.
getNamespaceName
();
RequestPrecondition
.
checkArgumentsNotEmpty
(
model
.
getEnv
(),
namespace
.
getAppId
(),
namespace
.
getClusterName
(),
namespace
.
getNamespaceName
());
try
{
// TODO: 16/6/17 某些环境创建失败,统一处理这种场景
namespaceService
.
createNamespace
(
Env
.
valueOf
(
model
.
getEnv
()),
namespace
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"create namespace fail."
,
e
);
Tracer
.
logError
(
String
.
format
(
"create namespace fail. (env=%s namespace=%s)"
,
model
.
getEnv
(),
namespace
.
getNamespaceName
()),
e
);
}
}
}
@RequestMapping
(
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces"
)
//default assign modify、release namespace role to namespace creator
public
List
<
NamespaceBO
>
findNamespaces
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
String
loginUser
=
userInfoHolder
.
getUser
().
getUserId
();
@PathVariable
String
clusterName
)
{
rolePermissionService
return
namespaceService
.
findNamespaceBOs
(
appId
,
Env
.
valueOf
(
env
),
clusterName
);
}
@RequestMapping
(
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName:.+}"
)
public
NamespaceBO
findNamespace
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
)
{
return
namespaceService
.
loadNamespaceBO
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
);
}
@RequestMapping
(
"/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/public"
)
public
NamespaceBO
findPublicNamespace
(
@PathVariable
String
env
,
@PathVariable
String
namespaceName
,
@PathVariable
String
clusterName
)
{
return
namespaceService
.
loadPublicNamespaceBO
(
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
);
}
@PreAuthorize
(
value
=
"@permissionValidator.hasCreateNamespacePermission(#appId)"
)
@RequestMapping
(
value
=
"/apps/{appId}/namespaces"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
Void
>
createNamespace
(
@PathVariable
String
appId
,
@RequestBody
List
<
NamespaceCreationModel
>
models
)
{
checkModel
(!
CollectionUtils
.
isEmpty
(
models
));
roleInitializationService
.
initNamespaceRoles
(
appId
,
models
.
get
(
0
).
getNamespace
().
getNamespaceName
());
String
namespaceName
=
null
;
for
(
NamespaceCreationModel
model
:
models
)
{
NamespaceDTO
namespace
=
model
.
getNamespace
();
namespaceName
=
namespace
.
getNamespaceName
();
RequestPrecondition
.
checkArgumentsNotEmpty
(
model
.
getEnv
(),
namespace
.
getAppId
(),
namespace
.
getClusterName
(),
namespace
.
getNamespaceName
());
try
{
// TODO: 16/6/17 某些环境创建失败,统一处理这种场景
namespaceService
.
createNamespace
(
Env
.
valueOf
(
model
.
getEnv
()),
namespace
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"create namespace fail."
,
e
);
Tracer
.
logError
(
String
.
format
(
"create namespace fail. (env=%s namespace=%s)"
,
model
.
getEnv
(),
namespace
.
getNamespaceName
()),
e
);
}
}
//default assign modify、release namespace role to namespace creator
String
loginUser
=
userInfoHolder
.
getUser
().
getUserId
();
rolePermissionService
.
assignRoleToUsers
(
RoleUtils
.
buildNamespaceRoleName
(
appId
,
namespaceName
,
RoleType
.
MODIFY_NAMESPACE
),
.
assignRoleToUsers
(
RoleUtils
.
buildNamespaceRoleName
(
appId
,
namespaceName
,
RoleType
.
MODIFY_NAMESPACE
),
Sets
.
newHashSet
(
loginUser
),
loginUser
);
Sets
.
newHashSet
(
loginUser
),
loginUser
);
rolePermissionService
rolePermissionService
.
assignRoleToUsers
(
RoleUtils
.
buildNamespaceRoleName
(
appId
,
namespaceName
,
RoleType
.
RELEASE_NAMESPACE
),
.
assignRoleToUsers
(
RoleUtils
.
buildNamespaceRoleName
(
appId
,
namespaceName
,
RoleType
.
RELEASE_NAMESPACE
),
Sets
.
newHashSet
(
loginUser
),
loginUser
);
Sets
.
newHashSet
(
loginUser
),
loginUser
);
return
ResponseEntity
.
ok
().
build
();
return
ResponseEntity
.
ok
().
build
();
}
}
@PreAuthorize
(
value
=
"@permissionValidator.isSuperAdmin()"
)
@PreAuthorize
(
value
=
"@permissionValidator.isSuperAdmin()"
)
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName:.+}"
,
method
=
RequestMethod
.
DELETE
)
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName:.+}"
,
method
=
RequestMethod
.
DELETE
)
public
ResponseEntity
<
Void
>
deleteNamespace
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
public
ResponseEntity
<
Void
>
deleteNamespace
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
)
{
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
)
{
namespaceService
.
deleteNamespace
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
);
namespaceService
.
deleteNamespace
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
);
return
ResponseEntity
.
ok
().
build
();
return
ResponseEntity
.
ok
().
build
();
}
@PreAuthorize
(
value
=
"@permissionValidator.hasCreateAppNamespacePermission(#appId, #appNamespace)"
)
@RequestMapping
(
value
=
"/apps/{appId}/appnamespaces"
,
method
=
RequestMethod
.
POST
)
public
AppNamespace
createAppNamespace
(
@PathVariable
String
appId
,
@RequestBody
AppNamespace
appNamespace
)
{
RequestPrecondition
.
checkArgumentsNotEmpty
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
());
if
(!
InputValidator
.
isValidAppNamespace
(
appNamespace
.
getName
()))
{
throw
new
BadRequestException
(
String
.
format
(
"Namespace格式错误: %s"
,
InputValidator
.
INVALID_CLUSTER_NAMESPACE_MESSAGE
+
" & "
+
InputValidator
.
INVALID_NAMESPACE_NAMESPACE_MESSAGE
));
}
}
@PreAuthorize
(
value
=
"@permissionValidator.hasCreateAppNamespacePermission(#appId, #appNamespace)"
)
//add app org id as prefix
@RequestMapping
(
value
=
"/apps/{appId}/appnamespaces"
,
method
=
RequestMethod
.
POST
)
App
app
=
appService
.
load
(
appId
);
public
AppNamespace
createAppNamespace
(
@PathVariable
String
appId
,
@RequestBody
AppNamespace
appNamespace
)
{
StringBuilder
appNamespaceName
=
new
StringBuilder
();
//add prefix postfix
RequestPrecondition
.
checkArgumentsNotEmpty
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
());
appNamespaceName
if
(!
InputValidator
.
isValidAppNamespace
(
appNamespace
.
getName
()))
{
throw
new
BadRequestException
(
String
.
format
(
"Namespace格式错误: %s"
,
InputValidator
.
INVALID_CLUSTER_NAMESPACE_MESSAGE
+
" & "
+
InputValidator
.
INVALID_NAMESPACE_NAMESPACE_MESSAGE
));
}
//add app org id as prefix
App
app
=
appService
.
load
(
appId
);
StringBuilder
appNamespaceName
=
new
StringBuilder
();
//add prefix postfix
appNamespaceName
.
append
(
appNamespace
.
isPublic
()
?
app
.
getOrgId
()
+
"."
:
""
)
.
append
(
appNamespace
.
isPublic
()
?
app
.
getOrgId
()
+
"."
:
""
)
.
append
(
appNamespace
.
getName
())
.
append
(
appNamespace
.
getName
())
.
append
(
appNamespace
.
formatAsEnum
()
==
ConfigFileFormat
.
Properties
?
""
:
"."
+
appNamespace
.
getFormat
());
.
append
(
appNamespace
.
formatAsEnum
()
==
ConfigFileFormat
.
Properties
?
""
:
"."
+
appNamespace
.
getFormat
());
appNamespace
.
setName
(
appNamespaceName
.
toString
());
appNamespace
.
setName
(
appNamespaceName
.
toString
());
String
operator
=
userInfoHolder
.
getUser
().
getUserId
();
if
(
StringUtils
.
isEmpty
(
appNamespace
.
getDataChangeCreatedBy
()))
{
appNamespace
.
setDataChangeCreatedBy
(
operator
);
}
appNamespace
.
setDataChangeLastModifiedBy
(
operator
);
AppNamespace
createdAppNamespace
=
appNamespaceService
.
createAppNamespaceInLocal
(
appNamespace
);
publisher
.
publishEvent
(
new
AppNamespaceCreationEvent
(
createdAppNamespace
));
return
createdAppNamespace
;
}
/**
String
operator
=
userInfoHolder
.
getUser
().
getUserId
();
* env -> cluster -> cluster has not published namespace?
if
(
StringUtils
.
isEmpty
(
appNamespace
.
getDataChangeCreatedBy
()))
{
* Example:
appNamespace
.
setDataChangeCreatedBy
(
operator
);
* dev ->
* default -> true (default cluster has not published namespace)
* customCluster -> false (customCluster cluster's all namespaces had published)
*
*/
@RequestMapping
(
"/apps/{appId}/namespaces/publish_info"
)
public
Map
<
String
,
Map
<
String
,
Boolean
>>
getNamespacesPublishInfo
(
@PathVariable
String
appId
)
{
return
namespaceService
.
getNamespacesPublishInfo
(
appId
);
}
}
appNamespace
.
setDataChangeLastModifiedBy
(
operator
);
AppNamespace
createdAppNamespace
=
appNamespaceService
.
createAppNamespaceInLocal
(
appNamespace
);
publisher
.
publishEvent
(
new
AppNamespaceCreationEvent
(
createdAppNamespace
));
return
createdAppNamespace
;
}
/**
* env -> cluster -> cluster has not published namespace?
* Example:
* dev ->
* default -> true (default cluster has not published namespace)
* customCluster -> false (customCluster cluster's all namespaces had published)
*/
@RequestMapping
(
"/apps/{appId}/namespaces/publish_info"
)
public
Map
<
String
,
Map
<
String
,
Boolean
>>
getNamespacesPublishInfo
(
@PathVariable
String
appId
)
{
return
namespaceService
.
getNamespacesPublishInfo
(
appId
);
}
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
View file @
b9057d27
...
@@ -11,7 +11,6 @@ import com.ctrip.framework.apollo.common.dto.ReleaseDTO;
...
@@ -11,7 +11,6 @@ import com.ctrip.framework.apollo.common.dto.ReleaseDTO;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
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.core.utils.StringUtils
;
...
@@ -26,10 +25,8 @@ import com.ctrip.framework.apollo.tracer.Tracer;
...
@@ -26,10 +25,8 @@ import com.ctrip.framework.apollo.tracer.Tracer;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.client.HttpClientErrorException
;
import
java.util.*
;
import
java.util.*
;
...
@@ -104,9 +101,9 @@ public class NamespaceService {
...
@@ -104,9 +101,9 @@ public class NamespaceService {
List
<
NamespaceBO
>
namespaceBOs
=
new
LinkedList
<>();
List
<
NamespaceBO
>
namespaceBOs
=
new
LinkedList
<>();
for
(
NamespaceDTO
namespace
:
namespaces
)
{
for
(
NamespaceDTO
namespace
:
namespaces
)
{
NamespaceBO
namespaceBO
=
null
;
NamespaceBO
namespaceBO
;
try
{
try
{
namespaceBO
=
transformNamespace2BO
(
appId
,
env
,
clusterName
,
namespace
);
namespaceBO
=
transformNamespace2BO
(
env
,
namespace
);
namespaceBOs
.
add
(
namespaceBO
);
namespaceBOs
.
add
(
namespaceBO
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}"
,
logger
.
error
(
"parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}"
,
...
@@ -123,16 +120,15 @@ public class NamespaceService {
...
@@ -123,16 +120,15 @@ public class NamespaceService {
if
(
namespace
==
null
)
{
if
(
namespace
==
null
)
{
throw
new
BadRequestException
(
"namespaces not exist"
);
throw
new
BadRequestException
(
"namespaces not exist"
);
}
}
return
transformNamespace2BO
(
appId
,
env
,
clusterName
,
namespace
);
return
transformNamespace2BO
(
env
,
namespace
);
}
}
public
NamespaceBO
loadPublicNamespaceBO
(
Env
env
,
String
clusterName
,
String
namespaceName
)
{
public
NamespaceBO
findPublicNamespaceForAssociatedNamespace
(
Env
env
,
String
appId
,
NamespaceDTO
namespace
=
namespaceAPI
.
loadPublicNamespace
(
env
,
clusterName
,
namespaceName
);
String
clusterName
,
String
namespaceName
)
{
NamespaceDTO
namespace
=
namespaceAPI
.
findPublicNamespaceForAssociatedNamespace
(
env
,
appId
,
clusterName
,
namespaceName
);
String
appId
=
namespace
.
getAppId
();
String
actualClusterName
=
namespace
.
getClusterName
();
return
transformNamespace2BO
(
appId
,
env
,
actualClusterName
,
namespace
);
return
transformNamespace2BO
(
env
,
namespace
);
}
}
public
Map
<
String
,
Map
<
String
,
Boolean
>>
getNamespacesPublishInfo
(
String
appId
)
{
public
Map
<
String
,
Map
<
String
,
Boolean
>>
getNamespacesPublishInfo
(
String
appId
)
{
...
@@ -148,19 +144,21 @@ public class NamespaceService {
...
@@ -148,19 +144,21 @@ public class NamespaceService {
return
result
;
return
result
;
}
}
private
NamespaceBO
transformNamespace2BO
(
String
appId
,
Env
env
,
String
clusterName
,
NamespaceDTO
namespace
)
{
private
NamespaceBO
transformNamespace2BO
(
Env
env
,
NamespaceDTO
namespace
)
{
NamespaceBO
namespaceBO
=
new
NamespaceBO
();
NamespaceBO
namespaceBO
=
new
NamespaceBO
();
namespaceBO
.
setBaseInfo
(
namespace
);
namespaceBO
.
setBaseInfo
(
namespace
);
String
appId
=
namespace
.
getAppId
();
String
clusterName
=
namespace
.
getClusterName
();
String
namespaceName
=
namespace
.
getNamespaceName
();
fillAppNamespaceProperties
(
namespaceBO
);
fillAppNamespaceProperties
(
namespaceBO
);
List
<
ItemBO
>
itemBOs
=
new
LinkedList
<>();
List
<
ItemBO
>
itemBOs
=
new
LinkedList
<>();
namespaceBO
.
setItems
(
itemBOs
);
namespaceBO
.
setItems
(
itemBOs
);
String
namespaceName
=
namespace
.
getNamespaceName
();
//latest Release
//latest Release
ReleaseDTO
latestRelease
=
null
;
ReleaseDTO
latestRelease
;
Map
<
String
,
String
>
releaseItems
=
new
HashMap
<>();
Map
<
String
,
String
>
releaseItems
=
new
HashMap
<>();
latestRelease
=
releaseService
.
loadLatestRelease
(
appId
,
env
,
clusterName
,
namespaceName
);
latestRelease
=
releaseService
.
loadLatestRelease
(
appId
,
env
,
clusterName
,
namespaceName
);
if
(
latestRelease
!=
null
)
{
if
(
latestRelease
!=
null
)
{
...
...
apollo-portal/src/main/resources/static/scripts/directive/namespace-panel-directive.js
View file @
b9057d27
...
@@ -227,7 +227,8 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
...
@@ -227,7 +227,8 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
return
;
return
;
}
}
//load public namespace
//load public namespace
ConfigService
.
load_public_namespace
(
scope
.
env
,
scope
.
cluster
,
namespace
.
baseInfo
.
namespaceName
)
ConfigService
.
load_public_namespace_for_associated_namespace
(
scope
.
env
,
scope
.
appId
,
scope
.
cluster
,
namespace
.
baseInfo
.
namespaceName
)
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
var
publicNamespace
=
result
;
var
publicNamespace
=
result
;
namespace
.
publicNamespace
=
publicNamespace
;
namespace
.
publicNamespace
=
publicNamespace
;
...
@@ -429,6 +430,8 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
...
@@ -429,6 +430,8 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
namespace
.
latestReleaseInstances
=
result
;
namespace
.
latestReleaseInstances
=
result
;
namespace
.
latestReleaseInstancesPage
++
;
namespace
.
latestReleaseInstancesPage
++
;
})
})
namespace
.
isLatestReleaseLoaded
=
true
;
});
});
}
else
{
}
else
{
InstanceService
.
findInstancesByRelease
(
scope
.
env
,
InstanceService
.
findInstancesByRelease
(
scope
.
env
,
...
...
apollo-portal/src/main/resources/static/scripts/services/ConfigService.js
View file @
b9057d27
...
@@ -5,10 +5,10 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
...
@@ -5,10 +5,10 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
isArray
:
false
,
isArray
:
false
,
url
:
'/apps/:appId/envs/:env/clusters/:clusterName/namespaces/:namespaceName'
url
:
'/apps/:appId/envs/:env/clusters/:clusterName/namespaces/:namespaceName'
},
},
load_public_namespace
:
{
load_public_namespace
_for_associated_namespace
:
{
method
:
'GET'
,
method
:
'GET'
,
isArray
:
false
,
isArray
:
false
,
url
:
'/envs/:env/
clusters/:clusterName/namespaces/:namespaceName/public
'
url
:
'/envs/:env/
apps/:appId/clusters/:clusterName/namespaces/:namespaceName/associated-public-namespace
'
},
},
load_all_namespaces
:
{
load_all_namespaces
:
{
method
:
'GET'
,
method
:
'GET'
,
...
@@ -52,24 +52,25 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
...
@@ -52,24 +52,25 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
load_namespace
:
function
(
appId
,
env
,
clusterName
,
namespaceName
)
{
load_namespace
:
function
(
appId
,
env
,
clusterName
,
namespaceName
)
{
var
d
=
$q
.
defer
();
var
d
=
$q
.
defer
();
config_source
.
load_namespace
({
config_source
.
load_namespace
({
appId
:
appId
,
appId
:
appId
,
env
:
env
,
env
:
env
,
clusterName
:
clusterName
,
clusterName
:
clusterName
,
namespaceName
:
namespaceName
namespaceName
:
namespaceName
},
function
(
result
)
{
},
function
(
result
)
{
d
.
resolve
(
result
);
d
.
resolve
(
result
);
},
function
(
result
)
{
},
function
(
result
)
{
d
.
reject
(
result
);
d
.
reject
(
result
);
});
});
return
d
.
promise
;
return
d
.
promise
;
},
},
load_public_namespace
:
function
(
env
,
clusterName
,
namespaceName
)
{
load_public_namespace
_for_associated_namespace
:
function
(
env
,
appId
,
clusterName
,
namespaceName
)
{
var
d
=
$q
.
defer
();
var
d
=
$q
.
defer
();
config_source
.
load_public_namespace
({
config_source
.
load_public_namespace_for_associated_namespace
({
env
:
env
,
env
:
env
,
clusterName
:
clusterName
,
appId
:
appId
,
namespaceName
:
namespaceName
clusterName
:
clusterName
,
},
function
(
result
)
{
namespaceName
:
namespaceName
},
function
(
result
)
{
d
.
resolve
(
result
);
d
.
resolve
(
result
);
},
function
(
result
)
{
},
function
(
result
)
{
d
.
reject
(
result
);
d
.
reject
(
result
);
...
...
apollo-portal/src/main/resources/static/views/component/namespace-panel-master-tab.html
View file @
b9057d27
...
@@ -163,7 +163,8 @@
...
@@ -163,7 +163,8 @@
<!--table view-->
<!--table view-->
<div
class=
"namespace-view-table"
ng-show=
"namespace.viewType == 'table'"
>
<div
class=
"namespace-view-table"
ng-show=
"namespace.viewType == 'table'"
>
<div
class=
"well well-sm no-radius text-center"
ng-show=
"!namespace.isLinkedNamespace && !namespace.latestRelease"
>
<div
class=
"J_namespace-release-tip well well-sm no-radius text-center"
ng-show=
"namespace.isLatestReleaseLoaded && !namespace.isLinkedNamespace && !namespace.latestRelease"
>
<span
style=
"color: red"
>
Tips: 此namespace从来没有发布过,Apollo客户端将获取不到配置并记录404日志信息,请及时发布。
</span>
<span
style=
"color: red"
>
Tips: 此namespace从来没有发布过,Apollo客户端将获取不到配置并记录404日志信息,请及时发布。
</span>
</div>
</div>
<!--not link namespace-->
<!--not link namespace-->
...
...
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