blob: 2de0c8e50daebfce7522db52b08e68b014a8e72b [file] [log] [blame]
Ray Milkey1aaff022018-10-22 16:45:20 -07001/*
2 * Copyright 2017-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.cli;
17
18import org.apache.karaf.shell.api.action.Command;
19import org.apache.karaf.shell.api.action.lifecycle.Service;
20import org.osgi.service.component.runtime.ServiceComponentRuntime;
21import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
22
23import java.util.Formatter;
24
25/**
26 * CLI command to dump out the SCR components list in the old karaf format.
27 */
28@Service
29@Command(scope = "onos", name = "scr-list",
30 description = "List components")
31public class ScrListCommand extends AbstractShellCommand {
32
33 @Override
34 protected void doExecute() {
35 StringBuilder output = new StringBuilder();
36 Formatter formatter = new Formatter(output);
37 ServiceComponentRuntime scrService = get(ServiceComponentRuntime.class);
38
39 scrService.getComponentDescriptionDTOs()
40 .forEach(componentDto -> {
41 scrService.getComponentConfigurationDTOs(componentDto)
42 .forEach(configurationDto -> {
43 String state;
44 switch (configurationDto.state) {
45 case ComponentConfigurationDTO.ACTIVE: {
46 state = "ACTIVE";
47 break;
48 }
49 case ComponentConfigurationDTO.SATISFIED: {
50 state = "SATISFIED";
51 break;
52 }
53 default: {
54 state = "UNKNOWN";
55 }
56 }
57 formatter.format("%3d | %9s | %s\n", configurationDto.id, state, componentDto.name);
58 });
59 });
60 print(output.toString());
61 }
62
63}