Commit ad392fa7 authored by Michael Ritter's avatar Michael Ritter
Browse files

#50 Additional servlet for handling TokenImportStatus

parent f58efa9a
package edu.umiacs.ace.monitor.register;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.util.EntityManagerServlet;
import edu.umiacs.ace.util.KSFuture;
import edu.umiacs.ace.util.PersistUtil;
import org.apache.log4j.Logger;
import javax.persistence.EntityManager;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class ImportStatusServlet extends EntityManagerServlet {
private static final Logger LOG = Logger.getLogger(ImportStatusServlet.class);
private static final String ACTIVE_PARAM = "active";
@Override
protected void processRequest(HttpServletRequest request,
HttpServletResponse response,
EntityManager em) throws ServletException, IOException {
IngestThreadPool pool = IngestThreadPool.getInstance();
long id = getParameter(request, ACTIVE_PARAM, -1);
if (id > 0) {
LOG.info("Querying for collection " + id);
EntityManager manager = PersistUtil.getEntityManager();
Collection collection = manager.find(Collection.class, id);
if (collection != null) {
LOG.info("Found collection " + id);
KSFuture<IngestSupervisor> ksSupervisor = pool.getCache().get(collection);
if (ksSupervisor != null) {
request.setAttribute(ACTIVE_PARAM, ksSupervisor.getKnownResult());
}
} else {
LOG.info("Unable to get collection " + id);
}
}
request.setAttribute("results", pool);
RequestDispatcher dispatcher = request.getRequestDispatcher("ingeststatus.jsp");
dispatcher.forward(request, response);
}
}
...@@ -33,37 +33,31 @@ package edu.umiacs.ace.monitor.register; ...@@ -33,37 +33,31 @@ package edu.umiacs.ace.monitor.register;
import edu.umiacs.ace.monitor.core.Collection; import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.monitor.core.MonitoredItem; import edu.umiacs.ace.monitor.core.MonitoredItem;
import edu.umiacs.ace.monitor.core.Token; import edu.umiacs.ace.monitor.core.Token;
import edu.umiacs.ace.monitor.log.LogEventManager;
import edu.umiacs.ace.token.TokenStoreEntry; import edu.umiacs.ace.token.TokenStoreEntry;
import edu.umiacs.ace.token.TokenStoreReader; import edu.umiacs.ace.token.TokenStoreReader;
import edu.umiacs.ace.util.EntityManagerServlet; import edu.umiacs.ace.util.EntityManagerServlet;
import edu.umiacs.ace.util.TokenUtil; import edu.umiacs.ace.util.TokenUtil;
import edu.umiacs.util.Strings; import edu.umiacs.util.Strings;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.commons.fileupload.FileItemIterator; import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream; import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.fileupload.util.Streams; import org.apache.commons.fileupload.util.Streams;
//import org.apache.tomcat.util.http.fileupload.FileUploadBase;
import javax.persistence.EntityManager;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
/** /**
* Servlet to ingest token stores * Servlet to ingest token stores
* @author toaster * @author toaster
*/ */
public class IngestStore extends EntityManagerServlet { public class IngestStore extends EntityManagerServlet {
// private static final Logger LOG = Logger.getLogger(IngestStore.class);
private LogEventManager logManager;
// private long session;
public static final String PAGE_RESULTS = "results"; public static final String PAGE_RESULTS = "results";
@Override @Override
...@@ -73,8 +67,7 @@ public class IngestStore extends EntityManagerServlet { ...@@ -73,8 +67,7 @@ public class IngestStore extends EntityManagerServlet {
Collection coll = null; //getCollection(request, em); Collection coll = null; //getCollection(request, em);
MonitoredItem item = getItem(request, em); MonitoredItem item = getItem(request, em);
TokenStoreReader tokenReader = null; TokenStoreReader tokenReader = null;
RequestDispatcher dispatcher; Map<String, Token> batchTokens = new HashMap<>();
Map<String, Token> batchTokens = new HashMap<String, Token>();
if (item != null && !item.isDirectory()) if (item != null && !item.isDirectory())
throw new ServletException( "Selected item is not a directory " throw new ServletException( "Selected item is not a directory "
...@@ -92,6 +85,11 @@ public class IngestStore extends EntityManagerServlet { ...@@ -92,6 +85,11 @@ public class IngestStore extends EntityManagerServlet {
FileItemStream fileItem = iter.next(); FileItemStream fileItem = iter.next();
InputStream stream = fileItem.openStream(); InputStream stream = fileItem.openStream();
// todo: find a better way to do this
// going to add some documentation for the next time anyone comes through here
// the "upload" has the form fields as well, so we need to iterate over it in order
// to get both the collection id (and instantiate the collection) as well as get
// the token store
if (fileItem.isFormField()) { if (fileItem.isFormField()) {
// Basic find collection id and set the collection // Basic find collection id and set the collection
...@@ -112,6 +110,7 @@ public class IngestStore extends EntityManagerServlet { ...@@ -112,6 +110,7 @@ public class IngestStore extends EntityManagerServlet {
// May want to log this stuff // May want to log this stuff
tokenReader = new TokenStoreReader(fileItem.openStream()); tokenReader = new TokenStoreReader(fileItem.openStream());
// If the above fails an exception is thrown rendering this useless
if ( tokenReader == null ) { if ( tokenReader == null ) {
throw new ServletException("Token file is corrupt"); throw new ServletException("Token file is corrupt");
} }
...@@ -140,11 +139,7 @@ public class IngestStore extends EntityManagerServlet { ...@@ -140,11 +139,7 @@ public class IngestStore extends EntityManagerServlet {
IngestThreadPool tPool = IngestThreadPool.getInstance(); IngestThreadPool tPool = IngestThreadPool.getInstance();
tPool.submitTokens(batchTokens, coll); tPool.submitTokens(batchTokens, coll);
HttpSession session = request.getSession(); response.sendRedirect("/TokenImportStatus?active=" + coll.getId());
session.setAttribute(PAGE_RESULTS, tPool);
dispatcher = request.getRequestDispatcher("ingeststatus.jsp");
dispatcher.forward(request, response);
} }
} }
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param> <context-param>
<description>Parameter used by replication startup listener to check replicas for new files every specified number of days</description> <description>Parameter used by replication startup listener to check replicas for new files
every specified number of days
</description>
<param-name>checkPeriod</param-name> <param-name>checkPeriod</param-name>
<param-value>5</param-value> <param-value>5</param-value>
</context-param> </context-param>
<filter> <filter>
<filter-name>PersistenceFilter</filter-name> <filter-name>PersistenceFilter</filter-name>
<filter-class>edu.umiacs.ace.rest.PersistenceServiceFilter</filter-class> <filter-class>edu.umiacs.ace.rest.PersistenceServiceFilter</filter-class>
</filter> </filter>
...@@ -36,7 +40,8 @@ ...@@ -36,7 +40,8 @@
</listener> </listener>
<listener> <listener>
<description>Auto Audit Disabled migration</description> <description>Auto Audit Disabled migration</description>
<listener-class>edu.umiacs.ace.monitor.settings.AutoAuditMigrationContextListener</listener-class> <listener-class>edu.umiacs.ace.monitor.settings.AutoAuditMigrationContextListener
</listener-class>
</listener> </listener>
<!-- Some of the migrations rely on the pause bean from the ACC, so init it early --> <!-- Some of the migrations rely on the pause bean from the ACC, so init it early -->
<listener> <listener>
...@@ -53,11 +58,13 @@ ...@@ -53,11 +58,13 @@
</listener> </listener>
<listener> <listener>
<description>ServletContextListener</description> <description>ServletContextListener</description>
<listener-class>edu.umiacs.ace.monitor.core.CollectionSettingsMigrationListener</listener-class> <listener-class>edu.umiacs.ace.monitor.core.CollectionSettingsMigrationListener
</listener-class>
</listener> </listener>
<listener> <listener>
<description>Settings migration to db</description> <description>Settings migration to db</description>
<listener-class>edu.umiacs.ace.monitor.settings.SettingsMigrationContextListener</listener-class> <listener-class>edu.umiacs.ace.monitor.settings.SettingsMigrationContextListener
</listener-class>
</listener> </listener>
<!-- normal startup listeners, schedulers, etc --> <!-- normal startup listeners, schedulers, etc -->
...@@ -86,7 +93,7 @@ ...@@ -86,7 +93,7 @@
<listener-class>edu.umiacs.ace.driver.QueryThrottle</listener-class> <listener-class>edu.umiacs.ace.driver.QueryThrottle</listener-class>
</listener> </listener>
<listener> <listener>
<description>Initial ingestion configuration </description> <description>Initial ingestion configuration</description>
<listener-class>edu.umiacs.ace.monitor.register.IngestContextListener</listener-class> <listener-class>edu.umiacs.ace.monitor.register.IngestContextListener</listener-class>
</listener> </listener>
<servlet> <servlet>
...@@ -195,6 +202,10 @@ ...@@ -195,6 +202,10 @@
<servlet-name>IngestStore</servlet-name> <servlet-name>IngestStore</servlet-name>
<servlet-class>edu.umiacs.ace.monitor.register.IngestStore</servlet-class> <servlet-class>edu.umiacs.ace.monitor.register.IngestStore</servlet-class>
</servlet> </servlet>
<servlet>
<servlet-name>TokenImportStatus</servlet-name>
<servlet-class>edu.umiacs.ace.monitor.register.ImportStatusServlet</servlet-class>
</servlet>
<servlet> <servlet>
<servlet-name>ChangePassword</servlet-name> <servlet-name>ChangePassword</servlet-name>
<servlet-class>edu.umiacs.ace.monitor.users.ChangePasswordServlet</servlet-class> <servlet-class>edu.umiacs.ace.monitor.users.ChangePasswordServlet</servlet-class>
...@@ -211,7 +222,7 @@ ...@@ -211,7 +222,7 @@
<servlet-name>DeleteSettingsServlet</servlet-name> <servlet-name>DeleteSettingsServlet</servlet-name>
<servlet-class>edu.umiacs.ace.monitor.settings.DeleteSettingsServlet</servlet-class> <servlet-class>edu.umiacs.ace.monitor.settings.DeleteSettingsServlet</servlet-class>
</servlet> </servlet>
<servlet> <servlet>
<servlet-name>StatisticsServlet</servlet-name> <servlet-name>StatisticsServlet</servlet-name>
<servlet-class>edu.umiacs.ace.stats.StatisticsServlet</servlet-class> <servlet-class>edu.umiacs.ace.stats.StatisticsServlet</servlet-class>
</servlet> </servlet>
...@@ -312,10 +323,6 @@ ...@@ -312,10 +323,6 @@
<servlet-name>ClearResourceServlet</servlet-name> <servlet-name>ClearResourceServlet</servlet-name>
<url-pattern>/ClearResource</url-pattern> <url-pattern>/ClearResource</url-pattern>
</servlet-mapping> </servlet-mapping>
<!--<servlet-mapping>
<servlet-name>IngestStore</servlet-name>
<url-pattern>/IngestStore</url-pattern>
</servlet-mapping>-->
<servlet-mapping> <servlet-mapping>
<servlet-name>ChangePassword</servlet-name> <servlet-name>ChangePassword</servlet-name>
<url-pattern>/ChangePassword</url-pattern> <url-pattern>/ChangePassword</url-pattern>
...@@ -324,6 +331,10 @@ ...@@ -324,6 +331,10 @@
<servlet-name>IngestStore</servlet-name> <servlet-name>IngestStore</servlet-name>
<url-pattern>/Ingest</url-pattern> <url-pattern>/Ingest</url-pattern>
</servlet-mapping> </servlet-mapping>
<servlet-mapping>
<servlet-name>TokenImportStatus</servlet-name>
<url-pattern>/TokenImportStatus</url-pattern>
</servlet-mapping>
<servlet-mapping> <servlet-mapping>
<servlet-name>SettingsServlet</servlet-name> <servlet-name>SettingsServlet</servlet-name>
<url-pattern>/UpdateSettings</url-pattern> <url-pattern>/UpdateSettings</url-pattern>
...@@ -861,9 +872,9 @@ ...@@ -861,9 +872,9 @@
<security-role> <security-role>
<description>Add/edit/remove stuff in /PartnerSite</description> <description>Add/edit/remove stuff in /PartnerSite</description>
<role-name>Modify Partner Sites</role-name> <role-name>Modify Partner Sites</role-name>
</security-role> </security-role>
<security-role> <security-role>
<description>Role used to modify system settings</description> <description>Role used to modify system settings</description>
<role-name>Modify System Settings</role-name> <role-name>Modify System Settings</role-name>
</security-role> </security-role>
</web-app> </web-app>
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