Skip to content
Open
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
f10d837
update discovery and mapping documentation
jainrocks Aug 6, 2025
e5cfd06
update discovery and mapping documentation
jainrocks Aug 6, 2025
bb90ef8
update discovery and mapping documentation
jainrocks Aug 6, 2025
954a485
update discovery and mapping documentation
jainrocks Aug 6, 2025
8ccdc7f
documentation changes
jainrocks Aug 6, 2025
0f113e5
documentation changes
jainrocks Aug 6, 2025
7d70341
update discovery and mapping documentation
jainrocks Aug 6, 2025
b8aa290
changes for documentation
jainrocks Aug 6, 2025
61dff24
changes for documentation
jainrocks Aug 6, 2025
c7fdbf5
changes for documentation
jainrocks Aug 6, 2025
1817747
Merge branch 'faucetsdn:master' into master
jainrocks Aug 12, 2025
397f2ca
Sequencer test for updating transitional state
jainrocks Aug 13, 2025
cd45896
changes in writeback sequence
jainrocks Aug 13, 2025
545962f
Sequencer test for updating transitional state
jainrocks Aug 13, 2025
58c24dd
Sequencer test for updating transitional state
jainrocks Aug 15, 2025
2ebe717
Sequencer test for updating transitional state
jainrocks Aug 15, 2025
66cdee0
Sequencer test for updating transitional state
jainrocks Aug 16, 2025
5120a8d
Sequencer test for updating transitional state
jainrocks Aug 17, 2025
036c44e
sequencer changes
jainrocks Aug 17, 2025
d438a13
sequencer changes
jainrocks Aug 17, 2025
3c3accc
Merge branch 'master' of github.com:jainrocks/udmi
jainrocks Aug 17, 2025
f111bfa
Sequencer test for updating transitional state
jainrocks Aug 17, 2025
9763401
Sequencer test for updating transitional state
jainrocks Aug 17, 2025
7651530
Sequencer test for updating transitional state
jainrocks Aug 17, 2025
52e8f8a
sequencer changes
jainrocks Aug 20, 2025
455e667
Sequencer test for updating transitional state
jainrocks Aug 20, 2025
38d873f
sequencer changes
jainrocks Aug 20, 2025
f6769c1
Sequencer test for updating transitional state
jainrocks Aug 20, 2025
4730cea
Sequencer test for updating transitional state
jainrocks Aug 21, 2025
a07b2a9
Sequencer test for updating transitional state
jainrocks Aug 21, 2025
98386b9
Sequencer test for updating transitional state
jainrocks Aug 21, 2025
2f58d60
sequencer changes
jainrocks Aug 21, 2025
965eb10
Sequencer test for updating transitional state
jainrocks Aug 21, 2025
e6cbb48
sequencer changes
jainrocks Aug 21, 2025
a259336
Merge branch 'master' of github.com:jainrocks/udmi
jainrocks Aug 21, 2025
54ec570
sequencer changes
jainrocks Aug 21, 2025
fa54d67
sequencer changes
jainrocks Aug 21, 2025
340c59f
sequencer changes
jainrocks Aug 23, 2025
56b19fc
sequencer changes
jainrocks Aug 23, 2025
f06413f
sequencer changes
jainrocks Aug 23, 2025
651b939
Trying to fix itemized tests
jainrocks Aug 24, 2025
c6e3bdb
Trying to fix itemized test for system_last_update
jainrocks Aug 24, 2025
69c4c11
increasing time for checking the set value during the writeback success
jainrocks Aug 24, 2025
ab05976
fixing test_mosquitto step in UDMIS local setup
jainrocks Aug 24, 2025
d6ec35c
fixing test_mosquitto step in UDMIS local setup, updating the options…
jainrocks Aug 24, 2025
6c1e51c
addressing review comments
jainrocks Aug 25, 2025
9e9b4b1
adding out files
jainrocks Aug 25, 2025
9e7e3ab
Testing updates and tweaks (#3)
grafnu Aug 26, 2025
ba49f74
avoiding updating state with intermediate state every time
jainrocks Aug 26, 2025
8270d43
fixing checkstyleMain error
jainrocks Aug 26, 2025
37caa4f
fixing checkstyleMain error
jainrocks Aug 26, 2025
53df7ae
config change detection (#4)
grafnu Aug 27, 2025
7ffdfe1
Merge remote-tracking branch 'upstream/master'
jainrocks Aug 27, 2025
2473296
addressing review comments
jainrocks Aug 27, 2025
b43e99e
addressing review comments
jainrocks Aug 27, 2025
9b077ee
addressing review comments
jainrocks Aug 27, 2025
bb3539f
adding fastWrite in test_mosquitto as it is failing most of the times
jainrocks Aug 28, 2025
99ef254
Use timeout instead of fastWrite (#5)
grafnu Aug 28, 2025
e910900
increasing timeout in bin/test_mosquitto
jainrocks Aug 28, 2025
4b180e3
trying checking the older implementation
jainrocks Aug 28, 2025
98e7b7a
trying checking the older implementation
jainrocks Aug 28, 2025
378ee26
trying checking the older implementation
jainrocks Aug 28, 2025
8e53e83
cleanup ofn intermediate state method changes
jainrocks Aug 29, 2025
5babcf4
uodating itemized out
jainrocks Aug 29, 2025
e4ff0eb
Merge branch 'faucetsdn:master' into master
jainrocks Aug 30, 2025
2bb785b
Merge branch 'master' of github.com:jainrocks/udmi
jainrocks Sep 13, 2025
643072e
adding the script for importing num ids
jainrocks Sep 15, 2025
d2f5fc8
adding the script for importing num ids
jainrocks Sep 15, 2025
a52c0b2
updated the script for importing num ids
jainrocks Sep 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions bin/import_site_num_ids
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#!/bin/bash -e

# This script automates the process of updating num_ids for a list of site models
# as requested in b/435662022 and incorporating review comments from PR #1186.

# --- Script Usage ---
# The script now accepts project_spec and the list of site models as command-line arguments.
#
# Usage:
# ./import_site_num_ids <project_spec> <site_model_1> <site_model_2> ...
#
# Example:
# ./import_site_num_ids //gbos/bos-platform-prod US-SVL-BRGUP1 US-SVL-OTHER

SITE_MODELS=()

UDMI_ROOT=$(dirname $0)/..
cd $UDMI_ROOT

# ==============================================================================

if [ "$#" -lt 2 ]; then
echo "Usage: $0 <project_spec> <site_model_1> <site_model_2> ..."
echo "Example: $0 //gbos/bos-platform-prod US-SVL-BRGUP1"
exit 1
fi

project_spec=$1
shift # Removes the first argument, so the rest are site models
SITE_MODELS=("$@") # Assigns the remaining arguments to the SITE_MODELS array

# Get the gcloud email address.
GCLOUD_EMAIL=$(gcloud config get-value account 2>/dev/null)

if [ -z "$GCLOUD_EMAIL" ]; then
echo "Error: Could not get gcloud email address."
echo "Please make sure you are authenticated with gcloud ('gcloud auth login')."
exit 1
fi

echo "Using gcloud email: $GCLOUD_EMAIL"

# Validate the project_spec format and extract the project ID.
# The project ID is expected to be the component after "//gbos/".
if [[ ! "$project_spec" =~ ^//gbos/ ]]; then
echo "Error: project_spec must start with //gbos/"
exit 1
fi

# Extracts the part like 'bos-platform-prod' or 'bos-platform-dev'
project_id=$(echo "$project_spec" | cut -d'/' -f4)

if [ -z "$project_id" ]; then
echo "Error: Could not extract project ID from project_spec '$project_spec'."
echo "Ensure it has at least one component after //gbos/ (e.g., //gbos/project-id)."
exit 1
fi

echo "Using Project ID: $project_id"
echo "Processing site models: ${SITE_MODELS[@]}"

# Check if the SITE_MODELS array is empty.
if [ ${#SITE_MODELS[@]} -eq 0 ]; then
echo "Please provide site models for which num_ids to be imported."
exit 1
fi

# Loop through each site model provided in the array.
for site_model in "${SITE_MODELS[@]}"; do
echo "-----------------------------------------------------"
echo "Processing site model: $site_model"
echo "-----------------------------------------------------"

SITE_PATH="$UDMI_ROOT/sites/$site_model"

# Prepare a clean directory for the site model.
if [ -d "$SITE_PATH/.git" ]; then
echo "Repository exists. Cleaning and pulling latest changes."
(
cd "$SITE_PATH" || exit
git reset --hard origin/main
git clean -fdx
git pull origin main
git checkout main
)
else
echo "Repository not found. Cloning a new one."
rm -rf "$SITE_PATH"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's not found then there's no reason to remove it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that the rm is redundant if the directory doesn't exist at all.

But, I've kept it in as a safeguard for the case where the path might exist but isn't a git repo (e.g., from a previous failed run). This ensures git clone always has a clean target.

GIT_CLONE_URL="ssh://${GCLOUD_EMAIL}@source.developers.google.com:2022/p/${project_id}/r/${site_model}"
git clone "$GIT_CLONE_URL" "$SITE_PATH"
fi

DEVICES_PATH="$SITE_PATH/udmi/devices"

if [ ! -d "$DEVICES_PATH" ]; then
echo " WARNING: Devices directory not found at '$DEVICES_PATH'. Skipping device-level operations."
continue
fi

# Step A: Normalize metadata.json files in the devices directory.
echo "Normalizing metadata for $site_model..."
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a separate script for normalizing metadata? Normalizing might introduce a lot of changes and the diff might become difficult to review. Normalizing as a separate step will increase the confidence in review when adding the actual num ids

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normalization stuff is already captured in a separate commit, so at last the churn will be compartmentalized. I'm not sure what the overall intended flow here is b/c I'm not sure what actual "review" we'd do on a 100 site models (I'm actually not even sure what they are).

Do we have a clearly identified "recipient" for this (is it Vik?), and maybe get them to sign off on what the review flow needs to be?

From a technical perspective I think having them split as separate commits is fine, because then they could be reviewed separately.

OTOH, another reason to split out the script would be that there might be other times when we want to normalize a site model. I just hate the thought of replicating all the common code (extracting site models)... and wouldn't want this "simple thing" to balloon into a bigger mess!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, Vik is the recipient for the same, will check with him and get sign off on review flow.

(
cd "$DEVICES_PATH" || exit
for device in */; do
device_name=${device%/}
if [ -f "$device_name/metadata.json" ]; then
echo " Normalizing $device_name/metadata.json"
jq -S . "$device_name/metadata.json" | sponge "$device_name/metadata.json"
fi
done
)

# --- Commit ---
echo "Committing normalized files for $site_model..."
(
cd "$SITE_PATH" || exit
git add .
git commit -m "Normalize metadata for $site_model"
)

# Step B: Run the registrar utility to update from IoT Core.
echo "Running registrar for $site_model..."
"$UDMI_ROOT/bin/registrar" "$SITE_PATH/udmi" "$project_spec" -u

# Step C: Update the num_id in metadata.json from the registrar's output.
echo "Updating num_id for $site_model..."
(
cd "$DEVICES_PATH" || exit
for device in */; do
device_name=${device%/}
echo " Updating num_id for $device_name"
if [ -f "$device_name/out/metadata_norm.json" ]; then
id=$(jq .cloud.num_id "$device_name/out/metadata_norm.json")
jq -S ".cloud.num_id = $id" "$device_name/metadata.json" | sponge "$device_name/metadata.json"
else
echo " WARNING: metadata_norm.json not found for $device_name. Skipping num_id update."
fi
done
)

# Step D: Commit and Push the num_id changes to git for Review.
echo "Committing and pushing num_id changes for $site_model..."
(
cd "$SITE_PATH" || exit
git add .
git commit -m "Import num_ids for site model $site_model"
)

# Push the main branch to the remote repository
echo "Pushing changes to main branch"
(
cd "$SITE_PATH" || exit
git push origin main
)


echo "Done processing $site_model."
done

echo "====================================================="
echo "All site models processed."
echo "====================================================="