aboutsummaryrefslogtreecommitdiffstats
path: root/operations/dcae/dcae.sh
blob: 31bb3345d3dd916d7c238ce816ad9ea8ea65c95a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/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.

#
# Onboard R-APP blueprint and deploy R-APP as DCAE Microservice.
#
set -e

NODE_IP=${NODE_IP:-$(../scripts/k8s_get_node_ip.sh)}
DCAE_DASHBOARD_NODEPORT=${DCAE_DASHBOARD_NODEPORT:-30418}
BASE_URL=https://${NODE_IP}:${DCAE_DASHBOARD_NODEPORT}

dcae_cli(){
    local parameters=("$@")
    python -u dcae-cli.py --base_url ${BASE_URL} --operation "${parameters[@]}"
}

create_blueprint() {
    local blueprint_file_path=$1
    dcae_cli create_blueprint --blueprint_file ${blueprint_file_path}
}

delete_blueprint() {
    local blueprint_name=$1
    local blueprint_id=$(dcae_cli get_blueprint --blueprint_name ${blueprint_name} | grep typeId | cut -d '"' -f 4)
    if [[ "$blueprint_id" != "" ]]; then
        dcae_cli delete_blueprint --blueprint_id ${blueprint_id}
    else
        echo "Given blueprint '$blueprint_name' does not exist!"
    fi
}

create_deployment() {
    local blueprint_id=$1
    local deployment_id=$2
    local deployment_id_prefix=$3
    local deployment_inputs_key_value=$4
    local deployment_inputs=""
    if [[ "$deployment_inputs_key_value" != "" ]]; then
        deployment_inputs="--deployment_inputs_key_value ${deployment_inputs_key_value}"
    fi
    dcae_cli create_deployment --blueprint_id ${blueprint_id} --deployment_id ${deployment_id} --deployment_id_prefix ${deployment_id_prefix} ${deployment_inputs}
}

deploy() {
    local blueprint_file_path=$1
    local deployment_id=$2
    local deployment_id_prefix=$3
    local deployment_inputs_key_value=$4
    out=$(create_blueprint ${blueprint_file_path})
    echo "$out"
    blueprint_id=$(echo "$out" | grep typeId | cut -d ' ' -f 2)
    create_deployment ${blueprint_id} ${deployment_id} ${deployment_id_prefix} ${deployment_inputs_key_value}
}

undeploy() {
    local deployment_id=$1
    dcae_cli delete_deployment --deployment_id ${deployment_id}
}

operation=$1
case "$operation" in
    -h|--help|help|?|"")
        echo "Script usage:"
        echo "$0 deploy - Deploy Blueprint"
        echo "$0 undeploy - Undeploy deployment instantiated from blueprint"
        echo "$0 redeploy - Redeploy deployment"
        echo "$0 delete - Delete blueprint"
        echo "$0 list - List blueprints and deployments"
        echo "$0 list_blueprints - List blueprints"
        echo "$0 list_deployments - List deployments"
        echo "$0 get_deployment_inputs - List all deployment input parameters given to a deployment"
        echo "$0 get_deployment_input - List only single deployment input value with given key."
        ;;
    deploy)
        blueprint_file_path=$2
        deployment_id=$3
        deployment_id_prefix=$4
        deployment_inputs_key_value=$5
        deploy ${blueprint_file_path} ${deployment_id} ${deployment_id_prefix} ${deployment_inputs_key_value}
        ;;
    undeploy)
        undeploy $2
       ;;
    redeploy)
        blueprint_file_path=$2
        deployment_id=$3
        deployment_inputs_key_value=$4
        undeploy ${deployment_id}
        # Note that deployment_id in creation does not have yet the prefix
        # Split full deployment id in format "myprefix_mydeploymentid" to prefix and id part
        deployment_id_prefix="${deployment_id%%_*}"
        deployment_id_for_create="${deployment_id#*_}"
        deploy ${blueprint_file_path} ${deployment_id_for_create} ${deployment_id_prefix} ${deployment_inputs_key_value}
       ;;
    delete)
        blueprint_name=$2
        delete_blueprint ${blueprint_name}
        ;;
    list)
        dcae_cli list_blueprints
        dcae_cli list_deployments
        ;;
    list_blueprints)
        dcae_cli list_blueprints
        ;;
    list_deployments)
        dcae_cli list_deployments
        ;;
    get_deployment_inputs)
        deployment_id=$2
        dcae_cli get_deployment_inputs --deployment_id ${deployment_id}
        ;;
    get_deployment_input)
        deployment_id=$2
        input_key=$3
        dcae_cli get_deployment_input --deployment_id ${deployment_id} --deployment_input_key ${input_key} | tail -1
        ;;
    *)
        echo "Wrong usage, check '$0 -h'" >&2
        exit 1
        ;;
esac