changeset 12:2f82b0faeb89

Javadoc.
author Mikhail Kryshen <mikhail@kryshen.net>
date Tue, 03 Nov 2009 00:36:43 +0300
parents 3a71cbe721f9
children 618d0df5d46c
files src/kryshen/catalina/startup/HomesUserConfig.java src/kryshen/catalina/startup/PasswdUserConfig.java src/kryshen/catalina/startup/UserConfig.java
diffstat 3 files changed, 94 insertions(+), 30 deletions(-) [+]
line diff
     1.1 --- a/src/kryshen/catalina/startup/HomesUserConfig.java	Mon Nov 02 23:47:14 2009 +0300
     1.2 +++ b/src/kryshen/catalina/startup/HomesUserConfig.java	Tue Nov 03 00:36:43 2009 +0300
     1.3 @@ -9,14 +9,14 @@
     1.4  import org.apache.juli.logging.LogFactory;
     1.5  
     1.6  /**
     1.7 + * Event listener for Host that deploys and updates applications 
     1.8 + * provided by users. Files in the specified base directory are 
     1.9 + * considered tp be user home directories.
    1.10   *
    1.11   * @author Mikhail Kryshen
    1.12   */
    1.13  public class HomesUserConfig extends UserConfig {
    1.14  
    1.15 -    protected static org.apache.juli.logging.Log log =
    1.16 -            org.apache.juli.logging.LogFactory.getLog(HomesUserConfig.class);
    1.17 -
    1.18      /**
    1.19       * The base directory containing user home directories.
    1.20       */
     2.1 --- a/src/kryshen/catalina/startup/PasswdUserConfig.java	Mon Nov 02 23:47:14 2009 +0300
     2.2 +++ b/src/kryshen/catalina/startup/PasswdUserConfig.java	Tue Nov 03 00:36:43 2009 +0300
     2.3 @@ -9,6 +9,8 @@
     2.4  import org.apache.juli.logging.LogFactory;
     2.5  
     2.6  /**
     2.7 + * Event listener for Host that deploys and updates applications 
     2.8 + * provided by users listed in passwd database.
     2.9   *
    2.10   * @author Mikhail Kryshen
    2.11   */
    2.12 @@ -31,6 +33,7 @@
    2.13       */
    2.14      private String passwd = "/etc/passwd";
    2.15  
    2.16 +    
    2.17      public PasswdUserConfig() {
    2.18          log = LogFactory.getLog(PasswdUserConfig.class);
    2.19      }
     3.1 --- a/src/kryshen/catalina/startup/UserConfig.java	Mon Nov 02 23:47:14 2009 +0300
     3.2 +++ b/src/kryshen/catalina/startup/UserConfig.java	Tue Nov 03 00:36:43 2009 +0300
     3.3 @@ -5,6 +5,11 @@
     3.4  import org.apache.juli.logging.LogFactory;
     3.5  
     3.6  /**
     3.7 + * Event listener for Host that deploys and updates applications
     3.8 + * provided by users. In multi-app mode (appsPerUser property &gt 1)
     3.9 + * each user's application is mapped to "/~username/application" path,
    3.10 + * ROOT is mapped to "/~username". In single-app mode (appsPerUser = 1)
    3.11 + * each user could have single webapp mapped to "/~username".
    3.12   *
    3.13   * @author Mikhail Kryshen
    3.14   */
    3.15 @@ -15,7 +20,12 @@
    3.16       */
    3.17      private String directoryName = "public_webapps";
    3.18  
    3.19 -    
    3.20 +    /**
    3.21 +     * Maximum number of application each user is allowed to deploy.
    3.22 +     */
    3.23 +    private int appsPerUser = -1;
    3.24 +
    3.25 +
    3.26      protected UserConfig() {
    3.27          log = LogFactory.getLog(UserConfig.class);
    3.28      }
    3.29 @@ -32,12 +42,33 @@
    3.30       *  Set the directory name to be searched for webapps for each user
    3.31       *  (relative to the user's home direcotry).
    3.32       * 
    3.33 -     * @param directoryName The new directory name
    3.34 +     * @param directoryName The new directory name.
    3.35       */
    3.36      public void setDirectoryName(String directoryName) {
    3.37          this.directoryName = directoryName;
    3.38      }
    3.39  
    3.40 +    
    3.41 +    /**
    3.42 +     * Returns the maximum number of application each user is allowed to
    3.43 +     * deploy.
    3.44 +     */
    3.45 +    public int getAppsPerUser() {
    3.46 +        return appsPerUser;
    3.47 +    }
    3.48 +
    3.49 +    /**
    3.50 +     * Set the maximum number of application each user is allowed to deploy.
    3.51 +     */
    3.52 +    public void setAppsPerUser(int appsPerUser) {
    3.53 +        if (appsPerUser < 1 && appsPerUser != -1) {
    3.54 +            throw new IllegalArgumentException("Invalid appsPerUser value.");
    3.55 +        }
    3.56 +
    3.57 +        this.appsPerUser = appsPerUser;
    3.58 +    }
    3.59 +
    3.60 +
    3.61      @Override
    3.62      protected void deployApps() {       
    3.63          deployUserApps();
    3.64 @@ -57,8 +88,8 @@
    3.65      /**
    3.66       * Deploy applications (if any) for specific user.
    3.67       *
    3.68 -     * @param user Username
    3.69 -     * @param home User home directory
    3.70 +     * @param user Username.
    3.71 +     * @param home User home directory.
    3.72       */
    3.73      protected void deployUserApps(String user, File home) {
    3.74          File base = new File(home, directoryName);
    3.75 @@ -67,22 +98,41 @@
    3.76              return;
    3.77          }
    3.78  
    3.79 -        // TODO: deployWars
    3.80 -
    3.81 -        deployDirectories(user, base, base.list());
    3.82 -    }
    3.83 -
    3.84 -    /**
    3.85 -     * Deploy user webapp directories.
    3.86 -     */
    3.87 -    protected void deployDirectories(String user, File base, String[] files) {
    3.88 +        String[] files = base.list();
    3.89  
    3.90          if (files == null) {
    3.91              log.warn("Error reading base directory: " + base.getPath() + ".");
    3.92              return;
    3.93          }
    3.94  
    3.95 -        for (int i = 0; i < files.length; i++) {
    3.96 +        // TODO: deployWars
    3.97 +
    3.98 +        if (appsPerUser == 1) {
    3.99 +            // Single application mode.
   3.100 +            deployUserApp(user, base, "ROOT");
   3.101 +        } else {
   3.102 +            // Multiple applications mode.
   3.103 +            deployUserDirectories(user, base, files);
   3.104 +        }
   3.105 +    }
   3.106 +
   3.107 +    /**
   3.108 +     * Deploy user application directories.
   3.109 +     *
   3.110 +     * @param user Username.
   3.111 +     * @param base Application base directory.
   3.112 +     * @param files Array of directories to deploy.
   3.113 +     */
   3.114 +    protected void deployUserDirectories(String user, File base, 
   3.115 +            String[] files) {
   3.116 +
   3.117 +        int appsNum = files.length;
   3.118 +
   3.119 +        if (appsNum > appsPerUser) {
   3.120 +            appsNum = appsPerUser;
   3.121 +        }
   3.122 +
   3.123 +        for (int i = 0; i < appsNum; i++) {
   3.124              if (files[i].equalsIgnoreCase("META-INF")) {
   3.125                  continue;
   3.126              }
   3.127 @@ -97,19 +147,30 @@
   3.128                  continue;
   3.129              }
   3.130  
   3.131 -            String contextPath;
   3.132 -
   3.133 -            if (files[i].equals("ROOT")) {
   3.134 -                contextPath = "/~" + user;
   3.135 -            } else {
   3.136 -                contextPath = "/~" + user + '/' + files[i].replace('#', '/');
   3.137 -            }
   3.138 -
   3.139 -            if (isServiced(contextPath)) {
   3.140 -                continue;
   3.141 -            }
   3.142 -
   3.143 -            deployDirectory(contextPath, dir, dir.getAbsolutePath());
   3.144 +            deployUserApp(user, dir, files[i]);
   3.145          }
   3.146      }
   3.147 +
   3.148 +    /**
   3.149 +     * Deploy user application.
   3.150 +     *
   3.151 +     * @param user Username.
   3.152 +     * @param dir Application directory.
   3.153 +     * @param app Application name.
   3.154 +     */
   3.155 +    protected void deployUserApp(String user, File dir, String app) {
   3.156 +        String contextPath;
   3.157 +
   3.158 +        if (app.equals("ROOT")) {
   3.159 +            contextPath = "/~" + user;
   3.160 +        } else {
   3.161 +            contextPath = "/~" + user + '/' + app.replace('#', '/');
   3.162 +        }
   3.163 +
   3.164 +        if (isServiced(contextPath)) {
   3.165 +            return;
   3.166 +        }
   3.167 +
   3.168 +        deployDirectory(contextPath, dir, dir.getAbsolutePath());
   3.169 +    }
   3.170  }