k.kedron | 81554bc | 2021-04-26 09:22:57 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright (C) 2019 by Samsung Electronics Co., Ltd. |
| 3 | # |
| 4 | # This software is the confidential and proprietary information of Samsung Electronics co., Ltd. |
| 5 | # ("Confidential Information"). You shall not disclose such Confidential Information and shall use |
| 6 | # it only in accordance with the terms of the license agreement you entered into with Samsung. |
| 7 | |
| 8 | set -e |
| 9 | |
| 10 | BLUEPRINTS_DIR=${BLUEPRINTS_DIR:-blueprints} |
| 11 | DEPLOYMENT_ID_PREFIX=${DEPLOYMENT_ID_PREFIX:-"samsung"} |
| 12 | |
| 13 | declare -a rapp_blueprint_files=( |
| 14 | ${BLUEPRINTS_DIR}/k8s-datacollector.yaml |
| 15 | ${BLUEPRINTS_DIR}/k8s-sleepingcelldetector.yaml |
| 16 | ) |
| 17 | |
| 18 | # Define deployment id names for rapps |
| 19 | declare -a rapp_deployment_ids=( |
| 20 | rapp-datacollector |
| 21 | rapp-sleepingcelldetector |
| 22 | ) |
| 23 | |
| 24 | exec_over_rapps() { |
| 25 | local action_func=$1 |
| 26 | local rapp_filter=$2 |
| 27 | for i in "${!rapp_blueprint_files[@]}" |
| 28 | do |
| 29 | if [[ "${DEPLOYMENT_ID_PREFIX}_${rapp_deployment_ids[$i]}" == *"$rapp_filter"* ]]; then |
| 30 | $action_func ${rapp_blueprint_files[$i]} ${rapp_deployment_ids[$i]} |
| 31 | fi |
| 32 | done |
| 33 | } |
| 34 | |
| 35 | operation=$1 |
| 36 | case "$operation" in |
| 37 | -h|--help|help|?|"") |
| 38 | echo "Script usage:" |
| 39 | echo "$0 deploy - Deploy rapp(s)" |
| 40 | echo "$0 undeploy - Undeploy rapp(s)" |
| 41 | echo "$0 redeploy - Redeploy rapp(s)" |
| 42 | echo "$0 list - List rapps properties" |
| 43 | echo |
| 44 | echo "BLUEPRINTS_DIR and DEPLOYMENT_ID_PREFIX variables can be exported to override default value." |
| 45 | echo "BLUEPRINTS_DIR default value is 'blueprints'." |
| 46 | echo "DEPLOYMENT_ID_PREFIX is a string prefixed to given deployment_id in the deploy operation." |
| 47 | echo "In other operations prefixed form is used. DEPLOYMENT_ID_PREFIX default value is 'samsung'." |
| 48 | ;; |
| 49 | deploy) |
| 50 | rapp_filter=$2 |
| 51 | # Create inputs. Currently the only input to be provided is database password and that is only |
| 52 | # applicable for datacollector r-app at the moment; |
k.kedron | 107d71b | 2021-06-25 14:39:39 +0200 | [diff] [blame] | 53 | if [[ -z ${DATABASE_PASSWORD:-} ]]; then |
| 54 | echo "DATABASE_PASSWORD value is missing!" |
| 55 | echo "Run: " |
| 56 | echo "\"kubectl get secret \`kubectl get secrets | grep mariadb-galera-db-root-password | awk '{print \$1}'\` -o jsonpath="{.data.password}" | base64 --decode\" in the ONAP k8s" |
| 57 | echo "and after that export DATABASE_PASSWORD=\${command_out}" |
| 58 | exit 1 |
| 59 | fi |
| 60 | |
k.kedron | 81554bc | 2021-04-26 09:22:57 +0200 | [diff] [blame] | 61 | deployment_inputs="database_password=${DATABASE_PASSWORD}" |
| 62 | do_deploy() { |
| 63 | local blueprint_file=$1 |
| 64 | local deployment_id=$2 |
| 65 | if [[ "${deployment_id}" != "rapp-datacollector" ]]; then |
| 66 | deployment_inputs="" |
| 67 | fi |
| 68 | ./dcae.sh deploy "${blueprint_file}" "${deployment_id}" "${DEPLOYMENT_ID_PREFIX}" "${deployment_inputs}" |
| 69 | } |
| 70 | exec_over_rapps do_deploy ${rapp_filter} |
| 71 | ./dcae.sh list |
| 72 | ;; |
| 73 | undeploy) |
| 74 | rapp_filter=$2 |
| 75 | do_undeploy() { |
| 76 | local blueprint_file=$1 |
| 77 | local deployment_id=$2 |
| 78 | ./dcae.sh undeploy ${DEPLOYMENT_ID_PREFIX}_${deployment_id} |
| 79 | ./dcae.sh delete $(basename ${blueprint_file} | cut -d'.' -f1) |
| 80 | } |
| 81 | exec_over_rapps do_undeploy ${rapp_filter} |
| 82 | ./dcae.sh list |
| 83 | ;; |
| 84 | redeploy) |
| 85 | rapp_filter=$2 |
| 86 | deployment_inputs_key_value=$3 |
| 87 | do_redeploy() { |
| 88 | local blueprint_file=$1 |
| 89 | local deployment_id=$2 |
| 90 | ./dcae.sh redeploy "${blueprint_file}" "${DEPLOYMENT_ID_PREFIX}_${deployment_id}" "${deployment_inputs_key_value}" |
| 91 | } |
| 92 | exec_over_rapps do_redeploy ${rapp_filter} |
| 93 | ./dcae.sh list |
| 94 | ;; |
| 95 | get_deployment_input) |
| 96 | property=$2 |
| 97 | rapp_filter=$3 |
| 98 | do_input() { |
| 99 | local blueprint_file=$1 |
| 100 | local deployment_id=$2 |
| 101 | local full_id=${DEPLOYMENT_ID_PREFIX}_${deployment_id} |
| 102 | echo "${full_id}" "$(./dcae.sh get_deployment_input ${full_id} ${property})" |
| 103 | } |
| 104 | exec_over_rapps do_input ${rapp_filter} |
| 105 | ;; |
| 106 | *) |
| 107 | echo "Wrong usage, check '$0 -h'" >&2 |
| 108 | exit 1 |
| 109 | ;; |
| 110 | esac |