Search in sources :

Example 1 with LogRequest

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

the class LogNetworkStreamMerger method getLogNetworkStreams.

private List<LogNetworkReader> getLogNetworkStreams() {
    List<NodeInfo> nodeInfo;
    List<LogNetworkReader> logNetworkStreams = new ArrayList<>();
    // Getting all nodes information
    if (request.getNodeIds().isEmpty()) {
        logger.info("No nodes specified, getting all nodes");
        nodeInfo = ClusterNodesUtil.getClusterNodeInfo();
    } else {
        nodeInfo = getClusterNodesWithIds(request.getNodeIds());
    }
    if (nodeInfo.isEmpty()) {
        throw APIException.internalServerErrors.noNodeAvailableError("collect logs info");
    }
    List<String> failedNodes = ClusterNodesUtil.getUnavailableControllerNodes();
    if (!request.getNodeIds().isEmpty()) {
        failedNodes.retainAll(request.getNodeIds());
    }
    if (!failedNodes.isEmpty()) {
        logger.error("Cannot collect logs from unavailable nodes: {}", failedNodes.toString());
    }
    for (final NodeInfo node : nodeInfo) {
        LogRequest req;
        SysClientFactory.SysClient sysClient;
        String baseNodeURL = String.format(SysClientFactory.BASE_URL_FORMAT, node.getIpAddress(), node.getPort());
        logger.debug("getting stream from node: " + baseNodeURL);
        logger.debug("connectTimeout=" + propertiesLoader.getNodeLogConnectionTimeout() * 1000);
        logger.debug("readTimeout=" + propertiesLoader.getNodeLogCollectorTimeout() * 1000);
        sysClient = SysClientFactory.getSysClient(URI.create(baseNodeURL), propertiesLoader.getNodeLogCollectorTimeout() * 1000, propertiesLoader.getNodeLogConnectionTimeout() * 1000);
        logger.debug("sysclient=" + sysClient + " uri=" + URI.create(baseNodeURL));
        try {
            req = request;
            req.setNodeIds(new ArrayList<String>() {

                {
                    add(node.getId());
                }
            });
            InputStream nodeResponseStream = sysClient.post(SysClientFactory.URI_NODE_LOGS, InputStream.class, req);
            if (nodeResponseStream != null && nodeResponseStream.available() > 0) {
                LogNetworkReader reader = new LogNetworkReader(node.getId(), node.getName(), nodeResponseStream, status);
                logNetworkStreams.add(reader);
            }
        } catch (Exception e) {
            logger.error("Exception accessing node {}:", baseNodeURL, e);
            // socketTimeoutException wrapped in ClientHandlerException
            if (e.getCause() != null && e.getCause().getCause() instanceof SocketTimeoutException) {
                throw InternalServerErrorException.internalServerErrors.logCollectionTimeout();
            }
        }
    }
    return logNetworkStreams;
}
Also used : LogNetworkReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogNetworkReader) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) SysClientFactory(com.emc.storageos.systemservices.impl.client.SysClientFactory) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SocketTimeoutException(java.net.SocketTimeoutException) CompressorException(org.apache.commons.compress.compressors.CompressorException) IOException(java.io.IOException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) LogRequest(com.emc.vipr.model.sys.logging.LogRequest) SocketTimeoutException(java.net.SocketTimeoutException) NodeInfo(com.emc.storageos.systemservices.impl.resource.util.NodeInfo)

Example 2 with LogRequest

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

the class SysLogReaderTest method testLogCountSysParser.

/**
 * Test if reader could recognize the correct count of system logs
 */
@Test
public void testLogCountSysParser() throws Exception {
    System.out.println("starting testLogCountSysParser");
    LogStatusInfo status = new LogStatusInfo();
    final int WARN = 5;
    // four kinds of different patterns in file
    String filePath = "src/main/data/testReaderData/testSyslogParser.log";
    long logCount = 47;
    LogReader reader = null;
    LogRequest req = new LogRequest.Builder().logLevel(WARN).build();
    reader = new LogReader(filePath, req, status, null);
    while (true) {
        LogMessage log = reader.readNextLogMessage();
        if (log == null) {
            assertEquals("Log count should match", logCount, reader.getLogCount());
            break;
        }
    }
    System.out.println("done testLogCountSysParser");
}
Also used : LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) Test(org.junit.Test)

