Remove redundant names in paths
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / cli / etree / EtreeAdd.java
1 /*
2  * Copyright (c) 2016 Hewlett Packard Enterprise, Co. 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 package org.opendaylight.netvirt.elan.cli.etree;
9
10 import org.apache.karaf.shell.commands.Argument;
11 import org.apache.karaf.shell.commands.Command;
12 import org.apache.karaf.shell.console.OsgiCommandSupport;
13 import org.opendaylight.netvirt.elanmanager.api.IElanService;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
16
17 @Command(scope = "etree", name = "add", description = "adding Etree Instance")
18 public class EtreeAdd extends OsgiCommandSupport {
19     private static final int MAX_LENGTH = 31;
20
21     @Argument(index = 0, name = "etreeName", description = "ETREE-NAME", required = true, multiValued = false)
22     private String etreeName;
23     @Argument(index = 1, name = "macTimeOut", description = "MAC Time-Out", required = false, multiValued = false)
24     private long macTimeOut = -1;
25     @Argument(index = 2, name = "elanDescr", description = "ELAN-Description", required = false, multiValued = false)
26     private String etreeDescr;
27     private static final Logger LOG = LoggerFactory.getLogger(EtreeAdd.class);
28     private IElanService elanProvider;
29
30     public void setElanProvider(IElanService elanServiceProvider) {
31         this.elanProvider = elanServiceProvider;
32     }
33
34     @Override
35     protected Object doExecute() throws Exception {
36         if (macTimeOut == -1) {
37             macTimeOut = 30;
38         }
39
40         LOG.debug("Executing create EtreeInstance command" + "\t" + etreeName + "\t" + macTimeOut + "\t"
41                 + etreeDescr + "\t");
42         if (etreeName.length() <= MAX_LENGTH) {
43             boolean isSuccess = elanProvider.createEtreeInstance(etreeName, macTimeOut, etreeDescr);
44             if (isSuccess) {
45                 session.getConsole().println("Etree Instance was created successfully");
46             }
47         } else {
48             session.getConsole().println("Failed to create Etree Instance, max length is allowed 1 .. 31");
49         }
50         return null;
51     }
52 }