blob: d920eec18171be0430435b98016bd4e560b0d477 [file] [log] [blame]
Thomas Vachuskacdac6e82016-02-29 19:21:49 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Thomas Vachuskacdac6e82016-02-29 19:21:49 -08003 *
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.cli.net;
17
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.apache.karaf.shell.api.action.Command;
19import org.apache.karaf.shell.api.action.lifecycle.Service;
Thomas Vachuskacdac6e82016-02-29 19:21:49 -080020import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.net.intent.IntentExtensionService;
22
23import java.util.OptionalInt;
24
25/**
26 * Lists the inventory of intents and their states.
27 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070028@Service
Thomas Vachuskacdac6e82016-02-29 19:21:49 -080029@Command(scope = "onos", name = "intent-compilers",
30 description = "Lists the mapping from intent type to compiler component")
31public class IntentListCompilers extends AbstractShellCommand {
32
33 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070034 protected void doExecute() {
Thomas Vachuskacdac6e82016-02-29 19:21:49 -080035 IntentExtensionService service = get(IntentExtensionService.class);
36 OptionalInt length = service.getCompilers().keySet().stream()
37 .mapToInt(s -> s.getName().length())
38 .max();
39 if (length.isPresent()) {
40 service.getCompilers().entrySet().forEach(e -> {
41 print("%-" + length.getAsInt() + "s\t%s",
42 e.getKey().getName(),
43 e.getValue().getClass().getName());
44 });
45 } else {
46 print("There are no compilers registered.");
47 }
48
49 }
50}