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
de9af2b4
Commit
de9af2b4
authored
Nov 05, 2014
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added eureka.instance.initial-status to customize the starting status.
fixes gh-53
parent
0f573dfe
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
15 deletions
+42
-15
EurekaClientConfiguration.java
...ework/cloud/netflix/eureka/EurekaClientConfiguration.java
+1
-4
EurekaInstanceConfigBean.java
...mework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
+3
-0
EurekaInstanceConfigBeanTests.java
...k/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java
+38
-11
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/EurekaClientConfiguration.java
View file @
de9af2b4
...
@@ -60,9 +60,6 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
...
@@ -60,9 +60,6 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
private
int
port
=
0
;
private
int
port
=
0
;
@Autowired
@Autowired
private
EurekaClientConfigBean
clientConfig
;
@Autowired
private
EurekaInstanceConfigBean
instanceConfig
;
private
EurekaInstanceConfigBean
instanceConfig
;
@PreDestroy
@PreDestroy
...
@@ -83,7 +80,7 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
...
@@ -83,7 +80,7 @@ public class EurekaClientConfiguration implements SmartLifecycle, Ordered {
discoveryManagerIntitializer
().
init
();
discoveryManagerIntitializer
().
init
();
logger
.
info
(
"Registering application {} with eureka with status UP"
,
logger
.
info
(
"Registering application {} with eureka with status UP"
,
instanceConfig
.
getAppname
());
instanceConfig
.
getAppname
());
ApplicationInfoManager
.
getInstance
().
setInstanceStatus
(
InstanceStatus
.
UP
);
ApplicationInfoManager
.
getInstance
().
setInstanceStatus
(
instanceConfig
.
getInitialStatus
()
);
running
=
true
;
running
=
true
;
}
}
}
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBean.java
View file @
de9af2b4
...
@@ -32,6 +32,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
...
@@ -32,6 +32,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import
com.netflix.appinfo.DataCenterInfo
;
import
com.netflix.appinfo.DataCenterInfo
;
import
com.netflix.appinfo.EurekaInstanceConfig
;
import
com.netflix.appinfo.EurekaInstanceConfig
;
import
com.netflix.appinfo.InstanceInfo.InstanceStatus
;
/**
/**
* @author Dave Syer
* @author Dave Syer
...
@@ -102,6 +103,8 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig {
...
@@ -102,6 +103,8 @@ public class EurekaInstanceConfigBean implements EurekaInstanceConfig {
private
boolean
preferIpAddress
=
false
;
private
boolean
preferIpAddress
=
false
;
private
InstanceStatus
initialStatus
=
InstanceStatus
.
UP
;
public
String
getHostname
()
{
public
String
getHostname
()
{
return
preferIpAddress
?
ipAddress
:
hostname
;
return
preferIpAddress
?
ipAddress
:
hostname
;
}
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/eureka/EurekaInstanceConfigBeanTests.java
View file @
de9af2b4
...
@@ -17,13 +17,16 @@ package org.springframework.cloud.netflix.eureka;
...
@@ -17,13 +17,16 @@ package org.springframework.cloud.netflix.eureka;
import
org.junit.After
;
import
org.junit.After
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.springframework.beans.factory.BeanCreationException
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.boot.test.EnvironmentTestUtils
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
com.netflix.appinfo.InstanceInfo.InstanceStatus
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
springframework
.
boot
.
test
.
EnvironmentTestUtils
.*;
/**
/**
* @author Dave Syer
* @author Dave Syer
...
@@ -42,13 +45,9 @@ public class EurekaInstanceConfigBeanTests {
...
@@ -42,13 +45,9 @@ public class EurekaInstanceConfigBeanTests {
@Test
@Test
public
void
basicBinding
()
{
public
void
basicBinding
()
{
EnvironmentTestUtils
.
addEnvironment
(
context
,
addEnvironment
(
context
,
"eureka.instance.appGroupName=mygroup"
);
"eureka.instance.appGroupName=mygroup"
);
setupContext
();
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
assertEquals
(
"mygroup"
,
getInstanceConfig
().
getAppGroupName
());
TestConfiguration
.
class
);
context
.
refresh
();
assertEquals
(
"mygroup"
,
context
.
getBean
(
EurekaInstanceConfigBean
.
class
)
.
getAppGroupName
());
}
}
@Test
@Test
...
@@ -72,12 +71,40 @@ public class EurekaInstanceConfigBeanTests {
...
@@ -72,12 +71,40 @@ public class EurekaInstanceConfigBeanTests {
}
}
private
void
testNonSecurePort
(
String
propName
)
{
private
void
testNonSecurePort
(
String
propName
)
{
EnvironmentTestUtils
.
addEnvironment
(
context
,
propName
+
":8888"
);
addEnvironment
(
context
,
propName
+
":8888"
);
setupContext
();
assertEquals
(
8888
,
getInstanceConfig
().
getNonSecurePort
());
}
@Test
public
void
testDefaultInitialStatus
()
{
setupContext
();
assertEquals
(
"initialStatus wrong"
,
InstanceStatus
.
UP
,
getInstanceConfig
().
getInitialStatus
());
}
@Test
(
expected
=
BeanCreationException
.
class
)
public
void
testBadInitialStatus
()
{
addEnvironment
(
context
,
"eureka.instance.initial-status:FOO"
);
setupContext
();
}
@Test
public
void
testCustomInitialStatus
()
{
addEnvironment
(
context
,
"eureka.instance.initial-status:STARTING"
);
setupContext
();
assertEquals
(
"initialStatus wrong"
,
InstanceStatus
.
STARTING
,
getInstanceConfig
().
getInitialStatus
());
}
private
void
setupContext
()
{
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
context
.
register
(
PropertyPlaceholderAutoConfiguration
.
class
,
TestConfiguration
.
class
);
TestConfiguration
.
class
);
context
.
refresh
();
context
.
refresh
();
assertEquals
(
8888
,
}
context
.
getBean
(
EurekaInstanceConfigBean
.
class
).
getNonSecurePort
());
protected
EurekaInstanceConfigBean
getInstanceConfig
()
{
return
context
.
getBean
(
EurekaInstanceConfigBean
.
class
);
}
}
/*
/*
...
...
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