[jboss-cvs] JBossAS SVN: r84455 - in trunk: profileservice/src/main/org/jboss/profileservice/management/upload and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 19 08:20:08 EST 2009


Author: emuckenhuber
Date: 2009-02-19 08:20:07 -0500 (Thu, 19 Feb 2009)
New Revision: 84455

Added:
   trunk/profileservice/src/main/org/jboss/profileservice/management/upload/AbstractDeploymentManager.java
   trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/AbstractDeployHandler.java
Modified:
   trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
   trunk/profileservice/src/main/org/jboss/profileservice/management/upload/DeploymentManagerImpl.java
   trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/DeployHandler.java
   trunk/profileservice/src/resources/profileservice-jboss-beans.xml
   trunk/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java
   trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverrideHandler.java
   trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractDeploymentRepository.java
   trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileService.java
   trunk/system/src/main/org/jboss/system/server/profileservice/repository/MutableDeploymentRepository.java
   trunk/testsuite/src/main/org/jboss/test/deployers/AbstractDeploymentTest.java
   trunk/testsuite/src/main/org/jboss/test/profileservice/test/AbstractProfileServiceTest.java
   trunk/testsuite/src/main/org/jboss/test/profileservice/test/SecurityManagedObjectsTestCase.java
Log:
[JBAS-6525] symmetric usage of DeploymentManager 

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2009-02-19 13:05:44 UTC (rev 84454)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java	2009-02-19 13:20:07 UTC (rev 84455)
@@ -112,7 +112,11 @@
    private ProfileService ps;
    /** The currently loaded profile */
    private Profile activeProfile;
-   private long activeProfileLastModified;
+   /** The last modified profiles */
+   private Map<ProfileKey, Long> lastModified = new HashMap<ProfileKey, Long>();
+   
+   private volatile boolean forceReload;
+   
    /** The MainDeployer used to process profile changes */
    private MainDeployer mainDeployer;
 
@@ -177,7 +181,7 @@
       if(activeProfile != null)
       {
          if(activeProfile.getKey().equals(key) == false)
-            this.activeProfileLastModified = 0;
+            this.forceReload = true;
       }
       
       // If the profile is not modified do nothing
@@ -186,7 +190,8 @@
          log.debug("Not reloading profiles");
          return;
       }
