Vxlan/Gre co-existence,Alarms,tunnelstate,TR fixes
[vpnservice.git] / itm / itm-impl / src / main / java / org / opendaylight / vpnservice / itm / cli / VtepSchemaUpdate.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.karaf.shell.commands.Command;
12 import org.apache.karaf.shell.commands.Option;
13 import org.apache.karaf.shell.console.OsgiCommandSupport;
14 import org.opendaylight.vpnservice.itm.api.IITMProvider;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * The Class which implements karaf command "vtep:schema-update".
20  */
21 @Command(scope = "vtep", name = "schema-update", description = "Update VTEP schema.")
22 public class VtepSchemaUpdate extends OsgiCommandSupport {
23
24     private static final String SCHEMA_NAME = "--schema-name";
25     private static final String AD = "--add-dpn-ids";
26     private static final String DD = "--del-dpn-ids";
27
28     /** The schema name. */
29     @Option(name = SCHEMA_NAME, aliases = { "-s" }, description = "Schema name", required = true, multiValued = false)
30     private String schemaName;
31
32     /** The dpn ids for add. */
33     @Option(name = AD, aliases = {
34             "-ad" }, description = "DPN ID's to be added to schema in a comma separated value format. e.g: 2,3,10", required = false, multiValued = false)
35     private String dpnIdsForAdd;
36
37     /** The dpn ids for delete. */
38     @Option(name = DD, aliases = {
39             "-dd" }, description = "DPN ID's to be deleted from schema in a comma separated value format. e.g: 2,3,10", required = false, multiValued = false)
40     private String dpnIdsForDelete;
41
42     /** The Constant logger. */
43     private static final Logger LOG = LoggerFactory.getLogger(VtepSchemaUpdate.class);
44
45     /** The itm provider. */
46     private IITMProvider itmProvider;
47
48     /**
49      * Sets the itm provider.
50      *
51      * @param itmProvider
52      *            the new itm provider
53      */
54     public void setItmProvider(IITMProvider itmProvider) {
55         this.itmProvider = itmProvider;
56     }
57
58     /**
59      * Command Usage.
60      */
61     private void usage() {
62         System.out.println(
63                 String.format("usage: vtep:schema-update [%s schema-name] [%s dpn-ids-for-add] [%s dpn-ids-for-delete]",
64                         SCHEMA_NAME, AD, DD));
65     }
66
67     /*
68      * (non-Javadoc)
69      * 
70      * @see org.apache.karaf.shell.console.AbstractAction#doExecute()
71      */
72     @Override
73     protected Object doExecute() {
74         try {
75             if (this.dpnIdsForAdd == null && this.dpnIdsForDelete == null) {
76                 System.out.println(String.format("Atleast one of the parameters [%s or %s] is mandatory", AD, DD));
77                 usage();
78                 return null;
79             }
80             LOG.debug("Executing vtep:schema-update command\t {} \t {} \t {} ", this.schemaName, this.dpnIdsForAdd,
81                     this.dpnIdsForDelete);
82
83             this.itmProvider.updateVtepSchema(this.schemaName, ItmCliUtils.constructDpnIdList(this.dpnIdsForAdd),
84                     ItmCliUtils.constructDpnIdList(this.dpnIdsForDelete));
85
86         } catch (IllegalArgumentException e) {
87             System.out.println(e.getMessage());
88         } catch (Exception e) {
89             LOG.error("Exception occurred during execution of command \"vtep:schema-update\": ", e);
90         }
91         return null;
92     }
93 }