Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 2 | // ----------------------------------------------------------------------- |
Joey Armstrong | 518f357 | 2024-02-11 07:56:25 -0500 | [diff] [blame] | 3 | // Copyright 2021-2024 Open Networking Foundation (ONF) and the ONF Contributors |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 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 | // ----------------------------------------------------------------------- |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 17 | |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 18 | def call(Map config) { |
| 19 | |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 20 | String iam = 'vars/setOnosLogLevels.groovy' |
| 21 | println("** ${iam}: ENTER") |
| 22 | |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 23 | def defaultConfig = [ |
| 24 | onosNamespace: "infra", |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 25 | apps: ['org.opencord.dhcpl2relay', 'org.opencord.olt', 'org.opencord.aaa'], |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 26 | logLevel: "DEBUG", |
| 27 | ] |
| 28 | |
| 29 | if (!config) { |
| 30 | config = [:] |
| 31 | } |
| 32 | |
| 33 | def cfg = defaultConfig + config |
| 34 | |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 35 | def onosInstances = sh ( |
| 36 | script: "kubectl get pods -n ${cfg.onosNamespace} -l app=onos-classic --no-headers | awk '{print \$1}'", |
| 37 | returnStdout: true |
| 38 | ).trim() |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 39 | |
| 40 | for(int i = 0;i<onosInstances.split( '\n' ).size();i++) { |
| 41 | def instance = onosInstances.split('\n')[i] |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 42 | println "Setting log levels on ${instance}" |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 43 | sh """ |
| 44 | _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] | 45 | ps aux | grep port-forward |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 46 | """ |
| 47 | |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 48 | for (int j = 0; j < cfg.apps.size(); j++) { |
| 49 | def app = cfg.apps[j] |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 50 | sh """ |
Matteo Scandolo | 64deaa9 | 2022-02-04 14:46:46 -0800 | [diff] [blame] | 51 | 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] | 52 | """ |
| 53 | } |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 54 | sh """ |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 55 | 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] | 56 | ps aux | grep port-forward |
Matteo Scandolo | 857376b | 2021-11-05 14:53:22 -0700 | [diff] [blame] | 57 | """ |
| 58 | } |
Joey Armstrong | 96158a9 | 2022-11-25 10:36:06 -0500 | [diff] [blame] | 59 | |
| 60 | println("** ${iam}: LEAVE") |
Matteo Scandolo | 0810f06 | 2021-11-04 16:42:56 -0700 | [diff] [blame] | 61 | } |
Joey Armstrong | af679da | 2023-01-31 14:22:41 -0500 | [diff] [blame] | 62 | |
| 63 | // [EOF] |