Skip to content

Commit

Permalink
Enhance registering spec image assets for initMultiCloud
Browse files Browse the repository at this point in the history
  • Loading branch information
cb-github-robot authored Apr 5, 2024
2 parents 02596a6 + 005f835 commit 28d0647
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 186 deletions.
34 changes: 32 additions & 2 deletions scripts/initMultiCloudEnv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $CBTUMBLEBUG_ROOT/src/testclient/scripts/2.configureTumblebug/create-ns.sh -x ns

echo -e "${BOLD}"
while true; do
echo "Loading common Specs and Images takes more than 10 minutes."
echo "Loading common Specs and Images takes around 10 minutes."
read -p 'Load common Specs and Images. Do you want to proceed ? (y/n) : ' CHECKPROCEED
echo -e "${NC}"
case $CHECKPROCEED in
Expand All @@ -36,8 +36,37 @@ done
# Start time
start_time=$(date +%s)


# Execute the load-common-resource script and capture its output
output="$("$CBTUMBLEBUG_ROOT"/src/testclient/scripts/2.configureTumblebug/load-common-resource.sh -n tb)"
EXPECTED_DURATION=480 # 8 minutes
progress_time=$(date +%s)

"$CBTUMBLEBUG_ROOT"/src/testclient/scripts/2.configureTumblebug/load-common-resource.sh -n tb > initTmp.out &
PID=$!

progress=0
printf " ["
printf "%-100s" "-" | tr " " "-"
printf "] %d%% " $progress

while kill -0 $PID 2> /dev/null; do

current_time=$(date +%s)
elapsed=$((current_time - progress_time))
progress=$((elapsed * 100 / EXPECTED_DURATION))
#progress=$((progress>100?100:progress))

printf "\r ["
printf "%-${progress}s" "#" | tr " " "#"
printf "%-$((100-progress))s" "-" | tr " " "-"
printf "] %d%% " $progress

sleep 1

done

output=$(<initTmp.out)
rm initTmp.out

# End time
end_time=$(date +%s)
Expand Down Expand Up @@ -68,6 +97,7 @@ while IFS= read -r line; do
done <<< "$output"

# Optionally, display failed items
echo ""
echo "Failed items:"
echo "$output" | grep "\[Failed\]" | while read line; do
echo "$line" | awk -F" " '{printf "%-50s %-10s\n", $1, $2}'
Expand Down
4 changes: 2 additions & 2 deletions src/core/common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ func ExecuteHttpRequest[B any, T any](

// Check if result is nil
if result == nil {
log.Debug().Msg("Fesult is nil, not caching")
log.Trace().Msg("Fesult is nil, not caching")
} else {
clientCache.Store(requestKey, CacheItem[T]{Response: *result, ExpiresAt: time.Now().Add(cacheDuration)})
log.Debug().Msg("Cached successfully!")
log.Trace().Msg("Cached successfully!")
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/core/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package common

import (
"database/sql"
"sync"
"time"

cbstore "github.com/cloud-barista/cb-store"
Expand All @@ -30,6 +31,14 @@ type KeyValue struct {

type IdList struct {
IdList []string `json:"output"`
mux sync.Mutex
}

// AddItem adds a new item to the IdList
func (list *IdList) AddItem(id string) {
list.mux.Lock()
defer list.mux.Unlock()
list.IdList = append(list.IdList, id)
}

// OptionalParameter is struct for optional parameter for function (ex. VmId)
Expand Down
Loading

0 comments on commit 28d0647

Please sign in to comment.