-
+      this.forceReload = false;
+      
       try
       {
          activeProfile = ps.getActiveProfile(key);
@@ -204,6 +209,7 @@
       this.moRegistry.clear();
       this.runtimeMOs.clear();
       this.unresolvedRefs.clear();
+      this.lastModified.clear();
 
       // Process the deployments
       boolean trace = log.isTraceEnabled();
@@ -229,12 +235,13 @@
    
    public void reloadProfile() throws Exception
    {
-      activeProfileLastModified = 0;
+      forceReload = true;
       loadProfile(activeProfile.getKey());
    }
    
    protected void loadProfiles(boolean trace)
    {
+      log.debug("reloading profiles: "+ this.ps.getActiveProfileKeys());
       for(ProfileKey key : this.ps.getActiveProfileKeys())
       {
          try
@@ -253,9 +260,7 @@
                   log.debug("Failed to create ManagedDeployment for: " + deployment.getName(), e);
                }
             }
-            long lastModified = profile.getLastModified();
-            if(activeProfileLastModified < lastModified)
-               this.activeProfileLastModified = lastModified;            
+            this.lastModified.put(key, profile.getLastModified());
          }
          catch(Exception e)
          {
@@ -266,21 +271,28 @@
    
    protected boolean reload()
    {
-      boolean reload = false;
+      if(forceReload == true)
+      {
+         forceReload = false;
+         return true;
+      }
+      
       if(activeProfile == null)
          return true;
+      
       for(ProfileKey key : this.ps.getActiveProfileKeys())
       {
          try
          {
             Profile profile = this.ps.getActiveProfile(key);
-            long lastModified = profile.getLastModified();
-            if(lastModified > this.activeProfileLastModified)
+            long lastModified = this.lastModified.get(key);
+            log.debug("reload: "+ key + " cached: " + lastModified + " new " + profile.getLastModified());
+            if(profile.getLastModified() > lastModified)
                return true;
          }
          catch(Exception ignore) { /** . */ }
       }
-      return reload;
+      return false;
    }
 
    /**
@@ -685,15 +697,18 @@
       log.debug("removeTemplate: "+template);
    }
 
+
    /**
+    * Get the managed deployment.
     * 
-    * @param key
-    * @param name
-    * @return
+    * @param name the deployment name
+    * @throws NoSuchDeploymentException if no matching deployment was found
     */
-   public ManagedDeployment getDeployment(String name, DeploymentPhase phase) throws NoSuchDeploymentException,
-         Exception
+   public ManagedDeployment getDeployment(String name, DeploymentPhase phase) throws NoSuchDeploymentException
    {
+      if(name == null)
+         throw new IllegalArgumentException("Null deployment name");
+      
       // Resolve internally.
       ManagedDeployment md = this.managedDeployments.get(name);
       if (md == null)
@@ -702,13 +717,22 @@
          md = this.bootstrapManagedDeployments.get(name);
       }
       
-      // Let the DeploymentRepository try to resolve the deployment (simpleName)
+      // Check the file name
       if(md == null)
       {
-         ProfileDeployment ctx = activeProfile.getDeployment(name);
-         md = this.managedDeployments.get(ctx.getName());
+         for(String deployment : this.managedDeployments.keySet())
+         {
+            String fixedDeploymentName = deployment;
+            if(deployment.endsWith("/"))
+               fixedDeploymentName = deployment.substring(0, deployment.length() - 1);
+
+            if(fixedDeploymentName.endsWith(name))
+            {
+               md = this.managedDeployments.get(deployment);
+               break;
+            }
+         }  
       }
-      
       // Do not return null
       if (md == null)
          throw new NoSuchDeploymentException("Managed deployment: " + name + " not found.");
@@ -1004,7 +1028,7 @@
    {
       mainDeployer.process();
       mainDeployer.checkComplete();
-      activeProfileLastModified = 0;
+      forceReload = true;
    }
 
    /**
@@ -1021,7 +1045,6 @@
          md = md.getParent();
          
       String name = md.getName();
-      DeploymentPhase phase = md.getDeploymentPhase();
       ProfileDeployment compDeployment = activeProfile.getDeployment(name);
       if( compDeployment == null )
       {
@@ -1033,7 +1056,7 @@
 
       // Apply the managed properties to the server ManagedDeployment/ManagedComponent
       ManagedDeployment compMD = managedDeployments.get(md.getName());
-      log.debug("updateComponent, profile="+activeProfile+", deploymentName="+name+", phase="+phase+", :"+compMD);
+      log.debug("updateComponent, profile="+activeProfile+", deploymentName="+name+": "+compMD);
       
       ManagedComponent serverComp = null;
       // Find the managed component again

Added: trunk/profileservice/src/main/org/jboss/profileservice/management/upload/AbstractDeploymentManager.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/upload/AbstractDeploymentManager.java	                        (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/upload/AbstractDeploymentManager.java	2009-02-19 13:20:07 UTC (rev 84455)
@@ -0,0 +1,163 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.profileservice.management.upload;
+
+import java.util.ArrayList;
+
+import org.jboss.logging.Logger;
+import org.jboss.profileservice.spi.Profile;
+import org.jboss.profileservice.spi.ProfileFactory;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.ProfileService;
+import org.jboss.profileservice.spi.metadata.ProfileMetaData;
+import org.jboss.system.server.profile.repository.metadata.BasicProfileMetaData;
+import org.jboss.system.server.profile.repository.metadata.ImmutableProfileSourceMetaData;
+
+/**
+ * The AbstractDeploymentManager maintains a profile for transient deployments.
+ * Transient deployments are copyContent = false, therefore they are not
+ * getting deployed again after AS is restarted.
+ * The aim of the transient profile is to expose those deployments to the
+ * ManagementView.
+ * 
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public abstract class AbstractDeploymentManager
+{
+   /** The transient profile name. */
+   public static final String TRANSIENT_PROFILE_NAME = "transient-deployment-profile";
+   
+   /** The transient profile key. */
+   public static final ProfileKey TRANSIENT_PROFILE_KEY = new ProfileKey(TRANSIENT_PROFILE_NAME);
+   
+   /** The profile factory. */
+   private ProfileFactory profileFactory;
+   
+   /** The profile service. */
+   protected ProfileService ps;
+   
+   /** The logger. */
+   private static final Logger log = Logger.getLogger(AbstractDeploymentManager.class);
+   
+   public ProfileService getProfileService()
+   {
+      return this.ps;
+   }
+   
+   public void setProfileService(ProfileService ps)
+   {
+      this.ps = ps;
+   }
+   
+   public ProfileFactory getProfileFactory()
+   {
+      return profileFactory;
+   }
+   
+   public void setProfileFactory(ProfileFactory profileFactory)
+   {
+      this.profileFactory = profileFactory;
+   }
+
+   /**
+    * Start registers and activates the transient deployments profile
+    * 
+    * @throws Exception for any error
+    */
+   public void start() throws Exception
+   {
+      if(this.ps == null)
+         throw new IllegalStateException("Null profile service.");
+      if(this.profileFactory == null)
+         throw new IllegalStateException("Null profile factory.");
+      
+      // Create the transient deployment profile
+      Profile profile = createTransientProfile();
+      // Register
+      this.ps.registerProfile(profile);
+      // Activate
+      {
+         log.debug("activating transient profile " + TRANSIENT_PROFILE_NAME);
+         this.ps.activateProfile(TRANSIENT_PROFILE_KEY);
+      }
+   }
+   
+   /**
+    * Stop deactivates and unregisteres the transient deployments profile.
+    */
+   public void stop()
+   {
+      try
+      {
+         // Deactivate
+         log.debug("deactivating transient profile: " + TRANSIENT_PROFILE_NAME);
+         this.ps.deactivateProfile(TRANSIENT_PROFILE_KEY);
+      }
+      catch(Exception e)
+      {
+         log.debug("Failed to deactivate transient profile: ", e);
+      }
+      try
+      {
+         // Unregister
+         log.debug("unregistering transient profile: " + TRANSIENT_PROFILE_NAME);
+         this.ps.unregisterProfile(TRANSIENT_PROFILE_KEY);
+      }
+      catch(Exception e)
+      {
+         log.debug("Failed to unregister transient profile: ", e);
+      }
+   }
+   
+   /**
+    * Create the transient profile.
+    * 
+    * @return the transient profile
+    * @throws Exception for any error
+    */
+   protected Profile createTransientProfile() throws Exception
+   {
+      ProfileMetaData metaData = createTransientProfileMetaData();
+      return profileFactory.createProfile(TRANSIENT_PROFILE_KEY, metaData);
+   }
+   
+   /**
+    * Create the transient profile meta data.
+    * 
+    * @return the transient profile meta data
+    */
+   @SuppressWarnings("deprecation")
+   protected ProfileMetaData createTransientProfileMetaData()
+   {
+      // Source
+      ImmutableProfileSourceMetaData source = new ImmutableProfileSourceMetaData();
+      source.setSources(new ArrayList<String>());
+      // Profile
+      BasicProfileMetaData profile = new BasicProfileMetaData();
+      profile.setSource(source);
+      profile.setName(TRANSIENT_PROFILE_NAME);
+      //
+      return profile;
+   }
+   
+}

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/upload/DeploymentManagerImpl.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/upload/DeploymentManagerImpl.java	2009-02-19 13:05:44 UTC (rev 84454)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/upload/DeploymentManagerImpl.java	2009-02-19 13:20:07 UTC (rev 84455)
@@ -41,32 +41,43 @@
 import org.jboss.profileservice.spi.Profile;
 import org.jboss.profileservice.spi.ProfileKey;
 import org.jboss.profileservice.spi.ProfileRepository;
-import org.jboss.profileservice.spi.ProfileService;
 import org.jboss.remoting.InvokerLocator;
 
 /**
- * The remoting base DeploymentManager implementation
+ * The remoting base DeploymentManager implementation.
+ * 
  * @author Scott.Stark at jboss.org
  * @version $Revision$
  */
-public class DeploymentManagerImpl implements DeploymentManager
+public class DeploymentManagerImpl extends AbstractDeploymentManager implements DeploymentManager
 {
+   /** The logger. */
    private static Logger log = Logger.getLogger(DeploymentManagerImpl.class);
+   
+   /** The bundle name. */
    private static final String BUNDLE_NAME = "org.jboss.profileservice.management.upload.messages"; //$NON-NLS-1$
-   /** */
-   private ProfileService ps;
+
    /** The currently loaded profile */
    private Profile activeProfile;
+
+   /** The profile repository. */
    private ProfileRepository profileRepository;
+   /** The remoting deploy handler. */
    private DeployHandler deployHandler;
+   
+   /** The transient deployment repository */
+   private DeploymentRepository transientDeploymentRepository;
 
-   /** */
+   /** The resource bundle. */
    private ResourceBundle i18n;
-   /** */
+   /** The current locale. */
    private Locale currentLocale;
-   /** */
+   /** The message formatter. */
    private MessageFormat formatter = new MessageFormat("");
+   
+   /** The invoker locator. */
    private InvokerLocator locator;
+   /** The remoting subSystem. */
    private String remotingSubsystem = "DeploymentManager";
 
    public DeploymentManagerImpl()
@@ -76,15 +87,6 @@
       i18n = ResourceBundle.getBundle(BUNDLE_NAME, currentLocale);
    }
 
