diff options
Diffstat (limited to 'operations/dcae/rapps.sh')
-rw-r--r-- | operations/dcae/rapps.sh | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/operations/dcae/rapps.sh b/operations/dcae/rapps.sh new file mode 100644 index 0000000..9af8284 --- /dev/null +++ b/operations/dcae/rapps.sh @@ -0,0 +1,103 @@ +#!/bin/bash +# Copyright (C) 2019 by Samsung Electronics Co., Ltd. +# +# This software is the confidential and proprietary information of Samsung Electronics co., Ltd. +# ("Confidential Information"). You shall not disclose such Confidential Information and shall use +# it only in accordance with the terms of the license agreement you entered into with Samsung. + +set -e + +BLUEPRINTS_DIR=${BLUEPRINTS_DIR:-blueprints} +DEPLOYMENT_ID_PREFIX=${DEPLOYMENT_ID_PREFIX:-"samsung"} + +declare -a rapp_blueprint_files=( + ${BLUEPRINTS_DIR}/k8s-datacollector.yaml + ${BLUEPRINTS_DIR}/k8s-sleepingcelldetector.yaml +) + +# Define deployment id names for rapps +declare -a rapp_deployment_ids=( + rapp-datacollector + rapp-sleepingcelldetector +) + +exec_over_rapps() { + local action_func=$1 + local rapp_filter=$2 + for i in "${!rapp_blueprint_files[@]}" + do + if [[ "${DEPLOYMENT_ID_PREFIX}_${rapp_deployment_ids[$i]}" == *"$rapp_filter"* ]]; then + $action_func ${rapp_blueprint_files[$i]} ${rapp_deployment_ids[$i]} + fi + done +} + +operation=$1 +case "$operation" in + -h|--help|help|?|"") + echo "Script usage:" + echo "$0 deploy - Deploy rapp(s)" + echo "$0 undeploy - Undeploy rapp(s)" + echo "$0 redeploy - Redeploy rapp(s)" + echo "$0 list - List rapps properties" + echo + echo "BLUEPRINTS_DIR and DEPLOYMENT_ID_PREFIX variables can be exported to override default value." + echo "BLUEPRINTS_DIR default value is 'blueprints'." + echo "DEPLOYMENT_ID_PREFIX is a string prefixed to given deployment_id in the deploy operation." + echo "In other operations prefixed form is used. DEPLOYMENT_ID_PREFIX default value is 'samsung'." + ;; + deploy) + rapp_filter=$2 + # Create inputs. Currently the only input to be provided is database password and that is only + # applicable for datacollector r-app at the moment; + . ./inputs_database_password.sh + deployment_inputs="database_password=${DATABASE_PASSWORD}" + do_deploy() { + local blueprint_file=$1 + local deployment_id=$2 + if [[ "${deployment_id}" != "rapp-datacollector" ]]; then + deployment_inputs="" + fi + ./dcae.sh deploy "${blueprint_file}" "${deployment_id}" "${DEPLOYMENT_ID_PREFIX}" "${deployment_inputs}" + } + exec_over_rapps do_deploy ${rapp_filter} + ./dcae.sh list + ;; + undeploy) + rapp_filter=$2 + do_undeploy() { + local blueprint_file=$1 + local deployment_id=$2 + ./dcae.sh undeploy ${DEPLOYMENT_ID_PREFIX}_${deployment_id} + ./dcae.sh delete $(basename ${blueprint_file} | cut -d'.' -f1) + } + exec_over_rapps do_undeploy ${rapp_filter} + ./dcae.sh list + ;; + redeploy) + rapp_filter=$2 + deployment_inputs_key_value=$3 + do_redeploy() { + local blueprint_file=$1 + local deployment_id=$2 + ./dcae.sh redeploy "${blueprint_file}" "${DEPLOYMENT_ID_PREFIX}_${deployment_id}" "${deployment_inputs_key_value}" + } + exec_over_rapps do_redeploy ${rapp_filter} + ./dcae.sh list + ;; + get_deployment_input) + property=$2 + rapp_filter=$3 + do_input() { + local blueprint_file=$1 + local deployment_id=$2 + local full_id=${DEPLOYMENT_ID_PREFIX}_${deployment_id} + echo "${full_id}" "$(./dcae.sh get_deployment_input ${full_id} ${property})" + } + exec_over_rapps do_input ${rapp_filter} + ;; + *) + echo "Wrong usage, check '$0 -h'" >&2 + exit 1 + ;; +esac |