[jboss-cvs] JBossAS SVN: r112178 - branches/JBPAPP_5_1/system-jmx/src/main/org/jboss/deployment.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Aug 31 01:45:16 EDT 2011
Author: bmaxwell
Date: 2011-08-31 01:45:16 -0400 (Wed, 31 Aug 2011)
New Revision: 112178
Modified:
branches/JBPAPP_5_1/system-jmx/src/main/org/jboss/deployment/MainDeployer.java
Log:
[JBPAPP-6716] fix MainDeployer MBean methods - deploy/undeploy/redeploy/isDeployed/listDeployed*
Modified: branches/JBPAPP_5_1/system-jmx/src/main/org/jboss/deployment/MainDeployer.java
===================================================================
--- branches/JBPAPP_5_1/system-jmx/src/main/org/jboss/deployment/MainDeployer.java 2011-08-31 05:36:56 UTC (rev 112177)
+++ branches/JBPAPP_5_1/system-jmx/src/main/org/jboss/deployment/MainDeployer.java 2011-08-31 05:45:16 UTC (rev 112178)
@@ -32,6 +32,7 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@@ -53,12 +54,19 @@
import org.jboss.bootstrap.spi.ServerConfig;
import org.jboss.deployers.client.spi.DeployerClient;
import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
+import org.jboss.deployers.spi.management.deploy.DeploymentStatus;
+import org.jboss.deployers.spi.management.KnownDeploymentTypes;
+import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.deployers.structure.spi.DeploymentContext;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
import org.jboss.deployers.vfs.spi.client.VFSDeployment;
import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedProperty;
import org.jboss.system.ServiceMBeanSupport;
import org.jboss.system.server.ServerConfigLocator;
import org.jboss.util.file.Files;
@@ -87,6 +95,9 @@
/** The controller */
private KernelController controller;
private DeployerClient delegate;
+ private DeploymentManager deploymentManager;
+ private ManagementView managementView;
+ private List<String> deployed = Collections.synchronizedList(new ArrayList<String>());
private Map<URL, String> contextMap = Collections.synchronizedMap(new HashMap<URL, String>());
/** The deployment factory */
@@ -264,12 +275,8 @@
* @jmx.managed-operation
*/
public Collection listDeployed()
- {
- synchronized (deploymentList)
- {
- log.debug("deployment list string: " + deploymentList);
- return new ArrayList(deploymentList);
- }
+ {
+ return getAllDeployments();
}
/**
@@ -281,25 +288,7 @@
*/
public Collection listDeployedModules()
{
- log.debug("listDeployedModules");
-
- HashMap map = new HashMap();
- synchronized (deploymentList)
- {
- Collection col = new ArrayList(deploymentList);
-
- // create a map entry for each deployment
- for (Iterator it = col.iterator(); it.hasNext();)
- {
- DeploymentInfo info = (DeploymentInfo) it.next();
- map.put(info.url, new SerializableDeploymentInfo(info));
- // assign parent and sub deployments
- fillParentAndChildrenSDI(info, map);
- }
- }
-
- // map.values is not serializable, so we copy
- return new ArrayList(map.values());
+ return getAllDeployments();
}
/**
@@ -309,8 +298,8 @@
* @jmx.managed-operation
*/
public String listDeployedAsString()
- {
- return "<pre>" + listDeployed() + "</pre>";
+ {
+ return "<pre>" + listDeployed() + "</pre>";
}
/**
@@ -572,7 +561,18 @@
public void redeploy(String urlspec)
throws DeploymentException, MalformedURLException
{
- redeploy(new URL(urlspec));
+ URL url;
+ try
+ {
+ url = new URL(urlspec);
+ }
+ catch (MalformedURLException e)
+ {
+ File file = new File(urlspec);
+ url = file.toURL();
+ }
+
+ redeploy(url);
}
/**
@@ -583,26 +583,29 @@
* @jmx.managed-operation
*/
public void redeploy(URL url) throws DeploymentException
- {
- String deploymentName = contextMap.get(url);
- if (deploymentName != null)
+ {
+ String urlspec = url.toString();
+ try
{
- try
- {
- Deployment deployment = delegate.getDeployment(deploymentName);
- delegate.addDeployment(deployment);
- delegate.process();
- delegate.checkComplete(deployment);
- }
- catch (org.jboss.deployers.spi.DeploymentException e)
- {
- throw new DeploymentException(e);
- }
+ // only call undeploy if it is known else profileserivce will log an exception stacktrace
+ if(isDeployedManagementView(urlspec, null))
+ undeploy(urlspec);
+ else
+ log.info(urlspec + " was not deployed, calling deploy");
}
- else
+ catch(Exception e)
{
- deploy(url);
+ // if we fail to undeploy, then try to deploy, if that fails then exception will be thrown up
+ log.warn("error occured trying to undeploy: " + url + " proceeding to deploy");
}
+ try
+ {
+ deploy(urlspec);
+ }
+ catch(MalformedURLException me)
+ {
+ throw new DeploymentException(me);
+ }
}
/**
@@ -636,7 +639,18 @@
public void undeploy(String urlspec)
throws DeploymentException, MalformedURLException
{
- undeploy(new URL(urlspec));
+ URL url;
+ try
+ {
+ url = new URL(urlspec);
+ }
+ catch (MalformedURLException e)
+ {
+ File file = new File(urlspec);
+ url = file.toURL();
+ }
+
+ undeploy(url);
}
/**
@@ -663,10 +677,47 @@
}
else
{
- log.warn("undeploy '" + url + "' : package not deployed");
+ // if the undeploy is called on a deployment not deployed by this mbean
+ // this will just warn, will not throw if url is not deployed, this was the previous behavior expected by testsuite
+ undeployDeploymentManager(url);
}
}
-
+
+ private void undeployDeploymentManager(URL url) throws DeploymentException
+ {
+ String urlspec = url.toString();
+ try
+ {
+ if (deployed.contains(urlspec)) // it was originally deployed by this mbean
+ {
+ log.debug("deployment was deployed my MBean");
+ try
+ {
+ unDeployment(urlspec, true);
+ }
+ finally
+ {
+ deployed.remove(urlspec);
+ }
+ }
+ else
+ // it was originally deployed by deployment scanner, calling remove will delete it from deploy which we do not want
+ {
+ log.debug("in deploy dir, stop will not remove: " + urlspec);
+ unDeployment(urlspec, false);
+ }
+ }
+ catch (RuntimeException re)
+ {
+ log.warn("undeploy '" + urlspec + "' : package not deployed");
+ }
+ catch (Exception e)
+ {
+ throw new DeploymentException(e);
+ }
+ }
+
+
/**
* The <code>undeploy</code> method undeploys a package represented by a
* DeploymentInfo object.
@@ -806,7 +857,7 @@
}
deploy(url);
- }
+ }
/**
* The <code>deploy</code> method deploys a package identified by a URL
@@ -821,26 +872,59 @@
// if it does not exist create a new deployment
if (deploymentName == null)
{
- try
+ // check to see if this was deployed by something other than this mbean
+ if( isDeployedManagementView(url.toExternalForm(), null) )
{
- VirtualFile file = VFS.createNewRoot(url);
- VFSDeployment deployment = deploymentFactory.createVFSDeployment(file);
- delegate.addDeployment(deployment);
- deploymentName = deployment.getName();
- delegate.process();
- // TODO: JBAS-4292
- contextMap.put(url, deploymentName);
- delegate.checkComplete(deployment);
+ deployDeploymentManager(url);
}
- catch(Exception e)
+ else
+ {
+ try
+ {
+ VirtualFile file = VFS.createNewRoot(url);
+ VFSDeployment deployment = deploymentFactory.createVFSDeployment(file);
+ delegate.addDeployment(deployment);
+ deploymentName = deployment.getName();
+ delegate.process();
+ // TODO: JBAS-4292
+ contextMap.put(url, deploymentName);
+ delegate.checkComplete(deployment);
+ }
+ catch(Exception e)
+ {
+ log.warn("Failed to deploy: "+url, e);
+ DeploymentException ex = new DeploymentException("Failed to deploy: "+url, e);
+ throw ex;
+ }
+ }
+ }
+ }
+
+ private void deployDeploymentManager(URL url) throws DeploymentException
+ {
+ log.debug("deploy, url=" + url);
+
+ String urlspec = url.toString();
+ try
+ {
+ if (isDeployedManagementView(urlspec, null))
{
- log.warn("Failed to deploy: "+url, e);
- DeploymentException ex = new DeploymentException("Failed to deploy: "+url, e);
- throw ex;
+ log.debug("already deployed, just start, do not distrubute" + urlspec);
+ doDeployment(urlspec, false);
}
+ else
+ {
+ log.debug("not deployed, doDeployment, then add to MBean list" + urlspec);
+ doDeployment(urlspec, true);
+ deployed.add(urlspec);
+ }
}
+ catch (Exception e)
+ {
+ throw new DeploymentException(e);
+ }
}
-
+
/**
* The <code>deploy</code> method deploys a package represented by a DeploymentInfo object.
*
@@ -1331,7 +1415,17 @@
public boolean isDeployed(String url)
throws MalformedURLException
{
- return isDeployed(new URL(url));
+ URL realUrl;
+ try
+ {
+ realUrl = new URL(url);
+ }
+ catch (MalformedURLException e)
+ {
+ File file = new File(url);
+ realUrl = file.toURL();
+ }
+ return isDeployed(realUrl);
}
/**
@@ -1346,21 +1440,15 @@
String name = contextMap.get(url);
if (name == null)
{
- if (log.isTraceEnabled())
- log.trace("No such context: " + url);
if (url == null)
throw new IllegalArgumentException("Null url");
- String urlString = url.toString();
- // remove this once the JBoss-test is updated with VFS usage
- if (urlString.startsWith("vfs") == false)
- return checkDeployed("vfs" + urlString);
- else
- return checkDeployed(urlString);
+
+ return isDeployedManagementView(url.toString(), DeploymentState.STARTED);
}
-
+
return checkDeployed(name);
}
-
+
/**
* Is deployed.
*
@@ -1492,4 +1580,223 @@
}
return sdi;
}
+
+ // Helper Methods for JBPAPP-6716 - we are calling the KernelController because if we had used injection we would need to change the MBean interface,
+ // which could cause backwards compatibilty issues for customers who are utilizing the current EAP 5.x MainDeployerMBean interface
+ private ManagementView getManagementView()
+ {
+ if(managementView == null)
+ managementView = (ManagementView) controller.getInstalledContext("ManagementView").getTarget();
+
+ return managementView;
+ }
+
+ private DeploymentManager getDeploymentManager()
+ {
+ if(deploymentManager == null)
+ deploymentManager = (DeploymentManager) controller.getInstalledContext("DeploymentManager").getTarget();
+ return deploymentManager;
+ }
+
+ private DeploymentInfo createDeploymentInfo(String urlPath, org.jboss.deployment.DeploymentState state) throws DeploymentException, MalformedURLException
+ {
+ if(urlPath.startsWith("vfs"))
+ {
+ urlPath = "file" + urlPath.substring(urlPath.indexOf(":"));
+ }
+
+ DeploymentInfo di = new DeploymentInfo(new URL(urlPath), null, null);
+ di.state = state;
+
+ // this is a hack to prevent SerializableDeploymentInfo from having a null pointer
+ di.deployer = new JARDeployer();
+
+ return di;
+ }
+
+ private Collection getAllDeployments()
+ {
+ List<ManagedDeployment> managedDeployments = getManagedDeployments();
+ List<DeploymentInfo> deploymentInfos = new ArrayList<DeploymentInfo>(managedDeployments.size() + contextMap.size());
+
+ for(URL url : contextMap.keySet())
+ {
+ try
+ {
+ org.jboss.deployers.spi.DeploymentState deploymentState = delegate.getDeploymentState(contextMap.get(url));
+ org.jboss.deployment.DeploymentState state = null;
+
+ // convert deployment state to DeploymentInfo state
+ if(deploymentState == org.jboss.deployers.spi.DeploymentState.DEPLOYED)
+ state = org.jboss.deployment.DeploymentState.STARTED;
+ else if(deploymentState == org.jboss.deployers.spi.DeploymentState.ERROR)
+ state = org.jboss.deployment.DeploymentState.FAILED;
+ else if(deploymentState == org.jboss.deployers.spi.DeploymentState.UNDEPLOYED)
+ state = org.jboss.deployment.DeploymentState.STOPPED;
+
+ deploymentInfos.add(createDeploymentInfo(url.toExternalForm(), state));
+ }
+ catch(Exception e)
+ {
+ log.warn("Unable to convert deployment: " + url + " to DeploymentInfo", e);
+ }
+ }
+
+ // convert from ManagedDeployment object to DeploymentInfo object
+ for (ManagedDeployment md : managedDeployments)
+ {
+ try
+ {
+ deploymentInfos.add( createDeploymentInfo(md.getName(), org.jboss.deployment.DeploymentState.getDeploymentState(md.getDeploymentState().toString())) );
+ }
+ catch (Exception e)
+ {
+ log.warn("Unable to convert managed deployment: " + md + " to DeploymentInfo", e);
+ }
+ }
+ return deploymentInfos;
+ }
+
+ private List<ManagedDeployment> getManagedDeployments() throws RuntimeException
+ {
+ try
+ {
+ getManagementView().reload();
+ List<ManagedDeployment> managedDeployments = new LinkedList<ManagedDeployment>();
+
+ for (KnownDeploymentTypes type : KnownDeploymentTypes.values())
+ {
+ Set<ManagedDeployment> deployments = getManagementView().getDeploymentsForType(type.getType());
+ managedDeployments.addAll(deployments);
+ }
+
+ return managedDeployments;
+ }
+ catch(Exception e)
+ {
+ log.error("Error getting deployments from ManagementView", e);
+ // this only returning message for twiddle calls that don't have access to the profile exceptions
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ private boolean isDeployedManagementView(String url, DeploymentState state)
+ {
+ String simpleName = getFilenameFromURL(url);
+
+ List<ManagedDeployment> managedDeployments = getManagedDeployments();
+
+ for (ManagedDeployment deployment : managedDeployments)
+ {
+ log.trace("SimpleName: " + deployment.getSimpleName() + "State: " + deployment.getDeploymentState());
+ if (simpleName.equals(deployment.getSimpleName()))
+ {
+ if (state == null)
+ {
+ return true;
+ }
+ else
+ {
+ return deployment.getDeploymentState().toString().compareTo(state.toString()) == 0;
+ }
+ }
+ }
+ return false;
+ }
+
+ private String getFilenameFromURL( String url )
+ {
+ String[] split_url = url.split("/");
+
+ return split_url[split_url.length - 1];
+ }
+
+ private void handleStatusFailures( String message, DeploymentProgress progress ) throws Exception
+ {
+ DeploymentStatus status = progress.getDeploymentStatus();
+
+ if( status.isFailed() ) {
+ throw new Exception(message + " - " + status.getFailure());
+ }
+ }
+
+ private void doDeployment(String url, boolean distribute)
+ {
+ try
+ {
+ URL contentURL = new URL(url);
+ log.debug("Content URL: " + contentURL);
+
+ String name = this.getFilenameFromURL(url);
+
+ log.debug("Content Name: " + name);
+
+ DeploymentProgress progress;
+ String[] uploadedNames = new String[] { name };
+
+ if(distribute)
+ {
+ log.trace("distribute: " + url);
+ // Upload the deployment target
+ // false means do not copy to the deploy directory
+ progress = getDeploymentManager().distribute(name, contentURL, false);
+
+ progress.run();
+
+ handleStatusFailures( "doDeployment.distribute", progress );
+
+ // Get the unique deployment name
+ uploadedNames = progress.getDeploymentID().getRepositoryNames();
+
+ log.debug("Uploaded deployment names: "+Arrays.asList(uploadedNames));
+ }
+
+ log.trace("start: " + url);
+ // Now start the deployment
+ progress = getDeploymentManager().start(uploadedNames);
+ progress.run();
+
+ handleStatusFailures( "doDeployment.start", progress );
+ }
+ catch(Exception e)
+ {
+ log.error("Error distributing / starting using DeploymentManager", e);
+ // this only returning message for twiddle calls that don't have access to the profile exceptions
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+
+ private void unDeployment(String name, boolean remove)
+ {
+ try
+ {
+ String simpleName = this.getFilenameFromURL(name);
+
+ String[] uploadedNames = {simpleName};
+
+ // Stop the deployment
+ log.trace("stop: " + name);
+ DeploymentProgress progress = getDeploymentManager().stop(uploadedNames);
+ progress.run();
+
+ handleStatusFailures( "unDeployment.stop", progress );
+
+ if(remove)
+ {
+ // Remove the deployment
+ log.trace("remove: " + name);
+ progress = getDeploymentManager().remove(uploadedNames);
+ progress.run();
+
+ handleStatusFailures( "unDeployment.remove", progress );
+ }
+ }
+ catch(Exception e)
+ {
+ log.error("Error stopping / remove using DeploymentManager", e);
+ // this only returning message for twiddle calls that don't have access to the profile exceptions
+ throw new RuntimeException(e.getMessage());
+ }
+ }
+ // End of : Helper Methods for JBPAPP-6716
}
More information about the jboss-cvs-commits
mailing list