-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#9317] Separate AgentListController
- Loading branch information
Showing
18 changed files
with
292 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...rc/main/java/com/navercorp/pinpoint/web/authorization/controller/AgentListController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.navercorp.pinpoint.web.authorization.controller; | ||
|
||
import com.navercorp.pinpoint.web.service.AgentInfoService; | ||
import com.navercorp.pinpoint.web.view.tree.StaticTreeView; | ||
import com.navercorp.pinpoint.web.view.tree.TreeView; | ||
import com.navercorp.pinpoint.web.vo.agent.AgentAndStatus; | ||
import com.navercorp.pinpoint.web.vo.agent.AgentInfoFilter; | ||
import com.navercorp.pinpoint.web.vo.agent.AgentInfoFilterChain; | ||
import com.navercorp.pinpoint.web.vo.agent.AgentStatusAndLink; | ||
import com.navercorp.pinpoint.web.vo.agent.DefaultAgentInfoFilter; | ||
import com.navercorp.pinpoint.web.vo.tree.InstancesList; | ||
import com.navercorp.pinpoint.web.vo.tree.AgentsMapByApplication; | ||
import com.navercorp.pinpoint.web.vo.tree.AgentsMapByHost; | ||
import com.navercorp.pinpoint.web.vo.tree.SortByAgentInfo; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author intr3p1d | ||
*/ | ||
@RestController | ||
@RequestMapping(value = "/agents") | ||
public class AgentListController { | ||
private final AgentInfoService agentInfoService; | ||
|
||
public AgentListController(AgentInfoService agentInfoService) { | ||
this.agentInfoService = Objects.requireNonNull(agentInfoService, "agentInfoService"); | ||
} | ||
|
||
@GetMapping(value = "/all") | ||
public TreeView<InstancesList<AgentAndStatus>> getAllAgentsList() { | ||
long timestamp = System.currentTimeMillis(); | ||
return getAllAgentsList(timestamp); | ||
} | ||
|
||
@GetMapping(value = "/all", params = {"from", "to"}) | ||
public TreeView<InstancesList<AgentAndStatus>> getAllAgentsList( | ||
@RequestParam("from") long from, | ||
@RequestParam("to") long to) { | ||
AgentInfoFilter filter = new DefaultAgentInfoFilter(from); | ||
long timestamp = to; | ||
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(filter, timestamp); | ||
return treeView(allAgentsList); | ||
} | ||
|
||
@GetMapping(value = "/all", params = {"timestamp"}) | ||
public TreeView<InstancesList<AgentAndStatus>> getAllAgentsList( | ||
@RequestParam("timestamp") long timestamp) { | ||
AgentsMapByApplication allAgentsList = this.agentInfoService.getAllAgentsList(AgentInfoFilter::accept, timestamp); | ||
return treeView(allAgentsList); | ||
} | ||
|
||
private static TreeView<InstancesList<AgentAndStatus>> treeView(AgentsMapByApplication agentsListsList) { | ||
List<InstancesList<AgentAndStatus>> list = agentsListsList.getAgentsListsList(); | ||
return new StaticTreeView<>(list); | ||
} | ||
|
||
|
||
@GetMapping(value = "/v1", params = {"application", "sortBy"}) | ||
public TreeView<InstancesList<AgentStatusAndLink>> getAgentsList( | ||
@RequestParam("application") String applicationName, | ||
@RequestParam("sortBy") SortByAgentInfo.Rules sortBy) { | ||
long timestamp = System.currentTimeMillis(); | ||
return getAgentsList(applicationName, timestamp, sortBy); | ||
} | ||
|
||
@GetMapping(value = "/v1", params = {"application", "from", "to", "sortBy"}) | ||
public TreeView<InstancesList<AgentStatusAndLink>> getAgentsList( | ||
@RequestParam("application") String applicationName, | ||
@RequestParam("from") long from, | ||
@RequestParam("to") long to, | ||
@RequestParam("sortBy") SortByAgentInfo.Rules sortBy) { | ||
AgentInfoFilter currentRunFilter = new AgentInfoFilterChain( | ||
new DefaultAgentInfoFilter(from) | ||
); | ||
long timestamp = to; | ||
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(currentRunFilter, applicationName, timestamp, sortBy); | ||
return treeView(list); | ||
} | ||
|
||
@GetMapping(value = "/v1", params = {"application", "timestamp", "sortBy"}) | ||
public TreeView<InstancesList<AgentStatusAndLink>> getAgentsList( | ||
@RequestParam("application") String applicationName, | ||
@RequestParam("timestamp") long timestamp, | ||
@RequestParam("sortBy") SortByAgentInfo.Rules sortBy) { | ||
AgentInfoFilter runningAgentFilter = new AgentInfoFilterChain( | ||
AgentInfoFilter::filterRunning | ||
); | ||
AgentsMapByHost list = this.agentInfoService.getAgentsListByApplicationName(runningAgentFilter, applicationName, timestamp, sortBy); | ||
return treeView(list); | ||
} | ||
|
||
private static TreeView<InstancesList<AgentStatusAndLink>> treeView(AgentsMapByHost agentsMapByHost) { | ||
List<InstancesList<AgentStatusAndLink>> list = agentsMapByHost.getAgentsListsList(); | ||
return new StaticTreeView<>(list); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
web/src/main/java/com/navercorp/pinpoint/web/view/tree/StaticTreeView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.navercorp.pinpoint.web.view.tree; | ||
|
||
import com.fasterxml.jackson.annotation.JsonUnwrapped; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class StaticTreeView<C> implements TreeView<C> { | ||
|
||
private final List<C> nodeList; | ||
|
||
public StaticTreeView(List<C> nodeList) { | ||
this.nodeList = Objects.requireNonNull(nodeList, "nodeList"); | ||
} | ||
|
||
@Override | ||
@JsonValue | ||
@JsonUnwrapped | ||
public Iterator<C> nodes() { | ||
return nodeList.stream().iterator(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TreeView{" + | ||
"itemList=" + nodeList + | ||
'}'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
* @author emeroad | ||
*/ | ||
public interface TreeView<C> { | ||
Iterator<TreeNode<C>> nodes(); | ||
Iterator<C> nodes(); | ||
} |
Oops, something went wrong.