[jboss-cvs] JBossAS SVN: r101799 - in trunk: system/src/main/java/org/jboss/system/server/profileservice/repository/clustered and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 3 23:48:19 EST 2010
Author: bstansberry at jboss.com
Date: 2010-03-03 23:48:18 -0500 (Wed, 03 Mar 2010)
New Revision: 101799
Modified:
trunk/cluster/src/main/java/org/jboss/profileservice/cluster/repository/DefaultRepositoryClusteringHandler.java
trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/ClusteredDeploymentRepository.java
trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/RepositoryClusteringHandler.java
trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/AbstractLocalContentManager.java
trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/LocalContentManager.java
trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/file/FileUtil.java
trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/file/FilesystemLocalContentManager.java
Log:
[JBAS-7781] Update ClusteredDeploymentRepository to deal with VFS3
Modified: trunk/cluster/src/main/java/org/jboss/profileservice/cluster/repository/DefaultRepositoryClusteringHandler.java
===================================================================
--- trunk/cluster/src/main/java/org/jboss/profileservice/cluster/repository/DefaultRepositoryClusteringHandler.java 2010-03-04 04:34:08 UTC (rev 101798)
+++ trunk/cluster/src/main/java/org/jboss/profileservice/cluster/repository/DefaultRepositoryClusteringHandler.java 2010-03-04 04:48:18 UTC (rev 101799)
@@ -56,7 +56,6 @@
import org.jboss.system.server.profileservice.repository.clustered.sync.SynchronizationReadAction;
import org.jboss.system.server.profileservice.repository.clustered.sync.SynchronizationRemoteAction;
import org.jboss.system.server.profileservice.repository.clustered.sync.SynchronizationWriteAction;
-import org.jboss.vfs.VirtualFile;
/**
* {@link RepositoryClusteringHandler} implementation that uses {@link HAPartition}.
@@ -357,9 +356,9 @@
return rrmd.getItemMetadata(item.getRelativePathElements());
}
- public void removeDeploymentContent(VirtualFile vf) throws Exception
+ public void removeDeploymentContent(String repositoryRoot, String relativePath) throws Exception
{
- RepositoryContentMetadata updated = this.contentManager.getContentMetadataForRemove(vf);
+ RepositoryContentMetadata updated = this.contentManager.getContentMetadataForRemove(repositoryRoot, relativePath);
RepositoryContentMetadata official = this.contentManager.getOfficialContentMetadata();
LocalContentModificationGenerator generator = new LocalContentModificationGenerator();
List<ContentModification> modifications;
Modified: trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/ClusteredDeploymentRepository.java
===================================================================
--- trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/ClusteredDeploymentRepository.java 2010-03-04 04:34:08 UTC (rev 101798)
+++ trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/ClusteredDeploymentRepository.java 2010-03-04 04:48:18 UTC (rev 101799)
@@ -209,11 +209,32 @@
"is capable of handling URIs " + namedURIMap.values() +
" -- registeredFactories are " + localContentManagerFactories);
}
+
+ this.localContentManager.initialize();
}
this.created = true;
}
+
+
+ @Override
+ public void destroy()
+ {
+ try
+ {
+ super.destroy();
+ }
+ finally
+ {
+ if (this.localContentManager != null)
+ {
+ this.localContentManager.shutdown();
+ }
+ }
+
+ }
+
public void load() throws Exception
{
if (!created)
@@ -354,9 +375,30 @@
try
{
ProfileDeployment deployment = getDeployment(vfsPath);
- VirtualFile root = deployment.getRoot();
- this.clusteringHandler.removeDeploymentContent(root);
- return super.removeDeployment(deployment.getName());
+ if (deployment != null)
+ {
+ VirtualFile vf = VFS.getChild(vfsPath);
+ for (Map.Entry<String, URI> entry : namedURIMap.entrySet())
+ {
+ String relativePath = null;
+ VirtualFile root = VFS.getChild(entry.getValue());
+ try
+ {
+ relativePath = vf.getPathNameRelativeTo(root);
+ }
+ catch (IllegalArgumentException notParent)
+ {
+ continue;
+ }
+ this.clusteringHandler.removeDeploymentContent(entry.getKey(), relativePath);
+ }
+
+ return super.removeDeployment(deployment.getName());
+ }
+ else
+ {
+ return null;
+ }
}
finally
{
@@ -479,6 +521,10 @@
public void remove() throws Exception
{
this.clusteringHandler = null;
+ if (this.localContentManager != null)
+ {
+ this.localContentManager.shutdown();
+ }
this.localContentManager = null;
this.created = false;
}
Modified: trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/RepositoryClusteringHandler.java
===================================================================
--- trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/RepositoryClusteringHandler.java 2010-03-04 04:34:08 UTC (rev 101798)
+++ trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/RepositoryClusteringHandler.java 2010-03-04 04:48:18 UTC (rev 101799)
@@ -30,7 +30,6 @@
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.vfs.VirtualFile;
/**
* Handles intra-cluster operations for a clustered DeploymentRepository.
@@ -161,5 +160,5 @@
*
* @throws Exception
*/
- void removeDeploymentContent(VirtualFile vf) throws Exception;
+ void removeDeploymentContent(String root, String relativePath) throws Exception;
}
Modified: trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/AbstractLocalContentManager.java
===================================================================
--- trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/AbstractLocalContentManager.java 2010-03-04 04:34:08 UTC (rev 101798)
+++ trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/AbstractLocalContentManager.java 2010-03-04 04:48:18 UTC (rev 101799)
@@ -22,6 +22,7 @@
package org.jboss.system.server.profileservice.repository.clustered.local;
+import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
@@ -64,6 +65,8 @@
private RepositoryContentMetadata currentContentMetadata;
private final Map<String, URI> namedURIMap;
private final Map<String, VirtualFile> vfCache = new ConcurrentHashMap<String, VirtualFile>();
+ /** The closeables. */
+ private Map<String, Closeable> mounts = new ConcurrentHashMap<String, Closeable>();
private final ProfileKey profileKey;
private final String storeName;
private final String localNodeName;
@@ -100,20 +103,20 @@
/**
* Create a new AbstractLocalContentManager.
*
- * @param namedURIMap Map of URIs managed by this object, keyed by a
+ * @param rootMap Map of URIs managed by this object, keyed by a
* String identifier
* @param profileKey key of the profile the content of which this
* object is managing
* @param localNodeName name of the local node in the cluster
* @param contentMetadataPersister object to use for storing/retrieving content metadata
*/
- protected AbstractLocalContentManager(Map<String, URI> namedURIMap,
+ protected AbstractLocalContentManager(Map<String, URI> rootMap,
ProfileKey profileKey, String localNodeName,
ContentMetadataPersister contentMetadataPersister)
{
- if (namedURIMap == null)
+ if (rootMap == null)
{
- throw new IllegalArgumentException("Null namedURIMap");
+ throw new IllegalArgumentException("Null rootMap");
}
if (profileKey == null)
{
@@ -128,7 +131,7 @@
throw new IllegalArgumentException("Null contentMetadataPersister");
}
- this.namedURIMap = namedURIMap;
+ this.namedURIMap = rootMap;
this.profileKey = profileKey;
this.storeName = createStoreName(profileKey);
this.localNodeName = localNodeName;
@@ -149,7 +152,39 @@
}
// ---------------------------------------------------- LocalContentManager
+
+ public void initialize()
+ {
+ String profileName = profileKey.getName();
+ VirtualFile backupRoot = VFS.getChild("/profileservice/originals/");
+
+ for (Map.Entry<String, URI> entry : namedURIMap.entrySet())
+ {
+ VirtualFile backup = backupRoot.getChild(profileName).getChild("roots").getChild(entry.getKey());
+ Closeable closeable = mountRepositoryRoot(entry.getValue(), backup);
+ vfCache.put(entry.getKey(), backup);
+ mounts.put(entry.getKey(), closeable);
+ }
+ }
+ public void shutdown()
+ {
+ for (Iterator<Map.Entry<String, Closeable>> it = mounts.entrySet().iterator(); it.hasNext();)
+ {
+ Map.Entry<String, Closeable> entry = it.next();
+ vfCache.remove(entry.getKey());
+ try
+ {
+ entry.getValue().close();
+ }
+ catch (IOException e)
+ {
+ log.error("Problem clearing repository root VFS mount for root " + entry.getKey(), e);
+ }
+ it.remove();
+ }
+ }
+
public RepositoryContentMetadata getOfficialContentMetadata()
{
return officialContentMetadata;
@@ -159,10 +194,10 @@
{
RepositoryContentMetadata md = new RepositoryContentMetadata(profileKey);
List<RepositoryRootMetadata> roots = new ArrayList<RepositoryRootMetadata>();
- for (Map.Entry<String, URI> entry : namedURIMap.entrySet())
+ for (String rootName : vfCache.keySet())
{
RepositoryRootMetadata rmd = new RepositoryRootMetadata();
- rmd.setName(entry.getKey());
+ rmd.setName(rootName);
roots.add(rmd);
}
md.setRepositories(roots);
@@ -176,13 +211,13 @@
RepositoryContentMetadata md = new RepositoryContentMetadata(profileKey);
List<RepositoryRootMetadata> roots = new ArrayList<RepositoryRootMetadata>();
RepositoryContentMetadata official = getOfficialContentMetadata();
- for (Map.Entry<String, URI> entry : namedURIMap.entrySet())
+ for (Map.Entry<String, VirtualFile> entry : vfCache.entrySet())
{
RepositoryRootMetadata rmd = new RepositoryRootMetadata();
rmd.setName(entry.getKey());
RepositoryRootMetadata existingRmd = official == null ? null : official.getRepositoryRootMetadata(entry.getKey());
- VirtualFile root = getCachedVirtualFile(entry.getValue());
+ VirtualFile root = entry.getValue();
if (isDirectory(root))
{
for(VirtualFile child: root.getChildren())
@@ -398,7 +433,8 @@
item.setRelativePath(vfsPath);
List<String> pathElements = item.getRelativePathElements();
String rootName = null;
- for (RepositoryRootMetadata rmd : getOfficialContentMetadata().getRepositories())
+ Collection<RepositoryRootMetadata> roots = getOfficialContentMetadata().getRepositories();
+ for (RepositoryRootMetadata rmd : roots)
{
if (rmd.getItemMetadata(pathElements) != null)
{
@@ -406,11 +442,15 @@
rootName = rmd.getName();
break;
}
- else if (rootName == null)
+ }
+
+ if (rootName == null)
+ {
+ // Use the first root that can accept children
+ for (RepositoryRootMetadata rmd : roots)
{
- // Use the first root that can accept children
- URI rootURI = namedURIMap.get(rmd.getName());
- VirtualFile vf = getCachedVirtualFile(rootURI);
+
+ VirtualFile vf = vfCache.get(rmd.getName());
if (isDirectory(vf))
{
rootName = rmd.getName();
@@ -459,8 +499,7 @@
public VirtualFile getVirtualFileForItem(RepositoryItemMetadata item) throws IOException
{
- URI uri = namedURIMap.get(item.getRootName());
- VirtualFile vf = getCachedVirtualFile(uri);
+ VirtualFile vf = vfCache.get(item.getRootName());
VirtualFile parent = null;
List<String> path = item.getRelativePathElements();
for (String element : path)
@@ -475,37 +514,21 @@
return vf;
}
- public RepositoryContentMetadata getContentMetadataForRemove(VirtualFile vf) throws IOException
+ public RepositoryContentMetadata getContentMetadataForRemove(String repositoryRoot, String relativePath) throws IOException
{
- List<String> path = null;
- RepositoryRootMetadata root = null;
RepositoryContentMetadata cmd = new RepositoryContentMetadata(getOfficialContentMetadata());
- for (RepositoryRootMetadata rmd : cmd.getRepositories())
- {
- URI uri = namedURIMap.get(rmd.getName());
- VirtualFile vfRoot = getCachedVirtualFile(uri);
- try
- {
- path = getRelativePath(vf, vfRoot);
- root = rmd;
- break;
- }
- catch (IllegalStateException ise)
- {
- // vf wasn't a child; ignore and move on to next root
- }
- }
+ RepositoryRootMetadata root = cmd.getRepositoryRootMetadata(repositoryRoot);
if (root == null)
{
- throw new IllegalArgumentException(vf + " is not a child of any known roots");
+ throw new IllegalArgumentException(repositoryRoot + " is not a child of any known roots");
}
- RepositoryItemMetadata remove = root.getItemMetadata(path);
+ RepositoryItemMetadata remove = root.getItemMetadata(RepositoryItemMetadata.getPathElements(relativePath));
if (remove != null)
{
Collection<RepositoryItemMetadata> items = root.getContent();
- if (isDirectory(vf))
+ if (remove.isDirectory())
{
for (Iterator<RepositoryItemMetadata> it = items.iterator(); it.hasNext(); )
{
@@ -524,7 +547,8 @@
// -------------------------------------------------------------- Protected
-
+ protected abstract Closeable mountRepositoryRoot(URI realURI, VirtualFile backup);
+
/**
* Create a {@link SynchronizationActionContext} for the given cluster-wide
* content synchronization.
@@ -683,24 +707,9 @@
return currentSynchronizationActionContext;
}
- /**
- * Gets a {@link VirtualFile} corresponding to the given URI.
- *
- * @param uri the uri. Cannot be <code>null</code>.
- * @return the virtual file
- *
- * @throws IOException
- * @throws NullPointerException if <code>uri</code> is <code>null</code>.
- */
- protected VirtualFile getCachedVirtualFile(URI uri) throws IOException
+ protected Map<String, VirtualFile> getRootVirtualFiles()
{
- VirtualFile vf = this.vfCache.get(uri.toString());
- if(vf == null)
- {
- vf = VFS.getChild(uri);
- this.vfCache.put(uri.toString(), vf);
- }
- return vf;
+ return Collections.unmodifiableMap(vfCache);
}
/**
@@ -715,9 +724,9 @@
*
* @see ContentModification#getRootName()
*/
- protected URI getRootURIForModification(ContentModification mod)
+ protected VirtualFile getRootVirtualFileForModification(ContentModification mod)
{
- return namedURIMap.get(mod.getRootName());
+ return vfCache.get(mod.getRootName());
}
// -------------------------------------------------------------- Private
Modified: trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/LocalContentManager.java
===================================================================
--- trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/LocalContentManager.java 2010-03-04 04:34:08 UTC (rev 101798)
+++ trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/LocalContentManager.java 2010-03-04 04:48:18 UTC (rev 101799)
@@ -198,5 +198,18 @@
*
* @throws IOException
*/
- RepositoryContentMetadata getContentMetadataForRemove(VirtualFile vf) throws IOException;
+ RepositoryContentMetadata getContentMetadataForRemove(String root, String relativePath) throws IOException;
+
+ /**
+ * Manager should prepare itself for operation.
+ *
+ * @param localContentManager object that handles repository content locally
+ */
+ void initialize() throws Exception;
+
+ /**
+ * Notification that manager can perform clean up work as it will not
+ * be asked to do further work.
+ */
+ void shutdown();
}
Modified: trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/file/FileUtil.java
===================================================================
--- trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/file/FileUtil.java 2010-03-04 04:34:08 UTC (rev 101798)
+++ trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/file/FileUtil.java 2010-03-04 04:48:18 UTC (rev 101799)
@@ -32,6 +32,7 @@
import org.jboss.logging.Logger;
import org.jboss.system.server.profileservice.repository.clustered.metadata.RepositoryItemMetadata;
+import org.jboss.vfs.VirtualFile;
/**
* Utility methods related to filesystem operations.
@@ -69,6 +70,16 @@
destination.setLastModified(modifiedTime);
}
+ /**
+ * No longer used; please post on dev forums or list if you need this.
+ *
+ * @param rootURI
+ * @param item
+ * @return
+ *
+ * @deprecated no longer used; please post on dev forums or list if you need this
+ */
+ @Deprecated
public static File getFileForItem(URI rootURI, RepositoryItemMetadata item)
{
File f = new File(rootURI);
@@ -79,6 +90,23 @@
return f;
}
+ public static File getFileForItem(VirtualFile rootVF, RepositoryItemMetadata item)
+ {
+ try
+ {
+ File f = rootVF.getPhysicalFile();
+ for (String element : item.getRelativePathElements())
+ {
+ f = new File(f, element);
+ }
+ return f;
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
public static File createTempFile(String tmpDirName, String partitionName) throws IOException
{
if (tmpDirName == null)
Modified: trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/file/FilesystemLocalContentManager.java
===================================================================
--- trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/file/FilesystemLocalContentManager.java 2010-03-04 04:34:08 UTC (rev 101798)
+++ trunk/system/src/main/java/org/jboss/system/server/profileservice/repository/clustered/local/file/FilesystemLocalContentManager.java 2010-03-04 04:48:18 UTC (rev 101799)
@@ -22,7 +22,9 @@
package org.jboss.system.server.profileservice.repository.clustered.local.file;
+import java.io.Closeable;
import java.io.File;
+import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Map;
@@ -38,6 +40,8 @@
import org.jboss.system.server.profileservice.repository.clustered.sync.SimpleSynchronizationRemoteAction;
import org.jboss.system.server.profileservice.repository.clustered.sync.SynchronizationId;
import org.jboss.system.server.profileservice.repository.clustered.sync.TwoPhaseCommitAction;
+import org.jboss.vfs.VFS;
+import org.jboss.vfs.VirtualFile;
/**
* {@link LocalContentManager} that persists to the local filesystem.
@@ -74,6 +78,19 @@
}
// -------------------------------------------------------------- Protected
+
+ protected Closeable mountRepositoryRoot(URI realURI, VirtualFile backup)
+ {
+ try
+ {
+ File realFile = new File(realURI);
+ return VFS.mountReal(realFile, backup);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException("Failed to mount file with URI " + realURI, e);
+ }
+ }
@Override
protected FileBasedSynchronizationActionContext createSynchronizationActionContext(
@@ -81,12 +98,12 @@
{
return new FileBasedSynchronizationActionContext(id, toUpdate, tmpDir, getStoreName());
}
-
+
@Override
protected TwoPhaseCommitAction<FileBasedSynchronizationActionContext> createPullFromClusterAction(
ContentModification mod, boolean localLed)
{
- File targetFile = FileUtil.getFileForItem(getRootURIForModification(mod), mod.getItem());
+ File targetFile = FileUtil.getFileForItem(getRootVirtualFileForModification(mod), mod.getItem());
if (localLed)
{
return new FileWriteAction(targetFile, getSynchronizationActionContext(), mod);
@@ -101,7 +118,7 @@
protected TwoPhaseCommitAction<FileBasedSynchronizationActionContext> createPushToClusterAction(ContentModification mod,
boolean localLed)
{
- File targetFile = FileUtil.getFileForItem(getRootURIForModification(mod), mod.getItem());
+ File targetFile = FileUtil.getFileForItem(getRootVirtualFileForModification(mod), mod.getItem());
if (localLed)
{
return new FileReadAction(targetFile, getSynchronizationActionContext(), mod);
@@ -116,7 +133,7 @@
@Override
protected TwoPhaseCommitAction<FileBasedSynchronizationActionContext> createPushStreamToClusterAction(ContentModification mod, InputStream stream)
{
- File targetFile = FileUtil.getFileForItem(getRootURIForModification(mod), mod.getItem());
+ File targetFile = FileUtil.getFileForItem(getRootVirtualFileForModification(mod), mod.getItem());
return new AddContentStreamAction(stream, targetFile, getSynchronizationActionContext(), mod);
}
@@ -126,7 +143,7 @@
{
if (localLed)
{
- File targetFile = FileUtil.getFileForItem(getRootURIForModification(mod), mod.getItem());
+ File targetFile = FileUtil.getFileForItem(getRootVirtualFileForModification(mod), mod.getItem());
return new RemoveFileAction(targetFile, getSynchronizationActionContext(),
mod);
}
@@ -147,7 +164,7 @@
}
else
{
- File targetFile = FileUtil.getFileForItem(getRootURIForModification(mod), mod.getItem());
+ File targetFile = FileUtil.getFileForItem(getRootVirtualFileForModification(mod), mod.getItem());
return new RemoveFileAction(targetFile, getSynchronizationActionContext(),
mod);
}
@@ -159,7 +176,7 @@
{
if (localLed)
{
- File targetFile = FileUtil.getFileForItem(getRootURIForModification(mod), mod.getItem());
+ File targetFile = FileUtil.getFileForItem(getRootVirtualFileForModification(mod), mod.getItem());
return new DirectoryTimestampUpdateAction(targetFile, getSynchronizationActionContext(),
mod);
}
@@ -175,7 +192,7 @@
{
if (localLed)
{
- File targetFile = FileUtil.getFileForItem(getRootURIForModification(mod), mod.getItem());
+ File targetFile = FileUtil.getFileForItem(getRootVirtualFileForModification(mod), mod.getItem());
return new MkDirAction(targetFile, getSynchronizationActionContext(),
mod);
}
@@ -195,7 +212,7 @@
}
else
{
- File targetFile = FileUtil.getFileForItem(getRootURIForModification(mod), mod.getItem());
+ File targetFile = FileUtil.getFileForItem(getRootVirtualFileForModification(mod), mod.getItem());
return new MkDirAction(targetFile, getSynchronizationActionContext(),
mod);
}
@@ -206,7 +223,7 @@
{
if (localLed)
{
- File targetFile = FileUtil.getFileForItem(getRootURIForModification(mod), mod.getItem());
+ File targetFile = FileUtil.getFileForItem(getRootVirtualFileForModification(mod), mod.getItem());
return new InitiateRmdirAction(targetFile, getSynchronizationActionContext(),
mod);
}
@@ -227,7 +244,7 @@
}
else
{
- File targetFile = FileUtil.getFileForItem(getRootURIForModification(mod), mod.getItem());
+ File targetFile = FileUtil.getFileForItem(getRootVirtualFileForModification(mod), mod.getItem());
return new InitiateRmdirAction(targetFile, getSynchronizationActionContext(),
mod);
}
More information about the jboss-cvs-commits
mailing list