Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
fc369a00
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
fc369a00
编写于
3月 29, 2016
作者:
L
lepdou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
portal support switch env
上级
b271bebe
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
81 addition
and
34 deletion
+81
-34
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
.../com/ctrip/apollo/portal/controller/ConfigController.java
+9
-3
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/EnvController.java
...ava/com/ctrip/apollo/portal/controller/EnvController.java
+24
-0
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/VersionController.java
...com/ctrip/apollo/portal/controller/VersionController.java
+9
-1
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+10
-6
apollo-portal/src/main/resources/application.yml
apollo-portal/src/main/resources/application.yml
+1
-1
apollo-portal/src/main/resources/static/scripts/controller/app/AppConfigController.js
...rces/static/scripts/controller/app/AppConfigController.js
+8
-4
apollo-portal/src/main/resources/static/scripts/services/EnvService.js
.../src/main/resources/static/scripts/services/EnvService.js
+19
-0
apollo-portal/src/main/resources/static/views/app/config.html
...lo-portal/src/main/resources/static/views/app/config.html
+0
-19
apollo-portal/src/main/resources/static/views/app/index.html
apollo-portal/src/main/resources/static/views/app/index.html
+1
-0
未找到文件。
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
浏览文件 @
fc369a00
...
...
@@ -24,14 +24,20 @@ public class ConfigController {
public
AppConfigVO
detail
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
long
versionId
)
{
if
(
Strings
.
isNullOrEmpty
(
appId
))
{
if
(
Strings
.
isNullOrEmpty
(
appId
)
||
Strings
.
isNullOrEmpty
(
env
)
)
{
throw
new
NotFoundException
();
}
Apollo
.
Env
e
=
Apollo
.
Env
.
valueOf
(
env
);
if
(
versionId
==
PortalConstants
.
LASTEST_VERSION_ID
)
{
return
configService
.
loadLatestConfig
(
Apollo
.
Env
.
DEV
,
appId
);
return
configService
.
loadLatestConfig
(
e
,
appId
);
}
else
if
(
versionId
>
0
)
{
return
configService
.
loadReleaseConfig
(
Apollo
.
Env
.
DEV
,
appId
,
versionId
);
return
configService
.
loadReleaseConfig
(
e
,
appId
,
versionId
);
}
else
{
throw
new
NotFoundException
();
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/EnvController.java
0 → 100644
浏览文件 @
fc369a00
package
com.ctrip.apollo.portal.controller
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.portal.PortalSettings
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/envs"
)
public
class
EnvController
{
@Autowired
private
PortalSettings
portalSettings
;
@RequestMapping
(
""
)
public
List
<
Apollo
.
Env
>
envs
(){
return
portalSettings
.
getEnvs
();
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/VersionController.java
浏览文件 @
fc369a00
package
com.ctrip.apollo.portal.controller
;
import
com.google.common.base.Strings
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.portal.service.VersionService
;
...
...
@@ -9,6 +11,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.Collections
;
import
java.util.List
;
@RestController
...
...
@@ -20,6 +23,11 @@ public class VersionController {
@RequestMapping
(
"/{appId}/{env}"
)
public
List
<
VersionDTO
>
versions
(
@PathVariable
String
appId
,
@PathVariable
String
env
)
{
return
versionService
.
findVersionsByApp
(
Apollo
.
Env
.
DEV
,
appId
);
if
(
Strings
.
isNullOrEmpty
(
appId
)
||
Strings
.
isNullOrEmpty
(
env
)){
return
Collections
.
EMPTY_LIST
;
}
return
versionService
.
findVersionsByApp
(
Apollo
.
Env
.
valueOf
(
env
),
appId
);
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
浏览文件 @
fc369a00
...
...
@@ -49,10 +49,11 @@ public class ConfigService {
long
releaseId
=
getReleaseIdFromVersionId
(
env
,
versionId
);
if
(
releaseId
==
-
1
)
{
logger
.
warn
(
"get release id error env:{}, app id:{}, version id:{}"
,
env
,
appId
,
versionId
);
return
null
;
}
ReleaseSnapshotDTO
[]
releaseSnapShots
=
configAPI
.
getConfigByReleaseId
(
Env
.
DEV
,
releaseId
);
ReleaseSnapshotDTO
[]
releaseSnapShots
=
configAPI
.
getConfigByReleaseId
(
env
,
releaseId
);
if
(
releaseSnapShots
==
null
||
releaseSnapShots
.
length
==
0
)
{
return
null
;
}
...
...
@@ -83,7 +84,8 @@ public class ConfigService {
private
void
collectDefaultClusterConfigs
(
String
appId
,
ReleaseSnapshotDTO
snapShot
,
AppConfigVO
appConfigVO
)
{
Map
<
String
,
List
<
ConfigItemDTO
>>
groupedConfigs
=
groupConfigsByApp
(
snapShot
.
getConfigurations
());
Map
<
String
,
List
<
ConfigItemDTO
>>
groupedConfigs
=
groupConfigsByApp
(
appId
,
snapShot
.
getConfigurations
());
List
<
AppConfigVO
.
OverrideAppConfig
>
overrideAppConfigs
=
appConfigVO
.
getOverrideAppConfigs
();
...
...
@@ -107,7 +109,7 @@ public class ConfigService {
/**
* appId -> List<KV>
*/
private
Map
<
String
,
List
<
ConfigItemDTO
>>
groupConfigsByApp
(
String
configJson
)
{
private
Map
<
String
,
List
<
ConfigItemDTO
>>
groupConfigsByApp
(
String
selfAppId
,
String
configJson
)
{
if
(
configJson
==
null
||
""
.
equals
(
configJson
))
{
return
Maps
.
newHashMap
();
}
...
...
@@ -120,8 +122,10 @@ public class ConfigService {
try
{
kvMaps
=
objectMapper
.
readValue
(
configJson
,
Map
.
class
);
}
catch
(
IOException
e
)
{
// todo log
logger
.
error
(
"parse release snapshot json error. app id:{}"
,
selfAppId
);
return
Maps
.
newHashMap
();
}
for
(
Map
.
Entry
<
String
,
String
>
entry
:
kvMaps
.
entrySet
())
{
key
=
entry
.
getKey
();
value
=
entry
.
getValue
();
...
...
@@ -151,7 +155,7 @@ public class ConfigService {
new
AppConfigVO
.
OverrideClusterConfig
();
overrideClusterConfig
.
setClusterName
(
snapShot
.
getClusterName
());
// todo step1: cluster special config can't override other app config
overrideClusterConfig
.
setConfigs
(
groupConfigsByApp
(
snapShot
.
getConfigurations
()).
get
(
appId
));
overrideClusterConfig
.
setConfigs
(
groupConfigsByApp
(
appId
,
snapShot
.
getConfigurations
()).
get
(
appId
));
overrideClusterConfigs
.
add
(
overrideClusterConfig
);
}
...
...
@@ -242,7 +246,7 @@ public class ConfigService {
for
(
ConfigItemDTO
config
:
clusterConfigs
)
{
String
targetAppId
=
config
.
getAppId
();
if
(
appId
==
targetAppId
)
{
// app self's configs
if
(
appId
.
equals
(
targetAppId
)
)
{
// app self's configs
defaultClusterConfigs
.
add
(
config
);
}
else
{
// override other app configs
if
(
appIdMapOverrideAppConfig
==
null
)
{
...
...
apollo-portal/src/main/resources/application.yml
浏览文件 @
fc369a00
...
...
@@ -20,4 +20,4 @@ ctrip:
apollo
:
portal
:
env
:
dev,fws,uat
env
:
local,
dev,fws,uat
apollo-portal/src/main/resources/static/scripts/controller/app/AppConfigController.js
浏览文件 @
fc369a00
application_module
.
controller
(
"
AppConfigController
"
,
[
'
$scope
'
,
'
$rootScope
'
,
'
$state
'
,
'
$location
'
,
'
toastr
'
,
'
AppService
'
,
'
ConfigService
'
,
'
VersionService
'
,
function
(
$scope
,
$rootScope
,
$state
,
$location
,
toastr
,
AppService
,
ConfigService
,
VersionService
)
{
'
AppService
'
,
'
EnvService
'
,
'
ConfigService
'
,
'
VersionService
'
,
function
(
$scope
,
$rootScope
,
$state
,
$location
,
toastr
,
AppService
,
EnvService
,
ConfigService
,
VersionService
)
{
var
configLocation
=
{
appId
:
$rootScope
.
appId
,
env
:
'
uat
'
,
env
:
'
LOCAL
'
,
versionId
:
-
1
};
...
...
@@ -15,7 +15,11 @@ application_module.controller("AppConfigController",
$scope
.
configLocation
=
configLocation
;
/**env*/
$scope
.
envs
=
[
'
dev
'
,
'
fws
'
,
'
fat
'
,
'
uat
'
,
'
lpt
'
,
'
prod
'
,
'
tools
'
];
EnvService
.
getAllEnvs
().
then
(
function
(
result
){
$scope
.
envs
=
result
;
},
function
(
result
){
toastr
.
error
(
"
加载环境信息失败
"
,
result
);
});
$scope
.
switchEnv
=
function
(
selectedEnv
)
{
configLocation
.
env
=
selectedEnv
;
...
...
apollo-portal/src/main/resources/static/scripts/services/EnvService.js
0 → 100644
浏览文件 @
fc369a00
appService
.
service
(
'
EnvService
'
,
[
'
$resource
'
,
'
$q
'
,
function
(
$resource
,
$q
)
{
var
env_resource
=
$resource
(
'
/envs
'
,
{},
{
all
:
{
method
:
'
GET
'
,
isArray
:
true
}
});
return
{
getAllEnvs
:
function
getAllEnvs
()
{
var
d
=
$q
.
defer
();
env_resource
.
all
({},
function
(
result
)
{
d
.
resolve
(
result
);
},
function
(
result
)
{
d
.
reject
(
result
);
});
return
d
.
promise
;
}
}
}]);
apollo-portal/src/main/resources/static/views/app/config.html
浏览文件 @
fc369a00
...
...
@@ -107,25 +107,6 @@
</tr>
</tbody>
</table>
<nav
class=
"text-right"
>
<ul
class=
"pagination"
>
<li>
<a
aria-label=
"Previous"
>
<span
aria-hidden=
"true"
>
«
</span>
</a>
</li>
<li><a
>
1
</a></li>
<li><a
>
2
</a></li>
<li><a
>
3
</a></li>
<li><a
>
4
</a></li>
<li><a
>
5
</a></li>
<li>
<a
aria-label=
"Next"
>
<span
aria-hidden=
"true"
>
»
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
...
...
apollo-portal/src/main/resources/static/views/app/index.html
浏览文件 @
fc369a00
...
...
@@ -60,6 +60,7 @@
<!--biz script-->
<script
type=
"application/javascript"
src=
"../../scripts/app.js"
></script>
<script
type=
"application/javascript"
src=
"../../scripts/services/AppService.js"
></script>
<script
type=
"application/javascript"
src=
"../../scripts/services/EnvService.js"
></script>
<script
type=
"application/javascript"
src=
"../../scripts/services/ConfigService.js"
></script>
<script
type=
"application/javascript"
src=
"../../scripts/services/VersionService.js"
></script>
<script
type=
"application/javascript"
src=
"../../scripts/controller/app/AppConfigController.js"
></script>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录