Venkata Harish K Kajur | d6f0c1e | 2017-09-27 10:42:28 -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} |
| 27 | DOCKER_IMAGE_VERSION=1.1-STAGING-latest |
| 28 | |
| 29 | function wait_for_container() { |
| 30 | |
| 31 | CONTAINER_NAME="$1"; |
| 32 | START_TEXT="$2"; |
| 33 | |
| 34 | TIMEOUT=360 |
| 35 | |
| 36 | # wait for the real startup |
| 37 | AMOUNT_STARTUP=$(docker logs ${CONTAINER_NAME} 2>&1 | grep "$START_TEXT" | wc -l) |
| 38 | while [[ ${AMOUNT_STARTUP} -ne 1 ]]; |
| 39 | do |
| 40 | echo "Waiting for '$CONTAINER_NAME' deployment to finish ..." |
| 41 | AMOUNT_STARTUP=$(docker logs ${CONTAINER_NAME} 2>&1 | grep "$START_TEXT" | wc -l) |
| 42 | if [ "$TIMEOUT" = "0" ]; |
| 43 | then |
| 44 | docker logs ${CONTAINER_NAME}; |
| 45 | echo "ERROR: $CONTAINER_NAME deployment failed." |
| 46 | exit 1 |
| 47 | fi |
| 48 | let TIMEOUT-=1 |
| 49 | sleep 1 |
| 50 | done |
| 51 | } |
| 52 | |
| 53 | DOCKER_COMPOSE_CMD="docker-compose"; |
| 54 | export MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1); |
| 55 | export DOCKER_REGISTRY="nexus3.onap.org:10001"; |
| 56 | export AAI_HAPROXY_IMAGE="${AAI_HAPROXY_IMAGE:-aaionap/haproxy}"; |
| 57 | export HBASE_IMAGE="${HBASE_IMAGE:-aaionap/hbase}"; |
| 58 | export HBASE_VERSION="${HBASE_VERSION:-1.2.0}"; |
| 59 | |
| 60 | docker pull ${HBASE_IMAGE}:${HBASE_VERSION}; |
Singhsumalee, Pete (ps2418) | 56bb06b | 2017-09-25 14:13:15 -0500 | [diff] [blame] | 61 | |
Venkata Harish K Kajur | d6f0c1e | 2017-09-27 10:42:28 -0400 | [diff] [blame] | 62 | docker pull ${DOCKER_REGISTRY}/openecomp/aai-resources:${DOCKER_IMAGE_VERSION}; |
| 63 | docker tag ${DOCKER_REGISTRY}/openecomp/aai-resources:${DOCKER_IMAGE_VERSION} ${DOCKER_REGISTRY}/openecomp/aai-resources:latest; |
| 64 | |
| 65 | docker pull ${DOCKER_REGISTRY}/openecomp/aai-traversal:${DOCKER_IMAGE_VERSION}; |
| 66 | docker tag ${DOCKER_REGISTRY}/openecomp/aai-traversal:${DOCKER_IMAGE_VERSION} ${DOCKER_REGISTRY}/openecomp/aai-traversal:latest; |
| 67 | |
| 68 | ${DOCKER_COMPOSE_CMD} stop |
| 69 | ${DOCKER_COMPOSE_CMD} rm -f -v |
| 70 | |
| 71 | # Start the hbase where the data will be stored |
| 72 | HBASE_CONTAINER_NAME=$(${DOCKER_COMPOSE_CMD} up -d aai.hbase.simpledemo.openecomp.org 2>&1 | grep 'Creating' | grep -v 'volume' | grep -v 'network' | awk '{ print $2; }' | head -1); |
| 73 | wait_for_container ${HBASE_CONTAINER_NAME} ' Started SelectChannelConnector@0.0.0.0:8085'; |
| 74 | wait_for_container ${HBASE_CONTAINER_NAME} ' Started SelectChannelConnector@0.0.0.0:8080'; |
| 75 | wait_for_container ${HBASE_CONTAINER_NAME} ' Started SelectChannelConnector@0.0.0.0:9095'; |
| 76 | |
| 77 | USER_EXISTS=$(check_if_user_exists aaiadmin); |
| 78 | |
| 79 | function check_if_user_exists(){ |
| 80 | local user_id=$1; |
| 81 | |
| 82 | if [ -z "$user_id" ]; then |
| 83 | echo "Needs to provide at least one argument for check_if_user_exists func"; |
| 84 | exit 1; |
| 85 | fi; |
| 86 | |
| 87 | id -u ${user_id} > /dev/null 2>&1 && { |
| 88 | echo "1"; |
| 89 | } || { |
| 90 | echo "0"; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | |
| 95 | if [ "${USER_EXISTS}" -eq 0 ]; then |
| 96 | export USER_ID=9000; |
| 97 | else |
| 98 | export USER_ID=$(id -u aaiadmin); |
| 99 | fi; |
| 100 | |
| 101 | RESOURCES_CONTAINER_NAME=$(${DOCKER_COMPOSE_CMD} up -d aai-resources.api.simpledemo.openecomp.org 2>&1 | grep 'Creating' | grep -v 'volume' | grep -v 'network' | awk '{ print $2; }' | head -1); |
| 102 | wait_for_container ${RESOURCES_CONTAINER_NAME} '0.0.0.0:8447'; |
| 103 | |
| 104 | TRAVERSAL_CONTAINER_NAME=$(${DOCKER_COMPOSE_CMD} up -d aai-traversal.api.simpledemo.openecomp.org 2>&1 | grep 'Creating' | grep -v 'volume' | grep -v 'network' | awk '{ print $2; }' | head -1); |
| 105 | wait_for_container ${TRAVERSAL_CONTAINER_NAME} '0.0.0.0:8446'; |
| 106 | |
| 107 | ${DOCKER_COMPOSE_CMD} up -d aai.api.simpledemo.openecomp.org |
| 108 | echo "A&AI Microservices, resources and traversal, are up and running along with HAProxy"; |
| 109 | # Set the host ip for robot from the haproxy |
| 110 | ROBOT_VARIABLES="-v HOST_IP:`ip addr show docker0 | head -3 | tail -1 | cut -d' ' -f6 | cut -d'/' -f1`" |