-   public ProfileService getProfileService()
-   {
-      return ps;
-   }
-   public void setProfileService(ProfileService ps)
-   {
-      this.ps = ps;
-   }
-
    public ProfileRepository getProfileRepository()
    {
       return profileRepository;
@@ -120,7 +122,27 @@
    {
       this.remotingSubsystem = remotingSubsystem;
    }
+   
+   @Override
+   public void start() throws Exception
+   {
+      // Start the transient profile
+      super.start();
+      
+      // Get the transient deployment repository
+      this.transientDeploymentRepository = profileRepository.getProfileDeploymentRepository(TRANSIENT_PROFILE_KEY);
+      if(this.transientDeploymentRepository == null)
+         throw new IllegalStateException("Could not obtain the deployment repository for transient deployments.");
+   }
 
+   @Override
+   public void stop()
+   {
+      this.transientDeploymentRepository = null;
+      // Stop the transient profile
+      super.stop();
+   }
+
    public DeploymentProgress distribute(String name, DeploymentPhase phase, URL contentURL)
       throws Exception
    {
@@ -130,6 +152,11 @@
    public DeploymentProgress distribute(String name, DeploymentPhase phase, URL contentURL, boolean copyContent)
       throws Exception
    {
+      if(name == null)
+         throw new IllegalArgumentException("Null name.");
+      if(contentURL == null)
+         throw new IllegalArgumentException("Null content url.");
+      
       if(activeProfile == null)
       {
          formatter.applyPattern(i18n.getString("DeploymentManager.NoProfileLoadedException")); //$NON-NLS-1$
@@ -169,10 +196,12 @@
       }
       log.debug("Loading profile, key: "+key+", allowHotDeployments: "+allowHotDeployments);
       activeProfile.enableModifiedDeploymentChecks(allowHotDeployments);
+      
       // Set the deployment repository on the handler
       DeploymentRepository repository = profileRepository.getProfileDeploymentRepository(key);
       log.debug("DeploymentRepository for profile: "+repository);
       deployHandler.setDeploymentRepository(repository);
+      deployHandler.setTransientDeploymentRepository(transientDeploymentRepository);
    }
 
    public void releaseProfile(ProfileKey key, boolean allowHotDeployments)
@@ -188,12 +217,20 @@
       }
       log.debug("Releasing profile, key: "+key);
       activeProfile.enableModifiedDeploymentChecks(allowHotDeployments);
+      
+      // Unset deployment repositories
       deployHandler.setDeploymentRepository(null);
+      deployHandler.setTransientDeploymentRepository(null);
    }
 
    public DeploymentProgress redeploy(String name, DeploymentPhase phase, URL contentURL)
       throws Exception
    {
+      if(name == null)
+         throw new IllegalArgumentException("Null name.");
+      if(contentURL == null)
+         throw new IllegalArgumentException("Null contentURL.");
+      
       if(activeProfile == null)
       {
          formatter.applyPattern(i18n.getString("DeploymentManager.NoProfileLoadedException")); //$NON-NLS-1$
@@ -214,16 +251,25 @@
 
    public DeploymentProgress start(DeploymentPhase phase, String... names) throws Exception
    {
+      if(names == null)
+         throw new IllegalArgumentException("Null names.");
+      
       return doProgress(CommandType.START, phase, names);
    }
 
    public DeploymentProgress stop(DeploymentPhase phase, String... names) throws Exception
    {
+      if(names == null)
+         throw new IllegalArgumentException("Null names.");
+      
       return doProgress(CommandType.STOP, phase, names);
    }
 
    public DeploymentProgress undeploy(DeploymentPhase phase, String... names) throws Exception
    {
+      if(names == null)
+         throw new IllegalArgumentException("Null names.");
+      
       return doProgress(CommandType.UNDEPLOY, phase, names);
    }
 

Added: trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/AbstractDeployHandler.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/AbstractDeployHandler.java	                        (rev 0)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/AbstractDeployHandler.java	2009-02-19 13:20:07 UTC (rev 84455)
@@ -0,0 +1,324 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.profileservice.management.upload.remoting;
+
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+
+import org.jboss.aop.joinpoint.Invocation;
+import org.jboss.aop.joinpoint.InvocationResponse;
+import org.jboss.aspects.remoting.AOPRemotingInvocationHandler;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.management.deploy.DeploymentID;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ManagedDeployment.DeploymentPhase;
+import org.jboss.profileservice.management.upload.SerializableDeploymentID;
+import org.jboss.profileservice.spi.DeploymentRepository;
+import org.jboss.profileservice.spi.ProfileDeployment;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.ServerInvoker;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
+import org.jboss.remoting.stream.StreamInvocationHandler;
+import org.jboss.system.server.profileservice.repository.DefaultProfileDeploymentFactory;
+import org.jboss.system.server.profileservice.repository.MainDeployerAdapter;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * A remoting StreamInvocationHandler installed as the profile service subsystem
+ * handler and used by the StreamingDeploymentTarget implementation.
+ * 
+ * @author Scott.Stark at jboss.org
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public abstract class AbstractDeployHandler extends AOPRemotingInvocationHandler
+   implements StreamInvocationHandler
+{
+
+   /** The profile deployment repository. */
+   private DeploymentRepository deploymentRepository;
+   
+   /** The deployer. */
+   private MainDeployerAdapter deployer;
+
+   /** The deployment factory */
+   private static final DefaultProfileDeploymentFactory deploymentFactory = DefaultProfileDeploymentFactory.getInstance();
+   
+   /** The logger. */
+   protected static final Logger log = Logger.getLogger(DeployHandler.class);
+   
+   public DeploymentRepository getDeploymentRepository()
+   {
+      return deploymentRepository;
+   }
+   
+   public void setDeploymentRepository(DeploymentRepository deploymentRepository)
+   {
+      this.deploymentRepository = deploymentRepository;
+   }
+   
+   public MainDeployerAdapter getDeployer()
+   {
+      return deployer;
+   }
+   
+   public void setDeployer(MainDeployerAdapter deployer)
+   {
+      this.deployer = deployer;
+   }
+   
+   protected String[] getRepositoryNames(String[] names) throws Exception
+   {
+      if(names == null || names.length == 0)
+         return new String[0];
+      // TODO
+      // return this.deploymentRepository.getRepositoryNames(names);
+      return names;
+   }
+   
+   public void addListener(InvokerCallbackHandler arg0)
+   {
+   }
+   
+   public void removeListener(InvokerCallbackHandler arg0)
+   {
+   }
+
+   public void setInvoker(ServerInvoker arg0)
+   {
+   }
+
+   public void setMBeanServer(MBeanServer arg0)
+   {
+   }
+   
+   /**
+    * Handle a DeploymentManager invocation other than distribute
+    * 
+    * @param request - the remoting invocation
+    * @return the result of the invocation
+    */
+   public Object invoke(InvocationRequest request) throws Throwable
+   {
+      Object parameter = request.getParameter();
+      Object returnValue = null;
+
+      if(parameter instanceof Invocation)
+      {
+         returnValue = super.invoke(request);
+      }
+      else
+      {
+         Map payload = request.getRequestPayload();
+         DeploymentID dtID = (DeploymentID) payload.get("DeploymentTargetID");
+         log.debug("invoke, payload: "+payload+", parameter: "+parameter);
+         if( parameter.equals("getRepositoryNames"))
+         {
+            String[] names = (String[]) payload.get("names");
+            returnValue = getRepositoryNames(names);
+         }
+         else if( parameter.equals("distribute") )
+         {
+            returnValue = distribute(dtID);
+         }
+         else if( parameter.equals("start") )
+         {
+            start(dtID);
+         }
+         else if( parameter.equals("stop") )
+         {
+            stop(dtID);
+         }
+         else if( parameter.equals("remove"))
+         {
+            remove(dtID);
+         }
+         // Keep for backward compatibility
+         else if( parameter.equals("undeploy") )
+         {
+            remove(dtID);
+         }
+      }
+      return returnValue;
+   }
+
+   protected abstract String[] distribute(DeploymentID dtID) throws Exception;
+   
+   /**
+    * Handle a DeploymentManager distribute invocation for copyContent == true
+    * 
+    * @see DeploymentManager#distribute(String, DeploymentPhase, java.net.URL)
+    * @param request - the remoting invocation
+    */
+   public Object handleStream(InputStream contentIS, InvocationRequest request) throws Throwable
+   {
+      SerializableDeploymentID deploymentTarget = (SerializableDeploymentID) request.getParameter();
+      log.info("Handle stream, deploymentTarget: " + deploymentTarget);
+      deploymentTarget.setContentIS(contentIS);
+      String[] names = deploymentTarget.getNames();
+      String repositoryName = deploymentRepository.addDeploymentContent(names[0], contentIS);
+      log.info("End handle stream, repositoryName: " + repositoryName);
+      String[] rnames = {repositoryName};
+      deploymentTarget.setRepositoryNames(rnames);
+      return new InvocationResponse(repositoryName);
+   }
+   
+   /**
+    * Start a deployment.
+    * 
+    * @param dtID the deployment id
+    * @throws Exception for any error
+    */
+   protected void start(DeploymentID dtID) throws Exception
+   {
+      String[] names = dtID.getNames();
+      DeploymentPhase phase = dtID.getPhase();
+      log.info("Begin start, "+Arrays.asList(names) + ", phase: " + phase);
+      
+      for(String name : names)
+      {
+         // Schedule start for the deployment
+         scheduleStart(name);
+      }
+      // CheckComplete
+      processCheckComplete();
+      log.info("End start, "+Arrays.asList(names));
+   }
+
+   protected void scheduleStart(String name) throws Exception
+   {
+      VirtualFile vf = this.deploymentRepository.getDeploymentContent(name);
+      scheduleStart(vf, this.deploymentRepository);
+   }
+   
+   protected void scheduleStart(VirtualFile vf, DeploymentRepository repository) throws Exception
+   {
+      // Create profile deployment
+      ProfileDeployment profileDeployment = createDeployment(vf);
+      // Add deployment to profile
+      repository.addDeployment(profileDeployment.getName(), profileDeployment);
+      // Add deployment 
+      deployer.addDeployment(profileDeployment);
+      // Unlock the contents
+      repository.unlockDeploymentContent(vf.getPathName());
+      
+      log.debug("Scheduling start for: "+ profileDeployment);
+   }
+   
+   /**
+    * Stop the deployments.
+    * 
+    * @param dtID the deployment id
+    * @throws Exception for any error
+    */
+   protected void stop(DeploymentID dtID) throws Exception
+   {
+      String[] names = dtID.getNames();
+      log.info("Stop, "+Arrays.asList(names));
+      
+      for(String name : names)
+      {
+         // Schedule stop
+         scheduleStop(name);
+      }
+      // CheckComplete
+      processCheckComplete();
+   }
+   
+   protected void scheduleStop(String name) throws Exception
+   {
+      scheduleStop(name, this.deploymentRepository);
+   }
+   
+   protected void scheduleStop(String name, DeploymentRepository repository) throws Exception
+   {
+      // Obtain the deployment
+      ProfileDeployment vfsd = repository.getDeployment(name);
+      // Lock the content to make it unavailable to the deployment scanner
+      String path = vfsd.getRoot().getPathName();
+      repository.lockDeploymentContent(path);
+      // Remove deployment
+      deployer.removeDeployment(vfsd);
+      
+      log.debug("Scheduling stop for: "+vfsd);
+   }
+   
+   /**
+    * Remove a deployment from the deployment repository.
+    * This will delete the file for non-transient deployments.
+    * 
+    * @param dtID the deployment id
+    * @throws Exception for any error
+    */
+   protected void remove(DeploymentID dtID) throws Exception
+   {
+      String[] names = dtID.getNames();
+      log.info("Remove, "+Arrays.asList(names));
+      for(String name : names)
+      {
+         // Remove from repository
+         removeDeployment(name);
+      }
+   }
+   
+   protected void removeDeployment(String name) throws Exception
+   {
+      removeDeployment(name, this.deploymentRepository);
+   }
+   
+   protected void removeDeployment(String name, DeploymentRepository repository) throws Exception
+   {
+      // Remove the deployment
+      ProfileDeployment deployment = repository.removeDeployment(name);
+      // Reset to an unlocked deployment
+      if(deployment != null)
+         repository.unlockDeploymentContent(deployment.getRoot().getPathName());
+      log.debug("Removed: "+name);
+   }
+   
+   protected void processCheckComplete() throws DeploymentException
+   {
+      // Process
+      deployer.process();
+      // And checkComplete
+      deployer.checkComplete();
+   }
+   
+   /**
+    * Create a profile deployment.
+    * 
+    * @param file the root file
+    * @return the deployment
+    */
+   protected ProfileDeployment createDeployment(VirtualFile file)
+   {
+      if (file == null)
+         throw new IllegalArgumentException("Null file");
+      
+      return deploymentFactory.createProfileDeployment(file);
+   }
+   
+}

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/DeployHandler.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/DeployHandler.java	2009-02-19 13:05:44 UTC (rev 84454)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/DeployHandler.java	2009-02-19 13:20:07 UTC (rev 84455)
@@ -22,267 +22,181 @@
 package org.jboss.profileservice.management.upload.remoting;
 
 import java.io.IOException;
-import java.io.InputStream;
+import java.net.URISyntaxException;
 import java.net.URL;
-import java.util.Arrays;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
-import javax.management.MBeanServer;
-
-import org.jboss.aop.joinpoint.Invocation;
-import org.jboss.aop.joinpoint.InvocationResponse;
-import org.jboss.aspects.remoting.AOPRemotingInvocationHandler;
 import org.jboss.deployers.spi.management.deploy.DeploymentID;
-import org.jboss.deployers.spi.management.deploy.DeploymentManager;
 import org.jboss.logging.Logger;
-import org.jboss.managed.api.ManagedDeployment.DeploymentPhase;
-import org.jboss.profileservice.management.upload.SerializableDeploymentID;
 import org.jboss.profileservice.spi.DeploymentRepository;
-import org.jboss.profileservice.spi.ProfileDeployment;
-import org.jboss.remoting.InvocationRequest;
-import org.jboss.remoting.ServerInvoker;
-import org.jboss.remoting.callback.InvokerCallbackHandler;
-import org.jboss.remoting.stream.StreamInvocationHandler;
-import org.jboss.system.server.profileservice.repository.DefaultProfileDeploymentFactory;
-import org.jboss.system.server.profileservice.repository.MainDeployerAdapter;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
 
 /**
- * A remoting StreamInvocationHandler installed as the profile service subsystem
- * handler and used by the StreamingDeploymentTarget implementation.
+ * A profile service deploy subsystem handling transient deployments. 
+ * The AbstractDeployHandler takes care of the profile deployments.
  *
  * @author Scott.Stark at jboss.org
  * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
  * @version $Revision$
  */
-public class DeployHandler extends AOPRemotingInvocationHandler
-   implements StreamInvocationHandler
+public class DeployHandler extends AbstractDeployHandler
 {
    /** The logger. */
    static final Logger log = Logger.getLogger(DeployHandler.class);
-   
-   /** The deployment repository. */
-   private DeploymentRepository deploymentRepository;
 
-   /** The deployer. */
-   private MainDeployerAdapter deployer;
-
-   /** The deployment factory */
-   private static final DefaultProfileDeploymentFactory deploymentFactory = DefaultProfileDeploymentFactory.getInstance();
-
-   public DeploymentRepository getDeploymentRepository()
+   /** The transient deployment repository. */
+   private DeploymentRepository transientDeploymentRepository;
+   
+   /** The transient deployments map. */
+   Map<String, VirtualFile> transientDeployments = new ConcurrentHashMap<String, VirtualFile>();
+   
+   public DeploymentRepository getTransientDeploymentRepository()
    {
-      return deploymentRepository;
+      return transientDeploymentRepository;
    }
-   public void setDeploymentRepository(DeploymentRepository deploymentRepository)
+   
+   public void setTransientDeploymentRepository(DeploymentRepository transientDeploymentRepository)
    {
-      log.debug("setDeploymentRepository, "+deploymentRepository);
-      this.deploymentRepository = deploymentRepository;
+      this.transientDeploymentRepository = transientDeploymentRepository;
    }
 
-   public MainDeployerAdapter getDeployer()
+   @Override
+   protected String[] getRepositoryNames(String[] names) throws Exception
    {
-      return deployer;
+      // get the transient repository names
+      List<String> repositoryNames = getTransientRepositoryNames(names);
+      
+      // Add the results from the profile deployment repository
+      for(String name : super.getRepositoryNames(names))
+         repositoryNames.add(name);
+      
+      return repositoryNames.toArray( new String[repositoryNames.size()] );
    }
-   public void setDeployer(MainDeployerAdapter deployer)
+   
+   protected List<String> getTransientRepositoryNames(String[] names)
    {
-      this.deployer = deployer;
-   }
-   /**
-    * Handle a DeploymentManager distribute invocation
-    * @see DeploymentManager#distribute(String, DeploymentPhase, java.net.URL)
-    * @param request - the remoting invocation
-    */
-   public Object handleStream(InputStream contentIS, InvocationRequest request) throws Throwable
-   {
-      SerializableDeploymentID deploymentTarget = (SerializableDeploymentID) request.getParameter();
-      log.info("Handle stream, deploymentTarget: " + deploymentTarget);
-      deploymentTarget.setContentIS(contentIS);
-      String[] names = deploymentTarget.getNames();
-      String repositoryName = deploymentRepository.addDeploymentContent(names[0], contentIS);
-      log.info("End handle stream, repositoryName: " + repositoryName);
-      String[] rnames = {repositoryName};
-      deploymentTarget.setRepositoryNames(rnames);
-      return new InvocationResponse(repositoryName);
-   }
-
-   public void addListener(InvokerCallbackHandler arg0)
-   {
-   }
-
-   /**
-    * Handle a DeploymentManager invocation other than distribute
-    * @param request - the remoting invocation
-    * @return the result of the invocation
-    */
-   public Object invoke(InvocationRequest request) throws Throwable
-   {
-      Object parameter = request.getParameter();
-      Object returnValue = null;
-
-      if(parameter instanceof Invocation)
+      List<String> repositoryNames = new ArrayList<String>();
+      for(String name : names)
       {
-         returnValue = super.invoke(request);
-      }
-      else
-      {
-         Map payload = request.getRequestPayload();
-         DeploymentID dtID = (DeploymentID) payload.get("DeploymentTargetID");
-         log.debug("invoke, payload: "+payload+", parameter: "+parameter);
-         if( parameter.equals("getRepositoryNames"))
+         if(this.transientDeployments.containsKey(name))
          {
-            String[] names = (String[]) payload.get("names");
-            DeploymentPhase phase = (DeploymentPhase) payload.get("phase");
-            returnValue = getRepositoryNames(names, phase);
+            repositoryNames.add(name);
+            continue;
          }
-         else if( parameter.equals("distribute") )
+         for(VirtualFile vf : this.transientDeployments.values())
          {
-            returnValue = distribute(dtID);
+            if(vf.getName().equals(name))
+            {
+               try
+               {
+                  repositoryNames.add(vf.toURI().toString());
+               }
+               catch(Exception ignored) { }
+            }
          }
-         else if( parameter.equals("start") )
-         {
-            start(dtID);
-         }
-         else if( parameter.equals("stop") )
-         {
-            stop(dtID);
-         }
-         else if( parameter.equals("undeploy") )
-         {
-            undeploy(dtID);
-         }
       }
-      return returnValue;
+      return repositoryNames;
    }
 
-   public void removeListener(InvokerCallbackHandler arg0)
+   /**
+    * Distribute a transient (copyContent == false) deployment. 
+    * 
+    * @param dtID the deployment id
+    * @return the name of the deployment
+    * @throws IOException
+    * @throws URISyntaxException 
+    */
+   @Override
+   protected String[] distribute(DeploymentID dtID) throws IOException, URISyntaxException 
    {
-   }
+      URL contentURL = dtID.getContentURL();
+      log.info("Begin distribute, content url: " + contentURL);
 
-   public void setInvoker(ServerInvoker arg0)
-   {
+      // Create the virtual file
+      VirtualFile vf = VFS.getRoot(contentURL);
+      String name = vf.toURI().toString();
+      this.transientDeployments.put(name, vf);        
+      
+      log.info("End distribute, " + name);
+      return new String[] { name };
    }
 
-   public void setMBeanServer(MBeanServer arg0)
+   @Override
+   protected void scheduleStart(String name) throws Exception
    {
-   }
-
-   protected String[] getRepositoryNames(String[] names, DeploymentPhase phase)
-      throws IOException
-   {
-      return names;
-   }
-
-   protected String[] distribute(DeploymentID dtID) throws Exception
-   {
-      URL contentURL = dtID.getContentURL();
-      DeploymentPhase phase = dtID.getPhase();
-      log.info("Begin distribute, content url: " + contentURL + ", phase: " + phase);
-      // Prevent hot deployment scans from seeing in transition deployments
-//      deploymentRepository.acquireDeploymentContentLock();
-      try
+      String deploymentName = resolveDeploymentName(name);
+      if(deploymentName != null)
       {
-         VirtualFile vf = VFS.getRoot(contentURL);
-         ProfileDeployment vfsd = createDeployment(vf);
-         deploymentRepository.addDeployment(vfsd.getName(), vfsd);
-         deployer.addDeployment(vfsd);
-         deployer.process();
-         deployer.checkComplete();         
-         String[] rnames = {vfsd.getName()};
-         log.info("End distribute, " + contentURL);
-         return rnames;
+         VirtualFile vf = this.transientDeployments.get(name);
+         super.scheduleStart(vf, this.transientDeploymentRepository);
       }
-      finally
+      else
       {
-//         deploymentRepository.releaseDeploymentContentLock();
+         super.scheduleStart(name);
       }
    }
-
-   protected void start(DeploymentID dtID) throws Exception
+   
+   @Override
+   protected void scheduleStop(String name) throws Exception
    {
-      String[] names = dtID.getNames();
-      DeploymentPhase phase = dtID.getPhase();
-      log.info("Begin start, "+Arrays.asList(names) + ", phase: " + phase);
-      // Prevent hot deployment scans from seeing in transition deployments
-//      deploymentRepository.acquireDeploymentContentLock();
-      try
+      String deploymentName = resolveDeploymentName(name);
+      if(deploymentName != null)
       {
-         for(String name : names)
-         {
-            VirtualFile vf = deploymentRepository.getDeploymentContent(name);
-            ProfileDeployment vfsd = createDeployment(vf);
-            deploymentRepository.addDeployment(vfsd.getName(), vfsd);
-            deploymentRepository.unlockDeploymentContent(vf.getPathName());
-            deployer.addDeployment(vfsd);
-            log.info("Scheduling start for: "+vfsd);
-         }
-         deployer.process();
-         deployer.checkComplete();
+         super.scheduleStop(name, this.transientDeploymentRepository);
       }
-      finally
+      else
       {
-//         deploymentRepository.releaseDeploymentContentLock();
+         super.scheduleStop(name);
       }
-      log.info("End start, "+Arrays.asList(names));
    }
-
-   protected void stop(DeploymentID dtID) throws Exception
+   
+   @Override
+   protected void removeDeployment(String name) throws Exception
    {
-      String[] names = dtID.getNames();
-      log.info("Stop, "+Arrays.asList(names));
-//      deploymentRepository.acquireDeploymentContentLock();
-      try
+      String deploymentName = resolveDeploymentName(name);
+      if(deploymentName != null)
       {
-         for(String name : names)
-         {
-            // Obtain the 
-            ProfileDeployment vfsd = deploymentRepository.getDeployment(name);
-            // Lock the content to make it unavailable to the deployment scanner
-            String path = vfsd.getRoot().getPathName();
-            deploymentRepository.lockDeploymentContent(path);
-            deployer.removeDeployment(vfsd);
-            log.info("Scheduling stop for: "+vfsd);
-         }
-         deployer.process();
-         deployer.checkComplete();
+         this.transientDeployments.remove(deploymentName);
+         super.removeDeployment(deploymentName, this.transientDeploymentRepository);
       }
-      finally
+      else
       {
-//         deploymentRepository.releaseDeploymentContentLock();
+         super.removeDeployment(name);
       }
    }
-
-   protected void undeploy(DeploymentID dtID) throws Exception
+   
+   /**
+    * Try to resolve the deployment name.
+    * 
+    * @param name the name
+    * @return the deployment name, null if there was no matching name
+    * @throws IllegalStateException if multiple matching names were found
+    */
+   protected String resolveDeploymentName(String name)
    {
-      String[] names = dtID.getNames();
-      log.info("Undeploy, "+Arrays.asList(names));
-//      deploymentRepository.acquireDeploymentContentLock();
-      try
+      String deploymentName = null;
+      if(this.transientDeployments.containsKey(name))
       {
-         for(String name : names)
+         deploymentName = name;
+      }
+      // Try to resolve the name
+      if(deploymentName == null)
+      {
+         List<String> names = getTransientRepositoryNames(new String[]{ name });
+         if(names.size() == 1)
          {
-            deploymentRepository.removeDeployment(name);
-            log.info("Undeployed: "+name);
+            deploymentName = names.get(0);
          }
+         else if(names.size() > 1)
+         {
+            throw new IllegalStateException("Multiple matching deployments found for name: "+ name + " available " + names);
+         }
       }
-      finally
-      {
-//         deploymentRepository.releaseDeploymentContentLock();
-      }
+      return deploymentName;
    }
-
-   /**
-    * Create a profile deployment.
-    * 
-    * @param file the root file
-    * @return the deployment
-    */
-   protected ProfileDeployment createDeployment(VirtualFile file)
-   {
-      if (file == null)
-         throw new IllegalArgumentException("Null file");
-      
-      return deploymentFactory.createProfileDeployment(file);
-   }
+   
 }

Modified: trunk/profileservice/src/resources/profileservice-jboss-beans.xml
===================================================================
--- trunk/profileservice/src/resources/profileservice-jboss-beans.xml	2009-02-19 13:05:44 UTC (rev 84454)
+++ trunk/profileservice/src/resources/profileservice-jboss-beans.xml	2009-02-19 13:20:07 UTC (rev 84455)
@@ -136,8 +136,9 @@
                 <null/>
             </parameter>
         </uninstall>
+        <property name="profileService"><inject bean="ProfileService"/></property>
+        <property name="profileFactory"><inject bean="ProfileFactory" /></property>
         <property name="profileRepository"><inject bean="ProfileRepositoryFactory" /></property>
-        <property name="profileService"><inject bean="ProfileService"/></property>
         <property name="deployHandler"><inject bean="DeploymentInvocationHandler"/></property>
         <property name="locator"><inject bean="ConnectorMBean" property="invokerLocator"/></property>
         <property name="remotingSubsystem">DeploymentManager</property>

Modified: trunk/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java	2009-02-19 13:05:44 UTC (rev 84454)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/ProfileServiceBootstrap.java	2009-02-19 13:20:07 UTC (rev 84455)
@@ -238,6 +238,7 @@
       }
       
       // Activate the root profile
+      log.info("Loading profile: " + this.profileKey);
       profileService.activateProfile(this.profileKey);
       
       try

Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverrideHandler.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverrideHandler.java	2009-02-19 13:05:44 UTC (rev 84454)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverrideHandler.java	2009-02-19 13:20:07 UTC (rev 84455)
@@ -436,7 +436,7 @@
          ManagedObject merged = updateManagedObject(originalMO , overrideMO, trace);
          return new GenericValueSupport(original.getMetaType(), merged);
       }
