summaryrefslogtreecommitdiffstats
path: root/bootstrap/vagrant-onap/lib/aai
blob: faf916d9b6b2a0e61dda1842db8c69302ecc3df8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash

set -o xtrace

source /var/onap/functions

hbase_version=1.2.3
aai_src_folder=$git_src_folder/aai
aai_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")

# install_hadoop() - Function that installs Hadoop
function install_hadoop {
    local release=titan
    local version=1.0.0
    local filename=$release-$version-hadoop1
    local dest_folder=/opt/hadoop/current

    if [ ! -d $dest_folder ]; then
        curl http://s3.thinkaurelius.com/downloads/$release/$filename.zip -o /tmp/${filename}.zip
        install_package unzip
        mkdir -p $dest_folder
        unzip /tmp/${filename}.zip -d $dest_folder
        pushd $dest_folder/${filename}
        # Change commitlog_directory and data_file_directories values (https://stackoverflow.com/a/26856246/1707651)
        sed -i "s|db/cassandra/data|/tmp/data|g" conf/cassandra/cassandra.yaml
        sed -i "s|db/cassandra/commitlog|/tmp/commitlog|g" conf/cassandra/cassandra.yaml

        install_java
        ./bin/titan.sh start
        popd
    fi
}

# install_haproxy() - Function that install HAProxy
function install_haproxy {
    if is_package_installed haproxy; then
        return
    fi
    install_package software-properties-common
    add-apt-repository -y ppa:vbernat/haproxy-1.7
    install_package haproxy
    cp /var/onap/files/haproxy.cfg /etc/haproxy/
    cp /var/onap/files/aai.pem /etc/ssl/private/
    chmod 640 /etc/ssl/private/aai.pem
    chown root:ssl-cert /etc/ssl/private/aai.pem
    mkdir /usr/local/etc/haproxy
    #echo "127.0.0.1 localhost aai-traversal.api.simpledemo.openecomp.org aai-resources.api.simpledemo.openecomp.org" >> /etc/hosts

    service haproxy restart
}

# clone_all_aai_repos() - Function that clones AAI source repo.
function clone_all_aai_repos {
    for dirc in ${aai_repos[@]}; do
        clone_repo aai/$dirc $aai_src_folder/$dirc
    done
}

# compile_aai_repos() - Function that compiles AAI source repo.
function compile_aai_repos {
    local repos=("aai-common" "resources" "logging-service" "traversal")
    if [[ "$compile_repo" == "True" ]]; then
        repos=("${aai_repos[@]}")
    fi

    for dirc in ${repos[@]}; do
        compile_src $aai_src_folder/$dirc
    done
}

# setup_titan() - Function that configures AAI services to connect to Hadoop Titan
function setup_titan {
    local subdirectory="bundleconfig-local/etc/appprops"
    install_python_package crudini

    for dirc in resources/aai-resources traversal/aai-traversal; do
        for file in titan-cached.properties titan-realtime.properties; do
            crudini --set "$aai_src_folder/$dirc/$subdirectory/$file" "" "storage.backend" "cassandra"
            crudini --set "$aai_src_folder/$dirc/$subdirectory/$file" "" "storage.hostname" "localhost"
        done
    done

    # Add the schema to the local isntance
    compile_src $aai_src_folder/resources/aai-resources/
    uninstall_packages default-jre openjdk-7-jdk openjdk-7-jre openjdk-7-jre-headless
    pushd $aai_src_folder
    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
    popd
}

# start_aai_microservices() - Function that starts AAI microservices
function start_aai_microservices {
    install_maven
    export MAVEN_OPTS="-Xms1024m -Xmx5120m -XX:PermSize=2024m -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=9446,server=y,suspend=n"
    for svc in resources traversal; do
        pushd $aai_src_folder/resources
        mvn -P runAjsc
        popd
    done
}

# _pull_hbase_image() - Pull HBase container image from a Docker Registry Hub
function _pull_hbase_image {
    docker_openecomp_login
    docker pull $nexus_docker_repo/aaidocker/aai-hbase-${hbase_version}
}

