All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scalar.db.storage.dynamo.DynamoConfig Maven / Gradle / Ivy

Go to download

A universal transaction manager that achieves database-agnostic transactions and distributed transactions that span multiple databases

There is a newer version: 3.14.0
Show newest version
package com.scalar.db.storage.dynamo;

import static com.scalar.db.config.ConfigUtils.getString;

import com.scalar.db.config.DatabaseConfig;
import java.util.Optional;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Immutable
public class DynamoConfig {
  private static final Logger logger = LoggerFactory.getLogger(DynamoConfig.class);

  public static final String PREFIX = DatabaseConfig.PREFIX + "dynamo.";
  public static final String ENDPOINT_OVERRIDE = PREFIX + "endpoint_override";
  public static final String TABLE_METADATA_NAMESPACE = PREFIX + "table_metadata.namespace";
  public static final String NAMESPACE_PREFIX = PREFIX + "namespace.prefix";

  private final String region;
  private final String accessKeyId;
  private final String secretAccessKey;
  @Nullable private final String endpointOverride;
  @Nullable private final String tableMetadataNamespace;
  @Nullable private final String namespacePrefix;

  public DynamoConfig(DatabaseConfig databaseConfig) {
    String storage = databaseConfig.getStorage();
    if (!"dynamo".equals(storage)) {
      throw new IllegalArgumentException(DatabaseConfig.STORAGE + " should be 'dynamo'");
    }

    if (databaseConfig.getContactPoints().isEmpty()) {
      throw new IllegalArgumentException(DatabaseConfig.CONTACT_POINTS + " is empty");
    }
    region = databaseConfig.getContactPoints().get(0);
    accessKeyId = databaseConfig.getUsername().orElse(null);
    secretAccessKey = databaseConfig.getPassword().orElse(null);
    if (databaseConfig.getProperties().containsKey("scalar.db.dynamo.endpoint-override")) {
      logger.warn(
          "The property \"scalar.db.dynamo.endpoint-override\" is deprecated and will be removed in 5.0.0. "
              + "Please use \""
              + ENDPOINT_OVERRIDE
              + "\" instead.");
    }
    endpointOverride =
        getString(
            databaseConfig.getProperties(),
            ENDPOINT_OVERRIDE,
            getString(
                databaseConfig.getProperties(),
                "scalar.db.dynamo.endpoint-override", // for backward compatibility
                null));
    tableMetadataNamespace =
        getString(databaseConfig.getProperties(), TABLE_METADATA_NAMESPACE, null);
    namespacePrefix = getString(databaseConfig.getProperties(), NAMESPACE_PREFIX, null);
  }

  public String getRegion() {
    return region;
  }

  public String getAccessKeyId() {
    return accessKeyId;
  }

  public String getSecretAccessKey() {
    return secretAccessKey;
  }

  public Optional getEndpointOverride() {
    return Optional.ofNullable(endpointOverride);
  }

  public Optional getTableMetadataNamespace() {
    return Optional.ofNullable(tableMetadataNamespace);
  }

  public Optional getNamespacePrefix() {
    return Optional.ofNullable(namespacePrefix);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy