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
0c7be074
Unverified
Commit
0c7be074
authored
Apr 04, 2018
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes get applications with regions.
Polishes tests.
parent
ab87e735
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
12 deletions
+62
-12
RestTemplateEurekaHttpClient.java
...oud/netflix/eureka/http/RestTemplateEurekaHttpClient.java
+7
-3
EurekaServerMockApplication.java
...loud/netflix/eureka/http/EurekaServerMockApplication.java
+52
-8
RestTemplateEurekaHttpClientTest.java
...netflix/eureka/http/RestTemplateEurekaHttpClientTest.java
+3
-1
No files found.
spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClient.java
View file @
0c7be074
...
...
@@ -56,6 +56,9 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
public
RestTemplateEurekaHttpClient
(
RestTemplate
restTemplate
,
String
serviceUrl
)
{
this
.
restTemplate
=
restTemplate
;
this
.
serviceUrl
=
serviceUrl
;
if
(!
serviceUrl
.
endsWith
(
"/"
))
{
this
.
serviceUrl
=
this
.
serviceUrl
+
"/"
;
}
}
@Override
...
...
@@ -67,7 +70,7 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
headers
.
add
(
HttpHeaders
.
CONTENT_TYPE
,
MediaType
.
APPLICATION_JSON_VALUE
);
ResponseEntity
<
Void
>
response
=
restTemplate
.
exchange
(
urlPath
,
HttpMethod
.
POST
,
new
HttpEntity
<
InstanceInfo
>(
info
,
headers
),
Void
.
class
);
new
HttpEntity
<>(
info
,
headers
),
Void
.
class
);
return
anEurekaHttpResponse
(
response
.
getStatusCodeValue
())
.
headers
(
headersOf
(
response
)).
build
();
...
...
@@ -141,9 +144,10 @@ public class RestTemplateEurekaHttpClient implements EurekaHttpClient {
String
[]
regions
)
{
String
url
=
serviceUrl
+
urlPath
;
if
(
regions
!=
null
&&
regions
.
length
>
0
)
url
Path
=
(
urlPath
.
contains
(
"?"
)
?
"&"
:
"?"
)
+
"regions="
if
(
regions
!=
null
&&
regions
.
length
>
0
)
{
url
=
url
+
(
urlPath
.
contains
(
"?"
)
?
"&"
:
"?"
)
+
"regions="
+
StringUtil
.
join
(
regions
);
}
ResponseEntity
<
EurekaApplications
>
response
=
restTemplate
.
exchange
(
url
,
HttpMethod
.
GET
,
null
,
EurekaApplications
.
class
);
...
...
spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/EurekaServerMockApplication.java
View file @
0c7be074
...
...
@@ -16,6 +16,15 @@
package
org
.
springframework
.
cloud
.
netflix
.
eureka
.
http
;
import
java.util.Collections
;
import
com.netflix.appinfo.DataCenterInfo
;
import
com.netflix.appinfo.InstanceInfo
;
import
com.netflix.appinfo.LeaseInfo
;
import
com.netflix.appinfo.MyDataCenterInfo
;
import
com.netflix.discovery.shared.Application
;
import
com.netflix.discovery.shared.Applications
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -38,10 +47,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import
org.springframework.web.bind.annotation.ResponseStatus
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.netflix.appinfo.InstanceInfo
;
import
com.netflix.discovery.shared.Application
;
import
com.netflix.discovery.shared.Applications
;
import
static
com
.
netflix
.
appinfo
.
InstanceInfo
.
DEFAULT_PORT
;
import
static
com
.
netflix
.
appinfo
.
InstanceInfo
.
DEFAULT_SECURE_PORT
;
import
static
org
.
springframework
.
util
.
Assert
.
isTrue
;
...
...
@@ -55,9 +60,46 @@ import static org.springframework.util.Assert.isTrue;
@RestController
@SpringBootApplication
public
class
EurekaServerMockApplication
{
private
static
final
InstanceInfo
INFO
=
new
InstanceInfo
(
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
0
,
null
,
null
,
null
,
null
,
null
,
null
,
null
,
0
l
,
0
l
,
null
,
null
);
private
static
final
InstanceInfo
INFO
=
InstanceInfo
.
Builder
.
newBuilder
()
.
setInstanceId
(
"app1instance1"
)
.
setAppName
(
"app1"
)
.
setAppNameForDeser
(
"app1fordeser"
)
.
setAppGroupName
(
"app1group"
)
.
setAppGroupNameForDeser
(
"app1group1fordeser"
)
.
setHostName
(
"app1host1"
)
.
setStatus
(
InstanceInfo
.
InstanceStatus
.
UP
)
.
setOverriddenStatus
(
InstanceInfo
.
InstanceStatus
.
DOWN
)
.
setIPAddr
(
"127.0.0.1"
)
.
setSID
(
"app1sid"
)
.
setPort
(
8080
)
.
setSecurePort
(
4443
)
.
enablePort
(
InstanceInfo
.
PortType
.
UNSECURE
,
true
)
.
setHomePageUrl
(
"/"
,
"http://localhost/"
)
.
setHomePageUrlForDeser
(
"http://localhost/"
)
.
setStatusPageUrl
(
"/status"
,
"http://localhost/info"
)
.
setStatusPageUrlForDeser
(
"http://localhost/status"
)
.
setHealthCheckUrls
(
"/ping"
,
"http://localhost/ping"
,
null
)
.
setHealthCheckUrlsForDeser
(
"http://localhost/ping"
,
null
)
.
setVIPAddress
(
"localhost:8080"
)
.
setVIPAddressDeser
(
"localhost:8080"
)
.
setSecureVIPAddress
(
"localhost:4443"
)
.
setSecureVIPAddressDeser
(
"localhost:4443"
)
.
setDataCenterInfo
(
new
MyDataCenterInfo
(
DataCenterInfo
.
Name
.
MyOwn
))
.
setLeaseInfo
(
LeaseInfo
.
Builder
.
newBuilder
()
.
setDurationInSecs
(
30
)
.
setRenewalIntervalInSecs
(
30
)
.
setEvictionTimestamp
(
System
.
currentTimeMillis
()+
30000
)
.
setRenewalTimestamp
(
System
.
currentTimeMillis
()-
1000
)
.
setRegistrationTimestamp
(
System
.
currentTimeMillis
()-
2000
)
.
build
())
.
add
(
"metadatakey1"
,
"metadatavalue1"
)
.
setASGName
(
"asg1"
)
.
setIsCoordinatingDiscoveryServer
(
false
)
.
setLastUpdatedTimestamp
(
System
.
currentTimeMillis
())
.
setLastDirtyTimestamp
(
System
.
currentTimeMillis
())
.
setActionType
(
InstanceInfo
.
ActionType
.
ADDED
)
.
setNamespace
(
"namespace1"
)
.
build
();
/**
* Simulates Eureka Server own's serialization.
...
...
@@ -116,7 +158,9 @@ public class EurekaServerMockApplication {
@GetMapping
(
value
=
{
"/apps"
,
"/apps/delta"
,
"/vips/{address}"
,
"/svips/{address}"
})
public
Applications
getApplications
(
@PathVariable
(
required
=
false
)
String
address
,
@RequestParam
(
required
=
false
)
String
regions
)
{
return
new
Applications
();
Applications
applications
=
new
Applications
();
applications
.
addApplication
(
new
Application
(
"app1"
,
Collections
.
singletonList
(
INFO
)));
return
applications
;
}
@GetMapping
(
value
=
"/apps/{appName}"
)
...
...
spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/http/RestTemplateEurekaHttpClientTest.java
View file @
0c7be074
...
...
@@ -16,6 +16,7 @@
package
org
.
springframework
.
cloud
.
netflix
.
eureka
.
http
;
import
com.netflix.discovery.shared.Applications
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -105,7 +106,8 @@ public class RestTemplateEurekaHttpClientTest {
@Test
public
void
testGetApplications
()
{
Assert
.
assertNotNull
(
eurekaHttpClient
.
getApplications
().
getEntity
());
Applications
entity
=
eurekaHttpClient
.
getApplications
().
getEntity
();
Assert
.
assertNotNull
(
entity
);
Assert
.
assertNotNull
(
eurekaHttpClient
.
getApplications
(
"us"
,
"eu"
).
getEntity
());
}
...
...
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