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