[jboss-cvs] JBossAS SVN: r87694 - in branches/Branch_5_x: system/src/main/org/jboss/system/server/profileservice/repository/clustered and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Apr 22 18:42:34 EDT 2009


Author: bstansberry at jboss.com
Date: 2009-04-22 18:42:34 -0400 (Wed, 22 Apr 2009)
New Revision: 87694

Modified:
   branches/Branch_5_x/cluster/src/main/org/jboss/profileservice/cluster/repository/DefaultRepositoryClusteringHandler.java
   branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/clustered/ClusteredDeploymentRepository.java
   branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/clustered/RepositoryClusteringHandler.java
Log:
[JBAS-5552] Descend from HotDeploymentRepository

Modified: branches/Branch_5_x/cluster/src/main/org/jboss/profileservice/cluster/repository/DefaultRepositoryClusteringHandler.java
===================================================================
--- branches/Branch_5_x/cluster/src/main/org/jboss/profileservice/cluster/repository/DefaultRepositoryClusteringHandler.java	2009-04-22 22:08:49 UTC (rev 87693)
+++ branches/Branch_5_x/cluster/src/main/org/jboss/profileservice/cluster/repository/DefaultRepositoryClusteringHandler.java	2009-04-22 22:42:34 UTC (rev 87694)
@@ -42,6 +42,7 @@
 import org.jboss.system.server.profileservice.repository.clustered.local.LocalContentManager;
 import org.jboss.system.server.profileservice.repository.clustered.metadata.RepositoryContentMetadata;
 import org.jboss.system.server.profileservice.repository.clustered.metadata.RepositoryItemMetadata;
+import org.jboss.system.server.profileservice.repository.clustered.metadata.RepositoryRootMetadata;
 import org.jboss.system.server.profileservice.repository.clustered.sync.ByteChunk;
 import org.jboss.system.server.profileservice.repository.clustered.sync.ContentModification;
 import org.jboss.system.server.profileservice.repository.clustered.sync.ImmutableSynchronizationPolicy;
@@ -333,7 +334,7 @@
       return result;      
    }
 
-   public VirtualFile addDeploymentContent(String vfsPath, InputStream contentIS) throws IOException
+   public RepositoryItemMetadata addDeploymentContent(String vfsPath, InputStream contentIS) throws IOException
    {
       RepositoryItemMetadata item = this.contentManager.getItemForAddition(vfsPath);
       RepositoryContentMetadata updated = this.contentManager.getContentMetadataForAdd(item, contentIS);
@@ -351,7 +352,9 @@
       
       installModifications(modifications, updated);
       
-      return this.contentManager.getVirtualFileForItem(item);
+      official = this.contentManager.getOfficialContentMetadata();
+      RepositoryRootMetadata rrmd = official.getRepositoryRootMetadata(item.getRootName());
+      return rrmd.getItemMetadata(item.getRelativePathElements());
    }
 
    public void removeDeploymentContent(VirtualFile vf) throws Exception

Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/clustered/ClusteredDeploymentRepository.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/clustered/ClusteredDeploymentRepository.java	2009-04-22 22:08:49 UTC (rev 87693)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/clustered/ClusteredDeploymentRepository.java	2009-04-22 22:42:34 UTC (rev 87694)
@@ -30,32 +30,33 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import org.jboss.deployers.vfs.spi.structure.modified.StructureModificationChecker;
 import org.jboss.logging.Logger;
 import org.jboss.profileservice.spi.DeploymentContentFlags;
 import org.jboss.profileservice.spi.ModificationInfo;
 import org.jboss.profileservice.spi.ProfileDeployment;
 import org.jboss.profileservice.spi.ProfileKey;
-import org.jboss.profileservice.spi.ModificationInfo.ModifyStatus;
-import org.jboss.system.server.profileservice.repository.AbstractDeploymentRepository;
+import org.jboss.system.server.profileservice.repository.HotDeploymentRepository;
 import org.jboss.system.server.profileservice.repository.clustered.local.LocalContentManager;
 import org.jboss.system.server.profileservice.repository.clustered.local.LocalContentManagerFactory;
 import org.jboss.system.server.profileservice.repository.clustered.metadata.RepositoryContentMetadata;