-      if(o == null && v == null) return new GenericValueSupport(original.getMetaType(), null);
+      if(o == null && v == null) return original;
       throw new RuntimeException("Cannot merge original: " + original + ", override: "+ override);
    }
 

Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractDeploymentRepository.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractDeploymentRepository.java	2009-02-19 13:05:44 UTC (rev 84454)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractDeploymentRepository.java	2009-02-19 13:20:07 UTC (rev 84455)
@@ -27,7 +27,6 @@
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -71,7 +70,7 @@
    private VirtualFileFilter deploymentFilter;
    
    /** The application phase deployment files keyed by VirtualFile URI string. */
-   private final Map<String, VirtualFile> applicationVFCache = new HashMap<String, VirtualFile>();
+   private final Map<String, VirtualFile> applicationVFCache = new ConcurrentHashMap<String, VirtualFile>();
    
    /** The attachmentStore. */
    private AttachmentStore attachmentStore;
@@ -139,6 +138,7 @@
       this.applicationCtxs.clear();
       this.applicationVFCache.clear();
       this.contentFlags.clear();
+      this.lastModified = 0;
    }
    
    public void addDeployment(String vfsPath, ProfileDeployment d) throws Exception
@@ -230,37 +230,25 @@
       if(vfsPath == null)
          throw new IllegalArgumentException("Null vfsPath");
       
