use of alma.acs.xmlfilestore.common.QueueFileHandler in project ACS by ACS-Community.
the class XmlFileStoreAlarmImpl method initialize.
/**
* Life cycle
* @see alma.acs.component.ComponentLifecycle#initialize()
*/
@Override
public void initialize(ContainerServices containerServices) throws ComponentLifecycleException {
super.initialize(containerServices);
cs = containerServices;
m_logger = cs.getLogger();
// Prepare the queue
String folderPath = System.getProperty(XmlFileStoreAlarmImpl.LOGDIR_PROPNAME, XmlFileStoreAlarmImpl.DEFAULLOGDIR);
File f = new File(folderPath);
if (!f.exists()) {
f.mkdirs();
}
int fileMax = Integer.getInteger(XmlFileStoreAlarmImpl.MAXNUMBEROFFILES_PROPNAME, XmlFileStoreAlarmImpl.DEFAULTMAXNUMBEROFFILES);
int fileSizeLimit = Integer.getInteger(XmlFileStoreAlarmImpl.MAXFILESIZE_PROPNAME, XmlFileStoreAlarmImpl.DEFAULTMAXFILESIZE);
if (fileMax < 1 || fileSizeLimit < 100000) {
StringBuilder str = new StringBuilder(XmlFileStoreAlarmImpl.MAXNUMBEROFFILES_PROPNAME);
str.append(" must be greater then 1 and ");
str.append(XmlFileStoreAlarmImpl.MAXFILESIZE_PROPNAME);
str.append(" must be greater then 100000");
throw new ComponentLifecycleException(str.toString());
}
StringBuilder str = new StringBuilder("Will save alarms files in : ");
str.append(folderPath);
str.append(" (max log file size: ");
str.append(fileSizeLimit);
str.append(", max # log files: ");
str.append(fileMax);
str.append(')');
m_logger.info(str.toString());
QueueFileHandler qFileHandler;
try {
qFileHandler = new QueueFileHandler(cs, folderPath, fileMax, fileSizeLimit, "alarmSources", "AlarmsLogger");
} catch (Throwable t) {
throw new ComponentLifecycleException("Could not create the queue file handler", t);
}
queue = new TimestampedStringQueue(qFileHandler, "<source-timestamp>");
queue.start();
// Connects to the alarm source NC
try {
alarmSourceClient = new SourceClient(cs);
alarmSourceClient.connect();
} catch (Throwable t) {
throw new ComponentLifecycleException("Could not connect to alarm source NC", t);
}
alarmSourceClient.addAlarmListener(this);
}
use of alma.acs.xmlfilestore.common.QueueFileHandler in project ACS by ACS-Community.
the class XmlFileStoreLoggerImpl method connectToLoggingChannel.
/**
*
* @param logFilePath
* @param fileMax
* @param fileSizeLimit
* @throws ComponentLifecycleException
*/
private void connectToLoggingChannel(String logFilePath, int fileMax, int fileSizeLimit) throws ComponentLifecycleException {
try {
// connect to LoggingChannel
QueueFileHandler queueFileHandler = new QueueFileHandler(cs, logFilePath, fileMax, fileSizeLimit, "log", "Logging");
engine = new LCEngine(queueFileHandler);
engine.connect(cs.getAdvancedContainerServices().getORB(), null);
engine.enableAutoReconnection(true);
} catch (Throwable e) {
m_logger.severe("Could not initialize connection to logging channel.");
cs.getAlarmSource().setAlarm("Logging", cs.getName(), 2, true);
throw new ComponentLifecycleException(e);
}
}
use of alma.acs.xmlfilestore.common.QueueFileHandler in project ACS by ACS-Community.
the class QueueFileHandlerTest method testCloseFile.
/**
* This test checks if the file has been renamed after calling {@link QueueFileHandler#fileProcessed(File, String, String)}.
* <P>
* The name of the file, after renaming, must match with the creation and closing time of the file
* and not depend on the content of the timestamped strings it contains.
* <BR>
* This test creates a file th invokes {@link QueueFileHandler#fileProcessed(File, String, String)} passing
* two timestamps and checks that they are ignored in favour of the actual timestamp
*
* @throws Exception
*/
public void testCloseFile() throws Exception {
// The format of the file after renaming
final String filenamePattern = "log\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}_\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}\\.xml";
// Create a file whose name contains the actual time
String now = IsoDateFormat.formatCurrentDate();
File oldLogFile = new File(logDir, "log" + now + "_YYYY-MM-DDTHH:MM:SS.mmm.xml");
// touch the log file
try (FileOutputStream ofs = new FileOutputStream(oldLogFile)) {
;
;
}
QueueFileHandler handler = new QueueFileHandler(this.getContainerServices(), logDir.getAbsolutePath(), 1, 1025L, "log", "Logging");
// The earliest timestamp must be before the actual timestamp to ensure it is ignored
String earliestLogTimestamp = "2014-12-06T13:00:00.000";
// The oldest timestamp must be after the actual timestamp to ensure it is ignored
int nextYear = Calendar.getInstance().get(Calendar.YEAR) + 1;
String oldestLogTimestamp = "" + nextYear + "-12-06T15:12:34.567";
// name of the file differ
try {
Thread.sleep(10000);
} catch (InterruptedException ie) {
}
handler.fileProcessed(oldLogFile, earliestLogTimestamp, oldestLogTimestamp);
try {
Thread.sleep(10);
} catch (InterruptedException ie) {
}
String timeAfterProcessing = IsoDateFormat.formatCurrentDate();
assertFalse(oldLogFile.exists());
File newLogFile = new File(logDir, String.format("log%s_%s.xml", earliestLogTimestamp, oldestLogTimestamp));
assertEquals("Too many log files in " + logDir.getAbsolutePath(), 1, logDir.list().length);
String fileName = logDir.list()[0];
// Check the format
assertTrue(fileName + " renamed with wrong format!", fileName.matches(filenamePattern));
// Check if the name contains the oldest or the newest timepstamp
assertEquals("The file name should not contain the oldest timestamp", -1, fileName.indexOf(oldestLogTimestamp));
assertEquals("The file name should not contain the newest timestamp", -1, fileName.indexOf(earliestLogTimestamp));
// The creationtimestamp (now) should be in the name of the file (i.e. not changed)
assertTrue("The start timestamp has been changed!", fileName.startsWith("log" + now + "_"));
// Check that the oldest timestamp in the name of the file is before
// the fileProcessed had been executed
int posUnderscore = fileName.lastIndexOf('_');
int posFileNameExtension = fileName.lastIndexOf(".xml");
String lastIsoTimestamp = fileName.substring(posUnderscore + 1, posFileNameExtension);
Date afterClosingDate = IsoDateFormat.parseIsoTimestamp(timeAfterProcessing);
Date closingTimestamp = IsoDateFormat.parseIsoTimestamp(lastIsoTimestamp);
assertTrue("The closing timestamp in the file is after fileProcessed had been called", closingTimestamp.before(afterClosingDate));
}
use of alma.acs.xmlfilestore.common.QueueFileHandler in project ACS by ACS-Community.
the class QueueFileHandlerTest method testGetNewFile.
/**
* This test checks the correctness of the format of the name of the file against a regular expresison.
*
* @throws Exception
*/
public void testGetNewFile() throws Exception {
final String filenamePattern = "log\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}_YYYY-MM-DDTHH:MM:SS\\.mmm\\.xml";
QueueFileHandler handler = new QueueFileHandler(this.getContainerServices(), logDir.getAbsolutePath(), 1, 1025L, "log", "Logging");
File f = handler.getNewFile();
assertNotNull(f);
assertTrue(f.getName() + " has a wrong format!", f.getName().matches(filenamePattern));
LOG.info(f.getAbsolutePath());
}
Aggregations