This repository was archived by the owner on Feb 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrecreateQueryServiceNamespace.sh
More file actions
executable file
·49 lines (36 loc) · 2.2 KB
/
Copy pathrecreateQueryServiceNamespace.sh
File metadata and controls
executable file
·49 lines (36 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# https://phabricator.wikimedia.org/T306693
set -eux
WIKI_DOMAIN=$1
NEW_PLATFORM_FREE_DOMAIN_SUFFIX=$2
case $NEW_PLATFORM_FREE_DOMAIN_SUFFIX in
"wikibase.dev")
CONTEXT="gke_wikibase-cloud_europe-west3-a_wbaas-2"
;;
"wikibase.cloud")
CONTEXT="gke_wikibase-cloud_europe-west3-a_wbaas-3"
;;
*)
echo "You must supply wikibase.dev or wikibase.cloud as the second argument"
exit 1
;;
esac
DETAILS_FILE=recreateQS-$WIKI_DOMAIN-details.json
REMOTE_RWSTORE_PROPERTIES_FILE=/tmp/recreateQS-$WIKI_DOMAIN-post.data
CLOUD_KUBECTL="kubectl --context=$CONTEXT"
API_POD=$($CLOUD_KUBECTL get pods --field-selector='status.phase=Running' -l app.kubernetes.io/name=api,app.kubernetes.io/component=queue -o jsonpath="{.items[0].metadata.name}")
$CLOUD_KUBECTL exec $API_POD -- sh -c "php artisan wbs-wiki:get domain $WIKI_DOMAIN" > ./$DETAILS_FILE
$CLOUD_KUBECTL exec $API_POD -- sh -c "cp app/data/RWStore.properties ${REMOTE_RWSTORE_PROPERTIES_FILE}"
WIKI_DETAILS="$(cat ./$DETAILS_FILE)"
WIKI_QS_BACKEND=$(echo $WIKI_DETAILS | jq -r '.wiki_queryservice_namespace.backend')
WIKI_QS_NAMESPACE=$(echo $WIKI_DETAILS | jq -r '.wiki_queryservice_namespace.namespace')
$CLOUD_KUBECTL exec $API_POD -- sh -c "sed -i 's/REPLACE_NAMESPACE/${WIKI_QS_NAMESPACE}/' ${REMOTE_RWSTORE_PROPERTIES_FILE}"
# Delete Query Service Namespace
# https://github.com/wbstack/api/blob/main/app/Jobs/DeleteQueryserviceNamespaceJob.php#L59
CURL_DELETE_QS="curl -s --http1.1 --user-agent 'wikibase.cloud migration recreateQueryServiceNamespace.sh' --request 'DELETE' --header 'content-type: text/plain' --url '${WIKI_QS_BACKEND}/bigdata/namespace/${WIKI_QS_NAMESPACE}'"
$CLOUD_KUBECTL exec $API_POD -- sh -c "$CURL_DELETE_QS"
# Recreate Query Service Namespace
# https://github.com/wbstack/api/blob/main/app/Jobs/ProvisionQueryserviceNamespaceJob.php#L65
CURL_CREATE_QS="curl -s --http1.1 --user-agent 'wikibase.cloud migration recreateQueryServiceNamespace.sh' --request 'POST' --header 'content-type: text/plain' --data-binary @$REMOTE_RWSTORE_PROPERTIES_FILE --url '${WIKI_QS_BACKEND}/bigdata/namespace'"
$CLOUD_KUBECTL exec $API_POD -- sh -c "$CURL_CREATE_QS"
$CLOUD_KUBECTL exec $API_POD -- sh -c "rm $REMOTE_RWSTORE_PROPERTIES_FILE"