/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.netvirt.vpnmanager.shell;
import com.google.common.base.Optional;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-@Command(scope = "vpnservice", name = "vpn-show", description = "Display all present vpnInstances with their " +
- "respective count of oper and config vpnInterfaces")
+@Command(scope = "vpnservice", name = "vpn-show", description = "Display all present vpnInstances with their "
+ + "respective count of oper and config vpnInterfaces")
public class ShowVpn extends OsgiCommandSupport {
- @Option(name = "--detail", aliases = {"--vpninstance"}, description = "Display oper and config interfaces for " +
- "given vpnInstanceName", required = false, multiValued = false)
- String detail;
+ @Option(name = "--detail", aliases = {"--vpninstance"}, description = "Display oper and config interfaces for "
+ + "given vpnInstanceName", required = false, multiValued = false)
+ private String detail;
- final Logger LOG = LoggerFactory.getLogger(ShowVpn.class);
+ private static final Logger LOG = LoggerFactory.getLogger(ShowVpn.class);
private DataBroker dataBroker;
- int configCount = 0;
- int operCount = 0;
- int totalOperCount = 0;
- int totalConfigCount = 0;
- Integer ifPresent ;
- List<org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance> vpnInstanceList = new ArrayList<>();
- List<VpnInterface> vpnInterfaceConfigList = new ArrayList<>();
- List<VpnInterface> vpnInterfaceOperList = new ArrayList<>();
+ private int configCount = 0;
+ private int operCount = 0;
+ private int totalOperCount = 0;
+ private int totalConfigCount = 0;
+ private Integer ifPresent;
+ private List<org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.VpnInstance>
+ vpnInstanceList = new ArrayList<>();
+ private List<VpnInterface> vpnInterfaceConfigList = new ArrayList<>();
+ private List<VpnInterface> vpnInterfaceOperList = new ArrayList<>();
public void setDataBroker(DataBroker broker) {
this.dataBroker = broker;
}
@Override
- protected Object doExecute() throws Exception{
- try{
-
- Map<String, Integer> instanceNameToConfigInterfaceMap = new HashMap<>();
- Map<String, Integer> instanceNameToOperInterfaceMap = new HashMap<>();
- if (detail == null) {
- showVpn();
- for (VpnInterface vpnInterface : vpnInterfaceConfigList) {
- ifPresent = instanceNameToConfigInterfaceMap.get(vpnInterface.getVpnInstanceName());
- if(ifPresent == null) {
- instanceNameToConfigInterfaceMap.put(vpnInterface.getVpnInstanceName(), 1);
- }
- else {instanceNameToConfigInterfaceMap.put(vpnInterface.getVpnInstanceName(),
- instanceNameToConfigInterfaceMap.get(vpnInterface.getVpnInstanceName())+1);
- }
+ protected Object doExecute() {
+ Map<String, Integer> instanceNameToConfigInterfaceMap = new HashMap<>();
+ Map<String, Integer> instanceNameToOperInterfaceMap = new HashMap<>();
+ if (detail == null) {
+ showVpn();
+ for (VpnInterface vpnInterface : vpnInterfaceConfigList) {
+ ifPresent = instanceNameToConfigInterfaceMap.get(vpnInterface.getVpnInstanceName());
+ if (ifPresent == null) {
+ instanceNameToConfigInterfaceMap.put(vpnInterface.getVpnInstanceName(), 1);
+ } else {
+ instanceNameToConfigInterfaceMap.put(vpnInterface.getVpnInstanceName(),
+ instanceNameToConfigInterfaceMap.get(vpnInterface.getVpnInstanceName()) + 1);
}
- for (VpnInterface vpnInterface : vpnInterfaceOperList) {
- ifPresent = instanceNameToOperInterfaceMap.get(vpnInterface.getVpnInstanceName());
- if(ifPresent == null) {
- instanceNameToOperInterfaceMap.put(vpnInterface.getVpnInstanceName(), 1);
- }
- else {instanceNameToOperInterfaceMap.put(vpnInterface.getVpnInstanceName(),
- instanceNameToOperInterfaceMap.get(vpnInterface.getVpnInstanceName())+1);
- }
+ }
+ for (VpnInterface vpnInterface : vpnInterfaceOperList) {
+ ifPresent = instanceNameToOperInterfaceMap.get(vpnInterface.getVpnInstanceName());
+ if (ifPresent == null) {
+ instanceNameToOperInterfaceMap.put(vpnInterface.getVpnInstanceName(), 1);
+ } else {
+ instanceNameToOperInterfaceMap.put(vpnInterface.getVpnInstanceName(),
+ instanceNameToOperInterfaceMap.get(vpnInterface.getVpnInstanceName()) + 1);
}
- System.out.println("-----------------------------------------------------------------------");
- System.out.println(String.format(" %s %14s %5s %5s", "VpnInstanceName", "RD", "Config " +
- "Count", "Oper Count"));
- System.out.println("\n-----------------------------------------------------------------------");
- for (VpnInstance vpnInstance : vpnInstanceList) {
- configCount = 0; operCount = 0;
- Integer count = instanceNameToConfigInterfaceMap.get(vpnInstance.getVpnInstanceName());
- if(count != null) {
- configCount = instanceNameToConfigInterfaceMap.get(vpnInstance.getVpnInstanceName());
- totalConfigCount = totalConfigCount + configCount;
- }
- count = instanceNameToOperInterfaceMap.get(vpnInstance.getVpnInstanceName());
- if (count != null) {
- operCount = instanceNameToOperInterfaceMap.get(vpnInstance.getVpnInstanceName());
- totalOperCount = totalOperCount + operCount;
- }
- System.out.println(String.format("%-32s %-10s %-10s %-10s", vpnInstance.getVpnInstanceName(),
- vpnInstance.getIpv4Family().getRouteDistinguisher(), configCount, operCount));
+ }
+ session.getConsole().println("-----------------------------------------------------------------------");
+ session.getConsole().println(
+ String.format(" %s %14s %5s %5s", "VpnInstanceName", "RD", "Config Count",
+ "Oper Count"));
+ session.getConsole().println(
+ "\n-----------------------------------------------------------------------");
+ for (VpnInstance vpnInstance : vpnInstanceList) {
+ configCount = 0;
+ operCount = 0;
+ Integer count = instanceNameToConfigInterfaceMap.get(vpnInstance.getVpnInstanceName());
+ if (count != null) {
+ configCount = instanceNameToConfigInterfaceMap.get(vpnInstance.getVpnInstanceName());
+ totalConfigCount = totalConfigCount + configCount;
}
- System.out.println("-----------------------------------------------------------------------");
- System.out.println(String.format("Total Count: %19s %8s", totalConfigCount,
- totalOperCount));
- System.out.println(getshowVpnCLIHelp());
- }else {
- showVpn();
- System.out.println("Present Config VpnInterfaces are:");
- for (VpnInterface vpnInterface : vpnInterfaceConfigList) {
- if (vpnInterface.getVpnInstanceName().equals(detail)) {
- System.out.println(vpnInterface.getName());
- }
+ count = instanceNameToOperInterfaceMap.get(vpnInstance.getVpnInstanceName());
+ if (count != null) {
+ operCount = instanceNameToOperInterfaceMap.get(vpnInstance.getVpnInstanceName());
+ totalOperCount = totalOperCount + operCount;
}
- System.out.println("Present Oper VpnInterfaces are:");
- for (VpnInterface vpnInterface : vpnInterfaceOperList) {
- if (vpnInterface.getVpnInstanceName().equals(detail)) {
- System.out.println(vpnInterface.getName());
- }
+ session.getConsole().println(
+ String.format("%-32s %-10s %-10s %-10s", vpnInstance.getVpnInstanceName(),
+ vpnInstance.getIpv4Family().getRouteDistinguisher(), configCount, operCount));
+ }
+ session.getConsole().println("-----------------------------------------------------------------------");
+ session.getConsole().println(
+ String.format("Total Count: %19s %8s", totalConfigCount, totalOperCount));
+ session.getConsole().println(getshowVpnCLIHelp());
+ } else {
+ showVpn();
+ session.getConsole().println("Present Config VpnInterfaces are:");
+ for (VpnInterface vpnInterface : vpnInterfaceConfigList) {
+ if (vpnInterface.getVpnInstanceName().equals(detail)) {
+ session.getConsole().println(vpnInterface.getName());
+ }
+ }
+ session.getConsole().println("Present Oper VpnInterfaces are:");
+ for (VpnInterface vpnInterface : vpnInterfaceOperList) {
+ if (vpnInterface.getVpnInstanceName().equals(detail)) {
+ session.getConsole().println(vpnInterface.getName());
}
}
- }catch (Exception e) {
- System.out.println("Error while fetching vpnInterfaces for " + detail);
- LOG.error("Failed to fetch parameters",e);
}
return null;
}
private <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType,
- InstanceIdentifier<T> path) {
-
- ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
-
- Optional<T> result = Optional.absent();
- try {
- result = tx.read(datastoreType, path).get();
- } catch (Exception e) {
+ InstanceIdentifier<T> path) {
+ try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
+ return tx.read(datastoreType, path).get();
+ } catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
-
- return result;
}
- private void showVpn(){
+ private void showVpn() {
InstanceIdentifier<VpnInstances> vpnsIdentifier = InstanceIdentifier.builder(VpnInstances.class).build();
InstanceIdentifier<VpnInterfaces> vpnInterfacesIdentifier = InstanceIdentifier.builder(VpnInterfaces
.class).build();
- Optional<VpnInstances> optionalVpnInstances = read( LogicalDatastoreType.CONFIGURATION, vpnsIdentifier);
+ Optional<VpnInstances> optionalVpnInstances = read(LogicalDatastoreType.CONFIGURATION, vpnsIdentifier);
if (!optionalVpnInstances.isPresent()) {
LOG.trace("No VPNInstances configured.");
- System.out.println("No VPNInstances configured.");
- }else{
+ session.getConsole().println("No VPNInstances configured.");
+ } else {
vpnInstanceList = optionalVpnInstances.get().getVpnInstance();
}
- Optional<VpnInterfaces> optionalVpnInterfacesConfig = read(LogicalDatastoreType.CONFIGURATION, vpnInterfacesIdentifier);
+ Optional<VpnInterfaces> optionalVpnInterfacesConfig =
+ read(LogicalDatastoreType.CONFIGURATION, vpnInterfacesIdentifier);
if (!optionalVpnInterfacesConfig.isPresent()) {
LOG.trace("No Config VpnInterface is present");
- System.out.println("No Config VpnInterface is present");
- }else{
+ session.getConsole().println("No Config VpnInterface is present");
+ } else {
vpnInterfaceConfigList = optionalVpnInterfacesConfig.get().getVpnInterface();
}
- Optional<VpnInterfaces> optionalVpnInterfacesOper = read(LogicalDatastoreType.OPERATIONAL, vpnInterfacesIdentifier);
+ Optional<VpnInterfaces> optionalVpnInterfacesOper =
+ read(LogicalDatastoreType.OPERATIONAL, vpnInterfacesIdentifier);
if (!optionalVpnInterfacesOper.isPresent()) {
LOG.trace("No Oper VpnInterface is present");
- System.out.println("No Oper VpnInterface is present");
- }else{
+ session.getConsole().println("No Oper VpnInterface is present");
+ } else {
vpnInterfaceOperList = optionalVpnInterfacesOper.get().getVpnInterface();
}
}
/*
- * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright © 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.netvirt.vpnmanager.shell;
import com.google.common.base.Optional;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
import org.apache.karaf.shell.commands.Command;
import org.apache.karaf.shell.commands.Option;
import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-@Command(scope = "vpnservice", name = "vpninstance-op-show", description = "List name of all vpnInstances that is " +
- "present or absent in vpnInstanceOpDataEntry")
+@Command(scope = "vpnservice", name = "vpninstance-op-show", description = "List name of all vpnInstances that is "
+ + "present or absent in vpnInstanceOpDataEntry")
public class ShowVpnInstanceOpData extends OsgiCommandSupport {
- @Option(name = "--detail", aliases = {"--vpnInstanceOp"}, description = "Display vpnInstanceOpDataEntry detail " +
- "for" +
- " given vpnInstanceName", required = false, multiValued = false)
- String detail;
- final Logger LOG = LoggerFactory.getLogger(ShowVpnInstanceOpData.class);
+ @Option(name = "--detail", aliases = {"--vpnInstanceOp"}, description = "Display vpnInstanceOpDataEntry detail "
+ + "for given vpnInstanceName", required = false, multiValued = false)
+ private String detail;
+ private static final Logger LOG = LoggerFactory.getLogger(ShowVpnInstanceOpData.class);
private DataBroker dataBroker;
- List<VpnInstance> vpnInstanceList = new ArrayList<>();
- Map<String, VpnInstanceOpDataEntry> vpnInstanceOpDataEntryMap = new HashMap<>();
+ private List<VpnInstance> vpnInstanceList = new ArrayList<>();
+ private Map<String, VpnInstanceOpDataEntry> vpnInstanceOpDataEntryMap = new HashMap<>();
public void setDataBroker(DataBroker broker) {
this.dataBroker = broker;
}
@Override
- protected Object doExecute() throws Exception{
- try{
- if (detail == null) {
- getVpnInstanceOpData();
- System.out.println("For following vpnInstances vpnInstanceOpDataEntry is present: \n");
- for (VpnInstance vpnInstance : vpnInstanceList) {
- VpnInstanceOpDataEntry check = vpnInstanceOpDataEntryMap.get(vpnInstance.getVpnInstanceName());
- if (check != null) {
- System.out.println(vpnInstance.getVpnInstanceName() + "\n");
- }
+ protected Object doExecute() {
+ if (detail == null) {
+ getVpnInstanceOpData();
+ session.getConsole().println("For following vpnInstances vpnInstanceOpDataEntry is present: \n");
+ for (VpnInstance vpnInstance : vpnInstanceList) {
+ VpnInstanceOpDataEntry check = vpnInstanceOpDataEntryMap.get(vpnInstance.getVpnInstanceName());
+ if (check != null) {
+ session.getConsole().println(vpnInstance.getVpnInstanceName() + "\n");
}
- System.out.println("\n\nFor following vpnInstances vpnInstanceOpDataEntry is not present: \n");
- for (VpnInstance vpnInstance : vpnInstanceList) {
- VpnInstanceOpDataEntry check = vpnInstanceOpDataEntryMap.get(vpnInstance.getVpnInstanceName());
- if (check == null) {
- System.out.println(vpnInstance.getVpnInstanceName() + "\n");
- }
+ }
+ session.getConsole().println("\n\nFor following vpnInstances vpnInstanceOpDataEntry is not present: \n");
+ for (VpnInstance vpnInstance : vpnInstanceList) {
+ VpnInstanceOpDataEntry check = vpnInstanceOpDataEntryMap.get(vpnInstance.getVpnInstanceName());
+ if (check == null) {
+ session.getConsole().println(vpnInstance.getVpnInstanceName() + "\n");
}
- System.out.println(getshowVpnCLIHelp());
- } else {
- getVpnInstanceOpData();
- System.out.println("Fetching details of given vpnInstance\n");
- System.out.println("------------------------------------------------------------------------------");
- VpnInstanceOpDataEntry check = vpnInstanceOpDataEntryMap.get(detail);
- System.out.println("VpnInstanceName: " + check.getVpnInstanceName() + "\n" + "VpnId: " + check
- .getVpnId() + "\n" + "VrfId: " + check.getVrfId() + "\n" + "Key: " + check.getKey() + "\n" +
- "VpnInterfaceCount: " + check.getVpnInterfaceCount() + "\n" + "VpnToDpnList: " + check.getVpnToDpnList() +
- "\n");
- System.out.println("------------------------------------------------------------------------------");
}
-
- }catch (Exception e) {
- System.out.println("Error fetching vpnInstanceOpDataEntry for " + detail);
- LOG.error("Failed to fetch parameters",e);
+ session.getConsole().println(getshowVpnCLIHelp());
+ } else {
+ getVpnInstanceOpData();
+ session.getConsole().println("Fetching details of given vpnInstance\n");
+ session.getConsole().println(
+ "------------------------------------------------------------------------------");
+ VpnInstanceOpDataEntry check = vpnInstanceOpDataEntryMap.get(detail);
+ session.getConsole().println(
+ "VpnInstanceName: " + check.getVpnInstanceName() + "\nVpnId: " + check.getVpnId() + "\nVrfId: "
+ + check.getVrfId() + "\nKey: " + check.getKey() + "\nVpnInterfaceCount: "
+ + check.getVpnInterfaceCount() + "\nVpnToDpnList: " + check.getVpnToDpnList() + "\n");
+ session.getConsole().println(
+ "------------------------------------------------------------------------------");
}
return null;
}
- private void getVpnInstanceOpData(){
+ private void getVpnInstanceOpData() {
List<VpnInstanceOpDataEntry> vpnInstanceOpDataEntryList = new ArrayList<>();
InstanceIdentifier<VpnInstances> vpnsIdentifier = InstanceIdentifier.builder(VpnInstances.class).build();
- InstanceIdentifier<VpnInstanceOpData> vpnInstanceOpDataEntryIdentifier = InstanceIdentifier.builder
- (VpnInstanceOpData.class).build();
- Optional<VpnInstances> optionalVpnInstances = read( LogicalDatastoreType.CONFIGURATION, vpnsIdentifier);
+ InstanceIdentifier<VpnInstanceOpData> vpnInstanceOpDataEntryIdentifier =
+ InstanceIdentifier.builder(VpnInstanceOpData.class).build();
+ Optional<VpnInstances> optionalVpnInstances = read(LogicalDatastoreType.CONFIGURATION, vpnsIdentifier);
- if (!optionalVpnInstances.isPresent() || optionalVpnInstances.get().getVpnInstance() == null ||
- optionalVpnInstances.get().getVpnInstance().isEmpty()) {
+ if (!optionalVpnInstances.isPresent() || optionalVpnInstances.get().getVpnInstance() == null
+ || optionalVpnInstances.get().getVpnInstance().isEmpty()) {
LOG.trace("No VPNInstances configured.");
- System.out.println("No VPNInstances configured.");
- }else {
+ session.getConsole().println("No VPNInstances configured.");
+ } else {
vpnInstanceList = optionalVpnInstances.get().getVpnInstance();
}
if (!optionalOpData.isPresent()) {
LOG.trace("No VPNInstanceOpDataEntry present.");
- System.out.println("No VPNInstanceOpDataEntry present.");
- }else {
+ session.getConsole().println("No VPNInstanceOpDataEntry present.");
+ } else {
vpnInstanceOpDataEntryList = optionalOpData.get().getVpnInstanceOpDataEntry();
}
- for(VpnInstanceOpDataEntry vpnInstanceOpDataEntry : vpnInstanceOpDataEntryList){
+ for (VpnInstanceOpDataEntry vpnInstanceOpDataEntry : vpnInstanceOpDataEntryList) {
vpnInstanceOpDataEntryMap.put(vpnInstanceOpDataEntry.getVpnInstanceName(), vpnInstanceOpDataEntry);
}
}
private <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType,
- InstanceIdentifier<T> path) {
-
- ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction();
-
- Optional<T> result = Optional.absent();
- try {
- result = tx.read(datastoreType, path).get();
- } catch (Exception e) {
+ InstanceIdentifier<T> path) {
+ try (ReadOnlyTransaction tx = dataBroker.newReadOnlyTransaction()) {
+ return tx.read(datastoreType, path).get();
+ } catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
-
- return result;
}
private String getshowVpnCLIHelp() {
- StringBuilder help = new StringBuilder("\nUsage:");
- help.append("To display vpn-instance-op-data for given vpnInstanceName vpnInstanceOpData-show --detail [<vpnInstanceName>]");
- return help.toString();
+ return "\nUsage:"
+ + "To display vpn-instance-op-data for given vpnInstanceName vpnInstanceOpData-show --detail "
+ + "[<vpnInstanceName>]";
}
}