Skip to content

Commit

Permalink
pulling in repair stats
Browse files Browse the repository at this point in the history
  • Loading branch information
barmintor committed Mar 18, 2013
1 parent 8cde5ec commit 4ac087a
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 22 deletions.
Expand Up @@ -22,7 +22,9 @@ public interface DatabaseService {

long getSuccessCount();

void addStat(int successCount, int errorCount);
long getRepairCount();

void addStat(int successCount, int errorCount, int repairCount);

List<DailyStatistics> getDailyStatistics();

Expand Down
Expand Up @@ -33,9 +33,14 @@ public void setSessionFactory(SessionFactory sessionFactory) {
@Transactional
public void addResult(ObjectFixity res) {
Session sess = sessionFactory.openSession();
int errors = res.getErrors().size();
int errors = 0;
int repairs = 0;
for (DatastreamFixity df: res.getErrors()){
if (df.getType() == ResultType.ERROR) errors++;
if (df.getType() == ResultType.REPAIRED) repairs++;
}
int successes = res.getSuccesses().size();
addStat(successes, errors);
addStat(successes, errors, repairs);
sess.save(res);
sess.flush();
sess.close();
Expand All @@ -60,6 +65,9 @@ public List<ObjectFixity> getResults(String objectId) {
for (ObjectFixity r : results) {
Hibernate.initialize(r.getSuccesses());
Hibernate.initialize(r.getErrors());
for (DatastreamFixity p:r.getErrors()){
Hibernate.initialize(p.getProblems());
}
}
sess.close();
return results;
Expand All @@ -77,6 +85,9 @@ public List<ObjectFixity> getResults(int offset, int length) {
for (ObjectFixity r : results) {
Hibernate.initialize(r.getSuccesses());
Hibernate.initialize(r.getErrors());
for (DatastreamFixity p:r.getErrors()){
Hibernate.initialize(p.getProblems());
}
}
sess.close();
return results;
Expand Down Expand Up @@ -117,13 +128,25 @@ public long getErrorCount() {
return value;
}

@Override
@Transactional(readOnly = true)
public long getRepairCount() {
Session sess = sessionFactory.openSession();
Long value = (Long) sess.createCriteria(DatastreamFixity.class)
.add(Restrictions.eq("type", ResultType.REPAIRED))
.setProjection(Projections.rowCount())
.uniqueResult();
sess.close();
return value;
}
@Override
@Transactional
public void addStat(int successCount, int errorCount) {
public void addStat(int successCount, int errorCount, int repairCount) {
Session sess = sessionFactory.openSession();
DailyStatistics stat = getDailyStat(new Date());
stat.setErrorCount(stat.getErrorCount() + errorCount);
stat.setSuccessCount(stat.getSuccessCount() + successCount);
stat.setRepairCount(stat.getRepairCount() + repairCount);
sess.saveOrUpdate(stat);
sess.flush();
sess.close();
Expand All @@ -140,6 +163,7 @@ private DailyStatistics getDailyStat(Date date) {
stat.setDate(date);
stat.setErrorCount(0);
stat.setSuccessCount(0);
stat.setRepairCount(0);
}
sess.close();
return stat;
Expand All @@ -162,6 +186,9 @@ public ObjectFixity getResult(long recordId) {
Session sess = sessionFactory.openSession();
ObjectFixity result = (ObjectFixity) sess.get(ObjectFixity.class, recordId);
Hibernate.initialize(result.getErrors());
for (DatastreamFixity p:result.getErrors()){
Hibernate.initialize(p.getProblems());
}
Hibernate.initialize(result.getSuccesses());
sess.close();
return result;
Expand Down
Expand Up @@ -54,7 +54,7 @@ public ObjectFixity check(String objectId) throws IOException, NoSuchAlgorithmEx
final org.fcrepo.jaxb.responses.management.DatastreamFixity ds = client.getDatastreamFixity(objectId, dsId);

DatastreamFixity dsFixity = new DatastreamFixity(ds);
if (dsFixity.getType() == ResultType.ERROR){
if (dsFixity.getType() != ResultType.SUCCESS){
errors.add(dsFixity);
} else {
successes.add(dsFixity);
Expand Down
Expand Up @@ -156,6 +156,7 @@ public GeneralStatistics getStatistics(){
stats.setNumObjects(databaseService.getResultCount());
stats.setErrorCount(databaseService.getErrorCount());
stats.setSuccessCount(databaseService.getSuccessCount());
stats.setRepairCount(databaseService.getRepairCount());
return stats;
}

Expand Down
Expand Up @@ -32,6 +32,8 @@ public class DailyStatistics {
private int errorCount;
@XmlAttribute(name = "successCount")
private int successCount;
@XmlAttribute(name = "repairCount")
private int repairCount;

public long getId() {
return id;
Expand Down Expand Up @@ -64,5 +66,13 @@ public int getSuccessCount() {
public void setSuccessCount(int successCount) {
this.successCount = successCount;
}

public int getRepairCount() {
return repairCount;
}

public void setRepairCount(int repairCount) {
this.repairCount = repairCount;
}

}
@@ -1,17 +1,23 @@
package org.fcrepo.services.fixity.model;

import java.net.URI;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlEnum;
import javax.xml.bind.annotation.XmlTransient;

Expand All @@ -28,7 +34,7 @@ public class DatastreamFixity {

@XmlEnum
public enum ResultType {
SUCCESS, ERROR;
SUCCESS, ERROR, REPAIRED;
}

@Id
Expand All @@ -48,6 +54,12 @@ public enum ResultType {
@XmlElement(name = "details")
private String details;

@XmlElementWrapper(name = "problems")
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name = "PROBLEM_ID")
private List<FixityProblem> problems = new ArrayList<FixityProblem>();


@Transient
private org.fcrepo.jaxb.responses.management.DatastreamFixity result;

Expand All @@ -68,21 +80,56 @@ public DatastreamFixity(org.fcrepo.jaxb.responses.management.DatastreamFixity re
this.datastreamId = result.dsId;
this.timestamp = result.timestamp;
this.type = ResultType.SUCCESS;
int aggregateStatus = FixityResult.SUCCESS;
for (FixityResult status:result.statuses){
if (!status.validChecksum){
details = checksumErrorDetails(result, status.dsChecksumType, status.dsChecksum, status.computedChecksum);
type = ResultType.ERROR;
break;
if ((status.status & FixityResult.BAD_CHECKSUM) == FixityResult.BAD_CHECKSUM){
FixityProblem problem = new FixityProblem();
problem.cacheId = status.storeIdentifier;
problem.details = checksumErrorDetails(result, status.dsChecksumType, status.dsChecksum, status.computedChecksum);
if ((status.status & FixityResult.REPAIRED) != FixityResult.REPAIRED) {
aggregateStatus = (FixityResult.BAD_CHECKSUM + FixityResult.BAD_SIZE);
aggregateStatus |= FixityResult.BAD_CHECKSUM;
problem.type = ResultType.ERROR;
} else {
if (aggregateStatus == FixityResult.SUCCESS) {
aggregateStatus |= status.status;
} else {
aggregateStatus &= status.status;
}
problem.type = ResultType.REPAIRED;
}
this.problems.add(problem);
}
if (!status.validSize){
details = sizeErrorDetails(result, status.dsSize, status.computedSize);
type = ResultType.ERROR;
break;
if ((status.status & FixityResult.BAD_SIZE) == FixityResult.BAD_SIZE){
FixityProblem problem = new FixityProblem();
problem.cacheId = status.storeIdentifier;
problem.details = sizeErrorDetails(result, status.dsSize, status.computedSize);
if ((status.status & FixityResult.REPAIRED) != FixityResult.REPAIRED) {
aggregateStatus = (FixityResult.BAD_CHECKSUM + FixityResult.BAD_SIZE);
aggregateStatus |= FixityResult.BAD_CHECKSUM;
problem.type = ResultType.ERROR;
} else {
if (aggregateStatus == FixityResult.SUCCESS) {
aggregateStatus |= status.status;
} else {
aggregateStatus &= status.status;
}
problem.type = ResultType.REPAIRED;
}
this.problems.add(problem);
}
}
if (type != ResultType.ERROR) {
if (aggregateStatus == FixityResult.SUCCESS) {
type = ResultType.SUCCESS;
details = successDetails(result);
}
else if ((aggregateStatus & FixityResult.REPAIRED) == FixityResult.REPAIRED) {
type = ResultType.REPAIRED;
details = "There were fixity problems detected, but they were repaired.";
} else {
type = ResultType.ERROR;
details = "There were fixity problems detected, and they were not repaired.";
}
}

public long getId() {
Expand Down Expand Up @@ -120,6 +167,14 @@ public String getDetails() {
public void setDetails(String details) {
this.details = details;
}

public List<FixityProblem> getProblems() {
return this.problems;
}

public void setProblems(List<FixityProblem> problems) {
this.problems = problems;
}

private static String successDetails(org.fcrepo.jaxb.responses.management.DatastreamFixity result) {
String details = "Success for Checksum: " + result.statuses.get(0).dsChecksum;
Expand Down
@@ -0,0 +1,47 @@
package org.fcrepo.services.fixity.model;

import java.net.URI;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;

import org.fcrepo.services.fixity.model.DatastreamFixity.ResultType;

@Entity
@Table(name = "cache_problems")
@XmlAccessorType(XmlAccessType.FIELD)
public class FixityProblem {
@Id
@GeneratedValue
@XmlAttribute(name = "record-id")
private long id;

@XmlAttribute(name = "type")
public ResultType type;

@XmlAttribute(name = "cache-id")
public String cacheId;

@XmlElement(name = "details")
public String details;

private static String checksumErrorDetails(org.fcrepo.jaxb.responses.management.DatastreamFixity result, String type, URI expected, URI actual) {
String details = "The calculated checksums of type " + type + " for the datastream " + result.dsId
+ " of the object "
+ result.objectId + " does not match the saved value: [" + actual + " != " + expected + " (expected)]";
return details;
}

private static String sizeErrorDetails(org.fcrepo.jaxb.responses.management.DatastreamFixity result, long expected, long actual) {
String details = "The calculated size for datastream " + result.dsId + " of the object " + result.objectId +
" does not match the saved value: [" + actual + " != " + expected + "(expected)]";
return details;
}

}
Expand Up @@ -14,6 +14,8 @@ public class GeneralStatistics {
private long errorCount;
@XmlAttribute(name = "success-count")
private long successCount;
@XmlAttribute(name = "repair-count")
private long repairCount;

public long getNumObjects() {
return numObjects;
Expand All @@ -39,4 +41,12 @@ public void setSuccessCount(long successCount) {
this.successCount = successCount;
}

public long getRepairCount() {
return this.repairCount;
}

public void setRepairCount(long repairCount) {
this.repairCount = repairCount;
}

}
Expand Up @@ -19,6 +19,8 @@
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import org.fcrepo.services.fixity.model.DatastreamFixity.ResultType;

@XmlRootElement(name = "fixity-result")
@XmlAccessorType(XmlAccessType.FIELD)
@Entity
Expand All @@ -35,6 +37,9 @@ public class ObjectFixity {

@XmlAttribute(name = "success")
private boolean success;

@XmlAttribute(name = "repaired")
private boolean repaired;

@XmlAttribute(name = "timestamp")
private Date timestamp;
Expand All @@ -59,6 +64,10 @@ public ObjectFixity(String pid, Date timestamp, List<DatastreamFixity> successes
this.pid = pid;
this.timestamp = timestamp;
this.success = (errors.size() == 0);
this.repaired = (!success);
for (DatastreamFixity df:errors){
this.repaired &= (df.getType() == ResultType.REPAIRED);
}
this.errors = errors;
this.successes = successes;
}
Expand Down Expand Up @@ -94,6 +103,10 @@ public void setPid(String pid) {
public void setSuccess(boolean success) {
this.success = success;
}

public void setRepaired(boolean repaired) {
this.repaired = repaired;
}

public void setErrors(List<DatastreamFixity> errors) {
this.errors = errors;
Expand All @@ -102,6 +115,10 @@ public void setErrors(List<DatastreamFixity> errors) {
public boolean isSuccess() {
return success;
}

public boolean isRepaired() {
return repaired;
}

public List<DatastreamFixity> getErrors() {
return errors;
Expand Down
Expand Up @@ -38,6 +38,7 @@
<value>org.fcrepo.services.fixity.model.DailyStatistics</value>
<value>org.fcrepo.services.fixity.model.ObjectFixity</value>
<value>org.fcrepo.services.fixity.model.DatastreamFixity</value>
<value>org.fcrepo.services.fixity.model.FixityProblem</value>
</list>
</property>
<property name="hibernateProperties">
Expand Down

0 comments on commit 4ac087a

Please sign in to comment.