Search in sources :

Example 1 with LogNetworkReader

use of com.emc.storageos.systemservices.impl.logsvc.stream.LogNetworkReader 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 LogNetworkReader

use of com.emc.storageos.systemservices.impl.logsvc.stream.LogNetworkReader in project coprhd-controller by CoprHD.

the class LogNetworkReaderPerfTest method testPerformance.

@Test
public void testPerformance() throws Exception {
    List<String> svcs = new ArrayList<String>() {

        {
            add("controllersvc");
            add("coordinatorsvc");
            add("apisvc");
        }
    };
    int bufSize = 1024 * 64;
    LogRequest req = new LogRequest.Builder().baseNames(svcs).build();
    final LogNetworkWriter writer = new LogNetworkWriter(req, propertiesLoader);
    try (final PipedOutputStream out = new PipedOutputStream();
        final BufferedOutputStream outputStream = new BufferedOutputStream(out, bufSize);
        final PipedInputStream inputStream = new PipedInputStream(out)) {
        LogNetworkReader reader = new LogNetworkReader("vipr1", "vipr1", inputStream, new LogStatusInfo());
        long totalSize = 0;
        long startTime = System.nanoTime();
        new Thread(new Runnable() {

            public void run() {
                try {
                    writer.write(outputStream);
                } catch (Exception e) {
                    // NOSONAR
                    e.printStackTrace();
                // ("squid:S1148 suppress sonar warning on printStackTrace. It's a test case and exceptions are meant to be printed to stdout/stderr")
                }
            }
        }).start();
        LogMessage log = null;
        while ((log = reader.readNextLogMessage()) != null) {
            totalSize += log.toStringOriginalFormat().getBytes().length;
        }
        long endTime = System.nanoTime();
        totalSize /= (1024L * 1024L);
        double elapsedTime = (double) (endTime - startTime) / 1000000000.0;
        System.out.println("Total read " + totalSize + " MB;" + " Used " + elapsedTime + " sec; Average " + (totalSize / elapsedTime) + " MB/sec.");
    }
}
Also used : LogStatusInfo(com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo) LogNetworkReader(com.emc.storageos.systemservices.impl.logsvc.stream.LogNetworkReader) ArrayList(java.util.ArrayList) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) LogRequest(com.emc.vipr.model.sys.logging.LogRequest) LogNetworkWriter(com.emc.storageos.systemservices.impl.logsvc.LogNetworkWriter) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) BufferedOutputStream(java.io.BufferedOutputStream) Test(org.junit.Test)

Aggregations

LogNetworkReader (com.emc.storageos.systemservices.impl.logsvc.stream.LogNetworkReader)2 LogRequest (com.emc.vipr.model.sys.logging.LogRequest)2 ArrayList (java.util.ArrayList)2 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 SysClientFactory (com.emc.storageos.systemservices.impl.client.SysClientFactory)1 LogMessage (com.emc.storageos.systemservices.impl.logsvc.LogMessage)1 LogNetworkWriter (com.emc.storageos.systemservices.impl.logsvc.LogNetworkWriter)1 LogStatusInfo (com.emc.storageos.systemservices.impl.logsvc.LogStatusInfo)1 NodeInfo (com.emc.storageos.systemservices.impl.resource.util.NodeInfo)1 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 PipedInputStream (java.io.PipedInputStream)1 PipedOutputStream (java.io.PipedOutputStream)1 SocketTimeoutException (java.net.SocketTimeoutException)1 CompressorException (org.apache.commons.compress.compressors.CompressorException)1 Test (org.junit.Test)1