blob: a26a460e42ccd5f3b9d96d90eb72bb4676f3446b [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
18import org.onosproject.cli.AbstractChoicesCompleter;
19import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException;
20import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService;
21import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService;
22import org.slf4j.Logger;
23
24import java.util.ArrayList;
25import java.util.List;
26
27import static org.onosproject.cli.AbstractShellCommand.get;
28import static org.slf4j.LoggerFactory.getLogger;
29
30/**
31 * CLI completer for Mep Id creation.
32 */
33public class CfmMepIdCompleter extends AbstractChoicesCompleter {
34 private final Logger log = getLogger(getClass());
35
36 @Override
37 public List<String> choices() {
38 List<String> choices = new ArrayList<>();
39
40 CfmMdService mdService = get(CfmMdService.class);
41 CfmMepService mepService = get(CfmMepService.class);
42
43 mdService.getAllMaintenanceDomain().forEach(md -> {
Sean Condon3a1efef2018-02-24 13:16:03 +000044 choices.add(md.mdId().mdName() + "(" + md.mdId().nameType() + ")");
Sean Condon96b896d2017-12-11 12:44:29 -080045
46 md.maintenanceAssociationList().forEach(ma -> {
Sean Condon3a1efef2018-02-24 13:16:03 +000047 choices.add(md.mdId().mdName() + "(" + md.mdId().nameType() +
48 ") " + ma.maId().maName() + "(" + ma.maId().nameType() + ")");
Sean Condon96b896d2017-12-11 12:44:29 -080049
50 try {
51 mepService.getAllMeps(md.mdId(), ma.maId()).forEach(mep ->
Sean Condon3a1efef2018-02-24 13:16:03 +000052 choices.add(md.mdId().mdName() + "(" +
53 md.mdId().nameType() + ") " + ma.maId().maName() +
54 "(" + ma.maId().nameType() + ") " + mep.mepId())
Sean Condon96b896d2017-12-11 12:44:29 -080055 );
56 } catch (CfmConfigException e) {
57 log.warn("Unable to retrieve mep details", e);
58 }
59 }
60 );
61 });
62
63 return choices;
64 }
65
66}