blob: 7d87870a0ad6fe67a6310cc7349e69d6f61481ef [file] [log] [blame]
Victor Morales89ce3212017-06-16 18:32:48 -05001#!/bin/bash
2
3set -o xtrace
4
5source /var/onap/functions
6
7hbase_version=1.2.3
Victor Morales8e08c872017-08-21 16:15:57 -05008aai_src_folder=$git_src_folder/aai
Victor Morales158c18c2017-08-06 11:23:15 -05009aai_repos=("aai-common" "aai-config" "aai-data" "aai-service" "data-router" "logging-service" "model-loader" "resources" "rest-client" "router-core" "search-data-service" "test-config" "traversal" "sparky-fe" "sparky-be")
Victor Morales455bece2017-07-31 18:40:39 -050010
11# install_hadoop() - Function that installs Hadoop
12function install_hadoop {
13 local release=titan
14 local version=1.0.0
15 local filename=$release-$version-hadoop1
16 local dest_folder=/opt/hadoop/current
17
18 if [ ! -d $dest_folder ]; then
19 curl http://s3.thinkaurelius.com/downloads/$release/$filename.zip -o /tmp/${filename}.zip
20 install_package unzip
21 mkdir -p $dest_folder
22 unzip /tmp/${filename}.zip -d $dest_folder
23 pushd $dest_folder/${filename}
Victor Morales158c18c2017-08-06 11:23:15 -050024 # Change commitlog_directory and data_file_directories values (https://stackoverflow.com/a/26856246/1707651)
25 sed -i "s|db/cassandra/data|/tmp/data|g" conf/cassandra/cassandra.yaml
26 sed -i "s|db/cassandra/commitlog|/tmp/commitlog|g" conf/cassandra/cassandra.yaml
27
28 install_java
Victor Morales455bece2017-07-31 18:40:39 -050029 ./bin/titan.sh start
30 popd
31 fi
32}
33
34# install_haproxy() - Function that install HAProxy
35function install_haproxy {
Victor Morales7ae05a42017-08-22 14:39:00 -050036 if is_package_installed haproxy; then
37 return
38 fi
39 install_package software-properties-common
40 add-apt-repository -y ppa:vbernat/haproxy-1.7
Victor Morales455bece2017-07-31 18:40:39 -050041 install_package haproxy
Victor Morales7ae05a42017-08-22 14:39:00 -050042 cp /var/onap/files/haproxy.cfg /etc/haproxy/
Victor Morales455bece2017-07-31 18:40:39 -050043 cp /var/onap/files/aai.pem /etc/ssl/private/
44 chmod 640 /etc/ssl/private/aai.pem
45 chown root:ssl-cert /etc/ssl/private/aai.pem
46 mkdir /usr/local/etc/haproxy
Victor Morales7ae05a42017-08-22 14:39:00 -050047 #echo "127.0.0.1 localhost aai-traversal.api.simpledemo.openecomp.org aai-resources.api.simpledemo.openecomp.org" >> /etc/hosts
Victor Morales455bece2017-07-31 18:40:39 -050048
49 service haproxy restart
50}
Victor Morales89ce3212017-06-16 18:32:48 -050051
Victor Moralesdd074802017-07-26 16:06:35 -050052# clone_all_aai_repos() - Function that clones AAI source repo.
53function clone_all_aai_repos {
Victor Morales455bece2017-07-31 18:40:39 -050054 for dirc in ${aai_repos[@]}; do
Victor Morales8e08c872017-08-21 16:15:57 -050055 clone_repo aai/$dirc $aai_src_folder/$dirc
Victor Moralesdd074802017-07-26 16:06:35 -050056 done
57}
58
Victor Morales455bece2017-07-31 18:40:39 -050059# compile_aai_repos() - Function that compiles AAI source repo.
60function compile_aai_repos {
61 local repos=("aai-common" "resources" "logging-service" "traversal")
62 if [[ "$compile_repo" == "True" ]]; then
Victor Morales158c18c2017-08-06 11:23:15 -050063 repos=("${aai_repos[@]}")
Victor Morales455bece2017-07-31 18:40:39 -050064 fi
Victor Moralesdd074802017-07-26 16:06:35 -050065
Victor Morales455bece2017-07-31 18:40:39 -050066 for dirc in ${repos[@]}; do
Victor Morales8e08c872017-08-21 16:15:57 -050067 compile_src $aai_src_folder/$dirc
Victor Moralesdd074802017-07-26 16:06:35 -050068 done
69}
70
Victor Morales455bece2017-07-31 18:40:39 -050071# setup_titan() - Function that configures AAI services to connect to Hadoop Titan
72function setup_titan {
Victor Morales7ae05a42017-08-22 14:39:00 -050073 local subdirectory="bundleconfig-local/etc/appprops"
Victor Morales455bece2017-07-31 18:40:39 -050074 install_python_package crudini
75
Victor Morales7ae05a42017-08-22 14:39:00 -050076 for dirc in resources/aai-resources traversal/aai-traversal; do
Victor Morales455bece2017-07-31 18:40:39 -050077 for file in titan-cached.properties titan-realtime.properties; do
Victor Morales7ae05a42017-08-22 14:39:00 -050078 crudini --set "$aai_src_folder/$dirc/$subdirectory/$file" "" "storage.backend" "cassandra"
79 crudini --set "$aai_src_folder/$dirc/$subdirectory/$file" "" "storage.hostname" "localhost"
Victor Morales455bece2017-07-31 18:40:39 -050080 done
81 done
82
Victor Morales7ae05a42017-08-22 14:39:00 -050083 # Add the schema to the local isntance
84 compile_src $aai_src_folder/resources/aai-resources/
85 uninstall_packages default-jre openjdk-7-jdk openjdk-7-jre openjdk-7-jre-headless
Victor Morales8e08c872017-08-21 16:15:57 -050086 pushd $aai_src_folder
Victor Morales8e08c872017-08-21 16:15:57 -050087 java -DAJSC_HOME=$aai_src_folder/resources/aai-resources -DBUNDLECONFIG_DIR="bundleconfig-local" -cp aai-common/aai-core/target/aai-core-1.1.0-SNAPSHOT.jar:resources/aai-resources/target/aai-resources.jar:resources/aai-resources/target/userjars/* org.openecomp.aai.dbgen.GenTester
Victor Morales455bece2017-07-31 18:40:39 -050088 popd
89}
90
91# start_aai_microservices() - Function that starts AAI microservices
92function start_aai_microservices {
Victor Morales7ae05a42017-08-22 14:39:00 -050093 install_maven
94 export MAVEN_OPTS="-Xms1024m -Xmx5120m -XX:PermSize=2024m -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=9446,server=y,suspend=n"
Victor Morales455bece2017-07-31 18:40:39 -050095 for svc in resources traversal; do
Victor Morales8e08c872017-08-21 16:15:57 -050096 pushd $aai_src_folder/resources
Victor Morales455bece2017-07-31 18:40:39 -050097 mvn -P runAjsc
98 popd
99 done
100}
101
Victor Morales158c18c2017-08-06 11:23:15 -0500102# _pull_hbase_image() - Pull HBase container image from a Docker Registry Hub
103function _pull_hbase_image {
Victor Moralesdd074802017-07-26 16:06:35 -0500104 docker_openecomp_login
Victor Morales89ce3212017-06-16 18:32:48 -0500105 docker pull $nexus_docker_repo/aaidocker/aai-hbase-${hbase_version}
106}
107
108# install_hbase() - Install HBase Service
109function install_hbase {
110 docker rm -f hbase
Victor Morales158c18c2017-08-06 11:23:15 -0500111 _pull_hbase_image
Victor Morales89ce3212017-06-16 18:32:48 -0500112 docker run -d --net=host --name="hbase" $nexus_docker_repo/aaidocker/aai-hbase-${hbase_version}
113}
114
115# install_ajsc() - Install ASJC Java service container
116function install_ajsc_aai {
117 cat <<EOL > /etc/ajsc-aai.conf
118AAI_REPO_PATH=r/aai
119AAI_CHEF_ENV=simpledemo
120AAI_CHEF_LOC=/var/chef/aai-data/environments
121docker_gitbranch=master
122EOL
123 docker rm -f aai-service
Victor Moralesdd074802017-07-26 16:06:35 -0500124 if [[ "$build_image" == "True" ]]; then
Victor Morales8e08c872017-08-21 16:15:57 -0500125 build_docker_image $aai_src_folder/aai-service/ajsc-aai
Victor Moralesdd074802017-07-26 16:06:35 -0500126 else
127 pull_openecomp_image ajsc-aai
128 fi
129
Victor Morales89ce3212017-06-16 18:32:48 -0500130 docker run --env-file /etc/ajsc-aai.conf --name=aai-service --net=host -v /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt -it -d $nexus_docker_repo/openecomp/ajsc-aai:$docker_version
131}
132
133# install_model_loader() Install Model Loader
134function install_model_loader {
Victor Morales89ce3212017-06-16 18:32:48 -0500135 cat <<EOL > /etc/model-loader.conf
136DISTR_CLIENT_ASDC_ADDRESS=${SDC_ADDRESS:-c2.vm1.sdc.simpledemo.openecomp.org:8443}
137DISTR_CLIENT_CONSUMER_GROUP=${UEB_CONSUMER_GROUP:-SDCGroup}
138DISTR_CLIENT_CONSUMER_ID=${UEB_CONSUMER_GROUP_ID:-UEB}
139DISTR_CLIENT_ENVIRONMENT_NAME=${dmaap_topic}
140DISTR_CLIENT_PASSWORD=${SDC_PASSWORD:-OBF:1ks51l8d1o3i1pcc1r2r1e211r391kls1pyj1z7u1njf1lx51go21hnj1y0k1mli1sop1k8o1j651vu91mxw1vun1mze1vv11j8x1k5i1sp11mjc1y161hlr1gm41m111nkj1z781pw31kku1r4p1e391r571pbm1o741l4x1ksp}
141DISTR_CLIENT_USER=${SDC_USER:-aai}
142
143APP_SERVER_BASE_URL=${APP_SERVER_URL:-https://c1.vm1.aai.simpledemo.openecomp.org:8443}
144APP_SERVER_AUTH_USER=${APP_USER:-ModelLoader}
145APP_SERVER_KEYSTORE_PASSWORD=OBF:1i9a1u2a1unz1lr61wn51wn11lss1unz1u301i6o
146APP_SERVER_AUTH_PASSWORD=${APP_PASSWORD:-OBF:1qvu1v2h1sov1sar1wfw1j7j1wg21saj1sov1v1x1qxw}
147EOL
148
Victor Moralesdd074802017-07-26 16:06:35 -0500149 ARGS=""
150
Victor Morales89ce3212017-06-16 18:32:48 -0500151 docker rm -f model-loader-service
152 if [[ "$build_image" == "True" ]]; then
Victor Morales8e08c872017-08-21 16:15:57 -0500153 build_docker_image $aai_src_folder/model-loader/
Victor Moralesdd074802017-07-26 16:06:35 -0500154 ARGS+="--env-file /etc/model-loader.conf model-loader"
Victor Morales89ce3212017-06-16 18:32:48 -0500155 else
156 pull_openecomp_image model-loader
Victor Moralesdd074802017-07-26 16:06:35 -0500157 ARGS+="--name=model-loader-service -it -d --env-file /etc/model-loader.conf $nexus_docker_repo/openecomp/model-loader:$docker_version"
Victor Morales89ce3212017-06-16 18:32:48 -0500158 fi
Victor Moralesdd074802017-07-26 16:06:35 -0500159 docker run ${ARGS}
Victor Morales89ce3212017-06-16 18:32:48 -0500160}
161
Victor Morales158c18c2017-08-06 11:23:15 -0500162# _wait_for_sdc() - Function that determines if SDC is up and running
163function _wait_for_sdc {
Victor Morales89ce3212017-06-16 18:32:48 -0500164 if [[ -s "/opt/config/sdc_ip_addr.txt" ]]; then
165 SDC_IP_ADDR=$(cat /opt/config/sdc_ip_addr.txt)
166 else
167 SDC_IP_ADDR="10.0.3.1"
168 fi
169
170 # Run Health Check against SDC and verify that all five components are up
171 RES=$(curl http://$SDC_IP_ADDR:8181/sdc1/rest/healthCheck | grep -c "OK")
172 while [[ $RES -lt 5 ]]; do
173 RES=$(curl http://$SDC_IP_ADDR:8181/sdc1/rest/healthCheck | grep -c "OK")
174 done
175}
176
177# init_aai() - Function that initialize AAI services
178function init_aai {
Victor Morales455bece2017-07-31 18:40:39 -0500179 install_hadoop
180 install_haproxy
Victor Morales89ce3212017-06-16 18:32:48 -0500181
Idan Amit1690e082017-08-20 08:58:14 +0300182 if [[ "$clone_repo" == "True" ]]; then
183 clone_all_aai_repos
184 if [[ "$compile_repo" == "True" ]]; then
185 compile_aai_repos
186 fi
187 fi
Victor Morales455bece2017-07-31 18:40:39 -0500188
189 setup_titan
Victor Morales14613122017-08-22 19:51:35 -0500190 #start_aai_microservices
Victor Morales455bece2017-07-31 18:40:39 -0500191
192 mkdir -p /opt/openecomp/aai/logs
193 mkdir -p /opt/openecomp/aai/data
Victor Moralesdd074802017-07-26 16:06:35 -0500194
Victor Morales89ce3212017-06-16 18:32:48 -0500195 install_hbase
196
197 # Wait 3 minutes before instantiating the A&AI container
198 sleep 180
199
200 install_ajsc_aai
Victor Morales158c18c2017-08-06 11:23:15 -0500201 _wait_for_sdc
Victor Morales89ce3212017-06-16 18:32:48 -0500202 install_model_loader
203}