Ignore flaky ITM test
[genius.git] / itm / itm-impl / src / main / java / org / opendaylight / genius / itm / cli / VtepSchemaUpdate.java
1 /*
2  * Copyright (c) 2016, 2017 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.genius.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.genius.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",
35             required = false, multiValued = false)
36     private String dpnIdsForAdd;
37
38     /** The dpn ids for delete. */
39     @Option(name = DD, aliases = {
40             "-dd" }, description = "DPN ID's to be deleted from schema in a comma separated value format. e.g: 2,3,10",
41             required = false, multiValued = false)
42     private String dpnIdsForDelete;
43
44     /** The Constant logger. */
45     private static final Logger LOG = LoggerFactory.getLogger(VtepSchemaUpdate.class);
46
47     /** The itm provider. */
48     private IITMProvider itmProvider;
49
50     /**
51      * Sets the itm provider.
52      *
53      * @param itmProvider
54      *            the new itm provider
55      */
56     public void setItmProvider(IITMProvider itmProvider) {
57         this.itmProvider = itmProvider;
58     }
59
60     /**
61      * Command Usage.
62      */
63     private void usage() {
64         session.getConsole().println(
65                 String.format("usage: vtep:schema-update [%s schema-name] [%s dpn-ids-for-add] [%s dpn-ids-for-delete]",
66                         SCHEMA_NAME, AD, DD));
67     }
68
69     /*
70      * (non-Javadoc)
71      *
72      * @see org.apache.karaf.shell.console.AbstractAction#doExecute()
73      */
74     @SuppressWarnings("checkstyle:IllegalCatch")
75     @Override
76     protected Object doExecute() {
77         try {
78             if (this.dpnIdsForAdd == null && this.dpnIdsForDelete == null) {
79                 session.getConsole().println(String.format("Atleast one of the parameters [%s or %s] is mandatory",
80                         AD, DD));
81                 usage();
82                 return null;
83             }
84             LOG.debug("Executing vtep:schema-update command\t {} \t {} \t {} ", this.schemaName, this.dpnIdsForAdd,
85                     this.dpnIdsForDelete);
86
87             this.itmProvider.updateVtepSchema(this.schemaName, ItmCliUtils.constructDpnIdList(this.dpnIdsForAdd),
88                     ItmCliUtils.constructDpnIdList(this.dpnIdsForDelete));
89
90         } catch (Exception e) {
91             LOG.error("Exception occurred during execution of command \"vtep:schema-update\": ", e);
92             throw e;
93         }
94         return null;
95     }
96 }