Revision 2108
Added by Duane Costa almost 21 years ago
src/edu/ucsb/nceas/metacat/harvesterClient/Harvester.java | ||
---|---|---|
58 | 58 |
*/ |
59 | 59 |
private static final String marker = |
60 | 60 |
"*****************************************************************************"; |
61 |
|
|
62 |
static Properties properties; |
|
61 | 63 |
|
62 | 64 |
|
63 | 65 |
/* |
... | ... | |
75 | 77 |
/** |
76 | 78 |
* Loads Harvester properties from a configuration file. |
77 | 79 |
*/ |
78 |
private static Properties loadProperties() {
|
|
80 |
private static void loadProperties() {
|
|
79 | 81 |
File configfile = new File("../../lib/harvester", "harvester.properties"); |
80 |
Properties properties = new Properties();
|
|
82 |
properties = new Properties(); |
|
81 | 83 |
|
82 | 84 |
try { |
83 | 85 |
properties.load(new FileInputStream(configfile)); |
... | ... | |
86 | 88 |
System.out.println("IOException: " + e.getMessage()); |
87 | 89 |
System.exit(1); |
88 | 90 |
} |
89 |
|
|
90 |
return properties; |
|
91 | 91 |
} |
92 | 92 |
|
93 | 93 |
|
... | ... | |
110 | 110 |
int maxHarvests = maxHarvestsDefault.intValue(); // Max number of harvests |
111 | 111 |
Integer mh; // used in determining max harvests |
112 | 112 |
int nHarvests = 0; // counts the number of harvest runs |
113 |
final long oneHour = (60 * 60 * 1000); |
|
114 |
final long oneSecond = 1000; |
|
113 |
final long oneHour = (60 * 60 * 1000); // milliseconds in one hour |
|
115 | 114 |
Integer periodDefault = new Integer(24); // Default hours between harvests |
116 | 115 |
int period = periodDefault.intValue(); // Hours between harvests |
117 | 116 |
Integer p; // Used in determining the period |
118 |
Properties properties; |
|
119 |
long startTime; // time that a harvest starts |
|
117 |
long startTime; // time that a harvest run starts |
|
120 | 118 |
|
121 | 119 |
System.out.println(marker); |
122 | 120 |
System.out.println("Starting Harvester"); |
123 |
properties = Harvester.loadProperties();
|
|
124 |
properties.list(System.out); |
|
121 |
Harvester.loadProperties(); |
|
122 |
//properties.list(System.out);
|
|
125 | 123 |
|
126 | 124 |
// Parse the delay property. Use default if necessary. |
127 | 125 |
try { |
... | ... | |
202 | 200 |
|
203 | 201 |
if (nHarvests < maxHarvests) { |
204 | 202 |
try { |
205 |
// Thread.sleep((period * oneHour) - delta); |
|
206 |
Thread.sleep((period * oneSecond) - delta); |
|
203 |
Thread.sleep((period * oneHour) - delta); |
|
207 | 204 |
} |
208 | 205 |
catch (InterruptedException e) { |
209 | 206 |
System.err.println("InterruptedException: " + e.getMessage()); |
... | ... | |
257 | 254 |
/** SMTP server for sending mail messages */ |
258 | 255 |
String smtpServer; |
259 | 256 |
|
257 |
/** The timestamp for this harvest run. Used for output only. */ |
|
258 |
String timestamp; |
|
259 |
|
|
260 | 260 |
|
261 | 261 |
/* |
262 | 262 |
* Object methods |
... | ... | |
506 | 506 |
|
507 | 507 |
out.println(marker); |
508 | 508 |
out.println("*"); |
509 |
out.println("* METACAT HARVESTER REPORT");
|
|
509 |
out.println("* METACAT HARVESTER REPORT: " + timestamp);
|
|
510 | 510 |
out.println("*"); |
511 | 511 |
|
512 | 512 |
if (nErrors > 0) { |
... | ... | |
717 | 717 |
String from = harvesterAdministrator; |
718 | 718 |
MailMessage msg; |
719 | 719 |
int siteScheduleID = 0; |
720 |
String subject = "Report from Metacat Harvester";
|
|
720 |
String subject = "Report from Metacat Harvester: " + timestamp;
|
|
721 | 721 |
String to = harvesterAdministrator; |
722 | 722 |
|
723 | 723 |
if (!to.equals("")) { |
... | ... | |
758 | 758 |
|
759 | 759 |
try { |
760 | 760 |
// Close the database connection |
761 |
System.out.println("Closing the database connection"); |
|
762 | 761 |
conn.close(); |
763 | 762 |
} |
764 | 763 |
catch (SQLException e) { |
... | ... | |
788 | 787 |
Properties properties; |
789 | 788 |
//String response; |
790 | 789 |
String sessionId; |
791 |
String timestamp; |
|
792 | 790 |
String url; |
793 | 791 |
String user; |
794 | 792 |
String userName = System.getProperty("user.name"); |
... | ... | |
797 | 795 |
// Log startup operation |
798 | 796 |
System.out.println(Harvester.marker); |
799 | 797 |
now = new Date(); |
800 |
timestamp = now.toString() + ": ";
|
|
801 |
System.out.println(timestamp + "Starting Next Harvest (" + |
|
798 |
timestamp = now.toString(); |
|
799 |
System.out.println(timestamp + ": Starting Next Harvest (" +
|
|
802 | 800 |
nHarvests + "/" + maxHarvests + ")"); |
803 |
properties = loadProperties(); |
|
801 |
Harvester.loadProperties(); |
|
802 |
properties = Harvester.properties; |
|
804 | 803 |
ctm = Boolean.valueOf(properties.getProperty("connectToMetacat", "true")); |
805 | 804 |
connectToMetacat = ctm.booleanValue(); |
806 | 805 |
dbDriver = properties.getProperty("dbDriver"); |
src/edu/ucsb/nceas/metacat/harvesterClient/HarvestLog.java | ||
---|---|---|
32 | 32 |
import java.sql.Statement; |
33 | 33 |
import java.text.SimpleDateFormat; |
34 | 34 |
import java.util.Date; |
35 |
import java.util.Properties; |
|
36 |
import java.util.StringTokenizer; |
|
35 | 37 |
|
36 | 38 |
|
37 | 39 |
/** |
... | ... | |
89 | 91 |
this.siteScheduleID = siteScheduleID; |
90 | 92 |
|
91 | 93 |
harvestOperationCodeLevel = |
92 |
dbGetHarvestOperationCodeLevel(harvestOperationCode);
|
|
93 |
explanation = dbGetExplanation(harvestOperationCode);
|
|
94 |
getHarvestOperationCodeLevel(harvestOperationCode);
|
|
95 |
explanation = getExplanation(harvestOperationCode);
|
|
94 | 96 |
dbInsertHarvestLogEntry(); // Insert this entry to the HARVEST_LOG table |
95 | 97 |
} |
96 | 98 |
|
... | ... | |
133 | 135 |
this.harvestDetailLog = new HarvestDetailLog(harvester, harvestLogID, |
134 | 136 |
harvestDocument, errorMessage); |
135 | 137 |
harvestOperationCodeLevel = |
136 |
dbGetHarvestOperationCodeLevel(harvestOperationCode);
|
|
137 |
explanation = dbGetExplanation(harvestOperationCode);
|
|
138 |
getHarvestOperationCodeLevel(harvestOperationCode);
|
|
139 |
explanation = getExplanation(harvestOperationCode);
|
|
138 | 140 |
dbInsertHarvestLogEntry(); // Insert to the HARVEST_LOG table |
139 | 141 |
harvestDetailLog.dbInsertHarvestDetailLogEntry(); // and HARVEST_DETAIL_LOG |
140 | 142 |
} |
141 | 143 |
|
142 | 144 |
|
143 | 145 |
/** |
144 |
* Retrieves the value of the EXPLANATION field of the HARVEST_OPERATION |
|
145 |
* table based on the value of the HARVEST_OPERATION_CODE field. |
|
146 |
* |
|
147 |
* @param harvestOperationCode string value of the harvest operation code |
|
148 |
* @return the explanation for this harvest operation, a String |
|
149 |
*/ |
|
150 |
String dbGetExplanation(String harvestOperationCode) { |
|
151 |
String explanation; |
|
152 |
String fieldName = "EXPLANATION"; |
|
153 |
|
|
154 |
explanation = dbQueryHarvestOperation(fieldName, harvestOperationCode); |
|
155 |
|
|
156 |
return explanation; |
|
157 |
} |
|
158 |
|
|
159 |
|
|
160 |
/** |
|
161 |
* Retrieves the value of the HARVEST_OPERATION_CODE_LEVEL field of the |
|
162 |
* HARVEST_OPERATION table based on the value of the HARVEST_OPERATION_CODE |
|
163 |
* field. |
|
164 |
* |
|
165 |
* @param harvestOperationCode string value of the harvest operation code |
|
166 |
* @return the code level value, a String, one of the following: |
|
167 |
* "error", "warning", "notice", "info", or "debug" |
|
168 |
*/ |
|
169 |
String dbGetHarvestOperationCodeLevel(String harvestOperationCode) { |
|
170 |
String harvestOperationCodeLevel; |
|
171 |
String fieldName = "HARVEST_OPERATION_CODE_LEVEL"; |
|
172 |
|
|
173 |
harvestOperationCodeLevel = |
|
174 |
dbQueryHarvestOperation(fieldName, harvestOperationCode); |
|
175 |
|
|
176 |
return harvestOperationCodeLevel; |
|
177 |
} |
|
178 |
|
|
179 |
|
|
180 |
/** |
|
181 | 146 |
* Inserts a new entry into the HARVEST_LOG table, based on the contents of |
182 | 147 |
* this HarvestLog object. Not yet implemented. |
183 | 148 |
*/ |
... | ... | |
211 | 176 |
|
212 | 177 |
|
213 | 178 |
/** |
179 |
* Maps each code level to an integer value. |
|
180 |
* |
|
181 |
* @param codeLevel the code level: "error", "warning", "notice", |
|
182 |
* "info", or "debug" |
|
183 |
* @return codeLevelValue the corresponding code level value |
|
184 |
*/ |
|
185 |
int getCodeLevelValue(String codeLevel) { |
|
186 |
int codeLevelValue = 0; |
|
187 |
|
|
188 |
if (codeLevel.equalsIgnoreCase("error")) { |
|
189 |
codeLevelValue = 1; |
|
190 |
} |
|
191 |
else if (codeLevel.equalsIgnoreCase("warning")) { |
|
192 |
codeLevelValue = 2; |
|
193 |
} |
|
194 |
else if (codeLevel.equalsIgnoreCase("notice")) { |
|
195 |
codeLevelValue = 3; |
|
196 |
} |
|
197 |
else if (codeLevel.equalsIgnoreCase("info")) { |
|
198 |
codeLevelValue = 4; |
|
199 |
} |
|
200 |
else if (codeLevel.equalsIgnoreCase("debug")) { |
|
201 |
codeLevelValue = 5; |
|
202 |
} |
|
203 |
|
|
204 |
return codeLevelValue; |
|
205 |
} |
|
206 |
|
|
207 |
|
|
208 |
/** |
|
209 |
* Retrieves the value of the EXPLANATION field of the HARVEST_OPERATION |
|
210 |
* table based on the value of the HARVEST_OPERATION_CODE field. |
|
211 |
* |
|
212 |
* @param harvestOperationCode string value of the harvest operation code |
|
213 |
* @return the explanation for this harvest operation, a String |
|
214 |
*/ |
|
215 |
String getExplanation(String harvestOperationCode) { |
|
216 |
String explanation; |
|
217 |
String fieldName = "EXPLANATION"; |
|
218 |
|
|
219 |
explanation = getHarvestOperation(fieldName, harvestOperationCode); |
|
220 |
|
|
221 |
return explanation; |
|
222 |
} |
|
223 |
|
|
224 |
|
|
225 |
/** |
|
214 | 226 |
* Retrieves the value of the either the EXPLANATION field or the |
215 | 227 |
* HARVEST_OPERATION_CODE_LEVEL field of the HARVEST_OPERATION table based on |
216 | 228 |
* the value of the HARVEST_OPERATION_CODE field. |
... | ... | |
219 | 231 |
* @param harvestOperationCode string value of the harvest operation code |
220 | 232 |
* @return the explanation string or the harvestOperationCodeLevel string |
221 | 233 |
*/ |
222 |
String dbQueryHarvestOperation(String fieldName, |
|
223 |
String harvestOperationCode |
|
224 |
) { |
|
234 |
String getHarvestOperation(String fieldName, String harvestOperationCode) { |
|
225 | 235 |
String explanation = "No explanation available"; |
226 | 236 |
String harvestOperationCodeLevel = "debug"; |
227 |
String queryString; |
|
237 |
Properties properties = Harvester.properties; |
|
238 |
String propertyValue; |
|
228 | 239 |
String returnString = ""; |
229 |
ResultSet rs; |
|
230 |
Statement stmt; |
|
231 |
SQLWarning warn; |
|
240 |
StringTokenizer stringTokenizer; |
|
232 | 241 |
|
233 |
queryString = "SELECT EXPLANATION, HARVEST_OPERATION_CODE_LEVEL " + |
|
234 |
"FROM HARVEST_OPERATION " + |
|
235 |
"WHERE HARVEST_OPERATION_CODE=" + |
|
236 |
"'" + harvestOperationCode + "'"; |
|
237 |
|
|
238 |
try { // Query the HARVEST_OPERATION table |
|
239 |
stmt = harvester.conn.createStatement(); |
|
240 |
rs = stmt.executeQuery(queryString); |
|
241 |
warn = rs.getWarnings(); |
|
242 |
|
|
243 |
if (warn != null) { |
|
244 |
System.out.println("\n---Warning---\n"); |
|
245 |
|
|
246 |
while (warn != null) { |
|
247 |
System.out.println("Message: " + warn.getMessage()); |
|
248 |
System.out.println("SQLState: " + warn.getSQLState()); |
|
249 |
System.out.print("Vendor error code: "); |
|
250 |
System.out.println(warn.getErrorCode()); |
|
251 |
System.out.println(""); |
|
252 |
warn = warn.getNextWarning(); |
|
253 |
} |
|
254 |
} |
|
255 |
|
|
256 |
while (rs.next()) { |
|
257 |
explanation = rs.getString("EXPLANATION"); |
|
258 |
harvestOperationCodeLevel = rs.getString("HARVEST_OPERATION_CODE_LEVEL"); |
|
259 |
warn = rs.getWarnings(); |
|
260 |
|
|
261 |
if (warn != null) { |
|
262 |
System.out.println("\n---Warning---\n"); |
|
263 |
|
|
264 |
while (warn != null) { |
|
265 |
System.out.println("Message: " + warn.getMessage()); |
|
266 |
System.out.println("SQLState: " + warn.getSQLState()); |
|
267 |
System.out.print("Vendor error code: "); |
|
268 |
System.out.println(warn.getErrorCode()); |
|
269 |
System.out.println(""); |
|
270 |
warn = warn.getNextWarning(); |
|
271 |
} |
|
272 |
} |
|
273 |
} |
|
274 |
|
|
275 |
rs.close(); |
|
276 |
stmt.close(); |
|
277 |
} |
|
278 |
catch (SQLException e) { |
|
279 |
System.out.println("SQLException: Database access failed: " + e); |
|
280 |
} |
|
281 |
|
|
242 |
propertyValue = properties.getProperty(harvestOperationCode); |
|
243 |
stringTokenizer = new StringTokenizer(propertyValue, ","); |
|
244 |
|
|
245 |
explanation = (String) stringTokenizer.nextElement(); |
|
246 |
harvestOperationCodeLevel = (String) stringTokenizer.nextElement(); |
|
247 |
|
|
282 | 248 |
if (fieldName.equals("EXPLANATION")) { |
283 | 249 |
returnString = explanation; |
284 | 250 |
} |
... | ... | |
291 | 257 |
|
292 | 258 |
|
293 | 259 |
/** |
294 |
* Maps each code level to an integer value. |
|
260 |
* Retrieves the value of the HARVEST_OPERATION_CODE_LEVEL field of the |
|
261 |
* HARVEST_OPERATION table based on the value of the HARVEST_OPERATION_CODE |
|
262 |
* field. |
|
295 | 263 |
* |
296 |
* @param codeLevel the code level: "error", "warning", "notice",
|
|
297 |
* "info", or "debug"
|
|
298 |
* @return codeLevelValue the corresponding code level value
|
|
264 |
* @param harvestOperationCode string value of the harvest operation code
|
|
265 |
* @return the code level value, a String, one of the following:
|
|
266 |
* "error", "warning", "notice", "info", or "debug"
|
|
299 | 267 |
*/ |
300 |
int getCodeLevelValue(String codeLevel) { |
|
301 |
int codeLevelValue = 0; |
|
268 |
String getHarvestOperationCodeLevel(String harvestOperationCode) { |
|
269 |
String harvestOperationCodeLevel; |
|
270 |
String fieldName = "HARVEST_OPERATION_CODE_LEVEL"; |
|
302 | 271 |
|
303 |
if (codeLevel.equalsIgnoreCase("error")) { |
|
304 |
codeLevelValue = 1; |
|
305 |
} |
|
306 |
else if (codeLevel.equalsIgnoreCase("warning")) { |
|
307 |
codeLevelValue = 2; |
|
308 |
} |
|
309 |
else if (codeLevel.equalsIgnoreCase("notice")) { |
|
310 |
codeLevelValue = 3; |
|
311 |
} |
|
312 |
else if (codeLevel.equalsIgnoreCase("info")) { |
|
313 |
codeLevelValue = 4; |
|
314 |
} |
|
315 |
else if (codeLevel.equalsIgnoreCase("debug")) { |
|
316 |
codeLevelValue = 5; |
|
317 |
} |
|
318 |
|
|
319 |
return codeLevelValue; |
|
272 |
harvestOperationCodeLevel = |
|
273 |
getHarvestOperation(fieldName, harvestOperationCode); |
|
274 |
|
|
275 |
return harvestOperationCodeLevel; |
|
320 | 276 |
} |
321 | 277 |
|
322 | 278 |
|
src/edu/ucsb/nceas/metacat/harvesterClient/HarvestSiteSchedule.java | ||
---|---|---|
383 | 383 |
String maxCodeLevel = "info"; |
384 | 384 |
MailMessage msg; |
385 | 385 |
int nErrors = 0; |
386 |
String subject = "Report from Metacat Harvester";
|
|
386 |
String subject = "Report from Metacat Harvester: " + harvester.timestamp;
|
|
387 | 387 |
String to = contactEmail; |
388 | 388 |
|
389 | 389 |
if (!to.equals("")) { |
Also available in: Unified diff
Omit HARVEST_OPERATION_TABLE and store harvest operations in properties file instead