-
-
Notifications
You must be signed in to change notification settings - Fork 26
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 #929 from openzim/upgrade_receiver_workers
Upgrade receiver and workers
- Loading branch information
Showing
25 changed files
with
403 additions
and
234 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/bin/bash | ||
|
||
# Call it once to create a `test_worker`: | ||
# - retrieve an admin token | ||
# - create the `test_worker`` user | ||
# - create the associated worker object | ||
# - upload a test public key. | ||
# | ||
# To be used to have a "real" test worker for local development, typically to start | ||
# a worker manager or a task manager or simply assign tasks to a worker in the UI/API | ||
|
||
set -e | ||
|
||
echo "Retrieving admin access token" | ||
|
||
ZF_ADMIN_TOKEN="$(curl -s -X 'POST' \ | ||
'http://localhost:8000/v1/auth/authorize' \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/x-www-form-urlencoded' \ | ||
-d 'username=admin&password=admin' \ | ||
| jq -r '.access_token')" | ||
|
||
echo "Create test_worker user" | ||
|
||
curl -s -X 'POST' \ | ||
'http://localhost:8000/v1/users/' \ | ||
-H 'accept: */*' \ | ||
-H 'Content-Type: application/json' \ | ||
-H "Authorization: Bearer $ZF_ADMIN_TOKEN" \ | ||
-d '{ | ||
"role":"worker", | ||
"username": "test_worker", | ||
"email":"[email protected]", | ||
"password":"test_worker" | ||
}' | ||
|
||
echo "Retrieving test_worker access token" | ||
|
||
ZF_USER_TOKEN="$(curl -s -X 'POST' \ | ||
'http://localhost:8000/v1/auth/authorize' \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/x-www-form-urlencoded' \ | ||
-d 'username=test_worker&password=test_worker' \ | ||
| jq -r '.access_token')" | ||
|
||
echo "Worker check-in (will create it since missing)" | ||
|
||
curl -s -X 'PUT' \ | ||
'http://localhost:8000/v1/workers/test_worker/check-in' \ | ||
-H 'accept: */*' \ | ||
-H 'Content-Type: application/json' \ | ||
-H "Authorization: Bearer $ZF_USER_TOKEN" \ | ||
-d '{ | ||
"username": "test_worker", | ||
"cpu": 3, | ||
"memory": 1024, | ||
"disk": 0, | ||
"offliners": [ | ||
"zimit" | ||
] | ||
}' | ||
|
||
echo "Add private key to test_worker" | ||
|
||
curl -X POST http://localhost:8000/v1/users/test_worker/keys \ | ||
-H 'accept: */*' \ | ||
-H "Authorization: Bearer $ZF_USER_TOKEN" \ | ||
-H 'Content-Type: application/json; charset=utf-8' \ | ||
-d '{"name": "test_key", "key": "AAAAB3NzaC1yc2EAAAADAQABAAABAQCn2r5IZSJp02FBAYSZBQRdOBKBK2VOErdrBCZm5Ig3hDKQuxq38+W5CJ2JUJU+LQm//uenm58scGlEtk5+w5SjObjzK8Qx6JeRhAiZ8xpyydSoUIvd0ARD9OKwdiQFqVlLPlOyrdIpQ2vRESdwzhe0f7EYUwgKzBw5k0foxQsGxTiztY/ugWJ8Jso5WOxXwzEw4cSnGhdrehqLphlZanr54wj5oTcrj/vJHlpbxkYzFMc2Zgj81GdIV4yP3H1yX4ySK8VkDPOCczHacdRnHw4u8Vgf6wS6Zy3iMpvuGu7BJkwNoTXvmVV5BXUm6GAMSQTAPcw5T8M+eXjSAnriGDAL"}' | ||
|
||
echo "DONE" |
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,40 @@ | ||
#!/bin/bash | ||
|
||
# Call as many times as necessary to transition the first (oldest) requested task in the | ||
# database into a reserved task, assigned to the `test_worker` worker. | ||
# | ||
# Displays the whole task JSON. | ||
|
||
set -e | ||
|
||
echo "Retrieving access token" | ||
|
||
ZF_ADMIN_TOKEN="$(curl -s -X 'POST' \ | ||
'http://localhost:8000/v1/auth/authorize' \ | ||
-H 'accept: application/json' \ | ||
-H 'Content-Type: application/x-www-form-urlencoded' \ | ||
-d 'username=admin&password=admin' \ | ||
| jq -r '.access_token')" | ||
|
||
echo "Get last requested task" | ||
|
||
FIRST_TASK_ID="$(curl -s -X 'GET' \ | ||
'http://localhost:8000/v1/requested-tasks/' \ | ||
-H 'accept: application/json' \ | ||
-H "Authorization: Bearer $ZF_ADMIN_TOKEN" \ | ||
| jq -r '.items[0]._id')" | ||
|
||
if [ "$FIRST_TASK_ID" = "null" ]; then | ||
echo "No pending requested task. Exiting script." | ||
exit 1 | ||
fi | ||
|
||
echo "Start task (i.e. mark it as started)" | ||
|
||
curl -s -X 'POST' \ | ||
"http://localhost:8000/v1/tasks/$FIRST_TASK_ID?worker_name=worker" \ | ||
-H 'accept: application/json' \ | ||
-H "Authorization: Bearer $ZF_ADMIN_TOKEN" \ | ||
-d '' | ||
|
||
echo "DONE" |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
mkdir -p \ | ||
/jail/zim/freecodecamp \ | ||
/jail/zim/gutenberg \ | ||
/jail/zim/ifixit \ | ||
/jail/zim/mooc \ | ||
/jail/zim/other \ | ||
/jail/zim/phet \ | ||
/jail/zim/stack_exchange \ | ||
/jail/zim/ted \ | ||
/jail/zim/videos \ | ||
/jail/zim/vikidia \ | ||
/jail/zim/wikibooks \ | ||
/jail/zim/wikihow \ | ||
/jail/zim/wikinews \ | ||
/jail/zim/wikipedia \ | ||
/jail/zim/wikiquote \ | ||
/jail/zim/wikisource \ | ||
/jail/zim/wikiversity \ | ||
/jail/zim/wikivoyage \ | ||
/jail/zim/wiktionary \ | ||
/jail/zim/zimit | ||
|
||
chmod 777 \ | ||
/jail/zim/freecodecamp \ | ||
/jail/zim/gutenberg \ | ||
/jail/zim/ifixit \ | ||
/jail/zim/mooc \ | ||
/jail/zim/other \ | ||
/jail/zim/phet \ | ||
/jail/zim/stack_exchange \ | ||
/jail/zim/ted \ | ||
/jail/zim/videos \ | ||
/jail/zim/vikidia \ | ||
/jail/zim/wikibooks \ | ||
/jail/zim/wikihow \ | ||
/jail/zim/wikinews \ | ||
/jail/zim/wikipedia \ | ||
/jail/zim/wikiquote \ | ||
/jail/zim/wikisource \ | ||
/jail/zim/wikiversity \ | ||
/jail/zim/wikivoyage \ | ||
/jail/zim/wiktionary \ | ||
/jail/zim/zimit |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.