use of org.smartdata.metrics.FileAccessEvent in project SSM by Intel-bigdata.
the class NNMetricsAccessEventCollector method collect.
@Override
public List<FileAccessEvent> collect() throws IOException {
try {
if (reader.exists(now)) {
reader.seekTo(now, false);
List<FileAccessEvent> events = new ArrayList<>();
while (reader.hasNext()) {
Info info = reader.next();
events.add(new FileAccessEvent(info.getPath(), info.getTimestamp()));
now = info.getTimestamp();
}
return events;
} else if (reader.exists(now + reader.getRollingIntervalMillis())) {
// This is the corner case that AccessEventFetcher starts a little bit ahead of Namenode
// and then Namenode begins log access event for the current rolling file, while
// AccessCountFetch is seeking for the last one, which will never exist.
now = now + reader.getRollingIntervalMillis() - now % reader.getRollingIntervalMillis();
}
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
return EMPTY_RESULT;
}
use of org.smartdata.metrics.FileAccessEvent in project SSM by Intel-bigdata.
the class AccessEventAggregator method addAccessEvents.
public void addAccessEvents(List<FileAccessEvent> eventList) {
if (this.currentWindow == null && !eventList.isEmpty()) {
this.currentWindow = assignWindow(eventList.get(0).getTimestamp());
}
for (FileAccessEvent event : eventList) {
if (this.currentWindow.contains(event.getTimestamp()) && !event.getPath().isEmpty()) {
this.eventBuffer.add(event);
} else {
// New Window occurs
this.createTable();
this.currentWindow = assignWindow(event.getTimestamp());
this.eventBuffer.clear();
if (!event.getPath().isEmpty()) {
this.eventBuffer.add(event);
}
}
}
}
use of org.smartdata.metrics.FileAccessEvent in project SSM by Intel-bigdata.
the class TestAccessCountTableManager method testAddAccessCountInfo.
@Test
public void testAddAccessCountInfo() throws Exception {
createTables(databaseTester.getConnection());
IDataSet dataSet = new XmlDataSet(getClass().getClassLoader().getResourceAsStream("files.xml"));
databaseTester.setDataSet(dataSet);
databaseTester.onSetup();
DBAdapter adapter = new DBAdapter(databaseTester.getConnection().getConnection());
AccessCountTableManager manager = new AccessCountTableManager(adapter);
List<FileAccessEvent> accessEvents = new ArrayList<>();
accessEvents.add(new FileAccessEvent("file1", 0));
accessEvents.add(new FileAccessEvent("file2", 1));
accessEvents.add(new FileAccessEvent("file2", 2));
accessEvents.add(new FileAccessEvent("file3", 2));
accessEvents.add(new FileAccessEvent("file3", 3));
accessEvents.add(new FileAccessEvent("file3", 4));
accessEvents.add(new FileAccessEvent("file3", 5000));
manager.onAccessEventsArrived(accessEvents);
AccessCountTable accessCountTable = new AccessCountTable(0L, 5000L);
ITable actual = databaseTester.getConnection().createTable(accessCountTable.getTableName());
ITable expect = databaseTester.getDataSet().getTable("expect1");
SortedTable sortedActual = new SortedTable(actual, new String[] { "fid" });
sortedActual.setUseComparable(true);
Assertion.assertEquals(expect, sortedActual);
}
Aggregations