blob: df903fd7b69f5a0259d3573382b04c8006fb6906 [file] [log] [blame]
Victor Morales89ce3212017-06-16 18:32:48 -05001#!/bin/bash
2
3set -o xtrace
4
5source /var/onap/functions
Victor Moralesdd074802017-07-26 16:06:35 -05006source /var/onap/asserts
Victor Morales89ce3212017-06-16 18:32:48 -05007
8hbase_version=1.2.3
Victor Morales455bece2017-07-31 18:40:39 -05009src_folder=$git_src_folder/aai
Victor Morales158c18c2017-08-06 11:23:15 -050010aai_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 -050011
12# install_hadoop() - Function that installs Hadoop
13function install_hadoop {
14 local release=titan
15 local version=1.0.0
16 local filename=$release-$version-hadoop1
17 local dest_folder=/opt/hadoop/current
18
19 if [ ! -d $dest_folder ]; then
20 curl http://s3.thinkaurelius.com/downloads/$release/$filename.zip -o /tmp/${filename}.zip
21 install_package unzip
22 mkdir -p $dest_folder
23 unzip /tmp/${filename}.zip -d $dest_folder
24 pushd $dest_folder/${filename}
Victor Morales158c18c2017-08-06 11:23:15 -050025 # Change commitlog_directory and data_file_directories values (https://stackoverflow.com/a/26856246/1707651)
26 sed -i "s|db/cassandra/data|/tmp/data|g" conf/cassandra/cassandra.yaml
27 sed -i "s|db/cassandra/commitlog|/tmp/commitlog|g" conf/cassandra/cassandra.yaml
28
29 install_java
Victor Morales455bece2017-07-31 18:40:39 -050030 ./bin/titan.sh start
31 popd
32 fi
33}
34
35# install_haproxy() - Function that install HAProxy
36function install_haproxy {
37 install_package haproxy
38 sed -i "s|ENABLED=0|ENABLED=1|g" /etc/default/haproxy
39# cp /var/onap/files/haproxy.cfg /etc/haproxy/
40 cp /var/onap/files/aai.pem /etc/ssl/private/
41 chmod 640 /etc/ssl/private/aai.pem
42 chown root:ssl-cert /etc/ssl/private/aai.pem
43 mkdir /usr/local/etc/haproxy
44 echo "127.0.0.1 localhost aai-traversal.api.simpledemo.openecomp.org aai-resources.api.simpledemo.openecomp.org" >> /etc/hosts
45
46 service haproxy restart
47}
Victor Morales89ce3212017-06-16 18:32:48 -050048
Victor Moralesdd074802017-07-26 16:06:35 -050049# clone_all_aai_repos() - Function that clones AAI source repo.
50function clone_all_aai_repos {
Victor Morales455bece2017-07-31 18:40:39 -050051 for dirc in ${aai_repos[@]}; do
Victor Moralesdd074802017-07-26 16:06:35 -050052 clone_repo aai/$dirc $src_folder/$dirc
53 done
54}
55
Victor Morales455bece2017-07-31 18:40:39 -050056# compile_aai_repos() - Function that compiles AAI source repo.
57function compile_aai_repos {
58 local repos=("aai-common" "resources" "logging-service" "traversal")
59 if [[ "$compile_repo" == "True" ]]; then
Victor Morales158c18c2017-08-06 11:23:15 -050060 repos=("${aai_repos[@]}")
Victor Morales455bece2017-07-31 18:40:39 -050061 fi
Victor Moralesdd074802017-07-26 16:06:35 -050062
Victor Morales455bece2017-07-31 18:40:39 -050063 for dirc in ${repos[@]}; do
Victor Moralesdd074802017-07-26 16:06:35 -050064 compile_src $src_folder/$dirc
65 done
66}
67
Victor Morales455bece2017-07-31 18:40:39 -050068# setup_titan() - Function that configures AAI services to connect to Hadoop Titan
69function setup_titan {
70 local $subdirectory=bundleconfig-local/etc/appprops
71 install_python_package crudini
72
73 for dirc in resources/aai-resources traversal/aai-travers; do
74 for file in titan-cached.properties titan-realtime.properties; do
75 crudini --set --existing $src_folder/$dirc/$subdirectory/$file "" storage.backend cassandra
76 crudini --set --existing $src_folder/$dirc/$subdirectory/$file "" storage.hostname localhost
77 done
78 done
79
80 # Addthe schema to the local isntance
81 pushd $src_folder
Victor Morales158c18c2017-08-06 11:23:15 -050082 install_java
Victor Morales455bece2017-07-31 18:40:39 -050083 java -DAJSC_HOME=$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
84 popd
85}
86
87# start_aai_microservices() - Function that starts AAI microservices
88function start_aai_microservices {
89 MAVEN_OPTS="-Xms1024m -Xmx5120m -XX:PermSize=2024m -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=9446,server=y,suspend=n"
90 for svc in resources traversal; do
91 pushd $src_folder/resources
92 mvn -P runAjsc
93 popd
94 done
95}
96
Victor Morales158c18c2017-08-06 11:23:15 -050097# _pull_hbase_image() - Pull HBase container image from a Docker Registry Hub
98function _pull_hbase_image {
Victor Moralesdd074802017-07-26 16:06:35 -050099 docker_openecomp_login
Victor Morales89ce3212017-06-16 18:32:48 -0500100 docker pull $nexus_docker_repo/aaidocker/aai-hbase-${hbase_version}
101}
102
103# install_hbase() - Install HBase Service
104function install_hbase {
105 docker rm -f hbase
Victor Morales158c18c2017-08-06 11:23:15 -0500106 _pull_hbase_image
Victor Morales89ce3212017-06-16 18:32:48 -0500107 docker run -d --net=host --name="hbase" $nexus_docker_repo/aaidocker/aai-hbase-${hbase_version}
108}
109
110# install_ajsc() - Install ASJC Java service container
111function install_ajsc_aai {
112 cat <<EOL > /etc/ajsc-aai.conf
113AAI_REPO_PATH=r/aai
114AAI_CHEF_ENV=simpledemo
115AAI_CHEF_LOC=/var/chef/aai-data/environments
116docker_gitbranch=master
117EOL
118 docker rm -f aai-service
Victor Moralesdd074802017-07-26 16:06:35 -0500119 if [[ "$build_image" == "True" ]]; then
Victor Morales158c18c2017-08-06 11:23:15 -0500120 build_docker_image $src_folder/aai-service/ajsc-aai
Victor Moralesdd074802017-07-26 16:06:35 -0500121 else
122 pull_openecomp_image ajsc-aai
123 fi
124
Victor Morales89ce3212017-06-16 18:32:48 -0500125 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
126}
127
128# install_model_loader() Install Model Loader
129function install_model_loader {
130 local src_folder=/opt/aai/model-loader/
131 cat <<EOL > /etc/model-loader.conf
132DISTR_CLIENT_ASDC_ADDRESS=${SDC_ADDRESS:-c2.vm1.sdc.simpledemo.openecomp.org:8443}
133DISTR_CLIENT_CONSUMER_GROUP=${UEB_CONSUMER_GROUP:-SDCGroup}
134DISTR_CLIENT_CONSUMER_ID=${UEB_CONSUMER_GROUP_ID:-UEB}
135DISTR_CLIENT_ENVIRONMENT_NAME=${dmaap_topic}
136DISTR_CLIENT_PASSWORD=${SDC_PASSWORD:-OBF:1ks51l8d1o3i1pcc1r2r1e211r391kls1pyj1z7u1njf1lx51go21hnj1y0k1mli1sop1k8o1j651vu91mxw1vun1mze1vv11j8x1k5i1sp11mjc1y161hlr1gm41m111nkj1z781pw31kku1r4p1e391r571pbm1o741l4x1ksp}
137DISTR_CLIENT_USER=${SDC_USER:-aai}
138
139APP_SERVER_BASE_URL=${APP_SERVER_URL:-https://c1.vm1.aai.simpledemo.openecomp.org:8443}
140APP_SERVER_AUTH_USER=${APP_USER:-ModelLoader}
141APP_SERVER_KEYSTORE_PASSWORD=OBF:1i9a1u2a1unz1lr61wn51wn11lss1unz1u301i6o
142APP_SERVER_AUTH_PASSWORD=${APP_PASSWORD:-OBF:1qvu1v2h1sov1sar1wfw1j7j1wg21saj1sov1v1x1qxw}
143EOL
144
Victor Moralesdd074802017-07-26 16:06:35 -0500145 ARGS=""
146
Victor Morales89ce3212017-06-16 18:32:48 -0500147 docker rm -f model-loader-service
148 if [[ "$build_image" == "True" ]]; then
149 clone_repo aai/model-loader $src_folder
150 build_docker_image $src_folder
Victor Moralesdd074802017-07-26 16:06:35 -0500151 ARGS+="--env-file /etc/model-loader.conf model-loader"
Victor Morales89ce3212017-06-16 18:32:48 -0500152 else
153 pull_openecomp_image model-loader
Victor Moralesdd074802017-07-26 16:06:35 -0500154 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 -0500155 fi
Victor Moralesdd074802017-07-26 16:06:35 -0500156 docker run ${ARGS}
Victor Morales89ce3212017-06-16 18:32:48 -0500157}
158
Victor Morales158c18c2017-08-06 11:23:15 -0500159# _wait_for_sdc() - Function that determines if SDC is up and running
160function _wait_for_sdc {
Victor Morales89ce3212017-06-16 18:32:48 -0500161 if [[ -s "/opt/config/sdc_ip_addr.txt" ]]; then
162 SDC_IP_ADDR=$(cat /opt/config/sdc_ip_addr.txt)
163 else
164 SDC_IP_ADDR="10.0.3.1"
165 fi
166
167 # Run Health Check against SDC and verify that all five components are up
168 RES=$(curl http://$SDC_IP_ADDR:8181/sdc1/rest/healthCheck | grep -c "OK")
169 while [[ $RES -lt 5 ]]; do
170 RES=$(curl http://$SDC_IP_ADDR:8181/sdc1/rest/healthCheck | grep -c "OK")
171 done
172}
173
174# init_aai() - Function that initialize AAI services
175function init_aai {
Victor Morales455bece2017-07-31 18:40:39 -0500176 install_hadoop
177 install_haproxy
Victor Morales89ce3212017-06-16 18:32:48 -0500178
Victor Moralesdd074802017-07-26 16:06:35 -0500179 clone_all_aai_repos
Victor Morales455bece2017-07-31 18:40:39 -0500180 compile_aai_repos
181
182 setup_titan
183 start_aai_microservices
184
185 mkdir -p /opt/openecomp/aai/logs
186 mkdir -p /opt/openecomp/aai/data
Victor Moralesdd074802017-07-26 16:06:35 -0500187
Victor Morales89ce3212017-06-16 18:32:48 -0500188 install_hbase
189
190 # Wait 3 minutes before instantiating the A&AI container
191 sleep 180
192
193 install_ajsc_aai
Victor Morales158c18c2017-08-06 11:23:15 -0500194 _wait_for_sdc
Victor Morales89ce3212017-06-16 18:32:48 -0500195 install_model_loader
196}