adressing helix' comments to the DS-2659 PR

This commit is contained in:
Ondřej Košarko
2015-07-30 16:48:02 +02:00
parent d2f9fb5104
commit aed0741fec
10 changed files with 85 additions and 66 deletions

View File

@@ -4,8 +4,6 @@
* tree and available online at * tree and available online at
* *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*
* by lindat-dev team
*/ */
package org.dspace.health; package org.dspace.health;
@@ -13,6 +11,7 @@ import org.apache.log4j.Logger;
/** /**
* Abstract check interface. * Abstract check interface.
* @author LINDAT/CLARIN dev team
*/ */
public abstract class Check { public abstract class Check {

View File

@@ -4,8 +4,6 @@
* tree and available online at * tree and available online at
* *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*
* by lindat-dev team
*/ */
package org.dspace.health; package org.dspace.health;
@@ -18,6 +16,9 @@ import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
/**
* @author LINDAT/CLARIN dev team
*/
public class ChecksumCheck extends Check { public class ChecksumCheck extends Check {
@Override @Override
@@ -27,9 +28,6 @@ public class ChecksumCheck extends Check {
Date process_start = Calendar.getInstance().getTime(); Date process_start = Calendar.getInstance().getTime();
checker.setProcessStartDate(process_start); checker.setProcessStartDate(process_start);
checker.setDispatcher( checker.setDispatcher(
// new LimitedCountDispatcher(new SimpleDispatcher(new
// BitstreamInfoDAO(), null, false), 1)
// loop through all files
new SimpleDispatcher(new BitstreamInfoDAO(), process_start, false)); new SimpleDispatcher(new BitstreamInfoDAO(), process_start, false));
md5_collector collector = new md5_collector(); md5_collector collector = new md5_collector();

View File

@@ -4,66 +4,82 @@
* tree and available online at * tree and available online at
* *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*
* by lindat-dev team
*/ */
package org.dspace.health; package org.dspace.health;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.dspace.content.Community; import org.dspace.app.util.CollectionDropDown;
import org.dspace.content.Item; import org.dspace.content.*;
import org.dspace.content.ItemIterator; import org.dspace.content.Collection;
import org.dspace.content.Metadatum;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.storage.rdbms.DatabaseManager; import org.dspace.storage.rdbms.DatabaseManager;
import org.dspace.storage.rdbms.TableRow; import org.dspace.storage.rdbms.TableRow;
import org.dspace.storage.rdbms.TableRowIterator; import org.dspace.storage.rdbms.TableRowIterator;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author LINDAT/CLARIN dev team
*/
public class Core { public class Core {
// get info // get info
// //
public static String getCollectionSizesInfo() throws SQLException { public static String getCollectionSizesInfo() throws SQLException {
String ret = ""; final StringBuffer ret = new StringBuffer();
List<TableRow> rows = sql( List<TableRow> rows = sql(
"SELECT " "SELECT" +
+ "(SELECT text_value FROM metadatavalue " "(SELECT text_value FROM metadatavalue NATURAL JOIN metadatafieldregistry " +
+ "WHERE metadata_field_id=64 AND resource_type_id=3 AND resource_id=col.collection_id) AS name, " "NATURAL JOIN metadataschemaregistry WHERE element='title' AND qualifier IS NULL AND short_id='dc'" +
+ "SUM(bit.size_bytes) AS sum " " AND resource_type_id=3 AND resource_id=col.collection_id) AS name," +
+ "FROM collection2item col, item2bundle item, bundle2bitstream bun, bitstream bit " "SUM(bit.size_bytes) AS sum," +
+ "WHERE col.item_id=item.item_id AND item.bundle_id=bun.bundle_id AND bun.bitstream_id=bit.bitstream_id " " collection_id" +
+ "GROUP BY col.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; 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) { for (TableRow row : rows) {
double size = row.getLongColumn("sum") / (1024. * 1024.); double size = row.getLongColumn("sum");
total_size += size; total_size += size;
ret += String.format( Collection col = Collection.find(context, row.getIntColumn("collection_id"));
"\t%s: %s\n", row.getStringColumn("name"), FileUtils.byteCountToDisplaySize((long)size)); ret.append(String.format(
"\t%s: %s\n", CollectionDropDown.collectionPath(col), FileUtils.byteCountToDisplaySize((long) size)));
} }
ret += String.format( context.abort();
"Total size: %s\n", FileUtils.byteCountToDisplaySize(total_size)); ret.append(String.format(
"Total size: %s\n", FileUtils.byteCountToDisplaySize(total_size)));
ret += String.format( ret.append(String.format(
"Resource without policy: %d\n", getBitstreamsWithoutPolicyCount()); "Resource without policy: %d\n", getBitstreamsWithoutPolicyCount()));
ret += String.format( ret.append(String.format(
"Deleted bitstreams: %d\n", getBitstreamsDeletedCount()); "Deleted bitstreams: %d\n", getBitstreamsDeletedCount()));
rows = getBitstreamOrphansRows(); rows = getBitstreamOrphansRows();
String list_str = ""; String list_str = "";
for (TableRow row : rows) { for (TableRow row : rows) {
list_str += String.format("%d, ", row.getIntColumn("bitstream_id")); list_str += String.format("%d, ", row.getIntColumn("bitstream_id"));
} }
ret += String.format( ret.append(String.format(
"Orphan bitstreams: %d [%s]\n", rows.size(), list_str); "Orphan bitstreams: %d [%s]\n", rows.size(), list_str));
return ret; return ret.toString();
} }
public static String getObjectSizesInfo() throws SQLException { public static String getObjectSizesInfo() throws SQLException {
@@ -183,13 +199,14 @@ public class Core {
Context c = new Context(); Context c = new Context();
TableRowIterator irows = DatabaseManager TableRowIterator irows = DatabaseManager
.query(c, .query(c,
"SELECT eperson_group_id, " "SELECT eperson_group_id," +
+ "(SELECT text_value FROM metadatavalue " "(SELECT text_value FROM metadatavalue NATURAL JOIN metadatafieldregistry" +
+ "WHERE metadata_field_id=64 AND resource_type_id=6 AND resource_id=eperson_group_id) AS name " " NATURAL JOIN metadataschemaregistry WHERE element='title'" +
+ "FROM epersongroup " " AND qualifier IS NULL AND short_id='dc' AND resource_type_id=6 AND resource_id=eperson_group_id) AS name "+
+ "WHERE eperson_group_id NOT IN (SELECT eperson_group_id FROM epersongroup2eperson)"); "FROM epersongroup " +
"WHERE eperson_group_id NOT IN (SELECT eperson_group_id FROM epersongroup2eperson)");
for (TableRow row : irows.toList()) { 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(); c.complete();
return ret; return ret;

View File

@@ -4,8 +4,6 @@
* tree and available online at * tree and available online at
* *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*
* by lindat-dev team
*/ */
package org.dspace.health; package org.dspace.health;
@@ -19,6 +17,9 @@ import org.dspace.embargo.service.EmbargoService;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Iterator; import java.util.Iterator;
/**
* @author LINDAT/CLARIN dev team
*/
public class EmbargoCheck extends Check { public class EmbargoCheck extends Check {
private static final EmbargoService embargoService = EmbargoServiceFactory.getInstance().getEmbargoService(); private static final EmbargoService embargoService = EmbargoServiceFactory.getInstance().getEmbargoService();

View File

@@ -4,8 +4,6 @@
* tree and available online at * tree and available online at
* *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*
* by lindat-dev team
*/ */
package org.dspace.health; package org.dspace.health;
@@ -16,6 +14,9 @@ import org.dspace.core.ConfigurationManager;
import java.io.File; import java.io.File;
import java.util.Date; import java.util.Date;
/**
* @author LINDAT/CLARIN dev team
*/
public class InfoCheck extends Check { public class InfoCheck extends Check {
@Override @Override
@@ -27,9 +28,9 @@ public class InfoCheck extends Check {
).append("\n"); ).append("\n");
sb.append("From - Till: ").append( 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( ).append(" - ").append(
new SimpleDateFormat("MM/dd/yyyy").format(ri.till().getTime()) new SimpleDateFormat("yyyy-MM-dd").format(ri.till().getTime())
).append("\n"); ).append("\n");
sb.append("Url: ").append( sb.append("Url: ").append(

View File

@@ -4,8 +4,6 @@
* tree and available online at * tree and available online at
* *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*
* by lindat-dev team
*/ */
package org.dspace.health; package org.dspace.health;
@@ -15,6 +13,9 @@ import org.dspace.storage.rdbms.TableRow;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Map; import java.util.Map;
/**
* @author LINDAT/CLARIN dev team
*/
public class ItemCheck extends Check { public class ItemCheck extends Check {
@Override @Override
@@ -23,7 +24,7 @@ public class ItemCheck extends Check {
int tot_cnt = 0; int tot_cnt = 0;
try { try {
for (Map.Entry<String, Integer> name_count : Core.getCommunities()) { 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()); name_count.getKey(), name_count.getValue());
tot_cnt += name_count.getValue(); tot_cnt += name_count.getValue();
} }

View File

@@ -4,8 +4,6 @@
* tree and available online at * tree and available online at
* *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*
* by lindat-dev team
*/ */
package org.dspace.health; package org.dspace.health;
@@ -17,6 +15,9 @@ import java.text.SimpleDateFormat;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/**
* @author LINDAT/CLARIN dev team
*/
public class LogAnalyserCheck extends Check { public class LogAnalyserCheck extends Check {
final static private String[][] interesting_fields = new String[][] { 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("%-17s: %s\n", info[1], info_map.get(info[0])) );
} }
sb.append( String.format("Items added since [%s] (db): %s\n", 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))); LogAnalyser.getNumItems(c)));
c.complete(); c.complete();

View File

@@ -4,15 +4,10 @@
* tree and available online at * tree and available online at
* *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*
* by lindat-dev team
*/ */
package org.dspace.health; package org.dspace.health;
import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.*;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;
import org.apache.commons.lang.exception.ExceptionUtils; import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.core.ConfigurationManager; import org.dspace.core.ConfigurationManager;
@@ -23,6 +18,9 @@ import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.Map.Entry; import java.util.Map.Entry;
/**
* @author LINDAT/CLARIN dev team
*/
public class Report { public class Report {
private static Logger log = Logger.getLogger(Report.class); private static Logger log = Logger.getLogger(Report.class);
@@ -147,7 +145,9 @@ public class Report {
for (String check_name: checks().keySet()) { for (String check_name: checks().keySet()) {
checks_summary += String.format( "%d. %s\n", pos++, check_name ); 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; return;
} }
@@ -198,6 +198,7 @@ public class Report {
email.send(); email.send();
} catch (Exception e) { } catch (Exception e) {
log.fatal("Error sending email:", e); log.fatal("Error sending email:", e);
System.err.println("Error sending email:\n" + e.getMessage());
System.exit(1); System.exit(1);
} }
} }

View File

@@ -4,8 +4,6 @@
* tree and available online at * tree and available online at
* *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*
* by lindat-dev team
*/ */
package org.dspace.health; package org.dspace.health;
@@ -18,6 +16,7 @@ import static java.util.Calendar.YEAR;
/** /**
* Information about a report run accessible by each check. * Information about a report run accessible by each check.
* @author LINDAT/CLARIN dev team
*/ */
public class ReportInfo { public class ReportInfo {

View File

@@ -4,8 +4,6 @@
* tree and available online at * tree and available online at
* *
* http://www.dspace.org/license/ * http://www.dspace.org/license/
*
* by lindat-dev team
*/ */
package org.dspace.health; package org.dspace.health;
@@ -19,6 +17,9 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* @author LINDAT/CLARIN dev team
*/
public class UserCheck extends Check { public class UserCheck extends Check {
@Override @Override