Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
apollo
Commits
46d6e00e
Commit
46d6e00e
authored
Mar 29, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #56 from lepdou/app_search
portal 的环境信息从后端读取 & 支持切换环境
parents
b271bebe
8f0a300c
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
84 additions
and
35 deletions
+84
-35
ConfigController.java
.../com/ctrip/apollo/portal/controller/ConfigController.java
+11
-4
EnvController.java
...ava/com/ctrip/apollo/portal/controller/EnvController.java
+24
-0
VersionController.java
...com/ctrip/apollo/portal/controller/VersionController.java
+10
-1
ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+10
-6
application.yml
apollo-portal/src/main/resources/application.yml
+1
-1
AppConfigController.js
...rces/static/scripts/controller/app/AppConfigController.js
+8
-4
EnvService.js
.../src/main/resources/static/scripts/services/EnvService.js
+19
-0
config.html
...lo-portal/src/main/resources/static/views/app/config.html
+0
-19
index.html
apollo-portal/src/main/resources/static/views/app/index.html
+1
-0
No files found.
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
View file @
46d6e00e
...
...
@@ -24,14 +24,21 @@ public class ConfigController {
public
AppConfigVO
detail
(
@PathVariable
String
appId
,
@PathVariable
String
env
,
@PathVariable
long
versionId
)
{
if
(
Strings
.
isNullOrEmpty
(
appId
))
{
throw
new
NotFoundException
();
if
(
Strings
.
isNullOrEmpty
(
appId
)
||
Strings
.
isNullOrEmpty
(
env
))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"app id and env can not be empty. app id:%s , env:%s"
,
appId
,
env
));
}
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
View file @
46d6e00e
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
View file @
46d6e00e
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,12 @@ 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
))
{
throw
new
IllegalArgumentException
(
String
.
format
(
"app id and env can not be empty. app id:%s , env:%s"
,
appId
,
env
));
}
return
versionService
.
findVersionsByApp
(
Apollo
.
Env
.
valueOf
(
env
),
appId
);
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
View file @
46d6e00e
...
...
@@ -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
View file @
46d6e00e
...
...
@@ -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
View file @
46d6e00e
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
View file @
46d6e00e
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
View file @
46d6e00e
...
...
@@ -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
View file @
46d6e00e
...
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment