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
10 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # SPDX-License-Identifier: Apache-2.0
19 # ============LICENSE_END=========================================================
22 # @author Gareth Roper (gareth.roper@est.tech)
23 # @auther Waqas Ikram (waqas.ikram@est.tech)
25 SCRIPT_NAME=$(basename $0)
26 SCRIPT_HOME="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
27 WAIT_FOR_SCRIPT=$SCRIPT_HOME/wait-for.sh
31 date +"%Y-%m-%d %H:%M:%S"
34 populate_aai_simulator()
36 $WAIT_FOR_SCRIPT -t "$TIMEOUT_IN_SECONDS" -h "$AAI_SIMULATOR_HOST" -p "$AAI_SIMULATOR_PORT"
40 echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator is Running."
42 echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator could not be found. Exiting..."
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"
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
57 STATUS_CODE_ACCEPTED="202"
59 echo "$SCRIPT_NAME $(current_timestamp): checking health of AAI Simulator"
60 response=$(curl -k $BASE_URL/healthcheck)
62 if [[ "$response" -ne "healthy" ]] ; then
63 echo "$SCRIPT_NAME $(current_timestamp) ERROR: AAI Simulator health check failed. Response: $response"
67 echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator is healthy"
69 echo "$SCRIPT_NAME $(current_timestamp): Populating AAI Simulator"
71 echo "$SCRIPT_NAME $(current_timestamp): Adding Cloud-Customer Data"
72 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")
74 if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
75 echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put customer data in AAI Simulator. Status code received: $status_code"
79 echo "$SCRIPT_NAME $(current_timestamp): Adding Project"
80 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")
82 if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
83 echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put project data in AAI Simulator. Status code received: $status_code"
87 echo "$SCRIPT_NAME $(current_timestamp): Adding Owning-Entity"
88 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")
90 if [[ "$status_code" -ne "$STATUS_CODE_ACCEPTED" ]] ; then
91 echo "$SCRIPT_NAME $(current_timestamp) ERROR: Unable to put owning entity data in AAI Simulator. Status code received: $status_code"
95 echo "$SCRIPT_NAME $(current_timestamp): AAI Simulator Populated Successfully"
99 populate_aai_simulator