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
ac77c8f8
Commit
ac77c8f8
authored
Mar 18, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Eureka Service Discovery
parent
fcd61233
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
48 additions
and
42 deletions
+48
-42
MetaServerApplication.java
...va/com/ctrip/apollo/metaserver/MetaServerApplication.java
+1
-11
DiscoveryService.java
...com/ctrip/apollo/metaserver/service/DiscoveryService.java
+3
-2
bootstrap.yml
apollo-metaserver/src/main/resources/bootstrap.yml
+1
-4
DiscoveryControllerTest.java
...apollo/metaserver/controller/DiscoveryControllerTest.java
+37
-0
DiscoveryServiceTest.java
...ctrip/apollo/metaserver/service/DiscoveryServiceTest.java
+0
-21
bootstrap.yml
apollo-metaserver/src/test/resources/bootstrap.yml
+5
-3
AppControllerTest.java
...com/ctrip/apollo/portal/controller/AppControllerTest.java
+1
-1
No files found.
apollo-metaserver/src/main/java/com/ctrip/apollo/metaserver/MetaServerApplication.java
View file @
ac77c8f8
package
com
.
ctrip
.
apollo
.
metaserver
;
import
java.util.List
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.cloud.netflix.eureka.EnableEurekaClient
;
import
org.springframework.cloud.netflix.eureka.server.EnableEurekaServer
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
com.ctrip.apollo.metaserver.service.DiscoveryService
;
import
com.netflix.appinfo.InstanceInfo
;
@SpringBootApplication
@EnableEurekaServer
...
...
@@ -17,10 +11,6 @@ import com.netflix.appinfo.InstanceInfo;
public
class
MetaServerApplication
{
public
static
void
main
(
String
[]
args
)
{
ConfigurableApplicationContext
context
=
new
SpringApplicationBuilder
(
MetaServerApplication
.
class
).
web
(
true
).
run
(
args
);
DiscoveryService
discoveryService
=
context
.
getBean
(
DiscoveryService
.
class
);
List
<
InstanceInfo
>
instances
=
discoveryService
.
getMetaServerServiceInstance
();
System
.
out
.
println
(
instances
);
new
SpringApplicationBuilder
(
MetaServerApplication
.
class
).
web
(
true
).
run
(
args
);
}
}
apollo-metaserver/src/main/java/com/ctrip/apollo/metaserver/service/DiscoveryService.java
View file @
ac77c8f8
package
com
.
ctrip
.
apollo
.
metaserver
.
service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -18,12 +19,12 @@ public class DiscoveryService {
public
List
<
InstanceInfo
>
getConfigServerServiceInstance
()
{
Application
application
=
eurekaClient
.
getApplication
(
ServiceIdConsts
.
APOLLO_CONFIGSERVER
);
return
application
.
getInstances
();
return
application
!=
null
?
application
.
getInstances
()
:
new
ArrayList
<>
();
}
public
List
<
InstanceInfo
>
getMetaServerServiceInstance
()
{
Application
application
=
eurekaClient
.
getApplication
(
ServiceIdConsts
.
APOLLO_METASERVER
);
return
application
.
getInstances
();
return
application
!=
null
?
application
.
getInstances
()
:
new
ArrayList
<>
();
}
}
apollo-metaserver/src/main/resources/bootstrap.yml
View file @
ac77c8f8
...
...
@@ -4,10 +4,8 @@ server:
eureka
:
instance
:
hostname
:
localhost
preferIpAddress
:
true
client
:
fetchRegistry
:
false
serviceUrl
:
defaultZone
:
http://${eureka.instance.hostname}:${server.port}/eureka/
healthcheck
:
enabled
:
true
\ No newline at end of file
enabled
:
true
apollo-metaserver/src/test/java/com/ctrip/apollo/metaserver/controller/DiscoveryControllerTest.java
0 → 100644
View file @
ac77c8f8
package
com
.
ctrip
.
apollo
.
metaserver
.
controller
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.test.TestRestTemplate
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.web.client.RestTemplate
;
import
com.ctrip.apollo.core.ServiceIdConsts
;
import
com.ctrip.apollo.metaserver.AbstractMetaServerTest
;
import
com.netflix.appinfo.InstanceInfo
;
@WebIntegrationTest
public
class
DiscoveryControllerTest
extends
AbstractMetaServerTest
{
RestTemplate
restTemplate
=
new
TestRestTemplate
();
@Value
(
"${local.server.port}"
)
String
serverPort
;
@Test
public
void
testGetMetaServerServices
()
throws
InterruptedException
,
URISyntaxException
{
// Wait Eureka Client to fresh meta
Thread
.
sleep
(
5000
);
URI
uri
=
new
URI
(
"http://localhost:"
+
serverPort
+
"/services/meta"
);
InstanceInfo
[]
serviceInstances
=
restTemplate
.
getForObject
(
uri
,
InstanceInfo
[].
class
);
Assert
.
assertEquals
(
1
,
serviceInstances
.
length
);
Assert
.
assertEquals
(
ServiceIdConsts
.
APOLLO_METASERVER
,
serviceInstances
[
0
].
getAppName
().
toLowerCase
());
}
}
apollo-metaserver/src/test/java/com/ctrip/apollo/metaserver/service/DiscoveryServiceTest.java
deleted
100644 → 0
View file @
fcd61233
package
com
.
ctrip
.
apollo
.
metaserver
.
service
;
import
java.util.List
;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
com.ctrip.apollo.metaserver.AbstractMetaServerTest
;
import
com.netflix.appinfo.InstanceInfo
;
public
class
DiscoveryServiceTest
extends
AbstractMetaServerTest
{
@Autowired
private
DiscoveryService
discoveryService
;
@Test
public
void
testGetLocalMetaServerServices
()
{
List
<
InstanceInfo
>
instances
=
discoveryService
.
getMetaServerServiceInstance
();
System
.
out
.
println
(
instances
);
}
}
apollo-metaserver/src/test/resources/bootstrap.yml
View file @
ac77c8f8
...
...
@@ -4,10 +4,11 @@ server:
eureka
:
instance
:
hostname
:
localhost
preferIpAddress
:
true
leaseRenewalIntervalInSeconds
:
1
client
:
fetchRegistry
:
false
# initialInstanceInfoReplicationIntervalSeconds: 1
registryFetchIntervalSeconds
:
2
serviceUrl
:
defaultZone
:
http://${eureka.instance.hostname}:${server.port}/eureka/
defaultZone
:
http://${eureka.instance.hostname}:${server.port
:8761
}/eureka/
healthcheck
:
enabled
:
true
\ No newline at end of file
apollo-portal/src/test/java/com/ctrip/apollo/portal/controller/AppControllerTest.java
View file @
ac77c8f8
...
...
@@ -26,7 +26,7 @@ public class AppControllerTest extends AbstractPortalTest {
@Autowired
AppRepository
appRepository
;
@Value
(
"${server.port}"
)
@Value
(
"${
local.
server.port}"
)
String
serverPort
;
@Test
...
...
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