Search in sources :

Example 1 with FileAccessEvent

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;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) FileAccessEvent(org.smartdata.metrics.FileAccessEvent) MetricsInfo(org.apache.hadoop.metrics2.MetricsInfo)

Example 2 with FileAccessEvent

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);
            }
        }
    }
}
Also used : FileAccessEvent(org.smartdata.metrics.FileAccessEvent)

Example 3 with FileAccessEvent

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);
}
Also used : DBAdapter(org.smartdata.server.metastore.DBAdapter) SortedTable(org.dbunit.dataset.SortedTable) ArrayList(java.util.ArrayList) ITable(org.dbunit.dataset.ITable) IDataSet(org.dbunit.dataset.IDataSet) FileAccessEvent(org.smartdata.metrics.FileAccessEvent) XmlDataSet(org.dbunit.dataset.xml.XmlDataSet) Test(org.junit.Test) DBTest(org.smartdata.server.metastore.DBTest)

Aggregations

FileAccessEvent (org.smartdata.metrics.FileAccessEvent)3 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 MetricsInfo (org.apache.hadoop.metrics2.MetricsInfo)1 IDataSet (org.dbunit.dataset.IDataSet)1 ITable (org.dbunit.dataset.ITable)1 SortedTable (org.dbunit.dataset.SortedTable)1 XmlDataSet (org.dbunit.dataset.xml.XmlDataSet)1 Test (org.junit.Test)1 DBAdapter (org.smartdata.server.metastore.DBAdapter)1 DBTest (org.smartdata.server.metastore.DBTest)1