Switch to JDT annotations for Nullable and NonNull
[netvirt.git] / elanmanager / impl / src / main / java / org / opendaylight / netvirt / elan / cli / ElanAdd.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 package org.opendaylight.netvirt.elan.cli;
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.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.netvirt.elanmanager.api.IElanService;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 @Command(scope = "elan", name = "add", description = "adding Elan Instance")
19 public class ElanAdd extends OsgiCommandSupport {
20     private static final int MAX_LENGTH = 31;
21
22     @Argument(index = 0, name = "elanName", description = "ELAN-NAME", required = true, multiValued = false)
23     private String elanName;
24     @Argument(index = 1, name = "macTimeOut", description = "MAC Time-Out", required = false, multiValued = false)
25     private long macTimeOut = -1;
26     @Argument(index = 2, name = "elanDescr", description = "ELAN-Description", required = false, multiValued = false)
27     private String elanDescr;
28     private static final Logger LOG = LoggerFactory.getLogger(ElanAdd.class);
29     private IElanService elanProvider;
30
31     public void setElanProvider(IElanService elanServiceProvider) {
32         this.elanProvider = elanServiceProvider;
33     }
34
35     @Override
36     @Nullable
37     protected Object doExecute() {
38         if (macTimeOut == -1) {
39             macTimeOut = 30;
40         }
41
42         LOG.debug("Executing create ElanInstance command for elanName : {}, macTimeOut : {}, elanDescr : {}",
43                 elanName, macTimeOut, elanDescr);
44         if (elanName.length() <= MAX_LENGTH) {
45             boolean isSuccess = elanProvider.createElanInstance(elanName, macTimeOut, elanDescr);
46             if (isSuccess) {
47                 session.getConsole().println("Elan Instance is created successfully");
48             }
49         } else {
50             session.getConsole().println("Failed to create Elan Instance, max length is allowed 1 .. 31");
51         }
52         return null;
53     }
54 }