blob: 0580489606aaa4bee81aa7283d159927709015ec [file] [log] [blame]
Victor Morales89ce3212017-06-16 18:32:48 -05001#!/bin/bash
2
3set -o xtrace
4
Victor Moralesdd074802017-07-26 16:06:35 -05005source /var/onap/functions
Victor Moralesdd074802017-07-26 16:06:35 -05006
Victor Moralese7467002017-08-30 14:50:43 -05007sdc_src_folder=$git_src_folder/sdc
Victor Moralesdbe2e0b2017-09-20 09:55:45 -07008sdc_repos=("jtosca" "sdc-distribution-client" "sdc-docker-base" "sdc-titan-cassandra" "sdc-tosca" "sdc-vnfdesign" "sdc-workflow-designer" "sdc_common")
Victor Moralesdd074802017-07-26 16:06:35 -05009
Victor Moralese7467002017-08-30 14:50:43 -050010# _mount_external_partition() - Create partition and mount the external volume
11function _mount_external_partition {
Idan Amitbf1e7f02017-08-20 16:05:46 +030012 cat <<EOL > /tmp/sdc_ext_volume_partitions.txt
Victor Morales89ce3212017-06-16 18:32:48 -050013# partition table of /dev/sdb
14unit: sectors
15
16/dev/sdb1 : start= 2048, size=209713152, Id=83
17/dev/sdb2 : start= 0, size= 0, Id= 0
18/dev/sdb3 : start= 0, size= 0, Id= 0
19/dev/sdb4 : start= 0, size= 0, Id= 0
20EOL
Idan Amitbf1e7f02017-08-20 16:05:46 +030021 sfdisk --force /dev/sdb < /tmp/sdc_ext_volume_partitions.txt
Victor Morales89ce3212017-06-16 18:32:48 -050022 mkfs -t ext4 /dev/sdb1
23 mkdir -p /data
24 mount /dev/sdb1 /data
25 echo "/dev/sdb1 /data ext4 errors=remount-ro,noatime,barrier=0 0 1" >> /etc/fstab
26}
27
Victor Moralese7467002017-08-30 14:50:43 -050028# _init_data_folders() - Function that initialize the data folders
29function _init_data_folders {
Victor Morales89ce3212017-06-16 18:32:48 -050030 mkdir -p /data/environments
31 mkdir -p /data/scripts
32 mkdir -p /data/logs/BE
33 mkdir -p /data/logs/FE
34 chmod 777 /data
Idan Amitc46e98f2017-08-21 17:04:10 +030035 chmod 777 /data/logs
Victor Morales89ce3212017-06-16 18:32:48 -050036}
37
Victor Moralese7467002017-08-30 14:50:43 -050038# _setup_docker_aliases() - Function that setups the aliases required by sdc scripts
39function _setup_docker_aliases {
Victor Morales89ce3212017-06-16 18:32:48 -050040 cat <<EOL > /root/.bash_aliases
41alias dcls='/data/scripts/docker_clean.sh \$1'
42alias dlog='/data/scripts/docker_login.sh \$1'
Idan Amit8e393c32017-09-27 17:55:52 +030043alias drun='/data/scripts/docker_run.sh'
Victor Morales89ce3212017-06-16 18:32:48 -050044alias health='/data/scripts/docker_health.sh'
45EOL
46}
47
Victor Moralesdd074802017-07-26 16:06:35 -050048# clone_all_sdc_repos() - Function that clones SDC source repo.
49function clone_all_sdc_repos {
Victor Moralese7467002017-08-30 14:50:43 -050050 clone_repo sdc $sdc_src_folder
Victor Moralesdd074802017-07-26 16:06:35 -050051
Victor Moralese7467002017-08-30 14:50:43 -050052 for dirc in ${sdc_repos[@]}; do
53 clone_repo sdc/$dirc $sdc_src_folder/$dirc
Victor Moralesdd074802017-07-26 16:06:35 -050054 done
55}
56
57# compile_all_sdc_repos() - Function that compiles SDC source repo.
58function compile_all_sdc_repos {
Victor Morales43906e62017-08-31 16:30:23 -050059 compile_src sdc $sdc_src_folder
Victor Moralesdd074802017-07-26 16:06:35 -050060
Victor Moralese7467002017-08-30 14:50:43 -050061 for dirc in ${sdc_repos[@]}; do
62 compile_src $sdc_src_folder/$dirc
Victor Moralesdd074802017-07-26 16:06:35 -050063 done
64}
65
Victor Moralese7467002017-08-30 14:50:43 -050066# get_sdc_images() - Function that retrieves the SDC docker images
67function get_sdc_images {
68 if [[ "$build_image" == "True" ]]; then
Idan Amit8e393c32017-09-27 17:55:52 +030069 if [[ "$compile_repo" == "True" ]]; then
Victor Moralese7467002017-08-30 14:50:43 -050070 compile_src $sdc_src_folder
71 fi
Victor Moralesdbe2e0b2017-09-20 09:55:45 -070072 build_docker_image $sdc_src_folder/sdc-docker-base
Victor Moralese7467002017-08-30 14:50:43 -050073 else
Idan Amit8e393c32017-09-27 17:55:52 +030074 if [["$pull_docker_image" == True]]; then
75 for image in backend frontend elasticsearch kibana cassandra sanity; do
76 pull_openecomp_image openecomp/sdc-$image
77 done
78 fi
Victor Moralese7467002017-08-30 14:50:43 -050079 fi
80}
81
Victor Morales89ce3212017-06-16 18:32:48 -050082# install_sdc() - Function that pull templates and executes
83function install_sdc {
Victor Morales89ce3212017-06-16 18:32:48 -050084 local ENV_NAME=$dmaap_topic
85 local MR_IP_ADDR='10.0.11.1'
Victor Moralesdd074802017-07-26 16:06:35 -050086
Victor Moralese7467002017-08-30 14:50:43 -050087 _init_data_folders
Idan Amit8e393c32017-09-27 17:55:52 +030088 cp $sdc_src_folder/sdc-os-chef/environments/Template.json /data/environments
89 cp $sdc_src_folder/sdc-os-chef/scripts/docker_run.sh /data/scripts
90 cp $sdc_src_folder/sdc-os-chef/scripts/docker_health.sh /data/scripts
91 cp $sdc_src_folder/sdc-os-chef/scripts/docker_login.sh /data/scripts
92 cp $sdc_src_folder/sdc-os-chef/scripts/docker_clean.sh /data/scripts
93 chmod +x /data/scripts/docker_run.sh
94 chmod +x /data/scripts/docker_health.sh
95 chmod +x /data/scripts/docker_login.sh
96 chmod +x /data/scripts/docker_clean.sh
97
Victor Morales89ce3212017-06-16 18:32:48 -050098 cat /data/environments/Template.json | sed "s/yyy/"$IP_ADDRESS"/g" > /data/environments/$ENV_NAME.json
99 sed -i "s/xxx/"$ENV_NAME"/g" /data/environments/$ENV_NAME.json
100 sed -i "s/\"ueb_url_list\":.*/\"ueb_url_list\": \""$MR_IP_ADDR","$MR_IP_ADDR"\",/g" /data/environments/$ENV_NAME.json
101 sed -i "s/\"fqdn\":.*/\"fqdn\": [\""$MR_IP_ADDR"\", \""$MR_IP_ADDR"\"]/g" /data/environments/$ENV_NAME.json
102
Idan Amit0a295552017-08-17 17:03:59 +0300103 install_docker
104 if [[ "$pull_docker_image" == "True" ]]; then
105 docker_openecomp_login
Victor Moralesdbe2e0b2017-09-20 09:55:45 -0700106 bash /data/scripts/docker_run.sh -e $ENV_NAME -r $docker_version -p $(echo $nexus_docker_repo | cut -d':' -f2)
107 else
108 bash /data/scripts/docker_run.sh -e $ENV_NAME -l
Idan Amit0a295552017-08-17 17:03:59 +0300109 fi
Victor Morales89ce3212017-06-16 18:32:48 -0500110}
111
Idan Amitbf1e7f02017-08-20 16:05:46 +0300112# init_sdc() - Function that initialize SDC services
113function init_sdc {
Victor Moralese7467002017-08-30 14:50:43 -0500114 _mount_external_partition
Idan Amit1690e082017-08-20 08:58:14 +0300115 if [[ "$clone_repo" == "True" ]]; then
116 clone_all_sdc_repos
117 if [[ "$compile_repo" == "True" ]]; then
118 compile_all_sdc_repos
119 fi
120 fi
Victor Moralese7467002017-08-30 14:50:43 -0500121 get_sdc_images
Victor Morales89ce3212017-06-16 18:32:48 -0500122 install_sdc
Victor Moralese7467002017-08-30 14:50:43 -0500123 _setup_docker_aliases
Victor Morales89ce3212017-06-16 18:32:48 -0500124}