Commit 1504d7dc authored by Michael Ritter's avatar Michael Ritter
Browse files

Merge branch '40-additional-collection-states' into 'develop'

Resolve "Additional Collection States"

See merge request !7
parents d7ef94a2 adb73058
...@@ -45,6 +45,7 @@ import edu.umiacs.ace.monitor.access.CollectionCountContext; ...@@ -45,6 +45,7 @@ import edu.umiacs.ace.monitor.access.CollectionCountContext;
import edu.umiacs.ace.monitor.compare.CollectionCompare2; import edu.umiacs.ace.monitor.compare.CollectionCompare2;
import edu.umiacs.ace.monitor.compare.CompareResults; import edu.umiacs.ace.monitor.compare.CompareResults;
import edu.umiacs.ace.monitor.core.Collection; import edu.umiacs.ace.monitor.core.Collection;
import edu.umiacs.ace.monitor.core.CollectionState;
import edu.umiacs.ace.monitor.core.ConfigConstants; import edu.umiacs.ace.monitor.core.ConfigConstants;
import edu.umiacs.ace.monitor.core.MonitoredItem; import edu.umiacs.ace.monitor.core.MonitoredItem;
import edu.umiacs.ace.monitor.core.MonitoredItemManager; import edu.umiacs.ace.monitor.core.MonitoredItemManager;
...@@ -347,7 +348,6 @@ public final class AuditThread extends Thread implements CancelCallback { ...@@ -347,7 +348,6 @@ public final class AuditThread extends Thread implements CancelCallback {
private void performAudit() { private void performAudit() {
// 1. Setup audit // 1. Setup audit
//TODO Clean up filtering creation
PathFilter filter = new SimpleFilter(coll); PathFilter filter = new SimpleFilter(coll);
Date startDate = new Date(); Date startDate = new Date();
...@@ -399,6 +399,10 @@ public final class AuditThread extends Thread implements CancelCallback { ...@@ -399,6 +399,10 @@ public final class AuditThread extends Thread implements CancelCallback {
iterableItems.cancel(); iterableItems.cancel();
} }
// 4. Clean up, set local inactive
lastFileSeen = "looking for missed items";
setInactiveBefore(startDate);
if (cancel || abortException != null) { if (cancel || abortException != null) {
return; return;
} }
...@@ -411,14 +415,9 @@ public final class AuditThread extends Thread implements CancelCallback { ...@@ -411,14 +415,9 @@ public final class AuditThread extends Thread implements CancelCallback {
batch = null; batch = null;
} }
// 4. Clean up, set local inactive
lastFileSeen = "looking for missed items";
setInactiveBefore(startDate);
// harvest remote collections // harvest remote collections
lastFileSeen = "comparing to peer sites"; lastFileSeen = "comparing to peer sites";
compareToPeers(); compareToPeers();
} }
private void generateAuditReport() { private void generateAuditReport() {
...@@ -450,7 +449,7 @@ public final class AuditThread extends Thread implements CancelCallback { ...@@ -450,7 +449,7 @@ public final class AuditThread extends Thread implements CancelCallback {
if (abortException instanceof InterruptedException if (abortException instanceof InterruptedException
|| abortException.getCause() instanceof InterruptedException) { || abortException.getCause() instanceof InterruptedException) {
LOG.trace("Audit ending with Interrupt"); LOG.trace("Audit ending with Interrupt");
logManager.persistCollectionEvent(LogEnum.FILE_AUDIT_FINISH, logManager.persistCollectionEvent(LogEnum.FILE_AUDIT_ABORT,
"Audit Interrupted", em); "Audit Interrupted", em);
} else { } else {
LOG.error("Uncaught exception in audit thread", abortException); LOG.error("Uncaught exception in audit thread", abortException);
...@@ -458,12 +457,12 @@ public final class AuditThread extends Thread implements CancelCallback { ...@@ -458,12 +457,12 @@ public final class AuditThread extends Thread implements CancelCallback {
String message = Strings.exceptionAsString(abortException); String message = Strings.exceptionAsString(abortException);
logManager.persistCollectionEvent( logManager.persistCollectionEvent(
LogEnum.SYSTEM_ERROR, message, em); LogEnum.SYSTEM_ERROR, message, em);
logManager.persistCollectionEvent(LogEnum.FILE_AUDIT_FINISH, logManager.persistCollectionEvent(LogEnum.FILE_AUDIT_ABORT,
"Uncaught audit thread exception ", em); "Uncaught audit thread exception ", em);
} }
} else if (cancel) { } else if (cancel) {
logManager.persistCollectionEvent(LogEnum.FILE_AUDIT_FINISH, logManager.persistCollectionEvent(LogEnum.FILE_AUDIT_CANCEL,
"Audit interrupted by user or token registration", em); "Audit interrupted by user or token registration", em);
LOG.trace("Audit ending on cancel request"); LOG.trace("Audit ending on cancel request");
} else { } else {
...@@ -729,10 +728,12 @@ public final class AuditThread extends Thread implements CancelCallback { ...@@ -729,10 +728,12 @@ public final class AuditThread extends Thread implements CancelCallback {
MonitoredItemManager mim = new MonitoredItemManager(em); MonitoredItemManager mim = new MonitoredItemManager(em);
if (mim.countErrorsInCollection(coll) == 0) { if (abortException != null || cancel) {
coll.setState('A'); coll.setState(CollectionState.INTERRUPTED);
} else if (mim.countErrorsInCollection(coll) == 0) {
coll.setState(CollectionState.ACTIVE);
} else { } else {
coll.setState('E'); coll.setState(CollectionState.ERROR);
} }
EntityTransaction trans = em.getTransaction(); EntityTransaction trans = em.getTransaction();
...@@ -743,7 +744,7 @@ public final class AuditThread extends Thread implements CancelCallback { ...@@ -743,7 +744,7 @@ public final class AuditThread extends Thread implements CancelCallback {
} }
private void setInactiveBefore(Date d) { private void setInactiveBefore(Date d) {
if (baseItemPathList != null || cancel || abortException != null) { if (baseItemPathList != null) {
return; return;
} }
......
...@@ -242,15 +242,7 @@ public class AuditThreadFactory { ...@@ -242,15 +242,7 @@ public class AuditThreadFactory {
// Clean up everything which may contain a reference to the thread // Clean up everything which may contain a reference to the thread
// Thread will only ever be removed once, so no need to worry about // Thread will only ever be removed once, so no need to worry about
// race conditions // race conditions
// AuditThread thread = runningAudits.remove(c); audits.remove(c);
// if ( thread != null ) {
// LOG.debug("Removing old audit thread from thread pool executor");
// executor.remove(thread);
// blockingQueue.remove(thread);
// runningAudits.remove(c);
// thread = null;
// }
KSFuture<AuditThread> future = audits.remove(c);
} }
public static boolean useSSL() { public static boolean useSSL() {
......
...@@ -38,6 +38,7 @@ import edu.umiacs.util.Argument; ...@@ -38,6 +38,7 @@ import edu.umiacs.util.Argument;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.CollectionTable; import javax.persistence.CollectionTable;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.ElementCollection; import javax.persistence.ElementCollection;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
...@@ -59,6 +60,7 @@ import java.util.Map; ...@@ -59,6 +60,7 @@ import java.util.Map;
/** /**
* Collection states * Collection states
* - A active * - A active
* - I interrupted
* - N - never completely scanned (default for new collections) * - N - never completely scanned (default for new collections)
* - E - * - E -
* @author toaster * @author toaster
...@@ -101,7 +103,8 @@ public class Collection implements Serializable { ...@@ -101,7 +103,8 @@ public class Collection implements Serializable {
private String storage; private String storage;
private char state; @Convert(converter = CollectionStateConverter.class)
private CollectionState state;
@Column(name = "COLGROUP") @Column(name = "COLGROUP")
private String group; private String group;
...@@ -193,11 +196,11 @@ public class Collection implements Serializable { ...@@ -193,11 +196,11 @@ public class Collection implements Serializable {
} }
public char getState() { public char getState() {
return state; return state.asChar();
} }
public void setState( char state ) { public void setState( char state ) {
this.state = state; this.state = CollectionState.fromChar(state);
} }
public String getStorage() { public String getStorage() {
...@@ -216,4 +219,7 @@ public class Collection implements Serializable { ...@@ -216,4 +219,7 @@ public class Collection implements Serializable {
this.group = group; this.group = group;
} }
public void setState(CollectionState state) {
this.state = state;
}
} }
package edu.umiacs.ace.monitor.core;
/**
* A test to see how we can do this
*
* Created by shake on 3/30/17.
*/
public enum CollectionState {
ACTIVE, INTERRUPTED, NEVER, ERROR;
public static CollectionState fromChar(char state) {
switch (state) {
case 'A':
return ACTIVE;
case 'I':
return INTERRUPTED;
case 'N':
return NEVER;
case 'E':
return ERROR;
default:
throw new IllegalArgumentException("Unknown state " + state);
}
}
public char asChar() {
return this.name().charAt(0);
}
}
package edu.umiacs.ace.monitor.core;
import javax.persistence.AttributeConverter;
/**
* Converter to go from CollectionState enum to a Char
*
* Created by shake on 3/30/17.
*/
public class CollectionStateConverter implements AttributeConverter<CollectionState, String> {
@Override
public String convertToDatabaseColumn(CollectionState collectionState) {
switch (collectionState) {
case ACTIVE:
return "A";
case NEVER:
return "N";
case INTERRUPTED:
return "I";
case ERROR:
return "E";
default:
throw new IllegalArgumentException("Unknown state " + collectionState);
}
}
@Override
public CollectionState convertToEntityAttribute(String s) {
switch (s) {
case "A":
return CollectionState.ACTIVE;
case "N":
return CollectionState.NEVER;
case "I":
return CollectionState.INTERRUPTED;
case "E":
return CollectionState.ERROR;
default:
throw new IllegalArgumentException("Unknown state " + s);
}
}
}
...@@ -100,6 +100,10 @@ public enum LogEnum { ...@@ -100,6 +100,10 @@ public enum LogEnum {
FILE_REGISTER(25, "File Registered", "New file registered but is not ready for auditing"), 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"), FILE_AUDIT_FALLBACK(26, "File Audit Fallback", "File Audit could not connect to the IMS, falling back to audit-only mode"),
SMTP_ERROR(27, "SMTP Communication Error", "Could not connect to designated SMTP host"), SMTP_ERROR(27, "SMTP Communication Error", "Could not connect to designated SMTP host"),
// audit stop errors
FILE_AUDIT_CANCEL(30, "File Audit Cancel", "Auditing of this collection's files was cancelled"),
FILE_AUDIT_ABORT(31, "File Audit Aborted", "Auditing of this collection's files was aborted"),
SYSTEM_ERROR(99, "System Error", "Unknown system error occurred, check server logs"); SYSTEM_ERROR(99, "System Error", "Unknown system error occurred, check server logs");
private int type; private int type;
private String shortName; private String shortName;
...@@ -178,6 +182,11 @@ public enum LogEnum { ...@@ -178,6 +182,11 @@ public enum LogEnum {
case 26: case 26:
return FILE_AUDIT_FALLBACK; return FILE_AUDIT_FALLBACK;
case 30:
return FILE_AUDIT_CANCEL;
case 31:
return FILE_AUDIT_ABORT;
case 99: case 99:
return SYSTEM_ERROR; return SYSTEM_ERROR;
} }
......
...@@ -282,42 +282,43 @@ public class LogServlet extends EntityManagerServlet { ...@@ -282,42 +282,43 @@ public class LogServlet extends EntityManagerServlet {
* @return * @return
*/ */
private String generateTypeString( Map<String, String> selectedTypes ) { private String generateTypeString( Map<String, String> selectedTypes ) {
String returnString = ""; StringBuilder returnString = new StringBuilder();
if ( selectedTypes.size() > 0 ) { if ( selectedTypes.size() > 0 ) {
returnString = " l.logType IN ( "; returnString = new StringBuilder(" l.logType IN ( ");
} }
for ( String key : selectedTypes.keySet() ) { for ( String key : selectedTypes.keySet() ) {
if ( CHOICE_ERRORS.equals(key) ) { if ( CHOICE_ERRORS.equals(key) ) {
returnString += LogEnum.SYSTEM_ERROR.getType() + ","; returnString.append(LogEnum.SYSTEM_ERROR.getType()).append(",");
returnString += LogEnum.SITE_UNACCESSABLE.getType() + ","; returnString.append(LogEnum.SITE_UNACCESSABLE.getType()).append(",");
returnString += LogEnum.LOG_TYPE_UNKNOWN.getType() + ","; returnString.append(LogEnum.LOG_TYPE_UNKNOWN.getType()).append(",");
returnString += LogEnum.CREATE_TOKEN_ERROR.getType() + ","; returnString.append(LogEnum.CREATE_TOKEN_ERROR.getType()).append(",");
returnString += LogEnum.ERROR_READING.getType() + ","; returnString.append(LogEnum.ERROR_READING.getType()).append(",");
returnString += LogEnum.UNKNOWN_IMS_COMMUNICATION_ERROR.getType() + ","; returnString.append(LogEnum.UNKNOWN_IMS_COMMUNICATION_ERROR.getType()).append(",");
} else if ( CHOICE_MISSING.equals(key) ) { } else if ( CHOICE_MISSING.equals(key) ) {
returnString += LogEnum.FILE_MISSING.getType() + ","; returnString.append(LogEnum.FILE_MISSING.getType()).append(",");
returnString += LogEnum.FILE_CORRUPT.getType() + ","; returnString.append(LogEnum.FILE_CORRUPT.getType()).append(",");
returnString += LogEnum.MISSING_TOKEN.getType() + ","; returnString.append(LogEnum.MISSING_TOKEN.getType()).append(",");
} else if ( CHOICE_NEWMASTER.equals(key) ) { } else if ( CHOICE_NEWMASTER.equals(key) ) {
returnString += LogEnum.FILE_NEW.getType() + ","; returnString.append(LogEnum.FILE_NEW.getType()).append(",");
returnString += LogEnum.ADD_TOKEN.getType() + ","; returnString.append(LogEnum.ADD_TOKEN.getType()).append(",");
returnString += LogEnum.FILE_ONLINE.getType() + ","; returnString.append(LogEnum.FILE_ONLINE.getType()).append(",");
returnString.append(LogEnum.FILE_REGISTER.getType()).append(",");
} else if ( CHOICE_SYNC.equals(key) ) { } else if ( CHOICE_SYNC.equals(key) ) {
returnString += LogEnum.FILE_AUDIT_FINISH.getType() + ","; returnString.append(LogEnum.FILE_AUDIT_FINISH.getType()).append(",");
returnString += LogEnum.FILE_AUDIT_START.getType() + ","; returnString.append(LogEnum.FILE_AUDIT_START.getType()).append(",");
returnString.append(LogEnum.FILE_AUDIT_CANCEL.getType()).append(",");
returnString.append(LogEnum.FILE_AUDIT_ABORT.getType()).append(",");
} }
} }
if ( returnString.length() > 0 ) { if ( returnString.length() > 0 ) {
// remove last ',' // remove last ','
returnString = returnString.substring(0, returnString.length() - 1); returnString = new StringBuilder(returnString.substring(0, returnString.length() - 1));
returnString += ")"; returnString.append(")");
} }
return returnString; return returnString.toString();
} }
/** /**
......
...@@ -15,5 +15,7 @@ ...@@ -15,5 +15,7 @@
</constructor-result> </constructor-result>
</sql-result-set-mapping> </sql-result-set-mapping>
<converter class="edu.umiacs.ace.monitor.core.CollectionStateConverter"/>
</entity-mappings> </entity-mappings>
...@@ -231,6 +231,9 @@ ...@@ -231,6 +231,9 @@
<c:when test="${'E'.bytes[0] == item.collection.state }"> <c:when test="${'E'.bytes[0] == item.collection.state }">
<img src="images/error.jpg" title="Collection contains errors" alt="Collection contains errors"/> <img src="images/error.jpg" title="Collection contains errors" alt="Collection contains errors"/>
</c:when> </c:when>
<c:when test="${'I'.bytes[0] == item.collection.state }">
<img src="images/error.jpg" title="Last audit was interrupted" alt="Last audit was interrupted"/>
</c:when>
<c:otherwise> <c:otherwise>
<img src="images/file-bad.jpg" title="Complete audit has not occurred" alt="Complete audit has not occurred"/> <img src="images/file-bad.jpg" title="Complete audit has not occurred" alt="Complete audit has not occurred"/>
</c:otherwise> </c:otherwise>
......
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