Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/error-handling'
Browse files Browse the repository at this point in the history
  • Loading branch information
gladky committed Sep 12, 2016
2 parents f9bb4bc + e24635a commit d521e37
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 70 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ch.cern</groupId>
<artifactId>DAQAggregator</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
<repositories>
<repository>
<id>libs-release-local</id>
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/rcms/utilities/daqaggregator/DAQAggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
Expand All @@ -14,19 +13,16 @@
import rcms.utilities.daqaggregator.data.DAQ;
import rcms.utilities.daqaggregator.datasource.FileFlashlistRetriever;
import rcms.utilities.daqaggregator.datasource.Flashlist;
import rcms.utilities.daqaggregator.datasource.FlashlistManager;
import rcms.utilities.daqaggregator.datasource.FlashlistRetriever;
import rcms.utilities.daqaggregator.datasource.HardwareConnector;
import rcms.utilities.daqaggregator.datasource.LASFlashlistRetriever;
import rcms.utilities.daqaggregator.datasource.MonitorManager;
import rcms.utilities.daqaggregator.datasource.SessionRetriever;
import rcms.utilities.daqaggregator.mappers.MappingManager;
import rcms.utilities.daqaggregator.persistence.PersistenceFormat;
import rcms.utilities.daqaggregator.persistence.PersistorManager;
import rcms.utilities.hwcfg.HardwareConfigurationException;
import rcms.utilities.hwcfg.InvalidNodeTypeException;
import rcms.utilities.hwcfg.PathNotFoundException;
import rcms.utilities.hwcfg.dp.DAQPartition;