# install_hbase() - Install HBase Service
function install_hbase {
    docker rm -f hbase
    _pull_hbase_image
    docker run -d --net=host --name="hbase" $nexus_docker_repo/aaidocker/aai-hbase-${hbase_version}
}

# install_ajsc() - Install ASJC Java service container
function install_ajsc_aai {
    cat <<EOL > /etc/ajsc-aai.conf
AAI_REPO_PATH=r/aai
AAI_CHEF_ENV=simpledemo
AAI_CHEF_LOC=/var/chef/aai-data/environments
docker_gitbranch=master
EOL
    docker rm -f aai-service
    if [[ "$build_image" == "True" ]]; then
        build_docker_image $aai_src_folder/aai-service/ajsc-aai
    else
        pull_openecomp_image ajsc-aai
    fi

    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
}

# install_model_loader() Install Model Loader 
function install_model_loader {
    cat <<EOL > /etc/model-loader.conf
DISTR_CLIENT_ASDC_ADDRESS=${SDC_ADDRESS:-c2.vm1.sdc.simpledemo.openecomp.org:8443}
DISTR_CLIENT_CONSUMER_GROUP=${UEB_CONSUMER_GROUP:-SDCGroup}
DISTR_CLIENT_CONSUMER_ID=${UEB_CONSUMER_GROUP_ID:-UEB}
DISTR_CLIENT_ENVIRONMENT_NAME=${dmaap_topic}
DISTR_CLIENT_PASSWORD=${SDC_PASSWORD:-OBF:1ks51l8d1o3i1pcc1r2r1e211r391kls1pyj1z7u1njf1lx51go21hnj1y0k1mli1sop1k8o1j651vu91mxw1vun1mze1vv11j8x1k5i1sp11mjc1y161hlr1gm41m111nkj1z781pw31kku1r4p1e391r571pbm1o741l4x1ksp}
DISTR_CLIENT_USER=${SDC_USER:-aai}
                     
APP_SERVER_BASE_URL=${APP_SERVER_URL:-https://c1.vm1.aai.simpledemo.openecomp.org:8443}
APP_SERVER_AUTH_USER=${APP_USER:-ModelLoader}
APP_SERVER_KEYSTORE_PASSWORD=OBF:1i9a1u2a1unz1lr61wn51wn11lss1unz1u301i6o
APP_SERVER_AUTH_PASSWORD=${APP_PASSWORD:-OBF:1qvu1v2h1sov1sar1wfw1j7j1wg21saj1sov1v1x1qxw}
EOL

    ARGS=""

    docker rm -f model-loader-service
    if [[ "$build_image" == "True" ]]; then
        build_docker_image $aai_src_folder/model-loader/
        ARGS+="--env-file /etc/model-loader.conf model-loader"
    else
        pull_openecomp_image model-loader
        ARGS+="--name=model-loader-service -it -d --env-file /etc/model-loader.conf $nexus_docker_repo/openecomp/model-loader:$docker_version"
    fi
    docker run ${ARGS}
}

# _wait_for_sdc() - Function that determines if SDC is up and running
function _wait_for_sdc {
    if [[ -s "/opt/config/sdc_ip_addr.txt" ]]; then
        SDC_IP_ADDR=$(cat /opt/config/sdc_ip_addr.txt)
    else
        SDC_IP_ADDR="10.0.3.1"
    fi

     # Run Health Check against SDC and verify that all five components are up
    RES=$(curl http://$SDC_IP_ADDR:8181/sdc1/rest/healthCheck | grep -c "OK")
    while [[ $RES -lt 5 ]]; do
        RES=$(curl http://$SDC_IP_ADDR:8181/sdc1/rest/healthCheck | grep -c "OK")
    done
}

# init_aai() - Function that initialize AAI services
function init_aai {
    install_hadoop
    install_haproxy

    clone_all_aai_repos
    compile_aai_repos

    setup_titan
    start_aai_microservices

    mkdir -p /opt/openecomp/aai/logs
    mkdir -p /opt/openecomp/aai/data

    install_hbase

    # Wait 3 minutes before instantiating the A&AI container
    sleep 180

    install_ajsc_aai
    _wait_for_sdc
    install_model_loader
}