Search in sources :

Example 1 with Payload

use of com.yahoo.vespa.config.protocol.Payload in project vespa by vespa-engine.

the class MemoryCache method writeConfigToFile.

private void writeConfigToFile(RawConfig config, String path) {
    String filename = null;
    Writer writer = null;
    try {
        filename = path + File.separator + createCacheFileName(config);
        if (log.isLoggable(LogLevel.DEBUG)) {
            log.log(LogLevel.DEBUG, "Writing '" + config.getKey() + "' to '" + filename + "'");
        }
        final Payload payload = config.getPayload();
        long protocolVersion = 3;
        log.log(LogLevel.DEBUG, "Writing config '" + config + "' to file '" + filename + "' with protocol version " + protocolVersion);
        writer = IOUtils.createWriter(filename, "UTF-8", false);
        // First three lines are meta-data about config as comment lines, fourth line is empty
        writer.write("# defMd5:" + config.getDefMd5() + "\n");
        writer.write("# configMd5:" + config.getConfigMd5() + "\n");
        writer.write("# generation:" + Long.toString(config.getGeneration()) + "\n");
        writer.write("# protocolVersion:" + Long.toString(protocolVersion) + "\n");
        writer.write("\n");
        writer.write(payload.withCompression(CompressionType.UNCOMPRESSED).toString());
        writer.write("\n");
        writer.close();
    } catch (IOException e) {
        log.log(LogLevel.WARNING, "Could not write to file '" + filename + "'");
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Payload(com.yahoo.vespa.config.protocol.Payload) IOException(java.io.IOException) Writer(java.io.Writer)

Example 2 with Payload

use of com.yahoo.vespa.config.protocol.Payload in project vespa by vespa-engine.

the class JRTConfigSubscription method toConfigInstance.

/**
 * This method should ideally throw new MissingConfig/Configuration exceptions and let the caller
 * catch them. However, this would make the code in JRT/File/RawSource uglier.
 * Alternatively, it could return a SetConfigStatus object with an int and an error message.
 *
 * @param jrtRequest a config request
 * @return an instance of a config class (subclass of ConfigInstance)
 */
private T toConfigInstance(JRTClientConfigRequest jrtRequest) {
    Payload payload = jrtRequest.getNewPayload();
    ConfigPayload configPayload = ConfigPayload.fromUtf8Array(payload.withCompression(CompressionType.UNCOMPRESSED).getData());
    T configInstance = configPayload.toInstance(configClass, jrtRequest.getConfigKey().getConfigId());
    configInstance.setConfigMd5(jrtRequest.getNewConfigMd5());
    return configInstance;
}
Also used : ConfigPayload(com.yahoo.vespa.config.ConfigPayload) Payload(com.yahoo.vespa.config.protocol.Payload) ConfigPayload(com.yahoo.vespa.config.ConfigPayload)

Aggregations

Payload (com.yahoo.vespa.config.protocol.Payload)2 ConfigPayload (com.yahoo.vespa.config.ConfigPayload)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1