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
03a00503
Commit
03a00503
authored
Nov 22, 2015
by
Micheal Swiggs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enables hystrix monitoring of multiple services on a single server.
parent
f46e8e8e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
1 deletion
+62
-1
EurekaInstanceDiscovery.java
...mework/cloud/netflix/turbine/EurekaInstanceDiscovery.java
+10
-1
SpringClusterMonitor.java
...framework/cloud/netflix/turbine/SpringClusterMonitor.java
+4
-0
TurbineProperties.java
...ingframework/cloud/netflix/turbine/TurbineProperties.java
+2
-0
EurekaInstanceDiscoveryTest.java
...rk/cloud/netflix/turbine/EurekaInstanceDiscoveryTest.java
+46
-0
No files found.
spring-cloud-netflix-turbine/src/main/java/org/springframework/cloud/netflix/turbine/EurekaInstanceDiscovery.java
View file @
03a00503
...
...
@@ -49,10 +49,12 @@ public class EurekaInstanceDiscovery extends CommonsInstanceDiscovery {
private
static
final
String
EUREKA_DEFAULT_CLUSTER_NAME_EXPRESSION
=
"appName"
;
private
final
EurekaClient
eurekaClient
;
private
final
boolean
combineHostPort
;
public
EurekaInstanceDiscovery
(
TurbineProperties
turbineProperties
,
EurekaClient
eurekaClient
)
{
super
(
turbineProperties
,
EUREKA_DEFAULT_CLUSTER_NAME_EXPRESSION
);
this
.
eurekaClient
=
eurekaClient
;
this
.
combineHostPort
=
turbineProperties
.
isCombineHostPort
();
}
/**
...
...
@@ -98,10 +100,12 @@ public class EurekaInstanceDiscovery extends CommonsInstanceDiscovery {
*/
Instance
marshall
(
InstanceInfo
instanceInfo
)
{
String
hostname
=
instanceInfo
.
getHostName
();
String
port
=
String
.
valueOf
(
instanceInfo
.
getPort
());
String
cluster
=
getClusterName
(
instanceInfo
);
Boolean
status
=
parseInstanceStatus
(
instanceInfo
.
getStatus
());
if
(
hostname
!=
null
&&
cluster
!=
null
&&
status
!=
null
)
{
Instance
instance
=
new
Instance
(
hostname
,
cluster
,
status
);
String
hostPart
=
combineHostPort
?
hostname
+
":"
+
port
:
hostname
;
Instance
instance
=
new
Instance
(
hostPart
,
cluster
,
status
);
// add metadata
Map
<
String
,
String
>
metadata
=
instanceInfo
.
getMetadata
();
...
...
@@ -126,6 +130,11 @@ public class EurekaInstanceDiscovery extends CommonsInstanceDiscovery {
if
(
securePortEnabled
)
{
instance
.
getAttributes
().
put
(
"securePort"
,
String
.
valueOf
(
instanceInfo
.
getSecurePort
()));
}
if
(
combineHostPort
)
{
String
fusedHostPort
=
securePortEnabled
?
hostname
+
":"
+
String
.
valueOf
(
instanceInfo
.
getSecurePort
())
:
hostPart
;
instance
.
getAttributes
().
put
(
"fusedHostPort"
,
fusedHostPort
);
}
return
instance
;
}
else
{
...
...
spring-cloud-netflix-turbine/src/main/java/org/springframework/cloud/netflix/turbine/SpringClusterMonitor.java
View file @
03a00503
...
...
@@ -87,6 +87,10 @@ public class SpringClusterMonitor extends AggregateClusterMonitor {
scheme
=
"http"
;
}
if
(
host
.
getAttributes
().
containsKey
(
"fusedHostPort"
))
{
return
String
.
format
(
"%s://%s/%s"
,
scheme
,
host
.
getAttributes
().
get
(
"fusedHostPort"
),
url
);
}
// determine if to insert port
String
insertPortKey
=
"turbine.instanceInsertPort."
+
host
.
getCluster
();
DynamicStringProperty
insertPortProp
=
DynamicPropertyFactory
.
getInstance
()
...
...
spring-cloud-netflix-turbine/src/main/java/org/springframework/cloud/netflix/turbine/TurbineProperties.java
View file @
03a00503
...
...
@@ -35,6 +35,8 @@ public class TurbineProperties {
private
String
appConfig
;
private
boolean
combineHostPort
=
false
;
public
List
<
String
>
getAppConfigList
()
{
if
(!
StringUtils
.
hasText
(
appConfig
))
{
return
null
;
...
...
spring-cloud-netflix-turbine/src/test/java/org/springframework/cloud/netflix/turbine/EurekaInstanceDiscoveryTest.java
View file @
03a00503
...
...
@@ -43,6 +43,52 @@ public class EurekaInstanceDiscoveryTest {
}
@Test
public
void
testSecureCombineHostPort
()
{
turbineProperties
.
setCombineHostPort
(
true
);
EurekaInstanceDiscovery
discovery
=
new
EurekaInstanceDiscovery
(
turbineProperties
,
eurekaClient
);
String
appName
=
"testAppName"
;
int
port
=
8080
;
int
securePort
=
8443
;
String
hostName
=
"myhost"
;
InstanceInfo
instanceInfo
=
builder
.
setAppName
(
appName
)
.
setHostName
(
hostName
)
.
setPort
(
port
)
.
setSecurePort
(
securePort
)
.
enablePort
(
InstanceInfo
.
PortType
.
SECURE
,
true
)
.
build
();
Instance
instance
=
discovery
.
marshall
(
instanceInfo
);
assertEquals
(
"port is wrong"
,
String
.
valueOf
(
port
),
instance
.
getAttributes
().
get
(
"port"
));
assertEquals
(
"securePort is wrong"
,
String
.
valueOf
(
securePort
),
instance
.
getAttributes
().
get
(
"securePort"
));
String
urlPath
=
SpringClusterMonitor
.
ClusterConfigBasedUrlClosure
.
getUrlPath
(
instance
);
assertEquals
(
"url is wrong"
,
"https://"
+
hostName
+
":"
+
securePort
+
"/hystrix.stream"
,
urlPath
);
}
@Test
public
void
testCombineHostPort
()
{
turbineProperties
.
setCombineHostPort
(
true
);
EurekaInstanceDiscovery
discovery
=
new
EurekaInstanceDiscovery
(
turbineProperties
,
eurekaClient
);
String
appName
=
"testAppName"
;
int
port
=
8080
;
String
hostName
=
"myhost"
;
InstanceInfo
instanceInfo
=
builder
.
setAppName
(
appName
)
.
setHostName
(
hostName
)
.
setPort
(
port
)
.
build
();
Instance
instance
=
discovery
.
marshall
(
instanceInfo
);
assertEquals
(
"hostname is wrong"
,
hostName
+
":"
+
port
,
instance
.
getHostname
());
assertEquals
(
"port is wrong"
,
String
.
valueOf
(
port
),
instance
.
getAttributes
().
get
(
"port"
));
String
urlPath
=
SpringClusterMonitor
.
ClusterConfigBasedUrlClosure
.
getUrlPath
(
instance
);
assertEquals
(
"url is wrong"
,
"http://"
+
hostName
+
":"
+
port
+
"/hystrix.stream"
,
urlPath
);
String
clusterName
=
discovery
.
getClusterName
(
instanceInfo
);
assertEquals
(
"clusterName is wrong"
,
appName
.
toUpperCase
(),
clusterName
);
}
@Test
public
void
testGetClusterName
()
{
EurekaInstanceDiscovery
discovery
=
new
EurekaInstanceDiscovery
(
turbineProperties
,
eurekaClient
);
...
...
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