56376faa012ccc3fffd85be0067735d0838d2977
[it/dep.git] / nonrtric / bin / install
1 #!/bin/bash
2 ################################################################################
3 #   Copyright (c) 2020 Nordix Foundation.                                      #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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 ################################################################################
17
18
19 while [ -n "$1" ]; do # while loop starts
20
21     case "$1" in
22
23     -f) OVERRIDEYAML=$2
24         shift
25         ;;
26     -c) LIST_OF_COMPONENTS=$2
27         shift
28         ;;
29     *) echo "Option $1 not recognized" ;; # In case you typed a different option other than a,b,c
30
31     esac
32
33     shift
34
35 done
36
37
38 if [ -z "$OVERRIDEYAML" ];then
39     echo "****************************************************************************************************************"
40     echo "                                                     ERROR                                                      "
41     echo "****************************************************************************************************************"
42     echo "RIC deployment without deployment recipe is currently disabled. Please specify an recipe with the -f option."
43     echo "****************************************************************************************************************"
44     exit 1
45 fi
46
47
48 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
49
50 COMMON_BLOCK=$(cat $OVERRIDEYAML | awk '/^common:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}')
51 NAMESPACE_BLOCK=$(cat $OVERRIDEYAML | awk '/^  namespace:/{getline; while ($0 ~ /^    .*|^ *$/) {print $0; if (getline == 0) {break}}}')
52 NONRTRIC_NAMESPACE=$(echo "$NAMESPACE_BLOCK" | awk '/^ *nonrtric:/{print $2}')
53 RELEASE_PREFIX=$(echo "$COMMON_BLOCK" | awk '/^ *releasePrefix:/{print $2}')
54 SIMULATOR_BLOCK=$(cat $OVERRIDEYAML | awk '/^  simulatorinstance:/{getline; while ($0 ~ /^ +.*|^ *$/) {print $0; if (getline == 0) {break}}}')
55 SIMULATOR_COUNT=$(echo "$SIMULATOR_BLOCK" | awk '/^ *count:/{print $2}')
56 COMPONENTS=${LIST_OF_COMPONENTS:-"a1simulator policymanagementservice"}
57 echo "SIMULATOR_COUNT [$SIMULATOR_COUNT]"
58
59 if ! kubectl get ns ${NONRTRIC_NAMESPACE:-nonrtric}> /dev/null 2>&1; then
60     kubectl create ns ${NONRTRIC_NAMESPACE:-nonrtric}
61 fi
62 if ! kubectl get ns onap > /dev/null 2>&1; then
63     kubectl create ns onap
64 fi
65
66 kubectl create configmap -n ${NONRTRIC_NAMESPACE:-nonrtric} nonrtric-recipe --from-file=recipe=$OVERRIDEYAML
67
68 echo "Deploying NONRTRIC components [$COMPONENTS]"
69
70 for component in $COMPONENTS; do
71     helm dep up $DIR/../helm/$component
72     case "$component" in
73             a1simulator)
74                 for((i=1;i<=$SIMULATOR_COUNT;i++)) ; do
75                     echo "CREATING SIMUALATOR INSTANCE $i"
76                     helm install -f $OVERRIDEYAML --namespace "${NONRTRIC_NAMESPACE:-nonrtric}" --name "${RELEASE_PREFIX}-$component-$i" --set a1simulator.instanceName=a1-sim-$i $DIR/../helm/$component
77                 done
78             ;;
79             *)
80                 helm install -f $OVERRIDEYAML --namespace "${NONRTRIC_NAMESPACE:-nonrtric}" --name "${RELEASE_PREFIX}-$component" $DIR/../helm/$component
81
82     esac
83
84 done