Search in sources :

Example 1 with Marshaller

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

the class LogNetworkStreamMerger method streamLogs.

public void streamLogs(OutputStream outputStream) {
    logger.trace("Entering into LogNetworkStreamMerger.streamLogs()");
    CountingOutputStream cos = new CountingOutputStream(new BufferedOutputStream(outputStream, LogConstants.BUFFER_SIZE));
    Marshaller marshaller = MarshallerFactory.getLogMarshaller(mediaType, cos);
    int finalCount = 0;
    try {
        marshaller.head();
        LogMessage msg = readNextMergedLogMessage();
        if (msg != null) {
            do {
                // Maximum bytes to stream check
                streamedBytes = cos.getByteCount();
                if (request.getMaxBytes() > 0 && streamedBytes >= request.getMaxBytes()) {
                    logger.info("Streamed log size {}bytes reached maximum allowed limit {}bytes. So quitting.", streamedBytes, request.getMaxBytes());
                    break;
                }
                List<LogMessage> currentLogBatch = new ArrayList<>();
                LogMessage startLogOfNextBatch = readLogBatch(msg, currentLogBatch);
                if (!LogUtil.permitNextLogBatch(request.getMaxCount(), finalCount, currentLogBatch.size())) {
                    // discard this batch
                    break;
                }
                // current log batch has been accepted
                for (String st : status.getStatus()) {
                    // use previous log message's timeStamp as status's timeStamp
                    marshaller.marshall(st, msg);
                }
                status.clear();
                for (LogMessage logMessage : currentLogBatch) {
                    marshaller.marshall(logMessage);
                    finalCount++;
                }
                msg = startLogOfNextBatch;
            } while (msg != null);
        }
        logger.info("final count={}", finalCount);
        marshaller.tail();
        marshaller.flush();
    } catch (Exception e) {
        logger.error("Exception in streamLogs:", e);
    }
}
Also used : CountingOutputStream(org.apache.commons.io.output.CountingOutputStream) Marshaller(com.emc.storageos.systemservices.impl.logsvc.marshaller.Marshaller) LogMessage(com.emc.storageos.systemservices.impl.logsvc.LogMessage) ArrayList(java.util.ArrayList) BufferedOutputStream(java.io.BufferedOutputStream) 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)

Aggregations

APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)1 InternalServerErrorException (com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException)1 LogMessage (com.emc.storageos.systemservices.impl.logsvc.LogMessage)1 Marshaller (com.emc.storageos.systemservices.impl.logsvc.marshaller.Marshaller)1 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 CompressorException (org.apache.commons.compress.compressors.CompressorException)1 CountingOutputStream (org.apache.commons.io.output.CountingOutputStream)1