+import org.jboss.system.server.profileservice.repository.clustered.metadata.RepositoryItemMetadata;
+import org.jboss.system.server.profileservice.repository.clustered.metadata.RepositoryRootMetadata;
 import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
 
 /**
+ * DeploymentRepository that keeps its contents in sync across a cluster.
+ * 
  * @author Brian Stansberry
  * 
  * @version $Revision: $
  */
-public class ClusteredDeploymentRepository 
-   extends AbstractDeploymentRepository
+public class ClusteredDeploymentRepository
+   extends HotDeploymentRepository
 {
    private enum LoadStatus { UNLOADED, LOADING, LOADED };
    
@@ -79,8 +80,6 @@
     */
    private volatile LoadStatus loadStatus = LoadStatus.UNLOADED;
    
-   /** The structure modification checker */
-   private StructureModificationChecker checker;
    private boolean created;
       
    /**
@@ -157,35 +156,18 @@
       return update;
    }
 
-   /**
-    * Get the structure modified checker.
-    *
-    * @return the checker
-    */
-   protected StructureModificationChecker getChecker()
-   {
-      if (checker == null)
-         throw new IllegalArgumentException("Checker must be set");
-
-      return checker;
-   }
-
-   /**
-    * Set the checker.
-    *
-    * @param checker the checker
-    */
-   public void setChecker(StructureModificationChecker checker)
-   {
-      this.checker = checker;
-   }
-
    // ---------------------------------------------------- DeploymentRepository
 
    /**
     * Extends superclass to check whether our configured URIs actually exist,
     * if so validating that a clustering handler has been injected, throwing
-    * an <code>IllegalStateException</code> if not.
+    * an <code>IllegalStateException</code> if not. This allows this
+    * repository to function as an empty repository in a non-clustered server 
+    * that doesn't have a RepositoryClusteringHandler, so long as the 
+    * configured URIs don't actually exist (e.g. AS "default" config w/o 
+    * a "farm/" dir). If the configured URIs *do* exist, that implies this
+    * repository is meant to work, and a missing clustering handler dependency
+    * is an exception condition.
     * 
     * {@inheritDoc}
     */
@@ -195,7 +177,7 @@
       super.create();
       
       // See if our URIs actually exist. If not we don't care
-      // if we are missing required dependencies
+      // if we are missing required dependencies. 
       boolean needToFunction = false;      
       for (URI uri : this.getRepositoryURIs())
       {
@@ -330,12 +312,21 @@
       }
       try
       {      
-         VirtualFile contentVF = this.clusteringHandler.addDeploymentContent(vfsPath, contentIS);
+         RepositoryContentMetadata existingRCMD = new RepositoryContentMetadata(this.localContentManager.getOfficialContentMetadata());         
+         RepositoryItemMetadata newRIMD = this.clusteringHandler.addDeploymentContent(vfsPath, contentIS);
+         RepositoryRootMetadata existingRRMD = existingRCMD.getRepositoryRootMetadata(newRIMD.getRootName());
+         boolean exists = existingRRMD != null && existingRRMD.getItemMetadata(newRIMD.getRelativePathElements()) != null;
+         VirtualFile root = getCachedVirtualFile(namedURIMap.get(newRIMD.getRootName()));
+         VirtualFile contentVF = root.getChild(newRIMD.getRelativePath());
 
          try
          {
-            contentVF = getCachedVirtualFile(contentVF.toURI());
-            repositoryName = contentVF.toURI().toString();
+            // Add the new virtual file to the cache
+            repositoryName = addVirtualFileCache(contentVF);
+            
+            // Cleanup 
+            if(exists)
+               cleanUpRoot(contentVF);
          }
          catch(URISyntaxException e)
          {
@@ -396,7 +387,7 @@
             // cluster. However, we might have had changes made to our
             // content (e.g. via addDeploymentContenxt(...)) that have not
             // been deployed. So, check for those...
-            return createModificationInfo();
+            return super.getModifiedDeployments();
          }
       }
       finally
@@ -419,7 +410,7 @@
          // pulling anything to cluster -- just push our changes
          latestContent = this.clusteringHandler.synchronizeContent(false);
          
-         return createModificationInfo();
+         return super.getModifiedDeployments();
       }
       finally
       {
@@ -478,7 +469,7 @@
    {      
       this.clusteringHandler = null;
       this.localContentManager = null; 
-      this.created = false;
+      this.created = false;     
    }
 
    // --------------------------------------  Legacy RepositoryContentPersister
@@ -750,88 +741,5 @@
       
       return map;
    }
