Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
superrain51
apollo
提交
0447fca3
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,发现更多精彩内容 >>
提交
0447fca3
编写于
7月 21, 2016
作者:
J
Jason Song
提交者:
GitHub
7月 21, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #335 from lepdou/cat_log
cat log & 按钮放重复点击 & call admin server retry
上级
e6c9c222
10b9281f
变更
43
隐藏空白更改
内联
并排
Showing
43 changed file
with
697 addition
and
220 deletion
+697
-220
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ReleaseController.java
...ork/apollo/adminservice/controller/ReleaseController.java
+1
-2
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ClusterService.java
...om/ctrip/framework/apollo/biz/service/ClusterService.java
+3
-1
apollo-common/src/main/java/com/ctrip/framework/apollo/common/aop/RepositoryAspect.java
...m/ctrip/framework/apollo/common/aop/RepositoryAspect.java
+1
-4
apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/MachineUtil.java
...va/com/ctrip/framework/apollo/core/utils/MachineUtil.java
+16
-12
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalSettings.java
...ava/com/ctrip/framework/apollo/portal/PortalSettings.java
+10
-20
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/API.java
.../main/java/com/ctrip/framework/apollo/portal/api/API.java
+1
-19
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
...om/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
+53
-64
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAddressLocator.java
...amework/apollo/portal/api/AdminServiceAddressLocator.java
+109
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/RetryableRestTemplate.java
...ip/framework/apollo/portal/api/RetryableRestTemplate.java
+150
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/ctrip/CtripLogoutHandler.java
...ramework/apollo/portal/auth/ctrip/CtripLogoutHandler.java
+3
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/ctrip/CtripSsoHeartbeatHandler.java
...rk/apollo/portal/auth/ctrip/CtripSsoHeartbeatHandler.java
+3
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/ctrip/CtripUserInfoHolder.java
...amework/apollo/portal/auth/ctrip/CtripUserInfoHolder.java
+3
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/ctrip/CtripUserService.java
.../framework/apollo/portal/auth/ctrip/CtripUserService.java
+2
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/defaultimpl/DefaultLogoutHandler.java
.../apollo/portal/auth/defaultimpl/DefaultLogoutHandler.java
+4
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/defaultimpl/DefaultSsoHeartbeatHandler.java
...o/portal/auth/defaultimpl/DefaultSsoHeartbeatHandler.java
+3
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/defaultimpl/DefaultUserInfoHolder.java
...apollo/portal/auth/defaultimpl/DefaultUserInfoHolder.java
+3
-2
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/defaultimpl/DefaultUserService.java
...rk/apollo/portal/auth/defaultimpl/DefaultUserService.java
+1
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/configutation/AuthConfiguration.java
...mework/apollo/portal/configutation/AuthConfiguration.java
+8
-8
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/constant/CatEventType.java
.../ctrip/framework/apollo/portal/constant/CatEventType.java
+21
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/form/NamespaceReleaseModel.java
...work/apollo/portal/entity/form/NamespaceReleaseModel.java
+6
-6
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/CreationListener.java
...ip/framework/apollo/portal/listener/CreationListener.java
+7
-7
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java
...com/ctrip/framework/apollo/portal/service/AppService.java
+4
-0
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ClusterService.java
...ctrip/framework/apollo/portal/service/ClusterService.java
+7
-1
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigService.java
.../ctrip/framework/apollo/portal/service/ConfigService.java
+19
-16
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
...rip/framework/apollo/portal/service/NamespaceService.java
+10
-16
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ReleaseService.java
...ctrip/framework/apollo/portal/service/ReleaseService.java
+17
-7
apollo-portal/src/main/resources/static/app.html
apollo-portal/src/main/resources/static/app.html
+1
-1
apollo-portal/src/main/resources/static/app/role.html
apollo-portal/src/main/resources/static/app/role.html
+1
-1
apollo-portal/src/main/resources/static/cluster.html
apollo-portal/src/main/resources/static/cluster.html
+1
-1
apollo-portal/src/main/resources/static/config.html
apollo-portal/src/main/resources/static/config.html
+2
-2
apollo-portal/src/main/resources/static/config/sync.html
apollo-portal/src/main/resources/static/config/sync.html
+1
-1
apollo-portal/src/main/resources/static/namespace.html
apollo-portal/src/main/resources/static/namespace.html
+1
-1
apollo-portal/src/main/resources/static/namespace/role.html
apollo-portal/src/main/resources/static/namespace/role.html
+2
-2
apollo-portal/src/main/resources/static/scripts/controller/AppController.js
...main/resources/static/scripts/controller/AppController.js
+5
-0
apollo-portal/src/main/resources/static/scripts/controller/ClusterController.js
.../resources/static/scripts/controller/ClusterController.js
+5
-0
apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js
...esources/static/scripts/controller/NamespaceController.js
+9
-0
apollo-portal/src/main/resources/static/scripts/controller/config/ConfigNamespaceController.js
...ic/scripts/controller/config/ConfigNamespaceController.js
+21
-1
apollo-portal/src/main/resources/static/scripts/controller/config/SyncConfigController.js
.../static/scripts/controller/config/SyncConfigController.js
+14
-8
apollo-portal/src/main/resources/static/scripts/controller/role/AppRoleController.js
...urces/static/scripts/controller/role/AppRoleController.js
+5
-0
apollo-portal/src/main/resources/static/scripts/controller/role/NamespaceRoleController.js
...static/scripts/controller/role/NamespaceRoleController.js
+9
-0
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/AllTests.java
...test/java/com/ctrip/framework/apollo/portal/AllTests.java
+2
-1
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/RetryableRestTemplateTest.java
...ip/framework/apollo/portal/RetryableRestTemplateTest.java
+146
-0
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/auth/ctrip/CtripUserServiceTest.java
...mework/apollo/portal/auth/ctrip/CtripUserServiceTest.java
+7
-5
未找到文件。
apollo-adminservice/src/main/java/com/ctrip/framework/apollo/adminservice/controller/ReleaseController.java
浏览文件 @
0447fca3
...
@@ -65,8 +65,7 @@ public class ReleaseController {
...
@@ -65,8 +65,7 @@ public class ReleaseController {
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
@PathVariable
(
"namespaceName"
)
String
namespaceName
)
{
Release
release
=
configService
.
findRelease
(
appId
,
clusterName
,
namespaceName
);
Release
release
=
configService
.
findRelease
(
appId
,
clusterName
,
namespaceName
);
if
(
release
==
null
)
{
if
(
release
==
null
)
{
throw
new
NotFoundException
(
String
.
format
(
"latest release not found for %s %s %s"
,
appId
,
return
null
;
clusterName
,
namespaceName
));
}
else
{
}
else
{
return
BeanUtils
.
transfrom
(
ReleaseDTO
.
class
,
release
);
return
BeanUtils
.
transfrom
(
ReleaseDTO
.
class
,
release
);
}
}
...
...
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ClusterService.java
浏览文件 @
0447fca3
...
@@ -46,10 +46,12 @@ public class ClusterService {
...
@@ -46,10 +46,12 @@ public class ClusterService {
}
}
List
<
Cluster
>
clusters
=
clusterRepository
.
findByAppId
(
appId
);
List
<
Cluster
>
clusters
=
clusterRepository
.
findByAppId
(
appId
);
Collections
.
sort
(
clusters
);
if
(
clusters
==
null
)
{
if
(
clusters
==
null
)
{
return
Collections
.
emptyList
();
return
Collections
.
emptyList
();
}
}
Collections
.
sort
(
clusters
);
return
clusters
;
return
clusters
;
}
}
...
...
apollo-
biz/src/main/java/com/ctrip/framework/apollo/biz
/aop/RepositoryAspect.java
→
apollo-
common/src/main/java/com/ctrip/framework/apollo/common
/aop/RepositoryAspect.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.
biz
.aop
;
package
com.ctrip.framework.apollo.
common
.aop
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.Message
;
...
@@ -10,9 +10,6 @@ import org.aspectj.lang.annotation.Aspect;
...
@@ -10,9 +10,6 @@ import org.aspectj.lang.annotation.Aspect;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Aspect
@Aspect
@Component
@Component
public
class
RepositoryAspect
{
public
class
RepositoryAspect
{
...
...
apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/MachineUtil.java
浏览文件 @
0447fca3
...
@@ -31,21 +31,25 @@ public class MachineUtil {
...
@@ -31,21 +31,25 @@ public class MachineUtil {
try
{
try
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
Enumeration
<
NetworkInterface
>
e
=
NetworkInterface
.
getNetworkInterfaces
();
Enumeration
<
NetworkInterface
>
e
=
NetworkInterface
.
getNetworkInterfaces
();
while
(
e
.
hasMoreElements
())
{
NetworkInterface
ni
=
e
.
nextElement
();
if
(
e
!=
null
){
sb
.
append
(
ni
.
toString
());
while
(
e
.
hasMoreElements
())
{
byte
[]
mac
=
ni
.
getHardwareAddress
();
NetworkInterface
ni
=
e
.
nextElement
();
if
(
mac
!=
null
)
{
sb
.
append
(
ni
.
toString
());
ByteBuffer
bb
=
ByteBuffer
.
wrap
(
mac
);
byte
[]
mac
=
ni
.
getHardwareAddress
();
try
{
if
(
mac
!=
null
)
{
sb
.
append
(
bb
.
getChar
());
ByteBuffer
bb
=
ByteBuffer
.
wrap
(
mac
);
sb
.
append
(
bb
.
getChar
());
try
{
sb
.
append
(
bb
.
getChar
());
sb
.
append
(
bb
.
getChar
());
}
catch
(
BufferUnderflowException
shortHardwareAddressException
)
{
//NOPMD
sb
.
append
(
bb
.
getChar
());
// mac with less than 6 bytes. continue
sb
.
append
(
bb
.
getChar
());
}
catch
(
BufferUnderflowException
shortHardwareAddressException
)
{
//NOPMD
// mac with less than 6 bytes. continue
}
}
}
}
}
}
}
machinePiece
=
sb
.
toString
().
hashCode
();
machinePiece
=
sb
.
toString
().
hashCode
();
}
catch
(
Throwable
ex
)
{
}
catch
(
Throwable
ex
)
{
// exception sometimes happens with IBM JVM, use random
// exception sometimes happens with IBM JVM, use random
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/PortalSettings.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal
;
package
com.ctrip.framework.apollo.portal
;
import
com.google.common.base.Strings
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
...
@@ -10,7 +9,6 @@ import com.ctrip.framework.apollo.portal.service.ServerConfigService;
...
@@ -10,7 +9,6 @@ import com.ctrip.framework.apollo.portal.service.ServerConfigService;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -33,9 +31,8 @@ public class PortalSettings {
...
@@ -33,9 +31,8 @@ public class PortalSettings {
private
Logger
logger
=
LoggerFactory
.
getLogger
(
PortalSettings
.
class
);
private
Logger
logger
=
LoggerFactory
.
getLogger
(
PortalSettings
.
class
);
private
static
final
int
HEALTH_CHECK_INTERVAL
=
5
000
;
private
static
final
int
HEALTH_CHECK_INTERVAL
=
10
*
1
000
;
private
List
<
String
>
allStrEnvs
;
@Autowired
@Autowired
ApplicationContext
applicationContext
;
ApplicationContext
applicationContext
;
...
@@ -43,9 +40,7 @@ public class PortalSettings {
...
@@ -43,9 +40,7 @@ public class PortalSettings {
@Autowired
@Autowired
private
ServerConfigService
serverConfigService
;
private
ServerConfigService
serverConfigService
;
private
List
<
Env
>
allEnvs
=
new
ArrayList
<
Env
>();
private
List
<
Env
>
allEnvs
=
new
ArrayList
<>();
private
List
<
Env
>
activeEnvs
;
//mark env up or down
//mark env up or down
private
Map
<
Env
,
Boolean
>
envStatusMark
=
new
ConcurrentHashMap
<>();
private
Map
<
Env
,
Boolean
>
envStatusMark
=
new
ConcurrentHashMap
<>();
...
@@ -54,19 +49,16 @@ public class PortalSettings {
...
@@ -54,19 +49,16 @@ public class PortalSettings {
@PostConstruct
@PostConstruct
private
void
postConstruct
()
{
private
void
postConstruct
()
{
//初始化portal支持操作的环境集合,线上的portal可能支持所有的环境操作,而线下环境则支持一部分.
//初始化portal支持操作的环境集合,线上的portal可能支持所有的环境操作,而线下环境则支持一部分.
// 每个环境的portal支持哪些环境配置在数据库里
// 每个环境的portal支持哪些环境配置在数据库里
String
serverConfig
=
serverConfigService
.
getValue
(
"apollo.portal.envs"
);
String
serverConfig
=
serverConfigService
.
getValue
(
"apollo.portal.envs"
,
"FAT,UAT,PRO"
);
if
(!
Strings
.
isNullOrEmpty
(
serverConfig
)){
String
[]
configedEnvs
=
serverConfig
.
split
(
","
);
String
[]
configedEnvs
=
serverConfig
.
split
(
","
);
List
<
String
>
allStrEnvs
=
Arrays
.
asList
(
configedEnvs
);
allStrEnvs
=
Arrays
.
asList
(
configedEnvs
);
}
for
(
String
e
:
allStrEnvs
)
{
for
(
String
e
:
allStrEnvs
)
{
allEnvs
.
add
(
Env
.
valueOf
(
e
.
toUpperCase
()));
allEnvs
.
add
(
Env
.
valueOf
(
e
.
toUpperCase
()));
}
}
for
(
Env
env
:
allEnvs
)
{
for
(
Env
env
:
allEnvs
)
{
envStatusMark
.
put
(
env
,
true
);
envStatusMark
.
put
(
env
,
true
);
}
}
...
@@ -79,6 +71,10 @@ public class PortalSettings {
...
@@ -79,6 +71,10 @@ public class PortalSettings {
}
}
public
List
<
Env
>
getAllEnvs
(){
return
allEnvs
;
}
public
List
<
Env
>
getActiveEnvs
()
{
public
List
<
Env
>
getActiveEnvs
()
{
List
<
Env
>
activeEnvs
=
new
LinkedList
<>();
List
<
Env
>
activeEnvs
=
new
LinkedList
<>();
for
(
Env
env
:
allEnvs
)
{
for
(
Env
env
:
allEnvs
)
{
...
@@ -86,15 +82,9 @@ public class PortalSettings {
...
@@ -86,15 +82,9 @@ public class PortalSettings {
activeEnvs
.
add
(
env
);
activeEnvs
.
add
(
env
);
}
}
}
}
this
.
activeEnvs
=
activeEnvs
;
return
activeEnvs
;
return
activeEnvs
;
}
}
public
Env
getFirstAliveEnv
()
{
return
activeEnvs
.
get
(
0
);
}
class
HealthCheckTask
implements
Runnable
{
class
HealthCheckTask
implements
Runnable
{
private
static
final
int
ENV_DIED_THREADHOLD
=
2
;
private
static
final
int
ENV_DIED_THREADHOLD
=
2
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/API.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.api
;
package
com.ctrip.framework.apollo.portal.api
;
import
javax.annotation.PostConstruct
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.client.RestTemplate
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.service.ServiceLocator
;
public
class
API
{
public
class
API
{
@Autowired
@Autowired
protected
ServiceLocator
serviceLocator
;
protected
RetryableRestTemplate
restTemplate
;
@Autowired
private
RestTemplateFactory
restTemplateFactory
;
protected
RestTemplate
restTemplate
;
@PostConstruct
private
void
postConstruct
()
{
restTemplate
=
restTemplateFactory
.
getObject
();
}
public
String
getAdminServiceHost
(
Env
env
)
{
return
serviceLocator
.
getServiceAddress
(
env
).
getHomepageUrl
();
}
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/AdminServiceAPI.java
浏览文件 @
0447fca3
...
@@ -16,7 +16,6 @@ import org.springframework.boot.actuate.health.Health;
...
@@ -16,7 +16,6 @@ import org.springframework.boot.actuate.health.Health;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.MultiValueMap
;
...
@@ -32,26 +31,19 @@ public class AdminServiceAPI {
...
@@ -32,26 +31,19 @@ public class AdminServiceAPI {
public
static
class
HealthAPI
extends
API
{
public
static
class
HealthAPI
extends
API
{
public
Health
health
(
Env
env
)
{
public
Health
health
(
Env
env
)
{
return
restTemplate
.
get
ForObject
(
getAdminServiceHost
(
env
)
+
"/health"
,
Health
.
class
);
return
restTemplate
.
get
(
env
,
"/health"
,
Health
.
class
);
}
}
}
}
@Service
@Service
public
static
class
AppAPI
extends
API
{
public
static
class
AppAPI
extends
API
{
public
List
<
AppDTO
>
findApps
(
Env
env
)
{
AppDTO
[]
appDTOs
=
restTemplate
.
getForObject
(
"{host}/apps"
,
AppDTO
[].
class
,
getAdminServiceHost
(
env
));
return
Arrays
.
asList
(
appDTOs
);
}
public
AppDTO
loadApp
(
Env
env
,
String
appId
)
{
public
AppDTO
loadApp
(
Env
env
,
String
appId
)
{
return
restTemplate
.
get
ForObject
(
"{host}/apps/{appId}"
,
AppDTO
.
class
,
getAdminServiceHost
(
env
)
,
appId
);
return
restTemplate
.
get
(
env
,
"apps/{appId}"
,
AppDTO
.
class
,
appId
);
}
}
public
AppDTO
createApp
(
Env
env
,
AppDTO
app
)
{
public
AppDTO
createApp
(
Env
env
,
AppDTO
app
)
{
return
restTemplate
.
postForEntity
(
"{host}/apps"
,
app
,
AppDTO
.
class
,
getAdminServiceHost
(
env
))
return
restTemplate
.
post
(
env
,
"apps"
,
app
,
AppDTO
.
class
);
.
getBody
();
}
}
}
}
...
@@ -60,31 +52,30 @@ public class AdminServiceAPI {
...
@@ -60,31 +52,30 @@ public class AdminServiceAPI {
public
static
class
NamespaceAPI
extends
API
{
public
static
class
NamespaceAPI
extends
API
{
public
List
<
NamespaceDTO
>
findNamespaceByCluster
(
String
appId
,
Env
env
,
String
clusterName
)
{
public
List
<
NamespaceDTO
>
findNamespaceByCluster
(
String
appId
,
Env
env
,
String
clusterName
)
{
NamespaceDTO
[]
namespaceDTOs
=
restTemplate
.
get
ForObject
(
"{host}/
apps/{appId}/clusters/{clusterName}/namespaces"
,
NamespaceDTO
[]
namespaceDTOs
=
restTemplate
.
get
(
env
,
"
apps/{appId}/clusters/{clusterName}/namespaces"
,
NamespaceDTO
[].
class
,
getAdminServiceHost
(
env
)
,
appId
,
NamespaceDTO
[].
class
,
appId
,
clusterName
);
clusterName
);
return
Arrays
.
asList
(
namespaceDTOs
);
return
Arrays
.
asList
(
namespaceDTOs
);
}
}
public
NamespaceDTO
loadNamespace
(
String
appId
,
Env
env
,
String
clusterName
,
public
NamespaceDTO
loadNamespace
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
String
namespaceName
)
{
NamespaceDTO
NamespaceDTO
dto
=
dto
=
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}"
,
restTemplate
.
getForObject
(
"{host}/apps/{appId}/clusters/{clusterName}/namespaces/"
+
namespaceName
,
NamespaceDTO
.
class
,
appId
,
clusterName
,
namespaceName
);
NamespaceDTO
.
class
,
getAdminServiceHost
(
env
),
appId
,
clusterName
);
return
dto
;
return
dto
;
}
}
public
NamespaceDTO
createNamespace
(
Env
env
,
NamespaceDTO
namespace
)
{
public
NamespaceDTO
createNamespace
(
Env
env
,
NamespaceDTO
namespace
)
{
return
restTemplate
return
restTemplate
.
post
ForEntity
(
"{host}/
apps/{appId}/clusters/{clusterName}/namespaces"
,
namespace
,
NamespaceDTO
.
class
,
.
post
(
env
,
"
apps/{appId}/clusters/{clusterName}/namespaces"
,
namespace
,
NamespaceDTO
.
class
,
getAdminServiceHost
(
env
),
namespace
.
getAppId
(),
namespace
.
getClusterName
()).
getBody
(
);
namespace
.
getAppId
(),
namespace
.
getClusterName
()
);
}
}
public
AppNamespaceDTO
createAppNamespace
(
Env
env
,
AppNamespaceDTO
appNamespace
)
{
public
AppNamespaceDTO
createAppNamespace
(
Env
env
,
AppNamespaceDTO
appNamespace
)
{
return
restTemplate
.
postForEntity
(
"{host}/apps/{appId}/appnamespaces"
,
appNamespace
,
AppNamespaceDTO
.
class
,
return
restTemplate
getAdminServiceHost
(
env
),
appNamespace
.
getAppId
()).
getBody
(
);
.
post
(
env
,
"apps/{appId}/appnamespaces"
,
appNamespace
,
AppNamespaceDTO
.
class
,
appNamespace
.
getAppId
()
);
}
}
}
}
...
@@ -94,34 +85,32 @@ public class AdminServiceAPI {
...
@@ -94,34 +85,32 @@ public class AdminServiceAPI {
public
List
<
ItemDTO
>
findItems
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
public
List
<
ItemDTO
>
findItems
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
ItemDTO
[]
itemDTOs
=
ItemDTO
[]
itemDTOs
=
restTemplate
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
.
getForObject
(
"{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
ItemDTO
[].
class
,
appId
,
clusterName
,
namespaceName
);
ItemDTO
[].
class
,
getAdminServiceHost
(
env
),
appId
,
clusterName
,
namespaceName
);
return
Arrays
.
asList
(
itemDTOs
);
return
Arrays
.
asList
(
itemDTOs
);
}
}
public
void
updateItemsByChangeSet
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
public
void
updateItemsByChangeSet
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
ItemChangeSets
changeSets
)
{
ItemChangeSets
changeSets
)
{
restTemplate
.
post
ForEntity
(
"{host}/
apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset"
,
restTemplate
.
post
(
env
,
"
apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/itemset"
,
changeSets
,
Void
.
class
,
getAdminServiceHost
(
env
)
,
appId
,
clusterName
,
namespace
);
changeSets
,
Void
.
class
,
appId
,
clusterName
,
namespace
);
}
}
public
void
updateItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
long
itemId
,
ItemDTO
item
)
{
public
void
updateItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
long
itemId
,
ItemDTO
item
)
{
restTemplate
.
put
(
"{host}/
apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{itemId}"
,
restTemplate
.
put
(
env
,
"
apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items/{itemId}"
,
item
,
getAdminServiceHost
(
env
),
appId
,
clusterName
,
namespace
,
itemId
);
item
,
appId
,
clusterName
,
namespace
,
itemId
);
}
}
public
ItemDTO
createItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
ItemDTO
item
)
{
public
ItemDTO
createItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
ItemDTO
item
)
{
return
restTemplate
.
post
ForEntity
(
"{host}/
apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
return
restTemplate
.
post
(
env
,
"
apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/items"
,
item
,
ItemDTO
.
class
,
getAdminServiceHost
(
env
)
,
appId
,
clusterName
,
namespace
)
item
,
ItemDTO
.
class
,
appId
,
clusterName
,
namespace
)
.
getBody
()
;
;
}
}
public
void
deleteItem
(
Env
env
,
long
itemId
,
String
operator
)
{
public
void
deleteItem
(
Env
env
,
long
itemId
,
String
operator
)
{
restTemplate
.
delete
(
"{host}/items/{itemId}?operator={operator}"
,
getAdminServiceHost
(
env
)
,
itemId
,
operator
);
restTemplate
.
delete
(
env
,
"items/{itemId}?operator={operator}"
,
itemId
,
operator
);
}
}
}
}
...
@@ -129,64 +118,64 @@ public class AdminServiceAPI {
...
@@ -129,64 +118,64 @@ public class AdminServiceAPI {
public
static
class
ClusterAPI
extends
API
{
public
static
class
ClusterAPI
extends
API
{
public
List
<
ClusterDTO
>
findClustersByApp
(
String
appId
,
Env
env
)
{
public
List
<
ClusterDTO
>
findClustersByApp
(
String
appId
,
Env
env
)
{
ClusterDTO
[]
clusterDTOs
=
restTemplate
.
get
ForObject
(
"{host}/
apps/{appId}/clusters"
,
ClusterDTO
[].
class
,
ClusterDTO
[]
clusterDTOs
=
restTemplate
.
get
(
env
,
"
apps/{appId}/clusters"
,
ClusterDTO
[].
class
,
getAdminServiceHost
(
env
),
appId
);
appId
);
return
Arrays
.
asList
(
clusterDTOs
);
return
Arrays
.
asList
(
clusterDTOs
);
}
}
public
ClusterDTO
loadCluster
(
String
appId
,
Env
env
,
String
clusterName
)
{
public
ClusterDTO
loadCluster
(
String
appId
,
Env
env
,
String
clusterName
)
{
return
restTemplate
.
get
ForObject
(
"{host}/
apps/{appId}/clusters/{clusterName}"
,
ClusterDTO
.
class
,
return
restTemplate
.
get
(
env
,
"
apps/{appId}/clusters/{clusterName}"
,
ClusterDTO
.
class
,
getAdminServiceHost
(
env
),
appId
,
clusterName
);
appId
,
clusterName
);
}
}
public
boolean
isClusterUnique
(
String
appId
,
Env
env
,
String
clusterName
)
{
public
boolean
isClusterUnique
(
String
appId
,
Env
env
,
String
clusterName
)
{
return
restTemplate
return
restTemplate
.
get
ForObject
(
"{host}/apps/{appId}/cluster/{clusterName}/unique"
,
Boolean
.
class
,
getAdminServiceHost
(
env
)
,
.
get
(
env
,
"apps/{appId}/cluster/{clusterName}/unique"
,
Boolean
.
class
,
appId
,
clusterName
);
appId
,
clusterName
);
}
}
public
ClusterDTO
create
(
Env
env
,
ClusterDTO
cluster
)
{
public
ClusterDTO
create
(
Env
env
,
ClusterDTO
cluster
)
{
return
restTemplate
.
post
ForObject
(
"{host}/
apps/{appId}/clusters"
,
cluster
,
ClusterDTO
.
class
,
return
restTemplate
.
post
(
env
,
"
apps/{appId}/clusters"
,
cluster
,
ClusterDTO
.
class
,
getAdminServiceHost
(
env
),
cluster
.
getAppId
());
cluster
.
getAppId
());
}
}
}
}
@Service
@Service
public
static
class
ReleaseAPI
extends
API
{
public
static
class
ReleaseAPI
extends
API
{
public
List
<
ReleaseDTO
>
findReleases
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
int
page
,
int
size
){
public
List
<
ReleaseDTO
>
findReleases
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
int
page
,
ReleaseDTO
[]
releaseDTOs
=
restTemplate
.
getForObject
(
int
size
)
{
"{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases?page={page}&size={size}"
,
ReleaseDTO
[]
releaseDTOs
=
restTemplate
.
get
(
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases?page={page}&size={size}"
,
ReleaseDTO
[].
class
,
ReleaseDTO
[].
class
,
getAdminServiceHost
(
env
),
appId
,
clusterName
,
namespaceName
,
page
,
size
);
appId
,
clusterName
,
namespaceName
,
page
,
size
);
return
Arrays
.
asList
(
releaseDTOs
);
return
Arrays
.
asList
(
releaseDTOs
);
}
}
public
ReleaseDTO
loadLatestRelease
(
String
appId
,
Env
env
,
String
clusterName
,
public
ReleaseDTO
loadLatestRelease
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
)
{
String
namespace
)
{
ReleaseDTO
releaseDTO
=
restTemplate
ReleaseDTO
releaseDTO
=
restTemplate
.
get
ForObject
(
"{host}/
apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/latest"
,
.
get
(
env
,
"
apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases/latest"
,
ReleaseDTO
.
class
,
getAdminServiceHost
(
env
)
,
appId
,
clusterName
,
namespace
);
ReleaseDTO
.
class
,
appId
,
clusterName
,
namespace
);
return
releaseDTO
;
return
releaseDTO
;
}
}
public
ReleaseDTO
release
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
public
ReleaseDTO
release
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespace
,
String
release
By
,
String
comment
,
String
operator
)
{
String
release
Title
,
String
comment
,
String
operator
)
{
HttpHeaders
headers
=
new
HttpHeaders
();
HttpHeaders
headers
=
new
HttpHeaders
();
headers
.
setContentType
(
MediaType
.
parseMediaType
(
MediaType
.
APPLICATION_FORM_URLENCODED_VALUE
+
";charset=UTF-8"
));
headers
.
setContentType
(
MediaType
.
parseMediaType
(
MediaType
.
APPLICATION_FORM_URLENCODED_VALUE
+
";charset=UTF-8"
));
MultiValueMap
<
String
,
String
>
parameters
=
new
LinkedMultiValueMap
<>();
MultiValueMap
<
String
,
String
>
parameters
=
new
LinkedMultiValueMap
<>();
parameters
.
add
(
"name"
,
release
By
);
parameters
.
add
(
"name"
,
release
Title
);
parameters
.
add
(
"comment"
,
comment
);
parameters
.
add
(
"comment"
,
comment
);
parameters
.
add
(
"operator"
,
operator
);
parameters
.
add
(
"operator"
,
operator
);
HttpEntity
<
MultiValueMap
<
String
,
String
>>
entity
=
HttpEntity
<
MultiValueMap
<
String
,
String
>>
entity
=
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
parameters
,
headers
);
new
HttpEntity
<>(
parameters
,
headers
);
ResponseEntity
<
ReleaseDTO
>
response
=
ReleaseDTO
response
=
restTemplate
.
post
(
restTemplate
env
,
"apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases"
,
entity
,
.
postForEntity
(
"{host}/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/releases"
,
entity
,
ReleaseDTO
.
class
,
ReleaseDTO
.
class
,
appId
,
clusterName
,
namespace
);
getAdminServiceHost
(
env
),
appId
,
clusterName
,
namespace
);
return
response
;
return
response
.
getBody
();
}
}
}
}
...
@@ -195,10 +184,10 @@ public class AdminServiceAPI {
...
@@ -195,10 +184,10 @@ public class AdminServiceAPI {
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
)
{
CommitDTO
[]
commitDTOs
=
restTemplate
.
get
ForObject
(
CommitDTO
[]
commitDTOs
=
restTemplate
.
get
(
env
,
"{host}/
apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit?page={page}&size={size}"
,
"
apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/commit?page={page}&size={size}"
,
CommitDTO
[].
class
,
CommitDTO
[].
class
,
getAdminServiceHost
(
env
),
appId
,
clusterName
,
namespaceName
,
page
,
size
);
appId
,
clusterName
,
namespaceName
,
page
,
size
);
return
Arrays
.
asList
(
commitDTOs
);
return
Arrays
.
asList
(
commitDTOs
);
}
}
...
@@ -208,9 +197,9 @@ public class AdminServiceAPI {
...
@@ -208,9 +197,9 @@ public class AdminServiceAPI {
public
static
class
NamespaceLockAPI
extends
API
{
public
static
class
NamespaceLockAPI
extends
API
{
public
NamespaceLockDTO
getNamespaceLockOwner
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
public
NamespaceLockDTO
getNamespaceLockOwner
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
)
{
return
restTemplate
.
get
ForObject
(
"{host}/
apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock"
,
return
restTemplate
.
get
(
env
,
"
apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/lock"
,
NamespaceLockDTO
.
class
,
NamespaceLockDTO
.
class
,
getAdminServiceHost
(
env
),
appId
,
clusterName
,
namespaceName
);
appId
,
clusterName
,
namespaceName
);
}
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/
service/Service
Locator.java
→
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/
api/AdminServiceAddress
Locator.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.
service
;
package
com.ctrip.framework.apollo.portal.
api
;
import
java.net.URI
;
import
com.ctrip.framework.apollo.core.MetaDomainConsts
;
import
java.util.Map
;
import
com.ctrip.framework.apollo.core.dto.ServiceDTO
;
import
java.util.concurrent.ConcurrentHashMap
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
import
com.dianping.cat.Cat
;
import
javax.annotation.PostConstruct
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.web.HttpMessageConverters
;
import
org.springframework.boot.autoconfigure.web.HttpMessageConverters
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
org.springframework.http.client.SimpleClientHttpRequestFactory
;
import
org.springframework.http.client.SimpleClientHttpRequestFactory
;
import
org.springframework.stereotype.
Service
;
import
org.springframework.stereotype.
Component
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
com.ctrip.framework.apollo.core.MetaDomainConsts
;
import
java.util.Arrays
;
import
com.ctrip.framework.apollo.core.dto.ServiceDTO
;
import
java.util.List
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
java.util.Map
;
import
com.ctrip.framework.apollo.core.exception.ServiceException
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.Executors
;
import
java.util.concurrent.ScheduledExecutorService
;
import
java.util.concurrent.TimeUnit
;
/**
import
javax.annotation.PostConstruct
;
* @author liuym
*/
@Service
public
class
ServiceLocator
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ServiceLocator
.
class
);
@Component
public
class
AdminServiceAddressLocator
{
private
static
final
int
DEFAULT_TIMEOUT_MS
=
1000
;
private
static
final
int
DEFAULT_TIMEOUT_MS
=
1000
;
private
static
final
long
REFRESH_INTERVAL
=
5
*
60
*
1000
;
private
static
final
int
RETRY_TIMES
=
3
;
private
static
final
int
RETRY_TIMES
=
3
;
private
static
final
int
CALL_META_SERVER_THRESHOLD
=
2
;
private
static
final
String
ADMIN_SERVICE_URL_PATH
=
"/services/admin"
;
private
static
final
String
ADMIN_SERVICE_URL_PATH
=
"/services/admin"
;
private
ScheduledExecutorService
refreshServiceAddressService
;
private
RestTemplate
restTemplate
;
private
RestTemplate
restTemplate
;
private
List
<
Env
>
allEnvs
;
private
Map
<
Env
,
List
<
ServiceDTO
>>
cache
=
new
ConcurrentHashMap
<>();
@Autowired
@Autowired
private
HttpMessageConverters
httpMessageConverters
;
private
HttpMessageConverters
httpMessageConverters
;
@Autowired
private
Map
<
Env
,
ServiceDTO
[]>
serviceAddressCache
=
new
ConcurrentHashMap
<>();
private
PortalSettings
portalSettings
;
private
final
AtomicInteger
adminCallCounts
=
new
AtomicInteger
(
0
);
@PostConstruct
@PostConstruct
private
void
postConstruct
()
{
public
void
init
()
{
allEnvs
=
portalSettings
.
getAllEnvs
();
//init restTemplate
restTemplate
=
new
RestTemplate
(
httpMessageConverters
.
getConverters
());
restTemplate
=
new
RestTemplate
(
httpMessageConverters
.
getConverters
());
if
(
restTemplate
.
getRequestFactory
()
instanceof
SimpleClientHttpRequestFactory
)
{
if
(
restTemplate
.
getRequestFactory
()
instanceof
SimpleClientHttpRequestFactory
)
{
SimpleClientHttpRequestFactory
rf
=
SimpleClientHttpRequestFactory
rf
=
...
@@ -60,58 +58,52 @@ public class ServiceLocator {
...
@@ -60,58 +58,52 @@ public class ServiceLocator {
rf
.
setReadTimeout
(
DEFAULT_TIMEOUT_MS
);
rf
.
setReadTimeout
(
DEFAULT_TIMEOUT_MS
);
rf
.
setConnectTimeout
(
DEFAULT_TIMEOUT_MS
);
rf
.
setConnectTimeout
(
DEFAULT_TIMEOUT_MS
);
}
}
refreshServiceAddressService
=
Executors
.
newScheduledThreadPool
(
1
);
refreshServiceAddressService
.
scheduleWithFixedDelay
(
new
RefreshAdminServerAddressTask
(),
0
,
REFRESH_INTERVAL
,
TimeUnit
.
MILLISECONDS
);
}
}
public
List
<
ServiceDTO
>
getServiceList
(
Env
env
)
{
return
cache
.
get
(
env
);
}
public
ServiceDTO
getServiceAddress
(
Env
env
)
throws
ServiceException
{
//Maintain admin server address
class
RefreshAdminServerAddressTask
implements
Runnable
{
if
(
adminCallCounts
.
get
()
%
CALL_META_SERVER_THRESHOLD
==
0
)
{
@Override
return
getServiceAddressFromMetaServer
(
env
);
public
void
run
()
{
}
else
{
for
(
Env
env
:
allEnvs
)
{
//if cached then return from cache
refreshServerAddressCache
(
env
);
ServiceDTO
[]
serviceDTOs
=
serviceAddressCache
.
get
(
env
);
if
(
serviceDTOs
!=
null
&&
serviceDTOs
.
length
>
0
){
return
randomServiceAddress
(
serviceDTOs
);
}
else
{
//return from meta server
return
getServiceAddressFromMetaServer
(
env
);
}
}
}
}
}
}
p
ublic
ServiceDTO
getServiceAddressFromMetaServer
(
Env
env
)
{
p
rivate
void
refreshServerAddressCache
(
Env
env
)
{
//retry
for
(
int
i
=
0
;
i
<
RETRY_TIMES
;
i
++)
{
for
(
int
i
=
0
;
i
<
RETRY_TIMES
;
i
++)
{
ServiceDTO
[]
services
=
getServices
(
env
);
if
(
services
!=
null
&&
services
.
length
>
0
)
{
try
{
serviceAddressCache
.
put
(
env
,
services
);
ServiceDTO
[]
services
=
getAdminServerAddress
(
env
);
return
randomServiceAddress
(
services
);
if
(
services
==
null
||
services
.
length
==
0
)
{
}
else
{
continue
;
logger
.
warn
(
String
.
format
(
"can not get %s admin service address at %d time"
,
env
,
i
));
}
cache
.
put
(
env
,
Arrays
.
asList
(
services
));
break
;
}
catch
(
Throwable
e
)
{
//meta server error
Cat
.
logError
(
"get admin server address fail"
,
e
);
continue
;
}
}
}
}
//clear cache
serviceAddressCache
.
remove
(
env
);
logger
.
error
(
String
.
format
(
"can not get %s admin service address"
,
env
));
throw
new
ServiceException
(
"No available admin service"
);
}
}
private
ServiceDTO
[]
getAdminServerAddress
(
Env
env
)
{
private
ServiceDTO
[]
getServices
(
Env
env
)
{
String
domainName
=
MetaDomainConsts
.
getDomain
(
env
);
String
domainName
=
MetaDomainConsts
.
getDomain
(
env
);
String
url
=
domainName
+
ADMIN_SERVICE_URL_PATH
;
String
url
=
domainName
+
ADMIN_SERVICE_URL_PATH
;
return
restTemplate
.
getForObject
(
url
,
ServiceDTO
[].
class
);
try
{
return
restTemplate
.
getForObject
(
new
URI
(
url
),
ServiceDTO
[].
class
);
}
catch
(
Exception
ex
)
{
logger
.
warn
(
ex
.
getMessage
());
return
null
;
}
}
}
private
ServiceDTO
randomServiceAddress
(
ServiceDTO
[]
services
){
return
services
[
Math
.
abs
(
adminCallCounts
.
getAndIncrement
())
%
services
.
length
];
}
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/api/RetryableRestTemplate.java
0 → 100644
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.api
;
import
com.ctrip.framework.apollo.core.dto.ServiceDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.exception.ServiceException
;
import
com.ctrip.framework.apollo.portal.constant.CatEventType
;
import
com.dianping.cat.Cat
;
import
com.dianping.cat.message.Message
;
import
com.dianping.cat.message.Transaction
;
import
org.apache.http.conn.ConnectTimeoutException
;
import
org.apache.http.conn.HttpHostConnectException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.client.RestClientException
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.util.DefaultUriTemplateHandler
;
import
org.springframework.web.util.UriTemplateHandler
;
import
java.net.SocketTimeoutException
;
import
java.util.List
;
import
javax.annotation.PostConstruct
;
/**
* 封装RestTemplate. admin server集群在某些机器宕机或者超时的情况下轮询重试
*/
@Component
public
class
RetryableRestTemplate
{
private
UriTemplateHandler
uriTemplateHandler
=
new
DefaultUriTemplateHandler
();
private
RestTemplate
restTemplate
;
@Autowired
private
RestTemplateFactory
restTemplateFactory
;
@Autowired
private
AdminServiceAddressLocator
adminServiceAddressLocator
;
@PostConstruct
private
void
postConstruct
()
{
restTemplate
=
restTemplateFactory
.
getObject
();
}
public
<
T
>
T
get
(
Env
env
,
String
path
,
Class
<
T
>
responseType
,
Object
...
urlVariables
)
throws
RestClientException
{
return
execute
(
HttpMethod
.
GET
,
env
,
path
,
null
,
responseType
,
urlVariables
);
}
public
<
T
>
T
post
(
Env
env
,
String
path
,
Object
request
,
Class
<
T
>
responseType
,
Object
...
uriVariables
)
throws
RestClientException
{
return
execute
(
HttpMethod
.
POST
,
env
,
path
,
request
,
responseType
,
uriVariables
);
}
public
void
put
(
Env
env
,
String
path
,
Object
request
,
Object
...
urlVariables
)
throws
RestClientException
{
execute
(
HttpMethod
.
PUT
,
env
,
path
,
request
,
null
,
urlVariables
);
}
public
void
delete
(
Env
env
,
String
path
,
Object
...
urlVariables
)
throws
RestClientException
{
execute
(
HttpMethod
.
DELETE
,
env
,
path
,
null
,
null
,
urlVariables
);
}
private
<
T
>
T
execute
(
HttpMethod
method
,
Env
env
,
String
path
,
Object
request
,
Class
<
T
>
responseType
,
Object
...
uriVariables
)
{
String
uri
=
uriTemplateHandler
.
expand
(
path
,
uriVariables
).
getPath
();
Transaction
ct
=
Cat
.
newTransaction
(
"AdminAPI"
,
uri
);
List
<
ServiceDTO
>
services
=
adminServiceAddressLocator
.
getServiceList
(
env
);
if
(
CollectionUtils
.
isEmpty
(
services
))
{
ServiceException
e
=
new
ServiceException
(
"No available admin service"
);
ct
.
setStatus
(
e
);
ct
.
complete
();
throw
e
;
}
for
(
ServiceDTO
serviceDTO
:
services
)
{
try
{
T
result
=
doExecute
(
method
,
serviceDTO
,
path
,
request
,
responseType
,
uriVariables
);
ct
.
setStatus
(
Message
.
SUCCESS
);
ct
.
complete
();
return
result
;
}
catch
(
Throwable
t
)
{
Cat
.
logError
(
t
);
if
(
canRetry
(
t
,
method
))
{
Cat
.
logEvent
(
CatEventType
.
API_RETRY
,
uri
);
continue
;
}
else
{
//biz exception rethrow
ct
.
setStatus
(
t
);
ct
.
complete
();
throw
t
;
}
}
}
//all admin server down
ServiceException
e
=
new
ServiceException
(
"No available admin service"
);
ct
.
setStatus
(
e
);
ct
.
complete
();
throw
e
;
}
private
<
T
>
T
doExecute
(
HttpMethod
method
,
ServiceDTO
service
,
String
path
,
Object
request
,
Class
<
T
>
responseType
,
Object
...
uriVariables
)
{
T
result
=
null
;
switch
(
method
)
{
case
GET:
result
=
restTemplate
.
getForObject
(
parseHost
(
service
)
+
path
,
responseType
,
uriVariables
);
break
;
case
POST:
result
=
restTemplate
.
postForEntity
(
parseHost
(
service
)
+
path
,
request
,
responseType
,
uriVariables
).
getBody
();
break
;
case
PUT:
restTemplate
.
put
(
parseHost
(
service
)
+
path
,
request
,
uriVariables
);
break
;
case
DELETE:
restTemplate
.
delete
(
parseHost
(
service
)
+
path
,
uriVariables
);
break
;
default
:
throw
new
UnsupportedOperationException
(
String
.
format
(
"not supported http method(method=%s)"
,
method
));
}
return
result
;
}
private
String
parseHost
(
ServiceDTO
serviceAddress
)
{
return
serviceAddress
.
getHomepageUrl
()
+
"/"
;
}
//post,delete,put请求在admin server处理超时情况下不重试
private
boolean
canRetry
(
Throwable
e
,
HttpMethod
method
)
{
Throwable
nestedException
=
e
.
getCause
();
if
(
method
==
HttpMethod
.
GET
)
{
return
nestedException
instanceof
SocketTimeoutException
||
nestedException
instanceof
HttpHostConnectException
||
nestedException
instanceof
ConnectTimeoutException
;
}
else
{
return
nestedException
instanceof
HttpHostConnectException
||
nestedException
instanceof
ConnectTimeoutException
;
}
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/CtripLogoutHandler.java
→
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/
ctrip/
CtripLogoutHandler.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.auth
;
package
com.ctrip.framework.apollo.portal.auth
.ctrip
;
import
com.ctrip.framework.apollo.portal.auth.LogoutHandler
;
import
com.ctrip.framework.apollo.portal.service.ServerConfigService
;
import
com.ctrip.framework.apollo.portal.service.ServerConfigService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -11,7 +12,7 @@ import javax.servlet.http.HttpServletRequest;
...
@@ -11,7 +12,7 @@ import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.http.HttpSession
;
public
class
CtripLogoutHandler
implements
LogoutHandler
{
public
class
CtripLogoutHandler
implements
LogoutHandler
{
@Autowired
@Autowired
private
ServerConfigService
serverConfigService
;
private
ServerConfigService
serverConfigService
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/CtripSsoHeartbeatHandler.java
→
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/
ctrip/
CtripSsoHeartbeatHandler.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.auth
;
package
com.ctrip.framework.apollo.portal.auth.ctrip
;
import
com.ctrip.framework.apollo.portal.auth.SsoHeartbeatHandler
;
import
java.io.IOException
;
import
java.io.IOException
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/CtripUserInfoHolder.java
→
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/
ctrip/
CtripUserInfoHolder.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.auth
;
package
com.ctrip.framework.apollo.portal.auth
.ctrip
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.entity.po.UserInfo
;
import
com.ctrip.framework.apollo.portal.entity.po.UserInfo
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
...
@@ -7,7 +8,7 @@ import java.lang.reflect.Method;
...
@@ -7,7 +8,7 @@ import java.lang.reflect.Method;
/**
/**
* ctrip内部实现的获取用户信息
* ctrip内部实现的获取用户信息
*/
*/
public
class
CtripUserInfoHolder
implements
UserInfoHolder
{
public
class
CtripUserInfoHolder
implements
UserInfoHolder
{
private
Object
assertionHolder
;
private
Object
assertionHolder
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/CtripUserService.java
→
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/
ctrip/
CtripUserService.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.auth
;
package
com.ctrip.framework.apollo.portal.auth
.ctrip
;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
...
@@ -62,7 +62,7 @@ public class CtripUserService implements UserService {
...
@@ -62,7 +62,7 @@ public class CtripUserService implements UserService {
}
}
@Override
@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
);
UserServiceRequest
request
=
assembleSearchUserRequest
(
keyword
,
offset
,
limit
);
HttpEntity
<
UserServiceRequest
>
entity
=
new
HttpEntity
<>(
request
);
HttpEntity
<
UserServiceRequest
>
entity
=
new
HttpEntity
<>(
request
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/DefaultLogoutHandler.java
→
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/
defaultimpl/
DefaultLogoutHandler.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.auth
;
package
com.ctrip.framework.apollo.portal.auth.defaultimpl
;
import
com.ctrip.framework.apollo.portal.auth.LogoutHandler
;
import
java.io.IOException
;
import
java.io.IOException
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
public
class
DefaultLogoutHandler
implements
LogoutHandler
{
public
class
DefaultLogoutHandler
implements
LogoutHandler
{
@Override
@Override
public
void
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
public
void
logout
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/DefaultSsoHeartbeatHandler.java
→
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/
defaultimpl/
DefaultSsoHeartbeatHandler.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.auth
;
package
com.ctrip.framework.apollo.portal.auth.defaultimpl
;
import
com.ctrip.framework.apollo.portal.auth.SsoHeartbeatHandler
;
import
java.io.IOException
;
import
java.io.IOException
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/DefaultUserInfoHolder.java
→
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/
defaultimpl/
DefaultUserInfoHolder.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.auth
;
package
com.ctrip.framework.apollo.portal.auth
.defaultimpl
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.entity.po.UserInfo
;
import
com.ctrip.framework.apollo.portal.entity.po.UserInfo
;
/**
/**
* 不是ctrip的公司默认提供一个假用户
* 不是ctrip的公司默认提供一个假用户
*/
*/
public
class
DefaultUserInfoHolder
implements
UserInfoHolder
{
public
class
DefaultUserInfoHolder
implements
UserInfoHolder
{
public
DefaultUserInfoHolder
(){
public
DefaultUserInfoHolder
(){
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/DefaultUserService.java
→
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/auth/
defaultimpl/
DefaultUserService.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.auth
;
package
com.ctrip.framework.apollo.portal.auth
.defaultimpl
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/configutation/AuthConfiguration.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.configutation
;
package
com.ctrip.framework.apollo.portal.configutation
;
import
com.ctrip.framework.apollo.portal.auth.CtripLogoutHandler
;
import
com.ctrip.framework.apollo.portal.auth.
ctrip.
CtripLogoutHandler
;
import
com.ctrip.framework.apollo.portal.auth.CtripSsoHeartbeatHandler
;
import
com.ctrip.framework.apollo.portal.auth.
ctrip.
CtripSsoHeartbeatHandler
;
import
com.ctrip.framework.apollo.portal.auth.CtripUserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.
ctrip.
CtripUserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.CtripUserService
;
import
com.ctrip.framework.apollo.portal.auth.
ctrip.
CtripUserService
;
import
com.ctrip.framework.apollo.portal.auth.DefaultLogoutHandler
;
import
com.ctrip.framework.apollo.portal.auth.
defaultimpl.
DefaultLogoutHandler
;
import
com.ctrip.framework.apollo.portal.auth.DefaultSsoHeartbeatHandler
;
import
com.ctrip.framework.apollo.portal.auth.
defaultimpl.
DefaultSsoHeartbeatHandler
;
import
com.ctrip.framework.apollo.portal.auth.DefaultUserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.
defaultimpl.
DefaultUserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.DefaultUserService
;
import
com.ctrip.framework.apollo.portal.auth.
defaultimpl.
DefaultUserService
;
import
com.ctrip.framework.apollo.portal.auth.LogoutHandler
;
import
com.ctrip.framework.apollo.portal.auth.LogoutHandler
;
import
com.ctrip.framework.apollo.portal.auth.SsoHeartbeatHandler
;
import
com.ctrip.framework.apollo.portal.auth.SsoHeartbeatHandler
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/constant/CatEventType.java
0 → 100644
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.constant
;
public
interface
CatEventType
{
String
RELEASE_NAMESPACE
=
"Namespace.Release"
;
String
MODIFY_NAMESPACE_BY_TEXT
=
"Namespace.Modify.Text"
;
String
MODIFY_NAMESPACE
=
"Namespace.Modify"
;
String
SYNC_NAMESPACE
=
"Namespace.Sync"
;
String
CREATE_APP
=
"App.Create"
;
String
CREATE_CLUSTER
=
"Cluster.Create"
;
String
CREATE_NAMESPACE
=
"Namespace.Create"
;
String
API_RETRY
=
"API.Retry"
;
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/entity/form/NamespaceReleaseModel.java
浏览文件 @
0447fca3
...
@@ -10,12 +10,12 @@ public class NamespaceReleaseModel implements Verifiable {
...
@@ -10,12 +10,12 @@ public class NamespaceReleaseModel implements Verifiable {
private
String
env
;
private
String
env
;
private
String
clusterName
;
private
String
clusterName
;
private
String
namespaceName
;
private
String
namespaceName
;
private
String
release
By
;
private
String
release
Title
;
private
String
releaseComment
;
private
String
releaseComment
;
@Override
@Override
public
boolean
isInvalid
()
{
public
boolean
isInvalid
()
{
return
StringUtils
.
isContainEmpty
(
appId
,
env
,
clusterName
,
namespaceName
,
release
By
);
return
StringUtils
.
isContainEmpty
(
appId
,
env
,
clusterName
,
namespaceName
,
release
Title
);
}
}
public
String
getAppId
()
{
public
String
getAppId
()
{
...
@@ -50,12 +50,12 @@ public class NamespaceReleaseModel implements Verifiable {
...
@@ -50,12 +50,12 @@ public class NamespaceReleaseModel implements Verifiable {
this
.
namespaceName
=
namespaceName
;
this
.
namespaceName
=
namespaceName
;
}
}
public
String
getRelease
By
()
{
public
String
getRelease
Title
()
{
return
release
By
;
return
release
Title
;
}
}
public
void
setRelease
By
(
String
releaseBy
)
{
public
void
setRelease
Title
(
String
releaseTitle
)
{
this
.
release
By
=
releaseBy
;
this
.
release
Title
=
releaseTitle
;
}
}
public
String
getReleaseComment
()
{
public
String
getReleaseComment
()
{
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/listener/CreationListener.java
浏览文件 @
0447fca3
...
@@ -6,7 +6,7 @@ import com.ctrip.framework.apollo.core.dto.AppNamespaceDTO;
...
@@ -6,7 +6,7 @@ import com.ctrip.framework.apollo.core.dto.AppNamespaceDTO;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
import
com.ctrip.framework.apollo.portal.PortalSettings
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.
ctrip.framework.apollo.portal.service.RoleInitializationService
;
import
com.
dianping.cat.Cat
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -27,8 +27,6 @@ public class CreationListener {
...
@@ -27,8 +27,6 @@ public class CreationListener {
private
AdminServiceAPI
.
AppAPI
appAPI
;
private
AdminServiceAPI
.
AppAPI
appAPI
;
@Autowired
@Autowired
private
AdminServiceAPI
.
NamespaceAPI
namespaceAPI
;
private
AdminServiceAPI
.
NamespaceAPI
namespaceAPI
;
@Autowired
private
RoleInitializationService
roleInitializationService
;
@EventListener
@EventListener
public
void
onAppCreationEvent
(
AppCreationEvent
event
)
{
public
void
onAppCreationEvent
(
AppCreationEvent
event
)
{
...
@@ -38,20 +36,22 @@ public class CreationListener {
...
@@ -38,20 +36,22 @@ public class CreationListener {
try
{
try
{
appAPI
.
createApp
(
env
,
appDTO
);
appAPI
.
createApp
(
env
,
appDTO
);
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
logger
.
error
(
"call appAPI.createApp error.[{app}, {env}]"
,
appDTO
.
getAppId
(),
env
,
e
);
logger
.
error
(
"call appAPI.createApp error.(appId={appId}, env={env})"
,
appDTO
.
getAppId
(),
env
,
e
);
Cat
.
logError
(
String
.
format
(
"call appAPI.createApp error. (appId=%s, env=%s)"
,
appDTO
.
getAppId
(),
env
),
e
);
}
}
}
}
}
}
@EventListener
@EventListener
public
void
onAppNamespaceCreationEvent
(
AppNamespaceCreationEvent
event
){
public
void
onAppNamespaceCreationEvent
(
AppNamespaceCreationEvent
event
){
AppNamespaceDTO
dto
=
BeanUtils
.
transfrom
(
AppNamespaceDTO
.
class
,
event
.
getAppNamespace
());
AppNamespaceDTO
appNamespace
=
BeanUtils
.
transfrom
(
AppNamespaceDTO
.
class
,
event
.
getAppNamespace
());
List
<
Env
>
envs
=
portalSettings
.
getActiveEnvs
();
List
<
Env
>
envs
=
portalSettings
.
getActiveEnvs
();
for
(
Env
env
:
envs
)
{
for
(
Env
env
:
envs
)
{
try
{
try
{
namespaceAPI
.
createAppNamespace
(
env
,
dto
);
namespaceAPI
.
createAppNamespace
(
env
,
appNamespace
);
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
logger
.
error
(
"call namespaceAPI.createAppNamespace error. [{app}, {env}]"
,
dto
.
getAppId
(),
env
,
e
);
logger
.
error
(
"call appAPI.createApp error.(appId={appId}, env={env})"
,
appNamespace
.
getAppId
(),
env
,
e
);
Cat
.
logError
(
String
.
format
(
"call appAPI.createApp error. (appId=%s, env=%s)"
,
appNamespace
.
getAppId
(),
env
),
e
);
}
}
}
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/AppService.java
浏览文件 @
0447fca3
...
@@ -20,8 +20,10 @@ import com.ctrip.framework.apollo.core.enums.Env;
...
@@ -20,8 +20,10 @@ import com.ctrip.framework.apollo.core.enums.Env;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.constant.CatEventType
;
import
com.ctrip.framework.apollo.portal.entity.vo.EnvClusterInfo
;
import
com.ctrip.framework.apollo.portal.entity.vo.EnvClusterInfo
;
import
com.ctrip.framework.apollo.portal.repository.AppRepository
;
import
com.ctrip.framework.apollo.portal.repository.AppRepository
;
import
com.dianping.cat.Cat
;
@Service
@Service
public
class
AppService
{
public
class
AppService
{
...
@@ -94,6 +96,8 @@ public class AppService {
...
@@ -94,6 +96,8 @@ public class AppService {
appNamespaceService
.
createDefaultAppNamespace
(
appId
);
appNamespaceService
.
createDefaultAppNamespace
(
appId
);
//role
//role
roleInitializationService
.
initAppRoles
(
createdApp
);
roleInitializationService
.
initAppRoles
(
createdApp
);
Cat
.
logEvent
(
CatEventType
.
CREATE_APP
,
appId
);
return
createdApp
;
return
createdApp
;
}
}
}
}
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ClusterService.java
浏览文件 @
0447fca3
...
@@ -4,6 +4,8 @@ import com.ctrip.framework.apollo.core.enums.Env;
...
@@ -4,6 +4,8 @@ import com.ctrip.framework.apollo.core.enums.Env;
import
com.ctrip.framework.apollo.core.dto.ClusterDTO
;
import
com.ctrip.framework.apollo.core.dto.ClusterDTO
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.constant.CatEventType
;
import
com.dianping.cat.Cat
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -24,7 +26,11 @@ public class ClusterService {
...
@@ -24,7 +26,11 @@ public class ClusterService {
if
(!
clusterAPI
.
isClusterUnique
(
cluster
.
getAppId
(),
env
,
cluster
.
getName
())){
if
(!
clusterAPI
.
isClusterUnique
(
cluster
.
getAppId
(),
env
,
cluster
.
getName
())){
throw
new
BadRequestException
(
String
.
format
(
"cluster %s already exists."
,
cluster
.
getName
()));
throw
new
BadRequestException
(
String
.
format
(
"cluster %s already exists."
,
cluster
.
getName
()));
}
}
return
clusterAPI
.
create
(
env
,
cluster
);
ClusterDTO
clusterDTO
=
clusterAPI
.
create
(
env
,
cluster
);
Cat
.
logEvent
(
CatEventType
.
CREATE_CLUSTER
,
cluster
.
getAppId
(),
"0"
,
cluster
.
getName
());
return
clusterDTO
;
}
}
}
}
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigService.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.service
;
package
com.ctrip.framework.apollo.portal.service
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
...
@@ -11,20 +9,23 @@ import org.springframework.util.CollectionUtils;
...
@@ -11,20 +9,23 @@ import org.springframework.util.CollectionUtils;
import
org.springframework.web.client.HttpClientErrorException
;
import
org.springframework.web.client.HttpClientErrorException
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.core.enums.ConfigFileFormat
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.framework.apollo.core.dto.ItemChangeSets
;
import
com.ctrip.framework.apollo.core.dto.ItemDTO
;
import
com.ctrip.framework.apollo.core.dto.ItemDTO
;
import
com.ctrip.framework.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.core.exception.BadRequestException
;
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.core.utils.StringUtils
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.constant.CatEventType
;
import
com.ctrip.framework.apollo.portal.entity.form.NamespaceReleaseModel
;
import
com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs
;
import
com.ctrip.framework.apollo.portal.entity.vo.ItemDiffs
;
import
com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifer
;
import
com.ctrip.framework.apollo.portal.entity.vo.NamespaceIdentifer
;
import
com.ctrip.framework.apollo.portal.entity.form.NamespaceTextModel
;
import
com.ctrip.framework.apollo.portal.entity.form.NamespaceTextModel
;
import
com.ctrip.framework.apollo.portal.service.txtresolver.ConfigTextResolver
;
import
com.ctrip.framework.apollo.portal.service.txtresolver.ConfigTextResolver
;
import
com.dianping.cat.Cat
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.List
;
...
@@ -33,8 +34,6 @@ import java.util.Map;
...
@@ -33,8 +34,6 @@ import java.util.Map;
@Service
@Service
public
class
ConfigService
{
public
class
ConfigService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
ConfigService
.
class
);
@Autowired
@Autowired
private
UserInfoHolder
userInfoHolder
;
private
UserInfoHolder
userInfoHolder
;
@Autowired
@Autowired
...
@@ -77,6 +76,9 @@ public class ConfigService {
...
@@ -77,6 +76,9 @@ public class ConfigService {
changeSets
.
setDataChangeLastModifiedBy
(
userInfoHolder
.
getUser
().
getUserId
());
changeSets
.
setDataChangeLastModifiedBy
(
userInfoHolder
.
getUser
().
getUserId
());
itemAPI
.
updateItemsByChangeSet
(
appId
,
env
,
clusterName
,
namespaceName
,
changeSets
);
itemAPI
.
updateItemsByChangeSet
(
appId
,
env
,
clusterName
,
namespaceName
,
changeSets
);
Cat
.
logEvent
(
CatEventType
.
MODIFY_NAMESPACE_BY_TEXT
,
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
));
}
}
...
@@ -92,7 +94,9 @@ public class ConfigService {
...
@@ -92,7 +94,9 @@ public class ConfigService {
item
.
setDataChangeCreatedBy
(
username
);
item
.
setDataChangeCreatedBy
(
username
);
item
.
setDataChangeLastModifiedBy
(
username
);
item
.
setDataChangeLastModifiedBy
(
username
);
return
itemAPI
.
createItem
(
appId
,
env
,
clusterName
,
namespaceName
,
item
);
ItemDTO
itemDTO
=
itemAPI
.
createItem
(
appId
,
env
,
clusterName
,
namespaceName
,
item
);
Cat
.
logEvent
(
CatEventType
.
MODIFY_NAMESPACE
,
String
.
format
(
"%s+%s+%s+%s"
,
appId
,
env
,
clusterName
,
namespaceName
));
return
itemDTO
;
}
}
public
void
updateItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
ItemDTO
item
)
{
public
void
updateItem
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
ItemDTO
item
)
{
...
@@ -115,17 +119,16 @@ public class ConfigService {
...
@@ -115,17 +119,16 @@ public class ConfigService {
NamespaceIdentifer
namespaceIdentifer
=
itemDiff
.
getNamespace
();
NamespaceIdentifer
namespaceIdentifer
=
itemDiff
.
getNamespace
();
ItemChangeSets
changeSets
=
itemDiff
.
getDiffs
();
ItemChangeSets
changeSets
=
itemDiff
.
getDiffs
();
changeSets
.
setDataChangeLastModifiedBy
(
userInfoHolder
.
getUser
().
getUserId
());
changeSets
.
setDataChangeLastModifiedBy
(
userInfoHolder
.
getUser
().
getUserId
());
try
{
itemAPI
String
appId
=
namespaceIdentifer
.
getAppId
();
.
updateItemsByChangeSet
(
namespaceIdentifer
.
getAppId
(),
namespaceIdentifer
.
getEnv
(),
Env
env
=
namespaceIdentifer
.
getEnv
();
namespaceIdentifer
.
getClusterName
(),
String
clusterName
=
namespaceIdentifer
.
getClusterName
();
namespaceIdentifer
.
getNamespaceName
(),
changeSets
);
String
namespaceName
=
namespaceIdentifer
.
getNamespaceName
(
);
}
catch
(
HttpClientErrorException
e
)
{
logger
.
error
(
"sync items error. namespace:{}"
,
namespaceIdentifer
);
itemAPI
.
updateItemsByChangeSet
(
appId
,
env
,
clusterName
,
namespaceName
,
changeSets
);
throw
new
ServiceException
(
String
.
format
(
"sync item error. env:%s, clusterName:%s"
,
namespaceIdentifer
.
getEnv
(),
namespaceIdentifer
.
getClusterName
()),
e
);
Cat
.
logEvent
(
CatEventType
.
SYNC_NAMESPACE
,
String
.
format
(
"%s+%s+%s+%s"
,
appId
,
env
,
clusterName
,
namespaceName
)
);
}
}
}
}
}
public
List
<
ItemDiffs
>
compare
(
List
<
NamespaceIdentifer
>
comparedNamespaces
,
List
<
ItemDTO
>
sourceItems
)
{
public
List
<
ItemDiffs
>
compare
(
List
<
NamespaceIdentifer
>
comparedNamespaces
,
List
<
ItemDTO
>
sourceItems
)
{
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java
浏览文件 @
0447fca3
...
@@ -4,7 +4,6 @@ import com.google.gson.Gson;
...
@@ -4,7 +4,6 @@ import com.google.gson.Gson;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.common.entity.AppNamespace
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.BeanUtils
;
import
com.ctrip.framework.apollo.common.utils.ExceptionUtils
;
import
com.ctrip.framework.apollo.core.dto.ItemDTO
;
import
com.ctrip.framework.apollo.core.dto.ItemDTO
;
import
com.ctrip.framework.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.framework.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.framework.apollo.core.dto.ReleaseDTO
;
...
@@ -13,14 +12,14 @@ import com.ctrip.framework.apollo.core.enums.Env;
...
@@ -13,14 +12,14 @@ import com.ctrip.framework.apollo.core.enums.Env;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
import
com.ctrip.framework.apollo.core.utils.StringUtils
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.constant.CatEventType
;
import
com.ctrip.framework.apollo.portal.entity.vo.NamespaceVO
;
import
com.ctrip.framework.apollo.portal.entity.vo.NamespaceVO
;
import
com.dianping.cat.Cat
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.client.HttpClientErrorException
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
...
@@ -42,13 +41,10 @@ public class NamespaceService {
...
@@ -42,13 +41,10 @@ public class NamespaceService {
private
AdminServiceAPI
.
ReleaseAPI
releaseAPI
;
private
AdminServiceAPI
.
ReleaseAPI
releaseAPI
;
@Autowired
@Autowired
private
AdminServiceAPI
.
NamespaceAPI
namespaceAPI
;
private
AdminServiceAPI
.
NamespaceAPI
namespaceAPI
;
@Autowired
@Autowired
private
AppNamespaceService
appNamespaceService
;
private
AppNamespaceService
appNamespaceService
;
public
NamespaceDTO
createNamespace
(
Env
env
,
NamespaceDTO
namespace
)
{
public
NamespaceDTO
createNamespace
(
Env
env
,
NamespaceDTO
namespace
)
{
if
(
StringUtils
.
isEmpty
(
namespace
.
getDataChangeCreatedBy
()))
{
if
(
StringUtils
.
isEmpty
(
namespace
.
getDataChangeCreatedBy
()))
{
namespace
.
setDataChangeCreatedBy
(
userInfoHolder
.
getUser
().
getUserId
());
namespace
.
setDataChangeCreatedBy
(
userInfoHolder
.
getUser
().
getUserId
());
...
@@ -56,6 +52,9 @@ public class NamespaceService {
...
@@ -56,6 +52,9 @@ public class NamespaceService {
namespace
.
setDataChangeLastModifiedBy
(
userInfoHolder
.
getUser
().
getUserId
());
namespace
.
setDataChangeLastModifiedBy
(
userInfoHolder
.
getUser
().
getUserId
());
NamespaceDTO
createdNamespace
=
namespaceAPI
.
createNamespace
(
env
,
namespace
);
NamespaceDTO
createdNamespace
=
namespaceAPI
.
createNamespace
(
env
,
namespace
);
Cat
.
logEvent
(
CatEventType
.
CREATE_NAMESPACE
,
String
.
format
(
"%s+%s+%s+%s"
,
namespace
.
getAppId
(),
env
,
namespace
.
getClusterName
(),
namespace
.
getNamespaceName
()));
return
createdNamespace
;
return
createdNamespace
;
}
}
...
@@ -100,17 +99,11 @@ public class NamespaceService {
...
@@ -100,17 +99,11 @@ public class NamespaceService {
String
namespaceName
=
namespace
.
getNamespaceName
();
String
namespaceName
=
namespace
.
getNamespaceName
();
//latest Release
//latest Release
ReleaseDTO
r
elease
=
null
;
ReleaseDTO
latestR
elease
=
null
;
Map
<
String
,
String
>
releaseItems
=
new
HashMap
<>();
Map
<
String
,
String
>
releaseItems
=
new
HashMap
<>();
try
{
latestRelease
=
releaseAPI
.
loadLatestRelease
(
appId
,
env
,
clusterName
,
namespaceName
);
release
=
releaseAPI
.
loadLatestRelease
(
appId
,
env
,
clusterName
,
namespaceName
);
if
(
latestRelease
!=
null
){
releaseItems
=
gson
.
fromJson
(
release
.
getConfigurations
(),
Map
.
class
);
releaseItems
=
gson
.
fromJson
(
latestRelease
.
getConfigurations
(),
Map
.
class
);
}
catch
(
HttpClientErrorException
e
)
{
if
(
e
.
getStatusCode
()
==
HttpStatus
.
NOT_FOUND
)
{
logger
.
warn
(
ExceptionUtils
.
toString
(
e
));
}
else
{
throw
e
;
}
}
}
//not Release config items
//not Release config items
...
@@ -161,6 +154,7 @@ public class NamespaceService {
...
@@ -161,6 +154,7 @@ public class NamespaceService {
namespace
.
setPublic
(
isPublic
);
namespace
.
setPublic
(
isPublic
);
}
}
private
List
<
NamespaceVO
.
ItemVO
>
parseDeletedItems
(
List
<
ItemDTO
>
newItems
,
Map
<
String
,
String
>
releaseItems
)
{
private
List
<
NamespaceVO
.
ItemVO
>
parseDeletedItems
(
List
<
ItemDTO
>
newItems
,
Map
<
String
,
String
>
releaseItems
)
{
Map
<
String
,
ItemDTO
>
newItemMap
=
BeanUtils
.
mapByKey
(
"key"
,
newItems
);
Map
<
String
,
ItemDTO
>
newItemMap
=
BeanUtils
.
mapByKey
(
"key"
,
newItems
);
...
...
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ReleaseService.java
浏览文件 @
0447fca3
...
@@ -6,8 +6,10 @@ import com.ctrip.framework.apollo.core.dto.ReleaseDTO;
...
@@ -6,8 +6,10 @@ import com.ctrip.framework.apollo.core.dto.ReleaseDTO;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAPI
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.auth.UserInfoHolder
;
import
com.ctrip.framework.apollo.portal.constant.CatEventType
;
import
com.ctrip.framework.apollo.portal.entity.form.NamespaceReleaseModel
;
import
com.ctrip.framework.apollo.portal.entity.form.NamespaceReleaseModel
;
import
com.ctrip.framework.apollo.portal.entity.vo.ReleaseVO
;
import
com.ctrip.framework.apollo.portal.entity.vo.ReleaseVO
;
import
com.dianping.cat.Cat
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -22,6 +24,7 @@ import java.util.Set;
...
@@ -22,6 +24,7 @@ import java.util.Set;
@Service
@Service
public
class
ReleaseService
{
public
class
ReleaseService
{
private
static
final
Gson
gson
=
new
Gson
();
private
static
final
Gson
gson
=
new
Gson
();
@Autowired
@Autowired
...
@@ -30,26 +33,33 @@ public class ReleaseService {
...
@@ -30,26 +33,33 @@ public class ReleaseService {
private
AdminServiceAPI
.
ReleaseAPI
releaseAPI
;
private
AdminServiceAPI
.
ReleaseAPI
releaseAPI
;
public
ReleaseDTO
createRelease
(
NamespaceReleaseModel
model
)
{
public
ReleaseDTO
createRelease
(
NamespaceReleaseModel
model
)
{
return
releaseAPI
.
release
(
model
.
getAppId
(),
model
.
getEnv
(),
model
.
getClusterName
(),
String
appId
=
model
.
getAppId
();
model
.
getNamespaceName
(),
model
.
getReleaseBy
(),
model
.
getReleaseComment
()
Env
env
=
model
.
getEnv
();
,
userInfoHolder
.
getUser
().
getUserId
());
String
clusterName
=
model
.
getClusterName
();
String
namespaceName
=
model
.
getNamespaceName
();
ReleaseDTO
releaseDTO
=
releaseAPI
.
release
(
appId
,
env
,
clusterName
,
namespaceName
,
model
.
getReleaseTitle
(),
model
.
getReleaseComment
()
,
userInfoHolder
.
getUser
().
getUserId
());
Cat
.
logEvent
(
CatEventType
.
RELEASE_NAMESPACE
,
String
.
format
(
"%s+%s+%s+%s"
,
appId
,
env
,
clusterName
,
namespaceName
));
return
releaseDTO
;
}
}
public
List
<
ReleaseVO
>
findReleases
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
int
page
,
int
size
){
public
List
<
ReleaseVO
>
findReleases
(
String
appId
,
Env
env
,
String
clusterName
,
String
namespaceName
,
int
page
,
int
size
)
{
List
<
ReleaseDTO
>
releaseDTOs
=
releaseAPI
.
findReleases
(
appId
,
env
,
clusterName
,
namespaceName
,
page
,
size
);
List
<
ReleaseDTO
>
releaseDTOs
=
releaseAPI
.
findReleases
(
appId
,
env
,
clusterName
,
namespaceName
,
page
,
size
);
if
(
CollectionUtils
.
isEmpty
(
releaseDTOs
)){
if
(
CollectionUtils
.
isEmpty
(
releaseDTOs
))
{
return
Collections
.
EMPTY_LIST
;
return
Collections
.
EMPTY_LIST
;
}
}
List
<
ReleaseVO
>
releases
=
new
LinkedList
<>();
List
<
ReleaseVO
>
releases
=
new
LinkedList
<>();
for
(
ReleaseDTO
releaseDTO
:
releaseDTOs
)
{
for
(
ReleaseDTO
releaseDTO
:
releaseDTOs
)
{
ReleaseVO
release
=
new
ReleaseVO
();
ReleaseVO
release
=
new
ReleaseVO
();
release
.
setBaseInfo
(
releaseDTO
);
release
.
setBaseInfo
(
releaseDTO
);
Set
<
ReleaseVO
.
KVEntity
>
kvEntities
=
new
LinkedHashSet
<>();
Set
<
ReleaseVO
.
KVEntity
>
kvEntities
=
new
LinkedHashSet
<>();
Set
<
Map
.
Entry
>
entries
=
gson
.
fromJson
(
releaseDTO
.
getConfigurations
(),
Map
.
class
).
entrySet
();
Set
<
Map
.
Entry
>
entries
=
gson
.
fromJson
(
releaseDTO
.
getConfigurations
(),
Map
.
class
).
entrySet
();
for
(
Map
.
Entry
<
String
,
String
>
entry:
entries
)
{
for
(
Map
.
Entry
<
String
,
String
>
entry
:
entries
)
{
kvEntities
.
add
(
new
ReleaseVO
.
KVEntity
(
entry
.
getKey
(),
entry
.
getValue
()));
kvEntities
.
add
(
new
ReleaseVO
.
KVEntity
(
entry
.
getKey
(),
entry
.
getValue
()));
}
}
release
.
setItems
(
kvEntities
);
release
.
setItems
(
kvEntities
);
...
...
apollo-portal/src/main/resources/static/app.html
浏览文件 @
0447fca3
...
@@ -57,7 +57,7 @@
...
@@ -57,7 +57,7 @@
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<div
class=
"col-sm-offset-2 col-sm-10"
>
<div
class=
"col-sm-offset-2 col-sm-10"
>
<button
type=
"submit"
class=
"btn btn-primary"
>
提交
</button>
<button
type=
"submit"
class=
"btn btn-primary"
ng-disabled=
"submitBtnDisabled"
>
提交
</button>
</div>
</div>
</div>
</div>
</form>
</form>
...
...
apollo-portal/src/main/resources/static/app/role.html
浏览文件 @
0447fca3
...
@@ -40,7 +40,7 @@
...
@@ -40,7 +40,7 @@
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<apollouserselector
apollo-id=
"userSelectWidgetId"
></apollouserselector>
<apollouserselector
apollo-id=
"userSelectWidgetId"
></apollouserselector>
</div>
</div>
<button
type=
"submit"
class=
"btn btn-default"
style=
"margin-left: 20px;"
>
添加
</button>
<button
type=
"submit"
class=
"btn btn-default"
style=
"margin-left: 20px;"
ng-disabled=
"submitBtnDisabled"
>
添加
</button>
</form>
</form>
<!-- Split button -->
<!-- Split button -->
<div
class=
"user-container"
>
<div
class=
"user-container"
>
...
...
apollo-portal/src/main/resources/static/cluster.html
浏览文件 @
0447fca3
...
@@ -70,7 +70,7 @@
...
@@ -70,7 +70,7 @@
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<div
class=
"col-sm-offset-2 col-sm-10"
>
<div
class=
"col-sm-offset-2 col-sm-10"
>
<button
type=
"submit"
class=
"btn btn-primary"
>
提交
</button>
<button
type=
"submit"
class=
"btn btn-primary"
ng-disabled=
"submitBtnDisabled"
>
提交
</button>
</div>
</div>
</div>
</div>
</form>
</form>
...
...
apollo-portal/src/main/resources/static/config.html
浏览文件 @
0447fca3
...
@@ -225,7 +225,7 @@
...
@@ -225,7 +225,7 @@
</div>
</div>
<div
class=
"modal-footer"
>
<div
class=
"modal-footer"
>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
关闭
</button>
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
关闭
</button>
<button
type=
"submit"
class=
"btn btn-primary"
>
发布
<button
type=
"submit"
class=
"btn btn-primary"
ng-disabled=
"releaseBtnDisabled"
>
发布
</button>
</button>
</div>
</div>
</div>
</div>
...
@@ -308,7 +308,7 @@
...
@@ -308,7 +308,7 @@
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
关闭
<button
type=
"button"
class=
"btn btn-default"
data-dismiss=
"modal"
>
关闭
</button>
</button>
<button
type=
"submit"
class=
"btn btn-primary"
<button
type=
"submit"
class=
"btn btn-primary"
ng-show=
"tableViewOperType != 'retrieve'"
>
提交
ng-show=
"tableViewOperType != 'retrieve'"
ng-disabled=
"addItemBtnDisabled && tableViewOperType == 'create'"
>
提交
</button>
</button>
</div>
</div>
</div>
</div>
...
...
apollo-portal/src/main/resources/static/config/sync.html
浏览文件 @
0447fca3
...
@@ -32,7 +32,7 @@
...
@@ -32,7 +32,7 @@
ng-click=
"diff()"
>
下一步
ng-click=
"diff()"
>
下一步
</button>
</button>
<button
type=
"button"
class=
"btn btn-success"
ng-show=
"syncItemStep == 2 && hasDiff"
<button
type=
"button"
class=
"btn btn-success"
ng-show=
"syncItemStep == 2 && hasDiff"
ng-click=
"syncItems()"
>
同步
ng-click=
"syncItems()"
ng-disabled=
"syncBtnDisabled"
>
同步
</button>
</button>
<button
type=
"button"
class=
"btn btn-info"
data-dismiss=
"modal"
<button
type=
"button"
class=
"btn btn-info"
data-dismiss=
"modal"
ng-click=
"backToAppHomePage()"
>
返回到项目首页
ng-click=
"backToAppHomePage()"
>
返回到项目首页
...
...
apollo-portal/src/main/resources/static/namespace.html
浏览文件 @
0447fca3
...
@@ -114,7 +114,7 @@
...
@@ -114,7 +114,7 @@
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<div
class=
"col-sm-offset-3 col-sm-10"
>
<div
class=
"col-sm-offset-3 col-sm-10"
>
<button
type=
"submit"
class=
"btn btn-primary"
>
提交
</button>
<button
type=
"submit"
class=
"btn btn-primary"
ng-disabled=
"submitBtnDisabled"
>
提交
</button>
</div>
</div>
</div>
</div>
</form>
</form>
...
...
apollo-portal/src/main/resources/static/namespace/role.html
浏览文件 @
0447fca3
...
@@ -40,7 +40,7 @@
...
@@ -40,7 +40,7 @@
<div
class=
"form-group"
>
<div
class=
"form-group"
>
<apollouserselector
apollo-id=
"modifyRoleWidgetId"
></apollouserselector>
<apollouserselector
apollo-id=
"modifyRoleWidgetId"
></apollouserselector>
</div>
</div>
<button
type=
"submit"
class=
"btn btn-default"
style=
"margin-left: 20px;"
>
添加
</button>
<button
type=
"submit"
class=
"btn btn-default"
style=
"margin-left: 20px;"
ng-disabled=
"modifyRoleSubmitBtnDisabled"
>
添加
</button>
</form>
</form>
<!-- Split button -->
<!-- Split button -->
<div
class=
"user-container"
>
<div
class=
"user-container"
>
...
@@ -70,7 +70,7 @@
...
@@ -70,7 +70,7 @@
<apollouserselector
apollo-id=
"releaseRoleWidgetId"
></apollouserselector>
<apollouserselector
apollo-id=
"releaseRoleWidgetId"
></apollouserselector>
</div>
</div>
<button
type=
"submit"
class=
"btn btn-default"
style=
"margin-left: 20px;"
>
添加
</button>
<button
type=
"submit"
class=
"btn btn-default"
style=
"margin-left: 20px;"
ng-disabled=
"ReleaseRoleSubmitBtnDisabled"
>
添加
</button>
</form>
</form>
<!-- Split button -->
<!-- Split button -->
<div
class=
"user-container"
>
<div
class=
"user-container"
>
...
...
apollo-portal/src/main/resources/static/scripts/controller/AppController.js
浏览文件 @
0447fca3
create_app_module
.
controller
(
'
CreateAppController
'
,
[
'
$scope
'
,
'
$window
'
,
'
toastr
'
,
'
AppService
'
,
'
UserService
'
,
'
AppUtil
'
,
'
OrganizationService
'
,
create_app_module
.
controller
(
'
CreateAppController
'
,
[
'
$scope
'
,
'
$window
'
,
'
toastr
'
,
'
AppService
'
,
'
UserService
'
,
'
AppUtil
'
,
'
OrganizationService
'
,
function
(
$scope
,
$window
,
toastr
,
AppService
,
UserService
,
AppUtil
,
OrganizationService
)
{
function
(
$scope
,
$window
,
toastr
,
AppService
,
UserService
,
AppUtil
,
OrganizationService
)
{
$scope
.
submitBtnDisabled
=
false
;
OrganizationService
.
find_organizations
().
then
(
function
(
result
)
{
OrganizationService
.
find_organizations
().
then
(
function
(
result
)
{
var
organizations
=
[];
var
organizations
=
[];
result
.
forEach
(
function
(
item
)
{
result
.
forEach
(
function
(
item
)
{
...
@@ -47,12 +49,15 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
...
@@ -47,12 +49,15 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
}
}
$scope
.
app
.
ownerName
=
user
.
id
;
$scope
.
app
.
ownerName
=
user
.
id
;
$scope
.
submitBtnDisabled
=
true
;
AppService
.
create
(
$scope
.
app
).
then
(
function
(
result
)
{
AppService
.
create
(
$scope
.
app
).
then
(
function
(
result
)
{
toastr
.
success
(
'
添加成功!
'
);
toastr
.
success
(
'
添加成功!
'
);
setInterval
(
function
()
{
setInterval
(
function
()
{
$scope
.
submitBtnDisabled
=
false
;
$window
.
location
.
href
=
'
/config.html?#appid=
'
+
result
.
appId
;
$window
.
location
.
href
=
'
/config.html?#appid=
'
+
result
.
appId
;
},
1000
);
},
1000
);
},
function
(
result
)
{
},
function
(
result
)
{
$scope
.
submitBtnDisabled
=
false
;
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
'
添加失败!
'
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
'
添加失败!
'
);
});
});
};
};
...
...
apollo-portal/src/main/resources/static/scripts/controller/ClusterController.js
浏览文件 @
0447fca3
...
@@ -9,6 +9,8 @@ cluster_module.controller('ClusterController',
...
@@ -9,6 +9,8 @@ cluster_module.controller('ClusterController',
$scope
.
step
=
1
;
$scope
.
step
=
1
;
$scope
.
submitBtnDisabled
=
false
;
EnvService
.
find_all_envs
().
then
(
function
(
result
)
{
EnvService
.
find_all_envs
().
then
(
function
(
result
)
{
$scope
.
envs
=
[];
$scope
.
envs
=
[];
result
.
forEach
(
function
(
env
)
{
result
.
forEach
(
function
(
env
)
{
...
@@ -35,6 +37,7 @@ cluster_module.controller('ClusterController',
...
@@ -35,6 +37,7 @@ cluster_module.controller('ClusterController',
$scope
.
envs
.
forEach
(
function
(
env
)
{
$scope
.
envs
.
forEach
(
function
(
env
)
{
if
(
env
.
checked
)
{
if
(
env
.
checked
)
{
noEnvChecked
=
false
;
noEnvChecked
=
false
;
$scope
.
submitBtnDisabled
=
true
;
ClusterService
.
create_cluster
(
$scope
.
appId
,
env
.
name
,
ClusterService
.
create_cluster
(
$scope
.
appId
,
env
.
name
,
{
{
name
:
$scope
.
clusterName
,
name
:
$scope
.
clusterName
,
...
@@ -42,8 +45,10 @@ cluster_module.controller('ClusterController',
...
@@ -42,8 +45,10 @@ cluster_module.controller('ClusterController',
}).
then
(
function
(
result
)
{
}).
then
(
function
(
result
)
{
toastr
.
success
(
env
.
name
,
"
集群创建成功
"
);
toastr
.
success
(
env
.
name
,
"
集群创建成功
"
);
$scope
.
step
=
2
;
$scope
.
step
=
2
;
$scope
.
submitBtnDisabled
=
false
;
},
function
(
result
)
{
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
集群创建失败
"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
集群创建失败
"
);
$scope
.
submitBtnDisabled
=
false
;
})
})
}
}
});
});
...
...
apollo-portal/src/main/resources/static/scripts/controller/NamespaceController.js
浏览文件 @
0447fca3
...
@@ -10,6 +10,8 @@ namespace_module.controller("LinkNamespaceController",
...
@@ -10,6 +10,8 @@ namespace_module.controller("LinkNamespaceController",
$scope
.
step
=
1
;
$scope
.
step
=
1
;
$scope
.
submitBtnDisabled
=
false
;
PermissionService
.
has_root_permission
().
then
(
function
(
result
)
{
PermissionService
.
has_root_permission
().
then
(
function
(
result
)
{
$scope
.
hasRootPermission
=
result
.
hasPermission
;
$scope
.
hasRootPermission
=
result
.
hasPermission
;
});
});
...
@@ -90,23 +92,29 @@ namespace_module.controller("LinkNamespaceController",
...
@@ -90,23 +92,29 @@ namespace_module.controller("LinkNamespaceController",
}
}
});
});
});
});
$scope
.
submitBtnDisabled
=
true
;
NamespaceService
.
createNamespace
(
$scope
.
appId
,
namespaceCreationModels
)
NamespaceService
.
createNamespace
(
$scope
.
appId
,
namespaceCreationModels
)
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
toastr
.
success
(
"
创建成功
"
);
toastr
.
success
(
"
创建成功
"
);
$scope
.
step
=
2
;
$scope
.
step
=
2
;
setInterval
(
function
()
{
setInterval
(
function
()
{
$scope
.
submitBtnDisabled
=
false
;
$window
.
location
.
href
=
$window
.
location
.
href
=
'
/namespace/role.html?#appid=
'
+
$scope
.
appId
'
/namespace/role.html?#appid=
'
+
$scope
.
appId
+
"
&namespaceName=
"
+
$scope
.
namespaceName
;
+
"
&namespaceName=
"
+
$scope
.
namespaceName
;
},
1000
);
},
1000
);
},
function
(
result
)
{
},
function
(
result
)
{
$scope
.
submitBtnDisabled
=
false
;
toastr
.
error
(
AppUtil
.
errorMsg
(
result
));
toastr
.
error
(
AppUtil
.
errorMsg
(
result
));
});
});
}
else
{
}
else
{
$scope
.
submitBtnDisabled
=
true
;
NamespaceService
.
createAppNamespace
(
$scope
.
appId
,
$scope
.
appNamespace
).
then
(
NamespaceService
.
createAppNamespace
(
$scope
.
appId
,
$scope
.
appNamespace
).
then
(
function
(
result
)
{
function
(
result
)
{
$scope
.
step
=
2
;
$scope
.
step
=
2
;
setInterval
(
function
()
{
setInterval
(
function
()
{
$scope
.
submitBtnDisabled
=
false
;
if
(
$scope
.
appNamespace
.
isPublic
)
{
if
(
$scope
.
appNamespace
.
isPublic
)
{
$window
.
location
.
reload
();
$window
.
location
.
reload
();
}
else
{
//private的直接link并且跳转到授权页面
}
else
{
//private的直接link并且跳转到授权页面
...
@@ -116,6 +124,7 @@ namespace_module.controller("LinkNamespaceController",
...
@@ -116,6 +124,7 @@ namespace_module.controller("LinkNamespaceController",
}
}
},
1000
);
},
1000
);
},
function
(
result
)
{
},
function
(
result
)
{
$scope
.
submitBtnDisabled
=
false
;
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
创建失败
"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
创建失败
"
);
});
});
}
}
...
...
apollo-portal/src/main/resources/static/scripts/controller/config/ConfigNamespaceController.js
浏览文件 @
0447fca3
...
@@ -38,7 +38,12 @@ application_module.controller("ConfigNamespaceController",
...
@@ -38,7 +38,12 @@ application_module.controller("ConfigNamespaceController",
$scope
.
createItem
=
createItem
;
$scope
.
createItem
=
createItem
;
$scope
.
doItem
=
doItem
;
$scope
.
doItem
=
doItem
;
$scope
.
releaseBtnDisabled
=
false
;
$scope
.
addItemBtnDisabled
=
false
;
$scope
.
commitChangeBtnDisabled
=
false
;
PermissionService
.
get_app_role_users
(
$rootScope
.
pageContext
.
appId
)
PermissionService
.
get_app_role_users
(
$rootScope
.
pageContext
.
appId
)
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
...
@@ -91,6 +96,12 @@ application_module.controller("ConfigNamespaceController",
...
@@ -91,6 +96,12 @@ application_module.controller("ConfigNamespaceController",
namespaceId
:
namespace
.
namespace
.
id
,
namespaceId
:
namespace
.
namespace
.
id
,
format
:
namespace
.
format
format
:
namespace
.
format
};
};
//prevent repeat submit
if
(
$scope
.
commitChangeBtnDisabled
){
return
;
}
$scope
.
commitChangeBtnDisabled
=
true
;
ConfigService
.
modify_items
(
$rootScope
.
pageContext
.
appId
,
$rootScope
.
pageContext
.
env
,
ConfigService
.
modify_items
(
$rootScope
.
pageContext
.
appId
,
$rootScope
.
pageContext
.
env
,
$rootScope
.
pageContext
.
clusterName
,
$rootScope
.
pageContext
.
clusterName
,
namespace
.
namespace
.
namespaceName
,
namespace
.
namespace
.
namespaceName
,
...
@@ -99,14 +110,17 @@ application_module.controller("ConfigNamespaceController",
...
@@ -99,14 +110,17 @@ application_module.controller("ConfigNamespaceController",
toastr
.
success
(
"
更新成功, 如需生效请发布
"
);
toastr
.
success
(
"
更新成功, 如需生效请发布
"
);
//refresh all namespace items
//refresh all namespace items
$rootScope
.
refreshNamespaces
();
$rootScope
.
refreshNamespaces
();
$scope
.
commitChangeBtnDisabled
=
false
;
return
true
;
return
true
;
},
function
(
result
)
{
},
function
(
result
)
{
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
更新失败
"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
更新失败
"
);
$scope
.
commitChangeBtnDisabled
=
false
;
return
false
;
return
false
;
}
}
);
);
}
}
var
releaseModal
=
$
(
'
#releaseModal
'
);
var
releaseModal
=
$
(
'
#releaseModal
'
);
$scope
.
toReleaseNamespace
=
{};
$scope
.
toReleaseNamespace
=
{};
function
prepareReleaseNamespace
(
namespace
)
{
function
prepareReleaseNamespace
(
namespace
)
{
...
@@ -125,6 +139,7 @@ application_module.controller("ConfigNamespaceController",
...
@@ -125,6 +139,7 @@ application_module.controller("ConfigNamespaceController",
$scope
.
releaseComment
=
''
;
$scope
.
releaseComment
=
''
;
function
release
()
{
function
release
()
{
$scope
.
releaseBtnDisabled
=
true
;
ReleaseService
.
release
(
$rootScope
.
pageContext
.
appId
,
$rootScope
.
pageContext
.
env
,
ReleaseService
.
release
(
$rootScope
.
pageContext
.
appId
,
$rootScope
.
pageContext
.
env
,
$rootScope
.
pageContext
.
clusterName
,
$rootScope
.
pageContext
.
clusterName
,
$scope
.
toReleaseNamespace
.
namespace
.
namespaceName
,
$scope
.
toReleaseNamespace
.
namespace
.
namespaceName
,
...
@@ -134,9 +149,11 @@ application_module.controller("ConfigNamespaceController",
...
@@ -134,9 +149,11 @@ application_module.controller("ConfigNamespaceController",
releaseModal
.
modal
(
'
hide
'
);
releaseModal
.
modal
(
'
hide
'
);
toastr
.
success
(
"
发布成功
"
);
toastr
.
success
(
"
发布成功
"
);
//refresh all namespace items
//refresh all namespace items
$scope
.
releaseBtnDisabled
=
false
;
$rootScope
.
refreshNamespaces
();
$rootScope
.
refreshNamespaces
();
},
function
(
result
)
{
},
function
(
result
)
{
$scope
.
releaseBtnDisabled
=
false
;
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
发布失败
"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
发布失败
"
);
}
}
...
@@ -240,6 +257,7 @@ application_module.controller("ConfigNamespaceController",
...
@@ -240,6 +257,7 @@ application_module.controller("ConfigNamespaceController",
return
;
return
;
}
}
$scope
.
addItemBtnDisabled
=
true
;
ConfigService
.
create_item
(
$rootScope
.
pageContext
.
appId
,
ConfigService
.
create_item
(
$rootScope
.
pageContext
.
appId
,
cluster
.
env
,
cluster
.
env
,
cluster
.
name
,
cluster
.
name
,
...
@@ -249,8 +267,10 @@ application_module.controller("ConfigNamespaceController",
...
@@ -249,8 +267,10 @@ application_module.controller("ConfigNamespaceController",
toastr
.
success
(
cluster
.
env
+
"
,
"
+
$scope
.
item
.
key
,
toastr
.
success
(
cluster
.
env
+
"
,
"
+
$scope
.
item
.
key
,
"
添加成功
"
);
"
添加成功
"
);
itemModal
.
modal
(
'
hide
'
);
itemModal
.
modal
(
'
hide
'
);
$scope
.
addItemBtnDisabled
=
false
;
$rootScope
.
refreshNamespaces
(
namespace_view_type
.
TABLE
);
$rootScope
.
refreshNamespaces
(
namespace_view_type
.
TABLE
);
},
function
(
result
)
{
},
function
(
result
)
{
$scope
.
addItemBtnDisabled
=
false
;
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
添加失败
"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
添加失败
"
);
});
});
...
...
apollo-portal/src/main/resources/static/scripts/controller/config/SyncConfigController.js
浏览文件 @
0447fca3
...
@@ -11,6 +11,7 @@ sync_item_module.controller("SyncItemController",
...
@@ -11,6 +11,7 @@ sync_item_module.controller("SyncItemController",
};
};
$scope
.
syncBtnDisabled
=
false
;
////// load items //////
////// load items //////
ConfigService
.
find_items
(
$scope
.
pageContext
.
appId
,
$scope
.
pageContext
.
env
,
ConfigService
.
find_items
(
$scope
.
pageContext
.
appId
,
$scope
.
pageContext
.
env
,
...
@@ -51,15 +52,20 @@ sync_item_module.controller("SyncItemController",
...
@@ -51,15 +52,20 @@ sync_item_module.controller("SyncItemController",
toastr
.
error
(
AppUtil
.
errorMsg
(
result
));
toastr
.
error
(
AppUtil
.
errorMsg
(
result
));
});
});
};
};
$scope
.
syncItems
=
function
()
{
$scope
.
syncItems
=
function
()
{
ConfigService
.
sync_items
(
$scope
.
pageContext
.
appId
,
$scope
.
pageContext
.
namespaceName
,
parseSyncSourceData
()).
then
(
function
(
result
)
{
$scope
.
syncBtnDisabled
=
true
;
$scope
.
syncItemStep
+=
1
;
ConfigService
.
sync_items
(
$scope
.
pageContext
.
appId
,
$scope
.
syncSuccess
=
true
;
$scope
.
pageContext
.
namespaceName
,
},
function
(
result
)
{
parseSyncSourceData
()).
then
(
function
(
result
)
{
$scope
.
syncSuccess
=
false
;
$scope
.
syncItemStep
+=
1
;
toastr
.
error
(
AppUtil
.
errorMsg
(
result
));
$scope
.
syncSuccess
=
true
;
});
$scope
.
syncBtnDisabled
=
false
;
},
function
(
result
)
{
$scope
.
syncSuccess
=
false
;
$scope
.
syncBtnDisabled
=
false
;
toastr
.
error
(
AppUtil
.
errorMsg
(
result
));
});
};
};
var
selectedClusters
=
[];
var
selectedClusters
=
[];
...
...
apollo-portal/src/main/resources/static/scripts/controller/role/AppRoleController.js
浏览文件 @
0447fca3
...
@@ -7,6 +7,8 @@ role_module.controller('AppRoleController',
...
@@ -7,6 +7,8 @@ role_module.controller('AppRoleController',
appId
:
params
.
appid
appId
:
params
.
appid
};
};
$scope
.
submitBtnDisabled
=
false
;
$scope
.
userSelectWidgetId
=
'
toAssignMasterRoleUser
'
;
$scope
.
userSelectWidgetId
=
'
toAssignMasterRoleUser
'
;
PermissionService
.
has_assign_user_permission
(
$scope
.
pageContext
.
appId
)
PermissionService
.
has_assign_user_permission
(
$scope
.
pageContext
.
appId
)
...
@@ -31,13 +33,16 @@ role_module.controller('AppRoleController',
...
@@ -31,13 +33,16 @@ role_module.controller('AppRoleController',
return
;
return
;
}
}
var
toAssignMasterRoleUser
=
user
.
id
;
var
toAssignMasterRoleUser
=
user
.
id
;
$scope
.
submitBtnDisabled
=
true
;
PermissionService
.
assign_master_role
(
$scope
.
pageContext
.
appId
,
PermissionService
.
assign_master_role
(
$scope
.
pageContext
.
appId
,
toAssignMasterRoleUser
)
toAssignMasterRoleUser
)
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
$scope
.
submitBtnDisabled
=
false
;
toastr
.
success
(
"
添加成功
"
);
toastr
.
success
(
"
添加成功
"
);
$scope
.
appRoleUsers
.
masterUsers
.
push
({
userId
:
toAssignMasterRoleUser
});
$scope
.
appRoleUsers
.
masterUsers
.
push
({
userId
:
toAssignMasterRoleUser
});
$
(
'
.
'
+
$scope
.
userSelectWidgetId
).
select2
(
"
val
"
,
""
);
$
(
'
.
'
+
$scope
.
userSelectWidgetId
).
select2
(
"
val
"
,
""
);
},
function
(
result
)
{
},
function
(
result
)
{
$scope
.
submitBtnDisabled
=
false
;
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
添加失败
"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
添加失败
"
);
});
});
};
};
...
...
apollo-portal/src/main/resources/static/scripts/controller/role/NamespaceRoleController.js
浏览文件 @
0447fca3
...
@@ -10,6 +10,9 @@ role_module.controller('NamespaceRoleController',
...
@@ -10,6 +10,9 @@ role_module.controller('NamespaceRoleController',
namespaceName
:
params
.
namespaceName
namespaceName
:
params
.
namespaceName
};
};
$scope
.
modifyRoleSubmitBtnDisabled
=
false
;
$scope
.
ReleaseRoleSubmitBtnDisabled
=
false
;
$scope
.
releaseRoleWidgetId
=
'
releaseRoleWidgetId
'
;
$scope
.
releaseRoleWidgetId
=
'
releaseRoleWidgetId
'
;
$scope
.
modifyRoleWidgetId
=
'
modifyRoleWidgetId
'
;
$scope
.
modifyRoleWidgetId
=
'
modifyRoleWidgetId
'
;
...
@@ -35,16 +38,19 @@ role_module.controller('NamespaceRoleController',
...
@@ -35,16 +38,19 @@ role_module.controller('NamespaceRoleController',
toastr
.
warning
(
"
请选择用户
"
);
toastr
.
warning
(
"
请选择用户
"
);
return
;
return
;
}
}
$scope
.
ReleaseRoleSubmitBtnDisabled
=
true
;
var
toAssignReleaseNamespaceRoleUser
=
user
.
id
;
var
toAssignReleaseNamespaceRoleUser
=
user
.
id
;
PermissionService
.
assign_release_namespace_role
(
$scope
.
pageContext
.
appId
,
PermissionService
.
assign_release_namespace_role
(
$scope
.
pageContext
.
appId
,
$scope
.
pageContext
.
namespaceName
,
$scope
.
pageContext
.
namespaceName
,
toAssignReleaseNamespaceRoleUser
)
toAssignReleaseNamespaceRoleUser
)
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
toastr
.
success
(
"
添加成功
"
);
toastr
.
success
(
"
添加成功
"
);
$scope
.
ReleaseRoleSubmitBtnDisabled
=
false
;
$scope
.
rolesAssignedUsers
.
releaseRoleUsers
.
push
(
$scope
.
rolesAssignedUsers
.
releaseRoleUsers
.
push
(
{
userId
:
toAssignReleaseNamespaceRoleUser
});
{
userId
:
toAssignReleaseNamespaceRoleUser
});
$
(
'
.
'
+
$scope
.
releaseRoleWidgetId
).
select2
(
"
val
"
,
""
);
$
(
'
.
'
+
$scope
.
releaseRoleWidgetId
).
select2
(
"
val
"
,
""
);
},
function
(
result
)
{
},
function
(
result
)
{
$scope
.
ReleaseRoleSubmitBtnDisabled
=
false
;
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
添加失败
"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
添加失败
"
);
});
});
}
else
{
}
else
{
...
@@ -53,16 +59,19 @@ role_module.controller('NamespaceRoleController',
...
@@ -53,16 +59,19 @@ role_module.controller('NamespaceRoleController',
toastr
.
warning
(
"
请选择用户
"
);
toastr
.
warning
(
"
请选择用户
"
);
return
;
return
;
}
}
$scope
.
modifyRoleSubmitBtnDisabled
=
true
;
var
toAssignModifyNamespaceRoleUser
=
user
.
id
;
var
toAssignModifyNamespaceRoleUser
=
user
.
id
;
PermissionService
.
assign_modify_namespace_role
(
$scope
.
pageContext
.
appId
,
PermissionService
.
assign_modify_namespace_role
(
$scope
.
pageContext
.
appId
,
$scope
.
pageContext
.
namespaceName
,
$scope
.
pageContext
.
namespaceName
,
toAssignModifyNamespaceRoleUser
)
toAssignModifyNamespaceRoleUser
)
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
toastr
.
success
(
"
添加成功
"
);
toastr
.
success
(
"
添加成功
"
);
$scope
.
modifyRoleSubmitBtnDisabled
=
false
;
$scope
.
rolesAssignedUsers
.
modifyRoleUsers
.
push
(
$scope
.
rolesAssignedUsers
.
modifyRoleUsers
.
push
(
{
userId
:
toAssignModifyNamespaceRoleUser
});
{
userId
:
toAssignModifyNamespaceRoleUser
});
$
(
'
.
'
+
$scope
.
modifyRoleWidgetId
).
select2
(
"
val
"
,
""
);
$
(
'
.
'
+
$scope
.
modifyRoleWidgetId
).
select2
(
"
val
"
,
""
);
},
function
(
result
)
{
},
function
(
result
)
{
$scope
.
modifyRoleSubmitBtnDisabled
=
false
;
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
添加失败
"
);
toastr
.
error
(
AppUtil
.
errorMsg
(
result
),
"
添加失败
"
);
});
});
}
}
...
...
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/AllTests.java
浏览文件 @
0447fca3
...
@@ -17,7 +17,8 @@ import org.junit.runners.Suite.SuiteClasses;
...
@@ -17,7 +17,8 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses
({
@SuiteClasses
({
ConfigServiceTest
.
class
,
PropertyResolverTest
.
class
,
ConfigServiceTest
.
class
,
PropertyResolverTest
.
class
,
NamespaceServiceTest
.
class
,
ServiceExceptionTest
.
class
,
RolePermissionServiceTest
.
class
,
NamespaceServiceTest
.
class
,
ServiceExceptionTest
.
class
,
RolePermissionServiceTest
.
class
,
AppNamespaceServiceTest
.
class
,
RoleInitializationServiceTest
.
class
,
FileTextResolverTest
.
class
AppNamespaceServiceTest
.
class
,
RoleInitializationServiceTest
.
class
,
FileTextResolverTest
.
class
,
RetryableRestTemplateTest
.
class
})
})
public
class
AllTests
{
public
class
AllTests
{
...
...
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/RetryableRestTemplateTest.java
0 → 100644
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal
;
import
com.ctrip.framework.apollo.core.dto.ServiceDTO
;
import
com.ctrip.framework.apollo.core.enums.Env
;
import
com.ctrip.framework.apollo.core.exception.ServiceException
;
import
com.ctrip.framework.apollo.portal.api.AdminServiceAddressLocator
;
import
com.ctrip.framework.apollo.portal.api.RetryableRestTemplate
;
import
org.apache.http.HttpHost
;
import
org.apache.http.conn.ConnectTimeoutException
;
import
org.apache.http.conn.HttpHostConnectException
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.client.ResourceAccessException
;
import
org.springframework.web.client.RestTemplate
;
import
java.net.ConnectException
;
import
java.net.SocketTimeoutException
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
public
class
RetryableRestTemplateTest
extends
AbstractUnitTest
{
@Mock
private
AdminServiceAddressLocator
serviceAddressLocator
;
@Mock
private
RestTemplate
restTemplate
;
@InjectMocks
private
RetryableRestTemplate
retryableRestTemplate
;
private
String
path
=
"app"
;
private
String
serviceOne
=
"http://10.0.0.1"
;
private
String
serviceTwo
=
"http://10.0.0.2"
;
private
String
serviceThree
=
"http://10.0.0.3"
;
private
ResourceAccessException
socketTimeoutException
=
new
ResourceAccessException
(
""
);
private
ResourceAccessException
httpHostConnectException
=
new
ResourceAccessException
(
""
);
private
ResourceAccessException
connectTimeoutException
=
new
ResourceAccessException
(
""
);
private
Object
request
=
new
Object
();
private
ResponseEntity
<
Object
>
entity
=
new
ResponseEntity
<>(
HttpStatus
.
OK
);
@Before
public
void
init
()
{
socketTimeoutException
.
initCause
(
new
SocketTimeoutException
());
httpHostConnectException
.
initCause
(
new
HttpHostConnectException
(
new
HttpHost
(
serviceOne
,
80
),
new
ConnectException
()));
connectTimeoutException
.
initCause
(
new
ConnectTimeoutException
());
}
@Test
(
expected
=
ServiceException
.
class
)
public
void
testNoAdminServer
()
{
when
(
serviceAddressLocator
.
getServiceList
(
any
())).
thenReturn
(
Collections
.
emptyList
());
retryableRestTemplate
.
get
(
Env
.
DEV
,
path
,
Object
.
class
);
}
@Test
(
expected
=
ServiceException
.
class
)
public
void
testAllServerDown
()
{
when
(
serviceAddressLocator
.
getServiceList
(
any
()))
.
thenReturn
(
Arrays
.
asList
(
mockService
(
serviceOne
),
mockService
(
serviceTwo
),
mockService
(
serviceThree
)));
when
(
restTemplate
.
getForObject
(
serviceOne
+
"/"
+
path
,
Object
.
class
)).
thenThrow
(
socketTimeoutException
);
when
(
restTemplate
.
getForObject
(
serviceTwo
+
"/"
+
path
,
Object
.
class
)).
thenThrow
(
httpHostConnectException
);
when
(
restTemplate
.
getForObject
(
serviceThree
+
"/"
+
path
,
Object
.
class
)).
thenThrow
(
connectTimeoutException
);
retryableRestTemplate
.
get
(
Env
.
DEV
,
path
,
Object
.
class
);
verify
(
restTemplate
).
getForObject
(
serviceOne
+
"/"
+
path
,
Object
.
class
);
verify
(
restTemplate
).
getForObject
(
serviceTwo
+
"/"
+
path
,
Object
.
class
);
verify
(
restTemplate
).
getForObject
(
serviceThree
+
"/"
+
path
,
Object
.
class
);
}
@Test
public
void
testOneServerDown
()
{
Object
result
=
new
Object
();
when
(
serviceAddressLocator
.
getServiceList
(
any
()))
.
thenReturn
(
Arrays
.
asList
(
mockService
(
serviceOne
),
mockService
(
serviceTwo
),
mockService
(
serviceThree
)));
when
(
restTemplate
.
getForObject
(
serviceOne
+
"/"
+
path
,
Object
.
class
)).
thenThrow
(
socketTimeoutException
);
when
(
restTemplate
.
getForObject
(
serviceTwo
+
"/"
+
path
,
Object
.
class
)).
thenReturn
(
result
);
when
(
restTemplate
.
getForObject
(
serviceThree
+
"/"
+
path
,
Object
.
class
)).
thenThrow
(
connectTimeoutException
);
Object
o
=
retryableRestTemplate
.
get
(
Env
.
DEV
,
path
,
Object
.
class
);
verify
(
restTemplate
).
getForObject
(
serviceOne
+
"/"
+
path
,
Object
.
class
);
verify
(
restTemplate
).
getForObject
(
serviceTwo
+
"/"
+
path
,
Object
.
class
);
verify
(
restTemplate
,
times
(
0
)).
getForObject
(
serviceThree
+
"/"
+
path
,
Object
.
class
);
Assert
.
assertEquals
(
result
,
o
);
}
@Test
(
expected
=
ResourceAccessException
.
class
)
public
void
testPostSocketTimeoutNotRetry
(){
when
(
serviceAddressLocator
.
getServiceList
(
any
()))
.
thenReturn
(
Arrays
.
asList
(
mockService
(
serviceOne
),
mockService
(
serviceTwo
),
mockService
(
serviceThree
)));
when
(
restTemplate
.
postForEntity
(
serviceOne
+
"/"
+
path
,
request
,
Object
.
class
)).
thenThrow
(
socketTimeoutException
);
when
(
restTemplate
.
postForEntity
(
serviceTwo
+
"/"
+
path
,
request
,
Object
.
class
)).
thenReturn
(
entity
);
retryableRestTemplate
.
post
(
Env
.
DEV
,
path
,
request
,
Object
.
class
);
verify
(
restTemplate
).
postForEntity
(
serviceOne
+
"/"
+
path
,
request
,
Object
.
class
);
verify
(
restTemplate
,
times
(
0
)).
postForEntity
(
serviceTwo
+
"/"
+
path
,
request
,
Object
.
class
);
}
@Test
public
void
testDelete
(){
when
(
serviceAddressLocator
.
getServiceList
(
any
()))
.
thenReturn
(
Arrays
.
asList
(
mockService
(
serviceOne
),
mockService
(
serviceTwo
),
mockService
(
serviceThree
)));
retryableRestTemplate
.
delete
(
Env
.
DEV
,
path
);
verify
(
restTemplate
).
delete
(
serviceOne
+
"/"
+
path
);
}
@Test
public
void
testPut
(){
when
(
serviceAddressLocator
.
getServiceList
(
any
()))
.
thenReturn
(
Arrays
.
asList
(
mockService
(
serviceOne
),
mockService
(
serviceTwo
),
mockService
(
serviceThree
)));
retryableRestTemplate
.
put
(
Env
.
DEV
,
path
,
request
);
verify
(
restTemplate
).
put
(
serviceOne
+
"/"
+
path
,
request
);
}
private
ServiceDTO
mockService
(
String
homeUrl
)
{
ServiceDTO
serviceDTO
=
new
ServiceDTO
();
serviceDTO
.
setHomepageUrl
(
homeUrl
);
return
serviceDTO
;
}
}
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/auth/CtripUserServiceTest.java
→
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/auth/
ctrip/
CtripUserServiceTest.java
浏览文件 @
0447fca3
package
com.ctrip.framework.apollo.portal.auth
;
package
com.ctrip.framework.apollo.portal.auth
.ctrip
;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.ctrip.framework.apollo.portal.AbstractUnitTest
;
import
com.ctrip.framework.apollo.portal.auth.ctrip.CtripUserService
;
import
com.ctrip.framework.apollo.portal.entity.po.UserInfo
;
import
com.ctrip.framework.apollo.portal.entity.po.UserInfo
;
import
com.ctrip.framework.apollo.portal.service.ServerConfigService
;
import
com.ctrip.framework.apollo.portal.service.ServerConfigService
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
import
org.springframework.core.ParameterizedTypeReference
;
import
org.springframework.core.ParameterizedTypeReference
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpMethod
;
...
@@ -32,8 +32,7 @@ import static org.mockito.Mockito.when;
...
@@ -32,8 +32,7 @@ import static org.mockito.Mockito.when;
/**
/**
* @author Jason Song(song_s@ctrip.com)
* @author Jason Song(song_s@ctrip.com)
*/
*/
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
CtripUserServiceTest
extends
AbstractUnitTest
{
public
class
CtripUserServiceTest
{
private
CtripUserService
ctripUserService
;
private
CtripUserService
ctripUserService
;
private
String
someUserServiceUrl
;
private
String
someUserServiceUrl
;
private
String
someUserServiceToken
;
private
String
someUserServiceToken
;
...
@@ -48,6 +47,8 @@ public class CtripUserServiceTest {
...
@@ -48,6 +47,8 @@ public class CtripUserServiceTest {
@Before
@Before
public
void
setUp
()
throws
Exception
{
public
void
setUp
()
throws
Exception
{
when
(
serverConfigService
.
getValue
(
"api.connectTimeout"
,
"3000"
)).
thenReturn
(
"3000"
);
when
(
serverConfigService
.
getValue
(
"api.readTimeout"
,
"3000"
)).
thenReturn
(
"3000"
);
ctripUserService
=
new
CtripUserService
(
serverConfigService
);
ctripUserService
=
new
CtripUserService
(
serverConfigService
);
ReflectionTestUtils
.
setField
(
ctripUserService
,
"restTemplate"
,
restTemplate
);
ReflectionTestUtils
.
setField
(
ctripUserService
,
"restTemplate"
,
restTemplate
);
someResponseType
=
someResponseType
=
...
@@ -58,6 +59,7 @@ public class CtripUserServiceTest {
...
@@ -58,6 +59,7 @@ public class CtripUserServiceTest {
someUserServiceToken
=
"someToken"
;
someUserServiceToken
=
"someToken"
;
when
(
serverConfigService
.
getValue
(
"userService.url"
)).
thenReturn
(
someUserServiceUrl
);
when
(
serverConfigService
.
getValue
(
"userService.url"
)).
thenReturn
(
someUserServiceUrl
);
when
(
serverConfigService
.
getValue
(
"userService.accessToken"
)).
thenReturn
(
someUserServiceToken
);
when
(
serverConfigService
.
getValue
(
"userService.accessToken"
)).
thenReturn
(
someUserServiceToken
);
}
}
@Test
@Test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录