Skip to content

Commit

Permalink
WIP editing new healthchecks
Browse files Browse the repository at this point in the history
  • Loading branch information
Matus Kasak committed Dec 19, 2024
1 parent b1f0978 commit abc6c39
Show file tree
Hide file tree
Showing 24 changed files with 9,938 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
*/
package org.dspace.health;

import org.dspace.health.additionalUtilities.Info;

public class AdditionalInfoCheck extends Check {

@Override
protected String run(ReportInfo ri) {
String output = "";

output += String.format(
"Server uptime: %s\n", Info.get_proc_uptime());
output += String.format(
"JVM uptime: %s\n", Info.get_jvm_uptime());
output += String.format(
Expand Down
14 changes: 9 additions & 5 deletions dspace-api/src/main/java/org/dspace/health/OAIPMHCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
*/
package org.dspace.health;

import org.dspace.health.additionalUtilities.IOUtils;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;

import java.io.File;

public class OAIPMHCheck extends Check {
protected static final ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();
Expand All @@ -18,14 +21,15 @@ public class OAIPMHCheck extends Check {
protected String run(ReportInfo ri) {
String output = "";
String dspace_dir = configurationService.getProperty("dspace.dir");
System.out.println("Dspace dir " + dspace_dir);
String dspace_url = configurationService.getProperty("dspace.server.url");
System.out.println("Dspace url " + dspace_url);
String oaiurl = dspace_url + "/oai/request";
System.out.println("Dspace oai " + oaiurl);
output += String.format("Trying [%s]\n", oaiurl);
//output += IOUtils.run(new File(dspace_dir + "/bin/"), new String[]{
// "python", "./validators/oai_pmh/validate.py", oaiurl});

File scriptDir = new File(
"C:\\WorkSpace\\DSpace\\dspace-api\\src\\main\\java\\org\\dspace\\health\\additionalUtilities\\");

output += IOUtils.runScript(scriptDir, new String[]{
"python", "validate.py", oaiurl});
return output;
}
}
117 changes: 116 additions & 1 deletion dspace-api/src/main/java/org/dspace/health/PIDCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,124 @@
*/
package org.dspace.health;

import org.apache.commons.lang.NotImplementedException;
import org.dspace.handle.PIDService;
import org.dspace.health.additionalUtilities.PIDLogMiner;
import org.dspace.health.additionalUtilities.PIDLogStatistics;
import org.dspace.health.additionalUtilities.PIDLogStatisticsEntry;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

public class PIDCheck extends Check {
protected static final ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();

@Override
protected String run(ReportInfo ri) {
return "";
String output = "";
output += "This is space for PID Check output";
try {
String whoami = PIDService.who_am_i("encoding=xml");
output += String.format("Who am I\n\t%s\n",
whoami.replaceAll("\n", "\n\t"));
String test_pid = configurationService.getProperty("lr.pid.service.testPid");
output += "Testing PID server\n\t";
if (test_pid != null) {
output += PIDService.test_pid(test_pid);
} else {
output += "Testing PID server not done! Test pid not in dspace.cfg!";
}
} catch (IllegalArgumentException e) {
error(e, "Warning: PID service type is not defined or wrong");
} catch (NotImplementedException e) {
error(e, "Testing PID server - method who_am_i not implemented");
} catch (Exception e) {
error(e, "Testing PID server failed - exception occurred: %s");
}

// try {
// long total_count = Core.getHandlesTotalCount();
// output += "\n";
// output += String.format("Total count: %d\n", total_count);
// List<TableRow> invalid_handles = Core.getHandlesInvalidRows();
// output += String.format("Invalid handles count: %d\n",
// invalid_handles.size());
// if (invalid_handles.size() > 0) {
// output += "\n";
// output += "Invalid handles:\n";
// output += "----------------\n";
// output += String.format("%-6s\t%-32s\t%-10s\t%-10s\t%s\n",
// "Handle ID", "Handle", "Res. type ID", "Resource ID",
// "URL");
// for (TableRow row : invalid_handles) {
// int handle_id = row.getIntColumn("handle_id");
// String handle = row.getStringColumn("handle");
//
// Integer resource_type_id = row.getIntColumn("resource_type_id");
// if (resource_type_id < 0)
// resource_type_id = null;
//
// Integer resource_id = row.getIntColumn("resource_id");
// if (resource_id < 0)
// resource_id = null;
//
// String url = row.getStringColumn("url");
// output += String.format("%-10d\t%-32s\t%-10d\t%-10d\t%s\n",
// handle_id, handle, resource_type_id, resource_id,
// url);
// }
// }
// } catch (SQLException e) {
// error(e);
// }

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar realEndDate = Calendar.getInstance();
realEndDate.setTime(ri.till());
realEndDate.add(Calendar.DATE, -1);

final int topN = 10;
StringBuffer buf = new StringBuffer();
buf.append("============================================================\n");
buf.append(String.format("PID resolution statistics\n"));
buf.append("============================================================\n");
buf.append("\n\n");
PIDLogMiner logMiner = new PIDLogMiner();
PIDLogStatistics statistics = logMiner.computeStatistics(
ri.from(), realEndDate.getTime());
Map<String, List<PIDLogStatisticsEntry>> topNEntries = statistics
.getTopN(topN);
String eventsToDisplay[] = { PIDLogMiner.FAILURE_EVENT,
PIDLogMiner.REQUEST_EVENT, PIDLogMiner.SUCCESS_EVENT,
PIDLogMiner.UNKNOWN_EVENT };
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss.SSS");
for (String event : eventsToDisplay) {
if (topNEntries.containsKey(event)) {
buf.append(String.format(
"Top %d events of type %s between %s and %s\n", topN,
event, dateFormat.format(ri.from()),
dateFormat.format(realEndDate.getTime())));
buf.append(String
.format("---------------------------------------------------------------\n"));
buf.append(String.format("%-10s%-40s%-25s%-25s\n", "Count",
"PID", "First occurence", "Last occurence"));
buf.append(String
.format("--------------------------------------------------------------------------------------------------\n"));
for (PIDLogStatisticsEntry entry : topNEntries.get(event)) {
buf.append(String.format("%-10d%-40s%-25s%-25s\n",
entry.getCount(), entry.getPID(),
dateTimeFormat.format(entry.getFirstOccurence()),
dateTimeFormat.format(entry.getLastOccurence())));
}
buf.append("\n");
}
}
return output + buf.toString();
}
}
114 changes: 113 additions & 1 deletion dspace-api/src/main/java/org/dspace/health/ShibbolethCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,121 @@
*/
package org.dspace.health;

import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
//import java.io.BufferedReader;
//import java.io.File;
//import java.io.InputStreamReader;
//import java.io.StringWriter;
//import java.net.URL;
//import java.text.SimpleDateFormat;
//import java.util.Date;
//import java.util.HashSet;
//import java.util.Iterator;
//import java.util.Set;

public class ShibbolethCheck extends Check {

protected static final ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();

@Override
protected String run(ReportInfo ri) {
return "";
// StringBuilder ret = new StringBuilder();
// final String input_dir = configurationService.getProperty("lr",
// "lr.shibboleth.log.path");
// final String default_log = configurationService.getProperty("lr",
// "lr.shibboleth.log.defaultName");
//
// String input_file = new File(input_dir, default_log).toString();
//
// ret.append(String.format("Parsing %s:\n", input_file));
// BufferedReader safe_reader = null;
// try {
// safe_reader = IOUtils.safe_reader(input_file);
// // output warnings
// ShibUserLogins user_logins = new ShibUserLogins(safe_reader);
// if (0 < user_logins.warnings().size()) {
// for (String warning : user_logins.warnings()) {
// ret.append(warning + "\n");
// }
// } else {
// ret.append("No shibboleth warnings have been found.\n");
// }
// } catch (Exception e) {
// error(e, String.format("Problematic file [%s]", default_log));
// return ret.toString();
// }
//
// // > WARN from shibd_warn in the last week
// ret.append("\nParsing shibd_warn.*:\n");
// File dir = new File(input_dir);
// String[] files = dir.list(new java.io.FilenameFilter() {
// @Override
// public boolean accept(File dir, String name) {
// return name.contains("shibd_warn");
// }
// });
// Long nowMillis = System.currentTimeMillis();
// String weekAgo = new SimpleDateFormat("yyyy-MM-dd").format(new Date(
// nowMillis - 604800000));
// String[] cmd = new String[] { "awk", "-v", "from=" + weekAgo,
// "BEGIN{FS=\" \"} {if($1>=from) print $0}" };
// String[] cmdWithFiles = new String[cmd.length + files.length];
// System.arraycopy(cmd, 0, cmdWithFiles, 0, cmd.length);
// System.arraycopy(files, 0, cmdWithFiles, cmd.length, files.length);
// try {
// Process child = Runtime.getRuntime().exec(cmdWithFiles, null, dir);
// BufferedReader[] outputs = new BufferedReader[] {
// new BufferedReader(new InputStreamReader(
// child.getInputStream())),
// new BufferedReader(new InputStreamReader(
// child.getErrorStream())) };
// for (BufferedReader out : outputs) {
// String s = null;
// while ((s = out.readLine()) != null) {
// ret.append(s);
// ret.append("\n");
// }
// }
// } catch (java.io.IOException e) {
// error(e);
// }
//
//
// try {
// String feedsConfig = configurationService.getProperty("discojuice", "feeds");
// ret.append(String.format( "Using these static discojuice feeds [%s] as source.\n",
// feedsConfig ));
// // Try to download our feeds file, so the proper action is triggered
// StringWriter writer = new StringWriter();
// org.apache.commons.io.IOUtils.copy(
// new URL(configurationService.getProperty("dspace.url")
// + "/discojuice/feeds").openStream(), writer);
// String json = writer.toString();
// // end download
// Set<String> entities = new HashSet<String>();
// JSONParser parser = new JSONParser();
// JSONArray entityArray = (JSONArray) parser.parse(json);
// Iterator<JSONObject> i = entityArray.iterator();
// int counter = 0;
// while (i.hasNext()) {
// counter++;
// JSONObject entity = i.next();
// String entityID = (String) entity.get("entityID");
// entities.add(entityID);
// }
// int idCount = entities.size();
// ret.append(String.format(
// "Our feeds file contains %d entities out of which %d are unique.\n"
// + "This number should be around 1200?? (20.11.2014).",
// counter, idCount)
// );
// } catch (Exception e) {
// error(e);
// }
//
// return ret.toString();
return "Space for shibboleth output.";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.health.additionalUtilities;

import org.apache.logging.log4j.Logger;

import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;

public class IOUtils {
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(IOUtils.class);

public static String runScript(File where, String[] cmd) {
String message = null;
try {
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.directory( where );
Process p = pb.start();
BufferedReader std_out = new BufferedReader(new InputStreamReader(p.getInputStream()) );
BufferedReader std_err = new BufferedReader(new InputStreamReader(p.getErrorStream()) );

String s = null;
message = "Returned stdout:\n";
while ((s = std_out.readLine()) != null) {
message += s + "\n ";
}
message += "Returned stderr:\n";
while ((s = std_err.readLine()) != null) {
message += s + "\n ";
}

//Wait to get exit value
int exitValue = p.waitFor();
message += "Exit code: [" + String.valueOf( exitValue ) + "]\n";

} catch (Exception e) {
message += "\nException:" + e.toString();
log.error( e );
}
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
*
* http://www.dspace.org/license/
*/
package org.dspace.health;

import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
//import src.main.java.org.dspace.xoai.services.impl.config.DSpaceConfigurationService;

package org.dspace.health.additionalUtilities;

import java.io.FileInputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Scanner;

import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
//import src.main.java.org.dspace.xoai.services.impl.config.DSpaceConfigurationService;

public class Info {

protected static final ConfigurationService configurationService
Expand Down
Loading

0 comments on commit abc6c39

Please sign in to comment.