2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
9 package org.opendaylight.genius.itm.cli;
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;
19 * The Class which implements karaf command "vtep:schema-update".
21 @Command(scope = "vtep", name = "schema-update", description = "Update VTEP schema.")
22 public class VtepSchemaUpdate extends OsgiCommandSupport {
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";
28 /** The schema name. */
29 @Option(name = SCHEMA_NAME, aliases = { "-s" }, description = "Schema name", required = true, multiValued = false)
30 private String schemaName;
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;
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;
42 /** The Constant logger. */
43 private static final Logger LOG = LoggerFactory.getLogger(VtepSchemaUpdate.class);
45 /** The itm provider. */
46 private IITMProvider itmProvider;
49 * Sets the itm provider.
52 * the new itm provider
54 public void setItmProvider(IITMProvider itmProvider) {
55 this.itmProvider = itmProvider;
61 private void usage() {
62 session.getConsole().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));
70 * @see org.apache.karaf.shell.console.AbstractAction#doExecute()
73 protected Object doExecute() {
75 if (this.dpnIdsForAdd == null && this.dpnIdsForDelete == null) {
76 session.getConsole().println(String.format("Atleast one of the parameters [%s or %s] is mandatory", AD, DD));
80 LOG.debug("Executing vtep:schema-update command\t {} \t {} \t {} ", this.schemaName, this.dpnIdsForAdd,
81 this.dpnIdsForDelete);
83 this.itmProvider.updateVtepSchema(this.schemaName, ItmCliUtils.constructDpnIdList(this.dpnIdsForAdd),
84 ItmCliUtils.constructDpnIdList(this.dpnIdsForDelete));
86 } catch (Exception e) {
87 LOG.error("Exception occurred during execution of command \"vtep:schema-update\": ", e);