blob: cc0b5c1b995338085bb4c3a862778e3ab4d75761 [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.lifecycle.Service;
19import org.apache.karaf.shell.api.console.CommandLine;
20import org.apache.karaf.shell.api.console.Completer;
21import org.apache.karaf.shell.api.console.Session;
22import org.apache.karaf.shell.support.completers.StringsCompleter;
23import org.onosproject.openstacktelemetry.api.TelemetryConfigService;
24import org.onosproject.openstacktelemetry.api.config.TelemetryConfig;
25
26import java.util.Comparator;
27import java.util.List;
28import java.util.Set;
29import java.util.SortedSet;
30import java.util.stream.Collectors;
31
32import static org.onosproject.cli.AbstractShellCommand.get;
33
34/**
35 * Telemetry configuration property completer.
36 */
37@Service
38public class TelemetryConfigNameCompleter implements Completer {
39
40 private static final String MASTER = "master";
41
42 @Override
43 public int complete(Session session, CommandLine commandLine, List<String> candidates) {
44 StringsCompleter delegate = new StringsCompleter();
45 TelemetryConfigService service = get(TelemetryConfigService.class);
46
47 Set<String> set = service.getConfigs().stream()
48 .filter(c -> !c.swVersion().equals(MASTER))
49 .sorted(Comparator.comparing(TelemetryConfig::name))
50 .map(TelemetryConfig::name)
51 .collect(Collectors.toSet());
52
53 SortedSet<String> strings = delegate.getStrings();
54 strings.addAll(set);
55 return delegate.complete(session, commandLine, candidates);
56 }
57}