Issue #3429 - Adding WebAppProvider.scan() method to JMX

+ Fixing up some bad JMX attributes as well.

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2019-03-08 16:23:10 -06:00
parent 3b7338888b
commit 32c5726f13
11 changed files with 80 additions and 85 deletions

View File

@ -69,7 +69,6 @@ public class App
_context = context; _context = context;
} }
/* ------------------------------------------------------------ */
/** /**
* @return The deployment manager * @return The deployment manager
*/ */
@ -78,7 +77,6 @@ public class App
return _manager; return _manager;
} }
/* ------------------------------------------------------------ */
/** /**
* @return The AppProvider * @return The AppProvider
*/ */
@ -87,7 +85,6 @@ public class App
return _provider; return _provider;
} }
/* ------------------------------------------------------------ */
/** /**
* Get ContextHandler for the App. * Get ContextHandler for the App.
* *
@ -149,7 +146,6 @@ public class App
return this._context.getContextPath(); return this._context.getContextPath();
} }
/** /**
* The origin of this {@link App} as specified by the {@link AppProvider} * The origin of this {@link App} as specified by the {@link AppProvider}
* *

View File

@ -37,7 +37,6 @@ public interface AppProvider extends LifeCycle
*/ */
void setDeploymentManager(DeploymentManager deploymentManager); void setDeploymentManager(DeploymentManager deploymentManager);
/* ------------------------------------------------------------ */
/** Create a ContextHandler for an App /** Create a ContextHandler for an App
* @param app The App * @param app The App
* @return A ContextHandler * @return A ContextHandler

View File

@ -152,7 +152,6 @@ public class DeploymentManager extends ContainerLifeCycle
} }
} }
/* ------------------------------------------------------------ */
/** Set the AppProviders. /** Set the AppProviders.
* The providers passed are added via {@link #addBean(Object)} so that * The providers passed are added via {@link #addBean(Object)} so that
* their lifecycles may be managed as a {@link ContainerLifeCycle}. * their lifecycles may be managed as a {@link ContainerLifeCycle}.
@ -170,7 +169,6 @@ public class DeploymentManager extends ContainerLifeCycle
addBean(provider); addBean(provider);
} }
@ManagedAttribute("Application Providers")
public Collection<AppProvider> getAppProviders() public Collection<AppProvider> getAppProviders()
{ {
return Collections.unmodifiableList(_providers); return Collections.unmodifiableList(_providers);
@ -292,7 +290,6 @@ public class DeploymentManager extends ContainerLifeCycle
return Collections.unmodifiableCollection(_apps); return Collections.unmodifiableCollection(_apps);
} }
@ManagedAttribute("Deployed Apps")
public Collection<App> getApps() public Collection<App> getApps()
{ {
List<App> ret = new ArrayList< >(); List<App> ret = new ArrayList< >();

View File

@ -22,7 +22,6 @@ import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.graph.Node; import org.eclipse.jetty.deploy.graph.Node;
import org.eclipse.jetty.server.DebugListener; import org.eclipse.jetty.server.DebugListener;
/** A Deployment binding that installs a DebugListener in all deployed contexts /** A Deployment binding that installs a DebugListener in all deployed contexts
*/ */
public class DebugListenerBinding extends DebugBinding public class DebugListenerBinding extends DebugBinding

View File

@ -18,8 +18,6 @@
package org.eclipse.jetty.deploy.bindings; package org.eclipse.jetty.deploy.bindings;
import java.io.File;
import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle; import org.eclipse.jetty.deploy.AppLifeCycle;
import org.eclipse.jetty.deploy.graph.Node; import org.eclipse.jetty.deploy.graph.Node;
@ -48,7 +46,6 @@ public class GlobalWebappConfigBinding implements AppLifeCycle.Binding
{ {
private static final Logger LOG = Log.getLogger(GlobalWebappConfigBinding.class); private static final Logger LOG = Log.getLogger(GlobalWebappConfigBinding.class);
private String _jettyXml; private String _jettyXml;
public String getJettyXml() public String getJettyXml()

View File

@ -204,7 +204,6 @@ public class Graph
return path; return path;
} }
private Path breadthFirst(Node from, Node destination, CopyOnWriteArrayList<Path> paths, Set<Edge> seen) private Path breadthFirst(Node from, Node destination, CopyOnWriteArrayList<Path> paths, Set<Edge> seen)
{ {
// Add next unseen segments to paths. // Add next unseen segments to paths.
@ -246,7 +245,6 @@ public class Graph
return null; return null;
} }
public Set<Edge> getEdges() public Set<Edge> getEdges()
{ {
return _edges; return _edges;

View File

@ -24,11 +24,11 @@ import java.util.List;
import java.util.stream.Collectors; 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.DeploymentManager; 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.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.ManagedOperation; import org.eclipse.jetty.util.annotation.ManagedOperation;
import org.eclipse.jetty.util.annotation.Name; import org.eclipse.jetty.util.annotation.Name;
@ -45,7 +45,7 @@ public class DeploymentManagerMBean extends ObjectMBean
_manager = (DeploymentManager) managedObject; _manager = (DeploymentManager) managedObject;
} }
@ManagedOperation(value = "list apps being tracked", impact = "INFO") @ManagedAttribute(value = "list apps being tracked")
public Collection<String> getApps() public Collection<String> getApps()
{ {
List<String> ret = new ArrayList<>(); List<String> ret = new ArrayList<>();
@ -95,9 +95,10 @@ public class DeploymentManagerMBean extends ObjectMBean
return apps; return apps;
} }
public Collection<AppProvider> getAppProviders() @ManagedAttribute("Registered AppProviders")
public List<String> getAppProviders()
{ {
return _manager.getAppProviders(); return _manager.getAppProviders().stream().map(String::valueOf).collect(Collectors.toList());
} }
public void requestAppGoal(String appId, String nodeName) public void requestAppGoal(String appId, String nodeName)

View File

