ab0b27b916d520a3200356933c23729e690662df
[policy/docker.git] / csit / resources / scripts / get-cluster-info.sh
1 #!/bin/bash
2 # ============LICENSE_START=======================================================
3 #  Copyright (C) 2023 Nordix Foundation. 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
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 # SPDX-License-Identifier: Apache-2.0
18 # ============LICENSE_END=========================================================
19
20 # This script will be used to gather cluster information
21 # for JMeter to work towards the installed cluster
22
23 # EXPLICITLY ASSIGN PORTS FOR TESTING PURPOSES
24 export APEX_PORT=30001
25 export API_PORT=30002
26 export PAP_PORT=30003
27 export XACML_PORT=30004
28 export DROOLS_PORT=30005
29 export DIST_PORT=30006
30 export ACM_PORT=30007
31 export POLICY_PF_PARTICIPANT_PORT=30008
32 export POLICY_HTTP_PARTICIPANT_PORT=30009
33 export POLICY_K8S_PARTICIPANT_PORT=30010
34 export SIMULATOR_PORT=30904
35
36 # Retrieve pod names
37 function get_pod_names() {
38   export APEX_POD=$(get_pod_name apex)
39   export PAP_POD=$(get_pod_name pap)
40   export API_POD=$(get_pod_name api)
41   export DMAAP_POD=$(get_pod_name message-router)
42   export XACML_POD=$(get_pod_name xacml)
43   export DROOLS_POD=$(get_pod_name drools-pdp)
44   export DIST_POD=$(get_pod_name distribution)
45   export ACM_POD=$(get_pod_name acm-runtime)
46   export POLICY_PPNT_POD=$(get_pod_name policy-ppnt)
47   export POLICY_PPNT_POD=$(get_pod_name http-ppnt)
48   export POLICY_PPNT_POD=$(get_pod_name k8s-ppnt)
49 }
50
51 # Retrieve service names
52 function get_svc_names() {
53   export APEX_SVC=$(get_svc_name policy-apex-pdp)
54   export PAP_SVC=$(get_svc_name policy-pap)
55   export API_SVC=$(get_svc_name policy-api)
56   export DMAAP_SVC=$(get_svc_name message-router)
57   export DROOLS_SVC=$(get_svc_name drools-pdp)
58   export XACML_SVC=$(get_svc_name policy-xacml-pdp)
59   export DIST_SVC=$(get_svc_name policy-distribution)
60   export ACM_SVC=$(get_svc_name policy-clamp-runtime-acm)
61   export POLICY_PPNT_SVC=$(get_svc_name policy-clamp-ac-pf-ppnt)
62   export POLICY_HTTP_SVC=$(get_svc_name policy-clamp-ac-http-ppnt)
63   export POLICY_K8S_SVC=$(get_svc_name policy-clamp-ac-k8s-ppnt)
64 }
65
66 # Expose services in order to perform tests from JMeter
67 function expose_services() {
68     expose_service $APEX_SVC
69     expose_service $PAP_SVC
70     expose_service $API_SVC
71     expose_service $XACML_SVC
72     expose_service $DROOLS_SVC
73     expose_service $DIST_SVC
74     expose_service $ACM_SVC
75     expose_service $POLICY_PPNT_SVC
76     expose_service POLICY_HTTP_SVC
77     expose_service POLICY_K8S_SVC
78
79     setup_message_router_svc
80     sleep 2
81     patch_ports
82 }
83
84 function get_pod_name() {
85   microk8s kubectl get pods --no-headers -o custom-columns=':metadata.name' | grep $1
86 }
87
88 function get_svc_name() {
89   microk8s kubectl get svc --no-headers -o custom-columns=':metadata.name' | grep $1
90 }
91
92 function expose_service() {
93   microk8s kubectl expose service $1 --name $1"-svc" --type NodePort --protocol TCP --port 6969 --target-port 6969
94 }
95
96 function patch_port() {
97   microk8s kubectl patch service "$1-svc" --namespace=default --type='json' --patch='[{"op": "replace", "path": "/spec/ports/0/nodePort", "value":'"$2"'}]'
98 }
99
100 # Assign set port values
101 function patch_ports() {
102   patch_port "$APEX_SVC" $APEX_PORT
103   patch_port "$API_SVC" $API_PORT
104   patch_port "$PAP_SVC" $PAP_PORT
105   patch_port "$ACM_SVC" $ACM_PORT
106   patch_port "$POLICY_PPNT_SVC" $POLICY_PF_PARTICIPANT_PORT
107   patch_port "$HTTP_PPNT_SVC" $POLICY_HTTP_PARTICIPANT_PORT
108   patch_port "$K8S_PPNT_SVC" $POLICY_K8S_PARTICIPANT_PORT
109   patch_port "$DIST_SVC" $DIST_PORT
110   patch_port "$DROOLS_SVC" $DROOLS_PORT
111   patch_port "$XACML_SVC" $XACML_PORT
112 }
113
114 function setup_message_router_svc() {
115   microk8s kubectl expose service message-router --name message-router-svc --type NodePort --protocol TCP --port 3904 --target-port 3904
116   microk8s kubectl patch service message-router-svc --namespace=default --type='json' --patch='[{"op": "replace", "path": "/spec/ports/0/nodePort", "value":'"$SIMULATOR_PORT"'}]'
117 }
118
119 ####MAIN###
120 get_pod_names
121 get_svc_names
122 expose_services