LISTSERV mailing list manager LISTSERV 16.5

Help for HPS-SVN Archives


HPS-SVN Archives

HPS-SVN Archives


HPS-SVN@LISTSERV.SLAC.STANFORD.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

HPS-SVN Home

HPS-SVN Home

HPS-SVN  May 2015

HPS-SVN May 2015

Subject:

r2894 - in /java/trunk/users/src/main/java/org/hps/users/jeremym/crawler: EvioFileCrawler.java EvioFileList.java EvioFileVisitor.java RunLog.java

From:

[log in to unmask]

Reply-To:

Notification of commits to the hps svn repository <[log in to unmask]>

Date:

Mon, 4 May 2015 20:56:22 -0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (235 lines)

Author: [log in to unmask]
Date: Mon May  4 13:56:13 2015
New Revision: 2894

Log:
Updates to EVIO file crawler.

Modified:
    java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/EvioFileCrawler.java
    java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/EvioFileList.java
    java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/EvioFileVisitor.java
    java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/RunLog.java

Modified: java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/EvioFileCrawler.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/EvioFileCrawler.java	(original)
+++ java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/EvioFileCrawler.java	Mon May  4 13:56:13 2015
@@ -166,9 +166,10 @@
                 runs.printRunSummaries();
             }
 
-            // Insert run summary into run_log table.
+            // Insert run information into database.
             if (this.update) {
-                runs.update();
+                // Update run log.
+                runs.insert();
             }
         }
 

Modified: java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/EvioFileList.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/EvioFileList.java	(original)
+++ java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/EvioFileList.java	Mon May  4 13:56:13 2015
@@ -2,22 +2,32 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.logging.Logger;
 
 import org.jlab.coda.jevio.EvioException;
 import org.jlab.coda.jevio.EvioReader;
+import org.lcsim.util.log.LogUtil;
 
 class EvioFileList extends ArrayList<File> {
 
+    private static final Logger LOGGER = LogUtil.create(EvioFileList.class);
+
     void cache() {
+        LOGGER.info("running cache commands ...");
         for (final File file : this) {
             EvioFileUtilities.cache(file);
         }
+        LOGGER.info("done running cache commands");
     }
 
     int computeTotalEvents() {
+        LOGGER.info("computing total events ...");
         int totalEvents = 0;
         for (final File file : this) {
             EvioReader reader = null;
@@ -36,6 +46,7 @@
                 }
             }
         }
+        LOGGER.info("done computing total events");
         return totalEvents;
     }
 
@@ -53,4 +64,22 @@
         this.clear();
         this.addAll(fileList);
     }
+
+    void insert(final Connection connection, final int run) throws SQLException {
+        LOGGER.info("updating file list ...");
+        PreparedStatement filesStatement = null;
+        filesStatement = connection
+                .prepareStatement("INSERT INTO run_log_files (run, directory, name) VALUES(?, ?, ?)");
+        LOGGER.info("inserting files from run " + run + " into database");
+        for (final File file : this) {
+            LOGGER.info("creating update statement for " + file.getPath());
+            filesStatement.setInt(1, run);
+            filesStatement.setString(2, file.getParentFile().getPath());
+            filesStatement.setString(3, file.getName());
+            LOGGER.info("executing statement: " + filesStatement);
+            filesStatement.executeUpdate();
+            // connection.commit();
+        }
+        LOGGER.info("run_log_files was updated!");
+    }
 }

Modified: java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/EvioFileVisitor.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/EvioFileVisitor.java	(original)
+++ java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/EvioFileVisitor.java	Mon May  4 13:56:13 2015
@@ -58,7 +58,7 @@
 
             this.runs.getRunSummary(run).addFile(file);
         } else {
-            LOGGER.fine("rejected file: " + file.getPath());
+            LOGGER.info("rejected file: " + file.getPath());
         }
         return FileVisitResult.CONTINUE;
     }

Modified: java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/RunLog.java
 =============================================================================
--- java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/RunLog.java	(original)
+++ java/trunk/users/src/main/java/org/hps/users/jeremym/crawler/RunLog.java	Mon May  4 13:56:13 2015
@@ -39,6 +39,65 @@
         return runList;
     }
 
