Vxlan/Gre co-existence,Alarms,tunnelstate,TR fixes
[vpnservice.git] / itm / itm-impl / src / main / java / org / opendaylight / vpnservice / itm / cli / VtepSchemaDelete.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.vpnservice.itm.cli;
10
11 import org.apache.commons.lang3.StringUtils;
12 import org.apache.karaf.shell.commands.Argument;
13 import org.apache.karaf.shell.commands.Command;
14 import org.apache.karaf.shell.console.OsgiCommandSupport;
15 import org.opendaylight.vpnservice.itm.api.IITMProvider;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * The Class which implements karaf command "vtep:schema-delete".
21  */
22 @Command(scope = "vtep", name = "schema-delete", description = "Delete VTEP schema.")
23 public class VtepSchemaDelete extends OsgiCommandSupport {
24
25     private static final String ALL = "all";
26
27     @Argument(index = 0, name = ALL, description = "Delete all VTEP schemas", required = true, multiValued = false)
28     String deleteAll = null;
29
30     /** The Constant logger. */
31     private static final Logger LOG = LoggerFactory.getLogger(VtepSchemaDelete.class);
32
33     /** The itm provider. */
34     private IITMProvider itmProvider;
35
36     /**
37      * Sets the itm provider.
38      *
39      * @param itmProvider
40      *            the new itm provider
41      */
42     public void setItmProvider(IITMProvider itmProvider) {
43         this.itmProvider = itmProvider;
44     }
45
46     private void usage() {
47         System.out.println("usage: vtep:schema-delete all");
48     }
49
50     /*
51      * (non-Javadoc)
52      * 
53      * @see org.apache.karaf.shell.console.AbstractAction#doExecute()
54      */
55     @Override
56     protected Object doExecute() {
57         try {
58             if (this.deleteAll == null || !StringUtils.equalsIgnoreCase(ALL, this.deleteAll)) {
59                 usage();
60                 return null;
61             }
62             LOG.debug("Executing vtep:schema-delete command\t {} ", this.deleteAll);
63             this.itmProvider.deleteAllVtepSchemas();
64
65         } catch (IllegalArgumentException e) {
66             System.out.println(e.getMessage());
67         } catch (Exception e) {
68             LOG.error("Exception occurred during execution of command \"vtep:schema-delete all\": ", e);
69         }
70         return null;
71     }
72
73 }