Commit 3fcbc8fe authored by Michael Ritter's avatar Michael Ritter
Browse files

Merge branch 'release-1.14.1'

parents 86061733 1f575d74
<?xml version="1.0"?> <?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
<artifactId>ace</artifactId> <artifactId>ace</artifactId>
<groupId>edu.umiacs.ace</groupId> <groupId>edu.umiacs.ace</groupId>
<version>1.14-RELEASE</version> <version>1.14.1-RELEASE</version>
</parent> </parent>
<artifactId>ace-am</artifactId> <artifactId>ace-am</artifactId>
<name>ace-am</name> <name>ace-am</name>
...@@ -55,35 +57,29 @@ ...@@ -55,35 +57,29 @@
<dependency> <dependency>
<groupId>org.apache.tomcat</groupId> <groupId>org.apache.tomcat</groupId>
<artifactId>catalina</artifactId> <artifactId>tomcat-catalina</artifactId>
<version>6.0.32</version> <version>7.0.94</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<!-- for persistence --> <!-- for persistence -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.3</version>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.persistence</groupId> <groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId> <artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.6.3</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.mail</groupId> <groupId>com.sun.mail</groupId>
<artifactId>mail</artifactId> <artifactId>javax.mail</artifactId>
<version>1.4.1</version>
</dependency> </dependency>
<!-- for json --> <!-- for json -->
<!--
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId> <artifactId>jackson-core</artifactId>
<version>2.8.1</version>
</dependency> </dependency>
-->
<dependency> <dependency>
<groupId>net.java.dev.rome</groupId> <groupId>net.java.dev.rome</groupId>
...@@ -93,9 +89,8 @@ ...@@ -93,9 +89,8 @@
<!-- for Jstl / webapp stuff--> <!-- for Jstl / webapp stuff-->
<dependency> <dependency>
<groupId>taglibs</groupId> <groupId>org.apache.taglibs</groupId>
<artifactId>standard</artifactId> <artifactId>taglibs-standard-impl</artifactId>
<version>1.1.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.servlet.jsp</groupId> <groupId>javax.servlet.jsp</groupId>
...@@ -104,14 +99,13 @@ ...@@ -104,14 +99,13 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl</artifactId> <artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.1.2</version> <version>1.2.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
...@@ -124,31 +118,26 @@ ...@@ -124,31 +118,26 @@
<dependency> <dependency>
<groupId>commons-fileupload</groupId> <groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId> <artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-collections</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-collections</artifactId> <artifactId>commons-collections4</artifactId>
<version>3.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId> <artifactId>commons-csv</artifactId>
<version>1.4</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.google.guava</groupId> <groupId>com.google.guava</groupId>
<artifactId>guava</artifactId> <artifactId>guava</artifactId>
<version>25.0-jre</version>
</dependency> </dependency>
<dependency> <dependency>
...@@ -200,12 +189,14 @@ ...@@ -200,12 +189,14 @@
<dependency> <dependency>
<groupId>org.glassfish.jersey.containers</groupId> <groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId> <artifactId>jersey-container-servlet</artifactId>
<version>2.24</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.glassfish.jersey.media</groupId> <groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId> <artifactId>jersey-media-json-jackson</artifactId>
<version>2.24</version> </dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
......
...@@ -593,9 +593,12 @@ public final class AuditThread extends Thread implements CancelCallback { ...@@ -593,9 +593,12 @@ public final class AuditThread extends Thread implements CancelCallback {
LOG.trace("Generated checksum: " + currentFileHash + " expected checksum: " + storedDigest); LOG.trace("Generated checksum: " + currentFileHash + " expected checksum: " + storedDigest);
LogEvent event; LogEvent event;
// If we have a registered file, set the digested value // If we have a registered file:
// set the stored digest to be the generated hash
// set the file digest of the current monitored_item to the generated hash
if (null == storedDigest) { if (null == storedDigest) {
LOG.trace("Setting digest for registered file " + item.getPath()); LOG.trace("Setting digest for registered file " + item.getPath());
storedDigest = currentFileHash;
item.setFileDigest(currentFileHash); item.setFileDigest(currentFileHash);
item.setLastSeen(new Date()); item.setLastSeen(new Date());
} }
......
...@@ -37,6 +37,8 @@ import edu.umiacs.ace.util.EntityManagerServlet; ...@@ -37,6 +37,8 @@ import edu.umiacs.ace.util.EntityManagerServlet;
import edu.umiacs.ace.util.PersistUtil; import edu.umiacs.ace.util.PersistUtil;
import edu.umiacs.util.Strings; import edu.umiacs.util.Strings;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.NDC;
import org.eclipse.persistence.exceptions.DatabaseException;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction; import javax.persistence.EntityTransaction;
...@@ -50,9 +52,11 @@ import java.io.IOException; ...@@ -50,9 +52,11 @@ import java.io.IOException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.ForkJoinPool;
/** /**
* add,modify,remove the settings of a collection * add,modify,remove the settings of a collection
*
* @author toaster * @author toaster
*/ */
public class ManageCollectionServlet extends EntityManagerServlet { public class ManageCollectionServlet extends EntityManagerServlet {
...@@ -77,7 +81,6 @@ public class ManageCollectionServlet extends EntityManagerServlet { ...@@ -77,7 +81,6 @@ public class ManageCollectionServlet extends EntityManagerServlet {
// private static final String PARAM_PEER_COLLECTION_PREFIX = "peer_col_id"; // private static final String PARAM_PEER_COLLECTION_PREFIX = "peer_col_id";
/** /**
*
* @param request * @param request
* @param response * @param response
* @param em * @param em
...@@ -105,23 +108,20 @@ public class ManageCollectionServlet extends EntityManagerServlet { ...@@ -105,23 +108,20 @@ public class ManageCollectionServlet extends EntityManagerServlet {
if (collection.getStorage() != null) { if (collection.getStorage() != null) {
storage = StorageDriverFactory.createStorageAccess(collection, em); storage = StorageDriverFactory.createStorageAccess(collection, em);
} }
/* /*
* Tst to see if we're removing a collection * Tst to see if we're removing a collection
*/ */
if (!Strings.isEmpty(request.getParameter(PARAM_REMOVE)) if (!Strings.isEmpty(request.getParameter(PARAM_REMOVE))
&& request.getParameter(PARAM_REMOVE).toLowerCase().equals("yes")) { && request.getParameter(PARAM_REMOVE).toLowerCase().equals("yes")) {
LOG.debug("removing collection " + collection.getName()); LOG.debug("removing collection " + collection.getName());
removeCollection(em, collection, storage); ForkJoinPool.commonPool().submit(new RemoveThread(collection, storage));
response.sendRedirect("Status?collectionid=-1"); response.sendRedirect("Status?collectionid=-1");
return; return;
} /* } /*
* otherwise, are we updating? * otherwise, are we updating?
*/ */ else if (checkParameters(request)
else if (checkParameters(request)
&& ((paramCheckResponse = checkStorage(storage, request, collection)) == null)) { && ((paramCheckResponse = checkStorage(storage, request, collection)) == null)) {
LOG.debug("updating collection: " + collection.getName()); LOG.debug("updating collection: " + collection.getName());
trans = em.getTransaction(); trans = em.getTransaction();
...@@ -135,8 +135,7 @@ public class ManageCollectionServlet extends EntityManagerServlet { ...@@ -135,8 +135,7 @@ public class ManageCollectionServlet extends EntityManagerServlet {
} /* } /*
* ok, we're just opening an existing collection for modification * ok, we're just opening an existing collection for modification
* - this should display the storage page since storage will be set * - this should display the storage page since storage will be set
*/ */ else {
else {
LOG.debug("loading existing collection: " + collection.getName()); LOG.debug("loading existing collection: " + collection.getName());
dispatcher = request.getRequestDispatcher("collectionmodify.jsp"); dispatcher = request.getRequestDispatcher("collectionmodify.jsp");
} }
...@@ -144,8 +143,7 @@ public class ManageCollectionServlet extends EntityManagerServlet { ...@@ -144,8 +143,7 @@ public class ManageCollectionServlet extends EntityManagerServlet {
* its either a new submission, or requesting a blank page. * its either a new submission, or requesting a blank page.
* We shouldn't set storage information here yet, just create the * We shouldn't set storage information here yet, just create the
* new collection and create a blank storage * new collection and create a blank storage
*/ */ else {
else {
collection = new Collection(); collection = new Collection();
collection.setState(CollectionState.NEVER); collection.setState(CollectionState.NEVER);
populateCollection(request, collection); populateCollection(request, collection);
...@@ -154,8 +152,7 @@ public class ManageCollectionServlet extends EntityManagerServlet { ...@@ -154,8 +152,7 @@ public class ManageCollectionServlet extends EntityManagerServlet {
if (checkParameters(request) && hasDigest(request)) { if (checkParameters(request) && hasDigest(request)) {
LOG.debug("creating collection, empty driver: " + collection.getName()); LOG.debug("creating collection, empty driver: " + collection.getName());
PersistUtil.persist(collection); PersistUtil.persist(collection);
storage = StorageDriverFactory.createStorageAccess(collection, storage = StorageDriverFactory.createStorageAccess(collection, em);
em);
CollectionCountContext.incrementTotalCollections(); CollectionCountContext.incrementTotalCollections();
} }
...@@ -182,37 +179,6 @@ public class ManageCollectionServlet extends EntityManagerServlet { ...@@ -182,37 +179,6 @@ public class ManageCollectionServlet extends EntityManagerServlet {
return result; return result;
} }
private void removeCollection(EntityManager em, Collection collection, StorageDriver storage) {
EntityTransaction trans;
Query q;
trans = em.getTransaction();
trans.begin();
q = em.createNamedQuery("LogEvent.deleteByCollection");
q.setParameter("coll", collection);
q.executeUpdate();
q = em.createNamedQuery("Token.deleteByCollection");
q.setParameter("coll", collection);
q.executeUpdate();
q = em.createNamedQuery("MonitoredItem.deleteByCollection");
q.setParameter("coll", collection);
q.executeUpdate();
q = em.createNamedQuery("FilterEntry.dropByCollection");
q.setParameter("coll", collection);
q.executeUpdate();
q = em.createNamedQuery("ReportSummary.deleteByCollection");
q.setParameter("coll", collection);
q.executeUpdate();
q = em.createNamedQuery("PeerCollection.deleteByCollection");
q.setParameter("coll", collection);
q.executeUpdate();
if (storage != null) {
storage.remove(em);
}
em.remove(collection);
CollectionCountContext.decrementTotalCollections(collection);
trans.commit();
}
private boolean hasDigest(HttpServletRequest req) { private boolean hasDigest(HttpServletRequest req) {
String digest = req.getParameter(PARAM_DIGEST); String digest = req.getParameter(PARAM_DIGEST);
if (!Strings.isEmpty(digest)) { if (!Strings.isEmpty(digest)) {
...@@ -246,29 +212,23 @@ public class ManageCollectionServlet extends EntityManagerServlet { ...@@ -246,29 +212,23 @@ public class ManageCollectionServlet extends EntityManagerServlet {
} }
if (col.getSettings() == null) if (col.getSettings() == null)
col.setSettings(new HashMap<String, String>()); col.setSettings(new HashMap<>());
if (!Strings.isEmpty(req.getParameter(PARAM_EMAILLIST))) { if (!Strings.isEmpty(req.getParameter(PARAM_EMAILLIST))) {
// col.setEmailList(req.getParameter(PARAM_EMAILLIST));
col.getSettings().put(ConfigConstants.ATTR_EMAIL_RECIPIENTS, req.getParameter(PARAM_EMAILLIST)); col.getSettings().put(ConfigConstants.ATTR_EMAIL_RECIPIENTS, req.getParameter(PARAM_EMAILLIST));
} }
//
if (Strings.isValidInt(req.getParameter(PARAM_CHECKPERIOD))) { if (Strings.isValidInt(req.getParameter(PARAM_CHECKPERIOD))) {
col.getSettings().put(ConfigConstants.ATTR_AUDIT_PERIOD, req.getParameter(PARAM_CHECKPERIOD)); col.getSettings().put(ConfigConstants.ATTR_AUDIT_PERIOD, req.getParameter(PARAM_CHECKPERIOD));
// col.setCheckPeriod(Integer.parseInt(req.getParameter(PARAM_CHECKPERIOD)));
} }
//
if (req.getParameter(PARAM_PROXY_DATA) != null) { if (req.getParameter(PARAM_PROXY_DATA) != null) {
col.getSettings().put(ConfigConstants.ATTR_PROXY_DATA, req.getParameter(PARAM_PROXY_DATA)); col.getSettings().put(ConfigConstants.ATTR_PROXY_DATA, req.getParameter(PARAM_PROXY_DATA));
// col.setProxyData("true".equals(req.getParameter(PARAM_PROXY_DATA).toLowerCase()));
} }
//
if (req.getParameter(PARAM_AUDIT_TOKENS) != null) { if (req.getParameter(PARAM_AUDIT_TOKENS) != null) {
col.getSettings().put(ConfigConstants.ATTR_AUDIT_TOKENS, req.getParameter(PARAM_AUDIT_TOKENS)); col.getSettings().put(ConfigConstants.ATTR_AUDIT_TOKENS, req.getParameter(PARAM_AUDIT_TOKENS));
// col.setAuditTokens("true".equals(req.getParameter(PARAM_AUDIT_TOKENS).toLowerCase()));
} }
} }
public boolean checkParameters(HttpServletRequest req) { public boolean checkParameters(HttpServletRequest req) {
...@@ -276,4 +236,93 @@ public class ManageCollectionServlet extends EntityManagerServlet { ...@@ -276,4 +236,93 @@ public class ManageCollectionServlet extends EntityManagerServlet {
&& !Strings.isEmpty(req.getParameter(PARAM_DIR)) && !Strings.isEmpty(req.getParameter(PARAM_DIR))
&& StorageDriverFactory.listResources().contains(req.getParameter(PARAM_DRIVER))); && StorageDriverFactory.listResources().contains(req.getParameter(PARAM_DRIVER)));
} }
private class RemoveThread implements Runnable {
private static final String COLL_ID = "collection_id";
private static final String PARENT_ID = "parent_id";
private static final String PARENT_COLL_ID = "parentcollection_id";
private static final String LOG_EVENT = "logevent";
private static final String LOG_EVENT_ID = COLL_ID;
private static final String ACE_TOKEN = "acetoken";
private static final String ACE_TOKEN_ID = PARENT_COLL_ID;
private static final String MONITORED_ITEM = "monitored_item";
private static final String MONITORED_ITEM_ID = PARENT_COLL_ID;
private static final String FILTER_ENTRY = "filter_entry";
private static final String FILTER_ENTRY_ID = COLL_ID;
private static final String REPORT_SUMMARY = "report_summary";
private static final String REPORT_SUMMARY_ID = COLL_ID;
private static final String PEER_COLLECTION = "peer_collection";
private static final String PEER_COLLECTION_ID = PARENT_ID;
private Boolean abort = false;
private Collection collection;
private StorageDriver storage;
private RemoveThread(Collection collection, StorageDriver storage) {
this.collection = collection;
this.storage = storage;
}
@Override
public void run() {
// this is on a separate thread so re-acquire the entity manager
NDC.push("[Remove " + collection.getName() + "] ");
EntityManager em = PersistUtil.getEntityManager();
// batching to reduce contention on tables when deleting many rows
// todo: native queries aren't the best for this, but deleting with jpql is... weird
// could possibly try to use a CriteriaBuilder and issue a subquery
LOG.info("Starting remove");
batchRm(em, collection, LOG_EVENT, LOG_EVENT_ID);
batchRm(em, collection, ACE_TOKEN, ACE_TOKEN_ID);
batchRm(em, collection, MONITORED_ITEM, MONITORED_ITEM_ID);
batchRm(em, collection, FILTER_ENTRY, FILTER_ENTRY_ID);
batchRm(em, collection, REPORT_SUMMARY, REPORT_SUMMARY_ID);
batchRm(em, collection, PEER_COLLECTION, PEER_COLLECTION_ID);
if (!abort) {
// The collection and storage driver are detached at this point so they need to be
// re-acquired
collection = em.find(Collection.class, collection.getId());
storage = StorageDriverFactory.createStorageAccess(collection, em);
if (storage != null) {
storage.remove(em);
}
LOG.info("Finishing remove");
EntityTransaction transaction = em.getTransaction();
transaction.begin();
em.remove(collection);
transaction.commit();
CollectionCountContext.decrementTotalCollections(collection);
}
NDC.pop();
NDC.clear();
}
private void batchRm(EntityManager em, Collection coll, String table, String row) {
final String queryString = "DELETE FROM %s WHERE %s = %s ORDER BY id LIMIT 1000";
boolean run = true;
LOG.debug("Removing entries for " + table);
Query q = em.createNativeQuery(String.format(queryString, table, row, coll.getId()));
while (run && !abort) {
EntityTransaction trans = em.getTransaction();
trans.begin();
try {
int affected = q.executeUpdate();
trans.commit();
run = (affected != 0);
// LOG.info("Removed " + affected + " rows setting run to " + run);
} catch (DatabaseException e) {
LOG.warn("Caught exception when removing collection", e);
trans.rollback();
run = false;
abort = true;
}
}
}
}
} }
...@@ -35,6 +35,12 @@ import edu.umiacs.ace.monitor.audit.AuditConfigurationContext; ...@@ -35,6 +35,12 @@ import edu.umiacs.ace.monitor.audit.AuditConfigurationContext;
import edu.umiacs.ace.monitor.audit.AuditConfigurationContext.PauseBean; import edu.umiacs.ace.monitor.audit.AuditConfigurationContext.PauseBean;
import edu.umiacs.ace.util.PersistUtil; import edu.umiacs.ace.util.PersistUtil;
import edu.umiacs.sql.SQL; import edu.umiacs.sql.SQL;
import org.apache.log4j.Logger;
import org.apache.log4j.NDC;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.sql.DataSource;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.sql.Blob; import java.sql.Blob;
...@@ -43,11 +49,6 @@ import java.sql.DatabaseMetaData; ...@@ -43,11 +49,6 @@ import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import javax.sql.DataSource;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Logger;
import org.apache.log4j.NDC;
/** /**
* Token migration listner to migrate tokens from the older pre-1.6 version to the current 1.6+ * Token migration listner to migrate tokens from the older pre-1.6 version to the current 1.6+
...@@ -225,7 +226,7 @@ public class TokenMigrationContextListener implements ServletContextListener { ...@@ -225,7 +226,7 @@ public class TokenMigrationContextListener implements ServletContextListener {
+ writeStmt.executeBatch().length); + writeStmt.executeBatch().length);
writeConn.commit(); writeConn.commit();
LOG.info("Entried processed: " + i); LOG.info("Entries processed: " + i);
} catch ( SQLException e ) { } catch ( SQLException e ) {
writeConn.rollback(); writeConn.rollback();
LOG.error("SQL Exception while moving tokens"); LOG.error("SQL Exception while moving tokens");
......
...@@ -139,7 +139,7 @@ public class IngestStore extends EntityManagerServlet { ...@@ -139,7 +139,7 @@ public class IngestStore extends EntityManagerServlet {
IngestThreadPool tPool = IngestThreadPool.getInstance(); IngestThreadPool tPool = IngestThreadPool.getInstance();
tPool.submitTokens(batchTokens, coll); tPool.submitTokens(batchTokens, coll);
response.sendRedirect("/TokenImportStatus?active=" + coll.getId()); response.sendRedirect("TokenImportStatus?active=" + coll.getId());
} }