Merge pull request #3445 from eclipse/jetty-9.4.x-3429-jmx-webappprovider

Issue #3429 - Adding WebAppProvider.scan() method to JMX
This commit is contained in:
Joakim Erdfelt 2019-03-13 16:50:13 -05:00 committed by GitHub
commit d719dce18c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 80 additions and 85 deletions

View File

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

View File

@ -36,8 +36,7 @@ public interface AppProvider extends LifeCycle
* if the provider {@link #isRunning()}.
*/
void setDeploymentManager(DeploymentManager deploymentManager);
/* ------------------------------------------------------------ */
/** Create a ContextHandler for an App
* @param app The App
* @return A ContextHandler

View File

@ -152,7 +152,6 @@ public class DeploymentManager extends ContainerLifeCycle
}
}
/* ------------------------------------------------------------ */
/** Set the AppProviders.
* The providers passed are added via {@link #addBean(Object)} so that
* their lifecycles may be managed as a {@link ContainerLifeCycle}.
@ -170,7 +169,6 @@ public class DeploymentManager extends ContainerLifeCycle
addBean(provider);
}
@ManagedAttribute("Application Providers")
public Collection<AppProvider> getAppProviders()
{
return Collections.unmodifiableList(_providers);
@ -181,7 +179,7 @@ public class DeploymentManager extends ContainerLifeCycle
if (isRunning())
throw new IllegalStateException();
_providers.add(provider);
addBean(provider);
addBean(provider);
}
public void setLifeCycleBindings(Collection<AppLifeCycle.Binding> bindings)
@ -292,7 +290,6 @@ public class DeploymentManager extends ContainerLifeCycle
return Collections.unmodifiableCollection(_apps);
}
@ManagedAttribute("Deployed Apps")
public Collection<App> getApps()
{
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.server.DebugListener;
/** A Deployment binding that installs a DebugListener in all deployed contexts
*/
public class DebugListenerBinding extends DebugBinding

View File

@ -18,8 +18,6 @@
package org.eclipse.jetty.deploy.bindings;
import java.io.File;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle;
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 String _jettyXml;
public String getJettyXml()

View File

@ -203,7 +203,6 @@ public class Graph
Path path = breadthFirst(from,to,new CopyOnWriteArrayList<Path>(),new HashSet<Edge>());
return path;
}
private Path breadthFirst(Node from, Node destination, CopyOnWriteArrayList<Path> paths, Set<Edge> seen)
{
@ -246,7 +245,6 @@ public class Graph
return null;
}
public Set<Edge> getEdges()
{
return _edges;

View File

@ -24,11 +24,11 @@ import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppProvider;
import org.eclipse.jetty.deploy.DeploymentManager;
import org.eclipse.jetty.deploy.graph.Node;
import org.eclipse.jetty.jmx.ObjectMBean;
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.ManagedOperation;
import org.eclipse.jetty.util.annotation.Name;
@ -45,7 +45,7 @@ public class DeploymentManagerMBean extends ObjectMBean
_manager = (DeploymentManager) managedObject;
}
@ManagedOperation(value = "list apps being tracked", impact = "INFO")
@ManagedAttribute(value = "list apps being tracked")
public Collection<String> getApps()
{
List<String> ret = new ArrayList<>();
@ -95,9 +95,10 @@ public class DeploymentManagerMBean extends ObjectMBean
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)

View File

