Commit 89fcc964 authored by toaster's avatar toaster
Browse files

added startup complete flag to json

git-svn-id: https://subversion.umiacs.umd.edu/ace/trunk@121 f1b3a171-7291-4a19-a512-95ad0ad9394a
parent c7a09ccd
......@@ -54,13 +54,7 @@
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>catalina</artifactId>
<version>6.0.32</version>
......@@ -71,12 +65,12 @@
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.0.0</version>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
<version>2.0.3</version>
</dependency>
......@@ -182,7 +176,7 @@
<dependency>
<groupId>edu.umiacs.irods</groupId>
<artifactId>irods-api</artifactId>
<version>1.5</version>
<version>1.6</version>
</dependency>
</dependencies>
</project>
......
package edu.umiacs.ace.driver2;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.monitor.core.MonitoredItem;
import java.util.Iterator;
/**
*
* @author toaster
*/
public interface AceDriverFactory<T,V> {
public FileReader<V> createReader(T settings);
public V translatePath(Collection c, MonitoredItem item);
public Iterator<V> createScanner(T settings);
}
package edu.umiacs.ace.driver2;
import edu.umiacs.ace.driver.FileBean;
import java.security.MessageDigest;
/**
* Core driver for reading files and returning their current state
*
* @author toaster
*/
public abstract class FileReader<T> {
private byte[] buffer;
private MessageDigest digest;
public FileReader( int bufferSize ) {
buffer = new byte[bufferSize];
}
void setDigest( MessageDigest digest ) {
this.digest = digest;
}
/**
* Implementing classes should use this digest when calculating the digest
* for a filebean. Please note, reset is called on the digest prior to returning
* @return digest to use for filebean
*/
protected MessageDigest getDigest() {
digest.reset();
return digest;
}
/**
* implementing classes may use this buffer rather than tracking and creating their
* own.
* @return
*/
protected byte[] getBuffer() {
return buffer;
}
public abstract FileBean readFile( T nextFile );
}
package edu.umiacs.ace.driver2;
import edu.umiacs.ace.driver.FileBean;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import org.apache.log4j.Logger;
/**
*
* @author toaster
*/
public class FileReaderThread implements Runnable {
private FileReader reader;
private LinkedBlockingQueue queue;
private boolean cancel;
private static final Logger LOG = Logger.getLogger(FileReaderThread.class);
private Queue<FileBean> resultQueue;
public FileReaderThread( FileReader reader, LinkedBlockingQueue fileQueue,
Queue<FileBean> resultQueue ) {
this.reader = reader;
this.queue = fileQueue;
this.resultQueue = resultQueue;
}
public void cancel() {
cancel = true;
}
@Override
public void run() {
while ( !cancel ) {
try {
resultQueue.add(reader.readFile(queue.take()));
} catch ( InterruptedException e ) {
LOG.info("Interrupted waiting for next file, cancel: " + cancel);
} catch ( Exception e ) {
LOG.error("Unknown error in read thread ",e);
// log unknown from reader
}
}
LOG.info("Thread exiting on cancel");
}
}
......@@ -57,6 +57,7 @@ import org.apache.log4j.NDC;
*/
public class CollectionCountContext implements ServletContextListener {
public static final String CTX_STARTUP = "startup_complete";
private static final Logger LOG = Logger.getLogger(
CollectionCountContext.class);
private static Map<Collection, Long> fileCountMap = new HashMap<Collection, Long>();
......@@ -73,37 +74,44 @@ public class CollectionCountContext implements ServletContextListener {
private static boolean abort = false;
@Override
public void contextInitialized( ServletContextEvent arg0 ) {
public void contextInitialized(final ServletContextEvent arg0) {
abort = false;
Runnable r = new Runnable() {
@Override
public void run() {
Thread.currentThread().setName("Startup Count Thread");
NDC.push("[Count]");
lock.lock();
LOG.debug("Starting count for all collections");
try {
EntityManager em = PersistUtil.getEntityManager();
Query collQuery = em.createNamedQuery(
"Collection.listAllCollections");
for ( Object o : collQuery.getResultList() ) {
if ( abort ) {
LOG.info("Collection count aborting, tomcat probably shutting down");
return;
arg0.getServletContext().setAttribute(CTX_STARTUP, false);
Thread.currentThread().setName("Startup Count Thread");
NDC.push("[Count]");
lock.lock();
LOG.debug("Starting count for all collections");
try {
EntityManager em = PersistUtil.getEntityManager();
Query collQuery = em.createNamedQuery(
"Collection.listAllCollections");
for (Object o : collQuery.getResultList()) {
if (abort) {
LOG.info("Collection count aborting, tomcat probably shutting down");
return;
}
queryCollection((Collection) o);
}
queryCollection((Collection) o);
em.close();
} catch (Exception e) {
LOG.error("Error starting up, collection count", e);
} finally {
lock.unlock();
}
em.close();
} catch ( Exception e ) {
LOG.error("Error starting up, collection count", e);
LOG.debug("Finished startup count");
NDC.pop();
} finally {
lock.unlock();
arg0.getServletContext().setAttribute(CTX_STARTUP, true);
}
LOG.debug("Finished startup count");
NDC.pop();
}
};
new Thread(r).start();
......@@ -112,76 +120,76 @@ public class CollectionCountContext implements ServletContextListener {
}
@Override
public void contextDestroyed( ServletContextEvent arg0 ) {
public void contextDestroyed(ServletContextEvent arg0) {
abort = true;
}
public static long getTokenMismatchCount( Collection c ) {
if ( fileTokenMismatchMap.containsKey(c) ) {
public static long getTokenMismatchCount(Collection c) {
if (fileTokenMismatchMap.containsKey(c)) {
return fileTokenMismatchMap.get(c);
}
return -1;
}
public static long getMissingTokenCount( Collection c ) {
if ( fileMissingTokenMap.containsKey(c) ) {
public static long getMissingTokenCount(Collection c) {
if (fileMissingTokenMap.containsKey(c)) {
return fileMissingTokenMap.get(c);
}
return -1;
}
public static long getMissingCount( Collection c ) {
if ( fileMissingMap.containsKey(c) ) {
public static long getMissingCount(Collection c) {
if (fileMissingMap.containsKey(c)) {
return fileMissingMap.get(c);
}
return -1;
}
public static long getCorruptCount( Collection c ) {
if ( fileCorruptMap.containsKey(c) ) {
public static long getCorruptCount(Collection c) {
if (fileCorruptMap.containsKey(c)) {
return fileCorruptMap.get(c);
}
return -1;
}
public static long getActiveCount( Collection c ) {
if ( fileActiveMap.containsKey(c) ) {
public static long getActiveCount(Collection c) {
if (fileActiveMap.containsKey(c)) {
return fileActiveMap.get(c);
}
return -1;
}
public static long getTotalErrors( Collection c ) {
if ( totalErrorMap.containsKey(c) ) {
public static long getTotalErrors(Collection c) {
if (totalErrorMap.containsKey(c)) {
return totalErrorMap.get(c);
}
return -1;
}
public static long getFileCount( Collection c ) {
if ( fileCountMap.containsKey(c) ) {
public static long getFileCount(Collection c) {
if (fileCountMap.containsKey(c)) {
return fileCountMap.get(c);
}
return -1;
}
public static long getTotelSize( Collection c ) {
if ( totalSizeMap.containsKey(c) ) {
public static long getTotelSize(Collection c) {
if (totalSizeMap.containsKey(c)) {
return totalSizeMap.get(c);
}
return -1;
}
public static long getRemoteMissing( Collection c ) {
if ( fileRemoteMissing.containsKey(c) ) {
public static long getRemoteMissing(Collection c) {
if (fileRemoteMissing.containsKey(c)) {
return fileRemoteMissing.get(c);
}
return -1;
}
public static long getRemoteCorrupt( Collection c ) {
if ( fileRemoteCorrupt.containsKey(c) ) {
public static long getRemoteCorrupt(Collection c) {
if (fileRemoteCorrupt.containsKey(c)) {
return fileRemoteCorrupt.get(c);
}
return -1;
......@@ -192,7 +200,7 @@ public class CollectionCountContext implements ServletContextListener {
*
* @param c
*/
private static void queryCollection( Collection c ) {
private static void queryCollection(Collection c) {
Connection connection = null;
PreparedStatement ps = null;
ResultSet rs = null;
......@@ -210,16 +218,17 @@ public class CollectionCountContext implements ServletContextListener {
long total = 0;
long totalErrors = 0;
while ( rs.next() ) {
if (abort)
while (rs.next()) {
if (abort) {
return;
}
char state = rs.getString(1).charAt(0);
long count = rs.getLong(2);
total += count;
switch ( state ) {
switch (state) {
case 'A':
fileActiveMap.put(c, count);
break;
......@@ -267,7 +276,7 @@ public class CollectionCountContext implements ServletContextListener {
long totalSize = rs.getLong(1);
totalSizeMap.put(c, totalSize);
} catch ( Exception e ) {
} catch (Exception e) {
LOG.error("Error starting up, collection count", e);
} finally {
SQL.release(rs);
......@@ -278,7 +287,7 @@ public class CollectionCountContext implements ServletContextListener {
}
}
public static void updateCollection( final Collection c ) {
public static void updateCollection(final Collection c) {
LOG.debug("Starting update for: " + c.getName());
Runnable r = new Runnable() {
......
......@@ -117,7 +117,6 @@ public class FileAuditCallback implements RequestBatchCallback {
+ item);
}
em.persist(token);
item.setFileDigest(map.get(tr.getName()));
item.setToken(token);
......
......@@ -2,6 +2,7 @@
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@page contentType="text/plain" pageEncoding="UTF-8"%>
<json:object>
<json:property name="startup_complete" value="${startup_complete}"/>
<json:property name="paused" value="${pause.paused}"/>
<json:array name="collections" items="${collections}" var="item">
<json:object>
......
......@@ -79,6 +79,7 @@
<module>ace-ims-api</module>
<module>ace-am</module>
<module>ace-dist</module>
<module>audit-core</module>
</modules>
<!--<reporting>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment