You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2005/03/25 15:04:47 UTC

svn commit: r159015 - in cocoon/whiteboard/block-deployer/src: client/org/apache/cocoon/blockdeployer/cli/ impl/org/apache/cocoon/blockdeployer/ impl/org/apache/cocoon/blockdeployer/configuration/ impl/org/apache/cocoon/blockdeployer/logging/ impl/org/apache/cocoon/blockdeployer/repository/

Author: reinhard
Date: Fri Mar 25 06:04:47 2005
New Revision: 159015

URL: http://svn.apache.org/viewcvs?view=rev&rev=159015
Log:
Introduce ConsoleLogger, remove Castor mapping for deployment configuration as the objects can be generated out of the schema file; work on the Launcher (for command line interface); modify ApplicationServer22Locator as the way of how the wiring is generated has changed

Added:
    cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/logging/
      - copied from r126205, cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/logging/
    cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/logging/ConsoleLogger.java
      - copied, changed from r159011, cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/logging/ConsoleLogger.java
Removed:
    cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/configuration/DeploymentConfigurationDTO10-mapping.xml
Modified:
    cocoon/whiteboard/block-deployer/src/client/org/apache/cocoon/blockdeployer/cli/Launcher.java
    cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/DeploymentService.java
    cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java

Modified: cocoon/whiteboard/block-deployer/src/client/org/apache/cocoon/blockdeployer/cli/Launcher.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/client/org/apache/cocoon/blockdeployer/cli/Launcher.java?view=diff&r1=159014&r2=159015
==============================================================================
--- cocoon/whiteboard/block-deployer/src/client/org/apache/cocoon/blockdeployer/cli/Launcher.java (original)
+++ cocoon/whiteboard/block-deployer/src/client/org/apache/cocoon/blockdeployer/cli/Launcher.java Fri Mar 25 06:04:47 2005
@@ -16,7 +16,12 @@
 package org.apache.cocoon.blockdeployer.cli;
 
 import java.io.File;
+import java.io.FileReader;
 
+import org.apache.cocoon.blockdeployer.DeploymentService;
+import org.apache.cocoon.blockdeployer.cli.deploy10.Deploy;
+import org.apache.cocoon.blockdeployer.logging.ConsoleLogger;
+import org.apache.cocoon.blockdeployer.logging.LoggerFacade;
 import org.apache.commons.cli.BasicParser;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.CommandLineParser;
