Fix findbugs violations in test-provider and drop-test-karaf
[openflowplugin.git] / drop-test-karaf / src / main / java / org / opendaylight / openflowplugin / droptestkaraf / DropAllPacketsCommandProvider.java
1 /*
2  * Copyright (c) 2013 Ericsson , Inc. 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.openflowplugin.droptestkaraf;
10
11 import java.io.PrintStream;
12 import org.apache.karaf.shell.commands.Argument;
13 import org.apache.karaf.shell.commands.Command;
14 import org.apache.karaf.shell.console.OsgiCommandSupport;
15 import org.opendaylight.openflowplugin.testcommon.DropTestDsProvider;
16
17 @Command(scope = "drop-test", name = "dropAllPackets",
18          description = "drop packet responder involving dataStore and FRM")
19 public class DropAllPacketsCommandProvider extends OsgiCommandSupport {
20
21     @Argument(index = 0, name = "on-off",
22             description = "target state of drop responder",
23             required = true, multiValued = false)
24     String targetStateArg;
25
26
27     @Override
28     protected Object doExecute() throws Exception {
29         PrintStream out = session.getConsole();
30         final DropTestDsProvider provider = DropTestProviderImpl.getDropDsProvider();
31
32         if ("on".equalsIgnoreCase(targetStateArg)) {
33             if (! provider.isActive()) {
34                 provider.start();
35                 out.println("DropAllFlows transitions to on");
36             } else {
37                 out.println("DropAllFlows is already on");
38             }
39         } else if ("off".equalsIgnoreCase(targetStateArg)) {
40             if (provider.isActive()) {
41                 provider.close();
42                 out.println("DropAllFlows transitions to off");
43             } else {
44                 out.println("DropAllFlows is already off");
45             }
46         }
47         return null;
48     }
49 }