[jboss-cvs] JBossAS SVN: r81170 - in trunk: server/src/etc/conf/default and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Nov 17 11:36:44 EST 2008
Author: emuckenhuber
Date: 2008-11-17 11:36:44 -0500 (Mon, 17 Nov 2008)
New Revision: 81170
Added:
trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java
Modified:
trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
trunk/server/src/etc/conf/default/profile-repository.xml
trunk/system/src/main/org/jboss/profileservice/spi/repository/Requirement.java
trunk/system/src/main/org/jboss/system/server/profileservice/attachments/AttachmentMetaData.java
trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java
trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepositoryFactory.java
Log:
[JBAS-6037] move persistence metadata operations to a central place and do not override the meta data for already persisted attachments
Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java 2008-11-17 15:33:47 UTC (rev 81169)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java 2008-11-17 16:36:44 UTC (rev 81170)
@@ -44,20 +44,15 @@
import org.jboss.aspects.security.SecurityClientInterceptor;
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.client.spi.main.MainDeployer;
-import org.jboss.deployers.plugins.main.MainDeployerImpl;
import org.jboss.deployers.spi.management.DeploymentTemplate;
import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.deployers.spi.management.NameMatcher;
import org.jboss.deployers.spi.management.RuntimeComponentDispatcher;
-import org.jboss.deployers.spi.structure.ContextInfo;
-import org.jboss.deployers.spi.structure.StructureMetaData;
-import org.jboss.deployers.structure.spi.DeploymentContext;
import org.jboss.deployers.vfs.spi.client.VFSDeployment;
import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
import org.jboss.logging.Logger;
import org.jboss.managed.api.ComponentType;
import org.jboss.managed.api.DeploymentTemplateInfo;
-import org.jboss.managed.api.ManagedCommon;
import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedDeployment;
import org.jboss.managed.api.ManagedObject;
@@ -88,9 +83,6 @@
import org.jboss.profileservice.spi.ProfileKey;
import org.jboss.profileservice.spi.ProfileService;
import org.jboss.remoting.InvokerLocator;
-import org.jboss.system.server.profileservice.attachments.AttachmentMetaData;
-import org.jboss.system.server.profileservice.attachments.RepositoryAttachmentMetaData;
-import org.jboss.system.server.profileservice.attachments.RepositoryAttachmentMetaDataFactory;
import org.jboss.virtual.VirtualFile;
/**
@@ -932,15 +924,11 @@
{
// Find the comp deployment
ManagedDeployment md = comp.getDeployment();
- // Create the metadata
- RepositoryAttachmentMetaData childMetaData = RepositoryAttachmentMetaDataFactory.createInstance(md);
- RepositoryAttachmentMetaData parentMetaData = childMetaData;
+
// Get the parent
while( md.getParent() != null )
- {
md = md.getParent();
- parentMetaData = RepositoryAttachmentMetaDataFactory.createNewParent(md, parentMetaData);
- }
+
String name = md.getName();
DeploymentPhase phase = md.getDeploymentPhase();
VFSDeployment compDeployment = activeProfile.getDeployment(name, phase);
@@ -1023,74 +1011,9 @@
dispatcher.set(componentName, ctxProp.getName(), metaValue);
}
- // Get the parent ManagedCommon
- ManagedCommon parent = serverComp;
- while(parent.getParent() != null)
- parent = parent.getParent();
-
- // Get the managed object
- ManagedObject managedObject = serverComp.getDeployment().getManagedObject(parent.getName());
- if(managedObject != null)
- {
- AttachmentMetaData attachment = new AttachmentMetaData();
- attachment.setName(managedObject.getAttachmentName());
- attachment.setAttachment(managedObject.getAttachment());
-
- //
- RepositoryAttachmentMetaDataFactory.addAttachment(childMetaData, attachment);
- }
- else
- {
- // maybe throw an exception ?
- log.debug("No managed object found to update.");
- return;
- }
-
-
- DeploymentContext deployment = ((MainDeployerImpl) mainDeployer).getDeploymentContext(md.getName(), false);
- StructureMetaData structure = deployment.getDeploymentUnit().getAttachment(StructureMetaData.class);
- // FIXME this should not be done here
- // apply structure information
- List<String> processedContexts = new ArrayList<String>();
- if(structure != null)
- {
- // root context
- RepositoryAttachmentMetaDataFactory.applyStructureContext(parentMetaData, structure.getContext(""));
- processedContexts.add("");
- // children
- if(parentMetaData.getChildren() != null && ! parentMetaData.getChildren().isEmpty())
- {
- for(RepositoryAttachmentMetaData child : parentMetaData.getChildren())
- {
- // TODO support more nested elements
- ContextInfo info = structure.getContext(child.getDeploymentName());
- if(info != null)
- {
- RepositoryAttachmentMetaDataFactory.applyStructureContext(child, info);
- processedContexts.add(child.getDeploymentName());
- }
- }
- }
- // Create a plain child meta data for not covered contexts
- for(ContextInfo info : structure.getContexts())
- {
- if(!processedContexts.contains(info.getPath()))
- {
- RepositoryAttachmentMetaData newChild = RepositoryAttachmentMetaDataFactory.createInstance();
- newChild.setDeploymentName(info.getPath());
-
- RepositoryAttachmentMetaDataFactory.applyStructureContext(newChild, info);
- RepositoryAttachmentMetaDataFactory.addChild(parentMetaData, newChild);
- }
- }
- }
-
- // TODO this updates the parent only - maybe we just need to update the child - if we also check it when restoring
- parentMetaData.setLastModified(System.currentTimeMillis());
-
// Wrap
- Map<String, Object> metaDataAttachment = Collections.singletonMap(RepositoryAttachmentMetaData.class.getName(), (Object) parentMetaData);
+ Map<String, Object> metaDataAttachment = Collections.singletonMap(ManagedComponent.class.getName(), (Object) serverComp);
// Update the repository deployment attachments
activeProfile.updateDeployment(compDeployment, phase, metaDataAttachment);
Modified: trunk/server/src/etc/conf/default/profile-repository.xml
===================================================================
--- trunk/server/src/etc/conf/default/profile-repository.xml 2008-11-17 15:33:47 UTC (rev 81169)
+++ trunk/server/src/etc/conf/default/profile-repository.xml 2008-11-17 16:36:44 UTC (rev 81170)
@@ -30,6 +30,7 @@
</array>
</property>
<property name="serializer"><inject bean="AttachmentsSerializer"/></property>
+ <property name="mainDeployer"><inject bean="MainDeployer"/></property>
</bean>
<bean name="AttachmentsSerializer" class="org.jboss.system.server.profileservice.repository.JAXBAttachmentSerializer">
<!-- TODO This is getting set in the DeploymentRepository.load, to make sure that we use the same directory.
Modified: trunk/system/src/main/org/jboss/profileservice/spi/repository/Requirement.java
===================================================================
--- trunk/system/src/main/org/jboss/profileservice/spi/repository/Requirement.java 2008-11-17 15:33:47 UTC (rev 81169)
+++ trunk/system/src/main/org/jboss/profileservice/spi/repository/Requirement.java 2008-11-17 16:36:44 UTC (rev 81170)
@@ -30,4 +30,53 @@
public interface Requirement
{
+ /**
+ * Return the name of the requirement.
+ *
+ * @return name
+ */
+ String getName();
+
+ /**
+ * Return the filter.
+ *
+ * @return filter string
+ */
+ String getFilter();
+
+ /**
+ * Is multiple.
+ *
+ * @return true for multiple, false otherwise
+ */
+ boolean isMultiple();
+
+ /**
+ * Is optional.
+ *
+ * @return true for optional, false otherwise
+ */
+ boolean isOptional();
+
+ /**
+ * Is extended.
+ *
+ * @return true for extended, false otherwise
+ */
+ boolean isExtend();
+
+ /**
+ * Get comment.
+ *
+ * @return the comment
+ */
+ String getComment();
+
+ /**
+ * Is satisfied.
+ *
+ * @param capability the capability to check
+ * @return true for satisfied, false otherwise
+ */
+ boolean isSatisfied(Capability capability);
}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/attachments/AttachmentMetaData.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/attachments/AttachmentMetaData.java 2008-11-17 15:33:47 UTC (rev 81169)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/attachments/AttachmentMetaData.java 2008-11-17 16:36:44 UTC (rev 81170)
@@ -34,6 +34,9 @@
/** The attachment name */
private String name;
+ /** The attachment class name */
+ private String className;
+
/** The attachment */
private transient Object attachment;
@@ -47,6 +50,17 @@
{
this.name = name;
}
+
+ @XmlElement(name = "attachment-class-name")
+ public String getClassName()
+ {
+ return className;
+ }
+
+ public void setClassName(String className)
+ {
+ this.className = className;
+ }
@XmlTransient
public Object getAttachment()
Added: trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java 2008-11-17 16:36:44 UTC (rev 81170)
@@ -0,0 +1,548 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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.system.server.profileservice.repository;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.spi.structure.ClassPathEntry;
+import org.jboss.deployers.spi.structure.ContextInfo;
+import org.jboss.deployers.spi.structure.StructureMetaData;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ManagedCommon;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedDeployment.DeploymentPhase;
+import org.jboss.profileservice.spi.AttachmentsSerializer;
+import org.jboss.system.server.profileservice.attachments.AttachmentMetaData;
+import org.jboss.system.server.profileservice.attachments.DeploymentClassPathMetaData;
+import org.jboss.system.server.profileservice.attachments.DeploymentStructureMetaData;
+import org.jboss.system.server.profileservice.attachments.LazyPredeterminedManagedObjects;
+import org.jboss.system.server.profileservice.attachments.RepositoryAttachmentMetaData;
+import org.jboss.system.server.profileservice.attachments.RepositoryAttachmentMetaDataFactory;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public abstract class AbstractAttachmentStore
+{
+
+ /** The attachment serializer. */
+ protected AttachmentsSerializer serializer;
+
+ /** The deployment factory. */
+ protected VFSDeploymentFactory deploymentFactory = VFSDeploymentFactory.getInstance();
+
+ /** The MainDeployerStructure. */
+ protected MainDeployerStructure mainDeployer;
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(AbstractAttachmentStore.class);
+
+ public VFSDeploymentFactory getDeploymentFactory()
+ {
+ return deploymentFactory;
+ }
+
+ public void setDeploymentFactory(VFSDeploymentFactory deploymentFactory)
+ {
+ this.deploymentFactory = deploymentFactory;
+ }
+
+ public MainDeployerStructure getMainDeployer()
+ {
+ return mainDeployer;
+ }
+
+ public void setMainDeployer(MainDeployerStructure mainDeployer)
+ {
+ this.mainDeployer = mainDeployer;
+ }
+
+ public AttachmentsSerializer getSerializer()
+ {
+ return serializer;
+ }
+
+ public void setSerializer(AttachmentsSerializer serializer)
+ {
+ this.serializer = serializer;
+ }
+
+ /**
+ * 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)
+ {
+ if(file == null)
+ throw new IllegalArgumentException("Cannot create a deployment for a null file.");
+
+ boolean trace = log.isTraceEnabled();
+ // Create VFS deployment
+ VFSDeployment deployment = deploymentFactory.createVFSDeployment(file);
+ if(trace)
+ log.trace("Created deployment: " + deployment);
+
+ // attachments/deploy/deployment/
+ String deploymentPath = getPhaseDirPath(phase) + deployment.getSimpleName() + File.separator;
+ if(trace)
+ log.trace("trying to load attachment from relative path: " + deploymentPath);
+
+ // Load the metadata
+ RepositoryAttachmentMetaData attachmentMetaData = loadAttachmentMetaData(deploymentPath);
+
+ if(attachmentMetaData == null)
+ {
+ if(trace)
+ log.trace("Did not find any presisted metadata for deployment: " + deployment);
+ return deployment;
+ }
+
+ try
+ {
+ // If the deployment has changes we skip this.
+ // TODO delete attachments ?
+ if(attachmentMetaData.getLastModified() < file.getLastModified())
+ {
+ log.debug("Not using the persisted metadata, as the deployment was modified.");
+ return deployment;
+ }
+ }
+ catch(IOException e)
+ {
+ log.error("failed to get LastModified date for file, no using persisted metadata: "+ file.getPathName());
+ return deployment;
+ }
+
+ // Start with "" the root contextPath
+ rebuildStructureContext(deployment, "", deploymentPath, attachmentMetaData, trace);
+
+ return deployment;
+ }
+
+ protected void updateDeployment(VFSDeployment deployment, DeploymentPhase phase, ManagedComponent comp)
+ throws Exception
+ {
+ if(deployment == null)
+ throw new IllegalArgumentException("VFSDeployment may not be null.");
+
+ if(comp == null)
+ throw new IllegalArgumentException("ManagedComponent may not be null.");
+
+ boolean trace = log.isTraceEnabled();
+
+ // attachments/deploy/deployment/
+ String deploymentPath = getPhaseDirPath(phase) + deployment.getSimpleName() + File.separator;
+ RepositoryAttachmentMetaData savedMetaData = loadAttachmentMetaData(deploymentPath);
+
+ // Get parent deployment
+ ManagedDeployment md = comp.getDeployment();
+ String currentContextName = "";
+ if(md.getParent() != null)
+ {
+ while( md.getParent() != null )
+ {
+ currentContextName = md.getSimpleName() + "/" + currentContextName;
+ md = md.getParent();
+ }
+ currentContextName = fixName(currentContextName);
+ }
+
+ RepositoryAttachmentMetaData currentContextMetaData = null;
+ if(savedMetaData != null)
+ {
+ if(trace)
+ log.trace("Previous metadata found for deployment: " + deployment);
+
+ // The root context
+ if("".equals(currentContextName))
+ {
+ currentContextMetaData = savedMetaData;
+ }
+ else
+ {
+ for(RepositoryAttachmentMetaData child : savedMetaData.getChildren())
+ {
+ // extract the current context
+ if(child.getDeploymentName().equals(currentContextName))
+ currentContextMetaData = child;
+ }
+ }
+ }
+ else
+ {
+ // Create the metadata
+ savedMetaData = RepositoryAttachmentMetaDataFactory.createInstance(md);
+ currentContextMetaData = createRepositoryMetaData(savedMetaData, currentContextName, md);
+ }
+
+ if(currentContextMetaData == null)
+ throw new IllegalStateException("Could not create child metadata");
+
+ // Get the currentTimeMillis
+ long lastModified = System.currentTimeMillis();
+
+ // Get the parent ManagedCommon
+ ManagedCommon parent = comp;
+ while(parent.getParent() != null)
+ parent = parent.getParent();
+
+ // Get the managed object
+ ManagedObject managedObject = comp.getDeployment().getManagedObject(parent.getName());
+ if(managedObject != null)
+ {
+ Object o = managedObject.getAttachment();
+ if(o != null)
+ {
+ AttachmentMetaData attachment = new AttachmentMetaData();
+ // Is attachmentName the same as the className ?
+ attachment.setName(managedObject.getAttachmentName());
+ attachment.setClassName(o.getClass().getName());
+ // Set attachment
+ attachment.setAttachment(o);
+ // Add attachment
+ RepositoryAttachmentMetaDataFactory.addAttachment(currentContextMetaData, attachment);
+ // Update lastModified
+ currentContextMetaData.setLastModified(lastModified);
+ }
+ }
+
+ // Plus set the last modified on the root metadata
+ savedMetaData.setLastModified(lastModified);
+ // Save the attachment
+ saveAttachmentMetaData(deploymentPath, savedMetaData);
+ }
+
+ /**
+ * Create the repository meta data from the parent ManagedDeployment.
+ *
+ * @param parentMd the parent managed deployment
+ * @return the RepositoryAttachmentMetaData with the structure information
+ * @throws Exception
+ */
+ protected RepositoryAttachmentMetaData createRepositoryMetaData(RepositoryAttachmentMetaData parentMetaData, String childPath, ManagedDeployment parentMd)
+ throws Exception
+ {
+ // Child metadata
+ RepositoryAttachmentMetaData childMetaData = null;
+
+ StructureMetaData structure = getStructureMetaData(parentMd.getName());
+ if(structure == null)
+ throw new IllegalStateException("Could not get the StructureMetaData.");
+
+ List<ContextInfo> contextInfos = structure.getContexts();
+ if(contextInfos == null)
+ throw new IllegalStateException("StructureMetaData has no contexts."); // can this happen anyway ?
+
+ // root context
+ RepositoryAttachmentMetaDataFactory.applyStructureContext(parentMetaData, structure.getContext(""));
+ // Other contexts
+ for(ContextInfo info : contextInfos)
+ {
+ // If it is not the root path
+ if(! "".equals(info.getPath()))
+ {
+ RepositoryAttachmentMetaData newChild = RepositoryAttachmentMetaDataFactory.createInstance();
+ newChild.setDeploymentName(info.getPath());
+
+ RepositoryAttachmentMetaDataFactory.applyStructureContext(newChild, info);
+ RepositoryAttachmentMetaDataFactory.addChild(parentMetaData, newChild);
+
+ if(childPath.equals(info.getPath()))
+ childMetaData = newChild;
+ }
+ }
+
+ if("".equals(childPath))
+ childMetaData = parentMetaData;
+
+ return childMetaData;
+ }
+
+ /**
+ * Get the structure meta data for a deployment.
+ *
+ * @param vfsDeploymentName the vfs deployment name
+ * @return the StructureMetaData
+ * @throws Exception
+ */
+ protected StructureMetaData getStructureMetaData(String vfsDeploymentName)
+ throws Exception
+ {
+ // Get the StructureMetaData;
+ DeploymentContext deploymentContext = mainDeployer.getDeploymentContext(vfsDeploymentName, false);
+ return deploymentContext.getDeploymentUnit().getAttachment(StructureMetaData.class);
+ }
+
+ /**
+ * Update a deployment based on it's RepositoryAttachmentMetaData
+ *
+ * TODO use a xml serializer, to drop the use of the childAttachment maps.
+ *
+ * @param d
+ * @param phase
+ * @param metaData
+ * @throws Exception
+ */
+ private void saveAttachmentMetaData(String deploymentPath, RepositoryAttachmentMetaData metaData)
+ throws Exception
+ {
+ boolean trace = log.isTraceEnabled();
+
+ // Save attachments for the root context
+ if(metaData.getAttachments() != null && !metaData.getAttachments().isEmpty())
+ {
+ for(AttachmentMetaData attachment : metaData.getAttachments())
+ {
+ // Only save attachment if the attachment is present :)
+ if(attachment.getAttachment() == null)
+ continue;
+
+ String attachmentPath = deploymentPath + attachment.getName();
+ // Serialize the attachment
+ serializer.saveAttachment(attachmentPath, attachment.getAttachment());
+
+ if(trace)
+ log.trace("Stored attachment to : " + attachmentPath);
+ }
+ }
+
+ // Save attachments for the children
+ List<RepositoryAttachmentMetaData> children = metaData.getChildren();
+ if(children != null && !children.isEmpty())
+ {
+ for(RepositoryAttachmentMetaData child : children)
+ {
+ // The relative child path
+ String childPath = deploymentPath + child.getDeploymentName() + File.separator;
+ if(child.getAttachments() != null && ! child.getAttachments().isEmpty())
+ {
+ for(AttachmentMetaData attachment : child.getAttachments())
+ {
+ if(attachment.getAttachment() == null)
+ continue;
+
+ String attachmentPath = childPath + attachment.getName();
+ // Serialize the attachment
+ serializer.saveAttachment(attachmentPath, attachment.getAttachment());
+
+ if(trace)
+ log.trace("Stored attachment to : " + attachmentPath);
+ }
+ }
+ }
+ }
+
+ // Finally store the repository metadata
+ this.serializer.saveAttachment(deploymentPath + "metadata", metaData);
+ }
+
+ /**
+ * Rebuild the StructureMetaData based on the RepositoryAttachmentMetaData
+ * and add predeterminedManagedObjects.
+ *
+ * @param deployment the VFSDeployment
+ * @param contextName the structure context path
+ * @param deploymentPath the path to the attachement
+ * @param attachmentMetaData the meta data
+ */
+ protected void rebuildStructureContext(VFSDeployment deployment,
+ String contextName,
+ String deploymentPath,
+ RepositoryAttachmentMetaData attachmentMetaData,
+ boolean trace)
+ {
+ // The toplevel context
+ boolean isRoot = "".equals(contextName);
+
+ if(trace)
+ log.trace("Rebuilding StructureMetaData for context: " + contextName);
+
+ // Get the stored deployment structure
+ DeploymentStructureMetaData structure = attachmentMetaData.getDeploymentStructure();
+
+ // MetaData and ClassPath
+ List<String> metaDataPaths = new ArrayList<String>();
+ List<ClassPathEntry> classPath = new ArrayList<ClassPathEntry>();
+ if(structure != null)
+ {
+ if(structure.getClassPaths() != null)
+ {
+ for(DeploymentClassPathMetaData md : structure.getClassPaths())
+ classPath.add(deploymentFactory.createClassPathEntry(md.getPath(), md.getSuffixes()));
+ }
+
+ if(structure.getMetaDataPaths() != null)
+ metaDataPaths = structure.getMetaDataPaths();
+ }
+
+ // Now create the ContextInfo
+ ContextInfo info = deploymentFactory.addContext(deployment, contextName, metaDataPaths, classPath);
+ if(structure != null)
+ {
+ // Set the comparator
+ info.setComparatorClassName(structure.getComparatorClass());
+ // Set the relative order
+ info.setRelativeOrder(structure.getRelatativeOrder());
+ }
+ if(trace)
+ log.trace("created ContextInfo: "+ info + " for deployment: "+ deployment);
+
+ // Add attachments if needed
+ if(attachmentMetaData.getAttachments() != null && ! attachmentMetaData.getAttachments().isEmpty())
+ {
+ Set<String> availableAttachments = new HashSet<String>();
+ for(AttachmentMetaData attachment : attachmentMetaData.getAttachments())
+ availableAttachments.add(attachment.getClassName());
+
+ MutableAttachments mutable = new LazyPredeterminedManagedObjects(this.serializer, deploymentPath, availableAttachments);
+
+ // TODO is there a better way to do this ?
+ if(isRoot)
+ {
+ deployment.setPredeterminedManagedObjects(mutable);
+ }
+ else
+ {
+ info.setPredeterminedManagedObjects(mutable);
+ }
+
+ if(trace)
+ log.trace("Added PredetminedManagedObjects: " + availableAttachments + " to context " + contextName);
+ }
+ else
+ {
+ if(trace)
+ log.trace("No PredetminedManagedObjects found for context " + contextName);
+ }
+
+ // Process children
+ List<RepositoryAttachmentMetaData> children = attachmentMetaData.getChildren();
+ if(children != null && ! children.isEmpty())
+ {
+ for(RepositoryAttachmentMetaData childMetaData : children)
+ {
+ // The structure context path
+ String childContextName = contextName + "/" + childMetaData.getDeploymentName();
+ // The relative path of the child attachment (therefore File.separator)
+ String relativePath = deploymentPath + childMetaData.getDeploymentName() + File.separator;
+
+ if(trace)
+ log.trace("Processing child context: "+ childContextName);
+
+ // Rebuild the structure of the child
+ rebuildStructureContext(deployment, fixName(childContextName), relativePath, childMetaData, trace);
+ }
+ }
+ }
+
+ /**
+ * Load the attachment metadata for a deployment.
+ *
+ * @param relativeDeploymentPath the relatative path to the metadata
+ * @return the attachment metadata
+ */
+ protected RepositoryAttachmentMetaData loadAttachmentMetaData(String relativeDeploymentPath)
+ {
+ final String metaDataName = "metadata";
+ // attachments/deploy/deployment/metadata
+ String fixedMetadataPath = relativeDeploymentPath.endsWith(File.separator) ? relativeDeploymentPath + metaDataName : relativeDeploymentPath + File.separator + metaDataName;
+
+ try
+ { // Try to load the repository attachment metadata
+ return this.serializer.loadAttachment(fixedMetadataPath, RepositoryAttachmentMetaData.class);
+ }
+ catch(Exception e)
+ {
+ log.error("Failed to load attachment metadata from relative path: "+ relativeDeploymentPath, e);
+ }
+ return null;
+ }
+
+ /**
+ * Make sure that the name does not start or end with /
+ *
+ * @param name
+ * @return
+ */
+ private String fixName(String name)
+ {
+ if(name == null)
+ return null;
+
+ if(name.equals(""))
+ return name;
+
+ if(name.startsWith("/"))
+ name = name.substring(1);
+
+ if(name.endsWith("/"))
+ name = name.substring(0, name.length() -1);
+
+ return name;
+ }
+
+}
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-11-17 15:33:47 UTC (rev 81169)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java 2008-11-17 16:36:44 UTC (rev 81170)
@@ -50,6 +50,7 @@
import org.jboss.deployers.vfs.spi.client.VFSDeployment;
import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
import org.jboss.logging.Logger;
+import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedDeployment.DeploymentPhase;
import org.jboss.profileservice.spi.AttachmentsSerializer;
import org.jboss.profileservice.spi.DeploymentContentFlags;
@@ -81,7 +82,7 @@
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
-public class SerializableDeploymentRepository
+public class SerializableDeploymentRepository extends AbstractAttachmentStore
implements DeploymentRepository
{
private static final Logger log = Logger.getLogger(SerializableDeploymentRepository.class);
@@ -108,8 +109,7 @@
private LinkedHashMap<String,VFSDeployment> deployerCtxs = new LinkedHashMap<String,VFSDeployment>();
/** The application VFSDeployments */
private LinkedHashMap<String,VFSDeployment> applicationCtxs = new LinkedHashMap<String,VFSDeployment>();
- /** The {@link VFSDeployment#PredeterminedManagedObjects} serializer */
- private AttachmentsSerializer serializer;
+
private Map<String, Integer> contentFlags = new ConcurrentHashMap<String, Integer>();
/** The last time the profile was modified */
private long lastModified;
@@ -117,8 +117,6 @@
private ReentrantReadWriteLock contentLock = new ReentrantReadWriteLock(true);
/** Should an attempt to overwrite existing content fail in {@link #addDeploymentContent(String, ZipInputStream, DeploymentPhase)}*/
private boolean failIfAlreadyExists = false;
- /** The deployment factory */
- private VFSDeploymentFactory factory = VFSDeploymentFactory.getInstance();
public SerializableDeploymentRepository(File root, URI[] appURIs, ProfileKey key)
{
@@ -127,15 +125,6 @@
this.setApplicationURIs(appURIs);
}
- public AttachmentsSerializer getSerializer()
- {
- return serializer;
- }
- public void setSerializer(AttachmentsSerializer serializer)
- {
- this.serializer = serializer;
- }
-
public URI[] getApplicationURIs()
{
URI[] appURIs = new URI[applicationDirs.length];
@@ -1072,275 +1061,18 @@
public void updateDeployment(VFSDeployment d, DeploymentPhase phase,
Map<String, Object> attachments) throws Exception
{
- RepositoryAttachmentMetaData metaData = (RepositoryAttachmentMetaData) attachments.get(RepositoryAttachmentMetaData.class.getName());
- if(metaData != null)
+ ManagedComponent comp = (ManagedComponent) attachments.get(ManagedComponent.class.getName());
+ if(comp != null)
{
- this.updateDeployment(d, phase, metaData);
+ // update component
+ updateDeployment(d, phase, comp);
+ // Update last moidfied
+ this.lastModified = System.currentTimeMillis();
}
else
{
log.error("no metadata attached.");
}
}
-
- /**
- * Update a deployment based on it's RepositoryAttachmentMetaData
- *
- * TODO use a xml serializer, to drop the use of the childAttachment maps.
- *
- * @param d
- * @param phase
- * @param metaData
- * @throws Exception
- */
- public void updateDeployment(VFSDeployment d, DeploymentPhase phase,
- RepositoryAttachmentMetaData metaData)
- throws Exception
- {
- boolean trace = log.isTraceEnabled();
-
- // The PhaseDir
- File path = getPhaseDir(phase);
- if(path == null)
- {
- log.warn("Could not get PhaseDir for DeploymentPhase: " + phase + ", unable to perstisted attachments.");
- return;
- }
-
- // attachments/deploy/deployment/
- String deploymentPath = path.getName() + File.separator + d.getSimpleName() + File.separator;
- RepositoryAttachmentMetaData savedMetaData = loadAttachmentMetaData(deploymentPath);
-
- if(savedMetaData != null)
- {
- if(trace)
- log.trace("Previous metadata found for deployment: " + d);
- // TODO merge updates
- }
-
- // Save attachments for the root context
- if(metaData.getAttachments() != null && !metaData.getAttachments().isEmpty())
- {
- for(AttachmentMetaData attachment : metaData.getAttachments())
- {
- String attachmentPath = deploymentPath + attachment.getName();
- // Serialize the attachment
- serializer.saveAttachment(attachmentPath, attachment.getAttachment());
-
- if(trace)
- log.trace("Stored attachment to : " + attachmentPath);
- }
- }
-
- // Save attachments for the children
- List<RepositoryAttachmentMetaData> children = metaData.getChildren();
- if(children != null && !children.isEmpty())
- {
- for(RepositoryAttachmentMetaData child : children)
- {
- // The relative child path
- String childPath = deploymentPath + child.getDeploymentName() + File.separator;
- if(child.getAttachments() != null && ! child.getAttachments().isEmpty())
- {
- for(AttachmentMetaData attachment : child.getAttachments())
- {
- String attachmentPath = childPath + attachment.getName();
- // Serialize the attachment
- serializer.saveAttachment(attachmentPath, attachment.getAttachment());
-
- if(trace)
- log.trace("Stored attachment to : " + attachmentPath);
- }
- }
- }
- }
-
- // Store the repository metadata
- this.serializer.saveAttachment(deploymentPath + "metadata", metaData);
-
- //
- this.lastModified = System.currentTimeMillis();
- }
-
- /**
- * Load the attachment metadata.
- *
- * @param file
- * @return the deployment
- */
- private VFSDeployment loadDeploymentData(VirtualFile file, DeploymentPhase phase)
- {
- boolean trace = log.isTraceEnabled();
- // Create VFS deployment
- VFSDeployment deployment = factory.createVFSDeployment(file);
- if(trace)
- log.trace("Created deployment: " + deployment);
-
- // The PhaseDir
- File path = getPhaseDir(phase);
- if(path == null)
- {
- log.debug("Could not get PhaseDir for DeploymentPhase: " + phase + ", do not scann for perstisted attachments.");
- return deployment;
- }
-
- // attachments/deploy/deployment/
- String deploymentPath = path.getName() + File.separator + deployment.getSimpleName() + File.separator;
- if(trace)
- log.trace("trying to load attachment from relative path: " + deploymentPath);
-
- // Load the metadata
- RepositoryAttachmentMetaData attachmentMetaData = loadAttachmentMetaData(deploymentPath);
-
- if(attachmentMetaData == null)
- {
- if(trace)
- log.trace("Did not find any presisted metadata for deployment: " + deployment);
- return deployment;
- }
-
- try
- {
- // If the deployment has changes we skip this.
- // TODO delete attachments ?
- if(attachmentMetaData.getLastModified() < file.getLastModified())
- {
- log.debug("Not using the persisted metadata, as the deployment was modified.");
- return deployment;
- }
- }
- catch(IOException e)
- {
- log.error("failed to get LastModified date for file, no using persisted metadata: "+ file.getPathName());
- return deployment;
- }
-
- // Start with "" the root contextPath
- rebuildStructureContext(deployment, "", deploymentPath, attachmentMetaData, trace);
-
- return deployment;
- }
-
- /**
- * Rebuild the StructureMetaData based on the RepositoryAttachmentMetaData
- * and add predeterminedManagedObjects.
- *
- * @param deployment the VFSDeployment
- * @param contextName the structure context path
- * @param deploymentPath the path to the attachement
- * @param attachmentMetaData the meta data
- */
- protected void rebuildStructureContext(VFSDeployment deployment,
- String contextName,
- String deploymentPath,
- RepositoryAttachmentMetaData attachmentMetaData,
- boolean trace)
- {
- // The toplevel context
- boolean isRoot = "".equals(contextName);
-
- if(trace)
- log.trace("Rebuilding StructureMetaData for context: " + contextName);
-
-
-
- // Get the stored deployment structure
- DeploymentStructureMetaData structure = attachmentMetaData.getDeploymentStructure();
-
- // MetaData and ClassPath
- List<String> metaDataPaths = new ArrayList<String>();
- List<ClassPathEntry> classPath = new ArrayList<ClassPathEntry>();
- if(structure != null)
- {
- if(structure.getClassPaths() != null)
- {
- for(DeploymentClassPathMetaData md : structure.getClassPaths())
- classPath.add(factory.createClassPathEntry(md.getPath(), md.getSuffixes()));
- }
-
- if(structure.getMetaDataPaths() != null)
- metaDataPaths = structure.getMetaDataPaths();
- }
-
- // Now create the ContextInfo
- ContextInfo info = factory.addContext(deployment, contextName, metaDataPaths, classPath);
- if(structure != null)
- {
- // Set the comparator
- info.setComparatorClassName(structure.getComparatorClass());
- // Set the relative order
- info.setRelativeOrder(structure.getRelatativeOrder());
- }
- if(trace)
- log.trace("created ContextInfo: "+ info + " for deployment: "+ deployment);
-
- // Add attachments if needed
- if(attachmentMetaData.getAttachments() != null && ! attachmentMetaData.getAttachments().isEmpty())
- {
- Set<String> availableAttachments = new HashSet<String>();
- for(AttachmentMetaData attachment : attachmentMetaData.getAttachments())
- availableAttachments.add(attachment.getName());
-
- MutableAttachments mutable = new LazyPredeterminedManagedObjects(this.serializer, deploymentPath, availableAttachments);
-
- // TODO is there a better way to do this ?
- if(isRoot)
- deployment.setPredeterminedManagedObjects(mutable);
- else
- info.setPredeterminedManagedObjects(mutable);
-
- if(trace)
- log.trace("Added PredetminedManagedObjects: " + availableAttachments + " to context " + contextName);
- }
- else
- {
- if(trace)
- log.trace("No PredetminedManagedObjects found for context " + contextName);
- }
-
- // Process children
- List<RepositoryAttachmentMetaData> children = attachmentMetaData.getChildren();
- if(children != null && ! children.isEmpty())
- {
- for(RepositoryAttachmentMetaData childMetaData : children)
- {
- // The structure context path
- String childContextName = contextName + "/" + childMetaData.getDeploymentName();
- // The relative path of the child attachment (therefore File.separator)
- String relativePath = deploymentPath + childMetaData.getDeploymentName() + File.separator;
-
- if(trace)
- log.trace("Processing child context: "+ childContextName);
-
- // Rebuild the structure of the child
- rebuildStructureContext(deployment, childContextName, relativePath, childMetaData, trace);
- }
- }
- }
-
- /**
- * Load the attachment metadata for a deployment.
- *
- * @param relativeDeploymentPath the relatative path to the metadata
- * @return the attachment metadata
- */
- protected RepositoryAttachmentMetaData loadAttachmentMetaData(String relativeDeploymentPath)
- {
- final String metaDataName = "metadata";
- // attachments/deploy/deployment/metadata
- String fixedMetadataPath = relativeDeploymentPath.endsWith(File.separator) ? relativeDeploymentPath + metaDataName : relativeDeploymentPath + File.separator + metaDataName;
-
- try
- {
- // Try to load metadata Attachment
- return this.serializer.loadAttachment(fixedMetadataPath, RepositoryAttachmentMetaData.class);
- }
- catch(Exception e)
- {
- log.error("Failed to load attachment metadata from relative path: "+ relativeDeploymentPath, e);
- }
- return null;
- }
-
}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepositoryFactory.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepositoryFactory.java 2008-11-17 15:33:47 UTC (rev 81169)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepositoryFactory.java 2008-11-17 16:36:44 UTC (rev 81170)
@@ -25,6 +25,7 @@
import java.net.URI;
import java.util.HashMap;
+import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
import org.jboss.profileservice.spi.AttachmentsSerializer;
import org.jboss.profileservice.spi.DeploymentRepository;
import org.jboss.profileservice.spi.DeploymentRepositoryFactory;
@@ -43,11 +44,13 @@
private File root;
/** The URIs for the application deployments */
private URI[] appURIs = {};
- /** */
+ /** The attachment serializer */
private AttachmentsSerializer serializer;
+ /** The main deployer structure */
+ private MainDeployerStructure mainDeployer;
private HashMap<ProfileKey, DeploymentRepository> profileRepositories
= new HashMap<ProfileKey, DeploymentRepository>();
-
+
/**
* Get the server profile store root directory.
* @return the server profile root directory containing the
@@ -85,6 +88,16 @@
{
this.serializer = serializer;
}
+
+ public MainDeployerStructure getMainDeployer()
+ {
+ return mainDeployer;
+ }
+
+ public void setMainDeployer(MainDeployerStructure mainDeployer)
+ {
+ this.mainDeployer = mainDeployer;
+ }
public synchronized DeploymentRepository getDeploymentRepository(ProfileKey key)
{
@@ -98,6 +111,7 @@
{
SerializableDeploymentRepository repo = new SerializableDeploymentRepository(root, appURIs, key);
repo.setSerializer(serializer);
+ repo.setMainDeployer(mainDeployer);
profileRepositories.put(key, repo);
dr = repo;
}
More information about the jboss-cvs-commits
mailing list