@@ -131,7 +131,7 @@ install_layer2_config() {
131131
132132# Function to install BAP Protocol Server
133133install_bap_protocol_server () {
134- # start_support_services # Start MongoDB, RabbitMQ, and Redis services
134+ start_support_services # Start MongoDB, RabbitMQ, and Redis services
135135 # POST containers are started, now update the configuration
136136 if [[ $1 ]]; then
137137 # If parameters are provided, use them to update the configuration
@@ -147,7 +147,6 @@ install_bap_protocol_server() {
147147
148148
149149 sleep 10
150- return
151150
152151 docker volume create bap_client_config_volume
153152 docker volume create bap_network_config_volume
@@ -175,12 +174,12 @@ install_bap_protocol_server() {
175174 # Keep trying API call until we get 200 status
176175 status_code=0
177176 attempt=1
178- max_attempts=5
177+ max_attempts=10
179178
180- while [ $status_code -ne 200 ] && [ $attempt -le $max_attempts ] ; do
181- echo " Attempt $attempt of $max_attempts to verify BAP protocol server..."
179+ while [ $status_code -ne 200 ]; do
180+ echo " Checking BAP protocol server health ..."
182181
183- response=$( curl -s -w " %{http_code}" --location " $bap_subscriber_url /status " \
182+ response=$( curl -s -w " %{http_code}" --location " $bap_subscriber_url /health " \
184183 -H " Content-Type: application/json" )
185184
186185 status_code=" ${response: -3} "
@@ -195,11 +194,7 @@ install_bap_protocol_server() {
195194 fi
196195 done
197196
198- if [ $status_code -ne 200 ]; then
199- echo " ${RED} Failed to verify BAP protocol server after $max_attempts attempts${NC} "
200- exit 1
201- fi
202-
197+
203198
204199 echo " ${BLUE} Registering BAP protocol server on the registry${NC} "
205200 create_network_participant " $registry_url " " application/json" " $bap_subscriber_id " " $bap_subscriber_key_id " " $bap_subscriber_url " " $public_key " " $public_key " " $valid_from " " $valid_until " " $type " " $api_key " " $np_domain "
@@ -210,21 +205,26 @@ install_bap_protocol_server() {
210205
211206# Function to install BPP Protocol Server without Sandbox
212207install_bpp_protocol_server () {
213- start_support_services
208+ start_support_services # Start MongoDB, RabbitMQ, and Redis services
209+ # POST containers are started, now update the configuration
214210 echo " ${GREEN} ................Installing Protocol Server for BPP................${NC} "
215211
216212 if [[ $1 ]]; then
213+ # If parameters are provided, use them to update the configuration
217214 registry_url=$1
218215 bpp_subscriber_id=$2
219216 bpp_subscriber_key_id=$3
220217 bpp_subscriber_url=$4
221- webhook_url=$5
222- bash scripts/update_bpp_config.sh $registry_url $bpp_subscriber_id $bpp_subscriber_key_id $bpp_subscriber_url $webhook_url $api_key $np_domain
218+ webhook_url=$5
219+ source scripts/update_bpp_config.sh $registry_url $bpp_subscriber_id $bpp_subscriber_key_id $bpp_subscriber_url $webhook_url $api_key " $np_domain "
220+
223221 else
224- bash scripts/update_bpp_config.sh
222+ # If no parameters are provided, use the default configuration
223+ source scripts/update_bpp_config.sh
225224 fi
226225
227226 sleep 10
227+
228228 docker volume create bpp_client_config_volume
229229 docker volume create bpp_network_config_volume
230230 docker run --rm -v $SCRIPT_DIR /../protocol-server-data:/source -v bpp_client_config_volume:/target busybox cp /source/bpp-client.yml /target/default.yml
@@ -244,6 +244,33 @@ install_bpp_protocol_server() {
244244 install_layer2_config bpp-client
245245 install_layer2_config bpp-network
246246 fi
247+
248+ # Keep trying API call until we get 200 status
249+ status_code=0
250+ attempt=1
251+ max_attempts=10
252+
253+ while [ $status_code -ne 200 ]; do
254+ echo " Checking BPP protocol server health..."
255+
256+ response=$( curl -s -w " %{http_code}" --location " $bpp_subscriber_url /health" \
257+ -H " Content-Type: application/json" )
258+
259+ status_code=" ${response: -3} "
260+
261+ if [ $status_code -eq 200 ]; then
262+ echo " ${GREEN} BPP protocol server is up and running${NC} "
263+ break
264+ else
265+ echo " ${YELLOW} BPP protocol server not ready yet (status: $status_code ). Retrying in 5 seconds...${NC} "
266+ sleep 5
267+ (( attempt++ ))
268+ fi
269+ done
270+
271+ echo " ${BLUE} Registering BPP protocol server on the registry${NC} "
272+ create_network_participant " $registry_url " " application/json" " $bpp_subscriber_id " " $bpp_subscriber_key_id " " $bpp_subscriber_url " " $public_key " " $public_key " " $valid_from " " $valid_until " " $type " " $api_key " " $np_domain "
273+
247274 echo " Protocol server BPP installation successful"
248275}
249276
@@ -373,7 +400,7 @@ validate_user() {
373400
374401 # Replace '/subscribers' with '/login' for validation
375402 local login_url=" ${registry_url%/ subscribers} /auth/local"
376- echo " login_url: $login_url "
403+
377404
378405 # Validate credentials using a POST request
379406 local response
@@ -387,7 +414,7 @@ validate_user() {
387414 if [ " $status_code " -eq 200 ]; then
388415 response_body=" ${response% ???} "
389416 api_key=$( echo " $response_body " | jq -r ' .jwt' )
390- echo " api_key: $api_key "
417+
391418 return 0
392419 else
393420 response=$( curl -s -w " %{http_code}" --location " $login_url " \
@@ -523,24 +550,30 @@ completeSetup() {
523550 public_address=$bap_subscriber_url
524551
525552 layer2_config
526- # install_package
553+ install_package
527554 install_bap_protocol_server $registry_url $bap_subscriber_id $bap_subscriber_key_id $bap_subscriber_url
528555
529556
530557 ;;
531558 " BPP" )
532- echo " ${GREEN} ................Installing Protocol Server for BPP................${NC} "
533559
560+ # Display installation header
561+ echo " ${GREEN} ................Installing Protocol Server for BPP................${NC} "
562+
563+ # Step 1: Get BPP Subscriber ID
534564 read -p " Enter BPP Subscriber ID: " bpp_subscriber_id
565+
566+ # Step 2: Get and validate BPP Subscriber URL
535567 while true ; do
536568 read -p " Enter BPP Subscriber URL: " bpp_subscriber_url
537569 if [[ $bpp_subscriber_url =~ ^(http| https):// ]]; then
538- break
570+ break # Valid URL format, exit loop
539571 else
540572 echo " ${RED} Invalid URL format. Please enter a valid URL starting with http:// or https://.${NC} "
541573 fi
542574 done
543575
576+ # Step 3: Get and validate Webhook URL
544577 while true ; do
545578 read -p " Enter Webhook URL: " webhook_url
546579 if [[ $webhook_url =~ ^(http| https):// ]]; then
@@ -550,19 +583,23 @@ completeSetup() {
550583 fi
551584 done
552585
586+ # Step 4: Get and validate Registry URL
553587 while true ; do
554588 read -p " Enter the registry URL (e.g., https://registry.becknprotocol.io/subscribers): " registry_url
555- if [[ $registry_url =~ ^(http| https):// ]] && [[ $registry_url == * /subscribers ]] ; then
556- break
589+ if [[ $registry_url =~ ^(http| https):// ]]; then
590+ break # Valid URL format, exit loop
557591 else
558592 echo " ${RED} Please mention /subscribers in your registry URL${NC} "
559593 fi
560594 done
595+
596+ # Step 5: Validate user credentials
561597 validate_user
562598 if [ $? -eq 1 ]; then
563599 exit
564600 fi
565601
602+ # Step 6: Get and validate NP Domain
566603 get_np_domain $bpp_subscriber_id
567604 if [ $? -eq 1 ]; then
568605 exit
0 commit comments