[jboss-cvs] JBossAS SVN: r97251 - in trunk: system/src/main/java/org/jboss/system/server/profileservice and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 1 12:05:54 EST 2009


Author: emuckenhuber
Date: 2009-12-01 12:05:53 -0500 (Tue, 01 Dec 2009)
New Revision: 97251

Added:
   trunk/testsuite/src/main/org/jboss/test/deployers/test/LegacyDeploymentScannerUnitTestCase.java
Modified:
   trunk/profileservice/src/resources/hdscanner-jboss-beans.xml
   trunk/system/src/main/java/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java
   trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/TypedProfileRepository.java
   trunk/system/src/main/java/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java
Log:
port changes for AS-7286 from 5_x branch.

Modified: trunk/profileservice/src/resources/hdscanner-jboss-beans.xml
===================================================================
--- trunk/profileservice/src/resources/hdscanner-jboss-beans.xml	2009-12-01 17:01:16 UTC (rev 97250)
+++ trunk/profileservice/src/resources/hdscanner-jboss-beans.xml	2009-12-01 17:05:53 UTC (rev 97251)
@@ -28,6 +28,7 @@
         <parameter><inject bean="ProfileService"/></parameter>
         <parameter><inject bean="StructureModificationChecker"/></parameter>
       </constructor>
+      <property name="profileRepository"><inject bean="ProfileRepositoryFactory" /></property>
     </bean>
 
 </deployment>

Modified: trunk/system/src/main/java/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java
===================================================================
--- trunk/system/src/main/java/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java	2009-12-01 17:01:16 UTC (rev 97250)
+++ trunk/system/src/main/java/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java	2009-12-01 17:05:53 UTC (rev 97251)
@@ -38,10 +38,6 @@
 import org.jboss.bootstrap.spi.as.JBossASBootstrap;
 import org.jboss.bootstrap.spi.as.config.JBossASServerConfig;
 import org.jboss.bootstrap.spi.as.server.JBossASServer;
-import org.jboss.bootstrap.spi.config.ServerConfig;
-import org.jboss.bootstrap.spi.mc.config.MCServerConfig;
-import org.jboss.bootstrap.spi.mc.server.MCBasedServer;
-import org.jboss.bootstrap.spi.mc.server.MCServer;
 import org.jboss.bootstrap.spi.server.Server;
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.dependency.spi.ControllerState;
@@ -262,12 +258,10 @@
          if(this.profileKey.equals(profile.getKey()) == false)
             this.bootstrapProfiles.add(0, profile.getKey());
       }
-      
       // Activate the root profile
       log.info("Loading profile: " + this.profileKey);
       this.profileService.activateProfile(this.profileKey);
       this.profileService.validateProfile(this.profileKey);
