[jboss-cvs] JBossAS SVN: r112174 - 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
Tue Aug 30 19:15:12 EDT 2011
Author: bmaxwell
Date: 2011-08-30 19:15:12 -0400 (Tue, 30 Aug 2011)
New Revision: 112174
Modified:
branches/JBPAPP_5_1_JBPAPP-6716/system-jmx/src/main/org/jboss/deployment/MainDeployer.java
Log:
[JBPAPP-6716] finishing up/clean up for fixiing deploy/undeploy/isDeploy/listDeploy*
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-30 22:21:51 UTC (rev 112173)
+++ branches/JBPAPP_5_1_JBPAPP-6716/system-jmx/src/main/org/jboss/deployment/MainDeployer.java 2011-08-30 23:15:12 UTC (rev 112174)
@@ -97,7 +97,7 @@
private DeployerClient delegate;
private DeploymentManager deploymentManager;
private ManagementView managementView;
- private List<String> deployed = new ArrayList<String>();
+ private List<String> deployed = Collections.synchronizedList(new ArrayList<String>());
private Map<URL, String> contextMap = Collections.synchronizedMap(new HashMap<URL, String>());
/** The deployment factory */
@@ -607,7 +607,6 @@
}
redeploy(url);
-// redeploy(new URL(urlspec));
}
/**
@@ -618,15 +617,12 @@
* @jmx.managed-operation
*/
public void redeploy(URL url) throws DeploymentException
- {
- // JBPAPP-6716
-// redeploy2(url.toString());
-
+ {
String urlspec = url.toString();
try
{
// only call undeploy if it is known else profileserivce will log an exception stacktrace
- if(isDeployed(urlspec, null))
+ if(isDeployedManagementView(urlspec, null))
undeploy(urlspec);
else
log.info(urlspec + " was not deployed, calling deploy");
@@ -634,6 +630,7 @@
catch(Exception e)
{
// 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
{
@@ -696,39 +693,6 @@
* @param url the url to undeploy
* @jmx.managed-operation
*/
-// public void undeploy(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);
-// }
-// }
-
public void undeploy(URL url) throws DeploymentException
{
String deploymentName = contextMap.remove(url);
@@ -747,10 +711,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.
@@ -898,31 +899,6 @@
* @param url an <code>URL</code> value
* @jmx.managed-operation
*/
-// public void deploy(URL url) throws DeploymentException
-// {
-// log.debug("deploy, url="+url);
-//
-// String urlspec = url.toString();
-// try
-// {
-// if(isDeployed(urlspec, null))
-// {
-// 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);
-// }
-// }
-
public void deploy(URL url) throws DeploymentException
{
log.info("deploy, url="+url);
@@ -930,24 +906,57 @@
// 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);
+ }
}
/**
@@ -1460,6 +1469,16 @@
* @return a <code>boolean</code> value
* @jmx.managed-operation
*/
+ public boolean isDeployed(URL url)
+ {
+ String name = contextMap.get(url);
+ if (name == null)
+ {
+ return isDeployedManagementView(url.toString(), DeploymentState.STARTED);
+ }
+
+ return checkDeployed(name);
+ }
// public boolean isDeployed(URL url)
// {
// String name = contextMap.get(url);
@@ -1479,17 +1498,6 @@
//
// return isDeployed(url.toString(), DeploymentState.STARTED);
// }
-
- public boolean isDeployed(URL url)
- {
- String name = contextMap.get(url);
- if (name == null)
- {
- return isDeployed(url.toString(), DeploymentState.STARTED);
- }
-
- return checkDeployed(name);
- }
/**
* Is deployed.
@@ -1639,111 +1647,67 @@
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 getDeployed()
-// {
-// List<ManagedDeployment> managedDeployments = getAllDeployments();
-// List<DeploymentInfo> deploymentInfos = new ArrayList<DeploymentInfo>(managedDeployments.size());
-//
-// // convert from ManagedDeployment object to DeploymentInfo object
-// for (ManagedDeployment md : managedDeployments)
-// {
-// try
-// {
-// String urlPath = md.getName();
-//
-// if(urlPath.startsWith("vfs"))
-// {
-// urlPath = "file" + urlPath.substring(urlPath.indexOf(":"));
-// }
-//
-// DeploymentInfo di = new DeploymentInfo(new URL(urlPath), null, null);
-//
-// di.state = org.jboss.deployment.DeploymentState.getDeploymentState(md.getDeploymentState().toString());
-//
-// // this is a hack to prevent SerializableDeploymentInfo from having a null pointer
-// di.deployer = new JARDeployer();
-//
-// deploymentInfos.add(di);
-// }
-// catch (Exception e)
-// {
-// e.printStackTrace();
-// }
-// }
-// return deploymentInfos;
-// }
-
private Collection getDeployed()
{
- List<ManagedDeployment> managedDeployments = getAllDeployments();
+ List<ManagedDeployment> managedDeployments = getManagedDeployments();
List<DeploymentInfo> deploymentInfos = new ArrayList<DeploymentInfo>(managedDeployments.size() + contextMap.size());
-
- try
+
+ for(URL url : contextMap.keySet())
{
- for(URL url : contextMap.keySet())
- {
- String urlPath = url.toExternalForm();
+ try
+ {
+ org.jboss.deployers.spi.DeploymentState deploymentState = delegate.getDeploymentState(contextMap.get(url));
+ org.jboss.deployment.DeploymentState state = null;
- if(urlPath.startsWith("vfs"))
- {
- urlPath = "file" + urlPath.substring(urlPath.indexOf(":"));
- }
-
- DeploymentInfo di = new DeploymentInfo(new URL(urlPath), null, null);
-
- String name = contextMap.get(url);
-
- org.jboss.deployers.spi.DeploymentState deploymentState = delegate.getDeploymentState(name);
-
+ // convert deployment state to DeploymentInfo state
if(deploymentState == org.jboss.deployers.spi.DeploymentState.DEPLOYED)
- di.state = org.jboss.deployment.DeploymentState.STARTED;
+ state = org.jboss.deployment.DeploymentState.STARTED;
else if(deploymentState == org.jboss.deployers.spi.DeploymentState.ERROR)
- di.state = org.jboss.deployment.DeploymentState.FAILED;
+ state = org.jboss.deployment.DeploymentState.FAILED;
else if(deploymentState == org.jboss.deployers.spi.DeploymentState.UNDEPLOYED)
- di.state = org.jboss.deployment.DeploymentState.STOPPED;
-
- // this is a hack to prevent SerializableDeploymentInfo from having a null pointer
- di.deployer = new JARDeployer();
-
- deploymentInfos.add(di);
+ 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);
+ }
}
- catch(Exception e)
- {
- e.printStackTrace();
- }
-
+
// convert from ManagedDeployment object to DeploymentInfo object
for (ManagedDeployment md : managedDeployments)
{
try
- {
- String urlPath = md.getName();
-
- if(urlPath.startsWith("vfs"))
- {
- urlPath = "file" + urlPath.substring(urlPath.indexOf(":"));
- }
-
- DeploymentInfo di = new DeploymentInfo(new URL(urlPath), null, null);
-
- di.state = org.jboss.deployment.DeploymentState.getDeploymentState(md.getDeploymentState().toString());
-
- // this is a hack to prevent SerializableDeploymentInfo from having a null pointer
- di.deployer = new JARDeployer();
-
- deploymentInfos.add(di);
+ {
+ deploymentInfos.add( createDeploymentInfo(md.getName(), org.jboss.deployment.DeploymentState.getDeploymentState(md.getDeploymentState().toString())) );
}
catch (Exception e)
- {
- e.printStackTrace();
+ {
+ log.warn("Unable to convert managed deployment: " + md + " to DeploymentInfo", e);
}
}
return deploymentInfos;
}
- private List<ManagedDeployment> getAllDeployments() throws RuntimeException
+ private List<ManagedDeployment> getManagedDeployments() throws RuntimeException
{
try
{
@@ -1766,28 +1730,28 @@
}
}
- private boolean isDeployed(String url, DeploymentState state)
- {
- String simpleName = getFilenameFromURL(url);
-
- List<ManagedDeployment> managedDeployments = getAllDeployments();
+ private boolean isDeployedManagementView(String url, DeploymentState state)
+ {
+ String simpleName = getFilenameFromURL(url);
- for (ManagedDeployment deployment : managedDeployments)
+ List<ManagedDeployment> managedDeployments = getManagedDeployments();
+
+ for (ManagedDeployment deployment : managedDeployments)
+ {
+ log.trace("SimpleName: " + deployment.getSimpleName() + "State: " + deployment.getDeploymentState());
+ if (simpleName.equals(deployment.getSimpleName()))
{
- log.trace("SimpleName: " + deployment.getSimpleName() + "State: " + deployment.getDeploymentState());
- if (simpleName.equals(deployment.getSimpleName()))
+ if (state == null)
{
- if (state == null)
- {
- return true;
- }
- else
- {
- return deployment.getDeploymentState().toString().compareTo(state.toString()) == 0;
- }
+ return true;
}
+ else
+ {
+ return deployment.getDeploymentState().toString().compareTo(state.toString()) == 0;
+ }
}
- return false;
+ }
+ return false;
}
private String getFilenameFromURL( String url )
@@ -1829,7 +1793,7 @@
progress.run();
- this.handleStatusFailures( "doDeployment.distribute", progress );
+ handleStatusFailures( "doDeployment.distribute", progress );
// Get the unique deployment name
uploadedNames = progress.getDeploymentID().getRepositoryNames();
@@ -1842,7 +1806,7 @@
progress = getDeploymentManager().start(uploadedNames);
progress.run();
- this.handleStatusFailures( "doDeployment.start", progress );
+ handleStatusFailures( "doDeployment.start", progress );
}
catch(Exception e)
{
@@ -1856,16 +1820,16 @@
{
try
{
- String simple_name = this.getFilenameFromURL(name);
+ String simpleName = this.getFilenameFromURL(name);
- String[] uploadedNames = {simple_name};
+ String[] uploadedNames = {simpleName};
// Stop the deployment
log.trace("stop: " + name);
DeploymentProgress progress = getDeploymentManager().stop(uploadedNames);
progress.run();
- this.handleStatusFailures( "unDeployment.stop", progress );
+ handleStatusFailures( "unDeployment.stop", progress );
if(remove)
{
@@ -1874,7 +1838,7 @@
progress = getDeploymentManager().remove(uploadedNames);
progress.run();
- this.handleStatusFailures( "unDeployment.remove", progress );
+ handleStatusFailures( "unDeployment.remove", progress );
}
}
catch(Exception e)
More information about the jboss-cvs-commits
mailing list