-      boolean trace = log.isTraceEnabled();
       ProfileDeployment ctx = this.applicationCtxs.get(vfsPath);
-      // TODO should a lookup of the simple name really be done here ? 
       if(ctx == null)
       {
-         // Try to find the deployment based on the file name.
-         if(trace)
-            log.trace("Failed to find application for: "+ vfsPath +", trying to match filename.");
-         for(ProfileDeployment deployment : applicationCtxs.values())
+         List<String> names = findDeploymentName(vfsPath);
+         if(names.size() == 1)
          {
-            // Skip deployment with no vfs root.
-            if(deployment.getRoot() == null)
-               continue;
-            // Get the filename
-            String fileName = deployment.getRoot().getName(); 
-            if(trace)
-               log.trace("Checking: "+fileName);
-            if(fileName.equals(vfsPath))
-            {
-               if(trace)
-                  log.trace("Matched to simple name of deployment:"+deployment);
-               ctx = deployment;
-               break;
-            }
+            ctx = this.applicationCtxs.get(names.get(0));
          }
-         if(ctx == null)
+         else if(names.size() > 1)
          {
-            log.debug("Failed to find application for: "+vfsPath+", available: " + applicationCtxs.values());
-            throw new NoSuchDeploymentException(vfsPath);
+            log.debug("Multiple deployments found for: "+vfsPath+", available: " + names);
+            throw new NoSuchDeploymentException(vfsPath);            
          }
       }
