Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.cfm.cli.completer; |
| 17 | |
Ray Milkey | c2b7b96 | 2018-10-02 15:00:02 -0700 | [diff] [blame^] | 18 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 19 | import org.onosproject.cli.AbstractChoicesCompleter; |
| 20 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 21 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService; |
| 22 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService; |
| 23 | import org.slf4j.Logger; |
| 24 | |
| 25 | import java.util.ArrayList; |
| 26 | import java.util.List; |
| 27 | |
| 28 | import static org.onosproject.cli.AbstractShellCommand.get; |
| 29 | import static org.slf4j.LoggerFactory.getLogger; |
| 30 | |
| 31 | /** |
| 32 | * CLI completer for Mep Id creation. |
| 33 | */ |
Ray Milkey | c2b7b96 | 2018-10-02 15:00:02 -0700 | [diff] [blame^] | 34 | @Service |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 35 | public 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 Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 46 | choices.add(md.mdId().mdName() + "(" + md.mdId().nameType() + ")"); |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 47 | |
| 48 | md.maintenanceAssociationList().forEach(ma -> { |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 49 | choices.add(md.mdId().mdName() + "(" + md.mdId().nameType() + |
| 50 | ") " + ma.maId().maName() + "(" + ma.maId().nameType() + ")"); |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 51 | |
| 52 | try { |
| 53 | mepService.getAllMeps(md.mdId(), ma.maId()).forEach(mep -> |
Sean Condon | 3a1efef | 2018-02-24 13:16:03 +0000 | [diff] [blame] | 54 | choices.add(md.mdId().mdName() + "(" + |
| 55 | md.mdId().nameType() + ") " + ma.maId().maName() + |
| 56 | "(" + ma.maId().nameType() + ") " + mep.mepId()) |
Sean Condon | 96b896d | 2017-12-11 12:44:29 -0800 | [diff] [blame] | 57 | ); |
| 58 | } catch (CfmConfigException e) { |
| 59 | log.warn("Unable to retrieve mep details", e); |
| 60 | } |
| 61 | } |
| 62 | ); |
| 63 | }); |
| 64 | |
| 65 | return choices; |
| 66 | } |
| 67 | |
| 68 | } |