Search in sources :

Example 1 with BKDLConfigFormat

use of com.twitter.distributedlog.thrift.BKDLConfigFormat in project distributedlog by twitter.

the class BKDLConfig method deserialize.

@Override
public void deserialize(byte[] data) throws IOException {
    BKDLConfigFormat configFormat = new BKDLConfigFormat();
    TMemoryInputTransport transport = new TMemoryInputTransport(data);
    TJSONProtocol protocol = new TJSONProtocol(transport);
    try {
        configFormat.read(protocol);
    } catch (TException e) {
        throw new IOException("Failed to deserialize data '" + new String(data, UTF_8) + "' : ", e);
    }
    // bookkeeper cluster settings
    if (configFormat.isSetBkZkServers()) {
        bkZkServersForWriter = configFormat.getBkZkServers();
    }
    if (configFormat.isSetBkZkServersForReader()) {
        bkZkServersForReader = configFormat.getBkZkServersForReader();
    } else {
        bkZkServersForReader = bkZkServersForWriter;
    }
    if (configFormat.isSetBkLedgersPath()) {
        bkLedgersPath = configFormat.getBkLedgersPath();
    }
    // dl zookeeper cluster settings
    if (configFormat.isSetDlZkServersForWriter()) {
        dlZkServersForWriter = configFormat.getDlZkServersForWriter();
    }
    if (configFormat.isSetDlZkServersForReader()) {
        dlZkServersForReader = configFormat.getDlZkServersForReader();
    } else {
        dlZkServersForReader = dlZkServersForWriter;
    }
    // dl settings
    sanityCheckTxnID = !configFormat.isSetSanityCheckTxnID() || configFormat.isSanityCheckTxnID();
    encodeRegionID = configFormat.isSetEncodeRegionID() && configFormat.isEncodeRegionID();
    if (configFormat.isSetAclRootPath()) {
        aclRootPath = configFormat.getAclRootPath();
    }
    if (configFormat.isSetFirstLogSegmentSeqNo()) {
        firstLogSegmentSeqNo = configFormat.getFirstLogSegmentSeqNo();
    }
    isFederatedNamespace = configFormat.isSetFederatedNamespace() && configFormat.isFederatedNamespace();
    // Validate the settings
    if (null == bkZkServersForWriter || null == bkZkServersForReader || null == bkLedgersPath || null == dlZkServersForWriter || null == dlZkServersForReader) {
        throw new IOException("Missing zk/bk settings in BKDL Config : " + new String(data, UTF_8));
    }
}
Also used : TException(org.apache.thrift.TException) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) BKDLConfigFormat(com.twitter.distributedlog.thrift.BKDLConfigFormat) IOException(java.io.IOException) TMemoryInputTransport(org.apache.thrift.transport.TMemoryInputTransport)

Example 2 with BKDLConfigFormat

use of com.twitter.distributedlog.thrift.BKDLConfigFormat in project distributedlog by twitter.

the class BKDLConfig method serialize.

@Override
public String serialize() {
    BKDLConfigFormat configFormat = new BKDLConfigFormat();
    if (null != bkZkServersForWriter) {
        configFormat.setBkZkServers(bkZkServersForWriter);
    }
    if (null != bkZkServersForReader) {
        configFormat.setBkZkServersForReader(bkZkServersForReader);
    }
    if (null != dlZkServersForWriter) {
        configFormat.setDlZkServersForWriter(dlZkServersForWriter);
    }
    if (null != dlZkServersForReader) {
        configFormat.setDlZkServersForReader(dlZkServersForReader);
    }
    if (null != bkLedgersPath) {
        configFormat.setBkLedgersPath(bkLedgersPath);
    }
    configFormat.setSanityCheckTxnID(sanityCheckTxnID);
    configFormat.setEncodeRegionID(encodeRegionID);
    if (null != aclRootPath) {
        configFormat.setAclRootPath(aclRootPath);
    }
    if (null != firstLogSegmentSeqNo) {
        configFormat.setFirstLogSegmentSeqNo(firstLogSegmentSeqNo);
    }
    if (isFederatedNamespace) {
        configFormat.setFederatedNamespace(true);
    }
    return serialize(configFormat);
}
Also used : BKDLConfigFormat(com.twitter.distributedlog.thrift.BKDLConfigFormat)

Aggregations

BKDLConfigFormat (com.twitter.distributedlog.thrift.BKDLConfigFormat)2 IOException (java.io.IOException)1 TException (org.apache.thrift.TException)1 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)1 TMemoryInputTransport (org.apache.thrift.transport.TMemoryInputTransport)1