Class OcpMongoShardedCluster

java.lang.Object
io.debezium.testing.system.tools.databases.mongodb.sharded.OcpMongoShardedCluster
All Implemented Interfaces:
AutoCloseable, org.testcontainers.lifecycle.Startable

public class OcpMongoShardedCluster extends Object implements org.testcontainers.lifecycle.Startable
Mongo sharded cluster containing config server replica set, one or more shard replica sets and a mongos router
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • replicaCount

      private final int replicaCount
    • configServerCount

      private final int configServerCount
    • rootUserName

      private final String rootUserName
    • rootPassword

      private final String rootPassword
    • useInternalAuth

      private final boolean useInternalAuth
    • ocp

      private final io.fabric8.openshift.client.OpenShiftClient ocp
    • ocpUtils

      private final OpenShiftUtils ocpUtils
    • initialShardCount

      private final int initialShardCount
    • project

      private final String project
    • shardKeys

      private final List<MongoShardKey> shardKeys
    • shardReplicaSets

      private final List<OcpMongoReplicaSet> shardReplicaSets
    • configServerReplicaSet

      private OcpMongoReplicaSet configServerReplicaSet
    • mongosRouter

      private OcpMongoDeploymentManager mongosRouter
    • isRunning

      private boolean isRunning
  • Constructor Details

    • OcpMongoShardedCluster

      public OcpMongoShardedCluster(int initialShardCount, int replicaCount, int configServerCount, @Nullable @Nullable String rootUserName, @Nullable @Nullable String rootPassword, boolean useInternalAuth, io.fabric8.openshift.client.OpenShiftClient ocp, String project, List<MongoShardKey> shardKeys)
  • Method Details

    • start

      public void start()
      Deploy all deployments and services to openshift, initialize replicaSets and sharding, create root user
      Specified by:
      start in interface org.testcontainers.lifecycle.Startable
    • stop

      public void stop()
      Scale all cluster deployments to zero
      Specified by:
      stop in interface org.testcontainers.lifecycle.Startable
    • waitForStopped

      public void waitForStopped()
    • removeShard

      public void removeShard()
      delete last added shard
    • addShard

      public void addShard(@Nullable @Nullable Map<MongoShardKey,ShardKeyRange> rangeMap)
      deploy new shard and initialize it. Requires running initialized sharded mongo cluster
    • getConnectionString

      public String getConnectionString()
      get connection string for mongos router
    • getShardKey

      public MongoShardKey getShardKey(String collection)
    • executeMongoSh

      public OpenShiftUtils.CommandOutputs executeMongoSh(String command)
      execute a mongosh command/script on mongos router
      Parameters:
      command -
      Returns:
      captured outputs of command execution
    • getShardKeys

      public List<MongoShardKey> getShardKeys()
    • getShardReplicaSets

      public List<OcpMongoReplicaSet> getShardReplicaSets()
    • getConfigServerReplicaSet

      public OcpMongoReplicaSet getConfigServerReplicaSet()
    • deployShards

      private void deployShards()
    • deployNewShard

      private OcpMongoReplicaSet deployNewShard(int shardNum)
      deploy new shard, initialize replica set and set authentication if specified
    • registerShardInMongos

      private void registerShardInMongos(@Nullable @Nullable Map<MongoShardKey,ShardKeyRange> rangeMap, OcpMongoReplicaSet rs)
    • deployConfigServers

      private void deployConfigServers()
    • deployMongos

      private void deployMongos()
    • initMongos

      private void initMongos() throws IOException, freemarker.template.TemplateException, InterruptedException
      Throws:
      IOException
      freemarker.template.TemplateException
      InterruptedException
    • addShardKeyRangeCommand

      private String addShardKeyRangeCommand(MongoShardKey key, ShardKeyRange range)
    • addShardAndZoneInMongosCommand

      private String addShardAndZoneInMongosCommand(OcpMongoReplicaSet shardRs)
    • shardCollectionCommand

      private String shardCollectionCommand(MongoShardKey key)
    • createKeyRangeCommand

      private String createKeyRangeCommand(ShardKeyRange range, MongoShardKey key)
    • builder