+      if(ctx == null)
+      {
+         log.debug("Failed to find application for: "+vfsPath+", available: " + applicationCtxs.values());
+         throw new NoSuchDeploymentException(vfsPath);
+      }
       return ctx;
    }
 
@@ -283,40 +271,63 @@
    {
       if(name == null)
          throw new IllegalArgumentException("Null name");
-      for(URI uri : this.uris)
+      
+      // A deploy content needs to be added over addDeployContent
+      VirtualFile vf = this.applicationVFCache.get(name);
+      if(vf == null)
       {
-         VirtualFile root = getCachedVirtualFile(uri);
-         VirtualFile vf = root.getChild(name);
-         if(vf != null)
-            return vf;
+         for(String cacheName : this.applicationVFCache.keySet())
+         {
+            if(cacheName.endsWith(name))
+            {
+               vf = this.applicationVFCache.get(cacheName);
+               break;
+            }
+         }
       }
-      throw new FileNotFoundException("Failed to content in profile: "+ key + " filename: " + name);
+      if(vf == null)
+         throw new FileNotFoundException("Failed to find content in profile: "+ key + " filename: " + name);
+      
+      return vf;
    }
    
    public String[] getRepositoryNames(String[] names) throws IOException
    {
       if(names == null)
          throw new IllegalArgumentException("Null names[]");
+      
       Collection<String> tmp = new HashSet<String>();
-      for(URI uri : this.uris)
+      for(String name : names)
       {
-         VirtualFile root = getCachedVirtualFile(uri);
-         for(String name : names)
+         if(this.applicationCtxs.containsKey(name))
          {
-            VirtualFile vf = root.getChild(name);
-            try
-            {
-               String content = vf.toURI().toString();
-               tmp.add(content);
-            }
-            catch(URISyntaxException e)
-            {
-               log.error("Should not happen", e);
-            }
+            tmp.add(name);
          }
+         else
+         {
+            // Try to find the name
+            List<String> deploymentNames = findDeploymentName(name);
+            if(deploymentNames != null)
+               tmp.addAll(deploymentNames);  
+         }
       }
       return tmp.toArray(new String[tmp.size()]);
    }
