Search in sources :

Example 1 with ConfigTable

use of com.couchbase.connector.config.toml.ConfigTable in project couchbase-elasticsearch-connector by couchbase.

the class ElasticsearchConfig method from.

static ImmutableElasticsearchConfig from(ConfigTable config) {
    config.expectOnly("hosts", "username", "pathToPassword", "secureConnection", "clientCertificate", "aws", "bulkRequestLimits", "docStructure", "typeDefaults", "type", "rejectionLog");
    final boolean secureConnection = config.getBoolean("secureConnection").orElse(false);
    final AwsConfig aws = AwsConfig.from(config.getTableOrEmpty("aws"));
    final ClientCertConfig clientCert = ClientCertConfig.from(config.getTableOrEmpty("clientCertificate"), "elasticsearch.clientCertificate");
    // Standard ES HTTP port is 9200. Amazon Elasticsearch Service listens on ports 80 & 443.
    final int defaultPort = aws.region().isEmpty() ? 9200 : secureConnection ? 443 : 80;
    final ImmutableElasticsearchConfig.Builder builder = ImmutableElasticsearchConfig.builder().secureConnection(secureConnection).hosts(config.getRequiredStrings("hosts").stream().map(h -> createHttpHost(h, defaultPort, secureConnection)).collect(toList())).username(config.getString("username").orElse("")).password(readPassword(config, "elasticsearch", "pathToPassword")).bulkRequest(BulkRequestConfig.from(config.getTableOrEmpty("bulkRequestLimits"))).aws(aws).clientCert(clientCert).docStructure(DocStructureConfig.from(config.getTableOrEmpty("docStructure")));
    final ConfigTable typeDefaults = config.getTableOrEmpty("typeDefaults");
    typeDefaults.expectOnly("typeName", "index", "pipeline", "ignore", "ignoreDeletes", "matchOnQualifiedKey");
    final TypeConfig defaultTypeConfig = ImmutableTypeConfig.builder().index(typeDefaults.getString("index").orElse(null)).type(typeDefaults.getString("typeName").orElse("_doc")).pipeline(typeDefaults.getString("pipeline").orElse(null)).ignore(typeDefaults.getBoolean("ignore").orElse(false)).ignoreDeletes(typeDefaults.getBoolean("ignoreDeletes").orElse(false)).matchOnQualifiedKey(typeDefaults.getBoolean("matchOnQualifiedKey").orElse(false)).matcher(s -> null).build();
    ImmutableList.Builder<TypeConfig> typeConfigs = ImmutableList.builder();
    ConfigArray types = config.getArrayOrEmpty("type");
    for (int i = 0; i < types.size(); i++) {
        typeConfigs.add(TypeConfig.from(types.getTable(i), types.inputPositionOf(i), defaultTypeConfig));
    }
    builder.types(typeConfigs.build());
    builder.rejectLog(RejectLogConfig.from(config.getTableOrEmpty("rejectionLog"), defaultTypeConfig.type()));
    return builder.build();
}
Also used : ConfigTable(com.couchbase.connector.config.toml.ConfigTable) ConfigArray(com.couchbase.connector.config.toml.ConfigArray) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList(com.google.common.collect.ImmutableList) Value(org.immutables.value.Value) ConfigHelper.readPassword(com.couchbase.connector.config.ConfigHelper.readPassword) ConfigHelper.createHttpHost(com.couchbase.connector.config.ConfigHelper.createHttpHost) ClientCertConfig(com.couchbase.connector.config.common.ClientCertConfig) ConfigException(com.couchbase.connector.config.ConfigException) HttpHost(org.apache.http.HttpHost) ClientCertConfig(com.couchbase.connector.config.common.ClientCertConfig) ImmutableList(com.google.common.collect.ImmutableList) ConfigArray(com.couchbase.connector.config.toml.ConfigArray) ConfigTable(com.couchbase.connector.config.toml.ConfigTable)

Example 2 with ConfigTable

use of com.couchbase.connector.config.toml.ConfigTable in project couchbase-elasticsearch-connector by couchbase.

the class ConsulConfig method from.

static ImmutableConsulConfig from(ConfigTable root) {
    root.expectOnly("consul");
    ConfigTable config = root.getTableOrEmpty("consul");
    config.expectOnly("aclToken");
    return ImmutableConsulConfig.builder().aclToken(config.getString("aclToken").orElse("")).build();
}
Also used : ConfigTable(com.couchbase.connector.config.toml.ConfigTable)

Example 3 with ConfigTable

use of com.couchbase.connector.config.toml.ConfigTable in project couchbase-elasticsearch-connector by couchbase.

the class GroupConfig method from.

static ImmutableGroupConfig from(ConfigTable config) {
    config.expectOnly("name", "static");
    final ConfigTable staticGroup = config.getTableOrEmpty("static");
    staticGroup.expectOnly("memberNumber", "totalMembers");
    final int totalMembers = staticGroup.getIntInRange("totalMembers", 1, 1024).orElseThrow((() -> new ConfigException("missing 'static.totalMembers' property")));
    final int memberNumber = staticGroup.getInt("memberNumber").orElseThrow(() -> new ConfigException("missing 'static.memberNumber' property"));
    try {
        return ImmutableGroupConfig.builder().name(config.getString("name").orElseThrow(() -> new ConfigException("missing 'name' property"))).staticMembership(Membership.of(memberNumber, totalMembers)).build();
    } catch (IllegalArgumentException e) {
        throw new ConfigException(e.getMessage());
    }
}
Also used : ConfigException(com.couchbase.connector.config.ConfigException) ConfigTable(com.couchbase.connector.config.toml.ConfigTable)

Aggregations

ConfigTable (com.couchbase.connector.config.toml.ConfigTable)3 ConfigException (com.couchbase.connector.config.ConfigException)2 ConfigHelper.createHttpHost (com.couchbase.connector.config.ConfigHelper.createHttpHost)1 ConfigHelper.readPassword (com.couchbase.connector.config.ConfigHelper.readPassword)1 ClientCertConfig (com.couchbase.connector.config.common.ClientCertConfig)1 ConfigArray (com.couchbase.connector.config.toml.ConfigArray)1 ImmutableList (com.google.common.collect.ImmutableList)1 Collectors.toList (java.util.stream.Collectors.toList)1 HttpHost (org.apache.http.HttpHost)1 Value (org.immutables.value.Value)1