blob: f1e282a08545dba8757b57cf31333d24b852b6c8 [file] [log] [blame]
Jian Li16f1f532018-12-27 17:45:09 +09001/*
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 */
16package org.onosproject.openstacktelemetry.cli;
17
18import org.apache.karaf.shell.api.action.Argument;
19import org.apache.karaf.shell.api.action.Command;
20import org.apache.karaf.shell.api.action.Completion;
21import org.apache.karaf.shell.api.action.lifecycle.Service;
22import org.onosproject.cli.AbstractShellCommand;
23import org.onosproject.openstacktelemetry.api.TelemetryConfigService;
24import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
25
26import java.util.SortedSet;
27import java.util.TreeSet;
28
29/**
30 * Queries the detailed information of telemetry config.
31 */
32@Service
33@Command(scope = "onos", name = "telemetry-config",
34 description = "Query a specific telemetry configuration")
35public class TelemetryConfigViewCommand extends AbstractShellCommand {
36
37 @Argument(index = 0, name = "config name", description = "telemetry config name",
38 required = true, multiValued = false)
39 @Completion(TelemetryConfigNameCompleter.class)
40 private String configName = null;
41
42 private static final String FORMAT = "%25s : %s";
43 private static final String NO_ELEMENT =
44 "No telemetry config is found with the given name";
45
46 @Override
47 protected void doExecute() {
48 TelemetryConfigService service = get(TelemetryConfigService.class);
49 TelemetryConfig config = service.getConfig(configName);
50
51 if (config == null) {
52 print(NO_ELEMENT);
53 return;
54 }
55
56 SortedSet<String> keys = new TreeSet<>(config.properties().keySet());
57
58 keys.forEach(k -> {
59 print(FORMAT, k, config.properties().get(k));
60 });
61 }
62}