blob: 10e8270617ff37d839e8d4e143f571429c042036 [file] [log] [blame]
Yi Tsengaf1c9f32017-05-12 11:45:42 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Yi Tsengaf1c9f32017-05-12 11:45:42 -07003 *
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;
Yi Tsengaf1c9f32017-05-12 11:45:42 -070020import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.net.intent.IntentExtensionService;
22
23import java.util.OptionalInt;
24
25/**
26 * Lists the installers of intents.
27 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070028@Service
Yi Tsengaf1c9f32017-05-12 11:45:42 -070029@Command(scope = "onos", name = "intent-installers",
30 description = "Lists the mapping from intent type to installer component")
31public class IntentListInstallers extends AbstractShellCommand {
32 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070033 protected void doExecute() {
Yi Tsengaf1c9f32017-05-12 11:45:42 -070034 IntentExtensionService service = get(IntentExtensionService.class);
35 OptionalInt length = service.getInstallers().keySet().stream()
36 .mapToInt(s -> s.getName().length())
37 .max();
38 if (length.isPresent()) {
39 service.getInstallers().entrySet().forEach(e -> {
40 print("%-" + length.getAsInt() + "s\t%s",
41 e.getKey().getName(),
42 e.getValue().getClass().getName());
43 });
44 } else {
45 print("There are no installers registered.");
46 }
47 }
48}