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
6e6f814f
Commit
6e6f814f
authored
Mar 25, 2016
by
lepdou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
admin service discovery
parent
7bc734b7
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
42 deletions
+49
-42
ConfigController.java
.../com/ctrip/apollo/portal/controller/ConfigController.java
+3
-2
VersionController.java
...com/ctrip/apollo/portal/controller/VersionController.java
+2
-1
ConfigService.java
...n/java/com/ctrip/apollo/portal/service/ConfigService.java
+8
-15
ServiceLocator.java
.../java/com/ctrip/apollo/portal/service/ServiceLocator.java
+10
-2
VersionService.java
.../java/com/ctrip/apollo/portal/service/VersionService.java
+9
-2
ConfigServiceTest.java
...va/com/ctrip/apollo/portal/service/ConfigServiceTest.java
+17
-20
No files found.
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/ConfigController.java
View file @
6e6f814f
package
com
.
ctrip
.
apollo
.
portal
.
controller
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.portal.constants.PortalConstants
;
import
com.ctrip.apollo.portal.entity.AppConfigVO
;
import
com.ctrip.apollo.portal.exception.NotFoundException
;
...
...
@@ -26,9 +27,9 @@ public class ConfigController {
}
if
(
versionId
==
PortalConstants
.
LASTEST_VERSION_ID
)
{
return
configService
.
loadLatestConfig
(
appId
);
return
configService
.
loadLatestConfig
(
Apollo
.
Env
.
DEV
,
appId
);
}
else
if
(
versionId
>
0
)
{
return
configService
.
loadReleaseConfig
(
appId
,
versionId
);
return
configService
.
loadReleaseConfig
(
Apollo
.
Env
.
DEV
,
appId
,
versionId
);
}
else
{
throw
new
NotFoundException
();
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/controller/VersionController.java
View file @
6e6f814f
package
com
.
ctrip
.
apollo
.
portal
.
controller
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.portal.service.VersionService
;
...
...
@@ -19,6 +20,6 @@ public class VersionController {
@RequestMapping
(
"/{appId}/{env}"
)
public
List
<
VersionDTO
>
versions
(
@PathVariable
long
appId
,
@PathVariable
String
env
)
{
return
versionService
.
findVersionsByApp
(
appId
,
env
);
return
versionService
.
findVersionsByApp
(
Apollo
.
Env
.
DEV
,
appId
);
}
}
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ConfigService.java
View file @
6e6f814f
...
...
@@ -31,23 +31,16 @@ public class ConfigService {
private
ObjectMapper
objectMapper
=
new
ObjectMapper
();
public
String
getAdminServiceUrl
()
{
List
<
ApolloService
>
services
=
serviceLocator
.
getAdminServices
(
Env
.
DEV
);
if
(
services
.
size
()
==
0
)
{
throw
new
RuntimeException
(
"No available admin service"
);
}
return
services
.
get
(
0
).
getHomepageUrl
();
}
public
AppConfigVO
loadReleaseConfig
(
long
appId
,
long
versionId
)
{
public
AppConfigVO
loadReleaseConfig
(
Env
env
,
long
appId
,
long
versionId
)
{
if
(
appId
<=
0
||
versionId
<=
0
)
{
return
null
;
}
long
releaseId
=
getReleaseIdFromVersionId
(
versionId
);
long
releaseId
=
getReleaseIdFromVersionId
(
env
,
versionId
);
String
serviceHost
=
serviceLocator
.
getAdminService
(
env
);
String
serviceHost
=
getAdminServiceUrl
();
ReleaseSnapshotDTO
[]
releaseSnapShots
=
RestUtils
.
exchangeInGET
(
serviceHost
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
);
if
(
releaseSnapShots
==
null
||
releaseSnapShots
.
length
==
0
)
{
...
...
@@ -69,8 +62,8 @@ public class ConfigService {
return
appConfigVO
;
}
private
long
getReleaseIdFromVersionId
(
long
versionId
)
{
String
serviceHost
=
getAdminServiceUrl
(
);
private
long
getReleaseIdFromVersionId
(
Env
env
,
long
versionId
)
{
String
serviceHost
=
serviceLocator
.
getAdminService
(
env
);
VersionDTO
version
=
RestUtils
.
exchangeInGET
(
serviceHost
+
"/version/"
+
versionId
,
VersionDTO
.
class
);
if
(
version
==
null
)
{
...
...
@@ -154,12 +147,12 @@ public class ConfigService {
overrideClusterConfigs
.
add
(
overrideClusterConfig
);
}
public
AppConfigVO
loadLatestConfig
(
long
appId
)
{
public
AppConfigVO
loadLatestConfig
(
Env
env
,
long
appId
)
{
if
(
appId
<=
0
)
{
return
null
;
}
String
serviceHost
=
getAdminServiceUrl
(
);
String
serviceHost
=
serviceLocator
.
getAdminService
(
env
);
ClusterDTO
[]
clusters
=
RestUtils
.
exchangeInGET
(
serviceHost
+
"/cluster/app/"
+
appId
,
ClusterDTO
[].
class
);
if
(
clusters
==
null
||
clusters
.
length
==
0
)
{
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/ServiceLocator.java
View file @
6e6f814f
...
...
@@ -14,9 +14,7 @@ import com.ctrip.apollo.core.MetaDomainConsts;
import
com.ctrip.apollo.core.serivce.ApolloService
;
/**
*
* @author liuym
*
*/
@Service
public
class
ServiceLocator
{
...
...
@@ -31,6 +29,16 @@ public class ServiceLocator {
return
getServices
(
env
,
"admin"
);
}
public
String
getAdminService
(
Env
env
)
{
//本地测试用
// return "http://localhost:8090";
List
<
ApolloService
>
services
=
getAdminServices
(
env
);
if
(
services
.
size
()
==
0
)
{
throw
new
RuntimeException
(
"No available admin service"
);
}
return
services
.
get
(
0
).
getHomepageUrl
();
}
public
List
<
ApolloService
>
getConfigServices
(
Env
env
)
{
return
getServices
(
env
,
"config"
);
}
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/service/VersionService.java
View file @
6e6f814f
package
com
.
ctrip
.
apollo
.
portal
.
service
;
import
com.ctrip.apollo.Apollo
;
import
com.ctrip.apollo.core.dto.VersionDTO
;
import
com.ctrip.apollo.portal.RestUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
...
...
@@ -10,7 +12,12 @@ import java.util.List;
@Service
public
class
VersionService
{
public
List
<
VersionDTO
>
findVersionsByApp
(
long
appId
,
String
env
)
{
return
RestUtils
.
exchangeInGET
(
"http://localhost:8090/version/app/"
+
appId
,
List
.
class
);
@Autowired
private
ServiceLocator
serviceLocator
;
public
List
<
VersionDTO
>
findVersionsByApp
(
Apollo
.
Env
env
,
long
appId
)
{
return
RestUtils
.
exchangeInGET
(
serviceLocator
.
getAdminService
(
env
)
+
"/version/app/"
+
appId
,
List
.
class
);
}
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/service/ConfigServiceTest.java
View file @
6e6f814f
...
...
@@ -57,11 +57,8 @@ public class ConfigServiceTest {
@Before
public
void
setUp
()
{
ReflectionTestUtils
.
setField
(
RestUtils
.
class
,
"restTemplate"
,
restTemplate
);
ApolloService
defaultAdminService
=
new
ApolloService
();
defaultAdminService
.
setHomepageUrl
(
"http://localhost:8090"
);
List
<
ApolloService
>
services
=
new
ArrayList
<>();
services
.
add
(
defaultAdminService
);
Mockito
.
doReturn
(
services
).
when
(
serviceLocator
).
getAdminServices
(
Env
.
DEV
);
String
defaultAdminService
=
"http://localhost:8090"
;
Mockito
.
doReturn
(
defaultAdminService
).
when
(
serviceLocator
).
getAdminService
(
Env
.
DEV
);
}
@Test
...
...
@@ -73,13 +70,13 @@ public class ConfigServiceTest {
VersionDTO
someVersion
=
assembleVersion
(
appId
,
"1.0"
,
releaseId
);
ReleaseSnapshotDTO
[]
someReleaseSnapShots
=
assembleReleaseSnapShots
();
restInvoke
(
configService
.
getAdminServiceUrl
(
)
+
"/configs/release/"
+
releaseId
,
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
someReleaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
configService
.
getAdminServiceUrl
(
)
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
Env
.
DEV
,
appId
,
versionId
);
assertEquals
(
appConfigVO
.
getAppId
(),
appId
);
assertEquals
(
appConfigVO
.
getVersionId
(),
versionId
);
...
...
@@ -99,13 +96,13 @@ public class ConfigServiceTest {
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
restInvoke
(
configService
.
getAdminServiceUrl
(
)
+
"/configs/release/"
+
releaseId
,
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
configService
.
getAdminServiceUrl
(
)
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
Env
.
DEV
,
appId
,
versionId
);
assertEquals
(
appConfigVO
.
getAppId
(),
appId
);
assertEquals
(
appConfigVO
.
getVersionId
(),
versionId
);
...
...
@@ -124,13 +121,13 @@ public class ConfigServiceTest {
releaseSnapShots
[
0
]
=
assembleReleaseSnapShot
(
11111
,
"default-cluster-name"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\", \"5555.bar\":\"demo2\", \"22.bar\":\"demo2\"}"
);
restInvoke
(
configService
.
getAdminServiceUrl
(
)
+
"/configs/release/"
+
releaseId
,
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
configService
.
getAdminServiceUrl
(
)
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
Env
.
DEV
,
appId
,
versionId
);
assertEquals
(
appConfigVO
.
getAppId
(),
appId
);
assertEquals
(
appConfigVO
.
getVersionId
(),
versionId
);
...
...
@@ -151,13 +148,13 @@ public class ConfigServiceTest {
releaseSnapShots
[
1
]
=
assembleReleaseSnapShot
(
11112
,
"cluster1"
,
"{\"6666.foo\":\"demo1\", \"6666.bar\":\"demo2\"}"
);
restInvoke
(
configService
.
getAdminServiceUrl
(
)
+
"/configs/release/"
+
releaseId
,
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/configs/release/"
+
releaseId
,
ReleaseSnapshotDTO
[].
class
,
releaseSnapShots
,
releaseSnapShotResponse
);
restInvoke
(
configService
.
getAdminServiceUrl
(
)
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/version/"
+
versionId
,
VersionDTO
.
class
,
someVersion
,
versionResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
appId
,
versionId
);
AppConfigVO
appConfigVO
=
configService
.
loadReleaseConfig
(
Env
.
DEV
,
appId
,
versionId
);
assertEquals
(
appConfigVO
.
getAppId
(),
appId
);
assertEquals
(
appConfigVO
.
getVersionId
(),
versionId
);
...
...
@@ -172,13 +169,13 @@ public class ConfigServiceTest {
ClusterDTO
[]
someClusters
=
assembleClusters
();
ConfigItemDTO
[]
someConfigItem
=
assembleConfigItems
();
restInvoke
(
configService
.
getAdminServiceUrl
(
)
+
"/cluster/app/"
+
appId
,
ClusterDTO
[].
class
,
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/cluster/app/"
+
appId
,
ClusterDTO
[].
class
,
someClusters
,
clusterResponse
);
restInvoke
(
configService
.
getAdminServiceUrl
(
)
+
"/configs/latest?clusterIds=100,101"
,
restInvoke
(
serviceLocator
.
getAdminService
(
Env
.
DEV
)
+
"/configs/latest?clusterIds=100,101"
,
ConfigItemDTO
[].
class
,
someConfigItem
,
configItemResponse
);
AppConfigVO
appConfigVO
=
configService
.
loadLatestConfig
(
appId
);
AppConfigVO
appConfigVO
=
configService
.
loadLatestConfig
(
Env
.
DEV
,
appId
);
assertEquals
(
appConfigVO
.
getAppId
(),
6666
);
assertEquals
(
appConfigVO
.
getVersionId
(),
PortalConstants
.
LASTEST_VERSION_ID
);
...
...
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