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 | |
| 18 | import org.onosproject.cli.AbstractChoicesCompleter; |
| 19 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmConfigException; |
| 20 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMdService; |
| 21 | import org.onosproject.incubator.net.l2monitoring.cfm.service.CfmMepService; |
| 22 | import org.slf4j.Logger; |
| 23 | |
| 24 | import java.util.ArrayList; |
| 25 | import java.util.List; |
| 26 | |
| 27 | import static org.onosproject.cli.AbstractShellCommand.get; |
| 28 | import static org.slf4j.LoggerFactory.getLogger; |
| 29 | |
| 30 | /** |
| 31 | * CLI completer for Mep Id creation. |
| 32 | */ |
| 33 | public 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 -> { |
| 44 | choices.add(new StringBuilder(md.mdId().mdName()) |
| 45 | .append("(") |
| 46 | .append(md.mdId().nameType()) |
| 47 | .append(")").toString()); |
| 48 | |
| 49 | md.maintenanceAssociationList().forEach(ma -> { |
| 50 | choices.add(new StringBuilder(md.mdId().mdName()) |
| 51 | .append("(") |
| 52 | .append(md.mdId().nameType()) |
| 53 | .append(") ") |
| 54 | .append(ma.maId().maName()) |
| 55 | .append("(") |
| 56 | .append(ma.maId().nameType()) |
| 57 | .append(")").toString()); |
| 58 | |
| 59 | try { |
| 60 | mepService.getAllMeps(md.mdId(), ma.maId()).forEach(mep -> |
| 61 | choices.add(new StringBuilder(md.mdId().mdName()) |
| 62 | .append("(") |
| 63 | .append(md.mdId().nameType()) |
| 64 | .append(") ") |
| 65 | .append(ma.maId().maName()) |
| 66 | .append("(") |
| 67 | .append(ma.maId().nameType()) |
| 68 | .append(") ") |
| 69 | .append(mep.mepId()).toString()) |
| 70 | ); |
| 71 | } catch (CfmConfigException e) { |
| 72 | log.warn("Unable to retrieve mep details", e); |
| 73 | } |
| 74 | } |
| 75 | ); |
| 76 | }); |
| 77 | |
| 78 | return choices; |
| 79 | } |
| 80 | |
| 81 | } |