@@ -24,18 +29,30 @@
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.OptionBuilder;
 import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
 
 /**
+ * <p>The main purpose of this class is reading options entered at command line and using these values
+ * to initialize the @link DeploymentService that takes care of the actual deployment. This class is
+ * meant to remain as small as possible:</p>
+ * <ul>
+ *   <li>only setting up a logger</li>
+ *   <li>reading values from command line</li>
+ *   <li>create an object that configures the deployment process</li>
+ * </ul>
+ * <p>Another reason for keeping it small is that unit testing of a main method isn't easy.</p>
+ * 
  * @since 0.1
  */
 public class Launcher {
     
     private static final String OPT_HELP = "help";
+    private static final String OPT_HELP1 = "?";
     private static final String OPT_FILE = "file";    
     private static final String OPT_QUIET = "quiet";
     private static final String OPT_VERBOSE = "verbose";
     private static final String OPT_LOGFILE = "logfile";  
-    private static final String OPT_DEVMODE = "devmode";
+    
 	private static final String DEFAULT_DEPLOYMENT_DESCRIPTOR_FILE = "deploy.xml";
     
     /**
@@ -44,27 +61,36 @@
      * @param args
      */
 	public static void main(String[] args) {
+        // setup the logger
+        LoggerFacade logger = new ConsoleLogger(LoggerFacade.LOG_ERROR);
+        
 		// create the parser
 		CommandLineParser parser = new BasicParser();
         Options options = createOptions();
         CommandLine line = null;
-        boolean devmode = false;
+        try {
+            line = parser.parse( options, args );
+        } catch (ParseException ex) {
+            ex.printStackTrace();
+        }
         
         String configuration = null;
-        
 		try {
             if(line.hasOption(OPT_QUIET) && line.hasOption(OPT_VERBOSE)) {
-                System.err.println("Output can't be extra quiet and verbose at the same time.");
+                logger.error("Output can't be extra quiet and verbose at the same time.");
                 printHelpAndExit(options);
             }
+            if(line.hasOption(OPT_QUIET)) {
+                logger.setLoglevel(LoggerFacade.LOG_WARN);
+            }
+            if(line.hasOption(OPT_VERBOSE)) {
+                logger.setLoglevel(LoggerFacade.LOG_DEBUG);
+            }
 			// parse the command line arguments
 			line = parser.parse(options, args);
-            if(line.hasOption(OPT_HELP)) {
+            if(line.hasOption(OPT_HELP) || line.hasOption(OPT_HELP1)) {
             	printHelpAndExit(options);
             }
-            if(line.hasOption(OPT_DEVMODE)) {
-            	devmode = true;
-            }
             if(line.hasOption(OPT_FILE)) {
             	configuration = line.getOptionValue(OPT_FILE);
             } else {
@@ -72,20 +98,29 @@
             }
 
 		} catch (org.apache.commons.cli.ParseException exp) {
-			System.err.println(exp.getMessage());
+			logger.error(exp.getMessage());
             printHelpAndExit(options);            
-		}
-        
-        File basedir = new File("");
-        
-        System.out.println("file configuring deployment: " + configuration);
-        
+		}   
+
+        // check whether deployment configuration file exists and is a file
+        File confFile = new File(configuration);
+        if(!confFile.exists() || !confFile.isFile()) {
+            logger.error("Deployment configuration file '" + confFile.getName() + "' does not exist!");
+            printHelpAndExit(options);
+        }
+
         // parse deployment configuration and setup the configuration object
-        
-        // setup logging
-        
-        // call the deployment service, either full deploy (block is physically installed) 
-        // or devDeploy (nothing is copied)
+        Deploy deploy = null;
+        try {
+            deploy = (Deploy) Deploy.unmarshal(new FileReader(confFile));
+        } catch (Exception ex) {
+            logger.error(Launcher.class, confFile.getName() + " caused problems: " + ex.getMessage());
+            printHelpAndExit(options);
+        }
+        
+        // call the deployment service that deploys the application server and the blocks
+        logger.debug(Launcher.class, "Deplyoment is configured by " + confFile.getName() + ".");
+        DeploymentService.deploy(deploy, logger);
         
 	}
 
@@ -97,22 +132,27 @@
 
 	public static Options createOptions() {
 		Option help = new Option(OPT_HELP, "print this message");
+        Option help1 = new Option(OPT_HELP1, "print this message");
 		Option file = OptionBuilder.withArgName(OPT_FILE)
                                    .hasArg()
                                    .withDescription("the COB deployment descriptor (default is \"deploy.xml\")")
                                    .create(OPT_FILE);
+        Option logfile = OptionBuilder.withArgName(OPT_LOGFILE)
+        .hasArg()
+        .withDescription("log file")
+        .create(OPT_FILE);        
         Option quiet = new Option(OPT_QUIET, "be extra quiet");
         Option verbose = new Option(OPT_VERBOSE, "be extra verbose");
-        
-        Option devmode = new Option(OPT_DEVMODE, "deploy block in development mode (block content is referenced)");
-        
+            
 		Options options = new Options();
-		options.addOption(file);       
+		options.addOption(file); 
+        options.addOption(logfile);
 		options.addOption(help);
+        options.addOption(help1);
         options.addOption(verbose);
         options.addOption(quiet);
    
 		return options;
 	}
-
+    
 }

Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/DeploymentService.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/DeploymentService.java?view=diff&r1=159014&r2=159015
==============================================================================
--- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/DeploymentService.java (original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/DeploymentService.java Fri Mar 25 06:04:47 2005
@@ -15,8 +15,7 @@
  */
 package org.apache.cocoon.blockdeployer;
 
-import org.apache.cocoon.blockdeployer.configuration.DeploymentConfigurationDTO10;
-import org.apache.cocoon.blockdeployer.configuration.DeploymentConfigurationException;
+import org.apache.cocoon.blockdeployer.cli.deploy10.Deploy;
 import org.apache.cocoon.blockdeployer.logging.LoggerFacade;
 
 /**
@@ -25,20 +24,30 @@
 public class DeploymentService {
     
     /**
-     * Deploy blocks using the information in the {@link DeploymentConfigurationDTO10}.
+     * Deploy blocks
      * @param conf
      * @param logger
      */
-    public static void deploy(DeploymentConfigurationDTO10 conf, LoggerFacade logger) throws DeploymentConfigurationException {
+    public static void deploy(Deploy conf, LoggerFacade logger) {
         if(logger == null) {
         	throw new NullPointerException("The logger mustn't be null.");
         }
-        checkDeploymentConfiguration(conf, logger);
+        logger.debug(DeploymentService.class, "deploy service called (" + conf.getClass().getName() + ")");
+        
+        // check for Cocoon Application Server (only Cocoon 2.2 is supported)
+        String casVersion = conf.getInstall().getCocoon().getVersion();
+        logger.info("Cocoon Application server: version=" + casVersion);
+
+        // initialize the repository with all its locators (a locator is created by the LocatorFactory)
+        
+        // get the blocks from the repository
+        
+        // deploy the blocks to the Cocoon server
+        
+        // deploy the blocks to locators that have the attribute 'add-unavailable-blocks' set
+        
+        
     }
     
-    protected static void checkDeploymentConfiguration(DeploymentConfigurationDTO10 conf, LoggerFacade logger)
-        throws DeploymentConfigurationException {
-       
-    }
     
 }

Copied: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/logging/ConsoleLogger.java (from r159011, cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/logging/ConsoleLogger.java)
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/logging/ConsoleLogger.java?view=diff&rev=159015&p1=cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/logging/ConsoleLogger.java&r1=159011&p2=cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/logging/ConsoleLogger.java&r2=159015
==============================================================================
--- cocoon/whiteboard/block-deployer/test/junit/org/apache/cocoon/blockdeployer/logging/ConsoleLogger.java (original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/logging/ConsoleLogger.java Fri Mar 25 06:04:47 2005
@@ -19,9 +19,32 @@
  * @since 0.1
  */
 public class ConsoleLogger implements LoggerFacade {
+    
+    public final static int LOGLEVEL_DEBUG = 1;
+    public final static int LOGLEVEL_INFO = 2;
+    public final static int LOGLEVEL_WARN = 3;
+    public final static int LOGLEVEL_ERROR = 4;
+    
+    int loglevel = -1;
+    
+    public ConsoleLogger(String level) {
+        this.setLoglevel(level);
+    }
+    
+    public void setLoglevel(String level) {
+        if(LoggerFacade.LOG_ERROR.equals(level)) loglevel = LOGLEVEL_ERROR;
+        if(LoggerFacade.LOG_WARN.equals(level))  loglevel = LOGLEVEL_WARN;
+        if(LoggerFacade.LOG_INFO.equals(level))  loglevel = LOGLEVEL_INFO;
+        if(LoggerFacade.LOG_DEBUG.equals(level)) loglevel = LOGLEVEL_DEBUG;
+        
+        if( loglevel < 1 ) {
+            throw new IllegalArgumentException(
+                    "The loglevel has to be either ERROR, WARN, INFO or DEBUG");
+        }        
+    }
 
 	public void debug(String msg) {
-		System.out.println("  DEBUG: " + msg);
+		if(isDebugEnabled()) System.out.println("  DEBUG: " + msg);
 	}
     
     public void debug(Class clazz, String msg) {
@@ -29,11 +52,11 @@
     }
 
 	public boolean isDebugEnabled() {
-		return true;
+		return loglevel == 1 ? true : false;
 	}
 
 	public void info(String msg) {
-		System.out.println("  INFO: " + msg);
+		if(isInfoEnabled()) System.out.println(msg);
 	}
 
     public void info(Class clazz, String msg) {
@@ -41,11 +64,11 @@
     }    
     
 	public boolean isInfoEnabled() {
-		return true;
-	}
+        return loglevel <= 2 ? true : false;
+    }
 
 	public void warn(String msg) {
-		System.out.println("  WARN: " + msg);
+		if(isWarnEnabled()) System.out.println("  WARN: " + msg);
 	}
 
     public void warn(Class clazz, String msg) {
@@ -53,11 +76,11 @@
     }
     
 	public boolean isWarnEnabled() {
-		return true;
+        return loglevel <= 3 ? true : false;
 	}
 
 	public void error(String msg) {
-		System.out.println("  ERROR: " + msg);
+		if(isWarnEnabled()) System.out.println("  ERROR: " + msg);
 	}
 
     public void error(Class clazz, String msg) {
@@ -74,7 +97,7 @@
     }
     
 	public boolean isErrorEnabled() {
-		return true;
+        return loglevel <= 4 ? true : false;
 	}
 
 }

Modified: cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java
URL: http://svn.apache.org/viewcvs/cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java?view=diff&r1=159014&r2=159015
==============================================================================
--- cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java (original)
+++ cocoon/whiteboard/block-deployer/src/impl/org/apache/cocoon/blockdeployer/repository/ApplicationServer22Locator.java Fri Mar 25 06:04:47 2005
@@ -25,17 +25,12 @@
 import java.util.zip.ZipInputStream;
 
 import org.apache.cocoon.blockdeployer.block.RemoteBlock;
-import org.apache.cocoon.blockdeployer.block.descriptor.BlockDescriptor;
 import org.apache.cocoon.blockdeployer.locking.Lock;
 import org.apache.cocoon.blockdeployer.locking.LockingException;
 import org.apache.cocoon.blockdeployer.logging.LoggerFacade;
-import org.apache.cocoon.blockdeployer.repository.Deployable;
-import org.apache.cocoon.blockdeployer.repository.Locator;
-import org.apache.cocoon.blockdeployer.repository.Lockable;
 import org.apache.cocoon.blockdeployer.utils.CommonsTransactionLogger;
 import org.apache.cocoon.blockdeployer.utils.LocatorUtils;
-import org.apache.cocoon.blockdeployer.wiring.WiredBlockDescriptor10;
-import org.apache.cocoon.blockdeployer.wiring.Wiring;
+import org.apache.cocoon.blockdeployer.wiring.wiring10.Wiring;
 import org.apache.commons.transaction.file.FileResourceManager;
 import org.apache.commons.transaction.file.ResourceManagerException;
 import org.apache.commons.transaction.file.ResourceManagerSystemException;
@@ -50,7 +45,6 @@
 public class ApplicationServer22Locator implements Locator, Deployable, Lockable {
 
     private File basedir;
-    private Wiring wiring;
     private LoggerFacade logger;
 
     /**
@@ -62,17 +56,12 @@
      * @param wiring
      *            is the {@link Wiring} (representing wiring.xml) of a Cocoon server
      */
-    public ApplicationServer22Locator(File basedir, Wiring wiring, LoggerFacade logger ) {
+    public ApplicationServer22Locator(File basedir, LoggerFacade logger ) {
         if(logger == null) {
             throw new NullPointerException("You have to set a logger!");
         }        
         LocatorUtils.checkBasedir(basedir, logger, ApplicationServer22Locator.class);
-        // FIXME shouldn't be the wiring encapsulated by this locator? currently its a mix ... :-/
-        if(wiring == null) {
-            throw new NullPointerException("The wiring mustn't be null!");
-        }
         this.basedir = basedir;
-        this.wiring = wiring;
         this.logger = logger;
     }
 
@@ -205,19 +194,6 @@
         }
     }
 
-    /**
-     * Create a wiring descriptor out of the block descriptor
-     * 
-     * @param Block
-     * @return returns a WiredBlockDescriptor10 object containing
-     */
-    protected static WiredBlockDescriptor10 createBlockWiringDescriptor(
-            RemoteBlock block) {
-        WiredBlockDescriptor10 wrbd = new WiredBlockDescriptor10();
-        BlockDescriptor rbd = block.getBlockDescriptor();
-        wrbd.setId(rbd.getBlockId());
-        return wrbd;
-    }
 
     public void setLock(Lock lock) throws LockingException {