Skip to content

Instantly share code, notes, and snippets.

@agup006
Last active May 16, 2022 05:20
Show Gist options
  • Save agup006/b489234139b7c32125936f5727fb1a86 to your computer and use it in GitHub Desktop.
Save agup006/b489234139b7c32125936f5727fb1a86 to your computer and use it in GitHub Desktop.
#!/bin/bash
#curl -X POST http://m3query:7201/api/v1/database/create -d '{
# "type": "local",
# "namespaceName": "default",
# "retentionTime": "12h"
#}'
#sleep 5;
#curl -X POST http://m3query:7201/api/v1/services/m3db/namespace/ready -d '{
# "name": "default"
#}'
# M3 cluster provisioning sequence
ATTEMPTS=50 MAX_TIMEOUT=4 TIMEOUT=1 retry_with_backoff \
'curl -sSf http://m3query/health'
provision_namespace
function provision_namespaces {
# Check if the namespace already exists and skip the provisioning step
set +e
curl -sSf http://m3query:7201/api/v1/services/m3db/namespace | jq --exit-status '.registry.namespaces.default'
[[ $? -eq 0 ]] && return 0
set -e
echo "Initializing namespaces"
curl -sSf -X POST http://m3query:7201/api/v1/services/m3db/namespace -d '{
"name": "default",
"options": {
"bootstrapEnabled": true,
"flushEnabled": true,
"writesToCommitLog": true,
"cleanupEnabled": true,
"snapshotEnabled": true,
"repairEnabled": false,
"retentionOptions": {
"retentionPeriodDuration": "48h",
"blockSizeDuration": "2h",
"bufferFutureDuration": "10m",
"bufferPastDuration": "10m",
"blockDataExpiry": true,
"blockDataExpiryAfterNotAccessPeriodDuration": "5m"
},
"indexOptions": {
"enabled": true,
"blockSizeDuration": "2h"
}
}
}'
echo "Done initializing namespaces"
echo "Validating namespace"
[ "$(curl -sSf -X GET http://m3query:7201/api/v1/services/m3db/namespace | jq .registry.namespaces.default.indexOptions.enabled)" == true ]
echo "Done validating namespace"
echo "Waiting for namespaces to be ready"
[ $(curl -sSf -X POST http://m3query:7201/api/v1/services/m3db/namespace/ready -d "{ \"name\": \"default\", \"force\": true }" | grep -c true) -eq 1 ]
echo "Done waiting for namespaces to be ready"
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment