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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate OcpMongoReplicaSetprivate final intprivate booleanprivate static final org.slf4j.Loggerprivate OcpMongoDeploymentManagerprivate final io.fabric8.openshift.client.OpenShiftClientprivate final OpenShiftUtilsprivate final Stringprivate final intprivate final Stringprivate final Stringprivate final List<MongoShardKey>private final List<OcpMongoReplicaSet>private final boolean -
Constructor Summary
ConstructorsConstructorDescriptionOcpMongoShardedCluster(int initialShardCount, int replicaCount, int configServerCount, @Nullable String rootUserName, @Nullable String rootPassword, boolean useInternalAuth, io.fabric8.openshift.client.OpenShiftClient ocp, String project, List<MongoShardKey> shardKeys) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddShard(@Nullable Map<MongoShardKey, ShardKeyRange> rangeMap) deploy new shard and initialize it.private Stringprivate StringaddShardKeyRangeCommand(MongoShardKey key, ShardKeyRange range) builder()private StringcreateKeyRangeCommand(ShardKeyRange range, MongoShardKey key) private voidprivate voidprivate OcpMongoReplicaSetdeployNewShard(int shardNum) deploy new shard, initialize replica set and set authentication if specifiedprivate voidexecuteMongoSh(String command) execute a mongosh command/script on mongos routerget connection string for mongos routergetShardKey(String collection) private voidprivate voidregisterShardInMongos(@Nullable Map<MongoShardKey, ShardKeyRange> rangeMap, OcpMongoReplicaSet rs) voiddelete last added shardprivate Stringvoidstart()Deploy all deployments and services to openshift, initialize replicaSets and sharding, create root uservoidstop()Scale all cluster deployments to zerovoidMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.testcontainers.lifecycle.Startable
close, getDependencies
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
replicaCount
private final int replicaCount -
configServerCount
private final int configServerCount -
rootUserName
-
rootPassword
-
useInternalAuth
private final boolean useInternalAuth -
ocp
private final io.fabric8.openshift.client.OpenShiftClient ocp -
ocpUtils
-
initialShardCount
private final int initialShardCount -
project
-
shardKeys
-
shardReplicaSets
-
configServerReplicaSet
-
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:
startin interfaceorg.testcontainers.lifecycle.Startable
-
stop
public void stop()Scale all cluster deployments to zero- Specified by:
stopin interfaceorg.testcontainers.lifecycle.Startable
-
waitForStopped
public void waitForStopped() -
removeShard
public void removeShard()delete last added shard -
addShard
deploy new shard and initialize it. Requires running initialized sharded mongo cluster -
getConnectionString
get connection string for mongos router -
getShardKey
-
executeMongoSh
execute a mongosh command/script on mongos router- Parameters:
command-- Returns:
- captured outputs of command execution
-
getShardKeys
-
getShardReplicaSets
-
getConfigServerReplicaSet
-
deployShards
private void deployShards() -
deployNewShard
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:
IOExceptionfreemarker.template.TemplateExceptionInterruptedException
-
addShardKeyRangeCommand
-
addShardAndZoneInMongosCommand
-
shardCollectionCommand
-
createKeyRangeCommand
-
builder
-