[jboss-cvs] JBossAS SVN: r112159 - 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 02:14:29 EDT 2011


Author: bmaxwell
Date: 2011-08-30 02:14:28 -0400 (Tue, 30 Aug 2011)
New Revision: 112159

Modified:
   branches/JBPAPP_5_1_JBPAPP-6716/system-jmx/src/main/org/jboss/deployment/MainDeployer.java
Log:
[JBPAPP-6716] revert deploy/undeploy/isDeployed and modified to fix

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-29 21:54:18 UTC (rev 112158)
+++ branches/JBPAPP_5_1_JBPAPP-6716/system-jmx/src/main/org/jboss/deployment/MainDeployer.java	2011-08-30 06:14:28 UTC (rev 112159)
@@ -620,27 +620,29 @@
    public void redeploy(URL url) throws DeploymentException
    {
       // JBPAPP-6716
-      redeploy2(url.toString());
+//      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);
-//      }
+      String urlspec = url.toString();
+      try
+      {
+         // only call undeploy if it is known else profileserivce will log an exception stacktrace
+         if(isDeployed(urlspec, null))
+            undeploy(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
+      }
+      try
+      {
+         deploy(urlspec);
+      }
+      catch(MalformedURLException me)
+      {
+         throw new DeploymentException(me);
+      }     
    }
 
    /**
@@ -686,7 +688,6 @@
       }
       
       undeploy(url);
-      //undeploy(new URL(urlspec));
    }
 
    /**
@@ -695,32 +696,61 @@
     * @param url the url to undeploy
     * @jmx.managed-operation
     */
-   public void undeploy(URL url) throws DeploymentException
-   {
-      // JBPAPP-6716
-      
-      undeploy2(url.toString());
-      
-//      String deploymentName = contextMap.remove(url);
-//      if (deploymentName != null)
+//   public void undeploy(URL url) throws DeploymentException
+//   {            
+//      String urlspec = url.toString();
+//      try
 //      {
-//         try
+//         if(deployed.contains(urlspec)) // it was originally deployed by this mbean
 //         {
-//            delegate.removeDeployment(deploymentName);
-//            delegate.process();
+//            log.debug("deployment was deployed my MBean");
+//            try
+//            {
+//               unDeployment(urlspec, true);
+//            }
+//           finally
+//            {
+//               deployed.remove(urlspec);
+//            }
 //         }
-//         catch(Exception e)
+//         else // it was originally deployed by deployment scanner, calling remove will delete it from deploy which we do not want
 //         {
-//            DeploymentException ex = new DeploymentException("Error during undeploy of: "+url, e);
-//            throw ex;
-//         }
+//            log.debug("in deploy dir, stop will not remove: " + urlspec);
+//            unDeployment(urlspec, false);
+//         }         
 //      }
-//      else
+//      catch(RuntimeException re)
 //      {
-//         log.warn("undeploy '" + url + "' : package not deployed");
+//         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);
+      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");
+      }
    }
-
+   
    /**
     * The <code>undeploy</code> method undeploys a package represented by a
     * DeploymentInfo object.
@@ -860,7 +890,7 @@
       }
 
       deploy(url);
-   }
+   }  
 
    /**
     * The <code>deploy</code> method deploys a package identified by a URL
@@ -868,6 +898,31 @@
     * @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);
@@ -877,18 +932,14 @@
       {
          try
          {
-            // 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);
+            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)
          {
@@ -898,7 +949,7 @@
          }
       }
    }
-
+   
    /**
     * The <code>deploy</code> method deploys a package represented by a DeploymentInfo object.
     *
@@ -1400,7 +1451,6 @@
          realUrl = file.toURL();
       }
       return isDeployed(realUrl);
-//      return isDeployed(new URL(url));
    }
 
    /**
@@ -1410,29 +1460,37 @@
     * @return a <code>boolean</code> value
     * @jmx.managed-operation
     */
+//   public boolean isDeployed(URL url)
+//   {
+//      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 isDeployed("vfs" + urlString, DeploymentState.STARTED);
+//         else
+//            return isDeployed(urlString, DeploymentState.STARTED);
+//      }
+//
+//      return isDeployed(url.toString(), DeploymentState.STARTED);
+//   }
+
    public boolean isDeployed(URL url)
    {
       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 isDeployed("vfs" + urlString, DeploymentState.STARTED);
-//            return checkDeployed("vfs" + urlString);
-         else
-            return isDeployed(urlString, DeploymentState.STARTED);
-//            return checkDeployed(urlString);
+         return isDeployed(url.toString(), DeploymentState.STARTED);
       }
-
-//      return checkDeployed(name);
-      return isDeployed(url.toString(), DeploymentState.STARTED);
+      
+      return checkDeployed(name);
    }
