Fixed #1679 - moving JMX specific behavior to jmx.DeploymentManagerMBean

This commit is contained in:
Joakim Erdfelt 2017-07-20 11:22:54 -07:00
parent 41938b2310
commit a2a0360269
2 changed files with 52 additions and 56 deletions

View File

@ -28,7 +28,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Queue; import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.stream.Collectors;
import org.eclipse.jetty.deploy.bindings.StandardDeployer; import org.eclipse.jetty.deploy.bindings.StandardDeployer;
import org.eclipse.jetty.deploy.bindings.StandardStarter; import org.eclipse.jetty.deploy.bindings.StandardStarter;
@ -289,13 +288,13 @@ public class DeploymentManager extends ContainerLifeCycle
public Collection<AppEntry> getAppEntries() public Collection<AppEntry> getAppEntries()
{ {
return _apps; return Collections.unmodifiableCollection(_apps);
} }
@ManagedAttribute("Deployed Apps") @ManagedAttribute("Deployed Apps")
public Collection<App> getApps() public Collection<App> getApps()
{ {
List<App> ret = new ArrayList<App>(); List<App> ret = new ArrayList< >();
for (AppEntry entry : _apps) for (AppEntry entry : _apps)
{ {
ret.add(entry.app); ret.add(entry.app);
@ -594,38 +593,11 @@ public class DeploymentManager extends ContainerLifeCycle
return _lifecycle.getNodes(); return _lifecycle.getNodes();
} }
@SuppressWarnings("unused") public Collection<App> getApps(String nodeName)
@ManagedOperation(value="list nodes that are tracked by DeploymentManager", impact="INFO")
public Collection<String> getNodeNames()
{
return _lifecycle.getNodes().stream().map(Node::getName).collect(Collectors.toList());
}
public Collection<App> getApps(@Name("nodeName") String nodeName)
{ {
return getApps(_lifecycle.getNodeByName(nodeName)); return getApps(_lifecycle.getNodeByName(nodeName));
} }
@SuppressWarnings("unused")
@ManagedOperation(value="list apps that are located at specified App LifeCycle nodes", impact="ACTION")
public Collection<String> getAppNames(@Name("nodeName") String nodeName)
{
Node node = _lifecycle.getNodeByName(nodeName);
if(node == null)
{
throw new IllegalArgumentException("Unable to find node [" + nodeName + "]");
}
List<String> ret = new ArrayList<>();
for (AppEntry entry : _apps)
{
if (entry.lifecyleNode == node)
{
ret.add(String.format("contextPath=%s,originId=%s,appProvider=%s", entry.app.getContextPath(), entry.app.getOriginId(), entry.app.getAppProvider().getClass().getName()));
}
}
return ret;
}
public void scope(XmlConfiguration xmlc, Resource webapp) public void scope(XmlConfiguration xmlc, Resource webapp)
throws IOException throws IOException

View File

@ -21,6 +21,7 @@ package org.eclipse.jetty.deploy.jmx;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppProvider; import org.eclipse.jetty.deploy.AppProvider;
@ -28,7 +29,12 @@ import org.eclipse.jetty.deploy.DeploymentManager;
import org.eclipse.jetty.deploy.graph.Node; import org.eclipse.jetty.deploy.graph.Node;
import org.eclipse.jetty.jmx.ObjectMBean; import org.eclipse.jetty.jmx.ObjectMBean;
import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.ManagedOperation;
import org.eclipse.jetty.util.annotation.Name;
@SuppressWarnings("unused")
@ManagedObject("MBean Wrapper for DeploymentManager")
public class DeploymentManagerMBean extends ObjectMBean public class DeploymentManagerMBean extends ObjectMBean
{ {
private final DeploymentManager _manager; private final DeploymentManager _manager;
@ -39,28 +45,46 @@ public class DeploymentManagerMBean extends ObjectMBean
_manager = (DeploymentManager) managedObject; _manager = (DeploymentManager) managedObject;
} }
public Collection<String> getNodes() @ManagedOperation(value = "list apps being tracked", impact = "INFO")
{
List<String> nodes = new ArrayList<String>();
for (Node node: _manager.getNodes())
nodes.add(node.getName());
return nodes;
}
public Collection<String> getApps() public Collection<String> getApps()
{ {
List<String> apps=new ArrayList<String>(); List<String> ret = new ArrayList<>();
for (App app: _manager.getApps()) for (DeploymentManager.AppEntry entry : _manager.getAppEntries())
apps.add(app.getOriginId()); {
return apps; ret.add(toRef(entry.getApp()));
}
return ret;
} }
public Collection<String> getApps(String nodeName) @ManagedOperation(value = "list nodes that are tracked by DeploymentManager", impact = "INFO")
public Collection<String> getNodes()
{ {
List<String> apps=new ArrayList<String>(); return _manager.getNodes().stream().map(Node::getName).collect(Collectors.toList());
for (App app: _manager.getApps(nodeName)) }
apps.add(app.getOriginId());
return apps; @ManagedOperation(value = "list apps that are located at specified App LifeCycle nodes", impact = "ACTION")
public Collection<String> getApps(@Name("nodeName") String nodeName)
{
Node node = _manager.getLifeCycle().getNodeByName(nodeName);
if (node == null)
{
throw new IllegalArgumentException("Unable to find node [" + nodeName + "]");
}
List<String> ret = new ArrayList<>();
for (DeploymentManager.AppEntry entry : _manager.getAppEntries())
{
if (entry.getLifecyleNode() == node)
{
ret.add(toRef(entry.getApp()));
}
}
return ret;
}
private String toRef(App app)
{
return String.format("originId=%s,contextPath=%s,appProvider=%s", app.getContextPath(), app.getOriginId(), app.getAppProvider().getClass().getName());
} }
public Collection<ContextHandler> getContexts() throws Exception public Collection<ContextHandler> getContexts() throws Exception