Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
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
spring-cloud-netflix
Commits
46fa2110
Commit
46fa2110
authored
Feb 24, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use default instanceid for sidecar
fixes gh-847
parent
ca81f567
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
8 deletions
+33
-8
pom.xml
spring-cloud-netflix-eureka-client/pom.xml
+2
-0
SidecarConfiguration.java
...framework/cloud/netflix/sidecar/SidecarConfiguration.java
+14
-3
SidecarApplicationTests.java
...mework/cloud/netflix/sidecar/SidecarApplicationTests.java
+16
-5
application.yml
...-cloud-netflix-sidecar/src/test/resources/application.yml
+1
-0
No files found.
spring-cloud-netflix-eureka-client/pom.xml
View file @
46fa2110
...
...
@@ -13,6 +13,8 @@
<name>
Spring Cloud Netflix Eureka Client
</name>
<description>
Spring Cloud Netflix Eureka Client
</description>
<properties>
<!-- Why do I need this now? -->
<maven.javadoc.failOnError>
false
</maven.javadoc.failOnError>
<main.basedir>
${basedir}/..
</main.basedir>
</properties>
<dependencies>
...
...
spring-cloud-netflix-sidecar/src/main/java/org/springframework/cloud/netflix/sidecar/SidecarConfiguration.java
View file @
46fa2110
...
...
@@ -26,10 +26,14 @@ import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean;
import
org.springframework.cloud.util.InetUtils
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.env.ConfigurableEnvironment
;
import
org.springframework.util.StringUtils
;
import
com.netflix.appinfo.HealthCheckHandler
;
import
com.netflix.discovery.EurekaClientConfig
;
import
static
org
.
springframework
.
cloud
.
util
.
IdUtils
.
getDefaultInstanceId
;
/**
* @author Spencer Gibb
*/
...
...
@@ -57,17 +61,24 @@ public class SidecarConfiguration {
@Autowired
private
InetUtils
inetUtils
;
@Value
(
"${server.port:${SERVER_PORT:${PORT:8080}}}"
)
private
int
serverPort
=
8080
;
@Value
(
"${management.port:${MANAGEMENT_PORT:${PORT:8080}}}"
)
private
int
managementPort
=
8080
;
@Value
(
"${eureka.instance.hostname:${EUREKA_INSTANCE_HOSTNAME:}}"
)
String
hostname
;
@Autowired
ConfigurableEnvironment
env
;
@Bean
public
EurekaInstanceConfigBean
eurekaInstanceConfigBean
()
{
EurekaInstanceConfigBean
config
=
new
EurekaInstanceConfigBean
(
inetUtils
);
int
port
=
this
.
sidecarProperties
.
getPort
();
config
.
setNonSecurePort
(
port
);
config
.
setInstanceId
(
getDefaultInstanceId
(
this
.
env
));
if
(
StringUtils
.
hasText
(
this
.
hostname
))
{
config
.
setHostname
(
this
.
hostname
);
}
String
scheme
=
config
.
getSecurePortEnabled
()
?
"https"
:
"http"
;
config
.
setStatusPageUrl
(
scheme
+
"://"
+
config
.
getHostname
()
+
":"
+
this
.
managementPort
+
config
.
getStatusPageUrlPath
());
...
...
spring-cloud-netflix-sidecar/src/test/java/org/springframework/cloud/netflix/sidecar/SidecarApplicationTests.java
View file @
46fa2110
...
...
@@ -18,19 +18,30 @@ package org.springframework.cloud.netflix.sidecar;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.b
oot.test.IntegrationTest
;
import
org.springframework.b
eans.factory.annotation.Autowired
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.test.context.web.WebAppConfiguration
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertThat
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
SidecarApplication
.
class
)
@IntegrationTest
(
"server.port=0"
)
@WebAppConfiguration
@WebIntegrationTest
(
randomPort
=
true
,
value
=
{
"spring.application.name=mytest"
,
"spring.cloud.client.hostname=mhhost"
,
"spring.application.instance_id=1"
,
"eureka.instance.hostname=mhhost"
,
"sidecar.port=7000"
})
public
class
SidecarApplicationTests
{
@Autowired
EurekaInstanceConfigBean
config
;
@Test
public
void
contextLoads
()
{
public
void
testEurekaConfigBean
()
{
assertThat
(
this
.
config
.
getAppname
(),
equalTo
(
"mytest"
));
assertThat
(
this
.
config
.
getHostname
(),
equalTo
(
"mhhost"
));
assertThat
(
this
.
config
.
getInstanceId
(),
equalTo
(
"mhhost:mytest:1"
));
assertThat
(
this
.
config
.
getNonSecurePort
(),
equalTo
(
7000
));
System
.
out
.
println
();
}
}
spring-cloud-netflix-sidecar/src/test/resources/application.yml
View file @
46fa2110
...
...
@@ -11,6 +11,7 @@ sidecar:
eureka
:
instance
:
app-group-name
:
mysidecargroup
hostname
:
mysidecarhost
client
:
serviceUrl
:
defaultZone
:
http://user:password@localhost:8761/eureka/
...
...
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