Thomas Vachuska
Committed by Gerrit Code Review

Adding command to list mapping between intent class and compiler

Change-Id: Ie85801b6e924d8bf119d77a7dddd12020b2b1320
1 +/*
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 + */
16 +package org.onosproject.cli.net;
17 +
18 +import org.apache.karaf.shell.commands.Command;
19 +import org.onosproject.cli.AbstractShellCommand;
20 +import org.onosproject.net.intent.IntentExtensionService;
21 +
22 +import java.util.OptionalInt;
23 +
24 +/**
25 + * Lists the inventory of intents and their states.
26 + */
27 +@Command(scope = "onos", name = "intent-compilers",
28 + description = "Lists the mapping from intent type to compiler component")
29 +public class IntentListCompilers extends AbstractShellCommand {
30 +
31 + @Override
32 + protected void execute() {
33 + IntentExtensionService service = get(IntentExtensionService.class);
34 + OptionalInt length = service.getCompilers().keySet().stream()
35 + .mapToInt(s -> s.getName().length())
36 + .max();
37 + if (length.isPresent()) {
38 + service.getCompilers().entrySet().forEach(e -> {
39 + print("%-" + length.getAsInt() + "s\t%s",
40 + e.getKey().getName(),
41 + e.getValue().getClass().getName());
42 + });
43 + } else {
44 + print("There are no compilers registered.");
45 + }
46 +
47 + }
48 +}
...@@ -218,6 +218,9 @@ ...@@ -218,6 +218,9 @@
218 <action class="org.onosproject.cli.net.IntentsListCommand"/> 218 <action class="org.onosproject.cli.net.IntentsListCommand"/>
219 </command> 219 </command>
220 <command> 220 <command>
221 + <action class="org.onosproject.cli.net.IntentListCompilers"/>
222 + </command>
223 + <command>
221 <action class="org.onosproject.cli.net.IntentRemoveCommand"/> 224 <action class="org.onosproject.cli.net.IntentRemoveCommand"/>
222 <completers> 225 <completers>
223 <ref component-id="appIdWithIntentNameCompleter"/> 226 <ref component-id="appIdWithIntentNameCompleter"/>
......