Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
| 2 | |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 3 | def call(Map config) { |
| 4 | |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 5 | String iam = 'vars/setOnosLogLevels.groovy' |
| 6 | println("** ${iam}: ENTER") |
| 7 | |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 8 | def defaultConfig = [ |
| 9 | onosNamespace: "infra", |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 10 | apps: ['org.opencord.dhcpl2relay', 'org.opencord.olt', 'org.opencord.aaa'], |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 11 | logLevel: "DEBUG", |
| 12 | ] |
| 13 | |
| 14 | if (!config) { |
| 15 | config = [:] |
| 16 | } |
| 17 | |
| 18 | def cfg = defaultConfig + config |
| 19 | |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 20 | def onosInstances = sh ( |
| 21 | script: "kubectl get pods -n ${cfg.onosNamespace} -l app=onos-classic --no-headers | awk '{print \$1}'", |
| 22 | returnStdout: true |
| 23 | ).trim() |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 24 | |
| 25 | for(int i = 0;i<onosInstances.split( '\n' ).size();i++) { |
| 26 | def instance = onosInstances.split('\n')[i] |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 27 | println "Setting log levels on ${instance}" |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 28 | sh """ |
| 29 | _TAG="onos-pf" bash -c "while true; do kubectl port-forward -n ${cfg.onosNamespace} ${instance} 8101; done"& |
Matteo Scandolo | 5de1319 | 2021-11-22 11:24:12 -0800 | [diff] [blame] | 30 | ps aux | grep port-forward |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 31 | """ |
| 32 | |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 33 | for (int j = 0; j < cfg.apps.size(); j++) { |
| 34 | def app = cfg.apps[j] |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 35 | sh """ |
Matteo Scandolo | 64deaa9 | 2022-02-04 14:46:46 -0800 | [diff] [blame] | 36 | sshpass -p karaf ssh -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p 8101 karaf@localhost log:set ${cfg.logLevel} ${app} || true |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 37 | """ |
| 38 | } |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 39 | sh """ |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 40 | ps e -ww -A | grep _TAG="onos-pf" | grep -v grep | awk '{print \$1}' | xargs --no-run-if-empty kill -9 |
Matteo Scandolo | 5de1319 | 2021-11-22 11:24:12 -0800 | [diff] [blame] | 41 | ps aux | grep port-forward |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 42 | """ |
| 43 | } |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 44 | |
| 45 | println("** ${iam}: LEAVE") |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 46 | } |