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
64483c44
Commit
64483c44
authored
Jun 17, 2016
by
Jason Song
Committed by
GitHub
Jun 17, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #272 from lepdou/0613_17
bugfix public appnamespace unique & repeat create namespace permission
parents
1f36fcd2
bb4c491b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
85 additions
and
33 deletions
+85
-33
GlobalDefaultExceptionHandler.java
...ollo/common/controller/GlobalDefaultExceptionHandler.java
+6
-1
NamespaceController.java
...amework/apollo/portal/controller/NamespaceController.java
+25
-5
BizLoggingCustomizer.java
...amework/apollo/portal/customize/BizLoggingCustomizer.java
+1
-1
package-info.java
...ctrip/framework/apollo/portal/customize/package-info.java
+1
-1
NamespaceCreationModel.java
...ork/apollo/portal/entity/form/NamespaceCreationModel.java
+27
-0
NamespaceService.java
...rip/framework/apollo/portal/service/NamespaceService.java
+5
-0
NamespaceController.js
...esources/static/scripts/controller/NamespaceController.js
+16
-15
NamespaceService.js
...ain/resources/static/scripts/services/NamespaceService.js
+4
-10
No files found.
apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/GlobalDefaultExceptionHandler.java
View file @
64483c44
...
@@ -44,12 +44,17 @@ public class GlobalDefaultExceptionHandler {
...
@@ -44,12 +44,17 @@ public class GlobalDefaultExceptionHandler {
return
handleError
(
request
,
INTERNAL_SERVER_ERROR
,
ex
);
return
handleError
(
request
,
INTERNAL_SERVER_ERROR
,
ex
);
}
}
@ExceptionHandler
({
HttpRequestMethodNotSupportedException
.
class
,
HttpMediaTypeException
.
class
,
BadRequestException
.
class
})
@ExceptionHandler
({
HttpRequestMethodNotSupportedException
.
class
,
HttpMediaTypeException
.
class
})
public
ResponseEntity
<
Map
<
String
,
Object
>>
badRequest
(
HttpServletRequest
request
,
public
ResponseEntity
<
Map
<
String
,
Object
>>
badRequest
(
HttpServletRequest
request
,
ServletException
ex
)
{
ServletException
ex
)
{
return
handleError
(
request
,
BAD_REQUEST
,
ex
);
return
handleError
(
request
,
BAD_REQUEST
,
ex
);
}
}
@ExceptionHandler
({
BadRequestException
.
class
})
public
ResponseEntity
<
Map
<
String
,
Object
>>
badRequest
(
HttpServletRequest
request
,
BadRequestException
ex
)
{
return
handleError
(
request
,
BAD_REQUEST
,
ex
);
}
@ExceptionHandler
(
NotFoundException
.
class
)
@ExceptionHandler
(
NotFoundException
.
class
)
public
ResponseEntity
<
Map
<
String
,
Object
>>
notFound
(
HttpServletRequest
request
,
public
ResponseEntity
<
Map
<
String
,
Object
>>
notFound
(
HttpServletRequest
request
,
NotFoundException
ex
)
{
NotFoundException
ex
)
{
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java
View file @
64483c44
...
@@ -5,13 +5,18 @@ import com.ctrip.framework.apollo.core.dto.NamespaceDTO;
...
@@ -5,13 +5,18 @@ 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.core.utils.StringUtils
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.entity.form.NamespaceCreationModel
;
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.listener.AppNamespaceCreationEvent
;
import
com.ctrip.framework.apollo.portal.service.NamespaceService
;
import
com.ctrip.framework.apollo.portal.service.NamespaceService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.util.CollectionUtils
;
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
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
@@ -21,10 +26,13 @@ import org.springframework.web.bind.annotation.RestController;
...
@@ -21,10 +26,13 @@ import org.springframework.web.bind.annotation.RestController;
import
java.util.List
;
import
java.util.List
;
import
static
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
.
RequestPrecondition
.
checkArgument
;
import
static
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
.
RequestPrecondition
.
checkArgument
;
import
static
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
.
RequestPrecondition
.
checkModel
;
@RestController
@RestController
public
class
NamespaceController
{
public
class
NamespaceController
{
Logger
logger
=
LoggerFactory
.
getLogger
(
NamespaceController
.
class
);
@Autowired
@Autowired
private
ApplicationEventPublisher
publisher
;
private
ApplicationEventPublisher
publisher
;
@Autowired
@Autowired
...
@@ -37,13 +45,25 @@ public class NamespaceController {
...
@@ -37,13 +45,25 @@ public class NamespaceController {
return
namespaceService
.
findPublicAppNamespaces
();
return
namespaceService
.
findPublicAppNamespaces
();
}
}
@PreAuthorize
(
value
=
"@permissionValidator.hasCreateNamespacePermission(#namespace.appId)"
)
@PreAuthorize
(
value
=
"@permissionValidator.hasCreateNamespacePermission(#appId)"
)
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/apps/{appId}/namespaces"
,
method
=
RequestMethod
.
POST
)
public
NamespaceDTO
createNamespace
(
@PathVariable
String
env
,
@RequestBody
NamespaceDTO
namespace
)
{
public
ResponseEntity
<
Void
>
createNamespace
(
@PathVariable
String
appId
,
@RequestBody
List
<
NamespaceCreationModel
>
models
)
{
checkModel
(!
CollectionUtils
.
isEmpty
(
models
));
checkArgument
(
namespace
.
getAppId
(),
namespace
.
getClusterName
(),
namespace
.
getNamespaceName
());
for
(
NamespaceCreationModel
model
:
models
)
{
NamespaceDTO
namespace
=
model
.
getNamespace
();
return
namespaceService
.
createNamespace
(
Env
.
valueOf
(
env
),
namespace
);
checkArgument
(
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 error."
,
e
);
}
}
return
ResponseEntity
.
ok
().
build
();
}
}
@RequestMapping
(
value
=
"/apps/{appId}/appnamespaces"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"/apps/{appId}/appnamespaces"
,
method
=
RequestMethod
.
POST
)
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/cu
ms
omize/BizLoggingCustomizer.java
→
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/cu
st
omize/BizLoggingCustomizer.java
View file @
64483c44
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
cu
ms
omize
;
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
cu
st
omize
;
import
com.ctrip.framework.apollo.common.customize.LoggingCustomizer
;
import
com.ctrip.framework.apollo.common.customize.LoggingCustomizer
;
import
com.ctrip.framework.apollo.portal.repository.ServerConfigRepository
;
import
com.ctrip.framework.apollo.portal.repository.ServerConfigRepository
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/cu
ms
omize/package-info.java
→
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/cu
st
omize/package-info.java
View file @
64483c44
/**
/**
* 携程内部的日志系统,第三方公司可删除
* 携程内部的日志系统,第三方公司可删除
*/
*/
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
cu
ms
omize
;
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
cu
st
omize
;
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/form/NamespaceCreationModel.java
0 → 100644
View file @
64483c44
package
com
.
ctrip
.
framework
.
apollo
.
portal
.
entity
.
form
;
import
com.ctrip.framework.apollo.core.dto.NamespaceDTO
;
public
class
NamespaceCreationModel
{
private
String
env
;
private
NamespaceDTO
namespace
;
public
String
getEnv
()
{
return
env
;
}
public
void
setEnv
(
String
env
)
{
this
.
env
=
env
;
}
public
NamespaceDTO
getNamespace
()
{
return
namespace
;
}
public
void
setNamespace
(
NamespaceDTO
namespace
)
{
this
.
namespace
=
namespace
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
View file @
64483c44
...
@@ -11,6 +11,7 @@ import com.ctrip.framework.apollo.core.dto.ItemDTO;
...
@@ -11,6 +11,7 @@ import com.ctrip.framework.apollo.core.dto.ItemDTO;
import
com.ctrip.framework.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.framework.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.core.exception.ServiceException
;
import
com.ctrip.framework.apollo.core.exception.ServiceException
;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
...
@@ -97,6 +98,10 @@ public class NamespaceService {
...
@@ -97,6 +98,10 @@ public class NamespaceService {
@Transactional
@Transactional
public
AppNamespace
createAppNamespaceInLocal
(
AppNamespace
appNamespace
)
{
public
AppNamespace
createAppNamespaceInLocal
(
AppNamespace
appNamespace
)
{
//not unique
if
(
appNamespaceRepository
.
findByName
(
appNamespace
.
getName
())
!=
null
){
throw
new
BadRequestException
(
appNamespace
.
getName
()
+
"已存在"
);
}
AppNamespace
managedAppNamespace
=
appNamespaceRepository
.
findByAppIdAndName
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
());
AppNamespace
managedAppNamespace
=
appNamespaceRepository
.
findByAppIdAndName
(
appNamespace
.
getAppId
(),
appNamespace
.
getName
());
//update
//update
if
(
managedAppNamespace
!=
null
){
if
(
managedAppNamespace
!=
null
){
...
...
apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js
View file @
64483c44
...
@@ -15,7 +15,7 @@ namespace_module.controller("LinkNamespaceController",
...
@@ -15,7 +15,7 @@ namespace_module.controller("LinkNamespaceController",
namespace
.
id
=
item
.
name
;
namespace
.
id
=
item
.
name
;
namespace
.
text
=
item
.
name
;
namespace
.
text
=
item
.
name
;
publicNamespaces
.
push
(
namespace
);
publicNamespaces
.
push
(
namespace
);
});
});
$
(
'#namespaces'
).
select2
({
$
(
'#namespaces'
).
select2
({
width
:
'250px'
,
width
:
'250px'
,
data
:
publicNamespaces
data
:
publicNamespaces
...
@@ -47,22 +47,23 @@ namespace_module.controller("LinkNamespaceController",
...
@@ -47,22 +47,23 @@ namespace_module.controller("LinkNamespaceController",
}
}
var
hasCreatedClusterCnt
=
0
;
var
hasCreatedClusterCnt
=
0
;
var
namespaceCreationModels
=
[];
selectedClusters
.
forEach
(
function
(
cluster
)
{
selectedClusters
.
forEach
(
function
(
cluster
)
{
NamespaceService
.
createNamespace
(
$scope
.
appId
,
cluster
.
env
,
cluster
.
clusterName
,
namespaceCreationModels
.
push
({
$scope
.
namespaceName
).
then
(
function
(
result
)
{
env
:
cluster
.
env
,
toastr
.
success
(
namespace
:
{
cluster
.
env
+
"_"
+
result
.
clusterName
+
"_"
+
result
.
namespaceName
appId
:
$scope
.
appId
,
+
"创建成功"
);
clusterName
:
cluster
.
clusterName
,
hasCreatedClusterCnt
++
;
namespaceName
:
$scope
.
namespaceName
if
(
hasCreatedClusterCnt
==
selectedClustersSize
){
}
$scope
.
step
=
2
;
});
}
});
NamespaceService
.
createNamespace
(
$scope
.
appId
,
namespaceCreationModels
)
.
then
(
function
(
result
)
{
toastr
.
success
(
"创建成功"
);
},
function
(
result
)
{
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
toastr
.
error
(
AppUtil
.
errorMsg
(
result
));
cluster
.
env
+
"_"
+
cluster
.
clusterName
+
"_"
+
$scope
.
namespaceName
+
"创建失败"
);
});
});
});
}
else
{
}
else
{
NamespaceService
.
createAppNamespace
(
$scope
.
appId
,
$scope
.
appNamespace
).
then
(
function
(
result
)
{
NamespaceService
.
createAppNamespace
(
$scope
.
appId
,
$scope
.
appNamespace
).
then
(
function
(
result
)
{
$scope
.
step
=
2
;
$scope
.
step
=
2
;
...
@@ -79,7 +80,7 @@ namespace_module.controller("LinkNamespaceController",
...
@@ -79,7 +80,7 @@ namespace_module.controller("LinkNamespaceController",
};
};
$scope
.
back
=
function
()
{
$scope
.
back
=
function
()
{
$window
.
location
.
href
=
'/config.html?#appid='
+
$scope
.
appId
;
$window
.
location
.
href
=
'/config.html?#appid='
+
$scope
.
appId
;
};
};
}]);
}]);
apollo-portal/src/main/resources/static/scripts/services/NamespaceService.js
View file @
64483c44
...
@@ -7,7 +7,7 @@ appService.service("NamespaceService", ['$resource', '$q', function ($resource,
...
@@ -7,7 +7,7 @@ appService.service("NamespaceService", ['$resource', '$q', function ($resource,
},
},
createNamespace
:
{
createNamespace
:
{
method
:
'POST'
,
method
:
'POST'
,
url
:
'/apps/:appId/
envs/:env/clusters/:clusterName/
namespaces'
,
url
:
'/apps/:appId/namespaces'
,
isArray
:
false
isArray
:
false
},
},
createAppNamespace
:
{
createAppNamespace
:
{
...
@@ -27,17 +27,11 @@ appService.service("NamespaceService", ['$resource', '$q', function ($resource,
...
@@ -27,17 +27,11 @@ appService.service("NamespaceService", ['$resource', '$q', function ($resource,
});
});
return
d
.
promise
;
return
d
.
promise
;
},
},
createNamespace
:
function
(
appId
,
env
,
clusterName
,
namespaceName
)
{
createNamespace
:
function
(
appId
,
namespaceCreationModel
)
{
var
d
=
$q
.
defer
();
var
d
=
$q
.
defer
();
namespace_source
.
createNamespace
({
namespace_source
.
createNamespace
({
appId
:
appId
,
appId
:
appId
env
:
env
,
},
namespaceCreationModel
,
function
(
result
)
{
clusterName
:
clusterName
},
{
appId
:
appId
,
clusterName
:
clusterName
,
namespaceName
:
namespaceName
},
function
(
result
)
{
d
.
resolve
(
result
);
d
.
resolve
(
result
);
},
function
(
result
)
{
},
function
(
result
)
{
d
.
reject
(
result
);
d
.
reject
(
result
);
...
...
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