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/08/21 15:25:54 UTC
[GitHub] dewrich closed pull request #2707: cdn-in-a-box: redo initial data
loading from dir structure
dewrich closed pull request #2707: cdn-in-a-box: redo initial data loading from dir structure
URL: https://github.com/apache/trafficcontrol/pull/2707
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 06371641a..0b19e4326 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile
+++ b/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile
@@ -80,7 +80,7 @@ ADD traffic_ops/run.sh \
traffic_ops/config.sh \
traffic_ops/adduser.pl \
traffic_ops/to-access.sh \
- trafficops-init.sh \
+ traffic_ops/trafficops-init.sh \
/
ADD traffic_ops_data /traffic_ops_data
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-go b/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-go
index 5acf20c13..edd47b2f0 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-go
+++ b/infrastructure/cdn-in-a-box/traffic_ops/Dockerfile-go
@@ -33,11 +33,5 @@ WORKDIR /opt/traffic_ops/app
ADD traffic_ops/config.sh \
traffic_ops/run-go.sh \
- traffic_ops/setup.sh \
- traffic_ops/cdns.json \
- traffic_ops/deliveryservices.json \
- traffic_ops/mid_cachegroup.json \
- traffic_ops/edge_cachegroup.json \
- traffic_ops/phys_location.json \
/
CMD /run-go.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 27ce0c757..821c062d0 100755
--- a/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/run-go.sh
@@ -57,19 +57,9 @@ while ! nc trafficops-perl 60443 </dev/null 2>/dev/null; do
done
cd /opt/traffic_ops/app
-ls -l bin
+
CDNCONF=/opt/traffic_ops/app/conf/cdn.conf
DBCONF=/opt/traffic_ops/app/conf/production/database.conf
mkdir -p /var/log/traffic_ops
-touch /var/log/traffic_ops.log
-./bin/traffic_ops_golang -cfg $CDNCONF -dbcfg $DBCONF >>/var/log/traffic_ops.log 2>>/var/log/traffic_ops.log &
-
-while ! nc localhost 6443 </dev/null; do
- echo "waiting for traffic_ops_golang:6443"
- sleep 3
-done
-
-/setup.sh
-
-cat /var/log/traffic_ops/*
-exec tail -f /var/log/traffic_ops.log
+touch /var/log/traffic_ops/traffic_ops.log
+./bin/traffic_ops_golang -cfg $CDNCONF -dbcfg $DBCONF
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/setup.sh b/infrastructure/cdn-in-a-box/traffic_ops/setup.sh
deleted file mode 100755
index b465ee153..000000000
--- a/infrastructure/cdn-in-a-box/traffic_ops/setup.sh
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/bash
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-set -x
-set -e
-
-# First, we need to authenticate
-curl -skc cookie.jar -d "{\"u\":\"$TO_ADMIN_USER\",\"p\":\"$TO_ADMIN_PASSWORD\"}" https://localhost:$TO_PORT/api/1.3/user/login
-echo
-# Now set up a new CDN...
-curl -skb cookie.jar -d @/cdns.json https://localhost:$TO_PORT/api/1.3/cdns
-echo
-#... and a delivery service
-curl -skb cookie.jar -d @/deliveryservices.json https://localhost:$TO_PORT/api/1.3/deliveryservices
-echo
-#... and two cachegroup
-MID_LOC_ID=$(curl -skb cookie.jar https://localhost:$TO_PORT/api/1.3/types | jq '.response|.[]|select(.name=="MID_LOC")|.id')
-EDGE_LOC_ID=$(curl -skb cookie.jar https://localhost:$TO_PORT/api/1.3/types | jq '.response|.[]|select(.name=="EDGE_LOC")|.id')
-
-
-sed -ie "s/MID_LOC_ID/${MID_LOC_ID}/g" /mid_cachegroup.json
-sed -ie "s/EDGE_LOC_ID/${EDGE_LOC_ID}/g" /edge_cachegroup.json
-curl -skb cookie.jar -d @/mid_cachegroup.json https://localhost:$TO_PORT/api/1.3/cachegroups
-echo
-curl -skb cookie.jar -d @/edge_cachegroup.json https://localhost:$TO_PORT/api/1.3/cachegroups
-echo
-#... and a division
-curl -skb cookie.jar -d '{"name":"CDN_in_a_Box"}' https://localhost:$TO_PORT/api/1.3/divisions
-echo
-#... and a region
-curl -skb cookie.jar -d '{"name":"CDN_in_a_Box"}' https://localhost:$TO_PORT/api/1.3/divisions/CDN_in_a_Box/regions
-echo
-#... and a physical location
-curl -skb cookie.jar -d @/phys_location.json https://localhost:$TO_PORT/api/1.3/regions/CDN_in_a_Box/phys_locations
-echo
-
-
-#cleanup at exit
-rm cookie.jar
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 6c2f87776..be91d10ff 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/to-access.sh
@@ -21,7 +21,7 @@
export TO_URL TO_ADMIN_USER TO_ADMIN_PASSWORD
-export CURLOPTS=${CURLOPTS:--L}
+export CURLOPTS=${CURLOPTS:--LfsS}
export CURLAUTH=${CURLAUTH:--k}
export COOKIEJAR=$(mktemp -t XXXX.cookie)
@@ -71,12 +71,12 @@ CREDS
to-ping() {
# ping endpoint does not require authentication
- curl $CURLAUTH $CURLOPTS -s -X GET "$TO_URL/api/1.3/ping"
+ curl $CURLAUTH $CURLOPTS -X GET "$TO_URL/api/1.3/ping"
}
to-get() {
to-auth && \
- curl $CURLAUTH $CURLOPTS -s --cookie "$COOKIEJAR" -X GET "$TO_URL/$1"
+ curl $CURLAUTH $CURLOPTS --cookie "$COOKIEJAR" -X GET "$TO_URL/$1"
}
to-post() {
@@ -88,7 +88,7 @@ to-post() {
data="--data $2"
fi
to-auth && \
- curl $CURLAUTH $CURLOPTS -s --cookie "$COOKIEJAR" -X POST $data "$TO_URL/$1"
+ curl $CURLAUTH $CURLOPTS --cookie "$COOKIEJAR" -X POST $data "$TO_URL/$1"
}
to-put() {
@@ -100,10 +100,10 @@ to-put() {
data="--data $2"
fi
to-auth && \
- curl $CURLAUTH $CURLOPTS -s --cookie "$COOKIEJAR" -X PUT $data "$TO_URL/$1"
+ curl $CURLAUTH $CURLOPTS --cookie "$COOKIEJAR" -X PUT $data "$TO_URL/$1"
}
to-delete() {
to-auth && \
- curl $CURLAUTH $CURLOPTS -s --cookie "$COOKIEJAR" -X DELETE "$TO_URL/$1"
+ curl $CURLAUTH $CURLOPTS --cookie "$COOKIEJAR" -X DELETE "$TO_URL/$1"
}
diff --git a/infrastructure/cdn-in-a-box/trafficops-init.sh b/infrastructure/cdn-in-a-box/traffic_ops/trafficops-init.sh
similarity index 87%
rename from infrastructure/cdn-in-a-box/trafficops-init.sh
rename to infrastructure/cdn-in-a-box/traffic_ops/trafficops-init.sh
index 89eeedd93..ee241c021 100755
--- a/infrastructure/cdn-in-a-box/trafficops-init.sh
+++ b/infrastructure/cdn-in-a-box/traffic_ops/trafficops-init.sh
@@ -36,7 +36,7 @@ while ! to-get api/1.3/ping 2>/dev/null; do
done
# NOTE: order dependent on foreign key references, e.g. tenants must be defined before users
-endpoints="tenants users cdns servers"
+endpoints="cdns divisions regions phys_locations tenants users cachegroups deliveryservices"
load_data_from() {
local dir="$1"
@@ -52,10 +52,18 @@ load_data_from() {
[[ -r $f ]] || continue
t=$(mktemp --tmpdir $ep-XXX.json)
envsubst <"$f" >"$t"
- to-post api/1.3/"$ep" "$t"
+ if ! to-post api/1.3/"$ep" "$t"; then
+ echo POST api/1.3/"$ep" "$t" failed
+ status=$?
+ fi
rm "$t"
done
done
+ if [ $status -ne 0 ]; then
+ exit $status
+ fi
+
+
}
# First, load required data at the top level
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/edge_cachegroup.json b/infrastructure/cdn-in-a-box/traffic_ops_data/cachegroups/edge_cachegroup.json
similarity index 82%
rename from infrastructure/cdn-in-a-box/traffic_ops/edge_cachegroup.json
rename to infrastructure/cdn-in-a-box/traffic_ops_data/cachegroups/edge_cachegroup.json
index efc18c42b..3f0b0ce7d 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops/edge_cachegroup.json
+++ b/infrastructure/cdn-in-a-box/traffic_ops_data/cachegroups/edge_cachegroup.json
@@ -3,5 +3,5 @@
"shortName": "ciabEdge",
"latitude": 38.897663,
"longitude": -77.036574,
-"typeId": EDGE_LOC_ID
+"typeId": 23
}
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/mid_cachegroup.json b/infrastructure/cdn-in-a-box/traffic_ops_data/cachegroups/mid_cachegroup.json
similarity index 83%
rename from infrastructure/cdn-in-a-box/traffic_ops/mid_cachegroup.json
rename to infrastructure/cdn-in-a-box/traffic_ops_data/cachegroups/mid_cachegroup.json
index 26f6c56c9..00c9e8406 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops/mid_cachegroup.json
+++ b/infrastructure/cdn-in-a-box/traffic_ops_data/cachegroups/mid_cachegroup.json
@@ -3,5 +3,5 @@
"shortName": "ciabMid",
"latitude": 38.897663,
"longitude": -77.036574,
-"typeId": MID_LOC_ID
+"typeId": 24
}
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/cdns.json b/infrastructure/cdn-in-a-box/traffic_ops_data/cdns/cdns.json
similarity index 100%
rename from infrastructure/cdn-in-a-box/traffic_ops/cdns.json
rename to infrastructure/cdn-in-a-box/traffic_ops_data/cdns/cdns.json
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/deliveryservices.json b/infrastructure/cdn-in-a-box/traffic_ops_data/deliveryservices/deliveryservices.json
similarity index 100%
rename from infrastructure/cdn-in-a-box/traffic_ops/deliveryservices.json
rename to infrastructure/cdn-in-a-box/traffic_ops_data/deliveryservices/deliveryservices.json
diff --git a/infrastructure/cdn-in-a-box/traffic_ops_data/divisions/north.json b/infrastructure/cdn-in-a-box/traffic_ops_data/divisions/north.json
new file mode 100644
index 000000000..b13855cfe
--- /dev/null
+++ b/infrastructure/cdn-in-a-box/traffic_ops_data/divisions/north.json
@@ -0,0 +1,3 @@
+{
+ "name": "Quebec"
+}
diff --git a/infrastructure/cdn-in-a-box/traffic_ops_data/divisions/usa.json b/infrastructure/cdn-in-a-box/traffic_ops_data/divisions/usa.json
new file mode 100644
index 000000000..4a6c163a5
--- /dev/null
+++ b/infrastructure/cdn-in-a-box/traffic_ops_data/divisions/usa.json
@@ -0,0 +1,3 @@
+{
+ "name": "U.S.A"
+}
diff --git a/infrastructure/cdn-in-a-box/traffic_ops_data/phys_locations/apachecon.json b/infrastructure/cdn-in-a-box/traffic_ops_data/phys_locations/apachecon.json
new file mode 100644
index 000000000..23ea3408c
--- /dev/null
+++ b/infrastructure/cdn-in-a-box/traffic_ops_data/phys_locations/apachecon.json
@@ -0,0 +1,9 @@
+{
+ "name": "Apachecon North America 2018",
+ "shortName": "Apachecon",
+ "address": " 1050 de la Gauchetiere West",
+ "city": "Montreal QC",
+ "state": "Canada",
+ "zip": "H3B 4C9",
+ "regionId": 2
+}
diff --git a/infrastructure/cdn-in-a-box/traffic_ops/phys_location.json b/infrastructure/cdn-in-a-box/traffic_ops_data/phys_locations/phys_location.json
similarity index 80%
rename from infrastructure/cdn-in-a-box/traffic_ops/phys_location.json
rename to infrastructure/cdn-in-a-box/traffic_ops_data/phys_locations/phys_location.json
index 94b168f4c..ffa588047 100644
--- a/infrastructure/cdn-in-a-box/traffic_ops/phys_location.json
+++ b/infrastructure/cdn-in-a-box/traffic_ops_data/phys_locations/phys_location.json
@@ -4,5 +4,6 @@
"address": "1600 Pennsylvania Avenue NW",
"city": "Washington",
"state": "D.C.",
- "zip": "20500"
+ "zip": "20500",
+ "regionId": 1
}
diff --git a/infrastructure/cdn-in-a-box/traffic_ops_data/regions/dc.json b/infrastructure/cdn-in-a-box/traffic_ops_data/regions/dc.json
new file mode 100644
index 000000000..850d6cbaa
--- /dev/null
+++ b/infrastructure/cdn-in-a-box/traffic_ops_data/regions/dc.json
@@ -0,0 +1,4 @@
+{
+ "division": 2,
+ "name": "Washington, D.C"
+}
diff --git a/infrastructure/cdn-in-a-box/traffic_ops_data/regions/montreal.json b/infrastructure/cdn-in-a-box/traffic_ops_data/regions/montreal.json
new file mode 100644
index 000000000..e28638182
--- /dev/null
+++ b/infrastructure/cdn-in-a-box/traffic_ops_data/regions/montreal.json
@@ -0,0 +1,4 @@
+{
+ "division": 1,
+ "name": "Montreal"
+}
----------------------------------------------------------------
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