blob: ab063a01f1f647ad05f46db685b8f3075ef6077a [file] [log] [blame]
Jian Li85060ac2016-02-04 09:58:56 -08001/*
2 * Copyright 2016 Open Networking Laboratory
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.cpman.cli;
17
18import org.apache.karaf.shell.console.completer.ArgumentCompleter;
19import org.apache.karaf.shell.console.completer.StringsCompleter;
20import org.onosproject.cli.AbstractCompleter;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.cpman.ControlPlaneMonitorService;
23
24import java.util.List;
25import java.util.Set;
26import java.util.SortedSet;
27
28import static org.onosproject.cpman.ControlResource.Type;
29
30/**
31 * Device identification completer for control plane manager.
32 */
33public class ControlMessageDeviceIdCompleter extends AbstractCompleter {
34 @Override
35 public int complete(String buffer, int cursor, List<String> candidates) {
36 // delegate string completer
37 StringsCompleter delegate = new StringsCompleter();
38
39 // Resource type is the second argument.
40 ArgumentCompleter.ArgumentList list = getArgumentList();
41 String type = list.getArguments()[1];
42
43 if (Type.CONTROL_MESSAGE.toString().toLowerCase().equals(type)) {
44 ControlPlaneMonitorService monitorService =
45 AbstractShellCommand.get(ControlPlaneMonitorService.class);
46
47 Set<String> set = monitorService.availableResources(Type.CONTROL_MESSAGE);
48
49 SortedSet<String> strings = delegate.getStrings();
50 if (set != null) {
51 set.forEach(s -> strings.add(s));
52 }
53 }
54 return delegate.complete(buffer, cursor, candidates);
55 }
56}