avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mirceat...@apache.org
Subject cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/deployer DefaultDeploymentRecorder.java Resources.properties
Date Thu, 01 Nov 2001 22:48:57 GMT
mirceatoma    01/11/01 14:48:57

  Modified:    src/java/org/apache/avalon/phoenix/components/deployer
                        DefaultDeploymentRecorder.java Resources.properties
  Log:
  Implement Installation persistence & re-creation.
  
  Revision  Changes    Path
  1.2       +139 -11   jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/deployer/DefaultDeploymentRecorder.java
  
  Index: DefaultDeploymentRecorder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/deployer/DefaultDeploymentRecorder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultDeploymentRecorder.java	2001/10/31 21:59:57	1.1
  +++ DefaultDeploymentRecorder.java	2001/11/01 22:48:57	1.2
  @@ -7,11 +7,22 @@
    */
   package org.apache.avalon.phoenix.components.deployer;
   
  -import java.util.HashMap;
  +import java.io.File;
   import org.apache.avalon.framework.logger.AbstractLoggable;
  +import org.apache.avalon.framework.configuration.Configuration;
  +import org.apache.avalon.framework.configuration.DefaultConfiguration;
  +import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  +import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
  +import org.apache.avalon.framework.configuration.ConfigurationException;
  +import org.apache.avalon.framework.parameters.Parameters;
  +import org.apache.avalon.framework.parameters.Parameterizable;
  +import org.apache.avalon.framework.parameters.ParameterException;
  +import org.apache.avalon.excalibur.i18n.ResourceManager;
  +import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.avalon.phoenix.interfaces.DeploymentRecorder;
   import org.apache.avalon.phoenix.interfaces.DeploymentException;
   import org.apache.avalon.phoenix.tools.installer.Installation;
  +import org.apache.avalon.phoenix.tools.installer.FileDigest;
   
   /**
    * Recorder for application deployment specific information (To avoid 
  @@ -22,26 +33,143 @@
    */
   public class DefaultDeploymentRecorder 
       extends AbstractLoggable 
  -    implements DeploymentRecorder {
  -           
  -    private final HashMap m_installations = new HashMap();
  +    implements DeploymentRecorder, Parameterizable {
   
  +    private static final Resources REZ =
  +        ResourceManager.getPackageResources( DefaultDeploymentRecorder.class );
  +
  +    private final static String PHOENIX_HOME      = System.getProperty( "phoenix.home",
".." );
  +    private final static String DEFAULT_APPS_PATH = PHOENIX_HOME + File.separator + "apps";
  +    private final static String DIGEST_FILE       = "install.log";
  +    
  +    private final static String SOURCE      = "source";
  +    private final static String DIRECTORY   = "directory";
  +    private final static String CONFIG      = "config";
  +    private final static String ASSEMBLY    = "assembly";
  +    private final static String SERVER      = "server";
  +    private final static String CLASSPATH   = "classpath";
  +    private final static String PATH        = "path";
  +    private final static String URL         = "url";
  +    private final static String DIGESTS     = "digests";
  +    private final static String DIGEST      = "digest";
  +    private final static String TIMESTAMP   = "timestamp";
  +    private final static String FILE        = "file";
  +    private final static String CHECKSUM    = "checksum";
  +    
  +    private File m_appsDirectory;
  +    private final DefaultConfigurationBuilder m_builder = new DefaultConfigurationBuilder();
  +    private final DefaultConfigurationSerializer m_serializer = new DefaultConfigurationSerializer();
  +
  +    public void parameterize(Parameters parameters) 
  +        throws ParameterException
  +    {
  +        final String appsLocation =
  +            parameters.getParameter( "applications-directory", DEFAULT_APPS_PATH );
  +        m_appsDirectory = new File( appsLocation );
  +    }
  +    
       public synchronized void recordInstallation( final String name, final Installation
installation ) 
          throws DeploymentException
       {
  -        if( null == installation )
  -        {
  -            m_installations.remove( name );
  +        final File file = getDigestFile( name );
  +            
  +        try 
  +        {            
  +            if ( null == installation ) 
  +            {
  +                //remove installation digest file
  +                if( file.exists() ) file.delete();
  +                return;
  +            }
  +            
  +            final DefaultConfiguration configuration = new DefaultConfiguration( "installation",
null );
  +            configuration.setAttribute( SOURCE, installation.getSource().getCanonicalPath()
);
  +            configuration.setAttribute( DIRECTORY, installation.getDirectory().getCanonicalPath()
);
  +            configuration.setAttribute( CONFIG, installation.getConfig() );
  +            configuration.setAttribute( ASSEMBLY, installation.getAssembly() );
  +            configuration.setAttribute( SERVER, installation.getServer() );
  +            configuration.setAttribute( TIMESTAMP, Long.toString( installation.getTimestamp()
) );
  +            
  +            final DefaultConfiguration classpath = new DefaultConfiguration( CLASSPATH,
null );
  +            final String[] urls = installation.getClassPath();
  +            for ( int i = 0; i < urls.length; i++ )
  +            {
  +                final DefaultConfiguration path = new DefaultConfiguration( PATH, null
);
  +                path.setAttribute( URL, urls[i] );
  +                classpath.addChild( path );
  +            }
  +            configuration.addChild( classpath );
  +            
  +            final DefaultConfiguration digests = new DefaultConfiguration( DIGESTS, null
);
  +            final FileDigest[] fileDigests = installation.getFileDigests();
  +            for ( int i = 0; i < fileDigests.length; i++ )
  +            {
  +                final DefaultConfiguration digest = new DefaultConfiguration( DIGEST, null
);
  +                digest.setAttribute( FILE, fileDigests[i].getFile().getCanonicalPath()
);
  +                digest.setAttribute( CHECKSUM, String.valueOf( fileDigests[i].getChecksum()
) );
  +                digests.addChild( digest );
  +            }            
  +            configuration.addChild( digests );
  +            
  +            m_serializer.serializeToFile( file, configuration );
           }
  -        else
  -        {        
  -            m_installations.put( name, installation );           
  +        catch ( Exception e )
  +        {
  +            final String message = REZ.getString( "recorder.warn.persist.failed", name
);
  +            getLogger().warn( message, e );
  +            
  +            //delete traces
  +            file.delete();
           }
       }           
   
       public synchronized Installation fetchInstallation( final String name ) 
          throws DeploymentException
       {
  -       return (Installation)m_installations.get( name );
  +        final File file = getDigestFile( name );
  +        if( !file.exists() ) return null;
  +            
  +        try 
  +        {
  +            final Configuration configuration = m_builder.buildFromFile( file );
  +
  +            final File source = new File( configuration.getAttribute( SOURCE ) );
  +            final File directory = new File( configuration.getAttribute( DIRECTORY ) );
  +            final String config = configuration.getAttribute( CONFIG );
  +            final String assembly = configuration.getAttribute( ASSEMBLY );
  +            final String server = configuration.getAttribute( SERVER );
  +            final long timestamp = configuration.getAttributeAsLong( TIMESTAMP );
  +
  +            final Configuration[] paths = configuration.getChild( CLASSPATH, true).getChildren(
PATH );
  +            final String[] classPath = new String[ paths.length ];
  +            for ( int i = 0; i < paths.length; i++ )
  +            {
  +                classPath[i] = paths[i].getAttribute( URL );
  +            }            
  +            
  +            final Configuration[] digests = configuration.getChild( DIGESTS, true).getChildren(
DIGEST );
  +            final FileDigest[] fileDigests = new FileDigest[digests.length];
  +            for ( int i = 0; i < digests.length; i++ )
  +            {
  +                final File installedFile = new File( digests[i].getAttribute( FILE ) );
  +                final long checksum = digests[i].getAttributeAsLong( CHECKSUM );
  +                final FileDigest digest = new FileDigest( installedFile, checksum );
  +            }            
  +            
  +            return new Installation( source, directory, config, assembly, server, classPath,
fileDigests, timestamp );
  +        }
  +        catch ( Exception e )
  +        {
  +            final String message = REZ.getString( "recorder.warn.rebuild.failed", name
);
  +            getLogger().warn( message, e );
  +            
  +            //force re-installation
  +            return null;
  +        }            
       }        
  +    
  +    private File getDigestFile( final String name )
  +    {
  +        return new File( m_appsDirectory, name + File.separator + DIGEST_FILE );
  +    }    
   }
  
  
  
  1.9       +2 -1      jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/deployer/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/deployer/Resources.properties,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Resources.properties	2001/10/24 16:18:55	1.8
  +++ Resources.properties	2001/11/01 22:48:57	1.9
  @@ -1,6 +1,7 @@
   deploy.notice.sar.add=Adding SarEntry named "{0}" to Kernel with ClassPath = {1}.
  -
   deploy.error.config.create=Error building configuration from {0}.
  +recorder.warn.persist.failed=Cannot persist installation digest for {0}.
  +recorder.warn.rebuild.failed=Cannot rebuild installation digest for {0}.
   deploy.error.sar.add=Error adding component entry ({0}) to container.
   deploy.error.deploy.failed=Failed to deploy {0} from {1}.
   deploy.error.extra.config=There is no coresponding Block or Listener for configuration
data in element "{0}".
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>


Mime
View raw message