Search in sources :

Example 6 with LogRequest

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

the class LogReaderTest method testReadRegularLogNoFilterSvcParser.

/**
 * Test if readMessage() can read regular service log from file and parse it correctly
 */
@Test
public void testReadRegularLogNoFilterSvcParser() throws Exception {
    LogStatusInfo status = new LogStatusInfo();
    LogRequest req = new LogRequest.Builder().build();
    LogReader reader = new LogReader(regularSvcLogPath, req, status, null);
    LogMessage l = reader.readNextLogMessage();
    Calendar calendar = Calendar.getInstance();
    // month starts from 0;
    calendar.set(2014, 0, 16, 17, 7, 57);
    calendar.set(Calendar.MILLISECOND, 561);
    Date date = calendar.getTime();
    long time = date.getTime();
    assertEquals("Time is wrong", l.getTime(), time);
    assertTrue("Thread name is wrong", Arrays.equals(LogUtil.stringToBytes("LogLevelResetter"), l.getThreadName()));
    assertEquals("Log level is wrong", new String(l.getLevel()), "INFO");
    assertTrue("File name is wrong", Arrays.equals(LogUtil.stringToBytes("LoggingMBean"), l.getFileName()));
    assertTrue("Line number is wrong", Arrays.equals(l.getLineNumber(), LogUtil.stringToBytes("322")));
    assertTrue("Log message contact is wrong", Arrays.equals(LogUtil.stringToBytes("Starting log level config reset, lastResetTime = 0"), l.getLogContent()));
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) Calendar(java.util.Calendar) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) Date(java.util.Date) Test(org.junit.Test)

Example 7 with LogRequest

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

the class LogRequestTest method testMarshalUnMarshal.

@Test
public void testMarshalUnMarshal() throws Exception {
    System.out.println("Entering testMarshlUnMarshal()");
    LogRequest req = new LogRequest();
    List<String> baseNames = new ArrayList<String>();
    List<String> nodeIds = new ArrayList<String>();
    baseNames.add("apisvc");
    nodeIds.add("standalone");
    req.setBaseNames(baseNames);
    req.setMaxCount(10);
    req.setNodeIds(nodeIds);
    File file = new File(PATH + File.separator + "file.xml");
    JAXBContext jc = JAXBContext.newInstance(LogRequest.class);
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(req, file);
    Unmarshaller jaxbUnmarshaller = jc.createUnmarshaller();
    LogRequest reqNew = (LogRequest) jaxbUnmarshaller.unmarshal(file);
    assertTrue("The object after marshal and unMarshal should be the same with " + "the origianl one", req.toString().equals(reqNew.toString()));
    System.out.println("Done testMarshlUnMarshal() ");
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) ArrayList(java.util.ArrayList) File(java.io.File) Test(org.junit.Test)

Example 8 with LogRequest

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

the class LogStreamMergerTest method testMergeSortCorrectness.

/**
 * Test if merge process can result correct content
 */
@Test
@Ignore
public void testMergeSortCorrectness() throws Exception {
    List<String> svcs = new ArrayList<String>() {

        {
            add("controllersvc");
            add("coordinatorsvc");
        }
    };
    LogRequest req = new LogRequest.Builder().baseNames(svcs).build();
    LogStreamMerger merger = new LogStreamMerger(req, propertiesLoader);
    long prevTime = -1;
    while (true) {
        LogMessage log = merger.readNextMergedLogMessage();
        if (log == null) {
            break;
        }
        long time = log.getTime();
        assertTrue("Output of StreamMerger should be sorted.", prevTime <= time);
        prevTime = time;
    }
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) ArrayList(java.util.ArrayList) LogStreamMerger(com.emc.storageos.systemservices.impl.logsvc.merger.LogStreamMerger) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with LogRequest

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

the class LogStreamTest method testGetFilePathTimeFilter.

/**
 * Test if LogStream can find all files need to read correctly with time
 * range filter
 * This test can only be tested on root@10.10.191.121
 */
@Test
@Ignore
public void testGetFilePathTimeFilter() {
    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"));
    Calendar calendar = Calendar.getInstance();
    calendar.set(2014, 0, 10, 0, 0);
    Date startTimeFilter = calendar.getTime();
    calendar.set(2014, 0, 14, 16, 38);
    Date endTimeFilter = calendar.getTime();
    LogRequest req = new LogRequest.Builder().startTime(startTimeFilter).endTime(endTimeFilter).build();
    LogFileStream stream = new LogFileStream(svcName, files, req, null);
    List<String> paths = stream.getLogPaths();
    List<String> result = new ArrayList<String>();
    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");
    int i = 0;
    assertTrue("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) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) File(java.io.File) Date(java.util.Date) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with LogRequest

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

the class LogStreamTest method testMultipleFilesTimeRangeFilter.

/**
 * Test if logs read from files are in time range specified in LogRequest
 * This test can only be tested on root@10.10.191.121
 */
@Test
@Ignore
public void testMultipleFilesTimeRangeFilter() throws Exception {
    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"));
    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();
        assertTrue("Lines read from LogStream should in time range(multiple files)", 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) Ignore(org.junit.Ignore) 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