@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
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;
@ -34,6 +35,7 @@ import org.eclipse.jetty.deploy.DeploymentManager;
import org.eclipse.jetty.util.Scanner; import org.eclipse.jetty.util.Scanner;
import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.ManagedOperation;
import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -55,7 +57,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
private int _scanInterval = 10; private int _scanInterval = 10;
private Scanner _scanner; private Scanner _scanner;
/* ------------------------------------------------------------ */
private final Scanner.DiscreteListener _scannerListener = new Scanner.DiscreteListener() private final Scanner.DiscreteListener _scannerListener = new Scanner.DiscreteListener()
{ {
@Override @Override
@ -77,18 +78,15 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
} }
}; };
/* ------------------------------------------------------------ */
protected ScanningAppProvider() protected ScanningAppProvider()
{ {
} }
/* ------------------------------------------------------------ */
protected ScanningAppProvider(FilenameFilter filter) protected ScanningAppProvider(FilenameFilter filter)
{ {
_filenameFilter = filter; _filenameFilter = filter;
} }
/* ------------------------------------------------------------ */
protected void setFilenameFilter(FilenameFilter filter) protected void setFilenameFilter(FilenameFilter filter)
{ {
if (isRunning()) if (isRunning())
@ -96,7 +94,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_filenameFilter = filter; _filenameFilter = filter;
} }
/* ------------------------------------------------------------ */
/** /**
* @return The index of currently deployed applications. * @return The index of currently deployed applications.
*/ */
@ -105,7 +102,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return _appMap; return _appMap;
} }
/* ------------------------------------------------------------ */
/** /**
* Called by the Scanner.DiscreteListener to create a new App object. * Called by the Scanner.DiscreteListener to create a new App object.
* Isolated in a method so that it is possible to override the default App * Isolated in a method so that it is possible to override the default App
@ -121,7 +117,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return new App(_deploymentManager,this,filename); return new App(_deploymentManager,this,filename);
} }
/* ------------------------------------------------------------ */
@Override @Override
protected void doStart() throws Exception protected void doStart() throws Exception
{ {
@ -150,7 +145,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_scanner.start(); _scanner.start();
} }
/* ------------------------------------------------------------ */
@Override @Override
protected void doStop() throws Exception protected void doStop() throws Exception
{ {
@ -162,13 +156,11 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
} }
} }
/* ------------------------------------------------------------ */
protected boolean exists(String path) protected boolean exists(String path)
{ {
return _scanner.exists(path); return _scanner.exists(path);
} }
/* ------------------------------------------------------------ */
protected void fileAdded(String filename) throws Exception protected void fileAdded(String filename) throws Exception
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
@ -181,7 +173,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
} }
} }
/* ------------------------------------------------------------ */
protected void fileChanged(String filename) throws Exception protected void fileChanged(String filename) throws Exception
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
@ -199,7 +190,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
} }
} }
/* ------------------------------------------------------------ */
protected void fileRemoved(String filename) throws Exception protected void fileRemoved(String filename) throws Exception
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
@ -209,7 +199,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_deploymentManager.removeApp(app); _deploymentManager.removeApp(app);
} }
/* ------------------------------------------------------------ */
/** /**
* Get the deploymentManager. * Get the deploymentManager.
* *
@ -220,8 +209,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return _deploymentManager; return _deploymentManager;
} }
/* ------------------------------------------------------------ */
public Resource getMonitoredDirResource() public Resource getMonitoredDirResource()
{ {
if (_monitored.size()==0) if (_monitored.size()==0)
@ -231,60 +218,51 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return _monitored.get(0); return _monitored.get(0);
} }
/* ------------------------------------------------------------ */
public String getMonitoredDirName() public String getMonitoredDirName()
{ {
Resource resource=getMonitoredDirResource(); Resource resource=getMonitoredDirResource();
return resource==null?null:resource.toString(); return resource==null?null:resource.toString();
} }
/* ------------------------------------------------------------ */
@ManagedAttribute("scanning interval to detect changes which need reloaded") @ManagedAttribute("scanning interval to detect changes which need reloaded")
public int getScanInterval() public int getScanInterval()
{ {
return _scanInterval; return _scanInterval;
} }
/* ------------------------------------------------------------ */
@ManagedAttribute("recursive scanning supported") @ManagedAttribute("recursive scanning supported")
public boolean isRecursive() public boolean isRecursive()
{ {
return _recursive; return _recursive;
} }
/* ------------------------------------------------------------ */
@Override @Override
public void setDeploymentManager(DeploymentManager deploymentManager) public void setDeploymentManager(DeploymentManager deploymentManager)
{ {
_deploymentManager = deploymentManager; _deploymentManager = deploymentManager;
} }
/* ------------------------------------------------------------ */
public void setMonitoredResources(List<Resource> resources) public void setMonitoredResources(List<Resource> resources)
{ {
_monitored.clear(); _monitored.clear();
_monitored.addAll(resources); _monitored.addAll(resources);
} }
/* ------------------------------------------------------------ */
public List<Resource> getMonitoredResources() public List<Resource> getMonitoredResources()
{ {
return Collections.unmodifiableList(_monitored); return Collections.unmodifiableList(_monitored);
} }
/* ------------------------------------------------------------ */
public void setMonitoredDirResource(Resource resource) public void setMonitoredDirResource(Resource resource)
{ {
setMonitoredResources(Collections.singletonList(resource)); setMonitoredResources(Collections.singletonList(resource));
} }
/* ------------------------------------------------------------ */
public void addScannerListener(Scanner.Listener listener) public void addScannerListener(Scanner.Listener listener)
{ {
_scanner.addListener(listener); _scanner.addListener(listener);
} }
/* ------------------------------------------------------------ */
/** /**
* @param dir * @param dir
* Directory to scan for context descriptors or war files * Directory to scan for context descriptors or war files
@ -294,7 +272,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
setMonitoredDirectories(Collections.singletonList(dir)); setMonitoredDirectories(Collections.singletonList(dir));
} }
/* ------------------------------------------------------------ */
public void setMonitoredDirectories(Collection<String> directories) public void setMonitoredDirectories(Collection<String> directories)
{ {
try try
@ -310,15 +287,23 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
} }
} }
/* ------------------------------------------------------------ */
protected void setRecursive(boolean recursive) protected void setRecursive(boolean recursive)
{ {
_recursive = recursive; _recursive = recursive;
} }
/* ------------------------------------------------------------ */
public void setScanInterval(int scanInterval) public void setScanInterval(int scanInterval)
{ {
_scanInterval = scanInterval; _scanInterval = scanInterval;
} }
@ManagedOperation(value = "Scan the monitored directories", impact = "ACTION")
public void scan()
{
LOG.info("Performing scan of monitored directories: {}",
getMonitoredResources().stream().map((r) -> r.getURI().toASCIIString())
.collect(Collectors.joining(", ", "[", "]"))
);
_scanner.scan();
}
} }