-   
-   /**
-    * FIXME This was cut-and-pasted from MutableDeploymentRepository. Turn
-    * the guts of it into a static utility method somewhere.
-    * 
-    * @return
-    * @throws Exception
-    */
-   private Collection<ModificationInfo> createModificationInfo() throws Exception
-   {
-      boolean trace = log.isTraceEnabled();
-      ArrayList<ModificationInfo> modified = new ArrayList<ModificationInfo>();
-      Collection<ProfileDeployment> apps = getDeployments();
-      if (trace)
-         log.trace("Checking applications for modifications");
-      if (apps != null)
-      {
-         Iterator<ProfileDeployment> iter = apps.iterator();
-         while (iter.hasNext())
-         {
-            ProfileDeployment ctx = iter.next();
-            VirtualFile root = ctx.getRoot();
-            String pathName = root.getPathName();
-            // Ignore locked or disabled applications
-            if (this.hasDeploymentContentFlags(pathName, ignoreFlags))
-            {
-               if (trace)
-                  log.trace("Ignoring locked application: " + root);
-               continue;
-            }
-            // Check for removal
-            if (root.exists() == false)
-            {
-               long rootLastModified = root.getLastModified();
-               ModificationInfo info = new ModificationInfo(ctx, rootLastModified, ModifyStatus.REMOVED);
-               modified.add(info);
-               iter.remove();
-               // Remove last modified cache
-               getChecker().removeStructureRoot(root);
-               if (trace)
-                  log.trace(pathName + " was removed");
-            }
-            // Check for modification
-            else if (hasDeploymentContentFlags(pathName, DeploymentContentFlags.MODIFIED)
-                  || getChecker().hasStructureBeenModified(root))
-            {
-               long rootLastModified = root.getLastModified();
-               if (trace)
-                  log.trace(pathName + " was modified: " + rootLastModified);
-               // Create the modification info
-               ModificationInfo info = new ModificationInfo(ctx, rootLastModified, ModifyStatus.MODIFIED);
-               modified.add(info);
-            }
-         }
-         // Now check for additions
-         for (URI applicationDir : getRepositoryURIs())
-         {
-            VirtualFile deployDir = getCachedVirtualFile(applicationDir);
-            ArrayList<VirtualFile> added = new ArrayList<VirtualFile>();
-            addedDeployments(added, deployDir);
-            for (VirtualFile vf : added)
-            {
-               if (this.hasDeploymentContentFlags(vf.getPathName(), ignoreFlags))
-               {
-                  if (trace)
-                     log.trace("Ignoring locked application: " + vf);
-                  continue;
-               }
-               ProfileDeployment ctx = createDeployment(vf);
-               if (trace)
-                  log.trace(vf.getPathName() + " was added: " + vf.getLastModified());
-               ModificationInfo info = new ModificationInfo(ctx, vf.getLastModified(), ModifyStatus.ADDED);
-               modified.add(info);
-               addDeployment(ctx.getName(), ctx);
-               getChecker().addStructureRoot(vf);
-            }
-         }
-      }
 
-      if (modified.size() > 0)
-         updateLastModfied();
-      return modified;
-   }
-
 }

Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/clustered/RepositoryClusteringHandler.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/clustered/RepositoryClusteringHandler.java	2009-04-22 22:08:49 UTC (rev 87693)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/clustered/RepositoryClusteringHandler.java	2009-04-22 22:42:34 UTC (rev 87694)
@@ -28,30 +28,138 @@
 import org.jboss.profileservice.spi.ProfileKey;
 import org.jboss.system.server.profileservice.repository.clustered.local.LocalContentManager;
 import org.jboss.system.server.profileservice.repository.clustered.metadata.RepositoryContentMetadata;