Example 3 with LogRequest

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

the class SysLogReaderTest method testLogStatusInfo.

/**
 * Test if reader could record correct status information
 */
@Test
public void testLogStatusInfo() throws Exception {
    System.out.println("starting testLogStatusInfo");
    LogStatusInfo status = new LogStatusInfo();
    String filePath = "src/main/data/testReaderData/testStatus.log";
    long logCount = 42;
    LogReader reader = null;
    LogRequest req = new LogRequest.Builder().build();
    reader = new LogReader(filePath, req, status, null);
    while (true) {
        LogMessage log = reader.readNextLogMessage();
        if (log == null) {
            assertEquals("Log count should match", logCount, reader.getLogCount());
            break;
        }
    }
    BufferedReader br = new BufferedReader(new FileReader("src/main/data/testReaderData/testStatusResult.log"));
    String line = br.readLine();
    int index = 0;
    while (line != null) {
        assertTrue("status's size is not correct!", status.getStatus().size() > index);
        assertEquals("status's contect is not correct!", line, status.getStatus().get(index));
        index++;
        line = br.readLine();
    }
    assertEquals("status's size is not correct!", status.getStatus().size(), index);
    br.close();
    System.out.println("done testLogStatusInfo");
}
Also used : LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) LogReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogReader) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Test(org.junit.Test)

Example 4 with LogRequest

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

the class SysLogReaderTest method testPriority.

/**
 * Test if priority value is corrtect
 */
@Test
public void testPriority() throws Exception {
    System.out.println("starting testPriority");
    LogSyslogParser parser = new LogSyslogParser();
    LogRequest req = new LogRequest.Builder().build();
    String log1 = "2014-03-13 15:12:56 [auth] notice sudo: storageos : ";
    String log2 = "2014-03-13 15:36:26 [syslog] info syslog-ng[4043]";
    String log3 = "2014-03-13 16:27:54 [local7] warning NTP: [CONFIGURED, DEGRADED]";
    String log4 = "2014-03-11 17:12:30 [user] err auditd: ";
    String log5 = "2014-03-12 00:00:02 [mail] crit sendmail[10183]: NOQUEUE: SYSERR(root)";
    assertTrue(LogSeverity.toLevel(new String(parser.parseLine(log1, req).getLevel())) == 6);
    assertTrue(LogSeverity.toLevel(new String(parser.parseLine(log2, req).getLevel())) == 7);
    assertTrue(LogSeverity.toLevel(new String(parser.parseLine(log3, req).getLevel())) == 5);
    assertTrue(LogSeverity.toLevel(new String(parser.parseLine(log4, req).getLevel())) == 4);
    assertTrue(LogSeverity.toLevel(new String(parser.parseLine(log5, req).getLevel())) == 3);
    System.out.println("done testPriority");
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) Test(org.junit.Test)

Example 5 with LogRequest

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

the class LogStreamPerfTest method testPerformance.

@Test
public void testPerformance() throws Exception {
    List<File> files = new ArrayList<>();
    files.add(new File("/opt/storageos/logs/testData/controllersvc.log"));
    files.add(new File("/opt/storageos/logs/testData/controllersvc.log.20131120-163817.gz"));
    LogRequest req = new LogRequest.Builder().build();
    LogStatusInfo status = new LogStatusInfo();
    LogFileStream stream = new LogFileStream("", files, req, status);
    long startTime = 0;
    long endTime = 0;
    startTime = System.nanoTime();
    while (true) {
        LogMessage log = stream.readNextLogMessage();
        if (log == null) {
            endTime = System.nanoTime();
            break;
        }
    }
    double elapsedTime = (double) (endTime - startTime) / 1000000000.0;
    double speed = 1510.8 / elapsedTime;
    System.out.println("Total read 1510.8 MB; Used " + elapsedTime + " sec; Average " + speed + " MB/sec.");
}
Also used : LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogFileStream(com.emc.storageos.systemservices.impl.logsvc.stream.LogFileStream) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) ArrayList(java.util.ArrayList) File(java.io.File) 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