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
b10bf9c3
Commit
b10bf9c3
authored
Sep 25, 2015
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use eureka securePort if enabled for turbine http aggregation.
fixes gh-417
parent
7cf0fa48
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
16 deletions
+93
-16
EurekaInstanceDiscovery.java
...mework/cloud/netflix/turbine/EurekaInstanceDiscovery.java
+11
-1
SpringClusterMonitor.java
...framework/cloud/netflix/turbine/SpringClusterMonitor.java
+24
-5
EurekaInstanceDiscoveryTest.java
...rk/cloud/netflix/turbine/EurekaInstanceDiscoveryTest.java
+58
-10
No files found.
spring-cloud-netflix-turbine/src/main/java/org/springframework/cloud/netflix/turbine/EurekaInstanceDiscovery.java
View file @
b10bf9c3
...
...
@@ -146,20 +146,30 @@ public class EurekaInstanceDiscovery implements InstanceDiscovery {
Boolean
status
=
parseInstanceStatus
(
instanceInfo
.
getStatus
());
if
(
hostname
!=
null
&&
cluster
!=
null
&&
status
!=
null
)
{
Instance
instance
=
new
Instance
(
hostname
,
cluster
,
status
);
// add metadata
Map
<
String
,
String
>
metadata
=
instanceInfo
.
getMetadata
();
if
(
metadata
!=
null
)
{
instance
.
getAttributes
().
putAll
(
metadata
);
}
// add amazon metadata
String
asgName
=
instanceInfo
.
getASGName
();
if
(
asgName
!=
null
)
{
instance
.
getAttributes
().
put
(
"asg"
,
asgName
);
}
instance
.
getAttributes
().
put
(
"port"
,
String
.
valueOf
(
instanceInfo
.
getPort
()));
DataCenterInfo
dcInfo
=
instanceInfo
.
getDataCenterInfo
();
if
(
dcInfo
!=
null
&&
dcInfo
.
getName
().
equals
(
DataCenterInfo
.
Name
.
Amazon
))
{
AmazonInfo
amznInfo
=
(
AmazonInfo
)
dcInfo
;
instance
.
getAttributes
().
putAll
(
amznInfo
.
getMetadata
());
}
// add ports
instance
.
getAttributes
().
put
(
"port"
,
String
.
valueOf
(
instanceInfo
.
getPort
()));
boolean
securePortEnabled
=
instanceInfo
.
isPortEnabled
(
InstanceInfo
.
PortType
.
SECURE
);
if
(
securePortEnabled
)
{
instance
.
getAttributes
().
put
(
"securePort"
,
String
.
valueOf
(
instanceInfo
.
getSecurePort
()));
}
return
instance
;
}
else
{
...
...
spring-cloud-netflix-turbine/src/main/java/org/springframework/cloud/netflix/turbine/SpringClusterMonitor.java
View file @
b10bf9c3
...
...
@@ -61,6 +61,8 @@ public class SpringClusterMonitor extends AggregateClusterMonitor {
throw
new
RuntimeException
(
"Host must have cluster name in order to use ClusterConfigBasedUrlClosure"
);
}
// find url
String
key
=
"turbine.instanceUrlSuffix."
+
host
.
getCluster
();
DynamicStringProperty
urlClosureConfig
=
DynamicPropertyFactory
.
getInstance
()
.
getStringProperty
(
key
,
null
);
...
...
@@ -73,6 +75,19 @@ public class SpringClusterMonitor extends AggregateClusterMonitor {
+
urlClosureConfig
.
getName
()
+
" or "
+
this
.
defaultUrlClosureConfig
.
getName
()
+
" must be set"
);
}
// find port and scheme
String
port
;
String
scheme
;
if
(
host
.
getAttributes
().
containsKey
(
"securePort"
))
{
port
=
host
.
getAttributes
().
get
(
"securePort"
);
scheme
=
"https"
;
}
else
{
port
=
host
.
getAttributes
().
get
(
"port"
);
scheme
=
"http"
;
}
// determine if to insert port
String
insertPortKey
=
"turbine.instanceInsertPort."
+
host
.
getCluster
();
DynamicStringProperty
insertPortProp
=
DynamicPropertyFactory
.
getInstance
()
.
getStringProperty
(
insertPortKey
,
null
);
...
...
@@ -83,18 +98,22 @@ public class SpringClusterMonitor extends AggregateClusterMonitor {
else
{
insertPort
=
Boolean
.
parseBoolean
(
insertPortProp
.
get
());
}
// format url with port
if
(
insertPort
)
{
if
(
url
.
startsWith
(
"/"
))
{
url
=
url
.
substring
(
1
);
}
if
(
!
host
.
getAttributes
().
containsKey
(
"port"
)
)
{
if
(
port
==
null
)
{
throw
new
RuntimeException
(
"Configured to use port, but port is not in host attributes"
);
"Configured to use port, but port
or securePort
is not in host attributes"
);
}
return
String
.
format
(
"http://%s:%s/%s"
,
host
.
getHostname
(),
host
.
getAttributes
().
get
(
"port"
)
,
url
);
return
String
.
format
(
"%s://%s:%s/%s"
,
scheme
,
host
.
getHostname
(),
port
,
url
);
}
return
"http://"
+
host
.
getHostname
()
+
url
;
//format url without port
return
scheme
+
"://"
+
host
.
getHostname
()
+
url
;
}
};
...
...
spring-cloud-netflix-turbine/src/test/java/org/springframework/cloud/netflix/turbine/EurekaInstanceDiscoveryTest.java
View file @
b10bf9c3
...
...
@@ -19,6 +19,8 @@ package org.springframework.cloud.netflix.turbine;
import
static
org
.
mockito
.
Mockito
.*;
import
com.netflix.discovery.EurekaClient
;
import
com.netflix.turbine.discovery.Instance
;
import
org.junit.Before
;
import
org.junit.Test
;
import
com.netflix.appinfo.InstanceInfo
;
...
...
@@ -30,26 +32,74 @@ import static org.junit.Assert.assertEquals;
*/
public
class
EurekaInstanceDiscoveryTest
{
private
EurekaClient
eurekaClient
;
private
TurbineProperties
turbineProperties
;
private
InstanceInfo
.
Builder
builder
;
@Before
public
void
setUp
()
throws
Exception
{
eurekaClient
=
mock
(
EurekaClient
.
class
);
turbineProperties
=
new
TurbineProperties
();
builder
=
InstanceInfo
.
Builder
.
newBuilder
();
}
@Test
public
void
testGetClusterName
()
{
EurekaClient
eurekaClient
=
mock
(
EurekaClient
.
class
);
String
appName
=
"testAppName"
;
EurekaInstanceDiscovery
discovery
=
new
EurekaInstanceDiscovery
(
new
TurbineProperties
(),
eurekaClient
);
InstanceInfo
instanceInfo
=
InstanceInfo
.
Builder
.
newBuilder
().
setAppName
(
appName
)
turbineProperties
,
eurekaClient
);
String
appName
=
"testAppName"
;
InstanceInfo
instanceInfo
=
builder
.
setAppName
(
appName
)
.
build
();
String
clusterName
=
discovery
.
getClusterName
(
instanceInfo
);
assertEquals
(
"clusterName is wrong"
,
appName
.
toUpperCase
(),
clusterName
);
}
@Test
public
void
testGetPort
()
{
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
.
marshallInstanceInfo
(
instanceInfo
);
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
);
}
@Test
public
void
testGetSecurePort
()
{
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
.
marshallInstanceInfo
(
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
testGetClusterNameCustomExpression
()
{
EurekaClient
eurekaClient
=
mock
(
EurekaClient
.
class
);
TurbineProperties
turbineProperties
=
new
TurbineProperties
();
turbineProperties
.
setClusterNameExpression
(
"aSGName"
);
EurekaInstanceDiscovery
discovery
=
new
EurekaInstanceDiscovery
(
turbineProperties
,
eurekaClient
);
String
asgName
=
"myAsgName"
;
InstanceInfo
instanceInfo
=
InstanceInfo
.
Builder
.
newBuilder
()
InstanceInfo
instanceInfo
=
builder
.
setAppName
(
"testApp"
).
setASGName
(
asgName
).
build
();
String
clusterName
=
discovery
.
getClusterName
(
instanceInfo
);
assertEquals
(
"clusterName is wrong"
,
asgName
,
clusterName
);
...
...
@@ -57,12 +107,10 @@ public class EurekaInstanceDiscoveryTest {
@Test
public
void
testGetClusterNameInstanceMetadataMapExpression
()
{
EurekaClient
eurekaClient
=
mock
(
EurekaClient
.
class
);
TurbineProperties
turbineProperties
=
new
TurbineProperties
();
turbineProperties
.
setClusterNameExpression
(
"metadata['cluster']"
);
EurekaInstanceDiscovery
discovery
=
new
EurekaInstanceDiscovery
(
turbineProperties
,
eurekaClient
);
String
metadataProperty
=
"myCluster"
;
InstanceInfo
instanceInfo
=
InstanceInfo
.
Builder
.
newBuilder
()
InstanceInfo
instanceInfo
=
builder
.
setAppName
(
"testApp"
).
add
(
"cluster"
,
metadataProperty
).
build
();
String
clusterName
=
discovery
.
getClusterName
(
instanceInfo
);
assertEquals
(
"clusterName is wrong"
,
metadataProperty
,
clusterName
);
...
...
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