+   
+   protected List<String> findDeploymentName(String name)
+   {
+      List<String> tmp = new ArrayList<String>();
+      for(ProfileDeployment d : this.applicationCtxs.values())
+      {
+         VirtualFile vf = d.getRoot();
+         if(vf != null)
+         {
+            if(vf.getName().equals(name))
+               tmp.add(d.getName());
+         }
+      }
+      return tmp;
+   }
 
    public int lockDeploymentContent(String vfsPath)
    {

Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileService.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileService.java	2009-02-19 13:05:44 UTC (rev 84454)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractProfileService.java	2009-02-19 13:20:07 UTC (rev 84455)
@@ -273,7 +273,7 @@
 
       try
       {
-         log.info("Activating profile: " + context.getProfile());
+         log.debug("Activating profile: " + context.getProfile());
          controller.change(context, ControllerState.INSTALLED);         
       }
       catch(Throwable t)
@@ -281,17 +281,27 @@
          throw new RuntimeException(t);
       }
       
+      // TODO let the caller validate  
       // Check if the profile was activated successfully 
       validate(context);
    }
    
+   public void validate(ProfileKey key) throws Exception
+   {
+      ProfileContext profile = this.registeredProfiles.get(key);
+      if(profile == null)
+         throw new NoSuchProfileException("No such profile registered: "+ key);
+      
+      validate(profile);
+   }
+   
    /**
     * Check if all dependencies are satisfied and the profile was installed successfully.
     * 
     * @param context the context to validate
     * @throws Exception
     */
-   public void validate(ControllerContext context) throws Exception
+   protected void validate(ControllerContext context) throws Exception
    {
       // 
       Set<String> errors = new HashSet<String>();

Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/MutableDeploymentRepository.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/MutableDeploymentRepository.java	2009-02-19 13:05:44 UTC (rev 84454)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/MutableDeploymentRepository.java	2009-02-19 13:20:07 UTC (rev 84455)
@@ -28,6 +28,7 @@
 import java.io.InputStream;
 import java.io.SyncFailedException;
 import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -37,9 +38,9 @@
 import org.jboss.deployers.vfs.spi.structure.modified.StructureModificationChecker;
 import org.jboss.profileservice.spi.DeploymentContentFlags;
 import org.jboss.profileservice.spi.ModificationInfo;
-import org.jboss.profileservice.spi.ModificationInfo.ModifyStatus;
 import org.jboss.profileservice.spi.ProfileDeployment;
 import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.ModificationInfo.ModifyStatus;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
 
@@ -133,9 +134,17 @@
                fos.write(tmp, 0, read);
             }
             fos.flush();