-
+   
    /**
     * Is deployed.
     *
@@ -1574,6 +1632,7 @@
       
       return managementView;
    }
+   
    private DeploymentManager getDeploymentManager()
    {
       if(deploymentManager == null)
@@ -1581,30 +1640,99 @@
       return deploymentManager;
    }
    
+//   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<DeploymentInfo> deploymentInfos = new ArrayList<DeploymentInfo>(managedDeployments.size());
+      List<DeploymentInfo> deploymentInfos = new ArrayList<DeploymentInfo>(managedDeployments.size() + contextMap.size());
 
+      try
+      {
+         for(URL url : contextMap.keySet())
+         {                  
+            String urlPath = url.toExternalForm();
+            
+            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);                  
+            
+            if(deploymentState == org.jboss.deployers.spi.DeploymentState.DEPLOYED)
+               di.state = org.jboss.deployment.DeploymentState.STARTED;
+            else if(deploymentState == org.jboss.deployers.spi.DeploymentState.ERROR)
+               di.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);
+         }
+      }
+      catch(Exception e)
+      {
+         e.printStackTrace();
+      }
+      
       // convert from ManagedDeployment object to DeploymentInfo object
       for (ManagedDeployment md : managedDeployments)
       {
          try
          {            
             String urlPath = md.getName();
-//            log.info("ManagedDeployment name: " + urlPath);
+            
             if(urlPath.startsWith("vfs"))
-               urlPath = "file" + urlPath.substring(urlPath.indexOf(":"));               
-//                  urlPath = urlPath.substring(3);                        
+            {
+               urlPath = "file" + urlPath.substring(urlPath.indexOf(":"));
+            }
             
-//            VirtualFile file = VFS.createNewRoot(url);
-//            VirtualFile vfile = VFS.getRoot(new URL(urlPath));
+            DeploymentInfo di = new DeploymentInfo(new URL(urlPath), null, null);
             
+            di.state = org.jboss.deployment.DeploymentState.getDeploymentState(md.getDeploymentState().toString());
             
-            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)
@@ -1623,8 +1751,7 @@
          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);                           
          }
@@ -1641,19 +1768,19 @@
    
    private boolean isDeployed(String url, DeploymentState state)
    {     
-         String simple_name = getFilenameFromURL(url);
+         String simpleName = getFilenameFromURL(url);
          
          List<ManagedDeployment> managedDeployments = getAllDeployments();
 
          for (ManagedDeployment deployment : managedDeployments)
          {
-            log.debug("SimpleName: " + deployment.getSimpleName());
-            log.debug("\tState: " + deployment.getDeploymentState());
-            if (simple_name.equals(deployment.getSimpleName()))
+            log.trace("SimpleName: " + deployment.getSimpleName() + "State: " + deployment.getDeploymentState());
+            if (simpleName.equals(deployment.getSimpleName()))
             {
-               //         return deployment.getDeploymentState().toString().equals("STARTED");
                if (state == null)
+               {
                   return true;
+               }
                else
                {
                   return deployment.getDeploymentState().toString().compareTo(state.toString()) == 0;                                                      
@@ -1670,12 +1797,12 @@
       return split_url[split_url.length - 1];
    }
    
-   private void handleStatusFailures( DeploymentProgress progress ) throws Exception
+   private void handleStatusFailures( String message, DeploymentProgress progress ) throws Exception
    {
       DeploymentStatus status = progress.getDeploymentStatus();
 
       if( status.isFailed() ) {
-        throw new Exception(status.getFailure());
+        throw new Exception(message + " - " + status.getFailure());
       }
    }
    
@@ -1695,24 +1822,27 @@
          
          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();
    
-            this.handleStatusFailures( progress );
+            this.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();
    
-         this.handleStatusFailures( progress );
+         this.handleStatusFailures( "doDeployment.start", progress );
       }
       catch(Exception e)
       {                 
@@ -1731,18 +1861,20 @@
          String[] uploadedNames = {simple_name};
    
          // Stop the deployment         
+         log.trace("stop: " + name);
          DeploymentProgress progress = getDeploymentManager().stop(uploadedNames);
          progress.run();
    
-         this.handleStatusFailures( progress );
+         this.handleStatusFailures( "unDeployment.stop", progress );
    
          if(remove)
          {
             // Remove the deployment
+            log.trace("remove: " + name);
             progress = getDeploymentManager().remove(uploadedNames);
             progress.run();
       
-            this.handleStatusFailures( progress );
+            this.handleStatusFailures( "unDeployment.remove", progress );
          }
       }
       catch(Exception e)
@@ -1752,63 +1884,5 @@
          throw new RuntimeException(e.getMessage());
       }
    }      
-   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