[jboss-cvs] JBossAS SVN: r81888 - trunk/system/src/main/org/jboss/system/server/profileservice/repository.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Dec 1 06:07:03 EST 2008
Author: emuckenhuber
Date: 2008-12-01 06:07:01 -0500 (Mon, 01 Dec 2008)
New Revision: 81888
Modified:
trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java
trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java
Log:
[JBAS-6037] use simpleName + a hash for storing the attachment
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java 2008-12-01 11:05:13 UTC (rev 81887)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java 2008-12-01 11:07:01 UTC (rev 81888)
@@ -23,7 +23,12 @@
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
+import java.util.Formatter;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -112,41 +117,13 @@
}
/**
- * Get a directory for deployment phase.
- *
- * @param phase
- * @return
- */
- protected abstract File getPhaseDir(DeploymentPhase phase);
-
- /**
- * Get a the directory path for a given DeploymentPhase.
- *
- * @param phase the deploymentPhase
- * @return the phase directory for the attachmentStore
- */
- protected String getPhaseDirPath(DeploymentPhase phase)
- {
- File file = getPhaseDir(phase);
- if(file == null)
- {
- return "";
- }
- else
- {
- // return deployers/, deploy/
- return file.getName() + File.separator;
- }
- }
-
- /**
* Create a VFSDeployment with predetermined managed object.
*
* @param file the deployment root.
* @param phase the deployment phase
* @return the VFSDeployment
*/
- protected VFSDeployment loadDeploymentData(VirtualFile file, DeploymentPhase phase)
+ protected VFSDeployment loadDeploymentData(VirtualFile file, DeploymentPhase phase) throws Exception
{
if(file == null)
throw new IllegalArgumentException("Cannot create a deployment for a null file.");
@@ -157,8 +134,9 @@
if(trace)
log.trace("Created deployment: " + deployment);
- // attachments/deploy/deployment/
- String deploymentPath = getPhaseDirPath(phase) + deployment.getSimpleName() + File.separator;
+ // simpleName + hash
+ String deploymentPath = createRelativeDeploymentPath(deployment);
+
if(trace)
log.trace("trying to load attachment from relative path: " + deploymentPath);
@@ -167,15 +145,17 @@
if(attachmentMetaData == null)
{
- if(trace)
- log.trace("Did not find any presisted metadata for deployment: " + deployment);
+ log.debug("No persisted attachment found for deployment " + deployment + " with relative path: "+ deploymentPath);
return deployment;
}
+ log.debug("Persisted attachment found for deployment " + deployment + " with relative path: "+ deploymentPath);
+
try
{
// If the deployment has changes we skip restoring the persisted metadata.
// TODO delete attachments ?
+ // TODO check metadata locations
if(attachPredeterminedObject(file, attachmentMetaData) == false)
{
log.debug("Not using the persisted metadata, as the deployment was modified.");
@@ -236,8 +216,8 @@
boolean trace = log.isTraceEnabled();
- // attachments/deploy/deployment/
- String deploymentPath = getPhaseDirPath(phase) + deployment.getSimpleName() + File.separator;
+ // simpleName + hash
+ String deploymentPath = createRelativeDeploymentPath(deployment);
RepositoryAttachmentMetaData savedMetaData = loadAttachmentMetaData(deploymentPath);
// Get parent deployment
@@ -537,6 +517,25 @@
}
/**
+ * Create the relative path to the persisted deployment attachment meta data.
+ * The string is simpleName + "-" + hash (based on the URI of the deployment)
+ *
+ * @param deployment the deployment
+ * @return the relative name
+ * @throws Exception
+ */
+ protected String createRelativeDeploymentPath(VFSDeployment deployment) throws Exception
+ {
+ if(deployment == null)
+ throw new IllegalStateException("Null deployment.");
+
+ String hash = HashGenerator.createHash(deployment);
+ // simple name + "-" + hash
+ return deployment.getSimpleName() + "-" + hash + File.separator;
+
+ }
+
+ /**
* Create a predetermined managedObject attachment.
*
* @param deploymentPath the relative deployment path
@@ -567,7 +566,7 @@
*/
protected RepositoryAttachmentMetaData loadAttachmentMetaData(String relativeDeploymentPath)
{
- // attachments/deploy/deployment/metadata.xml
+ // attachments/simpleName - hash/metadata.xml
String fixedMetadataPath = getMetaDataPathName(relativeDeploymentPath);
try
@@ -641,4 +640,64 @@
return name;
}
+ private static class HashGenerator
+ {
+ /** The digest. */
+ private static MessageDigest digest;
+
+ /**
+ * Create a hash based on a deployment vfs path name.
+ *
+ * @param deployment the deployment
+ * @return a hash
+ * @throws NoSuchAlgorithmException
+ * @throws MalformedURLException
+ * @throws URISyntaxException
+ */
+ public static String createHash(VFSDeployment deployment)
+ throws NoSuchAlgorithmException, MalformedURLException, URISyntaxException
+ {
+ // deployment URI toString
+ String pathName = deployment.getRoot().toURI().toString();
+ // buffer
+ StringBuffer buffer = new StringBuffer();
+ // formatter
+ Formatter f = new Formatter(buffer);
+ // get the bytez
+ byte[] bytez = internalCreateHash(pathName);
+ for(byte b : bytez)
+ {
+ // format the byte
+ f.format("%02x", b);
+ }
+ // toString
+ return f.toString();
+ }
+
+ protected static byte[] internalCreateHash(String pathName) throws NoSuchAlgorithmException
+ {
+ MessageDigest digest = getDigest();
+ try
+ {
+ // update
+ digest.update(pathName.getBytes());
+ // return
+ return digest.digest();
+ }
+ finally
+ {
+ // reset
+ digest.reset();
+ }
+ }
+
+ public static MessageDigest getDigest() throws NoSuchAlgorithmException
+ {
+ if(digest == null)
+ digest = MessageDigest.getInstance("MD5");
+
+ return digest;
+ }
+ }
+
}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java 2008-12-01 11:05:13 UTC (rev 81887)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java 2008-12-01 11:07:01 UTC (rev 81888)
@@ -1164,7 +1164,12 @@
}
/**
- * TODO Map<String, Object should not be required ?
+ * Update a deployment.
+ *
+ * @param d the deployment
+ * @param phase the deployment phase
+ * @param comp the managed component
+ * @throws Exception
*/
public void updateDeployment(VFSDeployment d, DeploymentPhase phase,
ManagedComponent comp) throws Exception
@@ -1173,7 +1178,7 @@
{
// update component
super.updateDeployment(d, phase, comp);
- // Update last moidfied
+ // Update last modified
this.lastModified = System.currentTimeMillis();
}
else
@@ -1181,5 +1186,17 @@
log.error("no metadata attached.");
}
}
+
+ protected VFSDeployment loadDeploymentData(VirtualFile file, DeploymentPhase phase)
+ {
+ try
+ {
+ return super.loadDeploymentData(file, phase);
+ }
+ catch(Exception e)
+ {
+ throw new RuntimeException("Could not load deployment data: "+ file, e);
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list