Commit 8e52c897 authored by shake's avatar shake
Browse files

Added audit-only mode.

Added roles to Collection REST methods

git-svn-id: https://subversion.umiacs.umd.edu/ace/trunk@179 f1b3a171-7291-4a19-a512-95ad0ad9394a
parent 751b34b9
......@@ -14,7 +14,7 @@
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<netbeans.hint.deploy.server>Tomcat6</netbeans.hint.deploy.server>
<netbeans.hint.deploy.server>Tomcat60</netbeans.hint.deploy.server>
</properties>
<build>
......
......@@ -31,7 +31,7 @@
package edu.umiacs.ace.driver;
import edu.umiacs.ace.monitor.core.ConfigConstants;
import edu.umiacs.ace.monitor.core.SettingsUtil;
import edu.umiacs.ace.monitor.settings.SettingsUtil;
import edu.umiacs.ace.util.EntityManagerServlet;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.monitor.core.MonitoredItem;
......
......@@ -30,19 +30,22 @@
// $Id$
package edu.umiacs.ace.monitor.audit;
import edu.umiacs.ace.monitor.core.SettingsUtil;
import edu.umiacs.ace.monitor.settings.SettingsUtil;
import edu.umiacs.ace.driver.StorageDriver;
import edu.umiacs.ace.driver.StorageDriverFactory;
import edu.umiacs.ace.util.PersistUtil;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.monitor.core.ConfigConstants;
import edu.umiacs.ace.monitor.core.MonitoredItem;
import edu.umiacs.ace.monitor.settings.SettingsConstants;
import edu.umiacs.ace.monitor.settings.SettingsParameter;
import edu.umiacs.util.Strings;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.NoResultException;
import javax.persistence.Query;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
......@@ -65,6 +68,7 @@ public final class AuditConfigurationContext implements ServletContextListener {
private static final String PARAM_IMS_TOKEN_CLASS = "ims.tokenclass";
private static final String PARAM_DISABLE_AUDIT = "auto.audit.disable";
private static final String PARAM_THROTTLE_MAXAUDIT = "throttle.maxaudit";
private static final String PARAM_AUDIT_ONLY = "audit.only";
public static final String ATTRIBUTE_PAUSE = "pause";
private static final long HOUR = 1000 * 60 * 60;
private Timer checkTimer;
......@@ -104,6 +108,18 @@ public final class AuditConfigurationContext implements ServletContextListener {
}
}
q.setParameter("attr", PARAM_AUDIT_ONLY);
try {
s = (SettingsParameter) q.getSingleResult();
AuditThreadFactory.setAuditOnly(Boolean.valueOf(s.getValue()));
}catch ( NoResultException ex ) {
EntityTransaction trans = em.getTransaction();
em.persist(new SettingsParameter(SettingsConstants.PARAM_AUDIT_ONLY,
SettingsConstants.auditOnly, false));
trans.commit();
AuditThreadFactory.setAuditOnly(false);
}
PauseBean pb = new PauseBean();
ctx.setAttribute(ATTRIBUTE_PAUSE, pb);
......
......@@ -54,7 +54,7 @@ import edu.umiacs.ace.monitor.reporting.SchedulerContextListener;
import edu.umiacs.ace.monitor.reporting.SummaryGenerator;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.monitor.core.ConfigConstants;
import edu.umiacs.ace.monitor.core.SettingsUtil;
import edu.umiacs.ace.monitor.settings.SettingsUtil;
import edu.umiacs.ace.monitor.log.LogEnum;
import edu.umiacs.ace.monitor.log.LogEvent;
import edu.umiacs.ace.monitor.peers.PeerCollection;
......@@ -82,6 +82,7 @@ import org.apache.log4j.NDC;
public final class AuditThread extends Thread implements CancelCallback {
private static final Logger LOG = Logger.getLogger(AuditThread.class);
private boolean fallback = false;
private Map<AceToken, MonitoredItem> itemMap =
new ConcurrentHashMap<AceToken, MonitoredItem>();
private String imsHost;
......@@ -104,11 +105,13 @@ public final class AuditThread extends Thread implements CancelCallback {
private String tokenClassName;
private LogEventManager logManager;
private AuditIterable<FileBean> iterableItems;
private boolean auditOnly;
AuditThread(Collection c, StorageDriver driver,
AuditThread(Collection c, StorageDriver driver, boolean auditOnly,
MonitoredItem... startItem) {
this.driver = driver;
this.coll = c;
this.auditOnly = auditOnly;
if (startItem != null && startItem[0] != null) {
baseItemPathList = Arrays.copyOf(startItem, startItem.length);
}
......@@ -190,11 +193,24 @@ public final class AuditThread extends Thread implements CancelCallback {
callback = new FileAuditCallback(coll, session, this);
boolean auditTokens = SettingsUtil.getBoolean(coll, ConfigConstants.ATTR_AUDIT_TOKENS);
/*
if (!openIms() || (auditTokens
&& !openTokenValidator(MessageDigest.getInstance(
"SHA-256")))) {
return;
}
*
*/
System.out.println(!auditOnly);
if( !auditOnly ) {
fallback = !openIms();
if ( !fallback ) {
if ( auditTokens &&
!openTokenValidator(MessageDigest.getInstance("SHA-256"))) {
return;
}
}
}
performAudit();
// Let outstanding tokens finish, TODO, de-hackify this.
......@@ -247,7 +263,9 @@ public final class AuditThread extends Thread implements CancelCallback {
trans.begin();
em.persist(logManager.createCollectionEvent(
LogEnum.UNKNOWN_IMS_COMMUNICATION_ERROR, e));
// em.persist(logManager.imsCommError("", coll, e));
em.persist(logManager.createCollectionEvent(
LogEnum.FILE_AUDIT_FALLBACK, imsHost));
trans.commit();
em.close();
return false;
......@@ -456,7 +474,7 @@ public final class AuditThread extends Thread implements CancelCallback {
String parentName = extractAndRegisterParent(mim, currentFile);
MonitoredItem item = null;
if ((item = mim.getItemByPath(fileName, coll)) != null) {
LogEvent event;
LogEvent event = null;
LOG.trace("Updating existing item" + fileName);
item.setLastVisited(new Date());
// if item is in error, log a message and update its state to M
......@@ -466,7 +484,7 @@ public final class AuditThread extends Thread implements CancelCallback {
} else {
if (item.getToken() != null) {
event = validateIntegrity(currentFile, item);
} else {
} else if (!auditOnly && !fallback) {
// we have no token, so set state to T and enqueue
event = requestNewToken(currentFile, item);
}
......@@ -479,7 +497,7 @@ public final class AuditThread extends Thread implements CancelCallback {
}
em.merge(item);
trans.commit();
} else {
} else if (!auditOnly && !fallback) {
// OK, no registered item, do the registration
LogEvent[] event = addNewFile(currentFile, fileName,
parentName, mim);
......@@ -494,7 +512,6 @@ public final class AuditThread extends Thread implements CancelCallback {
trans.commit();
}
}
}
} finally {
em.close();
......
......@@ -48,6 +48,7 @@ public class AuditThreadFactory {
private static String imsHost = null;
private static int imsPort = 8080;
private static String tokenClass = "SHA-256";
private static boolean auditOnly = false;
public static void setIMS( String ims ) {
imsHost = ims;
......@@ -73,6 +74,10 @@ public class AuditThreadFactory {
AuditThreadFactory.imsPort = imsPort;
}
static void setAuditOnly(boolean auditOnlyMode) {
AuditThreadFactory.auditOnly = auditOnlyMode;
}
/**
* Return a new or existing thread if any room is available New threads will start replication
*
......@@ -89,7 +94,8 @@ public class AuditThreadFactory {
// {
// pathList = new String[startItem.size()];
// }
AuditThread newThread = new AuditThread(c, tri, startItem);
AuditThread newThread = new AuditThread(c, tri, auditOnly,
startItem);
newThread.setImsHost(imsHost);
newThread.setImsport(imsPort);
newThread.setTokenClassName(tokenClass);
......
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.umiacs.ace.monitor.core;
/**
*
* @author toaster
*/
public class SettingsUtil {
/**
*
* @param c
* @param attr
* @return true if collection, settings are not null and parameter is "true"
*/
public static boolean getBoolean(Collection c, String attr) {
if (!containsKey(c, attr)) {
return false;
}
return "true".equalsIgnoreCase(c.getSettings().get(attr));
}
public static String getString(Collection c, String attr) {
if (!containsKey(c, attr)) {
return null;
}
return c.getSettings().get(attr);
}
public static int getInt(Collection c, String attr, int def) {
if (!containsKey(c, attr)) {
return def;
}
try {
return Integer.parseInt(c.getSettings().get(attr));
} catch (NumberFormatException e) {
return def;
}
}
public static boolean containsKey(Collection c, String attr) {
return (c != null && c.getSettings() != null
&& c.getSettings().containsKey(attr));
}
}
......@@ -98,6 +98,7 @@ public enum LogEnum {
TOKEN_AUDIT_FINISH(23, "Token Audit Finish", "Auditing of this collection's tokens finished"),
TOKEN_INGEST_UPDATE(24, "Token Ingest Update", "Token was out of date and has been updated"),
FILE_REGISTER(25, "File Registered", "New file registered but is not ready for auditing"),
FILE_AUDIT_FALLBACK(26, "File Audit Fallback", "File Audit could not connect to the IMS, falling back to audit-only mode"),
SYSTEM_ERROR(99, "System Error", "Unknown system error occurred, check server logs");
private int type;
private String shortName;
......@@ -173,6 +174,8 @@ public enum LogEnum {
return TOKEN_INGEST_UPDATE;
case 25:
return FILE_REGISTER;
case 26:
return FILE_AUDIT_FALLBACK;
case 99:
return SYSTEM_ERROR;
......
......@@ -6,6 +6,7 @@ package edu.umiacs.ace.monitor.settings;
*/
public class SettingsConstants {
// Attributes
public static final String PARAM_AUDIT_ONLY="audit.only";
public static final String PARAM_IMS = "ims";
public static final String PARAM_IMS_PORT = "ims.port";
public static final String PARAM_IMS_TOKEN_CLASS = "ims.tokenclass";
......@@ -31,6 +32,7 @@ public class SettingsConstants {
public static final String PARAM_INGEST = "ingest.maxthreads";
// Default Values
public static final String auditOnly = "false";
public static final String mailServer = "localhost.localdomain";
public static final String mailFrom = "acemail@localhost";
public static final String maxAudit = "3";
......
package edu.umiacs.ace.monitor.settings;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.util.PersistUtil;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
......@@ -154,8 +153,49 @@ public class SettingsUtil {
SettingsConstants.log4JRootLogger,false));
defaults.add(new SettingsParameter(SettingsConstants.PARAM_INGEST,
SettingsConstants.maxIngestThreads, false));
defaults.add(new SettingsParameter(SettingsConstants.PARAM_AUDIT_ONLY,
SettingsConstants.auditOnly, false));
return defaults;
}
/**
*
* @param c
* @param attr
* @return true if collection, settings are not null and parameter is "true"
*/
public static boolean getBoolean(Collection c, String attr) {
if (!containsKey(c, attr)) {
return false;
}
return "true".equalsIgnoreCase(c.getSettings().get(attr));
}
public static String getString(Collection c, String attr) {
if (!containsKey(c, attr)) {
return null;
}
return c.getSettings().get(attr);
}
public static int getInt(Collection c, String attr, int def) {
if (!containsKey(c, attr)) {
return def;
}
try {
return Integer.parseInt(c.getSettings().get(attr));
} catch (NumberFormatException e) {
return def;
}
}
public static boolean containsKey(Collection c, String attr) {
return (c != null && c.getSettings() != null
&& c.getSettings().containsKey(attr));
}
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ package edu.umiacs.ace.rest;
import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.util.PersistUtil;
import java.util.logging.Level;
import javax.annotation.security.RolesAllowed;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.ws.rs.Consumes;
......@@ -52,6 +53,7 @@ public class CollectionManagement {
@POST
@Path("xml")
@Consumes(MediaType.APPLICATION_XML)
@RolesAllowed("CollectionModify")
public void addCollectionXML(Collection coll) {
checkCollection(coll);
EntityManager em = PersistUtil.getEntityManager();
......@@ -64,6 +66,7 @@ public class CollectionManagement {
@POST
@Path("json")
@Consumes(MediaType.APPLICATION_JSON)
@RolesAllowed("CollectionModify")
// Instead of unmarshalling, this may be able to just take a Collection
public void addCollectionJSON(JSONObject jsonObj){
JAXBContext jc = null;
......@@ -103,6 +106,7 @@ public class CollectionManagement {
@GET
@Produces(MediaType.APPLICATION_XML)
@Path("xml/{id}")
@RolesAllowed("Browse")
public Collection getCollectionXML(@PathParam("id") long collId){
EntityManager em = PersistUtil.getEntityManager();
return em.find(Collection.class, collId);
......@@ -111,6 +115,7 @@ public class CollectionManagement {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("json/{id}")
@RolesAllowed({"Browse"})
public Collection getCollectionJSON(@PathParam("id") long collId){
EntityManager em = PersistUtil.getEntityManager();
return em.find(Collection.class, collId);
......
......@@ -52,6 +52,11 @@
<div class="settingsVal"><input type=text name="auto.audit.disable" value="${currSettings['auto.audit.disable']}"/></div>
<div class="settingsHelp"><img src="images/help.png" title="Start automated auditing"></div>
</div>
<div class="settingsRow">
<div class="settingsName">Audit Only Mode:</div>
<div class="settingsVal"><input type=text name="audit.only" value="${currSettings['audit.only']}"/></div>
<div class="settingsHelp"><img src="images/help.png" title="If true, do not attempt to register new items or contact the IMS during auditing"></div>
</div>
<div class="settingsRow">
<div class="settingsName">IMS Host:</div>
<div class="settingsVal"><input type=text name="ims" value="${currSettings['ims']}"/></div>
......
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