3 # ============LICENSE_START=======================================================
4 # Copyright (C) 2023 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 echo "Getting ready to upload model for subscription events ..."
24 createSchemaSetBasePath="/cps/api/v2/dataspaces/NCMP-Admin/schema-sets?schema-set-name=subscriptions"
25 createAnchorBasePath="/cps/api/v2/dataspaces/NCMP-Admin/anchors?schema-set-name=subscriptions&anchor-name=AVC-subscriptions"
31 hostIpAddress=$(ip -4 route show default | cut -d" " -f3)
33 if curl -X 'GET' 'http://'"$hostIpAddress"':'"$CPS_CORE_MANAGEMENT_PORT"'/manage/health/readiness' | grep -q "$status"
35 echo "Checking that NCMP dataspace exists ..."
36 ncmpDataspaceExists=$(curl --write-out %{http_code} --silent --output /dev/null -X 'GET' 'http://'"$hostIpAddress"':'"$CPS_CORE_PORT"'/cps/api/v2/admin/dataspaces/NCMP-Admin' -H 'accept: */*' --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=')
38 echo "NCMP dataspace exist: $ncmpDataspaceExists"
40 if [ "$ncmpDataspaceExists" == 200 ]
42 echo "Uploading model ..."
43 create_schema_set_status_code=$(curl --write-out %{http_code} --silent --output /dev/null -X 'POST' 'http://'"$hostIpAddress"':'"$CPS_CORE_PORT"''"$createSchemaSetBasePath"'' -H 'accept: */*' --form "file=@"/model/subscription.yang"" --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=')
44 create_anchor_status_code=$(curl --write-out %{http_code} --silent --output /dev/null -X 'POST' 'http://'"$hostIpAddress"':'"$CPS_CORE_PORT"''"$createAnchorBasePath"'' -H 'accept: */*' --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=')
46 echo "create schema set status: $create_schema_set_status_code"
47 echo "create anchor status: $create_anchor_status_code"
49 if [ "$create_schema_set_status_code" == 201 ] && [ "$create_anchor_status_code" == 201 ]
51 echo "Model upload finish!"
52 echo "Exiting container ..."
59 if [ $ATTEMPT_COUNT == 20 ]
61 echo -e "Creating schema set last status:\n $(curl -X 'POST' 'http://'"$hostIpAddress"':'"$CPS_CORE_PORT"''"$createSchemaSetBasePath"'' -H 'accept: */*' --form "file=@"/model/subscription.yang"" --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=')\n"
62 echo -e "Creating anchor last status:\n $(curl -X 'POST' 'http://'"$hostIpAddress"':'"$CPS_CORE_PORT"''"$createAnchorBasePath"'' -H 'accept: */*' --header 'Authorization: Basic Y3BzdXNlcjpjcHNyMGNrcyE=')\n"
63 echo -e "\nToo many attempts. Bye Bye!"
66 echo "RETRYING ...[ $ATTEMPT_COUNT attempt(s) ]"
67 ATTEMPT_COUNT=$(($ATTEMPT_COUNT +1))