forked from kubeflow/model-registry
-
Notifications
You must be signed in to change notification settings - Fork 8
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 #56 from tonyxrmdavidson/addTestDataScript
This commit adds a script that will push data to model-registry-db fo…
- Loading branch information
Showing
1 changed file
with
87 additions
and
0 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
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 |