Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright © 2017 AT&T Intellectual Property. |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
| 17 | # |
| 18 | # ECOMP is a trademark and service mark of AT&T Intellectual Property. |
| 19 | |
| 20 | source ${SCRIPTS}/common_functions.sh |
| 21 | |
| 22 | NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt) |
| 23 | NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt) |
| 24 | NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt) |
| 25 | DOCKER_IMAGE_VERSION=$(cat /opt/config/docker_version.txt) |
| 26 | DOCKER_REGISTRY=${NEXUS_DOCKER_REPO} |
Venkata Harish K Kajur | f1ffdbc | 2017-12-12 22:58:54 -0500 | [diff] [blame] | 27 | DOCKER_IMAGE_VERSION=1.2-STAGING-latest |
Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 28 | |
Venkata Harish K Kajur | 3918ac5 | 2018-03-14 10:05:27 -0400 | [diff] [blame] | 29 | export CURRENT_PWD=$(pwd); |
| 30 | |
Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 31 | function wait_for_container() { |
| 32 | |
| 33 | CONTAINER_NAME="$1"; |
| 34 | START_TEXT="$2"; |
| 35 | |
Singhsumalee, Pete (ps2418) | 56bb06b | 2017-09-25 14:13:15 -0500 | [diff] [blame] | 36 | TIMEOUT=360 |
Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 37 | |
| 38 | # wait for the real startup |
| 39 | AMOUNT_STARTUP=$(docker logs ${CONTAINER_NAME} 2>&1 | grep "$START_TEXT" | wc -l) |
| 40 | while [[ ${AMOUNT_STARTUP} -ne 1 ]]; |
| 41 | do |
| 42 | echo "Waiting for '$CONTAINER_NAME' deployment to finish ..." |
| 43 | AMOUNT_STARTUP=$(docker logs ${CONTAINER_NAME} 2>&1 | grep "$START_TEXT" | wc -l) |
| 44 | if [ "$TIMEOUT" = "0" ]; |
| 45 | then |
Venkata Harish K Kajur | cbcc00c | 2017-09-09 20:30:04 -0400 | [diff] [blame] | 46 | docker logs ${CONTAINER_NAME}; |
Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 47 | echo "ERROR: $CONTAINER_NAME deployment failed." |
| 48 | exit 1 |
| 49 | fi |
| 50 | let TIMEOUT-=1 |
| 51 | sleep 1 |
| 52 | done |
| 53 | } |
| 54 | |
| 55 | DOCKER_COMPOSE_CMD="docker-compose"; |
| 56 | export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1); |
| 57 | export DOCKER_REGISTRY="nexus3.onap.org:10001"; |
Venkata Harish K Kajur | cbcc00c | 2017-09-09 20:30:04 -0400 | [diff] [blame] | 58 | export AAI_HAPROXY_IMAGE="${AAI_HAPROXY_IMAGE:-aaionap/haproxy}"; |
Venkata Harish K Kajur | f1ffdbc | 2017-12-12 22:58:54 -0500 | [diff] [blame] | 59 | export HAPROXY_VERSION="${HAPROXY_VERSION:-1.2.0}"; |
Venkata Harish K Kajur | d6f0c1e | 2017-09-27 10:42:28 -0400 | [diff] [blame] | 60 | export HBASE_IMAGE="${HBASE_IMAGE:-aaionap/hbase}"; |
| 61 | export HBASE_VERSION="${HBASE_VERSION:-1.2.0}"; |
| 62 | |
| 63 | docker pull ${HBASE_IMAGE}:${HBASE_VERSION}; |
Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 64 | |
Singhsumalee, Pete (ps2418) | 56bb06b | 2017-09-25 14:13:15 -0500 | [diff] [blame] | 65 | docker pull ${HBASE_IMAGE}:${HBASE_VERSION}; |
Venkata Harish K Kajur | f1ffdbc | 2017-12-12 22:58:54 -0500 | [diff] [blame] | 66 | docker pull ${DOCKER_REGISTRY}/onap/aai-resources:${DOCKER_IMAGE_VERSION}; |
| 67 | docker tag ${DOCKER_REGISTRY}/onap/aai-resources:${DOCKER_IMAGE_VERSION} ${DOCKER_REGISTRY}/onap/aai-resources:latest; |
Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 68 | |
Venkata Harish K Kajur | f1ffdbc | 2017-12-12 22:58:54 -0500 | [diff] [blame] | 69 | docker pull ${DOCKER_REGISTRY}/onap/aai-traversal:${DOCKER_IMAGE_VERSION}; |
| 70 | docker tag ${DOCKER_REGISTRY}/onap/aai-traversal:${DOCKER_IMAGE_VERSION} ${DOCKER_REGISTRY}/onap/aai-traversal:latest; |
Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 71 | |
| 72 | ${DOCKER_COMPOSE_CMD} stop |
| 73 | ${DOCKER_COMPOSE_CMD} rm -f -v |
| 74 | |
| 75 | # Start the hbase where the data will be stored |
Kajur, Harish (vk250x) | fe33585 | 2018-03-29 07:11:11 -0400 | [diff] [blame] | 76 | CASSANDRA_CONTAINER_NAME=$(${DOCKER_COMPOSE_CMD} up -d aai.hbase.simpledemo.onap.org 2>&1 | grep 'Creating' | grep -v 'volume' | grep -v 'network' | awk '{ print $2; }' | head -1); |
| 77 | wait_for_container $CASSANDRA_CONTAINER_NAME 'Listening for thrift clients'; |
Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 78 | |
Singhsumalee, Pete (ps2418) | 56bb06b | 2017-09-25 14:13:15 -0500 | [diff] [blame] | 79 | USER_EXISTS=$(check_if_user_exists aaiadmin); |
Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 80 | |
Singhsumalee, Pete (ps2418) | 56bb06b | 2017-09-25 14:13:15 -0500 | [diff] [blame] | 81 | function check_if_user_exists(){ |
| 82 | local user_id=$1; |
Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 83 | |
Singhsumalee, Pete (ps2418) | 56bb06b | 2017-09-25 14:13:15 -0500 | [diff] [blame] | 84 | if [ -z "$user_id" ]; then |
| 85 | echo "Needs to provide at least one argument for check_if_user_exists func"; |
| 86 | exit 1; |
| 87 | fi; |
Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 88 | |
Singhsumalee, Pete (ps2418) | 56bb06b | 2017-09-25 14:13:15 -0500 | [diff] [blame] | 89 | id -u ${user_id} > /dev/null 2>&1 && { |
| 90 | echo "1"; |
| 91 | } || { |
| 92 | echo "0"; |
| 93 | } |
Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 94 | } |
| 95 | |
Singhsumalee, Pete (ps2418) | 56bb06b | 2017-09-25 14:13:15 -0500 | [diff] [blame] | 96 | |
| 97 | if [ "${USER_EXISTS}" -eq 0 ]; then |
| 98 | export USER_ID=9000; |
| 99 | else |
| 100 | export USER_ID=$(id -u aaiadmin); |
| 101 | fi; |
| 102 | |
Kajur, Harish (vk250x) | fe33585 | 2018-03-29 07:11:11 -0400 | [diff] [blame] | 103 | $DOCKER_COMPOSE_CMD run --rm aai-resources.api.simpledemo.onap.org createDBSchema.sh |
| 104 | |
Venkata Harish K Kajur | f1ffdbc | 2017-12-12 22:58:54 -0500 | [diff] [blame] | 105 | RESOURCES_CONTAINER_NAME=$(${DOCKER_COMPOSE_CMD} up -d aai-resources.api.simpledemo.onap.org 2>&1 | grep 'Creating' | grep -v 'volume' | grep -v 'network' | awk '{ print $2; }' | head -1); |
Venkata Harish K Kajur | 3918ac5 | 2018-03-14 10:05:27 -0400 | [diff] [blame] | 106 | wait_for_container $RESOURCES_CONTAINER_NAME 'Resources Microservice Started'; |
Singhsumalee, Pete (ps2418) | 56bb06b | 2017-09-25 14:13:15 -0500 | [diff] [blame] | 107 | |
| 108 | docker logs ${RESOURCES_CONTAINER_NAME}; |
| 109 | |
Venkata Harish K Kajur | f1ffdbc | 2017-12-12 22:58:54 -0500 | [diff] [blame] | 110 | ${DOCKER_COMPOSE_CMD} up -d aai-traversal.api.simpledemo.onap.org aai.api.simpledemo.onap.org |
Singhsumalee, Pete (ps2418) | 56bb06b | 2017-09-25 14:13:15 -0500 | [diff] [blame] | 111 | echo "A&AI Microservices, resources and traversal, are up and running along with HAProxy"; |
Venkata Harish K Kajur | 96f120c | 2017-09-07 22:09:25 -0400 | [diff] [blame] | 112 | # Set the host ip for robot from the haproxy |
Venkata Harish K Kajur | cbcc00c | 2017-09-09 20:30:04 -0400 | [diff] [blame] | 113 | ROBOT_VARIABLES="-v HOST_IP:`ip addr show docker0 | head -3 | tail -1 | cut -d' ' -f6 | cut -d'/' -f1`" |