[jboss-cvs] JBossAS SVN: r59202 - trunk/system/src/main/org/jboss/system/server/profileservice/repository

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Dec 21 15:52:53 EST 2006


Author: scott.stark at jboss.org
Date: 2006-12-21 15:52:50 -0500 (Thu, 21 Dec 2006)
New Revision: 59202

Modified:
   trunk/system/src/main/org/jboss/system/server/profileservice/repository/FileProfleRepository.java
   trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java
Log:
Save current work


Property changes on: trunk/system/src/main/org/jboss/system/server/profileservice/repository/FileProfleRepository.java
___________________________________________________________________
Name: svn:keywords
   + Id, Revision

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	2006-12-21 19:03:46 UTC (rev 59201)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java	2006-12-21 20:52:50 UTC (rev 59202)
@@ -22,21 +22,29 @@
 package org.jboss.system.server.profileservice.repository;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
+import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.net.URI;
 import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.zip.ZipInputStream;
 
+import org.jboss.deployers.plugins.structure.AbstractDeploymentContext;
 import org.jboss.deployers.spi.attachments.Attachments;
+import org.jboss.deployers.spi.deployment.MainDeployer;
 import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.logging.Logger;
 import org.jboss.profileservice.spi.DeploymentRepository;
 import org.jboss.profileservice.spi.NoSuchProfileException;
 import org.jboss.profileservice.spi.ProfileKey;
 import org.jboss.util.file.Files;
