-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from unumotors/cli-config-file
cli integration of replicaset and moveto config file
- Loading branch information
Showing
9 changed files
with
579 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,30 @@ | ||
#!/usr/bin/env node | ||
const yargs = require('yargs') | ||
const fs = require('fs') | ||
const yaml = require('js-yaml') | ||
const replication = require('./lib/cli/replication') | ||
|
||
// This seems required to parse | ||
// eslint-disable-next-line no-unused-vars | ||
const { argv } = yargs | ||
.command(replication) | ||
.demandCommand() | ||
.help() | ||
// Disable wrapping | ||
.wrap(null) | ||
.epilog('Hail Hydra\ncopyright 2020 unu GmbH') | ||
async function main() { | ||
// eslint-disable-next-line no-unused-vars | ||
const { argv } = await yargs | ||
.usage('Usage: $0 -c <configfile>') | ||
// Loads the configuration | ||
.config('f', 'Configuration file', (filename) => { | ||
const file = fs.existsSync(filename) ? filename : 'hydra.yaml' | ||
return yaml.safeLoad(fs.readFileSync(file, 'utf8')) | ||
}) | ||
.command(replication) | ||
.demandCommand() | ||
.help() | ||
// Disable wrapping | ||
.wrap(null) | ||
.epilog('Hail Hydra\ncopyright 2020 unu GmbH') | ||
} | ||
|
||
try { | ||
main() | ||
} catch (e) { | ||
console.log(e) | ||
throw e | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Replication Example | ||
|
||
This example shows off how to use mongo-hydra to configure replication with a basic 3 node replica set | ||
|
||
## Requirements | ||
|
||
* Docker | ||
* Docker compose | ||
* node >= 10 | ||
* npm | ||
|
||
### Steps | ||
|
||
1. Start instances `docker-compose up` | ||
2. Run hydra `hydra replication -f hydra.yaml` | ||
|
||
You now have a 3 node mongo replica set! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
version: '3.8' | ||
services: | ||
mongo-rs-0: | ||
image: "mongo:${MONGO_VERSION:-4.2}" | ||
command: | ||
- '--replSet' | ||
- 'mongo-rs' | ||
- '--port' | ||
- '27000' | ||
ports: | ||
- "27000:27000" | ||
mongo-rs-1: | ||
image: "mongo:${MONGO_VERSION:-4.2}" | ||
command: | ||
- '--replSet' | ||
- 'mongo-rs' | ||
- '--port' | ||
- '27001' | ||
ports: | ||
- "27001:27001" | ||
mongo-rs-2: | ||
image: "mongo:${MONGO_VERSION:-4.2}" | ||
command: | ||
- '--replSet' | ||
- 'mongo-rs' | ||
- '--port' | ||
- '27002' | ||
ports: | ||
- "27002:27002" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Define a replica set | ||
# to support multiple replica sets use multiple config files | ||
replicaSet: | ||
# Replica set name | ||
replicaSetName: mongo-rs | ||
# The servers that should be part of this replica set | ||
# host: The host mongo internally uses to name and connect to these | ||
# uri: the URI that hydra uses to connect and configure (can be a mapping/port-forwarding/public URI) | ||
servers: | ||
- host: mongo-rs-0:27000 | ||
uri: mongodb://localhost:27000 | ||
- host: mongo-rs-1:27001 | ||
uri: mongodb://localhost:27001 | ||
- host: mongo-rs-2:27002 | ||
uri: mongodb://localhost:27002 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
exports.command = 'replication [-r=mongo-1:27017]' | ||
const { ReplicaSetState, REPLICA_SET_STATUS } = require('../core/state/replication') | ||
const logger = require('../helpers/logger') | ||
|
||
exports.command = 'replication' | ||
|
||
exports.describe = 'Sets up replication against a basic replica set' | ||
|
||
exports.builder = { | ||
replica: { | ||
alias: 'r' | ||
} | ||
} | ||
|
||
exports.handler = (argv) => { | ||
console.log(argv) | ||
exports.handler = async (argv) => { | ||
logger.debug('Setting up replication') | ||
const { replicaSet } = argv | ||
const state = new ReplicaSetState(replicaSet) | ||
await state.apply() | ||
|
||
await state.disconnect() | ||
if (state.replicaSetStatus === REPLICA_SET_STATUS.HEALTHY) { | ||
logger.info('+ ReplicaSet status is healthy') | ||
} else { | ||
logger.warn('- ReplicaSet status not healthy') | ||
// this will cause an exit code | ||
throw new Error(`ReplicaSet not healthy. Has state ${state.replicaSetStatus}`) | ||
} | ||
} |
Oops, something went wrong.