Author: [log in to unmask]
Date: Wed Jul 1 08:13:01 2015
New Revision: 3217
Log:
Minor changes to crawler (fix allow updates flag and other changes).
Modified:
java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/JCacheManager.java
java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunLogUpdater.java
java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunProcessor.java
java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunSummaryUpdater.java
Modified: java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/JCacheManager.java
=============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/JCacheManager.java (original)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/JCacheManager.java Wed Jul 1 08:13:01 2015
@@ -50,6 +50,11 @@
* The current status from executing the 'jcache request' command.
*/
private String status;
+
+ /**
+ * The xml node with request data.
+ */
+ private Element xml;
/**
* Create a new <code>CacheStatus</code> object.
@@ -122,38 +127,58 @@
}
/**
- * Return </code>true</code> if status is "done".
- *
- * @return </code>true</code> if status is "done"
+ * Return <code>true</code> if status is "done".
+ *
+ * @return <code>true</code> if status is "done"
*/
boolean isDone() {
return "done".equals(this.status);
}
/**
- * Return </code>true</code> if status is "hit".
- *
- * @return </code>true</code> if status is "hit"
+ * Return <code>true</code> if status is "hit".
+ *
+ * @return <code>true</code> if status is "hit"
*/
boolean isHit() {
return "hit".equals(this.status);
}
/**
- * Return </code>true</code> if status is "pending".
- *
- * @return </code>true</code> if status is "pending"
+ * Return <code>true</code> if status is "pending".
+ *
+ * @return <code>true</code> if status is "pending"
*/
boolean isPending() {
return "pending".equals(this.status);
}
-
- /**
- * Request the file status string using the 'jcache request' command.
- *
- * @return the file status string
- */
- private String requestFileStatus() {
+
+ /**
+ * Return <code>true</code> if status is "failed".
+ */
+ boolean isFailed() {
+ return "failed".equals(this.status);
+ }
+
+ /**
+ * Get the error message from the XML request.
+ *
+ * @return the error message from the XML request
+ */
+ String getErrorMessage() {
+ if (this.xml.getChild("request").getChild("file").getChild("error") != null) {
+ return this.xml.getChild("request").getChild("file").getChild("error").getText();
+ } else {
+ return "";
+ }
+ }
+
+ /**
+ * Run the <i>jcache request</i> command for this request ID and return the XML output.
+ *
+ * @return the XML output from the <i>jcache request</i> command
+ */
+ private Element request() {
Process process = null;
try {
process = new ProcessBuilder(JCACHE_COMMAND, "request", this.requestId.toString()).start();
@@ -169,15 +194,22 @@
if (status != 0) {
throw new RuntimeException("The jcache request returned an error status: " + status);
}
- return this.getRequestXml(process.getInputStream()).getChild("request").getChild("file").getChildText("status");
+ return this.getRequestXml(process.getInputStream());
}
/**
* Update the cache status.
*/
void update() {
- this.status = this.requestFileStatus();
+ // Request status update and get the XML from that process.
+ this.xml = request();
+
+ // Update the status from the XML.
+ this.status = this.xml.getChild("request").getChild("file").getChildText("status");
+
+ // Is request done or file already in cache?
if (this.isDone() || this.isHit()) {
+ // Flag file as cached.
this.cached = true;
}
}
@@ -345,6 +377,13 @@
// Log that this file is now cached. It will not be checked next time.
LOGGER.info(cacheStatus.getFile().getPath() + " is cached with status " + cacheStatus.getStatus(false));
}
+
+ // Did the request fail?
+ if (cacheStatus.isFailed()) {
+ // Cache failure is a fatal error.
+ LOGGER.severe("cache request failed with error: " + cacheStatus.getErrorMessage());
+ throw new RuntimeException("Cache request failed.");
+ }
} else {
LOGGER.info(cacheStatus.getFile().getPath() + " is already cached");
}
Modified: java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunLogUpdater.java
=============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunLogUpdater.java (original)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunLogUpdater.java Wed Jul 1 08:13:01 2015
@@ -49,11 +49,14 @@
// Set the run log with the run info to update.
this.runLog = runLog;
+
+ // Set whether db updates are allowed (replacement of existing records).
+ this.allowUpdates = allowUpdates;
}
/**
- * Insert the run summary information into the database, including updating the run_log_files
- * and run_log_epics tables.
+ * Insert the run summary information into the database, including updating the <i>run_log_files</i>
+ * and <i>run_log_epics</i> tables.
*
* @param connection the database connection
* @throws SQLException if there is an error querying the database
@@ -76,9 +79,11 @@
// Create the db updater for the RunSummary.
RunSummaryUpdater runUpdater = new RunSummaryUpdater(connection, runSummary);
-
+
// Set whether existing records can be replaced.
runUpdater.setAllowDeleteExisting(allowUpdates);
+
+ LOGGER.info("allow updates: " + allowUpdates);
// Insert the run records.
runUpdater.insert();
Modified: java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunProcessor.java
=============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunProcessor.java (original)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunProcessor.java Wed Jul 1 08:13:01 2015
@@ -379,7 +379,9 @@
RunSummary runSummary = runs.getRunSummary(run);
// Clear the cache manager.
- cacheManager.clear();
+ if (config.useFileCache()) {
+ cacheManager.clear();
+ }
// Create a processor to process all the EVIO events in the run.
final RunProcessor runProcessor = RunProcessor.createRunProcessor(cacheManager, runSummary, config);
Modified: java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunSummaryUpdater.java
=============================================================================
--- java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunSummaryUpdater.java (original)
+++ java/trunk/record-util/src/main/java/org/hps/record/evio/crawler/RunSummaryUpdater.java Wed Jul 1 08:13:01 2015
@@ -145,7 +145,7 @@
// Does the run exist in the database already?
if (this.runExists()) {
// Is deleting existing rows allowed?
- if (allowDeleteExisting) {
+ if (this.allowDeleteExisting) {
// Delete the existing rows.
this.delete();
} else {
|