blob: 23aa3244a6e8a0be5bfe4aaa5d7837dda58a5a89 [file] [log] [blame]
Sean Condon96b896d2017-12-11 12:44:29 -08001/*
2 * Copyright 2018-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.cfm.cli.completer;
17
Ray Milkeyc2b7b962018-10-02 15:00:02 -070018import org.apache.karaf.shell.api.action.lifecycle.Service;
Sean Condon96b896d2017-12-11 12:44:29 -080019import org.onosproject.cli.AbstractChoicesCompleter;
20import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
21import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
22import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService;
23import org.slf4j.Logger;
24
25import java.util.ArrayList;
26import java.util.List;
27
28import static org.onosproject.cli.AbstractShellCommand.get;
29import static org.slf4j.LoggerFactory.getLogger;
30
31/**
32 * CLI completer for Mep Id creation.
33 */
Ray Milkeyc2b7b962018-10-02 15:00:02 -070034@Service
Sean Condon96b896d2017-12-11 12:44:29 -080035public class CfmMepIdCompleter extends AbstractChoicesCompleter {
36 private final Logger log = getLogger(getClass());
37
38 @Override
39 public List<String> choices() {
40 List<String> choices = new ArrayList<>();
41
42 CfmMdService mdService = get(CfmMdService.class);
43 CfmMepService mepService = get(CfmMepService.class);
44
45 mdService.getAllMaintenanceDomain().forEach(md -> {
Sean Condon3a1efef2018-02-24 13:16:03 +000046 choices.add(md.mdId().mdName() + "(" + md.mdId().nameType() + ")");
Sean Condon96b896d2017-12-11 12:44:29 -080047
48 md.maintenanceAssociationList().forEach(ma -> {
Sean Condon3a1efef2018-02-24 13:16:03 +000049 choices.add(md.mdId().mdName() + "(" + md.mdId().nameType() +
50 ") " + ma.maId().maName() + "(" + ma.maId().nameType() + ")");
Sean Condon96b896d2017-12-11 12:44:29 -080051
52 try {
53 mepService.getAllMeps(md.mdId(), ma.maId()).forEach(mep ->
Sean Condon3a1efef2018-02-24 13:16:03 +000054 choices.add(md.mdId().mdName() + "(" +
55 md.mdId().nameType() + ") " + ma.maId().maName() +
56 "(" + ma.maId().nameType() + ") " + mep.mepId())
Sean Condon96b896d2017-12-11 12:44:29 -080057 );
58 } catch (CfmConfigException e) {
59 log.warn("Unable to retrieve mep details", e);
60 }
61 }
62 );
63 });
64
65 return choices;
66 }
67
68}