-      
       try
       {
          // Check if everything is complete
@@ -281,7 +275,6 @@
       {
          log.error("Failed to load profile: ", e);
       }
-      
       // Enable modification checks on all mutable profiles 
       for(ProfileKey key : profileService.getActiveProfileKeys())
       {
@@ -289,7 +282,9 @@
          {
             Profile profile = profileService.getActiveProfile(key);
             if(profile.isMutable() && profile instanceof MutableProfile)
+            {
                ((MutableProfile) profile).enableModifiedDeploymentChecks(true);
+            }
          }
          catch(NoSuchProfileException ignore) { }
       }
@@ -298,31 +293,35 @@
    public void prepareShutdown(JBossASServer server)
    {
       shutdown.set(true);
-      if (mainDeployer != null)
-         mainDeployer.prepareShutdown();
-   }
-
-   public void shutdown(JBossASServer server)
-   {
-	  // Disable modification checks on all mutable profiles
+      // Disable modification checks on all mutable profiles
       for(ProfileKey key : profileService.getActiveProfileKeys())
       {
          try
          {
             Profile profile = profileService.getActiveProfile(key);
             if(profile.isMutable() && profile instanceof MutableProfile)
+            {
                ((MutableProfile) profile).enableModifiedDeploymentChecks(false);
+            }
          }
          catch(NoSuchProfileException ignore) { }
       }
-      
-      
+      if (mainDeployer != null)
+      {
+         mainDeployer.prepareShutdown();
+      }
+   }
+
+   public void shutdown(JBossASServer server)
+   {
       // Deactivate the root profile
       try
       {
          // Release 
     	 if(profileService.getActiveProfileKeys().contains(profileKey))
+    	 {
     		 profileService.deactivateProfile(profileKey);
+    	 }
       }
       catch(Throwable t)
       {
@@ -332,7 +331,9 @@
       {
          // Unregister
     	 if(profileService.getProfileKeys().contains(profileKey))
+    	 {
     		 profileService.unregisterProfile(profileKey);
+    	 }
       }
       catch(Throwable t)
       {

Modified: trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/TypedProfileRepository.java
===================================================================
--- trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/TypedProfileRepository.java	2009-12-01 17:01:16 UTC (rev 97250)
+++ trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/TypedProfileRepository.java	2009-12-01 17:05:53 UTC (rev 97251)
@@ -141,4 +141,45 @@
          this.repositoryFactories.remove(type);
    }
    
+   /**
+    * InCallback to register a repository bean.
+    * 
+    * @param repository the deploymentRepository to register
+    */
+   public void registerDeploymentRepository(AbstractDeploymentRepository repository)
+   {
+      if(repository == null)
+         throw new IllegalArgumentException("null deployment repository");
+      ProfileKey repositoryKey = repository.getProfileKey(); 
+      if(repositoryKey == null)
+         throw new IllegalArgumentException("null profile key");
+      if(this.repositories.containsKey(repositoryKey))
+         throw new IllegalStateException("duplicate repository " + repositoryKey);
+      
+      this.repositories.put(repositoryKey, repository);
+   }
+   
+   /**
+    * UnInCallback to unregister a repository bean.
+    * 
+    * @param repository the deploymentRepository to unregister
+    */
+   public void unregisterDeploymentRepository(AbstractDeploymentRepository repository)
+   {
+      if(repository == null)
+         throw new IllegalArgumentException("null deployment repository");
+      ProfileKey repositoryKey = repository.getProfileKey(); 
+      if(repositoryKey == null)
+         throw new IllegalArgumentException("null profile key");
+      
+      this.unregisterDeploymentRepository(repositoryKey);
+   }
+   
+   public void unregisterDeploymentRepository(ProfileKey repositoryKey)
+   {
+      if(repositoryKey == null)
+         throw new IllegalArgumentException("null profile key");
+      this.repositories.remove(repositoryKey);
+   }
+   
 }

Modified: trunk/system/src/main/java/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java
===================================================================
--- trunk/system/src/main/java/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java	2009-12-01 17:01:16 UTC (rev 97250)
+++ trunk/system/src/main/java/org/jboss/system/tools/ProfileServiceDeploymentRepositoryAdapter.java	2009-12-01 17:05:53 UTC (rev 97251)
@@ -21,6 +21,7 @@
  */
 package org.jboss.system.tools;
 
+import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -42,6 +43,8 @@
 import org.jboss.profileservice.spi.ProfileService;
 import org.jboss.system.server.profileservice.hotdeploy.Scanner;
 import org.jboss.system.server.profileservice.repository.HotDeploymentRepository;
+import org.jboss.system.server.profileservice.repository.TypedProfileRepository;
+import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
 
 /**
@@ -57,6 +60,7 @@
 
    private Scanner scanner;
    private ProfileService ps;
+   private TypedProfileRepository repositories;
    private StructureModificationChecker checker;
 
    private DeploymentScannerProfile profile;
@@ -74,6 +78,16 @@
       this.ps = ps;
       this.checker = checker;
    }
+   
+   public TypedProfileRepository getProfileRepository()
+   {
+      return repositories;
+   }
+   
+   public void setProfileRepository(TypedProfileRepository repositories)
+   {
+      this.repositories = repositories;
+   }
 
    /**
     * Create profile.
@@ -112,6 +126,9 @@
       log.debug("Activating deployment scanner profile " + profileName);
       this.ps.activateProfile(profileName);
       this.ps.validateProfile(profileName);
+      // Expose the profile to the DeploymentManager
+      if(this.repositories != null)
+         this.repositories.registerDeploymentRepository(profile);
    }
 
    public void resume()
@@ -129,6 +146,9 @@
     */
    public void stopProfile()
    {
+      // Unregister the profile
+      if(this.repositories != null)
+         this.repositories.unregisterDeploymentRepository(profile);
       try
       {
          // Deactivate
@@ -259,7 +279,7 @@
 
          return super.getModifiedDeployments();
       }
-
+      
       @Override
       protected void checkForAdditions(List<ModificationInfo> modified) throws Exception
       {
@@ -314,6 +334,49 @@
          newCache.put(applicationDir, files);
       }
 
+      @Override
+      protected List<String> findDeploymentContent(String name)
+      {
+         // FIXME this should not be done here
+         // Try to find the VirtualFile, as we only add real file urls
+         VirtualFile cached = getCachedVirtualFile(name);
+         if(cached != null)
+         {
+            try {
+               name = cached.toURI().toString();
+            } catch(Exception ignore) { }
+            return Collections.singletonList(name);
+         }
+         
+         List<String> contents = new ArrayList<String>();
+         for(URI uri : this.uris)
+         {
+            String cacheName = uri.toString(); 
+            String fixedName = cacheName;
+            if(cacheName.endsWith("/"))
+               fixedName = cacheName.substring(0, cacheName.length() -1);
+            
+            if(fixedName.endsWith(name))
+            {
+               VirtualFile vf = getCachedVirtualFile(cacheName);
+               if(vf != null)
+               {
+                  try {
+                     contents.add(vf.toURI().toString()); 
+                  } catch(Exception ignore) { }                  
+               }
+            }
+         }
+         return contents;
+      }
+      
+      @Override
+      public ProfileDeployment removeDeployment(String vfsPath) throws Exception
+      {
+         // We don't remove the actual deployment content
+         return super.removeDeployment(vfsPath, false);
+      }
+      
       public ProfileKey getKey()
       {
          return profileName;

Added: trunk/testsuite/src/main/org/jboss/test/deployers/test/LegacyDeploymentScannerUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/deployers/test/LegacyDeploymentScannerUnitTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/deployers/test/LegacyDeploymentScannerUnitTestCase.java	2009-12-01 17:05:53 UTC (rev 97251)
@@ -0,0 +1,160 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.deployers.test;
+
+import java.net.URL;
+
+import javax.management.ObjectName;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.profileservice.spi.NoSuchDeploymentException;
+import org.jboss.profileservice.spi.ProfileKey;
+
+/**
+ * Test the JBossTools legacy DeploymentScanner usage.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class LegacyDeploymentScannerUnitTestCase extends AbstractDeployTestBase
+{
+
+   /** The deployment scanner MBean name. */
+   private static final String DEPLOYMENT_SCANNER_MBEAN = "jboss.deployment:flavor=URL,type=DeploymentScanner";
+   
+   /** The scanner profile. */
+   private static final ProfileKey scannerProfile = new ProfileKey("deployment-scanner-profile");
+   
+   public static Test suite() throws Exception
+   {
+      TestSuite suite = new TestSuite();
+      
+      suite.addTest(new LegacyDeploymentScannerUnitTestCase("testDeploy"));
+      suite.addTest(new LegacyDeploymentScannerUnitTestCase("testlistDeployedURLs"));      
+      suite.addTest(new LegacyDeploymentScannerUnitTestCase("testDeploymentMgrRedeploy"));     
+      suite.addTest(new LegacyDeploymentScannerUnitTestCase("testUndeploy"));
+      
+      return suite;
+   }
+   
+   public LegacyDeploymentScannerUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testDeploy() throws Exception
+   {
+      final ObjectName scanner = new ObjectName(DEPLOYMENT_SCANNER_MBEAN);      
+
+      // The deployment
+      URL deployment = getDeployURL(EMTPY_DEPLOYMENT);
+      assertNotNull(EMTPY_DEPLOYMENT, deployment);
+      
+      // Suspend
+      invoke(scanner, "stop" , new Object[0], new String[0]);
+      try
+      {
+         // Add the deployment
+         invoke(scanner, "addURL", new Object[] { deployment }, new String[] { URL.class.getName() });
+      }
+      finally
+      {
+         // Resume
+         invoke(scanner, "start" , new Object[0], new String[0]);
+      }
+      
+      // Wait for HDScanner
+      Thread.sleep(8000);
+      
+      ManagedDeployment managedDeployment = getManagementView().getDeployment(EMTPY_DEPLOYMENT);
+      assertNotNull(managedDeployment);
+
+   }
+   
+   public void testUndeploy() throws Exception
+   {
+      final ObjectName scanner = new ObjectName(DEPLOYMENT_SCANNER_MBEAN); 
+
+      // The deployment
+      URL deployment = getDeployURL(EMTPY_DEPLOYMENT);
+      assertNotNull(EMTPY_DEPLOYMENT, deployment);
+      
+      // Suspend
+      invoke(scanner, "stop" , new Object[0], new String[0]);
+      try
+      {
+         // Add the deployment
+         invoke(scanner, "removeURL", new Object[] { deployment }, new String[] { URL.class.getName() });
+      }
+      finally
+      {
+         // Resume
+         invoke(scanner, "start" , new Object[0], new String[0]);
+      }
+      
+      // Wait for HDScanner
+      Thread.sleep(8000);
+      
+      try
+      {
+         ManagedDeployment managedDeployment = getManagementView().getDeployment(EMTPY_DEPLOYMENT);
+         fail("deployment not undeployed " + managedDeployment);
+      }
+      catch(NoSuchDeploymentException ok)
+      {
+         log.debug("saw NoSuchDeploymentException");
+      }
+   }
+   
+   public void testlistDeployedURLs() throws Exception
+   {
+      final ObjectName scanner = new ObjectName(DEPLOYMENT_SCANNER_MBEAN);
+      
+      String[] deployments = (String[]) invoke(scanner, "listDeployedURLs", new Object[0], new String[0]);
+      
+      assertNotNull(deployments);
+      assertTrue(deployments.length > 1);
+   }
+
+   public void testDeploymentMgrRedeploy() throws Exception
+   {
+      // Test redeploy using deploymentManager
+      DeploymentManager deployMgr = getDeploymentManager();
+      deployMgr.loadProfile(scannerProfile);
+      try
+      {
+         redeployCheckComplete(EMTPY_DEPLOYMENT);
+      }
+      finally
+      {
+         deployMgr.releaseProfile();
+      }      
+   }
+   
+}
+
+
+




More information about the jboss-cvs-commits mailing list