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;
import edu.umiacs.ace.monitor.compare.CollectionCompare2;
import edu.umiacs.ace.monitor.compare.CompareResults;
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.MonitoredItem;
import edu.umiacs.ace.monitor.core.MonitoredItemManager;
......@@ -347,7 +348,6 @@ public final class AuditThread extends Thread implements CancelCallback {
private void performAudit() {
// 1. Setup audit
//TODO Clean up filtering creation
PathFilter filter = new SimpleFilter(coll);
Date startDate = new Date();
......@@ -399,6 +399,10 @@ public final class AuditThread extends Thread implements CancelCallback {
iterableItems.cancel();
}
// 4. Clean up, set local inactive
lastFileSeen = "looking for missed items";
setInactiveBefore(startDate);
if (cancel || abortException != null) {
return;
}
......@@ -411,14 +415,9 @@ public final class AuditThread extends Thread implements CancelCallback {
batch = null;
}
// 4. Clean up, set local inactive
lastFileSeen = "looking for missed items";
setInactiveBefore(startDate);
// harvest remote collections
lastFileSeen = "comparing to peer sites";
compareToPeers();
}
private void generateAuditReport() {
......@@ -450,7 +449,7 @@ public final class AuditThread extends Thread implements CancelCallback {
if (abortException instanceof InterruptedException
|| abortException.getCause() instanceof InterruptedException) {
LOG.trace("Audit ending with Interrupt");
logManager.persistCollectionEvent(LogEnum.FILE_AUDIT_FINISH,
logManager.persistCollectionEvent(LogEnum.FILE_AUDIT_ABORT,
"Audit Interrupted", em);
} else {
LOG.error("Uncaught exception in audit thread", abortException);
......@@ -458,12 +457,12 @@ public final class AuditThread extends Thread implements CancelCallback {
String message = Strings.exceptionAsString(abortException);
logManager.persistCollectionEvent(
LogEnum.SYSTEM_ERROR, message, em);
logManager.persistCollectionEvent(LogEnum.FILE_AUDIT_FINISH,
logManager.persistCollectionEvent(LogEnum.FILE_AUDIT_ABORT,
"Uncaught audit thread exception ", em);
}
} else if (cancel) {
logManager.persistCollectionEvent(LogEnum.FILE_AUDIT_FINISH,
logManager.persistCollectionEvent(LogEnum.FILE_AUDIT_CANCEL,
"Audit interrupted by user or token registration", em);
LOG.trace("Audit ending on cancel request");
} else {
......@@ -729,10 +728,12 @@ public final class AuditThread extends Thread implements CancelCallback {
MonitoredItemManager mim = new MonitoredItemManager(em);
if (mim.countErrorsInCollection(coll) == 0) {
coll.setState('A');
if (abortException != null || cancel) {
coll.setState(CollectionState.INTERRUPTED);
} else if (mim.countErrorsInCollection(coll) == 0) {
coll.setState(CollectionState.ACTIVE);
} else {
coll.setState('E');
coll.setState(CollectionState.ERROR);
}
EntityTransaction trans = em.getTransaction();
......@@ -743,7 +744,7 @@ public final class AuditThread extends Thread implements CancelCallback {
}
private void setInactiveBefore(Date d) {
if (baseItemPathList != null || cancel || abortException != null) {
if (baseItemPathList != null) {
return;
}
......
......@@ -242,15 +242,7 @@ public class AuditThreadFactory {
// Clean up everything which may contain a reference to the thread
// Thread will only ever be removed once, so no need to worry about
// race conditions
// AuditThread thread = runningAudits.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);
audits.remove(c);
}
public static boolean useSSL() {
......
......@@ -38,6 +38,7 @@ import edu.umiacs.util.Argument;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
......@@ -59,6 +60,7 @@ import java.util.Map;
/**
* Collection states
* - A active
* - I interrupted
* - N - never completely scanned (default for new collections)
* - E -
* @author toaster
......@@ -101,7 +103,8 @@ public class Collection implements Serializable {
private String storage;
private char state;
@Convert(converter = CollectionStateConverter.class)
private CollectionState state;
@Column(name = "COLGROUP")
private String group;
......@@ -193,11 +196,11 @@ public class Collection implements Serializable {
}
public char getState() {
return state;
return state.asChar();
}
public void setState( char state ) {
this.state = state;
this.state = CollectionState.fromChar(state);
}
public String getStorage() {
......@@ -216,4 +219,7 @@ public class Collection implements Serializable {
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 {
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"),
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");
private int type;
private String shortName;
......@@ -178,6 +182,11 @@ public enum LogEnum {
case 26:
return FILE_AUDIT_FALLBACK;
case 30:
return FILE_AUDIT_CANCEL;
case 31:
return FILE_AUDIT_ABORT;
case 99:
return SYSTEM_ERROR;
}
......
......@@ -282,42 +282,43 @@ public class LogServlet extends EntityManagerServlet {
* @return
*/
private String generateTypeString( Map<String, String> selectedTypes ) {
String returnString = "";
StringBuilder returnString = new StringBuilder();
if ( selectedTypes.size() > 0 ) {
returnString = " l.logType IN ( ";
returnString = new StringBuilder(" l.logType IN ( ");
}
for ( String key : selectedTypes.keySet() ) {
if ( CHOICE_ERRORS.equals(key) ) {
returnString += LogEnum.SYSTEM_ERROR.getType() + ",";
returnString += LogEnum.SITE_UNACCESSABLE.getType() + ",";
returnString += LogEnum.LOG_TYPE_UNKNOWN.getType() + ",";
returnString += LogEnum.CREATE_TOKEN_ERROR.getType() + ",";
returnString += LogEnum.ERROR_READING.getType() + ",";
returnString += LogEnum.UNKNOWN_IMS_COMMUNICATION_ERROR.getType() + ",";
returnString.append(LogEnum.SYSTEM_ERROR.getType()).append(",");
returnString.append(LogEnum.SITE_UNACCESSABLE.getType()).append(",");
returnString.append(LogEnum.LOG_TYPE_UNKNOWN.getType()).append(",");
returnString.append(LogEnum.CREATE_TOKEN_ERROR.getType()).append(",");
returnString.append(LogEnum.ERROR_READING.getType()).append(",");
returnString.append(LogEnum.UNKNOWN_IMS_COMMUNICATION_ERROR.getType()).append(",");
} else if ( CHOICE_MISSING.equals(key) ) {
returnString += LogEnum.FILE_MISSING.getType() + ",";
returnString += LogEnum.FILE_CORRUPT.getType() + ",";
returnString += LogEnum.MISSING_TOKEN.getType() + ",";
returnString.append(LogEnum.FILE_MISSING.getType()).append(",");
returnString.append(LogEnum.FILE_CORRUPT.getType()).append(",");
returnString.append(LogEnum.MISSING_TOKEN.getType()).append(",");
} else if ( CHOICE_NEWMASTER.equals(key) ) {
returnString += LogEnum.FILE_NEW.getType() + ",";
returnString += LogEnum.ADD_TOKEN.getType() + ",";
returnString += LogEnum.FILE_ONLINE.getType() + ",";
returnString.append(LogEnum.FILE_NEW.getType()).append(",");
returnString.append(LogEnum.ADD_TOKEN.getType()).append(",");
returnString.append(LogEnum.FILE_ONLINE.getType()).append(",");
returnString.append(LogEnum.FILE_REGISTER.getType()).append(",");
} else if ( CHOICE_SYNC.equals(key) ) {
returnString += LogEnum.FILE_AUDIT_FINISH.getType() + ",";
returnString += LogEnum.FILE_AUDIT_START.getType() + ",";
returnString.append(LogEnum.FILE_AUDIT_FINISH.getType()).append(",");
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 ) {
// remove last ','
returnString = returnString.substring(0, returnString.length() - 1);
returnString += ")";
returnString = new StringBuilder(returnString.substring(0, returnString.length() - 1));
returnString.append(")");
}
return returnString;
return returnString.toString();
}
/**
......
......@@ -15,5 +15,7 @@
</constructor-result>
</sql-result-set-mapping>
<converter class="edu.umiacs.ace.monitor.core.CollectionStateConverter"/>
</entity-mappings>
......@@ -231,6 +231,9 @@
<c:when test="${'E'.bytes[0] == item.collection.state }">
<img src="images/error.jpg" title="Collection contains errors" alt="Collection contains errors"/>
</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>
<img src="images/file-bad.jpg" title="Complete audit has not occurred" alt="Complete audit has not occurred"/>
</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