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
9b6a6985
Commit
9b6a6985
authored
Jun 17, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bugfix public appnamespace unique & repeat create namespace permission
parent
38f02745
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
84 additions
and
33 deletions
+84
-33
GlobalDefaultExceptionHandler.java
...ollo/common/controller/GlobalDefaultExceptionHandler.java
+6
-1
NamespaceController.java
...amework/apollo/portal/controller/NamespaceController.java
+24
-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 @
9b6a6985
...
...
@@ -44,12 +44,17 @@ public class GlobalDefaultExceptionHandler {
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
,
ServletException
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
)
public
ResponseEntity
<
Map
<
String
,
Object
>>
notFound
(
HttpServletRequest
request
,
NotFoundException
ex
)
{
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java
View file @
9b6a6985
...
...
@@ -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.utils.StringUtils
;
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.listener.AppNamespaceCreationEvent
;
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.context.ApplicationEventPublisher
;
import
org.springframework.http.ResponseEntity
;
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.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -21,10 +26,13 @@ import org.springframework.web.bind.annotation.RestController;
import
java.util.List
;
import
static
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
.
RequestPrecondition
.
checkArgument
;
import
static
com
.
ctrip
.
framework
.
apollo
.
portal
.
util
.
RequestPrecondition
.
checkModel
;
@RestController
public
class
NamespaceController
{
Logger
logger
=
LoggerFactory
.
getLogger
(
NamespaceController
.
class
);
@Autowired
private
ApplicationEventPublisher
publisher
;
@Autowired
...
...
@@ -37,13 +45,24 @@ public class NamespaceController {
return
namespaceService
.
findPublicAppNamespaces
();
}
@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
)
{
@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
));
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
{
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
)
...
...
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 @
9b6a6985
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.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 @
9b6a6985
/**
* 携程内部的日志系统,第三方公司可删除
*/
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 @
9b6a6985
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 @
9b6a6985
...
...
@@ -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.ReleaseDTO
;
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.utils.StringUtils
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
...
...
@@ -97,6 +98,10 @@ public class NamespaceService {
@Transactional
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
());
//update
if
(
managedAppNamespace
!=
null
){
...
...
apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js
View file @
9b6a6985
...
...
@@ -15,7 +15,7 @@ namespace_module.controller("LinkNamespaceController",
namespace
.
id
=
item
.
name
;
namespace
.
text
=
item
.
name
;
publicNamespaces
.
push
(
namespace
);
});
});
$
(
'#namespaces'
).
select2
({
width
:
'250px'
,
data
:
publicNamespaces
...
...
@@ -47,22 +47,23 @@ namespace_module.controller("LinkNamespaceController",
}
var
hasCreatedClusterCnt
=
0
;
var
namespaceCreationModels
=
[];
selectedClusters
.
forEach
(
function
(
cluster
)
{
NamespaceService
.
createNamespace
(
$scope
.
appId
,
cluster
.
env
,
cluster
.
clusterName
,
$scope
.
namespaceName
).
then
(
function
(
result
)
{
toastr
.
success
(
cluster
.
env
+
"_"
+
result
.
clusterName
+
"_"
+
result
.
namespaceName
+
"创建成功"
);
hasCreatedClusterCnt
++
;
if
(
hasCreatedClusterCnt
==
selectedClustersSize
){
$scope
.
step
=
2
;
}
namespaceCreationModels
.
push
({
env
:
cluster
.
env
,
namespace
:
{
appId
:
$scope
.
appId
,
clusterName
:
cluster
.
clusterName
,
namespaceName
:
$scope
.
namespaceName
}
});
});
NamespaceService
.
createNamespace
(
$scope
.
appId
,
namespaceCreationModels
)
.
then
(
function
(
result
)
{
toastr
.
success
(
"创建成功"
);
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
cluster
.
env
+
"_"
+
cluster
.
clusterName
+
"_"
+
$scope
.
namespaceName
+
"创建失败"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
));
});
});
}
else
{
NamespaceService
.
createAppNamespace
(
$scope
.
appId
,
$scope
.
appNamespace
).
then
(
function
(
result
)
{
$scope
.
step
=
2
;
...
...
@@ -79,7 +80,7 @@ namespace_module.controller("LinkNamespaceController",
};
$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 @
9b6a6985
...
...
@@ -7,7 +7,7 @@ appService.service("NamespaceService", ['$resource', '$q', function ($resource,
},
createNamespace
:
{
method
:
'POST'
,
url
:
'/apps/:appId/
envs/:env/clusters/:clusterName/
namespaces'
,
url
:
'/apps/:appId/namespaces'
,
isArray
:
false
},
createAppNamespace
:
{
...
...
@@ -27,17 +27,11 @@ appService.service("NamespaceService", ['$resource', '$q', function ($resource,
});
return
d
.
promise
;
},
createNamespace
:
function
(
appId
,
env
,
clusterName
,
namespaceName
)
{
createNamespace
:
function
(
appId
,
namespaceCreationModel
)
{
var
d
=
$q
.
defer
();
namespace_source
.
createNamespace
({
appId
:
appId
,
env
:
env
,
clusterName
:
clusterName
},
{
appId
:
appId
,
clusterName
:
clusterName
,
namespaceName
:
namespaceName
},
function
(
result
)
{
appId
:
appId
},
namespaceCreationModel
,
function
(
result
)
{
d
.
resolve
(
result
);
},
function
(
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