Skip to content

Commit

Permalink
chore: update scripts to create/delete service resources (#71)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Neilson <[email protected]>
  • Loading branch information
ddneilson authored Oct 30, 2023
1 parent 83df295 commit 6996194
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
49 changes: 32 additions & 17 deletions scripts/create_service_resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ then

echo "Creating Amazon Deadline Cloud Farm $farm_name"
FARM_ID=$(aws deadline create-farm --display-name $farm_name | jq -r ".farmId")
# Wait to reduce race conditions
i=0
while [ $i -le 120 ]; do
echo "Waiting for Farm $FARM_ID to complete setup..."
sleep 5
i=$[$i+5]
done
fi

if [ "${QUEUE_ID_1:-}" == "" ]
Expand All @@ -54,7 +47,13 @@ then
{
"farmId": "$FARM_ID",
"displayName": "$queue_name",
"status": "ACTIVE",
"status": "IDLE",
"jobRunAsUser": {
"posix": {
"user": "",
"group": ""
}
},
"jobAttachmentSettings": {
"s3BucketName": "${assets_s3_bucket}",
"rootPrefix": "assets/"
Expand All @@ -66,8 +65,14 @@ EOF
{
"farmId": "$FARM_ID",
"displayName": "$queue_name",
"status": "ACTIVE",
"status": "IDLE",
"roleArn": "$queue_1_iam_role",
"jobRunAsUser": {
"posix": {
"user": "",
"group": ""
}
},
"jobAttachmentSettings": {
"s3BucketName": "${assets_s3_bucket}",
"rootPrefix": "assets/"
Expand All @@ -81,7 +86,7 @@ EOF
rm create-queue-config.json

ready=""
while [[ $ready != "ACTIVE" ]] && [[ $ready != "SCHEDULING" ]]; do
while [[ $ready != "IDLE" ]] && [[ $ready != "SCHEDULING" ]]; do
sleep 5
ready=$(aws deadline get-queue --farm-id $FARM_ID --queue-id $QUEUE_ID_1 | jq -r ".status")
echo "Queue $QUEUE_ID_1 in $ready status..."
Expand All @@ -105,7 +110,13 @@ then
{
"farmId": "$FARM_ID",
"displayName": "$queue_name",
"status": "ACTIVE",
"status": "IDLE",
"jobRunAsUser": {
"posix": {
"user": "",
"group": ""
}
},
"jobAttachmentSettings": {
"s3BucketName": "${assets_s3_bucket}",
"rootPrefix": "assets/"
Expand All @@ -117,8 +128,14 @@ EOF
{
"farmId": "$FARM_ID",
"displayName": "$queue_name",
"status": "ACTIVE",
"status": "IDLE",
"roleArn": "$queue_2_iam_role",
"jobRunAsUser": {
"posix": {
"user": "",
"group": ""
}
},
"jobAttachmentSettings": {
"s3BucketName": "${assets_s3_bucket}",
"rootPrefix": "assets/"
Expand All @@ -132,7 +149,7 @@ EOF
rm create-queue-config.json

ready=""
while [[ $ready != "ACTIVE" ]] && [[ $ready != "SCHEDULING" ]]; do
while [[ $ready != "IDLE" ]] && [[ $ready != "SCHEDULING" ]]; do
sleep 5
ready=$(aws deadline get-queue --farm-id $FARM_ID --queue-id $QUEUE_ID_2 | jq -r ".status")
echo "Queue $QUEUE_ID_2 in $ready status..."
Expand All @@ -155,12 +172,10 @@ then
"farmId": "$FARM_ID",
"displayName": "$fleet_name",
"roleArn": "$worker_iam_role",
"maxWorkerCount": 5,
"configuration": {
"customerManaged": {
"autoScalingConfiguration": {
"mode": "NO_SCALING",
"maxFleetSize": 5
},
"mode": "NO_SCALING",
"workerRequirements": {
"vCpuCount": {
"min": 1
Expand Down
27 changes: 18 additions & 9 deletions scripts/delete_service_resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,35 @@
# The complement to create_service_resources.sh
# This deletes the service resources created by that script

set -xeuo pipefail
set -euo pipefail

[ -f $(pwd)/.deployed_resources.sh ] && source $(pwd)/.deployed_resources.sh

delete_qfa() {
farm_id=$1
fleet_id=$2
queue_id=$3

aws deadline update-queue-fleet-association --farm-id $farm_id --fleet-id $fleet_id --queue-id $queue_id --status STOP_SCHEDULING_AND_CANCEL_TASKS
status=""
while [[ $status != "STOPPED" ]]; do
sleep 5
status=$(aws deadline get-queue-fleet-association --farm-id $farm_id --fleet-id $fleet_id --queue-id $queue_id | jq -r ".status")
echo "Queue $QUEUE_ID_1 in $status status... waiting for STOPPED status"
done
aws deadline delete-queue-fleet-association --farm-id $farm_id --fleet-id $fleet_id --queue-id $queue_id
}

if [ "${FLEET_ID:-}" != "" ] && [ "${QUEUE_ID_1:-}" != "" ];
then
aws deadline update-queue-fleet-association --farm-id $FARM_ID --fleet-id $FLEET_ID --queue-id $QUEUE_ID_1 --status CANCEL_WORK
sleep 30
aws deadline delete-queue-fleet-association --farm-id $FARM_ID --fleet-id $FLEET_ID --queue-id $QUEUE_ID_1
delete_qfa $FARM_ID $FLEET_ID $QUEUE_ID_1
fi

if [ "${FLEET_ID:-}" != "" ] && [ "${QUEUE_ID_2:-}" != "" ];
then
aws deadline update-queue-fleet-association --farm-id $FARM_ID --fleet-id $FLEET_ID --queue-id $QUEUE_ID_2 --status CANCEL_WORK
sleep 30
aws deadline delete-queue-fleet-association --farm-id $FARM_ID --fleet-id $FLEET_ID --queue-id $QUEUE_ID_2
delete_qfa $FARM_ID $FLEET_ID $QUEUE_ID_2
fi

sleep 30

if [ "${FLEET_ID:-}" != "" ];
then
aws deadline delete-fleet --farm-id $FARM_ID --fleet-id $FLEET_ID
Expand Down

0 comments on commit 6996194

Please sign in to comment.