public class DAQAggregator {

Expand Down Expand Up @@ -72,8 +68,8 @@ public static void main(String[] args) {
logger.info("Unsuccessful iteration, already for " + problems + "time(s)");
}
}
} catch (DAQAggregatorException e) {
if (e.getCode() == DAQAggregatorExceptionCode.NoMoreFlashlistSourceFiles)
} catch (DAQException e) {
if (e.getCode() == DAQExceptionCode.NoMoreFlashlistSourceFiles)
logger.info("All flashlist files processed");
else
throw e;
Expand All @@ -85,14 +81,23 @@ public static void main(String[] args) {
while (true) {
try {
monitorAndPersist(monitorManager, persistenceManager, persistMode);
} catch (PathNotFoundException | InvalidNodeTypeException e) {
logger.error("Problem in RT loop");
logger.info("Going to sleep for 30 seconds before trying again...\n");
} catch (DAQException e) {
logger.error(e.getMessage());
logger.info("Going to sleep for 10 seconds before trying again...");
try {
Thread.sleep(30000);
Thread.sleep(10000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
} catch (Exception e) {
logger.fatal("Fatal problem in RT loop, unknown problem, going to sleep for 2 minutes");
e.printStackTrace();

try {
Thread.sleep(120000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
Expand Down

This file was deleted.

16 changes: 16 additions & 0 deletions src/main/java/rcms/utilities/daqaggregator/DAQException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package rcms.utilities.daqaggregator;

public class DAQException extends RuntimeException {

private final DAQExceptionCode code;

public DAQException(DAQExceptionCode code, String message) {
super(message);
this.code = code;
}

public DAQExceptionCode getCode() {
return code;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package rcms.utilities.daqaggregator;

public enum DAQAggregatorExceptionCode {
public enum DAQExceptionCode {

/* General errors */
SessionCannotBeRetrieved(101, "Cannot retrieve session"),
Expand All @@ -12,7 +12,7 @@ public enum DAQAggregatorExceptionCode {

/* Persistence errors */

DAQAggregatorExceptionCode(int code, String name) {
DAQExceptionCode(int code, String name) {
this.code = code;
this.name = name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import org.apache.log4j.Logger;

import rcms.utilities.daqaggregator.DAQAggregatorException;
import rcms.utilities.daqaggregator.DAQAggregatorExceptionCode;
import rcms.utilities.daqaggregator.DAQException;
import rcms.utilities.daqaggregator.DAQExceptionCode;
import rcms.utilities.daqaggregator.persistence.PersistenceExplorer;
import rcms.utilities.daqaggregator.persistence.PersistenceFormat;
import rcms.utilities.daqaggregator.persistence.StructureSerializer;
Expand Down Expand Up @@ -118,7 +118,7 @@ public Map<FlashlistType, Flashlist> retrieveAllFlashlists() {
@Override
public Flashlist retrieveFlashlist(FlashlistType flashlistType) {
if (exploredFlashlists.get(flashlistType).size() <= i)
throw new DAQAggregatorException(DAQAggregatorExceptionCode.NoMoreFlashlistSourceFiles,
throw new DAQException(DAQExceptionCode.NoMoreFlashlistSourceFiles,
"Cannot retrieve flashlist, all flashlist source files has been processed");
File flashistFile = exploredFlashlists.get(flashlistType).get(i);
Flashlist flashlist = structureSerialzier.deserializeFlashlist(flashistFile, flashlistFormat);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import org.apache.commons.lang3.tuple.Triple;
import org.apache.log4j.Logger;

import rcms.utilities.daqaggregator.DAQAggregatorException;
import rcms.utilities.daqaggregator.DAQAggregatorExceptionCode;
import rcms.utilities.daqaggregator.DAQException;
import rcms.utilities.daqaggregator.DAQExceptionCode;
import rcms.utilities.daqaggregator.data.DAQ;
import rcms.utilities.daqaggregator.mappers.MappingManager;
import rcms.utilities.daqaggregator.mappers.PostProcessor;
Expand Down Expand Up @@ -42,43 +42,33 @@ public MonitorManager(FlashlistRetriever flashlistRetriever, SessionRetriever se
public Triple<DAQ, Collection<Flashlist>, Boolean> getSystemSnapshot()
throws HardwareConfigurationException, PathNotFoundException, InvalidNodeTypeException {

try {
boolean newSession = sessionDetector.detectNewSession();
boolean newSession = sessionDetector.detectNewSession();

if (newSession) {
logger.info("Loading hardware for new session");
daq = rebuildDaqModel(sessionDetector.getResult());
if (newSession) {
logger.info("Loading hardware for new session");
daq = rebuildDaqModel(sessionDetector.getResult());

flashlistRetriever.retrieveAvailableFlashlists(sessionDetector.getResult().getMiddle());
}
flashlistRetriever.retrieveAvailableFlashlists(sessionDetector.getResult().getMiddle());
}

Collection<Flashlist> flashlists = flashlistRetriever.retrieveAllFlashlists().values();
flashlistManager.mapFlashlists(flashlists);
Collection<Flashlist> flashlists = flashlistRetriever.retrieveAllFlashlists().values();
flashlistManager.mapFlashlists(flashlists);

long lastUpdate = 0L;
for (Flashlist flashlist : flashlists) {
// why null here?
logger.debug(flashlist.getRetrievalDate() + ", " + flashlist.getFlashlistType());
if (flashlist.getRetrievalDate() != null && lastUpdate < flashlist.getRetrievalDate().getTime()) {
lastUpdate = flashlist.getRetrievalDate().getTime();
}
long lastUpdate = 0L;
for (Flashlist flashlist : flashlists) {
// why null here?
logger.debug(flashlist.getRetrievalDate() + ", " + flashlist.getFlashlistType());
if (flashlist.getRetrievalDate() != null && lastUpdate < flashlist.getRetrievalDate().getTime()) {
lastUpdate = flashlist.getRetrievalDate().getTime();
}

daq.setLastUpdate(lastUpdate);
// postprocess daq (derived values, summary classes)
PostProcessor postProcessor = new PostProcessor(daq);
postProcessor.postProcess();
return Triple.of(daq, flashlists, newSession);

} catch (DAQAggregatorException e) {
if (e.getCode() == DAQAggregatorExceptionCode.SessionCannotBeRetrieved) {
logger.info("session cannot be retrieved temporarly");
flashlistRetriever.retrieveAllFlashlists();
} else
throw e;
return null;
}

daq.setLastUpdate(lastUpdate);
// postprocess daq (derived values, summary classes)
PostProcessor postProcessor = new PostProcessor(daq);
postProcessor.postProcess();
return Triple.of(daq, flashlists, newSession);

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import com.fasterxml.jackson.databind.JsonNode;

import rcms.utilities.daqaggregator.DAQAggregatorException;
import rcms.utilities.daqaggregator.DAQAggregatorExceptionCode;
import rcms.utilities.daqaggregator.DAQException;
import rcms.utilities.daqaggregator.DAQExceptionCode;

/**
* Retrieves session information from flashlist LEVEL_ZERO_STATIC
Expand All @@ -32,7 +32,7 @@ public class SessionRetriever {
private static final SimpleDateFormat df2 = new SimpleDateFormat("EEE, MMM dd yyyy HH:mm:ss Z");
private static final Logger logger = Logger.getLogger(SessionRetriever.class);

protected static final String EXCEPTION_MISSING_ROW_MESSAGE = "Could not found appropriate row in flashist to determine session";
protected static final String EXCEPTION_MISSING_ROW_MESSAGE = "Could not find the appropriate row in flashist LEVEL_ZERO_STATIC to determine session";
protected static final String EXCEPTION_OTHER_PROBLEM_MESSAGE = "Problem detecting the session";
protected static final String EXCEPTION_PARSING_DATE_PROBLEM_MESSAGE = "Could not parse timestamp from flashlist data";
protected static final String EXCEPTION_NO_DATA_MESSAGE = "Flashlist has no data";
Expand All @@ -58,8 +58,7 @@ public Triple<String, Integer, Long> retrieveSession(Flashlist flashlist) {
if (flashlist.getFlashlistType() != FlashlistType.LEVEL_ZERO_FM_STATIC)
throw new RuntimeException(EXCEPTION_WRONG_FLASHLIST_MESSAGE);
if (flashlist.getRowsNode() == null || flashlist.getRowsNode().size() == 0)
throw new DAQAggregatorException(DAQAggregatorExceptionCode.SessionCannotBeRetrieved,
EXCEPTION_NO_DATA_MESSAGE);
throw new DAQException(DAQExceptionCode.SessionCannotBeRetrieved, EXCEPTION_NO_DATA_MESSAGE);

Iterator<JsonNode> rowIterator = flashlist.getRowsNode().iterator();
Triple<String, Integer, Long> result = null;
Expand Down Expand Up @@ -87,7 +86,7 @@ public Triple<String, Integer, Long> retrieveSession(Flashlist flashlist) {
}

if (!foundRowSatisfyingFilters) {
throw new RuntimeException(EXCEPTION_MISSING_ROW_MESSAGE);
throw new DAQException(DAQExceptionCode.SessionCannotBeRetrieved, EXCEPTION_MISSING_ROW_MESSAGE);
}
if (result != null) {
logger.debug("Result of " + result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
import rcms.utilities.daqaggregator.Application;
import rcms.utilities.daqaggregator.ProxyManager;

/**
* This test will not work when there is data available in LAS flashlist
*
* @TODO: make it independent on flashlist availability
*
* @author Maciej Gladki ([email protected])
*
*/
public class LASFlashlistRetrieverTest {

private static String filter1;
Expand Down

0 comments on commit d521e37

Please sign in to comment.