Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
afa2a683
apollo
项目概览
superrain51
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
afa2a683
编写于
8月 10, 2016
作者:
J
Jason Song
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code reformat
上级
7b7d753f
变更
50
隐藏空白更改
内联
并排
Showing
50 changed file
with
331 addition
and
332 deletion
+331
-332
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/Consumer.java
...a/com/ctrip/framework/apollo/openapi/entity/Consumer.java
+1
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerRole.java
...m/ctrip/framework/apollo/openapi/entity/ConsumerRole.java
+5
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerToken.java
.../ctrip/framework/apollo/openapi/entity/ConsumerToken.java
+6
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ReleaseController.java
...ework/apollo/openapi/v1/controller/ReleaseController.java
+2
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalSettings.java
...ava/com/ctrip/framework/apollo/portal/PortalSettings.java
+2
-3
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
...om/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
+24
-24
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/RetryableRestTemplate.java
...ip/framework/apollo/portal/api/RetryableRestTemplate.java
+5
-5
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/PermissionValidator.java
...rip/framework/apollo/portal/auth/PermissionValidator.java
+12
-12
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/ctrip/CtripUserService.java
.../framework/apollo/portal/auth/ctrip/CtripUserService.java
+1
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/defaultimpl/DefaultUserInfoHolder.java
...apollo/portal/auth/defaultimpl/DefaultUserInfoHolder.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/defaultimpl/DefaultUserService.java
...rk/apollo/portal/auth/defaultimpl/DefaultUserService.java
+0
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/configuration/AuthConfiguration.java
...mework/apollo/portal/configuration/AuthConfiguration.java
+0
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/configuration/WebContextConfiguration.java
.../apollo/portal/configuration/WebContextConfiguration.java
+3
-3
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/constant/PermissionType.java
...trip/framework/apollo/portal/constant/PermissionType.java
+6
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java
...rip/framework/apollo/portal/controller/AppController.java
+4
-4
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ClusterController.java
...framework/apollo/portal/controller/ClusterController.java
+3
-3
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/CommitController.java
.../framework/apollo/portal/controller/CommitController.java
+2
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/EnvController.java
...rip/framework/apollo/portal/controller/EnvController.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ItemController.java
...ip/framework/apollo/portal/controller/ItemController.java
+16
-17
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java
...amework/apollo/portal/controller/NamespaceController.java
+4
-4
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceLockController.java
...ork/apollo/portal/controller/NamespaceLockController.java
+2
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PermissionController.java
...mework/apollo/portal/controller/PermissionController.java
+18
-19
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ReleaseController.java
...framework/apollo/portal/controller/ReleaseController.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/UserInfoController.java
...ramework/apollo/portal/controller/UserInfoController.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/customize/BizLoggingCustomizer.java
...amework/apollo/portal/customize/BizLoggingCustomizer.java
+3
-3
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/form/NamespaceReleaseModel.java
...work/apollo/portal/entity/form/NamespaceReleaseModel.java
+5
-5
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/form/NamespaceSyncModel.java
...amework/apollo/portal/entity/form/NamespaceSyncModel.java
+3
-3
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/form/NamespaceTextModel.java
...amework/apollo/portal/entity/form/NamespaceTextModel.java
+2
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/EnvClusterInfo.java
...rip/framework/apollo/portal/entity/vo/EnvClusterInfo.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/ItemDiffs.java
...om/ctrip/framework/apollo/portal/entity/vo/ItemDiffs.java
+2
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/NamespaceIdentifier.java
...ramework/apollo/portal/entity/vo/NamespaceIdentifier.java
+5
-5
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/NamespaceVO.java
.../ctrip/framework/apollo/portal/entity/vo/NamespaceVO.java
+2
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/enums/ChangeType.java
...a/com/ctrip/framework/apollo/portal/enums/ChangeType.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/CreationListener.java
...ip/framework/apollo/portal/listener/CreationListener.java
+2
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppNamespaceRepository.java
...work/apollo/portal/repository/AppNamespaceRepository.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/PermissionRepository.java
...mework/apollo/portal/repository/PermissionRepository.java
+1
-4
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/RoleRepository.java
...ip/framework/apollo/portal/repository/RoleRepository.java
+0
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/UserRoleRepository.java
...ramework/apollo/portal/repository/UserRoleRepository.java
+0
-8
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java
.../framework/apollo/portal/service/AppNamespaceService.java
+2
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java
...com/ctrip/framework/apollo/portal/service/AppService.java
+13
-13
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ClusterService.java
...ctrip/framework/apollo/portal/service/ClusterService.java
+4
-4
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/CommitService.java
.../ctrip/framework/apollo/portal/service/CommitService.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java
...om/ctrip/framework/apollo/portal/service/ItemService.java
+18
-18
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceLockService.java
...framework/apollo/portal/service/NamespaceLockService.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
...rip/framework/apollo/portal/service/NamespaceService.java
+13
-13
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ReleaseService.java
...ctrip/framework/apollo/portal/service/ReleaseService.java
+105
-105
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RoleInitializationService.java
...work/apollo/portal/service/RoleInitializationService.java
+4
-4
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/txtresolver/FileTextResolver.java
...k/apollo/portal/service/txtresolver/FileTextResolver.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/txtresolver/PropertyResolver.java
...k/apollo/portal/service/txtresolver/PropertyResolver.java
+11
-11
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java
...ava/com/ctrip/framework/apollo/portal/util/RoleUtils.java
+10
-9
未找到文件。
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/Consumer.java
浏览文件 @
afa2a683
...
...
@@ -81,6 +81,7 @@ public class Consumer extends BaseEntity {
this
.
ownerName
=
ownerName
;
}
@Override
public
String
toString
()
{
return
toStringHelper
().
add
(
"name"
,
name
).
add
(
"appId"
,
appId
)
.
add
(
"orgId"
,
orgId
)
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerRole.java
浏览文件 @
afa2a683
...
...
@@ -38,4 +38,9 @@ public class ConsumerRole extends BaseEntity {
public
void
setRoleId
(
long
roleId
)
{
this
.
roleId
=
roleId
;
}
@Override
public
String
toString
()
{
return
toStringHelper
().
add
(
"consumerId"
,
consumerId
).
add
(
"roleId"
,
roleId
).
toString
();
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/entity/ConsumerToken.java
浏览文件 @
afa2a683
...
...
@@ -51,4 +51,10 @@ public class ConsumerToken extends BaseEntity {
public
void
setExpires
(
Date
expires
)
{
this
.
expires
=
expires
;
}
@Override
public
String
toString
()
{
return
toStringHelper
().
add
(
"consumerId"
,
consumerId
).
add
(
"token"
,
token
)
.
add
(
"expires"
,
expires
).
toString
();
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ReleaseController.java
浏览文件 @
afa2a683
...
...
@@ -42,11 +42,11 @@ public class ReleaseController {
HttpServletRequest
request
)
{
checkModel
(
model
!=
null
);
RequestPrecondition
.
checkArguments
(!
StringUtils
.
isContainEmpty
(
model
.
getReleaseBy
(),
model
RequestPrecondition
.
checkArguments
(!
StringUtils
.
isContainEmpty
(
model
.
getRelease
d
By
(),
model
.
getReleaseTitle
()),
"releaseTitle and releaseBy can not be empty"
);
if
(
userService
.
findByUserId
(
model
.
getReleaseBy
())
==
null
)
{
if
(
userService
.
findByUserId
(
model
.
getRelease
d
By
())
==
null
)
{
throw
new
BadRequestException
(
"用户不存在."
);
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalSettings.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.service.ServerConfigService
;
...
...
@@ -67,11 +66,11 @@ public class PortalSettings {
healthCheckService
.
scheduleWithFixedDelay
(
new
HealthCheckTask
(
applicationContext
),
1000
,
HEALTH_CHECK_INTERVAL
,
TimeUnit
.
MILLISECONDS
);
TimeUnit
.
MILLISECONDS
);
}
public
List
<
Env
>
getAllEnvs
(){
public
List
<
Env
>
getAllEnvs
()
{
return
allEnvs
;
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.api
;
import
com.ctrip.framework.apollo.common.dto.AppNamespaceDTO
;
import
com.ctrip.framework.apollo.common.dto.CommitDTO
;
import
com.ctrip.framework.apollo.common.dto.NamespaceLockDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.common.dto.AppDTO
;
import
com.ctrip.framework.apollo.common.dto.AppNamespaceDTO
;
import
com.ctrip.framework.apollo.common.dto.ClusterDTO
;
import
com.ctrip.framework.apollo.common.dto.CommitDTO
;
import
com.ctrip.framework.apollo.common.dto.ItemChangeSets
;
import
com.ctrip.framework.apollo.common.dto.ItemDTO
;
import
com.ctrip.framework.apollo.common.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.common.dto.NamespaceLockDTO
;
import
com.ctrip.framework.apollo.common.dto.ReleaseDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.http.HttpEntity
;
...
...
@@ -53,8 +53,8 @@ public class AdminServiceAPI {
public
List
<
NamespaceDTO
>
findNamespaceByCluster
(
String
appId
,
Env
env
,
String
clusterName
)
{
NamespaceDTO
[]
namespaceDTOs
=
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces"
,
NamespaceDTO
[].
class
,
appId
,
clusterName
);
NamespaceDTO
[].
class
,
appId
,
clusterName
);
return
Arrays
.
asList
(
namespaceDTOs
);
}
...
...
@@ -62,7 +62,7 @@ public class AdminServiceAPI {
String
namespaceName
)
{
NamespaceDTO
dto
=
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}"
,
NamespaceDTO
.
class
,
appId
,
clusterName
,
namespaceName
);
NamespaceDTO
.
class
,
appId
,
clusterName
,
namespaceName
);
return
dto
;
}
...
...
@@ -70,7 +70,7 @@ public class AdminServiceAPI {
public
NamespaceDTO
createNamespace
(
Env
env
,
NamespaceDTO
namespace
)
{
return
restTemplate
.
post
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces"
,
namespace
,
NamespaceDTO
.
class
,
namespace
.
getAppId
(),
namespace
.
getClusterName
());
namespace
.
getAppId
(),
namespace
.
getClusterName
());
}
public
AppNamespaceDTO
createAppNamespace
(
Env
env
,
AppNamespaceDTO
appNamespace
)
{
...
...
@@ -86,7 +86,7 @@ public class AdminServiceAPI {
public
List
<
ItemDTO
>
findItems
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
ItemDTO
[]
itemDTOs
=
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
ItemDTO
[].
class
,
appId
,
clusterName
,
namespaceName
);
ItemDTO
[].
class
,
appId
,
clusterName
,
namespaceName
);
return
Arrays
.
asList
(
itemDTOs
);
}
...
...
@@ -97,18 +97,18 @@ public class AdminServiceAPI {
public
void
updateItemsByChangeSet
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
ItemChangeSets
changeSets
)
{
restTemplate
.
post
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset"
,
changeSets
,
Void
.
class
,
appId
,
clusterName
,
namespace
);
changeSets
,
Void
.
class
,
appId
,
clusterName
,
namespace
);
}
public
void
updateItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
long
itemId
,
ItemDTO
item
)
{
restTemplate
.
put
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{itemId}"
,
item
,
appId
,
clusterName
,
namespace
,
itemId
);
item
,
appId
,
clusterName
,
namespace
,
itemId
);
}
public
ItemDTO
createItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
ItemDTO
item
)
{
return
restTemplate
.
post
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
item
,
ItemDTO
.
class
,
appId
,
clusterName
,
namespace
);
item
,
ItemDTO
.
class
,
appId
,
clusterName
,
namespace
);
}
public
void
deleteItem
(
Env
env
,
long
itemId
,
String
operator
)
{
...
...
@@ -122,25 +122,25 @@ public class AdminServiceAPI {
public
List
<
ClusterDTO
>
findClustersByApp
(
String
appId
,
Env
env
)
{
ClusterDTO
[]
clusterDTOs
=
restTemplate
.
get
(
env
,
"apps/{appId}/clusters"
,
ClusterDTO
[].
class
,
appId
);
appId
);
return
Arrays
.
asList
(
clusterDTOs
);
}
public
ClusterDTO
loadCluster
(
String
appId
,
Env
env
,
String
clusterName
)
{
return
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}"
,
ClusterDTO
.
class
,
appId
,
clusterName
);
appId
,
clusterName
);
}
public
boolean
isClusterUnique
(
String
appId
,
Env
env
,
String
clusterName
)
{
return
restTemplate
.
get
(
env
,
"apps/{appId}/cluster/{clusterName}/unique"
,
Boolean
.
class
,
appId
,
clusterName
);
appId
,
clusterName
);
}
public
ClusterDTO
create
(
Env
env
,
ClusterDTO
cluster
)
{
return
restTemplate
.
post
(
env
,
"apps/{appId}/clusters"
,
cluster
,
ClusterDTO
.
class
,
cluster
.
getAppId
());
cluster
.
getAppId
());
}
}
...
...
@@ -174,7 +174,7 @@ public class AdminServiceAPI {
String
namespace
)
{
ReleaseDTO
releaseDTO
=
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/latest"
,
ReleaseDTO
.
class
,
appId
,
clusterName
,
namespace
);
ReleaseDTO
.
class
,
appId
,
clusterName
,
namespace
);
return
releaseDTO
;
}
...
...
@@ -197,8 +197,8 @@ public class AdminServiceAPI {
public
void
rollback
(
Env
env
,
long
releaseId
,
String
operator
)
{
restTemplate
.
put
(
env
,
"releases/{releaseId}/rollback?operator={operator}"
,
null
,
releaseId
,
operator
);
"releases/{releaseId}/rollback?operator={operator}"
,
null
,
releaseId
,
operator
);
}
}
...
...
@@ -208,9 +208,9 @@ public class AdminServiceAPI {
public
List
<
CommitDTO
>
find
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
int
page
,
int
size
)
{
CommitDTO
[]
commitDTOs
=
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit?page={page}&size={size}"
,
CommitDTO
[].
class
,
appId
,
clusterName
,
namespaceName
,
page
,
size
);
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit?page={page}&size={size}"
,
CommitDTO
[].
class
,
appId
,
clusterName
,
namespaceName
,
page
,
size
);
return
Arrays
.
asList
(
commitDTOs
);
}
...
...
@@ -221,8 +221,8 @@ public class AdminServiceAPI {
public
NamespaceLockDTO
getNamespaceLockOwner
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
return
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock"
,
NamespaceLockDTO
.
class
,
appId
,
clusterName
,
namespaceName
);
NamespaceLockDTO
.
class
,
appId
,
clusterName
,
namespaceName
);
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/RetryableRestTemplate.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.api
;
import
com.ctrip.framework.apollo.common.exception.ServiceException
;
import
com.ctrip.framework.apollo.core.dto.ServiceDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.common.exception.ServiceException
;
import
com.ctrip.framework.apollo.portal.constant.CatEventType
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.message.Message
;
...
...
@@ -66,7 +66,7 @@ public class RetryableRestTemplate {
private
<
T
>
T
execute
(
HttpMethod
method
,
Env
env
,
String
path
,
Object
request
,
Class
<
T
>
responseType
,
Object
...
uriVariables
)
{
if
(
path
.
startsWith
(
"/"
)){
if
(
path
.
startsWith
(
"/"
))
{
path
=
path
.
substring
(
1
,
path
.
length
());
}
...
...
@@ -143,11 +143,11 @@ public class RetryableRestTemplate {
Throwable
nestedException
=
e
.
getCause
();
if
(
method
==
HttpMethod
.
GET
)
{
return
nestedException
instanceof
SocketTimeoutException
||
nestedException
instanceof
HttpHostConnectException
||
nestedException
instanceof
ConnectTimeoutException
;
||
nestedException
instanceof
HttpHostConnectException
||
nestedException
instanceof
ConnectTimeoutException
;
}
else
{
return
nestedException
instanceof
HttpHostConnectException
||
nestedException
instanceof
ConnectTimeoutException
;
||
nestedException
instanceof
ConnectTimeoutException
;
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/PermissionValidator.java
浏览文件 @
afa2a683
...
...
@@ -18,42 +18,42 @@ public class PermissionValidator {
public
boolean
hasModifyNamespacePermission
(
String
appId
,
String
namespaceName
)
{
return
rolePermissionService
.
userHasPermission
(
userInfoHolder
.
getUser
().
getUserId
(),
PermissionType
.
MODIFY_NAMESPACE
,
RoleUtils
.
buildNamespaceTargetId
(
appId
,
namespaceName
));
PermissionType
.
MODIFY_NAMESPACE
,
RoleUtils
.
buildNamespaceTargetId
(
appId
,
namespaceName
));
}
public
boolean
hasReleaseNamespacePermission
(
String
appId
,
String
namespaceName
)
{
return
rolePermissionService
.
userHasPermission
(
userInfoHolder
.
getUser
().
getUserId
(),
PermissionType
.
RELEASE_NAMESPACE
,
RoleUtils
.
buildNamespaceTargetId
(
appId
,
namespaceName
));
PermissionType
.
RELEASE_NAMESPACE
,
RoleUtils
.
buildNamespaceTargetId
(
appId
,
namespaceName
));
}
public
boolean
hasAssignRolePermission
(
String
appId
)
{
return
rolePermissionService
.
userHasPermission
(
userInfoHolder
.
getUser
().
getUserId
(),
PermissionType
.
ASSIGN_ROLE
,
appId
);
PermissionType
.
ASSIGN_ROLE
,
appId
);
}
public
boolean
hasCreateNamespacePermission
(
String
appId
)
{
return
rolePermissionService
.
userHasPermission
(
userInfoHolder
.
getUser
().
getUserId
(),
PermissionType
.
CREATE_NAMESPACE
,
appId
);
PermissionType
.
CREATE_NAMESPACE
,
appId
);
}
public
boolean
hasCreateClusterPermission
(
String
appId
)
{
return
rolePermissionService
.
userHasPermission
(
userInfoHolder
.
getUser
().
getUserId
(),
PermissionType
.
CREATE_CLUSTER
,
appId
);
PermissionType
.
CREATE_CLUSTER
,
appId
);
}
public
boolean
hasCreateAppNamespacePermission
(
String
appId
,
AppNamespace
appNamespace
)
{
boolean
isPublicAppNamespace
=
appNamespace
.
isPublic
();
if
(
isPublicAppNamespace
){
if
(
isPublicAppNamespace
)
{
return
hasCreateNamespacePermission
(
appId
);
}
else
{
}
else
{
return
rolePermissionService
.
isSuperAdmin
(
userInfoHolder
.
getUser
().
getUserId
());
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/ctrip/CtripUserService.java
浏览文件 @
afa2a683
...
...
@@ -14,7 +14,6 @@ import org.springframework.http.HttpMethod;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.client.ClientHttpRequestFactory
;
import
org.springframework.http.client.SimpleClientHttpRequestFactory
;
import
org.springframework.http.converter.json.GsonHttpMessageConverter
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.client.RestTemplate
;
...
...
@@ -62,7 +61,7 @@ public class CtripUserService implements UserService {
}
@Override
public
List
<
UserInfo
>
searchUsers
(
String
keyword
,
int
offset
,
int
limit
)
{
public
List
<
UserInfo
>
searchUsers
(
String
keyword
,
int
offset
,
int
limit
)
{
UserServiceRequest
request
=
assembleSearchUserRequest
(
keyword
,
offset
,
limit
);
HttpEntity
<
UserServiceRequest
>
entity
=
new
HttpEntity
<>(
request
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/defaultimpl/DefaultUserInfoHolder.java
浏览文件 @
afa2a683
...
...
@@ -9,7 +9,7 @@ import com.ctrip.framework.apollo.portal.entity.po.UserInfo;
public
class
DefaultUserInfoHolder
implements
UserInfoHolder
{
public
DefaultUserInfoHolder
(){
public
DefaultUserInfoHolder
()
{
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/defaultimpl/DefaultUserService.java
浏览文件 @
afa2a683
...
...
@@ -6,7 +6,6 @@ import com.ctrip.framework.apollo.portal.entity.po.UserInfo;
import
com.ctrip.framework.apollo.portal.service.UserService
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
/**
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/configuration/AuthConfiguration.java
浏览文件 @
afa2a683
...
...
@@ -3,7 +3,6 @@ package com.ctrip.framework.apollo.portal.configuration;
import
com.google.common.collect.Maps
;
import
com.ctrip.framework.apollo.openapi.filter.ConsumerAuthenticationFilter
;
import
com.ctrip.framework.apollo.openapi.service.ConsumerService
;
import
com.ctrip.framework.apollo.openapi.util.ConsumerAuthUtil
;
import
com.ctrip.framework.apollo.portal.auth.LogoutHandler
;
import
com.ctrip.framework.apollo.portal.auth.SsoHeartbeatHandler
;
...
...
@@ -28,7 +27,6 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.context.annotation.Profile
;
import
java.util.EventListener
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.servlet.Filter
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/configuration/WebContextConfiguration.java
浏览文件 @
afa2a683
...
...
@@ -36,11 +36,11 @@ public class WebContextConfiguration {
String
loggingServerPort
=
serverConfigService
.
getValue
(
"loggingServerPort"
);
String
credisServiceUrl
=
serverConfigService
.
getValue
(
"credisServiceUrl"
);
servletContext
.
setInitParameter
(
"loggingServerIP"
,
Strings
.
isNullOrEmpty
(
loggingServerIP
)
?
""
:
loggingServerIP
);
Strings
.
isNullOrEmpty
(
loggingServerIP
)
?
""
:
loggingServerIP
);
servletContext
.
setInitParameter
(
"loggingServerPort"
,
Strings
.
isNullOrEmpty
(
loggingServerPort
)
?
""
:
loggingServerPort
);
Strings
.
isNullOrEmpty
(
loggingServerPort
)
?
""
:
loggingServerPort
);
servletContext
.
setInitParameter
(
"credisServiceUrl"
,
Strings
.
isNullOrEmpty
(
credisServiceUrl
)
?
""
:
credisServiceUrl
);
Strings
.
isNullOrEmpty
(
credisServiceUrl
)
?
""
:
credisServiceUrl
);
}
};
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/constant/PermissionType.java
浏览文件 @
afa2a683
...
...
@@ -2,7 +2,9 @@ package com.ctrip.framework.apollo.portal.constant;
public
interface
PermissionType
{
/** APP level permission */
/**
* APP level permission
*/
String
CREATE_NAMESPACE
=
"CreateNamespace"
;
...
...
@@ -13,7 +15,9 @@ public interface PermissionType {
*/
String
ASSIGN_ROLE
=
"AssignRole"
;
/** namespace level permission*/
/**
* namespace level permission
*/
String
MODIFY_NAMESPACE
=
"ModifyNamespace"
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/AppController.java
浏览文件 @
afa2a683
...
...
@@ -2,12 +2,12 @@ package com.ctrip.framework.apollo.portal.controller;
import
com.ctrip.framework.apollo.common.entity.App
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.http.MultiResponseEntity
;
import
com.ctrip.framework.apollo.common.http.RichResponseEntity
;
import
com.ctrip.framework.apollo.common.utils.InputValidator
;
import
com.ctrip.framework.apollo.common.utils.RequestPrecondition
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
import
com.ctrip.framework.apollo.portal.entity.po.UserInfo
;
import
com.ctrip.framework.apollo.portal.entity.vo.EnvClusterInfo
;
...
...
@@ -76,13 +76,13 @@ public class AppController {
public
ResponseEntity
<
Void
>
create
(
@RequestBody
App
app
)
{
RequestPrecondition
.
checkArgumentsNotEmpty
(
app
.
getName
(),
app
.
getAppId
(),
app
.
getOwnerName
(),
app
.
getOrgId
(),
app
.
getOrgName
());
app
.
getOrgId
(),
app
.
getOrgName
());
if
(!
InputValidator
.
isValidClusterNamespace
(
app
.
getAppId
()))
{
throw
new
BadRequestException
(
String
.
format
(
"AppId格式错误: %s"
,
InputValidator
.
INVALID_CLUSTER_NAMESPACE_MESSAGE
));
}
UserInfo
userInfo
=
userService
.
findByUserId
(
app
.
getOwnerName
());
if
(
userInfo
==
null
){
if
(
userInfo
==
null
)
{
throw
new
BadRequestException
(
"应用负责人不存在"
);
}
app
.
setOwnerEmail
(
userInfo
.
getEmail
());
...
...
@@ -99,7 +99,7 @@ public class AppController {
public
ResponseEntity
<
Void
>
create
(
@PathVariable
String
env
,
@RequestBody
App
app
)
{
RequestPrecondition
.
checkArgumentsNotEmpty
(
app
.
getName
(),
app
.
getAppId
(),
app
.
getOwnerEmail
(),
app
.
getOwnerName
(),
app
.
getOrgId
(),
app
.
getOrgName
());
app
.
getOrgId
(),
app
.
getOrgName
());
if
(!
InputValidator
.
isValidClusterNamespace
(
app
.
getAppId
()))
{
throw
new
BadRequestException
(
InputValidator
.
INVALID_CLUSTER_NAMESPACE_MESSAGE
);
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ClusterController.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.controller
;
import
com.ctrip.framework.apollo.common.utils.InputValidator
;
import
com.ctrip.framework.apollo.common.dto.ClusterDTO
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.utils.InputValidator
;
import
com.ctrip.framework.apollo.common.utils.RequestPrecondition
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.service.ClusterService
;
...
...
@@ -29,7 +29,7 @@ public class ClusterController {
@PreAuthorize
(
value
=
"@permissionValidator.hasCreateClusterPermission(#appId)"
)
@RequestMapping
(
value
=
"apps/{appId}/envs/{env}/clusters"
,
method
=
RequestMethod
.
POST
)
public
ClusterDTO
createCluster
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@RequestBody
ClusterDTO
cluster
){
@RequestBody
ClusterDTO
cluster
)
{
checkModel
(
cluster
!=
null
);
RequestPrecondition
.
checkArgumentsNotEmpty
(
cluster
.
getAppId
(),
cluster
.
getName
());
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/CommitController.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.controller
;
import
com.ctrip.framework.apollo.common.utils.RequestPrecondition
;
import
com.ctrip.framework.apollo.common.dto.CommitDTO
;
import
com.ctrip.framework.apollo.common.utils.RequestPrecondition
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.service.CommitService
;
...
...
@@ -23,7 +23,7 @@ public class CommitController {
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/commits"
)
public
List
<
CommitDTO
>
find
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestParam
(
defaultValue
=
"0"
)
int
page
,
@RequestParam
(
defaultValue
=
"10"
)
int
size
){
@RequestParam
(
defaultValue
=
"0"
)
int
page
,
@RequestParam
(
defaultValue
=
"10"
)
int
size
)
{
RequestPrecondition
.
checkNumberPositive
(
size
);
RequestPrecondition
.
checkNumberNotNegative
(
page
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/EnvController.java
浏览文件 @
afa2a683
...
...
@@ -18,7 +18,7 @@ public class EnvController {
private
PortalSettings
portalSettings
;
@RequestMapping
(
value
=
""
,
method
=
RequestMethod
.
GET
)
public
List
<
Env
>
envs
(){
public
List
<
Env
>
envs
()
{
return
portalSettings
.
getActiveEnvs
();
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ItemController.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.controller
;
import
com.ctrip.framework.apollo.common.dto.ItemDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
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.ItemDiffs
;
import
com.ctrip.framework.apollo.portal.entity.form.NamespaceSyncModel
;
import
com.ctrip.framework.apollo.portal.entity.form.NamespaceTextModel
;
import
com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs
;
import
com.ctrip.framework.apollo.portal.service.ItemService
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -38,8 +38,8 @@ public class ItemController {
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
method
=
RequestMethod
.
PUT
,
consumes
=
{
"application/json"
})
public
void
modifyItemsByText
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
NamespaceTextModel
model
)
{
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
NamespaceTextModel
model
)
{
checkModel
(
model
!=
null
);
...
...
@@ -55,7 +55,7 @@ public class ItemController {
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/item"
,
method
=
RequestMethod
.
POST
)
public
ItemDTO
createItem
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
ItemDTO
item
){
@RequestBody
ItemDTO
item
)
{
checkModel
(
isValidItem
(
item
));
return
configService
.
createItem
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
,
item
);
...
...
@@ -64,8 +64,8 @@ public class ItemController {
@PreAuthorize
(
value
=
"@permissionValidator.hasModifyNamespacePermission(#appId, #namespaceName)"
)
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/item"
,
method
=
RequestMethod
.
PUT
)
public
void
updateItem
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
ItemDTO
item
)
{
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestBody
ItemDTO
item
)
{
checkModel
(
isValidItem
(
item
));
configService
.
updateItem
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
,
item
);
...
...
@@ -76,27 +76,26 @@ public class ItemController {
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items/{itemId}"
,
method
=
RequestMethod
.
DELETE
)
public
void
deleteItem
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@PathVariable
long
itemId
)
{
if
(
itemId
<=
0
){
@PathVariable
long
itemId
)
{
if
(
itemId
<=
0
)
{
throw
new
BadRequestException
(
"item id invalid"
);
}
configService
.
deleteItem
(
Env
.
valueOf
(
env
),
itemId
,
userInfoHolder
.
getUser
().
getUserId
());
}
@RequestMapping
(
value
=
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/items"
)
public
List
<
ItemDTO
>
findItems
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
,
@RequestParam
(
defaultValue
=
"lineNum"
)
String
orderBy
){
@RequestParam
(
defaultValue
=
"lineNum"
)
String
orderBy
)
{
List
<
ItemDTO
>
items
=
configService
.
findItems
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
);
if
(
"lastModifiedTime"
.
equals
(
orderBy
)){
if
(
"lastModifiedTime"
.
equals
(
orderBy
))
{
Collections
.
sort
(
items
,
(
o1
,
o2
)
->
{
if
(
o1
.
getDataChangeLastModifiedTime
().
after
(
o2
.
getDataChangeLastModifiedTime
())){
if
(
o1
.
getDataChangeLastModifiedTime
().
after
(
o2
.
getDataChangeLastModifiedTime
()))
{
return
-
1
;
}
if
(
o1
.
getDataChangeLastModifiedTime
().
before
(
o2
.
getDataChangeLastModifiedTime
())){
if
(
o1
.
getDataChangeLastModifiedTime
().
before
(
o2
.
getDataChangeLastModifiedTime
()))
{
return
1
;
}
return
0
;
...
...
@@ -107,7 +106,7 @@ public class ItemController {
@RequestMapping
(
value
=
"/namespaces/{namespaceName}/diff"
,
method
=
RequestMethod
.
POST
,
consumes
=
{
"application/json"
})
public
List
<
ItemDiffs
>
diff
(
@RequestBody
NamespaceSyncModel
model
){
public
List
<
ItemDiffs
>
diff
(
@RequestBody
NamespaceSyncModel
model
)
{
checkModel
(
model
!=
null
&&
!
model
.
isInvalid
());
return
configService
.
compare
(
model
.
getSyncToNamespaces
(),
model
.
getSyncItems
());
...
...
@@ -117,14 +116,14 @@ public class ItemController {
@RequestMapping
(
value
=
"/apps/{appId}/namespaces/{namespaceName}/items"
,
method
=
RequestMethod
.
PUT
,
consumes
=
{
"application/json"
})
public
ResponseEntity
<
Void
>
update
(
@PathVariable
String
appId
,
@PathVariable
String
namespaceName
,
@RequestBody
NamespaceSyncModel
model
){
@RequestBody
NamespaceSyncModel
model
)
{
checkModel
(
model
!=
null
&&
!
model
.
isInvalid
());
configService
.
syncItems
(
model
.
getSyncToNamespaces
(),
model
.
getSyncItems
());
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
build
();
}
private
boolean
isValidItem
(
ItemDTO
item
){
private
boolean
isValidItem
(
ItemDTO
item
)
{
return
item
!=
null
&&
!
StringUtils
.
isContainEmpty
(
item
.
getKey
());
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceController.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.controller
;
import
com.ctrip.framework.apollo.common.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.common.entity.App
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.utils.InputValidator
;
import
com.ctrip.framework.apollo.common.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.common.utils.RequestPrecondition
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
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
;
...
...
@@ -93,8 +93,8 @@ public class NamespaceController {
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
));
InputValidator
.
INVALID_CLUSTER_NAMESPACE_MESSAGE
+
" & "
+
InputValidator
.
INVALID_NAMESPACE_NAMESPACE_MESSAGE
));
}
//add app org id as prefix
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/NamespaceLockController.java
浏览文件 @
afa2a683
...
...
@@ -17,9 +17,9 @@ public class NamespaceLockController {
@RequestMapping
(
"/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces/{namespaceName}/lock"
)
public
NamespaceLockDTO
getNamespaceLock
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
){
@PathVariable
String
clusterName
,
@PathVariable
String
namespaceName
)
{
return
namespaceLockService
.
getNamespaceLock
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
);
return
namespaceLockService
.
getNamespaceLock
(
appId
,
Env
.
valueOf
(
env
),
clusterName
,
namespaceName
);
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/PermissionController.java
浏览文件 @
afa2a683
...
...
@@ -28,7 +28,6 @@ import org.springframework.web.bind.annotation.RestController;
import
java.util.Set
;
@RestController
public
class
PermissionController
{
...
...
@@ -56,13 +55,13 @@ public class PermissionController {
permissionCondition
.
setHasPermission
(
rolePermissionService
.
userHasPermission
(
userInfoHolder
.
getUser
().
getUserId
(),
permissionType
,
RoleUtils
.
buildNamespaceTargetId
(
appId
,
namespaceName
)));
RoleUtils
.
buildNamespaceTargetId
(
appId
,
namespaceName
)));
return
ResponseEntity
.
ok
().
body
(
permissionCondition
);
}
@RequestMapping
(
"/permissions/root"
)
public
ResponseEntity
<
PermissionCondition
>
hasRootPermission
(){
public
ResponseEntity
<
PermissionCondition
>
hasRootPermission
()
{
PermissionCondition
permissionCondition
=
new
PermissionCondition
();
permissionCondition
.
setHasPermission
(
rolePermissionService
.
isSuperAdmin
(
userInfoHolder
.
getUser
().
getUserId
()));
...
...
@@ -72,7 +71,7 @@ public class PermissionController {
@RequestMapping
(
"/apps/{appId}/namespaces/{namespaceName}/role_users"
)
public
NamespaceRolesAssignedUsers
getNamespaceRoles
(
@PathVariable
String
appId
,
@PathVariable
String
namespaceName
){
public
NamespaceRolesAssignedUsers
getNamespaceRoles
(
@PathVariable
String
appId
,
@PathVariable
String
namespaceName
)
{
NamespaceRolesAssignedUsers
assignedUsers
=
new
NamespaceRolesAssignedUsers
();
assignedUsers
.
setNamespaceName
(
namespaceName
);
...
...
@@ -92,16 +91,16 @@ public class PermissionController {
@PreAuthorize
(
value
=
"@permissionValidator.hasAssignRolePermission(#appId)"
)
@RequestMapping
(
value
=
"/apps/{appId}/namespaces/{namespaceName}/roles/{roleType}"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
Void
>
assignNamespaceRoleToUser
(
@PathVariable
String
appId
,
@PathVariable
String
namespaceName
,
@PathVariable
String
roleType
,
@RequestBody
String
user
){
@PathVariable
String
roleType
,
@RequestBody
String
user
)
{
checkUserExists
(
user
);
RequestPrecondition
.
checkArgumentsNotEmpty
(
user
);
if
(!
RoleType
.
isValidRoleType
(
roleType
)){
if
(!
RoleType
.
isValidRoleType
(
roleType
))
{
throw
new
BadRequestException
(
"role type is illegal"
);
}
Set
<
String
>
assignedUser
=
rolePermissionService
.
assignRoleToUsers
(
RoleUtils
.
buildNamespaceRoleName
(
appId
,
namespaceName
,
roleType
),
Sets
.
newHashSet
(
user
),
userInfoHolder
.
getUser
().
getUserId
());
if
(
CollectionUtils
.
isEmpty
(
assignedUser
)){
Sets
.
newHashSet
(
user
),
userInfoHolder
.
getUser
().
getUserId
());
if
(
CollectionUtils
.
isEmpty
(
assignedUser
))
{
throw
new
BadRequestException
(
user
+
"已授权"
);
}
...
...
@@ -111,19 +110,19 @@ public class PermissionController {
@PreAuthorize
(
value
=
"@permissionValidator.hasAssignRolePermission(#appId)"
)
@RequestMapping
(
value
=
"/apps/{appId}/namespaces/{namespaceName}/roles/{roleType}"
,
method
=
RequestMethod
.
DELETE
)
public
ResponseEntity
<
Void
>
removeNamespaceRoleFromUser
(
@PathVariable
String
appId
,
@PathVariable
String
namespaceName
,
@PathVariable
String
roleType
,
@RequestParam
String
user
)
{
@PathVariable
String
roleType
,
@RequestParam
String
user
)
{
RequestPrecondition
.
checkArgumentsNotEmpty
(
user
);
if
(!
RoleType
.
isValidRoleType
(
roleType
)){
if
(!
RoleType
.
isValidRoleType
(
roleType
))
{
throw
new
BadRequestException
(
"role type is illegal"
);
}
rolePermissionService
.
removeRoleFromUsers
(
RoleUtils
.
buildNamespaceRoleName
(
appId
,
namespaceName
,
roleType
),
Sets
.
newHashSet
(
user
),
userInfoHolder
.
getUser
().
getUserId
());
Sets
.
newHashSet
(
user
),
userInfoHolder
.
getUser
().
getUserId
());
return
ResponseEntity
.
ok
().
build
();
}
@RequestMapping
(
value
=
"/apps/{appId}/role_users"
)
public
AppRolesAssignedUsers
getAppRoles
(
@PathVariable
String
appId
){
public
AppRolesAssignedUsers
getAppRoles
(
@PathVariable
String
appId
)
{
AppRolesAssignedUsers
users
=
new
AppRolesAssignedUsers
();
users
.
setAppId
(
appId
);
...
...
@@ -136,16 +135,16 @@ public class PermissionController {
@PreAuthorize
(
value
=
"@permissionValidator.hasAssignRolePermission(#appId)"
)
@RequestMapping
(
value
=
"/apps/{appId}/roles/{roleType}"
,
method
=
RequestMethod
.
POST
)
public
ResponseEntity
<
Void
>
assignAppRoleToUser
(
@PathVariable
String
appId
,
@PathVariable
String
roleType
,
@RequestBody
String
user
){
@RequestBody
String
user
)
{
checkUserExists
(
user
);
RequestPrecondition
.
checkArgumentsNotEmpty
(
user
);
if
(!
RoleType
.
isValidRoleType
(
roleType
)){
if
(!
RoleType
.
isValidRoleType
(
roleType
))
{
throw
new
BadRequestException
(
"role type is illegal"
);
}
Set
<
String
>
assignedUsers
=
rolePermissionService
.
assignRoleToUsers
(
RoleUtils
.
buildAppRoleName
(
appId
,
roleType
),
Sets
.
newHashSet
(
user
),
userInfoHolder
.
getUser
().
getUserId
());
if
(
CollectionUtils
.
isEmpty
(
assignedUsers
)){
Sets
.
newHashSet
(
user
),
userInfoHolder
.
getUser
().
getUserId
());
if
(
CollectionUtils
.
isEmpty
(
assignedUsers
))
{
throw
new
BadRequestException
(
user
+
"已授权"
);
}
...
...
@@ -155,14 +154,14 @@ public class PermissionController {
@PreAuthorize
(
value
=
"@permissionValidator.hasAssignRolePermission(#appId)"
)
@RequestMapping
(
value
=
"/apps/{appId}/roles/{roleType}"
,
method
=
RequestMethod
.
DELETE
)
public
ResponseEntity
<
Void
>
removeAppRoleFromUser
(
@PathVariable
String
appId
,
@PathVariable
String
roleType
,
@RequestParam
String
user
)
{
@RequestParam
String
user
)
{
RequestPrecondition
.
checkArgumentsNotEmpty
(
user
);
if
(!
RoleType
.
isValidRoleType
(
roleType
)){
if
(!
RoleType
.
isValidRoleType
(
roleType
))
{
throw
new
BadRequestException
(
"role type is illegal"
);
}
rolePermissionService
.
removeRoleFromUsers
(
RoleUtils
.
buildAppRoleName
(
appId
,
roleType
),
Sets
.
newHashSet
(
user
),
userInfoHolder
.
getUser
().
getUserId
());
Sets
.
newHashSet
(
user
),
userInfoHolder
.
getUser
().
getUserId
());
return
ResponseEntity
.
ok
().
build
();
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ReleaseController.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.controller
;
import
com.ctrip.framework.apollo.common.utils.RequestPrecondition
;
import
com.ctrip.framework.apollo.common.dto.ReleaseDTO
;
import
com.ctrip.framework.apollo.common.utils.RequestPrecondition
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.entity.form.NamespaceReleaseModel
;
import
com.ctrip.framework.apollo.portal.entity.vo.ReleaseCompareResult
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/UserInfoController.java
浏览文件 @
afa2a683
...
...
@@ -30,7 +30,7 @@ public class UserInfoController {
@RequestMapping
(
"/user"
)
public
UserInfo
getCurrentUserName
()
{
return
userInfoHolder
.
getUser
();
return
userInfoHolder
.
getUser
();
}
@RequestMapping
(
"/user/logout"
)
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/customize/BizLoggingCustomizer.java
浏览文件 @
afa2a683
...
...
@@ -9,7 +9,7 @@ import org.springframework.stereotype.Component;
@Component
@Profile
(
"ctrip"
)
public
class
BizLoggingCustomizer
extends
LoggingCustomizer
{
public
class
BizLoggingCustomizer
extends
LoggingCustomizer
{
private
static
final
String
CLOGGING_SERVER_URL_KEY
=
"clogging.server.url"
;
private
static
final
String
CLOGGING_SERVER_PORT_KEY
=
"clogging.server.port"
;
...
...
@@ -22,7 +22,7 @@ public class BizLoggingCustomizer extends LoggingCustomizer{
@Override
protected
String
cloggingUrl
()
{
if
(
cloggingUrl
==
null
){
if
(
cloggingUrl
==
null
)
{
cloggingUrl
=
serverConfigService
.
getValue
(
CLOGGING_SERVER_URL_KEY
);
}
return
cloggingUrl
;
...
...
@@ -30,7 +30,7 @@ public class BizLoggingCustomizer extends LoggingCustomizer{
@Override
protected
String
cloggingPort
()
{
if
(
cloggingPort
==
null
){
if
(
cloggingPort
==
null
)
{
cloggingPort
=
serverConfigService
.
getValue
(
CLOGGING_SERVER_PORT_KEY
);
}
return
cloggingPort
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/form/NamespaceReleaseModel.java
浏览文件 @
afa2a683
...
...
@@ -12,7 +12,7 @@ public class NamespaceReleaseModel implements Verifiable {
private
String
namespaceName
;
private
String
releaseTitle
;
private
String
releaseComment
;
private
String
releaseBy
;
private
String
release
d
By
;
@Override
public
boolean
isInvalid
()
{
...
...
@@ -67,11 +67,11 @@ public class NamespaceReleaseModel implements Verifiable {
this
.
releaseComment
=
releaseComment
;
}
public
String
getReleaseBy
()
{
return
releaseBy
;
public
String
getRelease
d
By
()
{
return
release
d
By
;
}
public
void
setRelease
By
(
String
release
By
)
{
this
.
release
By
=
release
By
;
public
void
setRelease
dBy
(
String
released
By
)
{
this
.
release
dBy
=
released
By
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/form/NamespaceSyncModel.java
浏览文件 @
afa2a683
...
...
@@ -14,11 +14,11 @@ public class NamespaceSyncModel implements Verifiable {
@Override
public
boolean
isInvalid
()
{
if
(
CollectionUtils
.
isEmpty
(
syncToNamespaces
)
||
CollectionUtils
.
isEmpty
(
syncItems
)){
if
(
CollectionUtils
.
isEmpty
(
syncToNamespaces
)
||
CollectionUtils
.
isEmpty
(
syncItems
))
{
return
true
;
}
for
(
NamespaceIdentifier
namespaceIdentifier
:
syncToNamespaces
){
if
(
namespaceIdentifier
.
isInvalid
()){
for
(
NamespaceIdentifier
namespaceIdentifier
:
syncToNamespaces
)
{
if
(
namespaceIdentifier
.
isInvalid
())
{
return
true
;
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/form/NamespaceTextModel.java
浏览文件 @
afa2a683
...
...
@@ -17,9 +17,10 @@ public class NamespaceTextModel implements Verifiable {
@Override
public
boolean
isInvalid
(){
public
boolean
isInvalid
()
{
return
StringUtils
.
isContainEmpty
(
appId
,
env
,
clusterName
,
namespaceName
)
||
namespaceId
<=
0
;
}
public
String
getAppId
()
{
return
appId
;
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/EnvClusterInfo.java
浏览文件 @
afa2a683
...
...
@@ -9,7 +9,7 @@ public class EnvClusterInfo {
private
Env
env
;
private
List
<
ClusterDTO
>
clusters
;
public
EnvClusterInfo
(
Env
env
){
public
EnvClusterInfo
(
Env
env
)
{
this
.
env
=
env
;
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/ItemDiffs.java
浏览文件 @
afa2a683
...
...
@@ -7,9 +7,10 @@ public class ItemDiffs {
private
ItemChangeSets
diffs
;
private
String
extInfo
;
public
ItemDiffs
(
NamespaceIdentifier
namespace
){
public
ItemDiffs
(
NamespaceIdentifier
namespace
)
{
this
.
namespace
=
namespace
;
}
public
NamespaceIdentifier
getNamespace
()
{
return
namespace
;
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/NamespaceIdentifier.java
浏览文件 @
afa2a683
...
...
@@ -51,10 +51,10 @@ public class NamespaceIdentifier implements Verifiable {
@Override
public
String
toString
()
{
return
"NamespaceIdentifer{"
+
"appId='"
+
appId
+
'\''
+
", env='"
+
env
+
'\''
+
", clusterName='"
+
clusterName
+
'\''
+
", namespaceName='"
+
namespaceName
+
'\''
+
'}'
;
"appId='"
+
appId
+
'\''
+
", env='"
+
env
+
'\''
+
", clusterName='"
+
clusterName
+
'\''
+
", namespaceName='"
+
namespaceName
+
'\''
+
'}'
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/vo/NamespaceVO.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.entity.vo
;
import
com.ctrip.framework.apollo.common.dto.ItemDTO
;
import
com.ctrip.framework.apollo.common.dto.NamespaceDTO
;
...
...
@@ -70,7 +71,7 @@ public class NamespaceVO {
this
.
comment
=
comment
;
}
public
static
class
ItemVO
{
public
static
class
ItemVO
{
private
ItemDTO
item
;
private
boolean
isModified
;
private
boolean
isDeleted
;
...
...
@@ -118,7 +119,6 @@ public class NamespaceVO {
}
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/enums/ChangeType.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.enums
;
public
enum
ChangeType
{
public
enum
ChangeType
{
ADDED
,
MODIFIED
,
DELETED
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/CreationListener.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.listener
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.dto.AppDTO
;
import
com.ctrip.framework.apollo.common.dto.AppNamespaceDTO
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
...
...
@@ -43,7 +43,7 @@ public class CreationListener {
}
@EventListener
public
void
onAppNamespaceCreationEvent
(
AppNamespaceCreationEvent
event
){
public
void
onAppNamespaceCreationEvent
(
AppNamespaceCreationEvent
event
)
{
AppNamespaceDTO
appNamespace
=
BeanUtils
.
transfrom
(
AppNamespaceDTO
.
class
,
event
.
getAppNamespace
());
List
<
Env
>
envs
=
portalSettings
.
getActiveEnvs
();
for
(
Env
env
:
envs
)
{
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/AppNamespaceRepository.java
浏览文件 @
afa2a683
...
...
@@ -6,7 +6,7 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import
java.util.List
;
public
interface
AppNamespaceRepository
extends
PagingAndSortingRepository
<
AppNamespace
,
Long
>{
public
interface
AppNamespaceRepository
extends
PagingAndSortingRepository
<
AppNamespace
,
Long
>
{
AppNamespace
findByAppIdAndName
(
String
appId
,
String
namespaceName
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/PermissionRepository.java
浏览文件 @
afa2a683
...
...
@@ -18,10 +18,7 @@ public interface PermissionRepository extends PagingAndSortingRepository<Permiss
/**
* find permissions by permission types and targetId
* @param permissionTypes
* @param targetId
* @return
*/
List
<
Permission
>
findByPermissionTypeInAndTargetId
(
Collection
<
String
>
permissionTypes
,
String
targetId
);
String
targetId
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/RoleRepository.java
浏览文件 @
afa2a683
...
...
@@ -10,8 +10,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
public
interface
RoleRepository
extends
PagingAndSortingRepository
<
Role
,
Long
>
{
/**
* find role by role name
* @param roleName
* @return
*/
Role
findTopByRoleName
(
String
roleName
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/repository/UserRoleRepository.java
浏览文件 @
afa2a683
...
...
@@ -6,7 +6,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Set
;
/**
* @author Jason Song(song_s@ctrip.com)
...
...
@@ -14,23 +13,16 @@ import java.util.Set;
public
interface
UserRoleRepository
extends
PagingAndSortingRepository
<
UserRole
,
Long
>
{
/**
* find user roles by userId
* @param userId
* @return
*/
List
<
UserRole
>
findByUserId
(
String
userId
);
/**
* find user roles by roleId
* @param roleId
* @return
*/
List
<
UserRole
>
findByRoleId
(
long
roleId
);
/**
* find user roles by userIds and roleId
* @param userId
* @param roleId
* @return
*/
List
<
UserRole
>
findByUserIdInAndRoleId
(
Collection
<
String
>
userId
,
long
roleId
);
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppNamespaceService.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.service
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.exception.ServiceException
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.repository.AppNamespaceRepository
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java
浏览文件 @
afa2a683
...
...
@@ -2,22 +2,12 @@ package com.ctrip.framework.apollo.portal.service;
import
com.google.common.collect.Lists
;
import
java.util.Collections
;
import
java.util.List
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.client.HttpStatusCodeException
;
import
com.ctrip.framework.apollo.common.dto.AppDTO
;
import
com.ctrip.framework.apollo.common.entity.App
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.ExceptionUtils
;
import
com.ctrip.framework.apollo.common.dto.AppDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.constant.CatEventType
;
...
...
@@ -25,6 +15,16 @@ import com.ctrip.framework.apollo.portal.entity.vo.EnvClusterInfo;
import
com.ctrip.framework.apollo.portal.repository.AppRepository
;
import
com.dianping.cat.Cat
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.client.HttpStatusCodeException
;
import
java.util.Collections
;
import
java.util.List
;
@Service
public
class
AppService
{
...
...
@@ -56,7 +56,7 @@ public class AppService {
public
App
load
(
String
appId
)
{
App
app
=
appRepository
.
findByAppId
(
appId
);
if
(
app
==
null
){
if
(
app
==
null
)
{
throw
new
BadRequestException
(
String
.
format
(
"app %s cant found."
,
appId
));
}
return
app
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ClusterService.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.service
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.common.dto.ClusterDTO
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.constant.CatEventType
;
import
com.dianping.cat.Cat
;
...
...
@@ -18,12 +18,12 @@ public class ClusterService {
@Autowired
private
AdminServiceAPI
.
ClusterAPI
clusterAPI
;
public
List
<
ClusterDTO
>
findClusters
(
Env
env
,
String
appId
){
public
List
<
ClusterDTO
>
findClusters
(
Env
env
,
String
appId
)
{
return
clusterAPI
.
findClustersByApp
(
appId
,
env
);
}
public
ClusterDTO
createCluster
(
Env
env
,
ClusterDTO
cluster
){
if
(!
clusterAPI
.
isClusterUnique
(
cluster
.
getAppId
(),
env
,
cluster
.
getName
())){
public
ClusterDTO
createCluster
(
Env
env
,
ClusterDTO
cluster
)
{
if
(!
clusterAPI
.
isClusterUnique
(
cluster
.
getAppId
(),
env
,
cluster
.
getName
()))
{
throw
new
BadRequestException
(
String
.
format
(
"cluster %s already exists."
,
cluster
.
getName
()));
}
ClusterDTO
clusterDTO
=
clusterAPI
.
create
(
env
,
cluster
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/CommitService.java
浏览文件 @
afa2a683
...
...
@@ -16,7 +16,7 @@ public class CommitService {
@Autowired
private
AdminServiceAPI
.
CommitAPI
commitAPI
;
public
List
<
CommitDTO
>
find
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
int
page
,
int
size
){
public
List
<
CommitDTO
>
find
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
int
page
,
int
size
)
{
return
commitAPI
.
find
(
appId
,
env
,
clusterName
,
namespaceName
,
page
,
size
);
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ItemService.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.service
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.client.HttpClientErrorException
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.common.dto.ItemChangeSets
;
import
com.ctrip.framework.apollo.common.dto.ItemDTO
;
import
com.ctrip.framework.apollo.common.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.constant.CatEventType
;
import
com.ctrip.framework.apollo.portal.entity.form.NamespaceTextModel
;
import
com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs
;
import
com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifier
;
import
com.ctrip.framework.apollo.portal.entity.form.NamespaceTextModel
;
import
com.ctrip.framework.apollo.portal.service.txtresolver.ConfigTextResolver
;
import
com.dianping.cat.Cat
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.client.HttpClientErrorException
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -65,7 +65,7 @@ public class ItemService {
model
.
getFormat
()
==
ConfigFileFormat
.
Properties
?
propertyResolver
:
fileTextResolver
;
ItemChangeSets
changeSets
=
resolver
.
resolve
(
namespaceId
,
configText
,
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
));
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
));
if
(
changeSets
.
isEmpty
())
{
return
;
}
...
...
@@ -74,7 +74,7 @@ public class ItemService {
itemAPI
.
updateItemsByChangeSet
(
appId
,
env
,
clusterName
,
namespaceName
,
changeSets
);
Cat
.
logEvent
(
CatEventType
.
MODIFY_NAMESPACE_BY_TEXT
,
String
.
format
(
"%s+%s+%s+%s"
,
appId
,
env
,
clusterName
,
namespaceName
));
String
.
format
(
"%s+%s+%s+%s"
,
appId
,
env
,
clusterName
,
namespaceName
));
Cat
.
logEvent
(
CatEventType
.
MODIFY_NAMESPACE
,
String
.
format
(
"%s+%s+%s+%s"
,
appId
,
env
,
clusterName
,
namespaceName
));
}
...
...
@@ -87,7 +87,7 @@ public class ItemService {
}
item
.
setNamespaceId
(
namespace
.
getId
());
if
(
StringUtils
.
isEmpty
(
item
.
getDataChangeCreatedBy
())){
if
(
StringUtils
.
isEmpty
(
item
.
getDataChangeCreatedBy
()))
{
String
username
=
userInfoHolder
.
getUser
().
getUserId
();
item
.
setDataChangeCreatedBy
(
username
);
item
.
setDataChangeLastModifiedBy
(
username
);
...
...
@@ -99,7 +99,7 @@ public class ItemService {
}
public
void
updateItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
ItemDTO
item
)
{
if
(
StringUtils
.
isEmpty
(
item
.
getDataChangeLastModifiedBy
())){
if
(
StringUtils
.
isEmpty
(
item
.
getDataChangeLastModifiedBy
()))
{
String
username
=
userInfoHolder
.
getUser
().
getUserId
();
item
.
setDataChangeLastModifiedBy
(
username
);
}
...
...
@@ -114,7 +114,7 @@ public class ItemService {
return
itemAPI
.
findItems
(
appId
,
env
,
clusterName
,
namespaceName
);
}
public
ItemDTO
loadItem
(
Env
env
,
long
itemId
){
public
ItemDTO
loadItem
(
Env
env
,
long
itemId
)
{
return
itemAPI
.
loadItem
(
env
,
itemId
);
}
...
...
@@ -178,7 +178,7 @@ public class ItemService {
List
<
ItemDTO
>
targetItems
=
itemAPI
.
findItems
(
namespace
.
getAppId
(),
namespace
.
getEnv
(),
namespace
.
getClusterName
(),
namespace
.
getNamespaceName
());
namespace
.
getClusterName
(),
namespace
.
getNamespaceName
());
long
namespaceId
=
getNamespaceId
(
namespace
);
...
...
@@ -203,7 +203,7 @@ public class ItemService {
changeSets
.
addCreateItem
(
buildItem
(
namespaceId
,
++
maxLineNum
,
sourceItem
));
}
else
if
(
isModified
(
sourceValue
,
targetItem
.
getValue
(),
sourceComment
,
targetItem
.
getComment
()))
{
//modified items
targetItem
.
getComment
()))
{
//modified items
targetItem
.
setValue
(
sourceValue
);
targetItem
.
setComment
(
sourceComment
);
changeSets
.
addUpdateItem
(
targetItem
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceLockService.java
浏览文件 @
afa2a683
...
...
@@ -13,7 +13,7 @@ public class NamespaceLockService {
@Autowired
private
AdminServiceAPI
.
NamespaceLockAPI
namespaceLockAPI
;
public
NamespaceLockDTO
getNamespaceLock
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
){
public
NamespaceLockDTO
getNamespaceLock
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
return
namespaceLockAPI
.
getNamespaceLockOwner
(
appId
,
env
,
clusterName
,
namespaceName
);
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
浏览文件 @
afa2a683
...
...
@@ -2,12 +2,12 @@ package com.ctrip.framework.apollo.portal.service;
import
com.google.gson.Gson
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.dto.ItemDTO
;
import
com.ctrip.framework.apollo.common.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.common.dto.ReleaseDTO
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.common.exception.BadRequestException
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
...
...
@@ -53,15 +53,15 @@ public class NamespaceService {
NamespaceDTO
createdNamespace
=
namespaceAPI
.
createNamespace
(
env
,
namespace
);
Cat
.
logEvent
(
CatEventType
.
CREATE_NAMESPACE
,
String
.
format
(
"%s+%s+%s+%s"
,
namespace
.
getAppId
(),
env
,
namespace
.
getClusterName
(),
namespace
.
getNamespaceName
()));
String
.
format
(
"%s+%s+%s+%s"
,
namespace
.
getAppId
(),
env
,
namespace
.
getClusterName
(),
namespace
.
getNamespaceName
()));
return
createdNamespace
;
}
public
NamespaceDTO
loadNamespaceBaseInfo
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
){
public
NamespaceDTO
loadNamespaceBaseInfo
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
NamespaceDTO
namespace
=
namespaceAPI
.
loadNamespace
(
appId
,
env
,
clusterName
,
namespaceName
);
if
(
namespace
==
null
){
throw
new
BadRequestException
(
"namespaces not exist
ed
"
);
if
(
namespace
==
null
)
{
throw
new
BadRequestException
(
"namespaces not exist"
);
}
return
namespace
;
}
...
...
@@ -73,7 +73,7 @@ public class NamespaceService {
List
<
NamespaceDTO
>
namespaces
=
namespaceAPI
.
findNamespaceByCluster
(
appId
,
env
,
clusterName
);
if
(
namespaces
==
null
||
namespaces
.
size
()
==
0
)
{
throw
new
BadRequestException
(
"namespaces not exist
ed
"
);
throw
new
BadRequestException
(
"namespaces not exist"
);
}
List
<
NamespaceVO
>
namespaceVOs
=
new
LinkedList
<>();
...
...
@@ -85,7 +85,7 @@ public class NamespaceService {
namespaceVOs
.
add
(
namespaceVO
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"parse namespace error. app id:{}, env:{}, clusterName:{}, namespace:{}"
,
appId
,
env
,
clusterName
,
namespace
.
getNamespaceName
(),
e
);
appId
,
env
,
clusterName
,
namespace
.
getNamespaceName
(),
e
);
throw
e
;
}
}
...
...
@@ -93,10 +93,10 @@ public class NamespaceService {
return
namespaceVOs
;
}
public
NamespaceVO
loadNamespace
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
){
public
NamespaceVO
loadNamespace
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
NamespaceDTO
namespace
=
namespaceAPI
.
loadNamespace
(
appId
,
env
,
clusterName
,
namespaceName
);
if
(
namespace
==
null
){
throw
new
BadRequestException
(
"namespaces not exist
ed
"
);
if
(
namespace
==
null
)
{
throw
new
BadRequestException
(
"namespaces not exist"
);
}
return
parseNamespace
(
appId
,
env
,
clusterName
,
namespace
);
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ReleaseService.java
浏览文件 @
afa2a683
...
...
@@ -31,109 +31,109 @@ import java.util.Set;
@Service
public
class
ReleaseService
{
private
static
final
Gson
gson
=
new
Gson
();
private
static
final
Type
configurationTypeReference
=
new
TypeToken
<
Map
<
String
,
String
>>()
{
}.
getType
();
@Autowired
private
UserInfoHolder
userInfoHolder
;
@Autowired
private
AdminServiceAPI
.
ReleaseAPI
releaseAPI
;
public
ReleaseDTO
createRelease
(
NamespaceReleaseModel
model
)
{
String
appId
=
model
.
getAppId
();
Env
env
=
model
.
getEnv
();
String
clusterName
=
model
.
getClusterName
();
String
namespaceName
=
model
.
getNamespaceName
();
String
releaseBy
=
StringUtils
.
isEmpty
(
model
.
getReleaseBy
())
?
userInfoHolder
.
getUser
().
getUserId
()
:
model
.
getRelease
By
();
ReleaseDTO
releaseDTO
=
releaseAPI
.
createRelease
(
appId
,
env
,
clusterName
,
namespaceName
,
model
.
getReleaseTitle
(),
model
.
getReleaseComment
()
,
releaseBy
);
Cat
.
logEvent
(
CatEventType
.
RELEASE_NAMESPACE
,
String
.
format
(
"%s+%s+%s+%s"
,
appId
,
env
,
clusterName
,
namespaceName
));
return
releaseDTO
;
}
public
List
<
ReleaseVO
>
findAllReleases
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
int
page
,
int
size
)
{
List
<
ReleaseDTO
>
releaseDTOs
=
releaseAPI
.
findAllReleases
(
appId
,
env
,
clusterName
,
namespaceName
,
page
,
size
);
if
(
CollectionUtils
.
isEmpty
(
releaseDTOs
))
{
return
Collections
.
emptyList
();
}
List
<
ReleaseVO
>
releases
=
new
LinkedList
<>();
for
(
ReleaseDTO
releaseDTO
:
releaseDTOs
)
{
ReleaseVO
release
=
new
ReleaseVO
();
release
.
setBaseInfo
(
releaseDTO
);
Set
<
KVEntity
>
kvEntities
=
new
LinkedHashSet
<>();
Map
<
String
,
String
>
configurations
=
gson
.
fromJson
(
releaseDTO
.
getConfigurations
(),
configurationTypeReference
);
Set
<
Map
.
Entry
<
String
,
String
>>
entries
=
configurations
.
entrySet
();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
entries
)
{
kvEntities
.
add
(
new
KVEntity
(
entry
.
getKey
(),
entry
.
getValue
()));
}
release
.
setItems
(
kvEntities
);
//为了减少数据量
releaseDTO
.
setConfigurations
(
""
);
releases
.
add
(
release
);
}
return
releases
;
}
public
List
<
ReleaseDTO
>
findActiveReleases
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
int
page
,
int
size
)
{
return
releaseAPI
.
findActiveReleases
(
appId
,
env
,
clusterName
,
namespaceName
,
page
,
size
);
}
public
ReleaseDTO
loadLatestRelease
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
return
releaseAPI
.
loadLatestRelease
(
appId
,
env
,
clusterName
,
namespaceName
);
}
public
void
rollback
(
Env
env
,
long
releaseId
)
{
releaseAPI
.
rollback
(
env
,
releaseId
,
userInfoHolder
.
getUser
().
getUserId
());
}
public
ReleaseCompareResult
compare
(
Env
env
,
long
firstReleaseId
,
long
secondReleaseId
)
{
ReleaseDTO
firstRelease
=
releaseAPI
.
loadRelease
(
env
,
firstReleaseId
);
ReleaseDTO
secondRelease
=
releaseAPI
.
loadRelease
(
env
,
secondReleaseId
);
Map
<
String
,
String
>
firstItems
=
gson
.
fromJson
(
firstRelease
.
getConfigurations
(),
configurationTypeReference
);
Map
<
String
,
String
>
secondItems
=
gson
.
fromJson
(
secondRelease
.
getConfigurations
(),
configurationTypeReference
);
ReleaseCompareResult
compareResult
=
new
ReleaseCompareResult
();
//added and modified in firstRelease
for
(
Map
.
Entry
<
String
,
String
>
entry
:
firstItems
.
entrySet
())
{
String
key
=
entry
.
getKey
();
String
firstValue
=
entry
.
getValue
();
String
secondValue
=
secondItems
.
get
(
key
);
//added
if
(
secondValue
==
null
)
{
compareResult
.
addEntityPair
(
ChangeType
.
DELETED
,
new
KVEntity
(
key
,
firstValue
),
new
KVEntity
(
key
,
secondValue
));
}
else
if
(!
Objects
.
equal
(
firstValue
,
secondValue
))
{
compareResult
.
addEntityPair
(
ChangeType
.
MODIFIED
,
new
KVEntity
(
key
,
firstValue
),
new
KVEntity
(
key
,
secondValue
));
}
}
//deleted in firstRelease
for
(
Map
.
Entry
<
String
,
String
>
entry
:
secondItems
.
entrySet
())
{
String
key
=
entry
.
getKey
();
String
value
=
entry
.
getValue
();
if
(
firstItems
.
get
(
key
)
==
null
)
{
compareResult
.
addEntityPair
(
ChangeType
.
ADDED
,
new
KVEntity
(
key
,
""
),
new
KVEntity
(
key
,
value
));
}
}
return
compareResult
;
}
private
static
final
Gson
gson
=
new
Gson
();
private
static
final
Type
configurationTypeReference
=
new
TypeToken
<
Map
<
String
,
String
>>()
{
}.
getType
();
@Autowired
private
UserInfoHolder
userInfoHolder
;
@Autowired
private
AdminServiceAPI
.
ReleaseAPI
releaseAPI
;
public
ReleaseDTO
createRelease
(
NamespaceReleaseModel
model
)
{
String
appId
=
model
.
getAppId
();
Env
env
=
model
.
getEnv
();
String
clusterName
=
model
.
getClusterName
();
String
namespaceName
=
model
.
getNamespaceName
();
String
releaseBy
=
StringUtils
.
isEmpty
(
model
.
getReleasedBy
())
?
userInfoHolder
.
getUser
().
getUserId
()
:
model
.
getReleased
By
();
ReleaseDTO
releaseDTO
=
releaseAPI
.
createRelease
(
appId
,
env
,
clusterName
,
namespaceName
,
model
.
getReleaseTitle
(),
model
.
getReleaseComment
()
,
releaseBy
);
Cat
.
logEvent
(
CatEventType
.
RELEASE_NAMESPACE
,
String
.
format
(
"%s+%s+%s+%s"
,
appId
,
env
,
clusterName
,
namespaceName
));
return
releaseDTO
;
}
public
List
<
ReleaseVO
>
findAllReleases
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
int
page
,
int
size
)
{
List
<
ReleaseDTO
>
releaseDTOs
=
releaseAPI
.
findAllReleases
(
appId
,
env
,
clusterName
,
namespaceName
,
page
,
size
);
if
(
CollectionUtils
.
isEmpty
(
releaseDTOs
))
{
return
Collections
.
emptyList
();
}
List
<
ReleaseVO
>
releases
=
new
LinkedList
<>();
for
(
ReleaseDTO
releaseDTO
:
releaseDTOs
)
{
ReleaseVO
release
=
new
ReleaseVO
();
release
.
setBaseInfo
(
releaseDTO
);
Set
<
KVEntity
>
kvEntities
=
new
LinkedHashSet
<>();
Map
<
String
,
String
>
configurations
=
gson
.
fromJson
(
releaseDTO
.
getConfigurations
(),
configurationTypeReference
);
Set
<
Map
.
Entry
<
String
,
String
>>
entries
=
configurations
.
entrySet
();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
entries
)
{
kvEntities
.
add
(
new
KVEntity
(
entry
.
getKey
(),
entry
.
getValue
()));
}
release
.
setItems
(
kvEntities
);
//为了减少数据量
releaseDTO
.
setConfigurations
(
""
);
releases
.
add
(
release
);
}
return
releases
;
}
public
List
<
ReleaseDTO
>
findActiveReleases
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
int
page
,
int
size
)
{
return
releaseAPI
.
findActiveReleases
(
appId
,
env
,
clusterName
,
namespaceName
,
page
,
size
);
}
public
ReleaseDTO
loadLatestRelease
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
return
releaseAPI
.
loadLatestRelease
(
appId
,
env
,
clusterName
,
namespaceName
);
}
public
void
rollback
(
Env
env
,
long
releaseId
)
{
releaseAPI
.
rollback
(
env
,
releaseId
,
userInfoHolder
.
getUser
().
getUserId
());
}
public
ReleaseCompareResult
compare
(
Env
env
,
long
firstReleaseId
,
long
secondReleaseId
)
{
ReleaseDTO
firstRelease
=
releaseAPI
.
loadRelease
(
env
,
firstReleaseId
);
ReleaseDTO
secondRelease
=
releaseAPI
.
loadRelease
(
env
,
secondReleaseId
);
Map
<
String
,
String
>
firstItems
=
gson
.
fromJson
(
firstRelease
.
getConfigurations
(),
configurationTypeReference
);
Map
<
String
,
String
>
secondItems
=
gson
.
fromJson
(
secondRelease
.
getConfigurations
(),
configurationTypeReference
);
ReleaseCompareResult
compareResult
=
new
ReleaseCompareResult
();
//added and modified in firstRelease
for
(
Map
.
Entry
<
String
,
String
>
entry
:
firstItems
.
entrySet
())
{
String
key
=
entry
.
getKey
();
String
firstValue
=
entry
.
getValue
();
String
secondValue
=
secondItems
.
get
(
key
);
//added
if
(
secondValue
==
null
)
{
compareResult
.
addEntityPair
(
ChangeType
.
DELETED
,
new
KVEntity
(
key
,
firstValue
),
new
KVEntity
(
key
,
secondValue
));
}
else
if
(!
Objects
.
equal
(
firstValue
,
secondValue
))
{
compareResult
.
addEntityPair
(
ChangeType
.
MODIFIED
,
new
KVEntity
(
key
,
firstValue
),
new
KVEntity
(
key
,
secondValue
));
}
}
//deleted in firstRelease
for
(
Map
.
Entry
<
String
,
String
>
entry
:
secondItems
.
entrySet
())
{
String
key
=
entry
.
getKey
();
String
value
=
entry
.
getValue
();
if
(
firstItems
.
get
(
key
)
==
null
)
{
compareResult
.
addEntityPair
(
ChangeType
.
ADDED
,
new
KVEntity
(
key
,
""
),
new
KVEntity
(
key
,
value
));
}
}
return
compareResult
;
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/RoleInitializationService.java
浏览文件 @
afa2a683
...
...
@@ -33,7 +33,7 @@ public class RoleInitializationService {
String
appMasterRoleName
=
RoleUtils
.
buildAppMasterRoleName
(
appId
);
//has created before
if
(
rolePermissionService
.
findRoleByRoleName
(
appMasterRoleName
)
!=
null
){
if
(
rolePermissionService
.
findRoleByRoleName
(
appMasterRoleName
)
!=
null
)
{
return
;
}
String
operaterUserId
=
userInfoHolder
.
getUser
().
getUserId
();
...
...
@@ -43,7 +43,7 @@ public class RoleInitializationService {
//assign master role to user
rolePermissionService
.
assignRoleToUsers
(
RoleUtils
.
buildAppMasterRoleName
(
appId
),
Sets
.
newHashSet
(
app
.
getOwnerName
()),
operaterUserId
);
operaterUserId
);
initNamespaceRoles
(
appId
,
ConfigConsts
.
NAMESPACE_APPLICATION
);
...
...
@@ -55,13 +55,13 @@ public class RoleInitializationService {
String
modifyNamespaceRoleName
=
RoleUtils
.
buildModifyNamespaceRoleName
(
appId
,
namespaceName
);
if
(
rolePermissionService
.
findRoleByRoleName
(
modifyNamespaceRoleName
)
==
null
)
{
createDefaultNamespaceRole
(
appId
,
namespaceName
,
PermissionType
.
MODIFY_NAMESPACE
,
RoleUtils
.
buildModifyNamespaceRoleName
(
appId
,
namespaceName
));
RoleUtils
.
buildModifyNamespaceRoleName
(
appId
,
namespaceName
));
}
String
releaseNamespaceRoleName
=
RoleUtils
.
buildReleaseNamespaceRoleName
(
appId
,
namespaceName
);
if
(
rolePermissionService
.
findRoleByRoleName
(
releaseNamespaceRoleName
)
==
null
)
{
createDefaultNamespaceRole
(
appId
,
namespaceName
,
PermissionType
.
RELEASE_NAMESPACE
,
RoleUtils
.
buildReleaseNamespaceRoleName
(
appId
,
namespaceName
));
RoleUtils
.
buildReleaseNamespaceRoleName
(
appId
,
namespaceName
));
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/txtresolver/FileTextResolver.java
浏览文件 @
afa2a683
package
com.ctrip.framework.apollo.portal.service.txtresolver
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.common.dto.ItemChangeSets
;
import
com.ctrip.framework.apollo.common.dto.ItemDTO
;
import
com.ctrip.framework.apollo.core.ConfigConsts
;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
import
org.springframework.stereotype.Component
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/txtresolver/PropertyResolver.java
浏览文件 @
afa2a683
...
...
@@ -35,7 +35,7 @@ public class PropertyResolver implements ConfigTextResolver {
String
[]
newItems
=
configText
.
split
(
ITEM_SEPARATOR
);
if
(
isHasRepeatKey
(
newItems
)){
if
(
isHasRepeatKey
(
newItems
))
{
throw
new
BadRequestException
(
"config text has repeat key please check."
);
}
...
...
@@ -71,27 +71,27 @@ public class PropertyResolver implements ConfigTextResolver {
return
changeSets
;
}
private
boolean
isHasRepeatKey
(
String
[]
newItems
){
private
boolean
isHasRepeatKey
(
String
[]
newItems
)
{
Set
<
String
>
keys
=
new
HashSet
<>();
int
lineCounter
=
1
;
int
keyCount
=
0
;
for
(
String
item
:
newItems
)
{
if
(!
isCommentItem
(
item
)
&&
!
isBlankItem
(
item
)){
for
(
String
item
:
newItems
)
{
if
(!
isCommentItem
(
item
)
&&
!
isBlankItem
(
item
))
{
keyCount
++;
String
[]
kv
=
parseKeyValueFromItem
(
item
);
if
(
kv
!=
null
)
{
keys
.
add
(
kv
[
0
]);
}
else
{
}
else
{
throw
new
BadRequestException
(
"line:"
+
lineCounter
+
" key value must separate by '='"
);
}
}
lineCounter
++;
lineCounter
++;
}
return
keyCount
>
keys
.
size
();
}
private
String
[]
parseKeyValueFromItem
(
String
item
){
private
String
[]
parseKeyValueFromItem
(
String
item
)
{
int
kvSeparator
=
item
.
indexOf
(
KV_SEPARATOR
);
if
(
kvSeparator
==
-
1
)
{
return
null
;
...
...
@@ -118,7 +118,7 @@ public class PropertyResolver implements ConfigTextResolver {
}
private
void
handleNormalLine
(
Long
namespaceId
,
Map
<
String
,
ItemDTO
>
keyMapOldItem
,
String
newItem
,
int
lineCounter
,
ItemChangeSets
changeSets
)
{
int
lineCounter
,
ItemChangeSets
changeSets
)
{
String
[]
kv
=
parseKeyValueFromItem
(
newItem
);
...
...
@@ -133,17 +133,17 @@ public class PropertyResolver implements ConfigTextResolver {
if
(
oldItem
==
null
)
{
//new item
changeSets
.
addCreateItem
(
buildNormalItem
(
0
l
,
namespaceId
,
newKey
,
newValue
,
""
,
lineCounter
));
}
else
if
(!
newValue
.
equals
(
oldItem
.
getValue
())
||
lineCounter
!=
oldItem
.
getLineNum
()){
//update item
}
else
if
(!
newValue
.
equals
(
oldItem
.
getValue
())
||
lineCounter
!=
oldItem
.
getLineNum
())
{
//update item
changeSets
.
addUpdateItem
(
buildNormalItem
(
oldItem
.
getId
(),
namespaceId
,
newKey
,
newValue
,
oldItem
.
getComment
(),
lineCounter
));
lineCounter
));
}
keyMapOldItem
.
remove
(
newKey
);
}
private
boolean
isCommentItem
(
ItemDTO
item
)
{
return
item
!=
null
&&
""
.
equals
(
item
.
getKey
())
&&
(
item
.
getComment
().
startsWith
(
"#"
)
||
item
.
getComment
().
startsWith
(
"!"
));
&&
(
item
.
getComment
().
startsWith
(
"#"
)
||
item
.
getComment
().
startsWith
(
"!"
));
}
private
boolean
isCommentItem
(
String
line
)
{
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/util/RoleUtils.java
浏览文件 @
afa2a683
...
...
@@ -9,38 +9,39 @@ public class RoleUtils {
private
static
final
Joiner
STRING_JOINER
=
Joiner
.
on
(
ConfigConsts
.
CLUSTER_NAMESPACE_SEPARATOR
);
public
static
String
buildAppMasterRoleName
(
String
appId
){
public
static
String
buildAppMasterRoleName
(
String
appId
)
{
return
STRING_JOINER
.
join
(
RoleType
.
MASTER
,
appId
);
}
public
static
String
buildAppRoleName
(
String
appId
,
String
roleType
){
public
static
String
buildAppRoleName
(
String
appId
,
String
roleType
)
{
return
STRING_JOINER
.
join
(
roleType
,
appId
);
}
public
static
String
buildModifyNamespaceRoleName
(
String
appId
,
String
namespaceName
){
public
static
String
buildModifyNamespaceRoleName
(
String
appId
,
String
namespaceName
)
{
return
STRING_JOINER
.
join
(
RoleType
.
MODIFY_NAMESPACE
,
appId
,
namespaceName
);
}
public
static
String
buildModifyDefaultNamespaceRoleName
(
String
appId
){
public
static
String
buildModifyDefaultNamespaceRoleName
(
String
appId
)
{
return
STRING_JOINER
.
join
(
RoleType
.
MODIFY_NAMESPACE
,
appId
,
ConfigConsts
.
NAMESPACE_APPLICATION
);
}
public
static
String
buildReleaseNamespaceRoleName
(
String
appId
,
String
namespaceName
){
public
static
String
buildReleaseNamespaceRoleName
(
String
appId
,
String
namespaceName
)
{
return
STRING_JOINER
.
join
(
RoleType
.
RELEASE_NAMESPACE
,
appId
,
namespaceName
);
}
public
static
String
buildNamespaceRoleName
(
String
appId
,
String
namespaceName
,
String
roleType
){
public
static
String
buildNamespaceRoleName
(
String
appId
,
String
namespaceName
,
String
roleType
)
{
return
STRING_JOINER
.
join
(
roleType
,
appId
,
namespaceName
);
}
public
static
String
buildReleaseDefaultNamespaceRoleName
(
String
appId
){
public
static
String
buildReleaseDefaultNamespaceRoleName
(
String
appId
)
{
return
STRING_JOINER
.
join
(
RoleType
.
RELEASE_NAMESPACE
,
appId
,
ConfigConsts
.
NAMESPACE_APPLICATION
);
}
public
static
String
buildNamespaceTargetId
(
String
appId
,
String
namespaceName
){
public
static
String
buildNamespaceTargetId
(
String
appId
,
String
namespaceName
)
{
return
STRING_JOINER
.
join
(
appId
,
namespaceName
);
}
public
static
String
buildDefaultNamespaceTargetId
(
String
appId
){
public
static
String
buildDefaultNamespaceTargetId
(
String
appId
)
{
return
STRING_JOINER
.
join
(
appId
,
ConfigConsts
.
NAMESPACE_APPLICATION
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录