mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 15:33:09 +00:00
adressing helix' comments to the DS-2659 PR
This commit is contained in:
@@ -4,8 +4,6 @@
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*
|
||||
* by lindat-dev team
|
||||
*/
|
||||
package org.dspace.health;
|
||||
|
||||
@@ -13,6 +11,7 @@ import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Abstract check interface.
|
||||
* @author LINDAT/CLARIN dev team
|
||||
*/
|
||||
|
||||
public abstract class Check {
|
||||
|
@@ -4,8 +4,6 @@
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*
|
||||
* by lindat-dev team
|
||||
*/
|
||||
package org.dspace.health;
|
||||
|
||||
@@ -18,6 +16,9 @@ import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author LINDAT/CLARIN dev team
|
||||
*/
|
||||
public class ChecksumCheck extends Check {
|
||||
|
||||
@Override
|
||||
@@ -27,9 +28,6 @@ public class ChecksumCheck extends Check {
|
||||
Date process_start = Calendar.getInstance().getTime();
|
||||
checker.setProcessStartDate(process_start);
|
||||
checker.setDispatcher(
|
||||
// new LimitedCountDispatcher(new SimpleDispatcher(new
|
||||
// BitstreamInfoDAO(), null, false), 1)
|
||||
// loop through all files
|
||||
new SimpleDispatcher(new BitstreamInfoDAO(), process_start, false));
|
||||
|
||||
md5_collector collector = new md5_collector();
|
||||
|
@@ -4,66 +4,82 @@
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*
|
||||
* by lindat-dev team
|
||||
*/
|
||||
package org.dspace.health;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.ItemIterator;
|
||||
import org.dspace.content.Metadatum;
|
||||
import org.dspace.app.util.CollectionDropDown;
|
||||
import org.dspace.content.*;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
import org.dspace.storage.rdbms.TableRow;
|
||||
import org.dspace.storage.rdbms.TableRowIterator;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author LINDAT/CLARIN dev team
|
||||
*/
|
||||
public class Core {
|
||||
|
||||
// get info
|
||||
//
|
||||
public static String getCollectionSizesInfo() throws SQLException {
|
||||
String ret = "";
|
||||
final StringBuffer ret = new StringBuffer();
|
||||
List<TableRow> rows = sql(
|
||||
"SELECT "
|
||||
+ "(SELECT text_value FROM metadatavalue "
|
||||
+ "WHERE metadata_field_id=64 AND resource_type_id=3 AND resource_id=col.collection_id) AS name, "
|
||||
+ "SUM(bit.size_bytes) AS sum "
|
||||
+ "FROM collection2item col, item2bundle item, bundle2bitstream bun, bitstream bit "
|
||||
+ "WHERE col.item_id=item.item_id AND item.bundle_id=bun.bundle_id AND bun.bitstream_id=bit.bitstream_id "
|
||||
+ "GROUP BY col.collection_id;");
|
||||
"SELECT" +
|
||||
"(SELECT text_value FROM metadatavalue NATURAL JOIN metadatafieldregistry " +
|
||||
"NATURAL JOIN metadataschemaregistry WHERE element='title' AND qualifier IS NULL AND short_id='dc'" +
|
||||
" AND resource_type_id=3 AND resource_id=col.collection_id) AS name," +
|
||||
"SUM(bit.size_bytes) AS sum," +
|
||||
" collection_id" +
|
||||
" FROM collection2item col, item2bundle item, bundle2bitstream bun, bitstream bit" +
|
||||
" WHERE col.item_id=item.item_id AND item.bundle_id=bun.bundle_id AND bun.bitstream_id=bit.bitstream_id " +
|
||||
"GROUP BY col.collection_id;"
|
||||
);
|
||||
long total_size = 0;
|
||||
final Context context = new Context();
|
||||
Collections.sort(rows, new Comparator<TableRow>() {
|
||||
@Override
|
||||
public int compare(TableRow o1, TableRow o2) {
|
||||
try {
|
||||
return CollectionDropDown.collectionPath(Collection.find(context, o1.getIntColumn("collection_id"))).compareTo(
|
||||
CollectionDropDown.collectionPath(Collection.find(context, o2.getIntColumn("collection_id")))
|
||||
);
|
||||
} catch (Exception e) {
|
||||
ret.append(e.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
for (TableRow row : rows) {
|
||||
double size = row.getLongColumn("sum") / (1024. * 1024.);
|
||||
double size = row.getLongColumn("sum");
|
||||
total_size += size;
|
||||
ret += String.format(
|
||||
"\t%s: %s\n", row.getStringColumn("name"), FileUtils.byteCountToDisplaySize((long)size));
|
||||
Collection col = Collection.find(context, row.getIntColumn("collection_id"));
|
||||
ret.append(String.format(
|
||||
"\t%s: %s\n", CollectionDropDown.collectionPath(col), FileUtils.byteCountToDisplaySize((long) size)));
|
||||
}
|
||||
ret += String.format(
|
||||
"Total size: %s\n", FileUtils.byteCountToDisplaySize(total_size));
|
||||
context.abort();
|
||||
ret.append(String.format(
|
||||
"Total size: %s\n", FileUtils.byteCountToDisplaySize(total_size)));
|
||||
|
||||
ret += String.format(
|
||||
"Resource without policy: %d\n", getBitstreamsWithoutPolicyCount());
|
||||
ret.append(String.format(
|
||||
"Resource without policy: %d\n", getBitstreamsWithoutPolicyCount()));
|
||||
|
||||
ret += String.format(
|
||||
"Deleted bitstreams: %d\n", getBitstreamsDeletedCount());
|
||||
ret.append(String.format(
|
||||
"Deleted bitstreams: %d\n", getBitstreamsDeletedCount()));
|
||||
|
||||
rows = getBitstreamOrphansRows();
|
||||
String list_str = "";
|
||||
for (TableRow row : rows) {
|
||||
list_str += String.format("%d, ", row.getIntColumn("bitstream_id"));
|
||||
}
|
||||
ret += String.format(
|
||||
"Orphan bitstreams: %d [%s]\n", rows.size(), list_str);
|
||||
ret.append(String.format(
|
||||
"Orphan bitstreams: %d [%s]\n", rows.size(), list_str));
|
||||
|
||||
return ret;
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
public static String getObjectSizesInfo() throws SQLException {
|
||||
@@ -183,13 +199,14 @@ public class Core {
|
||||
Context c = new Context();
|
||||
TableRowIterator irows = DatabaseManager
|
||||
.query(c,
|
||||
"SELECT eperson_group_id, "
|
||||
+ "(SELECT text_value FROM metadatavalue "
|
||||
+ "WHERE metadata_field_id=64 AND resource_type_id=6 AND resource_id=eperson_group_id) AS name "
|
||||
+ "FROM epersongroup "
|
||||
+ "WHERE eperson_group_id NOT IN (SELECT eperson_group_id FROM epersongroup2eperson)");
|
||||
"SELECT eperson_group_id," +
|
||||
"(SELECT text_value FROM metadatavalue NATURAL JOIN metadatafieldregistry" +
|
||||
" NATURAL JOIN metadataschemaregistry WHERE element='title'" +
|
||||
" AND qualifier IS NULL AND short_id='dc' AND resource_type_id=6 AND resource_id=eperson_group_id) AS name "+
|
||||
"FROM epersongroup " +
|
||||
"WHERE eperson_group_id NOT IN (SELECT eperson_group_id FROM epersongroup2eperson)");
|
||||
for (TableRow row : irows.toList()) {
|
||||
ret.add( row.getStringColumn("name") );
|
||||
ret.add(String.format("id=%s;name=%s", row.getIntColumn("eperson_group_id"), row.getStringColumn("name") ));
|
||||
}
|
||||
c.complete();
|
||||
return ret;
|
||||
|
@@ -4,8 +4,6 @@
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*
|
||||
* by lindat-dev team
|
||||
*/
|
||||
package org.dspace.health;
|
||||
|
||||
@@ -19,6 +17,9 @@ import org.dspace.embargo.service.EmbargoService;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @author LINDAT/CLARIN dev team
|
||||
*/
|
||||
public class EmbargoCheck extends Check {
|
||||
|
||||
private static final EmbargoService embargoService = EmbargoServiceFactory.getInstance().getEmbargoService();
|
||||
|
@@ -4,8 +4,6 @@
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*
|
||||
* by lindat-dev team
|
||||
*/
|
||||
package org.dspace.health;
|
||||
|
||||
@@ -16,6 +14,9 @@ import org.dspace.core.ConfigurationManager;
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author LINDAT/CLARIN dev team
|
||||
*/
|
||||
public class InfoCheck extends Check {
|
||||
|
||||
@Override
|
||||
@@ -27,9 +28,9 @@ public class InfoCheck extends Check {
|
||||
).append("\n");
|
||||
|
||||
sb.append("From - Till: ").append(
|
||||
new SimpleDateFormat("MM/dd/yyyy").format(ri.from().getTime())
|
||||
new SimpleDateFormat("yyyy-MM-dd").format(ri.from().getTime())
|
||||
).append(" - ").append(
|
||||
new SimpleDateFormat("MM/dd/yyyy").format(ri.till().getTime())
|
||||
new SimpleDateFormat("yyyy-MM-dd").format(ri.till().getTime())
|
||||
).append("\n");
|
||||
|
||||
sb.append("Url: ").append(
|
||||
|
@@ -4,8 +4,6 @@
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*
|
||||
* by lindat-dev team
|
||||
*/
|
||||
package org.dspace.health;
|
||||
|
||||
@@ -15,6 +13,9 @@ import org.dspace.storage.rdbms.TableRow;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author LINDAT/CLARIN dev team
|
||||
*/
|
||||
public class ItemCheck extends Check {
|
||||
|
||||
@Override
|
||||
@@ -23,7 +24,7 @@ public class ItemCheck extends Check {
|
||||
int tot_cnt = 0;
|
||||
try {
|
||||
for (Map.Entry<String, Integer> name_count : Core.getCommunities()) {
|
||||
ret += String.format("Collection [%s]: %d\n",
|
||||
ret += String.format("Community [%s]: %d\n",
|
||||
name_count.getKey(), name_count.getValue());
|
||||
tot_cnt += name_count.getValue();
|
||||
}
|
||||
|
@@ -4,8 +4,6 @@
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*
|
||||
* by lindat-dev team
|
||||
*/
|
||||
package org.dspace.health;
|
||||
|
||||
@@ -17,6 +15,9 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author LINDAT/CLARIN dev team
|
||||
*/
|
||||
public class LogAnalyserCheck extends Check {
|
||||
|
||||
final static private String[][] interesting_fields = new String[][] {
|
||||
@@ -56,7 +57,7 @@ public class LogAnalyserCheck extends Check {
|
||||
sb.append( String.format("%-17s: %s\n", info[1], info_map.get(info[0])) );
|
||||
}
|
||||
sb.append( String.format("Items added since [%s] (db): %s\n",
|
||||
new SimpleDateFormat("MM/dd/yyyy").format(ri.from().getTime()),
|
||||
new SimpleDateFormat("yyyy-MM-dd").format(ri.from().getTime()),
|
||||
LogAnalyser.getNumItems(c)));
|
||||
|
||||
c.complete();
|
||||
|
@@ -4,15 +4,10 @@
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*
|
||||
* by lindat-dev team
|
||||
*/
|
||||
package org.dspace.health;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.commons.cli.PosixParser;
|
||||
import org.apache.commons.cli.*;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
@@ -23,6 +18,9 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* @author LINDAT/CLARIN dev team
|
||||
*/
|
||||
public class Report {
|
||||
|
||||
private static Logger log = Logger.getLogger(Report.class);
|
||||
@@ -147,7 +145,9 @@ public class Report {
|
||||
for (String check_name: checks().keySet()) {
|
||||
checks_summary += String.format( "%d. %s\n", pos++, check_name );
|
||||
}
|
||||
System.out.println( "Available checks:\n" + checks_summary );
|
||||
HelpFormatter formatter = new HelpFormatter();
|
||||
formatter.printHelp("dspace healthcheck", options);
|
||||
System.out.println( "\nAvailable checks:\n" + checks_summary );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -198,6 +198,7 @@ public class Report {
|
||||
email.send();
|
||||
} catch (Exception e) {
|
||||
log.fatal("Error sending email:", e);
|
||||
System.err.println("Error sending email:\n" + e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
@@ -4,8 +4,6 @@
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*
|
||||
* by lindat-dev team
|
||||
*/
|
||||
package org.dspace.health;
|
||||
|
||||
@@ -18,6 +16,7 @@ import static java.util.Calendar.YEAR;
|
||||
|
||||
/**
|
||||
* Information about a report run accessible by each check.
|
||||
* @author LINDAT/CLARIN dev team
|
||||
*/
|
||||
public class ReportInfo {
|
||||
|
||||
|
@@ -4,8 +4,6 @@
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*
|
||||
* by lindat-dev team
|
||||
*/
|
||||
package org.dspace.health;
|
||||
|
||||
@@ -19,6 +17,9 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author LINDAT/CLARIN dev team
|
||||
*/
|
||||
public class UserCheck extends Check {
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user