View File

@ -124,7 +124,6 @@ public class WebAppProvider extends ScanningAppProvider
} }
} }
/* ------------------------------------------------------------ */
public WebAppProvider() public WebAppProvider()
{ {
super(); super();
@ -132,7 +131,6 @@ public class WebAppProvider extends ScanningAppProvider
setScanInterval(0); setScanInterval(0);
} }
/* ------------------------------------------------------------ */
/** Get the extractWars. /** Get the extractWars.
* @return the extractWars * @return the extractWars
*/ */
@ -142,7 +140,6 @@ public class WebAppProvider extends ScanningAppProvider
return _extractWars; return _extractWars;
} }
/* ------------------------------------------------------------ */
/** Set the extractWars. /** Set the extractWars.
* @param extractWars the extractWars to set * @param extractWars the extractWars to set
*/ */
@ -151,7 +148,6 @@ public class WebAppProvider extends ScanningAppProvider
_extractWars = extractWars; _extractWars = extractWars;
} }
/* ------------------------------------------------------------ */
/** Get the parentLoaderPriority. /** Get the parentLoaderPriority.
* @return the parentLoaderPriority * @return the parentLoaderPriority
*/ */
@ -161,7 +157,6 @@ public class WebAppProvider extends ScanningAppProvider
return _parentLoaderPriority; return _parentLoaderPriority;
} }
/* ------------------------------------------------------------ */
/** Set the parentLoaderPriority. /** Set the parentLoaderPriority.
* @param parentLoaderPriority the parentLoaderPriority to set * @param parentLoaderPriority the parentLoaderPriority to set
*/ */
@ -170,7 +165,6 @@ public class WebAppProvider extends ScanningAppProvider
_parentLoaderPriority = parentLoaderPriority; _parentLoaderPriority = parentLoaderPriority;
} }
/* ------------------------------------------------------------ */
/** Get the defaultsDescriptor. /** Get the defaultsDescriptor.
* @return the defaultsDescriptor * @return the defaultsDescriptor
*/ */
@ -180,7 +174,6 @@ public class WebAppProvider extends ScanningAppProvider
return _defaultsDescriptor; return _defaultsDescriptor;
} }
/* ------------------------------------------------------------ */
/** Set the defaultsDescriptor. /** Set the defaultsDescriptor.
* @param defaultsDescriptor the defaultsDescriptor to set * @param defaultsDescriptor the defaultsDescriptor to set
*/ */
@ -189,13 +182,11 @@ public class WebAppProvider extends ScanningAppProvider
_defaultsDescriptor = defaultsDescriptor; _defaultsDescriptor = defaultsDescriptor;
} }
/* ------------------------------------------------------------ */
public ConfigurationManager getConfigurationManager() public ConfigurationManager getConfigurationManager()
{ {
return _configurationManager; return _configurationManager;
} }
/* ------------------------------------------------------------ */
/** Set the configurationManager. /** Set the configurationManager.
* @param configurationManager the configurationManager to set * @param configurationManager the configurationManager to set
*/ */
@ -204,7 +195,6 @@ public class WebAppProvider extends ScanningAppProvider
_configurationManager = configurationManager; _configurationManager = configurationManager;
} }
/* ------------------------------------------------------------ */
/** /**
* @param configurations The configuration class names. * @param configurations The configuration class names.
*/ */
@ -213,7 +203,6 @@ public class WebAppProvider extends ScanningAppProvider
_configurationClasses = configurations==null?null:(String[])configurations.clone(); _configurationClasses = configurations==null?null:(String[])configurations.clone();
} }
/* ------------------------------------------------------------ */
@ManagedAttribute("configuration classes for webapps to be processed through") @ManagedAttribute("configuration classes for webapps to be processed through")
public String[] getConfigurationClasses() public String[] getConfigurationClasses()
{ {
@ -232,7 +221,6 @@ public class WebAppProvider extends ScanningAppProvider
_tempDirectory = directory; _tempDirectory = directory;
} }
/* ------------------------------------------------------------ */
/** /**
* Get the user supplied Work Directory. * Get the user supplied Work Directory.
* *
@ -244,7 +232,6 @@ public class WebAppProvider extends ScanningAppProvider
return _tempDirectory; return _tempDirectory;
} }
/* ------------------------------------------------------------ */
protected void initializeWebAppContextDefaults(WebAppContext webapp) protected void initializeWebAppContextDefaults(WebAppContext webapp)
{ {
if (_defaultsDescriptor != null) if (_defaultsDescriptor != null)
@ -266,7 +253,6 @@ public class WebAppProvider extends ScanningAppProvider
} }
} }
/* ------------------------------------------------------------ */
@Override @Override
public ContextHandler createContextHandler(final App app) throws Exception public ContextHandler createContextHandler(final App app) throws Exception
{ {
@ -350,7 +336,6 @@ public class WebAppProvider extends ScanningAppProvider
return webAppContext; return webAppContext;
} }
/* ------------------------------------------------------------ */
@Override @Override
protected void fileChanged(String filename) throws Exception protected void fileChanged(String filename) throws Exception
{ {
@ -410,7 +395,6 @@ public class WebAppProvider extends ScanningAppProvider
super.fileChanged(filename); super.fileChanged(filename);
} }
/* ------------------------------------------------------------ */
@Override @Override
protected void fileAdded(String filename) throws Exception protected void fileAdded(String filename) throws Exception
{ {
@ -433,7 +417,6 @@ public class WebAppProvider extends ScanningAppProvider
return; return;
} }
//is the file that was added a .war file? //is the file that was added a .war file?
String lowname = file.getName().toLowerCase(Locale.ENGLISH); String lowname = file.getName().toLowerCase(Locale.ENGLISH);
if (lowname.endsWith(".war")) if (lowname.endsWith(".war"))
@ -453,8 +436,6 @@ public class WebAppProvider extends ScanningAppProvider
super.fileAdded(filename); super.fileAdded(filename);
} }
/* ------------------------------------------------------------ */
@Override @Override
protected void fileRemoved(String filename) throws Exception protected void fileRemoved(String filename) throws Exception
{ {

View File

@ -0,0 +1,44 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.deploy.providers.jmx;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jetty.deploy.providers.WebAppProvider;
import org.eclipse.jetty.server.handler.jmx.AbstractHandlerMBean;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
@ManagedObject("WebAppProvider mbean wrapper")
public class WebAppProviderMBean extends AbstractHandlerMBean
{
public WebAppProviderMBean(Object managedObject)
{
super(managedObject);
}
@ManagedAttribute("List of monitored resources")
public List<String> getMonitoredResources()
{
return ((WebAppProvider) _managed).getMonitoredResources().stream()
.map((r) -> r.getURI().toASCIIString())
.collect(Collectors.toList());
}
}

View File

@ -20,7 +20,6 @@ package org.eclipse.jetty.deploy;
import java.io.IOException; import java.io.IOException;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import javax.management.MBeanServerConnection; import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnector;
@ -74,7 +73,6 @@ public class JmxServiceConnection
return serviceUrl; return serviceUrl;
} }
/* ------------------------------------------------------------ */
/** /**
* Retrieve a connection to MBean server * Retrieve a connection to MBean server
* *