-            // Get the vfs uri for the content as the repository name
-            VirtualFile contentVF = VFS.getVirtualFile(contentRoot.toURI(), vfsPath);
-            repositoryName = contentVF.getName();
+            // Get the vfs uri and add the VFS uri to the cached VFS uris
+            VirtualFile contentVF = VFS.getRoot(contentFile.toURI());
+            try
+            {
+               contentVF = getCachedVirtualFile(contentVF.toURI());
+               repositoryName = contentVF.toURI().toString();
+            }
+            catch(URISyntaxException e)
+            {
+               throw new RuntimeException(e); // This should not happen anyway
+            }
          }
          finally
          {

Modified: trunk/testsuite/src/main/org/jboss/test/deployers/AbstractDeploymentTest.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/deployers/AbstractDeploymentTest.java	2009-02-19 13:05:44 UTC (rev 84454)
+++ trunk/testsuite/src/main/org/jboss/test/deployers/AbstractDeploymentTest.java	2009-02-19 13:20:07 UTC (rev 84455)
@@ -26,19 +26,23 @@
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+
 import javax.management.MBeanServerConnection;
 import javax.naming.InitialContext;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
+
 import org.jboss.deployers.spi.management.ManagementView;
 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.deploy.ProgressEvent;
 import org.jboss.deployers.spi.management.deploy.ProgressListener;
-import org.jboss.deployers.spi.management.deploy.ProgressEvent;
 import org.jboss.deployment.MainDeployerMBean;
 import org.jboss.logging.Logger;
 import org.jboss.managed.api.ManagedDeployment;
@@ -103,6 +107,8 @@
       return new JBossTestSetup(clazz, suite)
       {
          private DeploymentManager dm;
+         
+         Collection<String> deploymentNames = new HashSet<String>();
 
          protected DeploymentManager getDeploymentManager() throws Exception
          {
@@ -139,20 +145,20 @@
                   distribute.run();
                   checkProgress(distribute);
 
-                  if (copyContent)
-                  {
-                     DeploymentProgress start = getDeploymentManager().start(ManagedDeployment.DeploymentPhase.APPLICATION, name);
-                     start.run();
-                     checkProgress(start);
-                  }
+                  deploymentNames.addAll(Arrays.asList(distribute.getDeploymentID().getRepositoryNames()));
+               }
+               
+               DeploymentProgress start = getDeploymentManager().start(ManagedDeployment.DeploymentPhase.APPLICATION, deploymentNames.toArray(new String[ deploymentNames.size()]));
+               start.run();
+               checkProgress(start);
 
-                  staticLog.info("Deployed package: " + name);
-               }
+               staticLog.info("Deployed package: " + deploymentNames);
             }
             catch (Exception ex)
             {
                // Throw this in testServerFound() instead.
                deploymentException = ex;
+               staticLog.error("Caught exception when trying to deploy : " + jarNames, ex);
             }
          }
 
@@ -161,18 +167,16 @@
             if (jarNames == null)
                return;
 
-            String[] names = jarNames.split(",");
-
-            DeploymentProgress stop = getDeploymentManager().stop(ManagedDeployment.DeploymentPhase.APPLICATION, names);
+            DeploymentProgress stop = getDeploymentManager().stop(ManagedDeployment.DeploymentPhase.APPLICATION, deploymentNames.toArray(new String[ deploymentNames.size()]));
             stop.run();
             checkProgress(stop);
 
-            if (copyContent)
-            {
-               DeploymentProgress undeploy = getDeploymentManager().undeploy(ManagedDeployment.DeploymentPhase.APPLICATION, names);
-               undeploy.run();
-               checkProgress(undeploy);
-            }
+            DeploymentProgress undeploy = getDeploymentManager().undeploy(ManagedDeployment.DeploymentPhase.APPLICATION, deploymentNames.toArray(new String[ deploymentNames.size()]));
+            undeploy.run();
+            checkProgress(undeploy);
+
+            // Clear names
+            this.deploymentNames.clear();
             
             // no secure handling
 
@@ -210,10 +214,10 @@
       {
          deployDir = "output/lib";
       }
-      String url = deployDir + "/" + filename;
-      staticLog.debug("Testing file: " + url);
+      File deployFile = new File(deployDir);
+      staticLog.debug("Testing file: " + deployFile);
       // try to canonicalize the strings a bit.
-      File file = new File(url);
+      File file = new File(deployFile, filename);
       if (file.exists())
       {
          staticLog.debug(file.getAbsolutePath() + " is a valid file");
@@ -221,8 +225,8 @@
       }
       else
       {
-         staticLog.debug("File does not exist, creating url: " + url);
-         return new URL(url);
+         staticLog.debug("File does not exist, creating url: " + deployFile);
+         return new URL(deployFile.toURL(), filename);
       }
    }
 

Modified: trunk/testsuite/src/main/org/jboss/test/profileservice/test/AbstractProfileServiceTest.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/test/AbstractProfileServiceTest.java	2009-02-19 13:05:44 UTC (rev 84454)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/test/AbstractProfileServiceTest.java	2009-02-19 13:20:07 UTC (rev 84455)
@@ -155,7 +155,7 @@
          InitialContext ctx = getInitialContext();
          ProfileService ps = (ProfileService) ctx.lookup("ProfileService");
          deployMgr = ps.getDeploymentManager();
-         deployMgr.loadProfile(getProfileKey(), false);
+         deployMgr.loadProfile(getProfileKey(), true);
          // Init the VFS to setup the vfs* protocol handlers
          VFS.init();
       }

Modified: trunk/testsuite/src/main/org/jboss/test/profileservice/test/SecurityManagedObjectsTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/test/SecurityManagedObjectsTestCase.java	2009-02-19 13:05:44 UTC (rev 84454)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/test/SecurityManagedObjectsTestCase.java	2009-02-19 13:20:07 UTC (rev 84455)
@@ -47,7 +47,7 @@
  * 
  * @author Scott.Stark at jboss.org
  * @author <a href="mailto:sguilhen at redhat.com">Stefan Guilhen</a>
- * @version $Revision:$
+ * @version $Revision$
  */
 public class SecurityManagedObjectsTestCase extends AbstractProfileServiceTest
 {
@@ -305,6 +305,8 @@
 
       // validate the managed deployment.
       ManagementView managementView = getManagementView();
+      managementView.reloadProfile();
+      
       ManagedDeployment deployment = managementView.getDeployment(domainsDeployment, DeploymentPhase.APPLICATION);
       assertNotNull(deployment);
       // verify the deployment contains the expected managed components.
@@ -422,13 +424,25 @@
       DeploymentProgress progress = manager.distribute(resourceName, DeploymentPhase.APPLICATION, contentURL, true);
       progress.addProgressListener(this.listener);
       progress.run();
+      
+      assertDeployed(progress);
 
       // start the deployment.
       String[] uploadedNames = progress.getDeploymentID().getRepositoryNames();
       progress = manager.start(DeploymentPhase.APPLICATION, uploadedNames);
       progress.addProgressListener(this.listener);
       progress.run();
+      
+      assertDeployed(progress);
    }
+   
+   private void assertDeployed(DeploymentProgress progress)
+   {
+      if(progress.getDeploymentStatus().isFailed())
+      {
+         fail("deployment failed: " + progress.getDeploymentStatus().getFailure());
+      }      
+   }
 
    /**
     * <p>




More information about the jboss-cvs-commits mailing list