Search in sources :

Example 31 with LogRequest

use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.

the class LogStreamTest method testGetFilePathNullTimeFilters.

/**
 * Test if LogStream can find all files need to read correctly And test if
 * LogStream can deal null time filter value correctly
 * This test can only be tested on root@10.10.191.121
 */
@Test
@Ignore
public void testGetFilePathNullTimeFilters() {
    String svcName = "controllersvc";
    List<File> files = new ArrayList<File>();
    files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140110-231105.gz"));
    files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140114-151216.gz"));
    files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140112-175108.gz"));
    files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140116-031010.gz"));
    files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log"));
    files.add(new File(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140109-101159.gz"));
    LogRequest req = new LogRequest.Builder().build();
    LogStatusInfo status = new LogStatusInfo();
    LogFileStream stream = new LogFileStream(svcName, files, req, status);
    List<String> paths = stream.getLogPaths();
    List<String> result = new ArrayList<String>();
    result.add(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140109-101159.gz");
    result.add(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140110-231105.gz");
    result.add(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140112-175108.gz");
    result.add(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140114-151216.gz");
    result.add(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log.20140116-031010.gz");
    result.add(HARD_CODE_PATH + "/src/main/data/streamData/controllersvc.log");
    int i = 0;
    assertEquals("Time range and svc filters are not correct", paths.size(), result.size());
    for (String str : paths) {
        assertEquals("Time range and svc filters are not correct", str, result.get(i));
        i++;
    }
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogFileStream(com.emc.storageos.systemservices.impl.logsvc.stream.LogFileStream) ArrayList(java.util.ArrayList) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 32 with LogRequest

use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.

the class LogStreamTest method testReadNextLogMaxCountFilterLessThanMAXCOUNTOVERFLOW.

/**
 * Test max count filter totalCount < maxCount + MAX_OVERFLOW
 *
 * @throws Exception
 */
@Test
@Ignore
public void testReadNextLogMaxCountFilterLessThanMAXCOUNTOVERFLOW() throws Exception {
    List<File> files = new ArrayList<File>();
    files.add(new File(timeStampFilePath));
    // should get 5 log Messages
    long maxCount = 1;
    int count = 0;
    LogRequest req = new LogRequest.Builder().maxCont(maxCount).build();
    LogStatusInfo status = new LogStatusInfo();
    LogFileStream stream = new LogFileStream("", files, req, status);
    while (true) {
        LogMessage log = stream.readNextLogMessage();
        if (log == null) {
            assertEquals("Total line number should match max count limit", 5, count);
            break;
        }
        count++;
    }
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogFileStream(com.emc.storageos.systemservices.impl.logsvc.stream.LogFileStream) ArrayList(java.util.ArrayList) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 33 with LogRequest

use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.

the class LogStreamTest method testSmallFileTimeRangeFilter.

/**
 * Test if logs read from one file are in time range specified in LogRequest
 */
@Test
public void testSmallFileTimeRangeFilter() throws Exception {
    File file = new File(timeRangeFilePath);
    List<File> files = new ArrayList<File>();
    files.add(file);
    Calendar calendar = Calendar.getInstance();
    calendar.set(2013, 10, 20, 16, 38);
    Date startTime = calendar.getTime();
    long startTimeLong = startTime.getTime();
    calendar.set(2014, 0, 16, 16, 38);
    Date endTime = calendar.getTime();
    long endTimeLong = endTime.getTime();
    LogRequest req = new LogRequest.Builder().startTime(startTime).endTime(endTime).build();
    LogStatusInfo status = new LogStatusInfo();
    LogFileStream stream = new LogFileStream("", files, req, status);
    while (true) {
        LogMessage log = stream.readNextLogMessage();
        if (log == null) {
            break;
        }
        long time = log.getTime();
        // System.out.println(startTimeLong + " " + endTimeLong + " " +
        // time);
        assertTrue("Lines read from LogStream should in time range(one file)", time >= startTimeLong && time <= endTimeLong);
    }
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogFileStream(com.emc.storageos.systemservices.impl.logsvc.stream.LogFileStream) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 34 with LogRequest

use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.

the class LogStreamTest method testReadLineNoFilter.

/**
 * Test if logCounter in LogStream can record number of logs correctly And
 * test if sizeCounter in LogStream can record count of total file size
 * correctly Test if fileCounter in LogStream can record file count
 * correctly
 *
 * @throws Exception
 *             This test can only be tested on root@10.10.191.121
 */
@Test
@Ignore
public void testReadLineNoFilter() throws Exception {
    String svcName = "dbsvc-";
    // dbsvc-0.log + dbsvc-1.log + dbsvc-2.log
    final long LINE_NUMBER = 500000 + 500000 + 10;
    File f1 = new File(HARD_CODE_PATH + "/src/main/data/streamData/dbsvc-0.log");
    File f2 = new File(HARD_CODE_PATH + "/src/main/data/streamData/dbsvc-1.log");
    File f3 = new File(HARD_CODE_PATH + "/src/main/data/streamData/dbsvc-2.log");
    List<File> files = new ArrayList<File>();
    files.add(f1);
    files.add(f2);
    files.add(f3);
    final long TOTAL_BYTES = f1.length() + f2.length() + f3.length();
    LogStatusInfo status = new LogStatusInfo();
    LogRequest req = new LogRequest.Builder().build();
    LogFileStream stream = new LogFileStream(svcName, files, req, status);
    // file count
    final int FILE_NUMBER = stream.getLogPaths().size();
    while (true) {
        LogMessage log = stream.readNextLogMessage();
        if (log == null) {
            assertEquals("Total logs number should match", LINE_NUMBER, stream.getTotalLogCount());
            assertEquals("Total file size should match", TOTAL_BYTES, stream.getTotalSizeCount());
            assertEquals("Total file number should match", FILE_NUMBER, stream.getFileCount());
            break;
        }
    }
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogFileStream(com.emc.storageos.systemservices.impl.logsvc.stream.LogFileStream) ArrayList(java.util.ArrayList) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 35 with LogRequest

use of com.emc.vipr.model.sys.logging.LogRequest in project coprhd-controller by CoprHD.

the class ParserTest method testNginxAccessLog.

@Test
public void testNginxAccessLog() throws Exception {
    LogReader reader = null;
    String regexStr = ".*login HTTP.*";
    Calendar calendar = Calendar.getInstance();
    calendar.set(2014, 1, 20, 16, 38, 16);
    Date startTimeFilter = calendar.getTime();
    calendar.set(2014, 6, 16, 16, 38, 0);
    Date endTimeFilter = calendar.getTime();
    LogRequest request = new LogRequest.Builder().regex(regexStr).startTime(startTimeFilter).endTime(endTimeFilter).build();
    LogStatusInfo status = new LogStatusInfo();
    // "/opt/storageos/logs/nginx_access.log";
    String filePath = nginxAccessLogPath;
    String baseName = "nginx";
    reader = new LogReader(filePath, request, status, baseName);
    final LogMessage log = reader.readNextLogMessage();
    assertTrue("log is null", log != null);
    assertTrue("log message is null", !new String(log.getLogContent()).equals("null"));
    assertTrue("log message does not match regex", Pattern.compile(regexStr, Pattern.DOTALL | Pattern.MULTILINE).matcher(LogUtil.bytesToString(log.getLogContent())).matches());
    assertTrue("log time does not fit time filter", log.getTime() >= startTimeFilter.getTime() && log.getTime() <= endTimeFilter.getTime());
    assertTrue("log file name is not null", new String(log.getFileName()).equals("null"));
    assertTrue("log thread name not is null", new String(log.getThreadName()).equals("null"));
    assertTrue("log level is not null", new String(log.getLevel()).equals("null"));
    assertTrue("log line is not -1", new String(log.getLineNumber()).equals("-1"));
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) Calendar(java.util.Calendar) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) Date(java.util.Date) Test(org.junit.Test)

Aggregations

LogRequest (com.emc.vipr.model.sys.logging.LogRequest)38 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)21 File (java.io.File)17 LogMessage (com.emc.storageos.systemservices.impl.logsvc.LogMessage)15 LogFileStream (com.emc.storageos.systemservices.impl.logsvc.stream.LogFileStream)13 Calendar (java.util.Calendar)13 Date (java.util.Date)13 LogStatusInfo (com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo)12 Ignore (org.junit.Ignore)12 LogReader (com.emc.storageos.systemservices.impl.logsvc.stream.LogReader)10 LogStreamMerger (com.emc.storageos.systemservices.impl.logsvc.merger.LogStreamMerger)4 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 SysClientFactory (com.emc.storageos.systemservices.impl.client.SysClientFactory)2 LogNetworkWriter (com.emc.storageos.systemservices.impl.logsvc.LogNetworkWriter)2 LogNetworkStreamMerger (com.emc.storageos.systemservices.impl.logsvc.merger.LogNetworkStreamMerger)2 LogNetworkReader (com.emc.storageos.systemservices.impl.logsvc.stream.LogNetworkReader)2 NodeInfo (com.emc.storageos.systemservices.impl.resource.util.NodeInfo)2 BufferedReader (java.io.BufferedReader)2 FileReader (java.io.FileReader)2