[jboss-cvs] JBossAS SVN: r112132 - branches/JBPAPP_5_1_JBPAPP-6716/system-jmx/src/main/org/jboss/deployment.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Aug 25 22:10:45 EDT 2011
Author: bmaxwell
Date: 2011-08-25 22:10:45 -0400 (Thu, 25 Aug 2011)
New Revision: 112132
Modified:
branches/JBPAPP_5_1_JBPAPP-6716/system-jmx/src/main/org/jboss/deployment/MainDeployer.java
Log:
[JBPAPP-6716] added DeploymentManager MC Bean helper methods
Modified: branches/JBPAPP_5_1_JBPAPP-6716/system-jmx/src/main/org/jboss/deployment/MainDeployer.java
===================================================================
--- branches/JBPAPP_5_1_JBPAPP-6716/system-jmx/src/main/org/jboss/deployment/MainDeployer.java 2011-08-26 01:44:40 UTC (rev 112131)
+++ branches/JBPAPP_5_1_JBPAPP-6716/system-jmx/src/main/org/jboss/deployment/MainDeployer.java 2011-08-26 02:10:45 UTC (rev 112132)
@@ -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,6 +54,9 @@
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;
@@ -62,6 +66,7 @@
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;
@@ -90,7 +95,9 @@
/** The controller */
private KernelController controller;
private DeployerClient delegate;
+ private DeploymentManager deploymentManager;
private ManagementView managementView;
+ private List<String> deployed = new ArrayList<String>();
private Map<URL, String> contextMap = Collections.synchronizedMap(new HashMap<URL, String>());
/** The deployment factory */
@@ -315,16 +322,8 @@
* @jmx.managed-operation
*/
public String listDeployedAsString()
- {
- try
- {
- return "<pre>" + listDeployed() + "</pre>";
- }
- catch(Exception e)
- {
- // return exception ?
- return "<pre>" + e.toString() + "</pre>";
- }
+ {
+ return "<pre>" + listDeployed() + "</pre>";
}
/**
@@ -598,25 +597,28 @@
*/
public void redeploy(URL url) throws DeploymentException
{
- String deploymentName = contextMap.get(url);
- if (deploymentName != null)
- {
- 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);
- }
- }
- else
- {
- deploy(url);
- }
+ // JBPAPP-6716
+ redeploy2(url.toString());
+
+// String deploymentName = contextMap.get(url);
+// if (deploymentName != null)
+// {
+// 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);
+// }
+// }
+// else
+// {
+// deploy(url);
+// }
}
/**
@@ -661,24 +663,28 @@
*/
public void undeploy(URL url) throws DeploymentException
{
- String deploymentName = contextMap.remove(url);
- if (deploymentName != null)
- {
- try
- {
- delegate.removeDeployment(deploymentName);
- delegate.process();
- }
- catch(Exception e)
- {
- DeploymentException ex = new DeploymentException("Error during undeploy of: "+url, e);
- throw ex;
- }
- }
- else
- {
- log.warn("undeploy '" + url + "' : package not deployed");
- }
+ // JBPAPP-6716
+
+ undeploy2(url.toString());
+
+// String deploymentName = contextMap.remove(url);
+// if (deploymentName != null)
+// {
+// try
+// {
+// delegate.removeDeployment(deploymentName);
+// delegate.process();
+// }
+// catch(Exception e)
+// {
+// DeploymentException ex = new DeploymentException("Error during undeploy of: "+url, e);
+// throw ex;
+// }
+// }
+// else
+// {
+// log.warn("undeploy '" + url + "' : package not deployed");
+// }
}
/**
@@ -837,14 +843,18 @@
{
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);
+ // JBPAPP-6716
+
+ deploy2(url.toString());
+
+// 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)
{
@@ -1367,12 +1377,15 @@
String urlString = url.toString();
// remove this once the JBoss-test is updated with VFS usage
if (urlString.startsWith("vfs") == false)
- return checkDeployed("vfs" + urlString);
+ return isDeployed("vfs" + urlString, DeploymentState.STARTED);
+// return checkDeployed("vfs" + urlString);
else
- return checkDeployed(urlString);
+ return isDeployed(urlString, DeploymentState.STARTED);
+// return checkDeployed(urlString);
}
- return checkDeployed(name);
+// return checkDeployed(name);
+ return isDeployed(url.toString(), DeploymentState.STARTED);
}
/**
@@ -1516,30 +1529,58 @@
return managementView;
}
+ private DeploymentManager getDeploymentManager()
+ {
+ if(deploymentManager == null)
+ deploymentManager = (DeploymentManager) controller.getInstalledContext("DeploymentManager").getTarget();
+ return deploymentManager;
+ }
- private Collection getDeployed() throws RuntimeException
+ private Collection getDeployed()
{
- try
+ List<ManagedDeployment> managedDeployments = getAllDeployments();
+ List<DeploymentInfo> deploymentInfos = new ArrayList<DeploymentInfo>(managedDeployments.size());
+
+ // convert from ManagedDeployment object to DeploymentInfo object
+ for (ManagedDeployment md : managedDeployments)
{
- List<ManagedDeployment> managedDeployments = getAllDeployments();
- List<DeploymentInfo> deploymentInfos = new ArrayList<DeploymentInfo>(managedDeployments.size());
-
- // convert from ManagedDeployment object to DeploymentInfo object
- for(ManagedDeployment md : managedDeployments)
+ try
{
- try
+ DeploymentInfo di = new DeploymentInfo(new URL(md.getName()), null, null);
+ di.state = org.jboss.deployment.DeploymentState.getDeploymentState(md.getDeploymentState().toString());
+ deploymentInfos.add(di);
+
+ Map<String, ManagedProperty> props = md.getProperties();
+ for (Map.Entry<String, ManagedProperty> entry : props.entrySet())
{
- DeploymentInfo di = new DeploymentInfo(new URL(md.getName()), null, null);
- di.state = org.jboss.deployment.DeploymentState.getDeploymentState(md.getDeploymentState().toString());
- deploymentInfos.add(di);
+ log.info(md);
+ log.info("Name: " + entry.getKey() + " value: " + entry.getValue());
}
- catch(Exception e)
- {
- e.printStackTrace();
- }
}
- return deploymentInfos;
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
}
+ return deploymentInfos;
+ }
+
+ private List<ManagedDeployment> getAllDeployments() throws RuntimeException
+ {
+ try
+ {
+ getManagementView().reload();
+ List<ManagedDeployment> managedDeployments = new LinkedList<ManagedDeployment>();
+
+ for (KnownDeploymentTypes type : KnownDeploymentTypes.values())
+ {
+ log.debug("type: " + type.getType());
+ Set<ManagedDeployment> deployments = getManagementView().getDeploymentsForType(type.getType());
+ managedDeployments.addAll(deployments);
+ }
+
+ return managedDeployments;
+ }
catch(Exception e)
{
log.error("Error getting deployments from ManagementView", e);
@@ -1547,41 +1588,27 @@
}
}
- private List<ManagedDeployment> getAllDeployments() throws Exception
- {
- getManagementView().reload();
- List<ManagedDeployment> managedDeployments = new LinkedList<ManagedDeployment>();
-
- for (KnownDeploymentTypes type : KnownDeploymentTypes.values())
- {
- log.debug("type: " + type.getType());
- Set<ManagedDeployment> deployments = getManagementView().getDeploymentsForType(type.getType());
- managedDeployments.addAll(deployments);
- }
-
- return managedDeployments;
- }
-
- private boolean isDeployed(String url, DeploymentState state) throws Exception
+ private boolean isDeployed(String url, DeploymentState state)
{
- String simple_name = getFilenameFromURL(url);
+
+ String simple_name = getFilenameFromURL(url);
- List<ManagedDeployment> managedDeployments = getAllDeployments();
+ List<ManagedDeployment> managedDeployments = getAllDeployments();
- for(ManagedDeployment deployment : managedDeployments)
- {
- log.debug("SimpleName: "+deployment.getSimpleName());
- log.debug("\tState: "+deployment.getDeploymentState());
- if( simple_name.equals(deployment.getSimpleName()) )
- {
-// return deployment.getDeploymentState().toString().equals("STARTED");
- if(state == null)
- return true;
- else
- return deployment.getDeploymentState().toString().equals(state);
- }
- }
- return false;
+ for (ManagedDeployment deployment : managedDeployments)
+ {
+ log.debug("SimpleName: " + deployment.getSimpleName());
+ log.debug("\tState: " + deployment.getDeploymentState());
+ if (simple_name.equals(deployment.getSimpleName()))
+ {
+ // return deployment.getDeploymentState().toString().equals("STARTED");
+ if (state == null)
+ return true;
+ else
+ return deployment.getDeploymentState().toString().equals(state);
+ }
+ }
+ return false;
}
private String getFilenameFromURL( String url )
@@ -1590,4 +1617,144 @@
return split_url[split_url.length - 1];
}
+
+ private void handleStatusFailures( DeploymentProgress progress ) throws Exception
+ {
+ DeploymentStatus status = progress.getDeploymentStatus();
+
+ if( status.isFailed() ) {
+ throw new Exception(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)
+ {
+ // Upload the deployment target
+ // false means do not copy to the deploy directory
+ progress = getDeploymentManager().distribute(name, contentURL, false);
+ progress.run();
+
+ this.handleStatusFailures( progress );
+
+ // Get the unique deployment name
+ uploadedNames = progress.getDeploymentID().getRepositoryNames();
+
+ log.debug("Uploaded deployment names: "+Arrays.asList(uploadedNames));
+ }
+
+ // Now start the deployment
+ progress = getDeploymentManager().start(uploadedNames);
+ progress.run();
+
+ this.handleStatusFailures( progress );
+ }
+ catch(Exception e)
+ {
+ log.error("Error distributing / starting using DeploymentManager", e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void unDeployment(String name, boolean remove)
+ {
+ try
+ {
+ String simple_name = this.getFilenameFromURL(name);
+
+ String[] uploadedNames = {simple_name};
+
+ // Stop the deployment
+ DeploymentProgress progress = getDeploymentManager().stop(uploadedNames);
+ progress.run();
+
+ this.handleStatusFailures( progress );
+
+ if(remove)
+ {
+ // Remove the deployment
+ progress = getDeploymentManager().remove(uploadedNames);
+ progress.run();
+
+ this.handleStatusFailures( progress );
+ }
+ }
+ catch(Exception e)
+ {
+ log.error("Error stopping / remove using DeploymentManager", e);
+ throw new RuntimeException(e);
+ }
+ }
+ private void redeploy2(String urlspec) throws DeploymentException
+ {
+ try
+ {
+ // only call undeploy if it is known else profileserivce will log an exception stacktrace
+ if(isDeployed(urlspec, null))
+ undeploy2(urlspec);
+ else
+ log.info(urlspec + " was not deployed, calling deploy");
+ }
+ catch(Exception e)
+ {
+ // if we fail to undeploy, then try to deploy, if that fails then exception will be thrown up
+ }
+ deploy2(urlspec);
+ }
+
+ private void undeploy2(String urlspec) throws DeploymentException
+ {
+ try
+ {
+ if(deployed.contains(urlspec)) // it was originally deployed by this mbean
+ {
+ unDeployment(urlspec, true);
+ 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 ( Exception e )
+ {
+ throw new DeploymentException(e);
+ }
+ }
+
+ private void deploy2(String urlspec) throws DeploymentException
+ {
+ try
+ {
+ if(isDeployed(urlspec, null))
+ {
+ log.debug("already deployed, just start do not distrubute" + urlspec);
+ doDeployment(urlspec, false);
+ }
+ else
+ {
+ doDeployment(urlspec, true);
+ deployed.add(urlspec);
+ }
+ }
+ catch ( Exception e )
+ {
+ throw new DeploymentException(e);
+ }
+ }
+ // End of : Helper Methods for JBPAPP-6716
}
More information about the jboss-cvs-commits
mailing list