Skip to content

Commit

Permalink
Added more logging to RunningJobs classes. Removed requirement of JDK…
Browse files Browse the repository at this point in the history
… 1.8 to build
  • Loading branch information
svcarlsen committed Sep 30, 2016
1 parent 18d3e08 commit 640d8b3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
Expand Up @@ -71,7 +71,7 @@ public void shutdown() {
super.shutdown();
HarvestDBConnection.cleanup();
}

/*
public static Provider<JMSConnection> getJMSConnectionProvider() {
return () -> JMSConnectionFactory.getInstance();
}
Expand All @@ -84,9 +84,8 @@ public static Provider<HarvestDefinitionDAO> getHarvestDefinitionDAOProvider() {
public static Provider<Notifications> getNotificationsProvider() {
return () -> NotificationsFactory.getInstance();
}
*/


/*
public static Provider<JMSConnection> getJMSConnectionProvider() {
return new Provider<JMSConnection>() {

Expand Down Expand Up @@ -119,5 +118,5 @@ public Notifications get() {
return NotificationsFactory.getInstance();
}};
}
*/

}
Expand Up @@ -229,7 +229,7 @@ public synchronized void store(StartedJobInfo startedJobInfo) {
if (!shouldSample) {
return; // we're done
}

log.debug("Adding history Record for job {} to runningJobsHistory table", startedJobInfo.getJobId());
try {
c.setAutoCommit(false);

Expand Down Expand Up @@ -491,7 +491,7 @@ public StartedJobInfo getMostRecentByJobId(long jobId) {
sji.setActiveToeCount(rs.getInt(HM_COLUMN.activeToeCount.rank()));
sji.setStatus(CrawlStatus.values()[rs.getInt(HM_COLUMN.status.rank())]);
sji.setTimestamp(new Date(rs.getTimestamp(HM_COLUMN.tstamp.rank()).getTime()));

log.debug("getMostRecentByJobId for {}:{}", jobId, sji);
return sji;
}

Expand Down
Expand Up @@ -31,6 +31,7 @@

import javax.jms.MessageListener;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -64,18 +65,24 @@ public class HarvestMonitor extends HarvesterMessageHandler implements MessageLi

/** Singleton instance of the monitor. */
private static HarvestMonitor instance;
/** Harvest Monitor refresh Interval. */
private int refreshInterval;

/** The JMS channel on which to listen for {@link CrawlProgressMessage}s. */
public static final ChannelID HARVEST_MONITOR_CHANNEL_ID = HarvesterChannels.getHarvestMonitorChannel();

private Map<Long, StartedJobHistoryChartGen> chartGenByJobId = new HashMap<Long, StartedJobHistoryChartGen>();

private HarvestMonitor() {
refreshInterval = Settings.getInt(HarvesterSettings.HARVEST_MONITOR_REFRESH_INTERVAL);
LOG.info("Initializing HarvestMonitor with refreshInterval={} seconds", refreshInterval);

// Perform initial cleanup (in case apps crashed)
cleanOnStartup();

// Register for listening JMS messages
JMSConnectionFactory.getInstance().setListener(HARVEST_MONITOR_CHANNEL_ID, this);
LOG.info("Started listening to queue {}", HARVEST_MONITOR_CHANNEL_ID);
}

/**
Expand All @@ -97,7 +104,7 @@ public void cleanup() {
/**
* @return the singleton instance for this class.
*/
public static HarvestMonitor getInstance() {
public static synchronized HarvestMonitor getInstance() {
if (instance == null) {
instance = new HarvestMonitor();
}
Expand All @@ -107,15 +114,16 @@ public static HarvestMonitor getInstance() {
@Override
public void visit(CrawlProgressMessage msg) {
ArgumentNotValid.checkNotNull(msg, "msg");

Long jobId = Long.valueOf(msg.getJobID());

JobStatus jobStatus = JobDAO.getInstance().read(jobId).getStatus();
if (!JobStatus.STARTED.equals(jobStatus)) {
LOG.warn("Receiving CrawlProgressMessage for job {} registered as state {} instead of STARTED. Ignoring message", jobId, jobStatus);
return;
}

StartedJobInfo info = StartedJobInfo.build(msg);
LOG.trace("Received CrawlProgressMessage for jobId {}: {}", jobId, info);
RunningJobsInfoDAO.getInstance().store(info);

// Start a chart generator if none has been started yet
Expand All @@ -139,7 +147,7 @@ public void visit(JobEndedMessage msg) {
// Delete records in the DB
RunningJobsInfoDAO dao = RunningJobsInfoDAO.getInstance();
int delCount = dao.removeInfoForJob(jobId);
LOG.info("Deleted {} running job info records for job ID {} on transition to status {}", delCount, jobId,
LOG.info("Processing JobEndedMessage. Deleted {} running job info records for job ID {} on transition to status {}", delCount, jobId,
newStatus.name());

// Stop chart generation
Expand Down Expand Up @@ -267,7 +275,7 @@ private void cleanOnStartup() {
delCount += dao.deleteFrontierReports(jobId);
}
if (delCount > 0) {
LOG.info("Cleaned up {} obsolete history records.", delCount);
LOG.info("Cleaned up {} obsolete history records for finished jobs {}", delCount, StringUtils.join(idsToRemove, ","));
}

}
Expand Down
Expand Up @@ -28,6 +28,9 @@

import javax.servlet.ServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import dk.netarkivet.common.exceptions.UnknownID;
import dk.netarkivet.harvester.datamodel.DomainDAO;
import dk.netarkivet.harvester.datamodel.Job;
Expand All @@ -40,6 +43,8 @@
*/
public class FindRunningJobQuery {

static final Logger log = LoggerFactory.getLogger(FindRunningJobQuery.class);

/**
* Defines the UI fields and their default values.
*/
Expand Down Expand Up @@ -84,7 +89,7 @@ public Object getDefaultValue() {
private Set<Long> runningJobIds = new TreeSet<Long>();

/**
* Builds a request to find a running job. UI fileds values will be extracted from the given {@link ServletRequest}.
* Builds a request to find a running job. UI field values will be extracted from the given {@link ServletRequest}.
*
* @param req the {@link ServletRequest} to parse.
*/
Expand All @@ -107,6 +112,7 @@ public FindRunningJobQuery(ServletRequest req) {
if (domains.contains(domainName)) {
runningJobIds.add(jobId);
}
log.info("Found {} jobs in status STARTED harvesting domain {}", runningJobIds.size(), domainName);
}
}

Expand Down
Expand Up @@ -28,7 +28,8 @@
import dk.netarkivet.common.utils.TableSort;

/**
* class used to manage the sort of tables in the harvest status running screen.
* Class used to manage the sort of tables in the harvest status running screen.
* Used only by History/Harveststatus-running.jsp
*/
public class HarvestStatusRunningTablesSort {
/** list of the column id. */
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -13,8 +13,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- maven-java-formatter-plugin -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<slf4j.version>1.7.7</slf4j.version>
<logback.version>1.0.13</logback.version>
<webarchive-commons.version>1.1.5</webarchive-commons.version>
Expand Down

0 comments on commit 640d8b3

Please sign in to comment.