Skip to content

Commit

Permalink
Merge pull request #56 from tonyxrmdavidson/addTestDataScript
Browse files Browse the repository at this point in the history
This commit adds a script that will push data to model-registry-db fo…
  • Loading branch information
tonyxrmdavidson authored Apr 30, 2024
2 parents 5eca863 + 4945e13 commit 1bd60d9
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions test/scripts/populateDatabase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

# This script will push data to model-registry-db. It targets the default model-registry
# To run the script from the root of the repo : ./test/scripts/populateDatabase.sh <number of entries>
# Example : Putting 5 entries into the database : ./test/scripts/populateDatabase.sh 5

LOOPS=$1
MR_HOSTNAME="http://$(oc get route modelregistry-sample-http -n opendatahub --template='{{.spec.host}}')"

# Function to send data and extract ID from response
make_post_extract_id() {
local url="$1"
local data="$2"
local id=$(curl -s -X POST "$url" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d "$data" | jq -r '.id')

if [ -z "$id" ]; then
echo -e "${RED}Error:${NC} Error: Failed to extract ID from response"
exit 1
else
echo "$id"
fi
}

# Function to post model registry data
post_model_registry_data() {
test_data_number=$1
timestamp=$(date +"%Y%m%d%H%M%S")
rm_name="test-data-2-$test_data_number"

rm_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha3/registered_models" '{
"description": "lorem ipsum registered model",
"name": "'"$rm_name"'"
}')

if [ $? -ne 0 ]; then
echo -e "${RED}Error:${NC} Registered Model ID not returned"
exit 1
else
echo -e "${GREEN}✔ Success:${NC} Registered Model ID: $rm_id"
fi

mv_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha3/model_versions" '{
"description": "lorem ipsum model version",
"name": "v1",
"author": "John Doe",
"registeredModelId": "'"$rm_id"'"
}')

if [ $? -ne 0 ]; then
echo -e "${RED}Error:${NC} Model Version ID not returned"
exit 1
else
echo -e "${GREEN}✔ Success:${NC} Model Version ID: $mv_id"
fi

RAW_ML_MODEL_URI='https://huggingface.co/tarilabs/mnist/resolve/v1.nb20231206162408/mnist.onnx'
ma_id=$(make_post_extract_id "$MR_HOSTNAME/api/model_registry/v1alpha3/model_versions/$mv_id/artifacts" '{
"description": "lorem ipsum model artifact",
"uri": "'"$RAW_ML_MODEL_URI"'",
"name": "mnist",
"modelFormatName": "onnx",
"modelFormatVersion": "1",
"storageKey": "aws-connection-unused",
"storagePath": "unused just demo",
"artifactType": "model-artifact"
}')

if [ $? -ne 0 ]; then
echo -e "${RED}Error:${NC} Model Artifact ID not returned"
exit 1
else
echo -e "${GREEN}✔ Success:${NC} Model Artifact ID: $ma_id"
fi
}

# Main function for populating database
main() {
for i in {$(seq 1 $LOOPS)}; do
post_model_registry_data $i
done
}

# Execute main function
main

0 comments on commit 1bd60d9

Please sign in to comment.