+import org.jboss.system.server.profileservice.repository.clustered.metadata.RepositoryItemMetadata;
 import org.jboss.system.server.profileservice.repository.clustered.sync.InconsistentRepositoryStructureException;
 import org.jboss.virtual.VirtualFile;
 
 /**
+ * Handles intra-cluster operations for a clustered DeploymentRepository.
+ * 
  * @author Brian Stansberry
- *
+ * 
+ * @version $Revision: $
  */
 public interface RepositoryClusteringHandler
 {
+   /** Gets the key identifying the Profile this handler is meant for */
    ProfileKey getProfileKey();
+   /** Gets the name of the cluster partition this hander is associated with */
    String getPartitionName();
+   /** Gets the unique id for this node within the cluster partition */
    String getLocalNodeName();
    
+   /** 
+    * Gets whether this handler allows a node to push content changes to the
+    * cluster. If <code>true</code>, what changes will be accepted are an
+    * implementation detail.
+    * 
+    * @return <code>true</code> if content changes are <strong>not</strong> allowed; 
+    *         <code>false</code> otherwise
+    */
    boolean isImmutable();
+   
+   /** 
+    * Sets whether this handler allows a node to push content changes to the
+    * cluster. If <code>true</code>, what changes will be accepted are an
+    * implementation detail.
+    * 
+    * @param immutable <code>true</code> if content changes are <strong>not</strong> allowed; 
+    *         <code>false</code> otherwise
+    */
    void setImmutable(boolean immutable);
    
-   void initialize(LocalContentManager<?> persister) throws Exception;
+   /**
+    * Handler should prepare itself for operation.
+    * 
+    * @param localContentManager object that handles repository content locally
+    * 
+    * @throws Exception
+    */
+   void initialize(LocalContentManager<?> localContentManager) throws Exception;
+   
+   /**
+    * Notification that handler can perform clean up work as it will not 
+    * be asked to coordinate further with the cluster.
+    * 
+    * @throws Exception
+    */
    void shutdown() throws Exception;
+   
+   /**
+    * Acquire a cluster-wide lock for this repository. Must not be invoked
+    * if a {@link #lockLocally() local lock} is already held.
+    * 
+    * @return <code>true</code> if the lock was acquired, <code>false</code>
+    *         if not
+    */
    boolean lockGlobally();
+   
+   /**
+    * Acquire a local-only lock for this repository. Will not be granted if
+    * a node already owns a {@link #lockGlobally() cluster-wide lock}.
+    * 
+    * @return <code>true</code> if the lock was acquired, <code>false</code>
+    *         if not
+    */
    boolean lockLocally();
+   
+   /**
+    * Release a cluster-wide lock obtained in {@link #lockGlobally()}.
+    */
+   void unlockGlobally();
+   
+   /**
+    * Release a local lock obtained in {@link #lockLocally()}.
+    */
+   void unlockLocally();
+   
+   /**
+    * Synchronize this node's repository content with the rest of the cluster.
+    * This would typically involve a scan of repository content with any
+    * detected changes being propagated to the cluster.
+    * 
+    * @param pullFromCluster <code>true</code> if the synchronization should
+    *                        include pulling in changes from the cluster, e.g.
+    *                        as part of the startup of a node or during a merge
+    *                        following the healing of a cluster split;
+    *                        <code>false</code> if the synchronization should
+    *                        only consist of pushing local modifications to
+    *                        the cluster, e.g. as part of a hot deployment scan
+    *                        
+    * @return metadata describing the local repository content after the
+    *         synchronization
+    *         
+    * @throws InconsistentRepositoryStructureException 
+    * @throws IOException
+    */
    RepositoryContentMetadata synchronizeContent(boolean pullFromCluster) 
          throws InconsistentRepositoryStructureException, IOException;
-   VirtualFile addDeploymentContent(String vfsPath, InputStream contentIS) throws IOException;
+   
+   /**
+    * Read the content from the given input stream and add it to the repository
+    * across the cluster. This is used as part of processing of programmatic
+    * changes to the repository content, as opposed to asking the
+    * handler to deal with changes made manually.
+    * 
+    * @param vfsPath path describing where the content should be located in
+    *                the repository
+    * 
+    * @param contentIS input stream from which the content can be read
+    * 
+    * @return metadata describing the new content
+    * 
+    * @throws IOException
+    */
+   RepositoryItemMetadata addDeploymentContent(String vfsPath, InputStream contentIS) throws IOException;
+   
+   /**
+    * Remove content from the repository across the cluster. This is used as part of processing of programmatic
+    * changes to the repository content, as opposed to asking the
+    * handler to deal with changes made manually.
+    * 
+    * @param vf VirtualFile that contains the content
+    * 
+    * @throws Exception
+    */
    void removeDeploymentContent(VirtualFile vf) throws Exception;
-   void unlockGlobally();
-   void unlockLocally();
 }




More information about the jboss-cvs-commits mailing list