2 # ============LICENSE_START=======================================================
3 # Copyright (c) 2019-2020 AT&T Intellectual Property. All rights reserved.
4 # ================================================================================
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # ============LICENSE_END=========================================================
17 # Runs at deployment time to load the plugins/type files
18 # that were stored into the container file system at build time
20 PLUGINS_LOADED=/opt/manager/plugins-loaded
21 PLUGIN_DIR=/opt/plugins
23 # Set defaults for CM address, protocol, and port
24 CMADDR=${CMADDR:-dcae-cloudify-manager}
25 CMPROTO=${CMPROTO:-https}
28 # Password is currently fixed at the default
29 # Eventually the password will be passed in as an environment variable
30 CMPASS=${CMPASS:-admin}
32 # Set up additional parameters for using HTTPS
33 CACERT="/opt/onap/certs/cacert.pem"
35 if [ $CMPROTO = "https" ]
37 CURLTLS="--cacert $CACERT"
40 ### FUNCTION DEFINITIONS ###
42 # cm_hasany: Query Cloudify Manager and return 0 (true) if there are any entities matching the query
43 # Used to see if something is already present on CM
44 # $1 -- query fragment, for instance "plugins?archive_name=xyz.wgn" to get
45 # the number of plugins that came from the archive file "xyz.wgn"
47 # We use _include=id to limit the amount of data the CM sends back
48 # We rely on the "metadata.pagination.total" field in the response
49 # for the total number of matching entities
50 COUNT=$(curl -Ss -H "Tenant: default_tenant" --user admin:${CMPASS} ${CURLTLS} "${CMPROTO}://${CMADDR}:${CMPORT}/api/v3.1/$1&_include=id" \
51 | /bin/jq .metadata.pagination.total)
60 # Install plugin if it's not already installed
61 # $1 -- path to wagon file for plugin
62 # $2 -- path to type file for plugin
63 function install_plugin {
64 ARCHIVE=$(basename $1)
65 # See if it's already installed
66 if cm_hasany "plugins?archive_name=$ARCHIVE"
68 echo plugin $1 already installed on ${CMADDR}
70 cfy plugin upload -y $2 $1
74 ### END FUNCTION DEFINTIONS ###
79 # Wait for Cloudify Manager to come up
80 while ! /scripts/cloudify-ready.sh
82 echo "Waiting for CM to come up"
86 if [[ ! -f ${PLUGINS_LOADED} ]]
89 # Each subdirectory of ${PLUGIN_DIR} contains a wagon (.wgn) and type file (.yaml)
90 for p in ${PLUGIN_DIR}/*
92 # Expecting exactly 1 .wgn and 1 .yaml
93 # But just in case, taking only the first of each
94 # (If either is missing, will fail on install_plugin)
97 install_plugin ${wagons[0]} ${types[0]}
100 touch ${PLUGINS_LOADED}
102 echo "Plugins already loaded"