blob: d96301cfaa6fddfe47c2f96b7f15a71a73aa0d8c [file] [log] [blame]
waqas.ikrama5aeeda2019-08-07 16:03:14 +00001#!/bin/bash
2#
3# ============LICENSE_START=======================================================
4# Copyright (C) 2019 Nordix Foundation.
5# ================================================================================
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
18# SPDX-License-Identifier: Apache-2.0
19# ============LICENSE_END=========================================================
20#
21
22# @author Gareth Roper (gareth.roper@est.tech)
23# @auther Waqas Ikram (waqas.ikram@est.tech)
24
25SCRIPT_NAME=$(basename $0)
26SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
27WAIT_FOR_SCRIPT=$SCRIPT_HOME/wait-for.sh
28
29current_timestamp()
30{
31 date +"%Y-%m-%d %H:%M:%S"
32}
33
34populate_aai_simulator()
35{
36 $WAIT_FOR_SCRIPT -t "$TIMEOUT_IN_SECONDS" -h "$AAI_SIMULATOR_HOST" -p "$AAI_SIMULATOR_PORT"
37
38 if [ $? -eq 0 ]
39 then
40 echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator is Running."
41 else
42 echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator could not be found. Exiting..."
43 exit 1
44 fi
45
46 BASE_URL="https://$AAI_SIMULATOR_HOST:$AAI_SIMULATOR_PORT/aai/v15"
47 BASIC_AUTHORIZATION_HEADER="Authorization: Basic YWFpOmFhaS5vbmFwLm9yZzpkZW1vMTIzNDU2IQ=="
48 APPICATION_JSON="application/json"
49 ACCEPT_HEADER="Accept: $APPICATION_JSON"
50 CONTENT_TYPE_HEADER="Content-Type: $APPICATION_JSON"
51 CURL_COMMAND="curl -k -H $BASIC_AUTHORIZATION_HEADER -H $ACCEPT_HEADER -H $CONTENT_TYPE_HEADER"
52
53 AAI_SIMULATOR_DATA_DIR=$SCRIPT_HOME/aai-simulator-populate-data
54 CUSTOMER_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/customer.json
55 PROJECT_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/project.json
56 OWNING_ENTITY_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/owning-entity.json
waqas.ikram241cd372019-08-20 10:46:55 +000057 LINE_OF_BUSINESS_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/line-of-business.json
58 PLATFORM_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/platform.json
waqas.ikramb7045fd2019-08-20 15:01:02 +000059 CLOUD_REGION_JSON_FILE=$AAI_SIMULATOR_DATA_DIR/cloud-region.json
waqas.ikrama5aeeda2019-08-07 16:03:14 +000060 STATUS_CODE_ACCEPTED="202"
61
62 echo "$SCRIPT_NAME $(current_timestamp): checking health of AAI Simulator"
63 response=$(curl -k $BASE_URL/healthcheck)
64
65 if [[ "$response" -ne "healthy" ]] ; then
66 echo "$SCRIPT_NAME $(current_timestamp) ERROR: AAI Simulator health check failed. Response: $response"
67 exit 1
68 fi
69
70 echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator is healthy"
71
72 echo "$SCRIPT_NAME $(current_timestamp): Populating AAI Simulator"
73
74 echo "$SCRIPT_NAME $(current_timestamp): Adding Cloud-Customer Data"
75 status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/customers/customer/DemoCustomer -X PUT -d @"$CUSTOMER_JSON_FILE")
76
77 if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
78 echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put customer data in AAI Simulator. Status code received: $status_code"
79 exit 1
80 fi
81
82 echo "$SCRIPT_NAME $(current_timestamp): Adding Project"
83 status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/projects/project/etsiCsitProject -X PUT -d @"$PROJECT_JSON_FILE")
84
85 if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
86 echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put project data in AAI Simulator. Status code received: $status_code"
87 exit 1
88 fi
89
90 echo "$SCRIPT_NAME $(current_timestamp): Adding Owning-Entity"
91 status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/owning-entities/owning-entity/oe_1 -X PUT -d @$"$OWNING_ENTITY_JSON_FILE")
92
93 if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
94 echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put owning entity data in AAI Simulator. Status code received: $status_code"
95 exit 1
96 fi
97
waqas.ikram241cd372019-08-20 10:46:55 +000098 echo "$SCRIPT_NAME $(current_timestamp): Adding Line Of Business"
99 status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/lines-of-business/line-of-business/EtsiCsitLineOfBusiness -X PUT -d @$"$LINE_OF_BUSINESS_JSON_FILE")
100
101 if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
102 echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put line of business data in AAI Simulator. Status code received: $status_code"
103 exit 1
104 fi
105
106 echo "$SCRIPT_NAME $(current_timestamp): Adding Platform"
107 status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/business/platforms/platform/EtsiCsitPlatform -X PUT -d @$"$PLATFORM_JSON_FILE")
108
109 if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
110 echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put platform data in AAI Simulator. Status code received: $status_code"
111 exit 1
112 fi
113
waqas.ikramb7045fd2019-08-20 15:01:02 +0000114 echo "$SCRIPT_NAME $(current_timestamp): Adding Cloud Region"
115 status_code=$(curl -k --write-out %{http_code} --silent --output /dev/null -H "$BASIC_AUTHORIZATION_HEADER" -H "$ACCEPT_HEADER" -H "$CONTENT_TYPE_HEADER" $BASE_URL/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/EtsiCloudRegion -X PUT -d @$"$CLOUD_REGION_JSON_FILE")
116
117 if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
118 echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put Cloud Region data in AAI Simulator. Status code received: $status_code"
119 exit 1
120 fi
121
waqas.ikrama5aeeda2019-08-07 16:03:14 +0000122 echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator Populated Successfully"
123}
124
125# main body
126populate_aai_simulator