1 |
+ |
/* |
2 |
+ |
* i-scream central monitoring system |
3 |
+ |
* http://www.i-scream.org.uk |
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.filtermanager; |
22 |
> |
package uk.org.iscream.cms.server.filtermanager; |
23 |
|
|
24 |
|
//---IMPORTS--- |
25 |
< |
import uk.ac.ukc.iscream.core.*; |
26 |
< |
import uk.ac.ukc.iscream.filter.*; |
27 |
< |
import uk.ac.ukc.iscream.util.*; |
28 |
< |
import uk.ac.ukc.iscream.componentmanager.*; |
25 |
> |
import uk.org.iscream.cms.server.core.*; |
26 |
> |
import uk.org.iscream.cms.server.filter.*; |
27 |
> |
import uk.org.iscream.cms.util.*; |
28 |
> |
import uk.org.iscream.cms.server.componentmanager.*; |
29 |
|
import java.net.*; |
30 |
|
import java.io.*; |
31 |
|
import java.util.*; |
79 |
|
// this is our config name |
80 |
|
String configName = "Host." + _socket.getInetAddress().getHostName().toLowerCase(); |
81 |
|
try { |
82 |
< |
// try for STARTCONFIG |
83 |
< |
getInBound("STARTCONFIG"); |
84 |
< |
_socketOut.println("OK"); |
85 |
< |
|
86 |
< |
// try for LASTMODIFIED |
87 |
< |
getInBound("LASTMODIFIED"); |
88 |
< |
_socketOut.println(cp.getLastModified(configName)); |
89 |
< |
|
90 |
< |
// try for FILELIST |
91 |
< |
getInBound("FILELIST"); |
92 |
< |
_socketOut.println(cp.getFileList(configName)); |
93 |
< |
|
94 |
< |
// try for FQDN |
95 |
< |
getInBound("FQDN"); |
96 |
< |
_socketOut.println(_socket.getInetAddress().getHostName().toLowerCase()); |
97 |
< |
|
98 |
< |
// get properties |
99 |
< |
String reqProperty = getInBound(); |
100 |
< |
while(!reqProperty.equals("ENDCONFIG")) { |
101 |
< |
// get the property |
102 |
< |
try { |
103 |
< |
String returnedProperty = cp.getProperty(configName, "Host."+reqProperty); |
104 |
< |
_socketOut.println(returnedProperty); |
105 |
< |
} catch (PropertyNotFoundException e) { |
82 |
> |
// look for a command: |
83 |
> |
// STARTCONFIG - to get a configuration |
84 |
> |
// CHECKCONFIG - to check a configuration |
85 |
> |
// END - to finish |
86 |
> |
String cmd = getInBound(); |
87 |
> |
while(!cmd.equals("END")) { |
88 |
> |
if(cmd.equals("STARTCONFIG")) { |
89 |
> |
// respond to STARTCONFIG |
90 |
> |
_socketOut.println("OK"); |
91 |
> |
|
92 |
> |
// try for LASTMODIFIED |
93 |
> |
getInBound("LASTMODIFIED"); |
94 |
> |
_socketOut.println(cp.getLastModified(configName)); |
95 |
> |
|
96 |
> |
// try for FILELIST |
97 |
> |
getInBound("FILELIST"); |
98 |
> |
_socketOut.println(cp.getFileList(configName)); |
99 |
> |
|
100 |
> |
// try for FQDN |
101 |
> |
getInBound("FQDN"); |
102 |
> |
_socketOut.println(_socket.getInetAddress().getHostName().toLowerCase()); |
103 |
> |
|
104 |
> |
// get properties |
105 |
> |
String reqProperty = getInBound(); |
106 |
> |
while(!reqProperty.equals("ENDCONFIG")) { |
107 |
> |
// get the property |
108 |
> |
try { |
109 |
> |
String returnedProperty = cp.getProperty(configName, "Host."+reqProperty); |
110 |
> |
_socketOut.println(returnedProperty); |
111 |
> |
} catch (PropertyNotFoundException e) { |
112 |
> |
_socketOut.println("ERROR"); |
113 |
> |
} |
114 |
> |
// get the next request |
115 |
> |
reqProperty = _socketIn.readLine(); |
116 |
> |
} |
117 |
> |
_logger.write(toString(), Logger.SYSMSG, "configured host"); |
118 |
> |
_socketOut.println("OK"); |
119 |
> |
|
120 |
> |
// get filter reference |
121 |
> |
getInBound("FILTER"); |
122 |
> |
// send info |
123 |
> |
String filterList = cp.getProperty(configName, "Host.filter"); |
124 |
> |
FilterInfo filterInfoRef = null; |
125 |
> |
String filter = null; |
126 |
> |
StringTokenizer st = new StringTokenizer(filterList, ";"); |
127 |
> |
while (filterInfoRef==null && st.hasMoreTokens()) { |
128 |
> |
filter = st.nextToken(); |
129 |
> |
_logger.write(toString(), Logger.DEBUG, " looking for filter- " + filter); |
130 |
> |
try { |
131 |
> |
filterInfoRef = FilterInfoHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.FilterInfo\\." + filter)); |
132 |
> |
} catch (ComponentCORBAException e) { |
133 |
> |
_logger.write(toString(), Logger.DEBUG, " unable to find filter- " + filter); |
134 |
> |
} |
135 |
> |
} |
136 |
> |
|
137 |
> |
// hopefully we found a filter |
138 |
> |
if(filterInfoRef != null) { |
139 |
> |
_logger.write(toString(), Logger.DEBUG, " found filter- " + filter); |
140 |
> |
try { |
141 |
> |
// tell the host about it... |
142 |
> |
_socketOut.println(filterInfoRef.getHostName() + ";" |
143 |
> |
+ filterInfoRef.getUDPPort()); |
144 |
> |
} |
145 |
> |
catch(org.omg.CORBA.COMM_FAILURE e) { |
146 |
> |
// failed to talk to filter, lets signal an error |
147 |
> |
_socketOut.println("ERROR"); |
148 |
> |
throw new IOException("error communicating with filter - " + e); |
149 |
> |
} |
150 |
> |
} |
151 |
> |
else { |
152 |
> |
// ...or throw a wobbly (and tell the host!) |
153 |
> |
_socketOut.println("ERROR"); |
154 |
> |
throw new IOException("unable to find filter for host"); |
155 |
> |
} |
156 |
> |
|
157 |
> |
} |
158 |
> |
else if(cmd.equals("CHECKCONFIG")) { |
159 |
> |
// respond to CHECKCONFIG |
160 |
> |
_socketOut.println("OK"); |
161 |
> |
|
162 |
> |
// try for {filelist} |
163 |
> |
String filelist = getInBound(); |
164 |
> |
_socketOut.println("OK"); |
165 |
> |
|
166 |
> |
// try for {lastModified} |
167 |
> |
String lastModified = getInBound(); |
168 |
> |
// check to see if a config update has happen |
169 |
> |
boolean newConfig = _configManager.isModified(filelist, Long.parseLong(lastModified)); |
170 |
> |
if(newConfig) { |
171 |
> |
// new config ! |
172 |
> |
_socketOut.println("EXPIRED"); |
173 |
> |
} |
174 |
> |
else { |
175 |
> |
// nothing has changed |
176 |
> |
_socketOut.println("OK"); |
177 |
> |
} |
178 |
> |
} |
179 |
> |
else { |
180 |
|
_socketOut.println("ERROR"); |
181 |
|
} |
182 |
< |
// get the next request |
183 |
< |
reqProperty = _socketIn.readLine(); |
182 |
> |
// get the next command |
183 |
> |
cmd = getInBound(); |
184 |
|
} |
185 |
< |
_logger.write(toString(), Logger.SYSMSG, "configured host"); |
185 |
> |
// respond to END |
186 |
|
_socketOut.println("OK"); |
187 |
|
|
94 |
– |
// get filter reference |
95 |
– |
getInBound("FILTER"); |
96 |
– |
// send info |
97 |
– |
String filterList = cp.getProperty(configName, "Host.filter"); |
98 |
– |
Filter filterRef = null; |
99 |
– |
String filter = null; |
100 |
– |
StringTokenizer st = new StringTokenizer(filterList, ";"); |
101 |
– |
while (filterRef==null && st.hasMoreTokens()) { |
102 |
– |
filter = st.nextToken(); |
103 |
– |
_logger.write(toString(), Logger.DEBUG, " looking for filter- " + filter); |
104 |
– |
try { |
105 |
– |
filterRef = FilterHelper.narrow(ReferenceManager.getInstance().getCORBARef("iscream.Filter." + filter)); |
106 |
– |
} catch (ComponentCORBAException e) { |
107 |
– |
_logger.write(toString(), Logger.DEBUG, " unable to find filter- " + filter); |
108 |
– |
} |
109 |
– |
} |
110 |
– |
|
111 |
– |
// hopefully we found a filter |
112 |
– |
if(filterRef != null) { |
113 |
– |
_logger.write(toString(), Logger.DEBUG, " found filter- " + filter); |
114 |
– |
// tell the host about it... |
115 |
– |
_socketOut.println(filterRef.getHostName() + ";" |
116 |
– |
+ filterRef.getUDPPort() + ";" |
117 |
– |
+ filterRef.getTCPPort()); |
118 |
– |
} |
119 |
– |
else { |
120 |
– |
// ...or throw a wobbly (and tell the host!) |
121 |
– |
_socketOut.println("ERROR"); |
122 |
– |
throw new IOException("unable to find filter for host"); |
123 |
– |
} |
124 |
– |
|
125 |
– |
// confirm ok with END |
126 |
– |
getInBound("END"); |
127 |
– |
_socketOut.println("OK"); |
128 |
– |
|
188 |
|
} catch (Exception e) { |
189 |
|
_logger.write(toString(), Logger.ERROR, "ERROR - " + e); |
190 |
|
} |
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.NameFormat class |
207 |
> |
* This uses the uk.org.iscream.cms.util.NameFormat class |
208 |
|
* to format the toString() |
209 |
|
* |
210 |
|
* @return the name of this class and its CVS revision |