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