+import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
 
 /**
@@ -51,18 +59,28 @@
  * + server/{name}/admin - admin edits to deployments
  * 
  * @author Scott.Stark at jboss.org
- * @version $Revision:$
+ * @version $Revision$
  */
 public class SerializableDeploymentRepository implements DeploymentRepository
 {
+   private static final Logger log = Logger.getLogger(SerializableDeploymentRepository.class);
+
+   private MainDeployer mainDeployer;
+   /** */
    private File root;
    private File confDir;
    private File libDir;
    private File deployersDir;
    private File deployDir;
-   private File metaDataRoot;
+   private File deploymentCtxDir;
    private File adminEditsRoot;
    private ProfileKey key;
+   private LinkedHashMap<String,DeploymentContext> bootstraps = new LinkedHashMap<String,DeploymentContext>();
+   private LinkedHashMap<String,DeploymentContext> deployments = new LinkedHashMap<String,DeploymentContext>();
+   private LinkedHashMap<String,DeploymentContext> deployers = new LinkedHashMap<String,DeploymentContext>();
+   private LinkedHashMap<String,DeploymentContext> bootstrapCtxs = new LinkedHashMap<String,DeploymentContext>();
+   private LinkedHashMap<String,DeploymentContext> deploymentCtxs = new LinkedHashMap<String,DeploymentContext>();
+   private LinkedHashMap<String,DeploymentContext> deployerCtxs = new LinkedHashMap<String,DeploymentContext>();
 
    public SerializableDeploymentRepository(File root, ProfileKey key)
    {
@@ -74,17 +92,19 @@
    {
       File profileRoot = new File(root, "server/"+key.getName());
       if( profileRoot.exists() == true )
-         throw new IOException("Profile root alread exists: "+profileRoot);
+         throw new IOException("Profile root already exists: "+profileRoot);
       if( profileRoot.mkdirs() == false )
          throw new IOException("Failed to create profile root: "+profileRoot);
       // server/{name}/conf
       confDir = new File(profileRoot, "conf");
       if( confDir.mkdirs() == false )
          throw new IOException("Failed to create profile conf dir: "+confDir);
+
       // server/{name}/deployers
       deployersDir = new File(profileRoot, "deployers");
       if( deployersDir.mkdirs() == false )
          throw new IOException("Failed to create profile deployers dir: "+deployersDir);
+
       // server/{name}/deploy
       deployDir = new File(profileRoot, "deploy");
       if( deployDir.mkdirs() == false )
@@ -93,24 +113,63 @@
       libDir = new File(profileRoot, "lib");
       if( libDir.mkdirs() == false )
          throw new IOException("Failed to create profile lib dir: "+libDir);
-      metaDataRoot = new File(profileRoot, "metaData");
-      if( metaDataRoot.mkdirs() == false )
-         throw new IOException("Failed to create profile metaData dir: "+metaDataRoot);
-      
-      adminEditsRoot = new File(profileRoot, "adminEdits");
+      deploymentCtxDir = new File(profileRoot, "profile/ctxs");
+      if( deploymentCtxDir.mkdirs() == false )
+         throw new IOException("Failed to create profile metaData dir: "+deploymentCtxDir);
+
+      adminEditsRoot = new File(profileRoot, "profile/edits");
       if( adminEditsRoot.mkdirs() == false )
          throw new IOException("Failed to create profile adminEdits dir: "+adminEditsRoot);
    }
 
+   /**
+    * Load the profile deployments
+    * 
+    * @throws IOException
+    * @throws NoSuchProfileException
+    */
    void load() throws IOException, NoSuchProfileException
    {
       File profileRoot = new File(root, "server/"+key.getName());
-      if( profileRoot.exists() == true )
-         throw new NoSuchProfileException("Profile root alread exists: "+profileRoot);
-      //
-      
+      if( profileRoot.exists() == false )
+         throw new NoSuchProfileException("Profile root does not exists: "+profileRoot);
+      // server/{name}/conf
+      confDir = new File(profileRoot, "conf");
+      if( confDir.exists() == false )
+         throw new FileNotFoundException("Profile contains no conf dir: "+confDir);
+
+      // server/{name}/deployers
+      deployersDir = new File(profileRoot, "deployers");
+      if( deployersDir.exists() == false )
+         throw new FileNotFoundException("Profile contains no deployers dir: "+deployersDir);
+
+      // server/{name}/deploy
+      deployDir = new File(profileRoot, "deploy");
+      if( deployDir.exists() == false )
+         throw new FileNotFoundException("Profile contains no deploy dir: "+deployDir);
+
+      deploymentCtxDir = new File(profileRoot, "profile/ctxs");
+      if( deploymentCtxDir.exists() == false )
+      {
+         if( deploymentCtxDir.mkdirs() == false )
+            throw new IOException("Failed to create profile metaData dir: "+deploymentCtxDir);
+      }
+
+      adminEditsRoot = new File(profileRoot, "profile/edits");
+
+      VFS confVFS = VFS.getVFS(confDir.toURI());
+      loadBootstraps(confVFS.getRoot());
+      VFS deployersVFS = VFS.getVFS(deployersDir.toURI());
+      loadDeployers(deployersVFS.getRoot());
+      VFS deployVFS = VFS.getVFS(deployDir.toURI());
+      loadDeployers(deployVFS.getRoot());
    }
 
+   /**
+    * 
+    * @throws IOException
+    * @throws NoSuchProfileException
+    */
    void remove() throws IOException, NoSuchProfileException
    {
       File profileRoot = new File(root, "server/"+key.getName());
@@ -150,13 +209,10 @@
       oos.writeObject(map);
       oos.close();
       fos.close();
-
    }
 
    public void addDeployer(String vfsPath, DeploymentContext ctx) throws IOException
    {
-      // TODO Auto-generated method stub
-      
    }
 
    public void addDeployment(String vfsPath, DeploymentContext ctx) throws IOException
@@ -269,20 +325,20 @@
       if( transientAttachments.getAttachments().size() > 0 )
       {
          Map<String, Object> map = transientAttachments.getAttachments();
-         File attachments = new File(metaDataRoot, vfsPath+".transientAttachments");
+         File attachments = new File(deploymentCtxDir, vfsPath+".transientAttachments");
          FileOutputStream fos = new FileOutputStream(attachments);
          ObjectOutputStream oos = new ObjectOutputStream(fos);
          oos.writeObject(map);
          oos.close();
          fos.close();
       }
-   
+
       // Write out the base transient managed objects
       Attachments transientManagedObjects = ctx.getTransientManagedObjects();
       if( transientManagedObjects.getAttachments().size() > 0 )
       {
          Map<String, Object> map = transientManagedObjects.getAttachments();
-         File attachments = new File(metaDataRoot, vfsPath+".transientManagedObjects");
+         File attachments = new File(deploymentCtxDir, vfsPath+".transientManagedObjects");
          FileOutputStream fos = new FileOutputStream(attachments);
          ObjectOutputStream oos = new ObjectOutputStream(fos);
          oos.writeObject(map);
@@ -291,4 +347,106 @@
       }
    }
 
+   private void loadAttachments(String vfsPath, DeploymentContext ctx)
+      throws ClassNotFoundException, IOException
+   {
+      File transientAttachments = new File(deploymentCtxDir, vfsPath+".transientAttachments");
+      if( transientAttachments.exists() )
+      {
+         FileInputStream fis = new FileInputStream(transientAttachments);
+         ObjectInputStream ois = new ObjectInputStream(fis);
+         Map<String, Object> map = (Map<String, Object>) ois.readObject();
+         ois.close();
+         fis.close();
+         for(String key : map.keySet())
+         {
+            Object value = map.get(key);
+            ctx.getTransientAttachments().addAttachment(key, value);
+         }
+      }
+
+      File transientManagedObjects = new File(deploymentCtxDir, vfsPath+".transientManagedObjects");
+      if( transientManagedObjects.exists() )
+      {
+         FileInputStream fis = new FileInputStream(transientManagedObjects);
+         ObjectInputStream ois = new ObjectInputStream(fis);
+         Map<String, Object> map = (Map<String, Object>) ois.readObject();
+         ois.close();
+         fis.close();
+         for(String key : map.keySet())
+         {
+            Object value = map.get(key);
+            ctx.getTransientManagedObjects().addAttachment(key, value);
+         }         
+      }
+   }
+
+   /**
+    * Load the know bootstrap descriptors under confDir, bootstrap-beans.xml
+    * and jboss-service.xml. The jboss-service.xml is optional.
+    * 
+    * @param confDir
+    * @throws IOException
+    */
+   private void loadBootstraps(VirtualFile confDir)
+      throws IOException
+   {
+      VirtualFile bootstrapBeans = confDir.findChild("bootstrap-beans.xml");
+      DeploymentContext bootstrapBeansCtx = loadDeploymentData(bootstrapBeans);
+      bootstrapCtxs.put(bootstrapBeans.getPathName(), bootstrapBeansCtx);
+      try
+      {
+         VirtualFile jbossService = confDir.findChild("jboss-service.xml");
+         DeploymentContext jbossServiceCtx = loadDeploymentData(bootstrapBeans);
+         bootstrapCtxs.put(jbossService.getPathName(), jbossServiceCtx);
+      }
+      catch(IOException e)
+      {
+         log.debug("No jboss-service.xml bootstrap found", e);
+      }
+   }
+
+   /**
+    * Load all the deployments under the deployersDir.
+    * 
+    * @param deployersDir
+    * @throws IOException
+    */
+   private void loadDeployers(VirtualFile deployersDir)
+      throws IOException
+   {
+      List<VirtualFile> children = deployersDir.getChildren();
+      for(VirtualFile vf : children)
+      {
+         DeploymentContext vfCtx = loadDeploymentData(vf);
+         bootstrapCtxs.put(vf.getPathName(), vfCtx);         
+      }
+   }
+
+   /**
+    * Load all the deployments under the deployersDir.
+    * 
+    * @param deployDir
+    * @throws IOException
+    */
+   private void loadDeployments(VirtualFile deployDir)
+      throws IOException
+   {
+      List<VirtualFile> children = deployDir.getChildren();
+      for(VirtualFile vf : children)
+      {
+         DeploymentContext vfCtx = loadDeploymentData(vf);
+         bootstrapCtxs.put(vf.getPathName(), vfCtx);         
+      }
+   }
+
+   private DeploymentContext loadDeploymentData(VirtualFile file)
+   {
+      // Check for a persisted context
+      // Load the base deployment
+      DeploymentContext deployment = new AbstractDeploymentContext(file);
+      // Load any attachments
+      return deployment;
+   }
+
 }


Property changes on: trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java
___________________________________________________________________
Name: svn:keywords
   + Id, Revision




More information about the jboss-cvs-commits mailing list