ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationManagerServant.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationManagerServant.java (file contents):
Revision 1.12 by tdb, Thu Mar 1 20:22:21 2001 UTC vs.
Revision 1.26 by tdb, Sun Aug 1 10:40:54 2004 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * http://www.i-scream.org
4 + * Copyright (C) 2000-2002 i-scream
5 + *
6 + * This program is free software; you can redistribute it and/or
7 + * modify it under the terms of the GNU General Public License
8 + * as published by the Free Software Foundation; either version 2
9 + * of the License, or (at your option) any later version.
10 + *
11 + * This program is distributed in the hope that it will be useful,
12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 + * GNU General Public License for more details.
15 + *
16 + * You should have received a copy of the GNU General Public License
17 + * along with this program; if not, write to the Free Software
18 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 + */
20 +
21   //---PACKAGE DECLARATION---
22 < package uk.ac.ukc.iscream.core;
22 > package uk.org.iscream.cms.server.core;
23  
24   //---IMPORTS---
25 < import uk.ac.ukc.iscream.util.*;
26 < import uk.ac.ukc.iscream.componentmanager.*;
25 > import uk.org.iscream.cms.util.*;
26 > import uk.org.iscream.cms.server.componentmanager.*;
27 > import java.net.InetAddress;
28 > import java.net.UnknownHostException;
29   import java.util.*;
30   import java.io.*;
31  
# Line 18 | Line 40 | import java.io.*;
40   *
41   * It also relies on the System.properties to set internal values.
42   *
21 * ###
22 * A point to note is that this class does NOT yet manage
23 * created configurations which may cause memory problems!
24 * ###
25 *
43   * @author  $Author$
44   * @version $Id$
45   */
# Line 45 | Line 62 | class ConfigurationManagerServant extends Configuratio
62       */
63      ConfigurationManagerServant() {
64          // assign some local variables
65 <        _configPath = System.getProperty("uk.ac.ukc.iscream.ConfigurationLocation");
66 <        _systemConfigFile = System.getProperty("uk.ac.ukc.iscream.SystemConfigurationFile");
65 >        _configPath = System.getProperty("uk.org.iscream.cms.server.ConfigurationLocation");
66 >        _systemConfigFile = System.getProperty("uk.org.iscream.cms.server.SystemConfigurationFile");
67  
68          // load the system config
69          loadSystemConfig();
# Line 90 | Line 107 | class ConfigurationManagerServant extends Configuratio
107          }
108  
109          // search config for group membership
110 <        LinkedList groups = getGroupMembership(source);
111 <
110 >        // and obain a list of groups by name
111 >        LinkedList nameGroups = getGroupMembership(source);
112          // add the hosts individual config to the start of the list
113 <        groups.addFirst(source);
113 >        nameGroups.addFirst(source);
114 >        
115 >        // this list will be used to compile the groupings
116 >        LinkedList groups = new LinkedList();
117 >                    
118 >        // if we are dealing with a Host.<hostname> request, then we also
119 >        // want to look for ip address details, as configuration entries may relate to it
120 >        // if we can't resolve it, we don't look.
121 >        LinkedList ipGroups = null;
122 >        if (source.startsWith("Host.")) {
123 >            // hostname is after Host.
124 >            String hostname = source.substring(5);
125 >            try {
126 >                String ip = "Host." + InetAddress.getByName(hostname).getHostAddress();
127 >                ipGroups = getGroupMembership(ip);
128 >                ipGroups.addFirst(ip);
129 >                // add to our list of groups
130 >                groups.addAll(ipGroups);
131 >            } catch (UnknownHostException e) {
132 >                _logger.write(toString(), Logger.ERROR, "could not resolve hostname - " + hostname);
133 >            }
134 >        }
135 >        
136 >        // add the rest of the groups to the end        
137 >        groups.addAll(nameGroups);
138  
139          Iterator i = groups.iterator();
140          String fileList = "";
# Line 123 | Line 164 | class ConfigurationManagerServant extends Configuratio
164              }
165          }
166          // add the system config as the final check
167 <        fileList += _systemConfigFile + ";";
167 >        fileList = _systemConfigFile + ";" + fileList;
168          _logger.write(toString(), Logger.DEBUG, "config tree - " + fileList);
169          
170          // build the configuration
# Line 163 | Line 204 | class ConfigurationManagerServant extends Configuratio
204       * Overrides the {@link java.lang.Object#toString() Object.toString()}
205       * method to provide clean logging (every class should have this).
206       *
207 <     * This uses the uk.ac.ukc.iscream.util.FormatName class
207 >     * This uses the uk.org.iscream.cms.util.FormatName class
208       * to format the toString()
209       *
210       * @return the name of this class and its CVS revision
# Line 281 | Line 322 | class ConfigurationManagerServant extends Configuratio
322       * @return the list of groups that this source is a member of
323       */
324      private LinkedList getGroupMembership(String source) {
325 +        _logger.write(toString(), Logger.DEBUG, "searching groups for - " + source);
326          LinkedList groupMembership = new LinkedList();        
327          Iterator i = new TreeSet(_systemConfigHolder.keySet()).iterator();
328          while(i.hasNext()) {
329              String key = (String) i.next();
330 +            // look for a key that's a group entry
331              if (key.startsWith("group.")) {
332 +                // get the list of hosts in the group
333                  String group = _systemConfig.getProperty(key);
334 <                if (group.indexOf(source) != -1) {
334 >                if(groupMatch(source, group)) {
335                      groupMembership.add(key.substring(6));
336 +                    _logger.write(toString(), Logger.DEBUG, "group match found for - " + source + " in group - " + key);
337                  }
338              }  
339          }
340          return groupMembership;
341 <    }    
341 >    }
342 >    
343 >    /**
344 >     * Checks that a given source is matched within the
345 >     * given list of hosts. For example:<br>
346 >     * <br>
347 >     * Given "stue5de.ukc.ac.uk"<br>
348 >     * And   "raptor.ukc.ac.uk;stue*.ukc.ac.uk<br>
349 >     * <br>
350 >     * This method would return true as there is a match.
351 >     *
352 >     * This method will also match if the source is exactly
353 >     * matched within the group of hosts (ie. no wildcard).
354 >     *
355 >     * @param source the string to look for
356 >     * @param group the group to search for a match
357 >     *
358 >     * @return if there is a match
359 >     */
360 >    public static boolean groupMatch(String source, String group) {
361 >        StringTokenizer st = new StringTokenizer(group, ";");
362 >        // go through all the hosts in the group
363 >        while (st.hasMoreTokens()) {
364 >            String host = st.nextToken();
365 >            if(StringUtils.wildcardMatch(source, host)) {
366 >                return true;
367 >            }
368 >        }
369 >        // not had a match
370 >        return false;
371 >    }
372  
373      /**
374       * Build the properties as a Configuration to be
# Line 315 | Line 390 | class ConfigurationManagerServant extends Configuratio
390                  
391                  // some holders for variables
392                  File currentFile;
393 <                long lastModified, newLastModified;
394 <                Properties properties, prevProperties;
393 >                long lastModified = 0, newLastModified = 0;
394 >                Properties properties = null, prevProperties = null;
395                  
396                  // the root of all configurations will be the system config
397                  // so we need to open the properties of that
398                  Properties defaultProperties = new Properties();
324                currentFile = new File(_configPath, _systemConfigFile);
325                lastModified = currentFile.lastModified();
326                defaultProperties.load(new FileInputStream(currentFile));
399                  
400                  // This loop then iterates over the file list
401                  // creates the properties to be passed to the
402                  // Configuration constructor
403 <                do {
403 >                while (st.hasMoreTokens()) {
404                      properties = new Properties(defaultProperties);
405                      currentFile = new File(_configPath, st.nextToken());
406                      newLastModified = currentFile.lastModified();
# Line 337 | Line 409 | class ConfigurationManagerServant extends Configuratio
409                      }
410                      properties.load(new FileInputStream(currentFile));
411                      defaultProperties = properties;
412 <                } while (st.hasMoreTokens());
412 >                }
413  
414                  // this creates the configuration, all nice, ready to be returned
415                  ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified);
416                  org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref);
417                  config = ConfigurationHelper.narrow(objRef);
418 <
418 >                _logger.write(toString(), Logger.DEBUG, "returning built configuration");
419              } catch (Exception e) {
420                  // not sure what to do here
421                  // so we just log the error

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines