Search in sources :

Example 6 with EUnexpected

use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.

the class StartupSequence method initLogging.

/**
 * Initialize the logging framework.
 *
 * <p>Logging can be configured by setting the property logging.url in the config
 * section of the root configuration, to point to the location of a logging config file.
 * TRAC uses Log4j2 as a backend for slf4j, so the logging config file must be a valid
 * log4j2 config file. If no logging config is provided, messages will be logged
 * to stdout.</p>
 *
 * <p>This method should be called immediately after calling initConfigPlugins(),
 * since it uses the config loading mechanism which relies on those plugins being
 * available.</p>
 *
 * @throws EStartup There was an error processing the logging config
 */
public void initLogging() {
    // Logger configured using initStartupLogging
    var log = LoggerFactory.getLogger(getClass());
    var rootConfigMap = config.loadRootConfigObject(Map.class);
    String loggingConfigUrl = lookupLoggingConfigUrl(rootConfigMap);
    if (loggingConfigUrl != null && !loggingConfigUrl.isBlank()) {
        var loggingConfig = config.loadConfigFile(loggingConfigUrl);
        try (var configStream = new ByteArrayInputStream(loggingConfig.getBytes())) {
            var configSource = new ConfigurationSource(configStream);
            Configurator.initialize(getClass().getClassLoader(), configSource);
        // Invalid logging configuration cause the startup sequence to bomb out
        } catch (IOException e) {
            // Unexpected error condition - IO error reading from a byte buffer
            throw new EUnexpected(e);
        }
    } else {
        log.info("Using default logging config");
    }
    log.info("Initialize logging...");
    Configurator.reconfigure();
}
Also used : ConfigurationSource(org.apache.logging.log4j.core.config.ConfigurationSource) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) EUnexpected(com.accenture.trac.common.exception.EUnexpected)

Example 7 with EUnexpected

use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.

the class Bytes method toProtoBytes.

public static ByteString toProtoBytes(ByteBuf buf) {
    try {
        if (buf.nioBufferCount() == 1) {
            var nioBuffer = buf.nioBuffer();
            return ByteString.copyFrom(nioBuffer);
        }
        if (buf.nioBufferCount() > 1) {
            var nioBuffers = buf.nioBuffers();
            var byteStream = Arrays.stream(nioBuffers).map(ByteString::copyFrom).reduce(ByteString::concat);
            if (byteStream.isEmpty())
                throw new EUnexpected();
            return byteStream.get();
        }
        if (buf.hasArray()) {
            return UnsafeByteOperations.unsafeWrap(buf.array());
        }
        var bufCopy = new byte[buf.readableBytes()];
        buf.readBytes(bufCopy);
        return UnsafeByteOperations.unsafeWrap(bufCopy);
    } finally {
        buf.release();
    }
}
Also used : ByteString(com.google.protobuf.ByteString) EUnexpected(com.accenture.trac.common.exception.EUnexpected)

Example 8 with EUnexpected

use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.

the class LocalFileWriter method writeNextChunk.

private void writeNextChunk() {
    ByteBuf chunk = null;
    try {
        if (chunkInProgress || chunkBuffer.isEmpty())
            throw new EUnexpected();
        chunkInProgress = true;
        chunksRequested -= 1;
        chunk = chunkBuffer.remove();
        var offset = bytesReceived;
        bytesReceived += chunk.readableBytes();
        if (chunk.nioBufferCount() < 1)
            throw new EUnexpected();
        var nioChunk = chunk.nioBuffer();
        channel.write(nioChunk, offset, chunk, writeHandler);
    } catch (Exception e) {
        if (chunk != null)
            releaseBuffer(chunk);
        gotError = true;
        handleError(e, true);
    }
}
Also used : EUnexpected(com.accenture.trac.common.exception.EUnexpected) ByteBuf(io.netty.buffer.ByteBuf)

Example 9 with EUnexpected

use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.

the class ConfigParser method parseConfig.

public static <TConfig extends Message, B extends Message.Builder> TConfig parseConfig(ByteBuf configData, ConfigFormat configFormat, Class<TConfig> configClass) {
    try {
        var newBuilder = configClass.getMethod("newBuilder");
        var builder = (TConfig.Builder) newBuilder.invoke(null);
        var blankConfig = (TConfig) builder.build();
        switch(configFormat) {
            case PROTO:
                return parseProtoConfig(configData, blankConfig);
            case JSON:
                return parseJsonConfig(configData, blankConfig);
            case YAML:
                return parseYamlConfig(configData, blankConfig);
            default:
                throw new EStartup(String.format("Unknown config format [%s]", configFormat));
        }
    } catch (InvalidProtocolBufferException e) {
        throw new EStartup("Invalid config: " + e.getMessage(), e);
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        // Error invoking reflective method for builder
        throw new EUnexpected();
    } finally {
        configData.release();
    }
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) EUnexpected(com.accenture.trac.common.exception.EUnexpected) EStartup(com.accenture.trac.common.exception.EStartup) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 10 with EUnexpected

use of com.accenture.trac.common.exception.EUnexpected in project tracdap by finos.

the class Flows method concat.

public static <T> Flow.Publisher<T> concat(List<Flow.Publisher<T>> publishers) {
    if (publishers.isEmpty())
        throw new EUnexpected();
    var concat = new ConcatProcessor<>(publishers);
    publishers.get(0).subscribe(concat);
    return concat;
}
Also used : EUnexpected(com.accenture.trac.common.exception.EUnexpected)

Aggregations

EUnexpected (com.accenture.trac.common.exception.EUnexpected)44 IOException (java.io.IOException)8 EDataCorruption (com.accenture.trac.common.exception.EDataCorruption)4 ArrayList (java.util.ArrayList)3 ECacheTicket (com.accenture.trac.common.exception.ECacheTicket)2 EInputValidation (com.accenture.trac.common.exception.EInputValidation)2 ByteSeekableChannel (com.accenture.trac.common.util.ByteSeekableChannel)2 Http1to2Framing (com.accenture.trac.gateway.proxy.http.Http1to2Framing)2 JacksonException (com.fasterxml.jackson.core.JacksonException)2 JsonToken (com.fasterxml.jackson.core.JsonToken)2 ByteString (com.google.protobuf.ByteString)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)2 MetadataBatchRequest (com.accenture.trac.api.MetadataBatchRequest)1 MetadataBatchResponse (com.accenture.trac.api.MetadataBatchResponse)1 MetadataWriteRequest (com.accenture.trac.api.MetadataWriteRequest)1 TrustedMetadataApiGrpc (com.accenture.trac.api.TrustedMetadataApiGrpc)1 EMetadataNotFound (com.accenture.trac.common.exception.EMetadataNotFound)1 EPluginNotAvailable (com.accenture.trac.common.exception.EPluginNotAvailable)1 EStartup (com.accenture.trac.common.exception.EStartup)1