1 |
|
//---PACKAGE DECLARATION--- |
2 |
< |
package uk.ac.ukc.iscream.core; |
2 |
> |
package uk.org.iscream.cms.server.core; |
3 |
|
|
4 |
|
//---IMPORTS--- |
5 |
< |
import uk.ac.ukc.iscream.util.*; |
6 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
5 |
> |
import uk.org.iscream.cms.server.util.*; |
6 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
7 |
> |
import java.net.InetAddress; |
8 |
> |
import java.net.UnknownHostException; |
9 |
|
import java.util.*; |
10 |
|
import java.io.*; |
11 |
|
|
47 |
|
*/ |
48 |
|
ConfigurationManagerServant() { |
49 |
|
// assign some local variables |
50 |
< |
_configPath = System.getProperty("uk.ac.ukc.iscream.ConfigurationLocation"); |
51 |
< |
_systemConfigFile = System.getProperty("uk.ac.ukc.iscream.SystemConfigurationFile"); |
50 |
> |
_configPath = System.getProperty("uk.org.iscream.cms.server.ConfigurationLocation"); |
51 |
> |
_systemConfigFile = System.getProperty("uk.org.iscream.cms.server.SystemConfigurationFile"); |
52 |
|
|
53 |
|
// load the system config |
54 |
|
loadSystemConfig(); |
92 |
|
} |
93 |
|
|
94 |
|
// search config for group membership |
95 |
< |
LinkedList groups = getGroupMembership(source); |
96 |
< |
|
95 |
> |
// and obain a list of groups by name |
96 |
> |
LinkedList nameGroups = getGroupMembership(source); |
97 |
|
// add the hosts individual config to the start of the list |
98 |
< |
groups.addFirst(source); |
98 |
> |
nameGroups.addFirst(source); |
99 |
> |
|
100 |
> |
// this list will be used to compile the groupings |
101 |
> |
LinkedList groups = new LinkedList(); |
102 |
> |
|
103 |
> |
// if we are dealing with a Host.<hostname> request, then we also |
104 |
> |
// want to look for ip address details, as configuration entries may relate to it |
105 |
> |
// if we can't resolve it, we don't look. |
106 |
> |
LinkedList ipGroups = null; |
107 |
> |
if (source.startsWith("Host.")) { |
108 |
> |
// hostname is after Host. |
109 |
> |
String hostname = source.substring(5); |
110 |
> |
try { |
111 |
> |
String ip = "Host." + InetAddress.getByName(hostname).getHostAddress(); |
112 |
> |
ipGroups = getGroupMembership(ip); |
113 |
> |
ipGroups.addFirst(ip); |
114 |
> |
// add to our list of groups |
115 |
> |
groups.addAll(ipGroups); |
116 |
> |
} catch (UnknownHostException e) { |
117 |
> |
_logger.write(toString(), Logger.ERROR, "could not resolve hostname - " + hostname); |
118 |
> |
} |
119 |
> |
} |
120 |
> |
|
121 |
> |
// add the rest of the groups to the end |
122 |
> |
groups.addAll(nameGroups); |
123 |
|
|
124 |
|
Iterator i = groups.iterator(); |
125 |
|
String fileList = ""; |
126 |
|
while (i.hasNext()) { |
127 |
|
String groupName = (String) i.next(); |
128 |
< |
|
128 |
> |
_logger.write(toString(), Logger.DEBUG, "looking for config entry for - " + groupName); |
129 |
|
// we look for this entry in the systemConfig |
130 |
|
String configFile = _systemConfig.getProperty("config." + groupName); |
131 |
< |
_logger.write(toString(), Logger.DEBUG, "looking for config tree in - " + configFile); |
132 |
< |
|
133 |
< |
// get the file list of includes etc + the system config |
134 |
< |
String groupFileList = null; |
135 |
< |
try { |
136 |
< |
groupFileList = getIncludedFiles(configFile, "") + ";"; |
137 |
< |
} catch (Exception e) { |
138 |
< |
// not sure what to do here |
139 |
< |
// so we just log the error |
140 |
< |
_logger.write(toString(), Logger.ERROR, "ERROR - " + e); |
131 |
> |
// if there is a config entry then |
132 |
> |
if (configFile != null) { |
133 |
> |
_logger.write(toString(), Logger.DEBUG, "looking for config tree in - " + configFile); |
134 |
> |
|
135 |
> |
// get the file list of includes etc + the system config |
136 |
> |
String groupFileList = null; |
137 |
> |
try { |
138 |
> |
groupFileList = getIncludedFiles(configFile, "") + ";"; |
139 |
> |
} catch (Exception e) { |
140 |
> |
// not sure what to do here |
141 |
> |
// so we just log the error |
142 |
> |
_logger.write(toString(), Logger.ERROR, "ERROR - " + e); |
143 |
> |
} |
144 |
> |
if (groupFileList != null) { |
145 |
> |
fileList += groupFileList; |
146 |
> |
} |
147 |
> |
} else { |
148 |
> |
_logger.write(toString(), Logger.DEBUG, "no config entry for - " + groupName); |
149 |
|
} |
116 |
– |
if (groupFileList != null) { |
117 |
– |
fileList += groupFileList; |
118 |
– |
} |
150 |
|
} |
151 |
|
// add the system config as the final check |
152 |
< |
fileList += _systemConfigFile + ";"; |
152 |
> |
fileList = _systemConfigFile + ";" + fileList; |
153 |
|
_logger.write(toString(), Logger.DEBUG, "config tree - " + fileList); |
154 |
|
|
155 |
|
// build the configuration |
189 |
|
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
190 |
|
* method to provide clean logging (every class should have this). |
191 |
|
* |
192 |
< |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
192 |
> |
* This uses the uk.org.iscream.cms.server.util.FormatName class |
193 |
|
* to format the toString() |
194 |
|
* |
195 |
|
* @return the name of this class and its CVS revision |
307 |
|
* @return the list of groups that this source is a member of |
308 |
|
*/ |
309 |
|
private LinkedList getGroupMembership(String source) { |
310 |
+ |
_logger.write(toString(), Logger.DEBUG, "searching groups for - " + source); |
311 |
|
LinkedList groupMembership = new LinkedList(); |
312 |
|
Iterator i = new TreeSet(_systemConfigHolder.keySet()).iterator(); |
313 |
|
while(i.hasNext()) { |
314 |
|
String key = (String) i.next(); |
315 |
|
if (key.startsWith("group.")) { |
316 |
|
String group = _systemConfig.getProperty(key); |
317 |
+ |
// if it is in the group |
318 |
|
if (group.indexOf(source) != -1) { |
319 |
|
groupMembership.add(key.substring(6)); |
320 |
+ |
_logger.write(toString(), Logger.DEBUG, "group match found for - " + source + " in - " + key); |
321 |
+ |
|
322 |
+ |
// if there are wildcards in the group |
323 |
+ |
} else if (group.indexOf("*") != -1) { |
324 |
+ |
// check the wildcards apply to this srce |
325 |
+ |
if(StringUtils.wildcardCheck(source, group)) { |
326 |
+ |
groupMembership.add(key.substring(6)); |
327 |
+ |
_logger.write(toString(), Logger.DEBUG, "wildcard group match found for - " + source + " in - " + key); |
328 |
+ |
} |
329 |
|
} |
330 |
+ |
|
331 |
|
} |
332 |
|
} |
333 |
|
return groupMembership; |
334 |
< |
} |
334 |
> |
} |
335 |
|
|
336 |
|
/** |
337 |
|
* Build the properties as a Configuration to be |
353 |
|
|
354 |
|
// some holders for variables |
355 |
|
File currentFile; |
356 |
< |
long lastModified, newLastModified; |
357 |
< |
Properties properties, prevProperties; |
356 |
> |
long lastModified = 0, newLastModified = 0; |
357 |
> |
Properties properties = null, prevProperties = null; |
358 |
|
|
359 |
|
// the root of all configurations will be the system config |
360 |
|
// so we need to open the properties of that |
361 |
|
Properties defaultProperties = new Properties(); |
319 |
– |
currentFile = new File(_configPath, _systemConfigFile); |
320 |
– |
lastModified = currentFile.lastModified(); |
321 |
– |
defaultProperties.load(new FileInputStream(currentFile)); |
362 |
|
|
363 |
|
// This loop then iterates over the file list |
364 |
|
// creates the properties to be passed to the |
365 |
|
// Configuration constructor |
366 |
< |
do { |
366 |
> |
while (st.hasMoreTokens()) { |
367 |
|
properties = new Properties(defaultProperties); |
368 |
|
currentFile = new File(_configPath, st.nextToken()); |
369 |
|
newLastModified = currentFile.lastModified(); |
372 |
|
} |
373 |
|
properties.load(new FileInputStream(currentFile)); |
374 |
|
defaultProperties = properties; |
375 |
< |
} while (st.hasMoreTokens()); |
375 |
> |
} |
376 |
|
|
377 |
|
// this creates the configuration, all nice, ready to be returned |
378 |
|
ConfigurationServant ref = new ConfigurationServant(properties, fileList, lastModified); |
379 |
|
org.omg.CORBA.Object objRef = _refman.getRootPOA().servant_to_reference(ref); |
380 |
|
config = ConfigurationHelper.narrow(objRef); |
381 |
< |
|
381 |
> |
_logger.write(toString(), Logger.DEBUG, "returning built configuration"); |
382 |
|
} catch (Exception e) { |
383 |
|
// not sure what to do here |
384 |
|
// so we just log the error |