2d55a3053c937d8e4c971633c74d14ebe31132d2
[ric-app/mc.git] / mc-core / mc / queries / generate_runall.py
1 # ------------------------------------------------
2 #Copyright 2020 AT&T Intellectual Property
3 #   Licensed under the Apache License, Version 2.0 (the "License");
4 #   you may not use this file except in compliance with the License.
5 #   You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #   Unless required by applicable law or agreed to in writing, software
10 #   distributed under the License is distributed on an "AS IS" BASIS,
11 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 #   See the License for the specific language governing permissions and
13 #   limitations under the License.
14 # ------------------------------------------- 
15
16 import xml.etree.ElementTree as ET
17 import json
18 from optparse import OptionParser
19 import sys
20 import os
21
22
23
24 optparser = OptionParser(usage="usage: %prog [options] path_file [path_file*]")
25 optparser.add_option("-Q", "--querydir", dest="querydir",
26                  default=".",help="directory with qtree.xml and output_spec.cfg" )
27 (options, args) = optparser.parse_args()
28
29 odoc = ""
30
31 nibflnm = options.querydir+"/nib.json"
32 nibfl = open(nibflnm, "r")
33 nib = json.load(nibfl)
34 nibfl.close()
35
36 osflnm = options.querydir+"/output_spec.cfg"
37 osfl = open(osflnm, "r")
38 oqy = {}
39 for line in osfl:
40         flds = line.split(",")
41         oqy[flds[0]]=1
42
43 runall = """
44 #!/bin/bash
45
46 # -------------------------------------------------------------------------------
47 #    Copyright (c) 2018-2019 AT&T Intellectual Property.
48 #
49 #   Licensed under the Apache License, Version 2.0 (the "License");
50 #   you may not use this file except in compliance with the License.
51 #   You may obtain a copy of the License at
52 #
53 #       http://www.apache.org/licenses/LICENSE-2.0
54 #
55 #   Unless required by applicable law or agreed to in writing, software
56 #   distributed under the License is distributed on an "AS IS" BASIS,
57 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
58 #   See the License for the specific language governing permissions and
59 #   limitations under the License.
60 # -------------------------------------------------------------------------------
61
62 set -m
63
64 FIFO_DIR="/tmp/mcl/fifos"
65
66 SIMULATOR_MODE=`python /mc/extract_params.py $XAPP_DESCRIPTOR_PATH simulator_mode`
67
68 DEBUG_MODE=`python /mc/extract_params.py $XAPP_DESCRIPTOR_PATH debug_mode`
69
70 WINDOW=`python /mc/extract_params.py $XAPP_DESCRIPTOR_PATH measurement_interval`
71
72 # export DBAAS_SERVICE_HOST=`python /mc/extract_params.py $XAPP_DESCRIPTOR_PATH __DBAAS_SERVICE_HOST__`
73 # export DBAAS_SERVICE_PORT=`python /mc/extract_params.py $XAPP_DESCRIPTOR_PATH __DBAAS_SERVICE_PORT__`
74
75 if [ "$SIMULATOR_MODE" = "true" ]
76 then
77         mkdir -p $FIFO_DIR
78         python /mc/data_gen/dc_gen.py &
79         python /mc/data_gen/rrcx_gen.py &
80 fi
81
82 if [ "$WINDOW" = "" ]
83 then
84         WINDOW="10000"
85 fi
86
87 VES_COLLECTOR=`python /mc/extract_params.py $XAPP_DESCRIPTOR_PATH ves_collector_address`
88
89 VES_NAME=`echo $VES_COLLECTOR | awk 'BEGIN{FS=":"} {print $1}'`
90 VES_PORT=`echo $VES_COLLECTOR | awk 'BEGIN{FS=":"} {print $2}'`
91 VES_IP=`getent ahosts $VES_NAME | awk '{ print $1; exit }'`
92
93 echo "Clearing MC NIB namespace" >&2
94 /mc/gs-lite/bin/mc_clear >&2
95
96 echo "Storing MC NIB schemas" >&2
97 /mc/gs-lite/bin/mc_store_schema >&2
98
99 ./runit
100 sleep 1
101
102 """
103
104 debug_q = ""
105 for q in oqy:
106         if "debug" in q:
107                 debug_q += "\t/mc/gs-lite/bin/gsprintconsole -e `cat gshub.log` default "+q+" window=$WINDOW &\n"
108
109 if len(debug_q)>0:
110         runall += """
111 if [ "$DEBUG_MODE" = "true" ]
112 then
113     # invoke gsprintconsole for all the queries with debug in their name
114 """
115         runall += debug_q
116         runall += """
117 fi
118 """
119
120 runall += """
121
122 # invoke gsprintconsole_ves gsmcnib for all non-debug queries
123 """
124
125 for q in oqy:
126         if "debug" not in q:
127                 runall += " /mc/gs-lite/bin/gsprintconsole_ves -C $VES_IP:$VES_PORT -U /vescollector/eventListener/v7 -V 7 `cat gshub.log` default "+q+" window=$WINDOW &\n"
128                 keys = nib[q]["keys"]
129                 if len(keys)>0:
130                         keys_str = ",".join(keys)
131                         runall += " /mc/gs-lite/bin/gsmcnib -K "+keys_str+" `cat gshub.log` default "+q+" window=$WINDOW &\n"
132                 else:
133                         runall += " /mc/gs-lite/bin/gsmcnib `cat gshub.log` default "+q+" window=$WINDOW &\n"
134
135 runall += """
136
137 sleep 1
138 bash /mc/gs-lite/bin/start_processing
139 fg %1
140 """
141
142 rflnm = options.querydir+"/runall"
143 rfl = open(rflnm, "w")
144 rfl.write(runall)
145 rfl.close()
146
147 cmd = "chmod +x "+rflnm
148 sys.stderr.write("Executing "+cmd+"\n")
149 ret = os.system(cmd)
150 if ret != 0:
151         sys.stderr.write("Error executing "+cmd+"\n")
152         exit(1)
153 exit(0)