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
60407e41
Commit
60407e41
authored
Apr 25, 2018
by
Nastya Smirnova
Committed by
Spencer Gibb
Apr 25, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Turbine] Turbine controller (#2223)
parent
127b2a80
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
126 additions
and
0 deletions
+126
-0
ClusterInformation.java
...ngframework/cloud/netflix/turbine/ClusterInformation.java
+44
-0
TurbineController.java
...ingframework/cloud/netflix/turbine/TurbineController.java
+24
-0
TurbineInformationService.java
...work/cloud/netflix/turbine/TurbineInformationService.java
+58
-0
No files found.
spring-cloud-netflix-turbine/src/main/java/org/springframework/cloud/netflix/turbine/ClusterInformation.java
0 → 100644
View file @
60407e41
package
org
.
springframework
.
cloud
.
netflix
.
turbine
;
import
java.util.Objects
;
public
class
ClusterInformation
{
private
final
String
name
;
private
final
String
link
;
public
ClusterInformation
(
String
name
,
String
link
)
{
this
.
name
=
name
;
this
.
link
=
link
;
}
public
String
getName
()
{
return
name
;
}
public
String
getLink
()
{
return
link
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
ClusterInformation
that
=
(
ClusterInformation
)
o
;
return
Objects
.
equals
(
name
,
that
.
name
)
&&
Objects
.
equals
(
link
,
that
.
link
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
name
,
link
);
}
@Override
public
String
toString
()
{
return
"ClusterInformation{"
+
"name='"
+
name
+
'\''
+
", link='"
+
link
+
'\''
+
'}'
;
}
}
spring-cloud-netflix-turbine/src/main/java/org/springframework/cloud/netflix/turbine/TurbineController.java
0 → 100644
View file @
60407e41
package
org
.
springframework
.
cloud
.
netflix
.
turbine
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Collection
;
@RestController
public
class
TurbineController
{
private
final
TurbineInformationService
turbineInformationService
;
public
TurbineController
(
TurbineInformationService
turbineInformationService
)
{
this
.
turbineInformationService
=
turbineInformationService
;
}
@GetMapping
(
value
=
"/clusters"
,
produces
=
MediaType
.
APPLICATION_JSON_VALUE
)
public
Collection
<
ClusterInformation
>
clusters
(
HttpServletRequest
request
)
{
return
turbineInformationService
.
getClusterInformations
(
request
);
}
}
spring-cloud-netflix-turbine/src/main/java/org/springframework/cloud/netflix/turbine/TurbineInformationService.java
0 → 100644
View file @
60407e41
package
org
.
springframework
.
cloud
.
netflix
.
turbine
;
import
com.netflix.turbine.data.AggDataFromCluster
;
import
com.netflix.turbine.data.DataFromSingleInstance
;
import
com.netflix.turbine.monitor.MonitorConsole
;
import
com.netflix.turbine.monitor.TurbineDataMonitor
;
import
com.netflix.turbine.monitor.cluster.ClusterMonitor
;
import
org.springframework.http.server.ServletServerHttpRequest
;
import
org.springframework.web.util.UriComponents
;
import
org.springframework.web.util.UriComponentsBuilder
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
static
com
.
netflix
.
turbine
.
monitor
.
cluster
.
AggregateClusterMonitor
.
AggregatorClusterMonitorConsole
;
public
class
TurbineInformationService
{
public
Collection
<
ClusterInformation
>
getClusterInformations
(
HttpServletRequest
request
)
{
String
hostName
=
getHostName
(
request
);
return
getClusterInformations
(
hostName
);
}
private
Collection
<
ClusterInformation
>
getClusterInformations
(
String
hostName
)
{
Collection
<
TurbineDataMonitor
<
AggDataFromCluster
>>
monitors
=
AggregatorClusterMonitorConsole
.
getAllMonitors
();
List
<
ClusterInformation
>
clusterInformations
=
new
ArrayList
<>();
for
(
TurbineDataMonitor
<
AggDataFromCluster
>
monitor
:
monitors
)
{
ClusterMonitor
clusterMonitor
=
(
ClusterMonitor
)
monitor
;
MonitorConsole
<
DataFromSingleInstance
>
instanceConsole
=
clusterMonitor
.
getInstanceMonitors
();
for
(
TurbineDataMonitor
<
DataFromSingleInstance
>
single
:
instanceConsole
.
getAllMonitors
())
{
String
cluster
=
single
.
getStatsInstance
().
getCluster
();
ClusterInformation
info
=
new
ClusterInformation
(
cluster
,
getLink
(
hostName
,
cluster
));
clusterInformations
.
add
(
info
);
}
}
return
clusterInformations
;
}
private
String
getLink
(
String
hostName
,
String
cluster
)
{
return
hostName
+
"/turbine.stream?cluster="
+
cluster
;
}
private
String
getHostName
(
HttpServletRequest
request
)
{
UriComponents
components
=
UriComponentsBuilder
.
fromHttpRequest
(
new
ServletServerHttpRequest
(
request
)).
build
();
String
host
=
components
.
getHost
();
int
port
=
components
.
getPort
();
String
scheme
=
components
.
getScheme
();
if
(
port
>
-
1
)
{
return
String
.
format
(
"%s://%s:%d"
,
scheme
,
host
,
port
);
}
return
String
.
format
(
"%s://%s"
,
scheme
,
host
);
}
}
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