You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2018/12/05 22:29:54 UTC

[GitHub] mitchell852 closed pull request #3082: CIAB: fix race issue where server not avail when server assignment done

mitchell852 closed pull request #3082: CIAB: fix race issue where server not avail when server assignment done
URL: https://github.com/apache/trafficcontrol/pull/3082
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile b/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile
index e38add614..0c9ec0762 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile
+++ b/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile
@@ -36,7 +36,8 @@ RUN yum install -y epel-release && \
         perl-Crypt-ScryptKDF \
         perl-Test-CPAN-Meta \
         perl-JSON-PP \
-        git && \
+        git \
+        jq && \
     yum-config-manager --add-repo 'http://vault.centos.org/7.5.1804/os/x86_64/' && \
     yum -y install --enablerepo=vault* golang-1.9.4 && \
     yum -y clean all
@@ -86,4 +87,5 @@ ADD enroller/server_template.json \
 
 ADD traffic_ops_data /traffic_ops_data
 
+RUN chown -R trafops:trafops /opt/traffic_ops
 CMD /run.sh
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh b/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh
index 374ab44a1..1aa8094c0 100755
--- a/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh
@@ -75,23 +75,6 @@ TO_USER=$TO_ADMIN_USER TO_PASSWORD=$TO_ADMIN_PASSWORD to-enroll $(hostname -s) &
 
 to-enroll "to" ALL || (while true; do echo "enroll failed."; sleep 3 ; done)
 
-### Workaround: Start DeliveryService and Edge association
-while true; do
-  edge_name="$(to-get 'api/1.3/servers/hostname/edge/details' 2>/dev/null | jq -r -c '.response|.hostName')"
-  ds_name="$(to-get 'api/1.3/deliveryservices' 2>/dev/null | jq -r -c '.response[].xmlId')"
-
-  if [ -n "$edge_name" ] && [ "$ds_name" ] ; then
-    tmp_file=$(mktemp)
-    echo "{ \"xmlId\" : \"$ds_name\", \"serverNames\": [ \"$edge_name\" ] }" > $tmp_file
-    cp $tmp_file /shared/enroller/deliveryservice_servers/
-    break
-  else 
-    echo "Waiting for delivery service and edge to exist..."
-  fi
-
-  sleep 2
-done
-
 while true; do
   echo "Verifying that edge was associated to delivery service..."
 
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh b/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh
index 712ff5a6b..21fa5fcea 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh
@@ -142,12 +142,6 @@ to-enroll() {
 		sleep 2
 	done
 
-	while true; do
-		[ "$serverType" = "to" ] && break
-		[ -f "$ENROLLER_DIR/initial-load-done" ] && break
-		echo "Waiting for traffic-ops to do initial load ..."
-		sleep 2
-	done
 	if [[ ! -d ${ENROLLER_DIR}/servers ]]; then
 		echo "${ENROLLER_DIR}/servers not found -- contents:"
 		find ${ENROLLER_DIR} -ls
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/trafficops-init.sh b/infrastructure/cdn-in-a-box/traffic_ops/trafficops-init.sh
index e72838cc1..d41790d54 100755
--- a/infrastructure/cdn-in-a-box/traffic_ops/trafficops-init.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/trafficops-init.sh
@@ -39,6 +39,38 @@ done
 endpoints="cdns types divisions regions phys_locations tenants users cachegroups deliveryservices profiles parameters servers deliveryservice_servers"
 vars=$(awk -F = '/^\w/ {printf "$%s ",$1}' /variables.env)
 
+waitfor() {
+    local endpoint="$1"
+    local field="$2"
+    local value="$3"
+
+    while true; do
+        v=$(to-get "api/1.4/$endpoint?$field=$value" | jq -r --arg field "$field" '.response[][$field]')
+        if [[ $v == $value ]]; then
+            break
+        fi
+        echo "waiting for $endpoint $field=$value"
+        sleep 3
+    done
+}
+
+# special cases -- any data type requiring specific data to already be available in TO should have an entry here.
+# e,g. deliveryservice_servers requires both deliveryservice and all servers to be available
+delayfor() {
+    local f="$1"
+    local d="${f%/*}"
+
+    case $d in
+        deliveryservice_servers)
+            ds=$( jq -r .xmlId <"$f" )
+            waitfor deliveryservices xmlId "$ds"
+            for s in $( jq -r .serverNames[] <"$f" ); do
+                waitfor servers hostName "$s"
+            done
+            ;;
+    esac
+}
+
 load_data_from() {
     local dir="$1"
     if [[ ! -d $dir ]] ; then
@@ -50,6 +82,7 @@ load_data_from() {
         [[ -d $d ]] || continue
         for f in "$d"/*.json; do 
             echo "Loading $f"
+            delayfor "$f"
             envsubst "$vars" <$f  > "$ENROLLER_DIR"/$f
         done
     done


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services