Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhangjian1949
apollo
提交
9b6a6985
apollo
项目概览
zhangjian1949
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9b6a6985
编写于
6月 17, 2016
作者:
L
lepdou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bugfix public appnamespace unique & repeat create namespace permission
上级
38f02745
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
84 addition
and
33 deletion
+84
-33
apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/GlobalDefaultExceptionHandler.java
...ollo/common/controller/GlobalDefaultExceptionHandler.java
+6
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java
...amework/apollo/portal/controller/NamespaceController.java
+24
-5
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/customize/BizLoggingCustomizer.java
...amework/apollo/portal/customize/BizLoggingCustomizer.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/customize/package-info.java
...ctrip/framework/apollo/portal/customize/package-info.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/form/NamespaceCreationModel.java
...ork/apollo/portal/entity/form/NamespaceCreationModel.java
+27
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
...rip/framework/apollo/portal/service/NamespaceService.java
+5
-0
apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js
...esources/static/scripts/controller/NamespaceController.js
+16
-15
apollo-portal/src/main/resources/static/scripts/services/NamespaceService.js
...ain/resources/static/scripts/services/NamespaceService.js
+4
-10
未找到文件。
apollo-common/src/main/java/com/ctrip/framework/apollo/common/controller/GlobalDefaultExceptionHandler.java
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录