@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import org.eclipse.jetty.deploy.App;
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.annotation.ManagedAttribute;
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.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -55,7 +57,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
private int _scanInterval = 10;
private Scanner _scanner;
/* ------------------------------------------------------------ */
private final Scanner.DiscreteListener _scannerListener = new Scanner.DiscreteListener()
{
@Override
@ -77,26 +78,22 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
}
};
/* ------------------------------------------------------------ */
protected ScanningAppProvider()
{
}
/* ------------------------------------------------------------ */
protected ScanningAppProvider(FilenameFilter filter)
{
_filenameFilter = filter;
}
/* ------------------------------------------------------------ */
protected void setFilenameFilter(FilenameFilter filter)
{
if (isRunning())
throw new IllegalStateException();
_filenameFilter = filter;
}
/* ------------------------------------------------------------ */
/**
* @return The index of currently deployed applications.
*/
@ -105,7 +102,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return _appMap;
}
/* ------------------------------------------------------------ */
/**
* 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
@ -121,7 +117,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return new App(_deploymentManager,this,filename);
}
/* ------------------------------------------------------------ */
@Override
protected void doStart() throws Exception
{
@ -150,7 +145,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_scanner.start();
}
/* ------------------------------------------------------------ */
@Override
protected void doStop() throws Exception
{
@ -161,14 +155,12 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_scanner = null;
}
}
/* ------------------------------------------------------------ */
protected boolean exists(String path)
{
return _scanner.exists(path);
}
/* ------------------------------------------------------------ */
protected void fileAdded(String filename) throws Exception
{
if (LOG.isDebugEnabled())
@ -181,7 +173,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
}
}
/* ------------------------------------------------------------ */
protected void fileChanged(String filename) throws Exception
{
if (LOG.isDebugEnabled())
@ -198,8 +189,7 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_deploymentManager.addApp(app);
}
}
/* ------------------------------------------------------------ */
protected void fileRemoved(String filename) throws Exception
{
if (LOG.isDebugEnabled())
@ -208,8 +198,7 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
if (app != null)
_deploymentManager.removeApp(app);
}
/* ------------------------------------------------------------ */
/**
* Get the deploymentManager.
*
@ -220,8 +209,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return _deploymentManager;
}
/* ------------------------------------------------------------ */
public Resource getMonitoredDirResource()
{
if (_monitored.size()==0)
@ -231,60 +218,51 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return _monitored.get(0);
}
/* ------------------------------------------------------------ */
public String getMonitoredDirName()
{
Resource resource=getMonitoredDirResource();
return resource==null?null:resource.toString();
}
/* ------------------------------------------------------------ */
@ManagedAttribute("scanning interval to detect changes which need reloaded")
public int getScanInterval()
{
return _scanInterval;
}
/* ------------------------------------------------------------ */
@ManagedAttribute("recursive scanning supported")
public boolean isRecursive()
{
return _recursive;
}
/* ------------------------------------------------------------ */
@Override
public void setDeploymentManager(DeploymentManager deploymentManager)
{
_deploymentManager = deploymentManager;
}
/* ------------------------------------------------------------ */
public void setMonitoredResources(List<Resource> resources)
{
_monitored.clear();
_monitored.addAll(resources);
}
/* ------------------------------------------------------------ */
public List<Resource> getMonitoredResources()
{
return Collections.unmodifiableList(_monitored);
}
/* ------------------------------------------------------------ */
public void setMonitoredDirResource(Resource resource)
{
setMonitoredResources(Collections.singletonList(resource));
}
/* ------------------------------------------------------------ */
public void addScannerListener(Scanner.Listener listener)
{
_scanner.addListener(listener);
}
/* ------------------------------------------------------------ */
/**
* @param dir
* 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));
}
/* ------------------------------------------------------------ */
public void setMonitoredDirectories(Collection<String> directories)
{
try
@ -309,16 +286,24 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
throw new IllegalArgumentException(e);
}
}
/* ------------------------------------------------------------ */
protected void setRecursive(boolean recursive)
{
_recursive = recursive;
}
/* ------------------------------------------------------------ */
public void setScanInterval(int 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()
{
super();
@ -132,7 +131,6 @@ public class WebAppProvider extends ScanningAppProvider
setScanInterval(0);
}
/* ------------------------------------------------------------ */
/** Get the extractWars.
* @return the extractWars
*/
@ -142,7 +140,6 @@ public class WebAppProvider extends ScanningAppProvider
return _extractWars;
}
/* ------------------------------------------------------------ */
/** Set the extractWars.
* @param extractWars the extractWars to set
*/
@ -151,7 +148,6 @@ public class WebAppProvider extends ScanningAppProvider
_extractWars = extractWars;
}
/* ------------------------------------------------------------ */
/** Get the parentLoaderPriority.
* @return the parentLoaderPriority
*/
@ -161,7 +157,6 @@ public class WebAppProvider extends ScanningAppProvider
return _parentLoaderPriority;
}
/* ------------------------------------------------------------ */
/** Set the parentLoaderPriority.
* @param parentLoaderPriority the parentLoaderPriority to set
*/
@ -169,8 +164,7 @@ public class WebAppProvider extends ScanningAppProvider
{
_parentLoaderPriority = parentLoaderPriority;
}
/* ------------------------------------------------------------ */
/** Get the defaultsDescriptor.
* @return the defaultsDescriptor
*/
@ -180,7 +174,6 @@ public class WebAppProvider extends ScanningAppProvider
return _defaultsDescriptor;
}
/* ------------------------------------------------------------ */
/** Set the defaultsDescriptor.
* @param defaultsDescriptor the defaultsDescriptor to set
*/
@ -189,13 +182,11 @@ public class WebAppProvider extends ScanningAppProvider
_defaultsDescriptor = defaultsDescriptor;
}
/* ------------------------------------------------------------ */
public ConfigurationManager getConfigurationManager()
{
return _configurationManager;
}
/* ------------------------------------------------------------ */
/** Set the configurationManager.
* @param configurationManager the configurationManager to set
*/
@ -203,8 +194,7 @@ public class WebAppProvider extends ScanningAppProvider
{
_configurationManager = configurationManager;
}
/* ------------------------------------------------------------ */
/**
* @param configurations The configuration class names.
*/
@ -212,8 +202,7 @@ public class WebAppProvider extends ScanningAppProvider
{
_configurationClasses = configurations==null?null:(String[])configurations.clone();
}
/* ------------------------------------------------------------ */
@ManagedAttribute("configuration classes for webapps to be processed through")
public String[] getConfigurationClasses()
{
@ -231,8 +220,7 @@ public class WebAppProvider extends ScanningAppProvider
{
_tempDirectory = directory;
}
/* ------------------------------------------------------------ */
/**
* Get the user supplied Work Directory.
*
@ -244,7 +232,6 @@ public class WebAppProvider extends ScanningAppProvider
return _tempDirectory;
}
/* ------------------------------------------------------------ */
protected void initializeWebAppContextDefaults(WebAppContext webapp)
{
if (_defaultsDescriptor != null)
@ -265,8 +252,7 @@ public class WebAppProvider extends ScanningAppProvider
webapp.setAttribute(WebAppContext.BASETEMPDIR, _tempDirectory);
}
}
/* ------------------------------------------------------------ */
@Override
public ContextHandler createContextHandler(final App app) throws Exception
{
@ -349,8 +335,7 @@ public class WebAppProvider extends ScanningAppProvider
return webAppContext;
}
/* ------------------------------------------------------------ */
@Override
protected void fileChanged(String filename) throws Exception
{
@ -410,7 +395,6 @@ public class WebAppProvider extends ScanningAppProvider
super.fileChanged(filename);
}
/* ------------------------------------------------------------ */
@Override
protected void fileAdded(String filename) throws Exception
{
@ -433,7 +417,6 @@ public class WebAppProvider extends ScanningAppProvider
return;
}
//is the file that was added a .war file?
String lowname = file.getName().toLowerCase(Locale.ENGLISH);
if (lowname.endsWith(".war"))
@ -453,8 +436,6 @@ public class WebAppProvider extends ScanningAppProvider
super.fileAdded(filename);
}
/* ------------------------------------------------------------ */
@Override
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.lang.management.ManagementFactory;
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
@ -74,7 +73,6 @@ public class JmxServiceConnection
return serviceUrl;
}
/* ------------------------------------------------------------ */
/**
* Retrieve a connection to MBean server
*