+    void insert() {
+
+        LOGGER.info("inserting runs into run_log ...");
+        final ConnectionParameters cp = new ConnectionParameters("root", "derp", "hps_run_db", "localhost");
+        final Connection connection = cp.createConnection();
+        try {
+            connection.setAutoCommit(false);
+
+            insertRunLog(connection);
+
+            insertFiles(connection);
+
+            connection.commit();
+
+        } catch (final SQLException e) {
+            LOGGER.log(Level.SEVERE, "rolling back transaction", e);
+            try {
+                connection.rollback();
+            } catch (final SQLException e2) {
+                throw new RuntimeException(e);
+            }
+        } finally {
+            if (connection != null) {
+                try {
+                    connection.setAutoCommit(true);
+                    connection.close();
+                } catch (final SQLException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+    }
+
+    void insertFiles(final Connection connection) throws SQLException {
+        for (final int run : getSortedRunNumbers()) {
+            getRunSummary(run).getFiles().insert(connection, run);
+        }
+    }
+
+    void insertRunLog(final Connection connection) throws SQLException {
+        PreparedStatement runLogStatement = null;
+        runLogStatement = connection
+                .prepareStatement("INSERT INTO run_log (run, start_date, end_date, nevents, nfiles, end_ok, last_updated) VALUES(?, ?, ?, ?, ?, ?, NOW())");
+        for (final Integer run : getSortedRunNumbers()) {
+            LOGGER.info("preparing to insert run " + run + " into database ..");
+            final RunSummary runSummary = this.runs.get(run);
+            runLogStatement.setInt(1, run);
+            runLogStatement.setTimestamp(2, new java.sql.Timestamp(runSummary.getStartDate().getTime()));
+            runLogStatement.setTimestamp(3, new java.sql.Timestamp(runSummary.getEndDate().getTime()));
+            runLogStatement.setInt(4, runSummary.getTotalEvents());
+            runLogStatement.setInt(5, runSummary.getFiles().size());
+            runLogStatement.setBoolean(6, runSummary.isEndOkay());
+            runLogStatement.executeUpdate();
+            // connection.commit();
+            LOGGER.info("committed run " + run + " to run_log");
+        }
+        LOGGER.info("run_log was updated!");
+    }
+
     void printRunSummaries() {
         for (final int run : this.runs.keySet()) {
             this.runs.get(run).printRunSummary(System.out);
@@ -50,49 +109,4 @@
             this.runs.get(run).sortFiles();
         }
     }
-
-    void update() {
-        LOGGER.info("updating database from run log ...");
-        final ConnectionParameters cp = new ConnectionParameters("root", "derp", "hps_run_db", "localhost");
-        Connection connection = null;
-        PreparedStatement runLogStatement = null;
-        try {
-            connection = cp.createConnection();
-            connection.setAutoCommit(false);
-            runLogStatement = connection
-                    .prepareStatement("INSERT INTO run_log (run, start_date, end_date, nevents, nfiles, end_ok, last_updated) VALUES(?, ?, ?, ?, ?, ?, NOW())");
-            for (final Integer run : getSortedRunNumbers()) {
-                LOGGER.info("inserting run " + run + " into database");
-                final RunSummary runSummary = this.runs.get(run);
-                runLogStatement.setInt(1, run);
-                runLogStatement.setTimestamp(2, new java.sql.Timestamp(runSummary.getStartDate().getTime()));
-                runLogStatement.setTimestamp(3, new java.sql.Timestamp(runSummary.getEndDate().getTime()));
-                runLogStatement.setInt(4, runSummary.getTotalEvents());
-                runLogStatement.setInt(5, runSummary.getFiles().size());
-                runLogStatement.setBoolean(6, runSummary.isEndOkay());
-                runLogStatement.executeUpdate();
-                connection.commit();
-            }
-        } catch (final SQLException e) {
-            LOGGER.log(Level.SEVERE, "rolling back transaction", e);
-            try {
-                connection.rollback();
-            } catch (final SQLException e2) {
-                throw new RuntimeException(e);
-            }
-        } finally {
-            if (connection != null) {
-                try {
-                    connection.setAutoCommit(true);
-                    if (!connection.isClosed()) {
-                        connection.close();
-                    }
-                } catch (final SQLException e) {
-                    e.printStackTrace();
-                }
-            }
-        }
-        LOGGER.info("database was updated!");
-    }
-
 }

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

November 2017
August 2017
July 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013

ATOM RSS1 RSS2



LISTSERV.SLAC.STANFORD.EDU

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager

Privacy Notice, Security Notice and Terms of Use