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.15 by ajm, Sat Mar 3 14:52:56 2001 UTC vs.
Revision 1.23 by tdb, Sat May 18 18:16:01 2002 UTC

# Line 1 | Line 1
1 + /*
2 + * i-scream central monitoring system
3 + * Copyright (C) 2000-2002 i-scream
4 + *
5 + * This program is free software; you can redistribute it and/or
6 + * modify it under the terms of the GNU General Public License
7 + * as published by the Free Software Foundation; either version 2
8 + * of the License, or (at your option) any later version.
9 + *
10 + * This program is distributed in the hope that it will be useful,
11 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 + * GNU General Public License for more details.
14 + *
15 + * You should have received a copy of the GNU General Public License
16 + * along with this program; if not, write to the Free Software
17 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 + */
19 +
20   //---PACKAGE DECLARATION---
21 < package uk.ac.ukc.iscream.core;
21 > package uk.org.iscream.cms.server.core;
22  
23   //---IMPORTS---
24 < import uk.ac.ukc.iscream.util.*;
25 < import uk.ac.ukc.iscream.componentmanager.*;
24 > import uk.org.iscream.cms.server.util.*;
25 > import uk.org.iscream.cms.server.componentmanager.*;
26   import java.net.InetAddress;
27   import java.net.UnknownHostException;
28   import java.util.*;
# Line 20 | Line 39 | import java.io.*;
39   *
40   * It also relies on the System.properties to set internal values.
41   *
23 * ###
24 * A point to note is that this class does NOT yet manage
25 * created configurations which may cause memory problems!
26 * ###
27 *
42   * @author  $Author$
43   * @version $Id$
44   */
# Line 47 | Line 61 | class ConfigurationManagerServant extends Configuratio
61       */
62      ConfigurationManagerServant() {
63          // assign some local variables
64 <        _configPath = System.getProperty("uk.ac.ukc.iscream.ConfigurationLocation");
65 <        _systemConfigFile = System.getProperty("uk.ac.ukc.iscream.SystemConfigurationFile");
64 >        _configPath = System.getProperty("uk.org.iscream.cms.server.ConfigurationLocation");
65 >        _systemConfigFile = System.getProperty("uk.org.iscream.cms.server.SystemConfigurationFile");
66  
67          // load the system config
68          loadSystemConfig();
# Line 92 | Line 106 | class ConfigurationManagerServant extends Configuratio
106          }
107  
108          // search config for group membership
109 <        LinkedList groups = getGroupMembership(source);
109 >        // and obain a list of groups by name
110 >        LinkedList nameGroups = getGroupMembership(source);
111 >        // add the hosts individual config to the start of the list
112 >        nameGroups.addFirst(source);
113          
114 +        // this list will be used to compile the groupings
115 +        LinkedList groups = new LinkedList();
116 +                    
117          // if we are dealing with a Host.<hostname> request, then we also
118          // want to look for ip address details, as configuration entries may relate to it
119          // if we can't resolve it, we don't look.
120 +        LinkedList ipGroups = null;
121          if (source.startsWith("Host.")) {
122              // hostname is after Host.
123              String hostname = source.substring(5);
124              try {
125                  String ip = "Host." + InetAddress.getByName(hostname).getHostAddress();
126 <                LinkedList ipGroups = getGroupMembership(ip);
127 <                groups.addFirst(ip);
126 >                ipGroups = getGroupMembership(ip);
127 >                ipGroups.addFirst(ip);
128 >                // add to our list of groups
129                  groups.addAll(ipGroups);
130              } catch (UnknownHostException e) {
131                  _logger.write(toString(), Logger.ERROR, "could not resolve hostname - " + hostname);
132              }
133          }
134 +        
135 +        // add the rest of the groups to the end        
136 +        groups.addAll(nameGroups);
137  
113        // add the hosts individual config to the start of the list
114        groups.addFirst(source);
115
138          Iterator i = groups.iterator();
139          String fileList = "";
140          while (i.hasNext()) {
# Line 181 | Line 203 | class ConfigurationManagerServant extends Configuratio
203       * Overrides the {@link java.lang.Object#toString() Object.toString()}
204       * method to provide clean logging (every class should have this).
205       *
206 <     * This uses the uk.ac.ukc.iscream.util.FormatName class
206 >     * This uses the uk.org.iscream.cms.server.util.FormatName class
207       * to format the toString()
208       *
209       * @return the name of this class and its CVS revision
# Line 299 | Line 321 | class ConfigurationManagerServant extends Configuratio
321       * @return the list of groups that this source is a member of
322       */
323      private LinkedList getGroupMembership(String source) {
324 <        _logger.write(toString(), Logger.DEBUG, "searching group members for - " + source);
324 >        _logger.write(toString(), Logger.DEBUG, "searching groups for - " + source);
325          LinkedList groupMembership = new LinkedList();        
326          Iterator i = new TreeSet(_systemConfigHolder.keySet()).iterator();
327          while(i.hasNext()) {
328              String key = (String) i.next();
329 +            // look for a key that's a group entry
330              if (key.startsWith("group.")) {
331 +                // get the list of hosts in the group
332                  String group = _systemConfig.getProperty(key);
333 <                // if it is in the group
310 <                if (group.indexOf(source) != -1) {
333 >                if(groupMatch(source, group)) {
334                      groupMembership.add(key.substring(6));
335 <                
313 <                // if there are wildcards in the group
314 <                } else if (group.indexOf("*") != -1) {
315 <                    // check the wildcards apply to this srce
316 <                    if( wildcardCheck(source, group)) {
317 <                        groupMembership.add(key.substring(6));
318 <                    }
335 >                    _logger.write(toString(), Logger.DEBUG, "group match found for - " + source + " in group - " + key);
336                  }
320                
337              }  
338          }
339          return groupMembership;
340 <    }    
341 <
340 >    }
341 >    
342      /**
343 <     * Checks that a given string is not matched within the
344 <     * given list of strings. eg:<br>
343 >     * Checks that a given source is matched within the
344 >     * given list of hosts. For example:<br>
345       * <br>
346       * Given "stue5de.ukc.ac.uk"<br>
347       * And   "raptor.ukc.ac.uk;stue*.ukc.ac.uk<br>
348       * <br>
349 <     * This method would return true as there is a match
350 <     *
349 >     * This method would return true as there is a match.
350 >     *
351 >     * This method will also match if the source is exactly
352 >     * matched within the group of hosts (ie. no wildcard).
353 >     *
354       * @param source the string to look for
355 <     * @param group the group to search for a wilcard entry
355 >     * @param group the group to search for a match
356       *
357       * @return if there is a match
358       */
359 <    private boolean wildcardCheck(String source, String group) {
341 <        boolean foundMatch = false;
359 >    public static boolean groupMatch(String source, String group) {
360          StringTokenizer st = new StringTokenizer(group, ";");
361          // go through all the hosts in the group
362          while (st.hasMoreTokens()) {
363              String host = st.nextToken();
364 <            // this host has wildcards
365 <            if(host.indexOf("*") != -1) {
348 <                StringTokenizer hostst = new StringTokenizer(host, "*");
349 <                String part = "";
350 <                int index = 0;
351 <                // the first token will be everything at the start
352 <                // unless it starts with a wildcard
353 <                if(!host.startsWith("*")) {
354 <                    part = hostst.nextToken();
355 <                    if (source.startsWith(part)) {
356 <                        foundMatch = true;
357 <                        index = part.length();
358 <                    }
359 <                // all of the start of the string is matched
360 <                } else {
361 <                    foundMatch = true;
362 <                }
363 <                // if the start matched, we want to check the rest...
364 <                if (foundMatch) {
365 <                    while (hostst.hasMoreTokens()) {
366 <                        part = hostst.nextToken();
367 <                        // if the next section can't be matched
368 <                        // then this isn't in the source
369 <                        if(source.substring(index).indexOf(part) == -1) {
370 <                            foundMatch = false;
371 <                            // we don't want to look through any more of it
372 <                            break;
373 <                        } else {
374 <                            foundMatch = true;
375 <                            index += source.substring(index).indexOf(part) + part.length();
376 <                        }
377 <                    }
378 <                    // if we reach here and we've found a match
379 <                    // we want to check that the last part
380 <                    // of the wildcard string is the last part
381 <                    // of the source, if it is, we break out
382 <                    // and finish as we've found a match.
383 <                    // if the end of the wildcard is a *, then
384 <                    // we don't care
385 <                    if (!host.endsWith("*") && foundMatch) {
386 <                        if ((source.endsWith(part))) {
387 <                            _logger.write(toString(), Logger.DEBUG, "wildcard match found for - " + source + " in - " + host);
388 <                            break;
389 <                        // if there is no match, say so so we go round again
390 <                        } else {
391 <                            foundMatch = false;
392 <                        }
393 <                    } else if (foundMatch) {
394 <                        _logger.write(toString(), Logger.DEBUG, "wildcard match found for - " + source + " in - " + host);
395 <                        break;
396 <                    }
397 <                }
364 >            if(StringUtils.wildcardMatch(source, host)) {
365 >                return true;
366              }
367          }
368 <        return foundMatch;
368 >        // not had a match
369 >        return false;
370      }
402
371  
372      /**
373       * Build the properties as a Configuration to be

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines