use of java.io.FilenameFilter in project Openfire by igniterealtime.
the class AuditorImpl method ensureMaxDays.
/**
* Deletes old audit files that exceeded the max number of days limit.
*/
private void ensureMaxDays() {
if (maxDays == -1) {
// Do nothing since we don't have any limit
return;
}
// Set limit date after which we need to delete old audit files
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, maxDays * -1);
final String oldestFile = "jive.audit-" + dateFormat.format(calendar.getTime()) + "-000.log";
// Get list of audit files to delete
FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("jive.audit-") && name.endsWith(".log") && name.compareTo(oldestFile) < 0;
}
};
File[] files = baseFolder.listFiles(filter);
// Delete old audit files
for (File fileToDelete : files) {
if (fileToDelete.equals(currentAuditFile)) {
// Close current file
close();
}
if (!fileToDelete.delete()) {
Log.warn("Unable to delete file '{}' as part of regular log rotation based on age of file. (Openfire failed to clean up after itself)!", fileToDelete);
}
}
}
use of java.io.FilenameFilter in project flink by apache.
the class JarListHandler method handleJsonRequest.
@Override
public String handleJsonRequest(Map<String, String> pathParams, Map<String, String> queryParams, ActorGateway jobManager) throws Exception {
try {
StringWriter writer = new StringWriter();
JsonGenerator gen = JsonFactory.jacksonFactory.createGenerator(writer);
gen.writeStartObject();
gen.writeStringField("address", queryParams.get(RuntimeMonitorHandler.WEB_MONITOR_ADDRESS_KEY));
gen.writeArrayFieldStart("files");
File[] list = jarDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(".jar");
}
});
for (File f : list) {
// separate the uuid and the name parts.
String id = f.getName();
int startIndex = id.indexOf("_");
if (startIndex < 0) {
continue;
}
String name = id.substring(startIndex + 1);
if (name.length() < 5 || !name.endsWith(".jar")) {
continue;
}
gen.writeStartObject();
gen.writeStringField("id", id);
gen.writeStringField("name", name);
gen.writeNumberField("uploaded", f.lastModified());
gen.writeArrayFieldStart("entry");
String[] classes = new String[0];
try {
JarFile jar = new JarFile(f);
Manifest manifest = jar.getManifest();
String assemblerClass = null;
if (manifest != null) {
assemblerClass = manifest.getMainAttributes().getValue(PackagedProgram.MANIFEST_ATTRIBUTE_ASSEMBLER_CLASS);
if (assemblerClass == null) {
assemblerClass = manifest.getMainAttributes().getValue(PackagedProgram.MANIFEST_ATTRIBUTE_MAIN_CLASS);
}
}
if (assemblerClass != null) {
classes = assemblerClass.split(",");
}
} catch (IOException ignored) {
// we simply show no entries here
}
// show every entry class that can be loaded later on.
for (String clazz : classes) {
clazz = clazz.trim();
PackagedProgram program = null;
try {
program = new PackagedProgram(f, clazz, new String[0]);
} catch (Exception ignored) {
// ignore jar files which throw an error upon creating a PackagedProgram
}
if (program != null) {
gen.writeStartObject();
gen.writeStringField("name", clazz);
String desc = program.getDescription();
gen.writeStringField("description", desc == null ? "No description provided" : desc);
gen.writeEndObject();
}
}
gen.writeEndArray();
gen.writeEndObject();
}
gen.writeEndArray();
gen.writeEndObject();
gen.close();
return writer.toString();
} catch (Exception e) {
throw new RuntimeException("Failed to fetch jar list: " + e.getMessage(), e);
}
}
use of java.io.FilenameFilter in project hadoop by apache.
the class TestEditLog method testEditLogFailOverFromCorrupt.
/**
* Test edit log failover from a corrupt edit log
*/
@Test
public void testEditLogFailOverFromCorrupt() throws IOException {
File f1 = new File(TEST_DIR + "/failover0");
File f2 = new File(TEST_DIR + "/failover1");
List<URI> editUris = ImmutableList.of(f1.toURI(), f2.toURI());
NNStorage storage = setupEdits(editUris, 3);
final long startErrorTxId = 1 * TXNS_PER_ROLL + 1;
final long endErrorTxId = 2 * TXNS_PER_ROLL;
File[] files = new File(f1, "current").listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.startsWith(NNStorage.getFinalizedEditsFileName(startErrorTxId, endErrorTxId))) {
return true;
}
return false;
}
});
assertEquals(1, files.length);
long fileLen = files[0].length();
LOG.debug("Corrupting Log File: " + files[0] + " len: " + fileLen);
RandomAccessFile rwf = new RandomAccessFile(files[0], "rw");
// seek to checksum bytes
rwf.seek(fileLen - 4);
int b = rwf.readInt();
rwf.seek(fileLen - 4);
rwf.writeInt(b + 1);
rwf.close();
FSEditLog editlog = getFSEditLog(storage);
editlog.initJournalsForWrite();
long startTxId = 1;
Collection<EditLogInputStream> streams = null;
try {
streams = editlog.selectInputStreams(startTxId, 4 * TXNS_PER_ROLL);
readAllEdits(streams, startTxId);
} catch (IOException e) {
LOG.error("edit log failover didn't work", e);
fail("Edit log failover didn't work");
} finally {
IOUtils.cleanup(null, streams.toArray(new EditLogInputStream[0]));
}
}
use of java.io.FilenameFilter in project hadoop by apache.
the class TestFileJournalManager method testManyLogsWithCorruptInprogress.
/**
* Test that we can load an edits directory with a corrupt inprogress file.
* The corrupt inprogress file should be moved to the side.
*/
@Test
public void testManyLogsWithCorruptInprogress() throws IOException {
File f = new File(TestEditLog.TEST_DIR + "/manylogswithcorruptinprogress");
NNStorage storage = setupEdits(Collections.<URI>singletonList(f.toURI()), 10, new AbortSpec(10, 0));
StorageDirectory sd = storage.dirIterator(NameNodeDirType.EDITS).next();
File[] files = new File(f, "current").listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.startsWith("edits_inprogress")) {
return true;
}
return false;
}
});
assertEquals(files.length, 1);
corruptAfterStartSegment(files[0]);
FileJournalManager jm = new FileJournalManager(conf, sd, storage);
assertEquals(10 * TXNS_PER_ROLL + 1, getNumberOfTransactions(jm, 1, true, false));
}
use of java.io.FilenameFilter in project hadoop by apache.
the class TestFileJournalManager method testManyLogsWithGaps.
/**
* Test that we receive the correct number of transactions when we count
* the number of transactions around gaps.
* Set up a single edits directory, with no failures. Delete the 4th logfile.
* Test that getNumberOfTransactions returns the correct number of
* transactions before this gap and after this gap. Also verify that if you
* try to count on the gap that an exception is thrown.
*/
@Test
public void testManyLogsWithGaps() throws IOException {
File f = new File(TestEditLog.TEST_DIR + "/manylogswithgaps");
NNStorage storage = setupEdits(Collections.<URI>singletonList(f.toURI()), 10);
StorageDirectory sd = storage.dirIterator(NameNodeDirType.EDITS).next();
final long startGapTxId = 3 * TXNS_PER_ROLL + 1;
final long endGapTxId = 4 * TXNS_PER_ROLL;
File[] files = new File(f, "current").listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.startsWith(NNStorage.getFinalizedEditsFileName(startGapTxId, endGapTxId))) {
return true;
}
return false;
}
});
assertEquals(1, files.length);
assertTrue(files[0].delete());
FileJournalManager jm = new FileJournalManager(conf, sd, storage);
assertEquals(startGapTxId - 1, getNumberOfTransactions(jm, 1, true, true));
assertEquals(0, getNumberOfTransactions(jm, startGapTxId, true, true));
// rolled 10 times so there should be 11 files.
assertEquals(11 * TXNS_PER_ROLL - endGapTxId, getNumberOfTransactions(jm, endGapTxId + 1, true, true));
}
Aggregations