Update OOF to v14 AAI schema
[demo.git] / heat / ONAP / cloud-config / oof_vm_init.sh
1 #!/bin/bash
2
3
4 NEXUS_USERNAME=$(cat /opt/config/nexus_username.txt)
5 NEXUS_PASSWD=$(cat /opt/config/nexus_password.txt)
6 NEXUS_DOCKER_REPO=$(cat /opt/config/nexus_docker_repo.txt)
7 CASS_MUSIC_IMAGE_VERSION=$(cat /opt/config/cass_version.txt)
8 MUSIC_IMAGE_VERSION=$(cat /opt/config/music_version.txt)
9 HAS_IMAGE_VERSION=$(cat /opt/config/has_docker_version.txt)
10 OSDF_IMAGE_VERSION=$(cat /opt/config/osdf_docker_version.txt)
11
12 cd /opt/optf-has
13 git pull
14
15 COND_CONF=/opt/optf-has/conductor.conf
16 LOG_CONF=/opt/optf-has/log.conf
17
18 # Certification file for OOF-HAS
19 AAI_cert=/usr/local/bin/AAF_RootCA.cer
20 BUNDLE=/opt/optf-has/AAF_RootCA.cer
21
22 OSDF_IMG=${NEXUS_DOCKER_REPO}/onap/optf-osdf:${OSDF_IMAGE_VERSION}
23 HAS_IMG=${NEXUS_DOCKER_REPO}/onap/optf-has:${HAS_IMAGE_VERSION}
24
25 # pull OOF images from repo
26 docker login -u $NEXUS_USERNAME -p $NEXUS_PASSWD $NEXUS_DOCKER_REPO
27 docker pull ${OSDF_IMG}
28 docker pull ${HAS_IMG}
29
30 # Install MUSIC
31 # MUSIC parameters
32 CASS_IMG=${NEXUS_DOCKER_REPO}/onap/music/cassandra_music:$CASS_MUSIC_IMAGE_VERSION
33 MUSIC_IMG=${NEXUS_DOCKER_REPO}/onap/music/music:$MUSIC_IMAGE_VERSION
34 TOMCAT_IMG=library/tomcat:8.5
35 ZK_IMG=library/zookeeper:3.4
36 WORK_DIR=/opt/optf-has
37 CASS_USERNAME=cassandra1
38 CASS_PASSWORD=cassandra1
39
40 # pull MUSIC images
41 docker pull ${ZK_IMG}
42 docker pull ${TOMCAT_IMG}
43 docker pull ${CASS_IMG}
44 docker pull ${MUSIC_IMG}
45
46 # create directory for music properties and logs
47 mkdir -p /opt/optf-has/music/properties
48 mkdir -p /opt/optf-has/music/logs
49
50 # add music.properties file
51 cat > /opt/optf-has/music/properties/music.properties<<NEWFILE
52 my.id=0
53 all.ids=0
54 my.public.ip=localhost
55 all.public.ips=localhost
56
57 #######################################
58
59 # Optional current values are defaults
60
61 #######################################
62 zookeeper.host=music-zk
63 cassandra.host=music-db
64 #music.ip=localhost
65 #debug=true
66 #music.rest.ip=localhost
67 #lock.lease.period=6000
68 cassandra.user=cassandra1
69 cassandra.password=cassandra1
70
71 # AAF Endpoint if using AAF
72 aaf.endpoint.url=https://aaf.api.simpledemo.onap.org
73 NEWFILE
74
75 # Create Volume for mapping war file and tomcat
76 docker volume create music-vol
77
78 # Create a network for all the containers to run in.
79 docker network create music-net
80
81 # Start Cassandra
82 docker run -d --rm --name music-db --network music-net -p "7000:7000" -p "7001:7001" -p "7199:7199" -p "9042:9042" -p "9160:9160" -e CASSUSER=${CASS_USERNAME} -e CASSPASS=${CASS_PASSWORD} ${CASS_IMG}
83
84 # Start Music war
85 docker run -d --rm --name music-war -v music-vol:/app ${MUSIC_IMG}
86
87 # Start Zookeeper
88 docker run -d --rm --name music-zk --network music-net -p "2181:2181" -p "2888:2888" -p "3888:3888" ${ZK_IMG}
89
90 # Delay for Cassandra
91 sleep 20;
92
93 # Start Up tomcat - Needs to have properties,logs dir and war file volume mapped.
94 docker run -d --rm --name music-tomcat --network music-net -p "8080:8080" -v music-vol:/usr/local/tomcat/webapps -v ${WORK_DIR}/music/properties:/opt/app/music/etc:ro -v ${WORK_DIR}/music/logs:/opt/app/music/logs ${TOMCAT_IMG}
95
96 # Connect tomcat to host bridge network so that its port can be seen.
97 docker network connect bridge music-tomcat;
98 sleep 6;
99 echo "Running onboarding curl command"
100 curl -X POST \
101   http://localhost:8080/MUSIC/rest/v2/admin/onboardAppWithMusic \
102   -H 'Cache-Control: no-cache' \
103   -H 'Content-Type: application/json' \
104   -H 'Postman-Token: 7d2839f4-b032-487a-8998-4d1b27a932d7' \
105   -d '{
106 "appname": "conductor",
107 "userId" : "conductor",
108 "isAAF"  : false,
109 "password" : "c0nduct0r"
110 }
111 '
112 echo "Onboarding curl complete"
113
114 # Get MUSIC url
115 MUSIC_URL=$(docker inspect --format '{{ .NetworkSettings.Networks.bridge.IPAddress}}' music-tomcat)
116
117 # Run OOF-HAS
118 # Set A&AI and MUSIC url inside OOF-HAS conductor.conf
119 sed -i "160 s%.*%server_url = https://aai.api.simpledemo.onap.org:8443/aai%" $COND_CONF
120 sed -i "163 s%.*%server_url_version = v14%" $COND_CONF
121 sed -i "279 s%.*%server_url = http://$MUSIC_URL:8080/MUSIC/rest/v2%" $COND_CONF
122 sed -i "306 s%.*%replication_factor = 1%" $COND_CONF
123 sed -i "381 s%.*%server_url = http://msb.api.simpledemo.onap.org/api/multicloud%" $COND_CONF
124
125 # Set A&AI authentication file locations inside OOF-HAS conductor.conf
126 sed -i "175 s%.*%certificate_authority_bundle_file = $AAI_cert%" $COND_CONF
127
128
129 echo "Values to data component"
130 echo $BUNDLE
131
132 # run optf-has
133 docker run -d --name controller -v $COND_CONF:/usr/local/bin/conductor.conf -v $LOG_CONF:/usr/local/bin/log.conf ${HAS_IMG} python /usr/local/bin/conductor-controller --config-file=/usr/local/bin/conductor.conf
134
135 docker run -d --name api -p "8091:8091" -v $COND_CONF:/usr/local/bin/conductor.conf -v $LOG_CONF:/usr/local/bin/log.conf ${HAS_IMG} python /usr/local/bin/conductor-api --port=8091 -- --config-file=/usr/local/bin/conductor.conf
136
137 docker run -d --name solver -v $COND_CONF:/usr/local/bin/conductor.conf -v $LOG_CONF:/usr/local/bin/log.conf ${HAS_IMG} python /usr/local/bin/conductor-solver --config-file=/usr/local/bin/conductor.conf
138
139 docker run -d --name reservation -v $COND_CONF:/usr/local/bin/conductor.conf -v $LOG_CONF:/usr/local/bin/log.conf ${HAS_IMG} python /usr/local/bin/conductor-reservation --config-file=/usr/local/bin/conductor.conf
140
141 docker run -d --name data -v $COND_CONF:/usr/local/bin/conductor.conf -v $LOG_CONF:/usr/local/bin/log.conf -v $BUNDLE:/usr/local/bin/AAF_RootCA.cer ${HAS_IMG} python /usr/local/bin/conductor-data --config-file=/usr/local/bin/conductor.conf
142
143 sleep 10
144
145 echo "Inserting healthcheck plan"
146
147 curl -X POST \
148   http://$MUSIC_URL:8080/MUSIC/rest/v2/keyspaces/conductor/tables/plans/rows/ \
149   -H 'Cache-Control: no-cache' \
150   -H 'Content-Type: application/json' \
151   -H 'Postman-Token: 502781e8-d588-475d-b181-c2e26625ac95' \
152   -H 'X-minorVersion: 3' \
153   -H 'X-patchVersion: 0' \
154   -H 'ns: conductor' \
155   -H 'password: c0nduct0r' \
156   -H 'userId: conductor' \
157   -d '{
158     "consistencyInfo": {
159         "type": "eventual"
160     },
161     "values": {
162         "id" : "healthcheck",
163         "created": 1479482603641,
164         "message": "",
165         "name": "foo",
166         "recommend_max": 1,
167         "solution": "{\"healthcheck\": \" healthcheck\"}",
168         "status": "done",
169         "template": "{\"healthcheck\": \"healthcheck\"}",
170         "timeout": 3600,
171         "translation": "{\"healthcheck\": \" healthcheck\"}",
172         "updated": 1484324150629
173     }
174 }
175 '
176
177 echo "Healthcheck plan inserted"
178
179
180 #run optf-osdf
181 OSDF_CONFIG=/opt/optf-osdf/config/osdf_config.yaml
182 HAS_HOST=$(docker inspect --format '{{ .NetworkSettings.Networks.bridge.IPAddress}}' api)
183
184 mkdir -p /opt/optf-osdf/config
185
186 cat > $OSDF_CONFIG<<NEWFILE
187
188 # Credentials for SO
189 soUsername: ""   # SO username for call back.
190 soPassword: ""   # SO password for call back.
191
192 # Credentials for Conductor
193 conductorUrl: http://$HAS_HOST:8091/v1/plans/
194 conductorUsername: admin1
195 conductorPassword: plan.15
196 conductorPingWaitTime: 60  # seconds to wait before calling the conductor retry URL
197 conductorMaxRetries: 30  # if we don't get something in 30 minutes, give up
198
199 # Policy Platform -- requires ClientAuth, Authorization, and Environment
200 policyPlatformUrl: http://policy.api.simpledemo.onap.org:8081/pdp/api/getConfig # Policy Dev platform URL
201 policyPlatformEnv: TEST  # Environment for policy platform
202 policyPlatformUsername: testpdp   # Policy platform username.
203 policyPlatformPassword: alpha123   # Policy platform password.
204 policyClientUsername: python   # For use with ClientAuth
205 policyClientPassword: test   # For use with ClientAuth
206
207 # Credentials for DMaaP
208 messageReaderHosts: NA
209 messageReaderTopic: NA
210 messageReaderAafUserId: NA
211 messageReaderAafPassword: NA
212
213 # Credentials for SDC
214 sdcUrl: NA
215 sdcUsername: NA
216 sdcPassword: NA
217 sdcONAPInstanceID: NA
218
219 # Credentials for the OOF placement service - Generic
220 osdfPlacementUsername: test
221 osdfPlacementPassword: testpwd
222
223 # Credentials for the OOF placement service - SO
224 osdfPlacementSOUsername: so_test
225 osdfPlacementSOPassword: so_testpwd
226
227 # Credentials for the OOF CM scheduling service - Generic
228 osdfCMSchedulerUsername: test1
229 osdfCMSchedulerPassword: testpwd1
230
231 NEWFILE
232
233 docker run -d --name osdf -v $OSDF_CONFIG:/opt/app/config/osdf_config.yaml -p 8698:8699 ${OSDF_IMG}