Jian Li | 69600e0 | 2018-12-24 13:21:18 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.openstacktelemetry.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.api.action.Command; |
| 19 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 20 | import org.onosproject.cli.AbstractShellCommand; |
| 21 | import org.onosproject.openstacktelemetry.api.TelemetryConfigService; |
| 22 | import org.onosproject.openstacktelemetry.api.config.TelemetryConfig; |
| 23 | |
| 24 | import java.util.Comparator; |
| 25 | import java.util.List; |
| 26 | import java.util.stream.Collectors; |
| 27 | |
| 28 | /** |
| 29 | * Lists Telemetry configurations. |
| 30 | */ |
| 31 | @Service |
| 32 | @Command(scope = "onos", name = "telemetry-configs", |
| 33 | description = "Lists all Telemetry configurations") |
| 34 | public class TelemetryConfigListCommand extends AbstractShellCommand { |
| 35 | |
| 36 | private static final String FORMAT = "%-30s%-15s%-15s%-30s%-15s"; |
| 37 | private static final String MASTER = "master"; |
| 38 | |
| 39 | @Override |
| 40 | protected void doExecute() { |
| 41 | TelemetryConfigService service = get(TelemetryConfigService.class); |
| 42 | List<TelemetryConfig> configs = service.getConfigs().stream() |
| 43 | .filter(c -> !c.swVersion().equals(MASTER)) |
| 44 | .sorted(Comparator.comparing(TelemetryConfig::type)) |
| 45 | .collect(Collectors.toList()); |
| 46 | |
| 47 | print(FORMAT, "Name", "Type", "Enabled", "Manufacturer", "swVersion"); |
| 48 | for (TelemetryConfig config : configs) { |
| 49 | print(FORMAT, config.name(), |
| 50 | config.type(), |
| 51 | config.enabled() ? "ENABLED" : "DISABLED", |
| 52 | config.manufacturer(), |
| 53 | config.swVersion()); |
| 54 | } |
| 55 | } |
| 56 | } |