Ditch blueprint from srm-impl
[serviceutils.git] / srm / shell / src / main / java / org / opendaylight / serviceutils / srm / shell / SrmDebugCommand.java
1 /*
2  * Copyright (c) 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 package org.opendaylight.serviceutils.srm.shell;
9
10 import org.apache.karaf.shell.commands.Command;
11 import org.apache.karaf.shell.commands.Option;
12 import org.apache.karaf.shell.console.OsgiCommandSupport;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15 import org.opendaylight.mdsal.binding.api.DataBroker;
16 import org.opendaylight.mdsal.binding.api.WriteTransaction;
17 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.serviceutils.srm.ops.rev180626.ServiceOps;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20
21 @Command(scope = "srm", name = "debug", description = "SRM debug commands")
22 public class SrmDebugCommand extends OsgiCommandSupport {
23     @Option(name = "-c", aliases = {"--clear-ops"}, description = "Clear operations DS",
24         required = true, multiValued = false)
25     boolean clearOps;
26     private final DataBroker txDataBroker;
27
28     public SrmDebugCommand(DataBroker dataBroker) {
29         txDataBroker = dataBroker;
30     }
31
32     @Override
33     @Deprecated
34     protected @Nullable Object doExecute() throws Exception {
35         if (clearOps) {
36             clearOpsDs();
37         }
38         return null;
39     }
40
41     private void clearOpsDs() throws Exception {
42         InstanceIdentifier<ServiceOps> path = getInstanceIdentifier();
43         @NonNull WriteTransaction tx = txDataBroker.newWriteOnlyTransaction();
44         tx.delete(LogicalDatastoreType.OPERATIONAL, path);
45         tx.commit().get();
46     }
47
48     private static InstanceIdentifier<ServiceOps> getInstanceIdentifier() {
49         return InstanceIdentifier.create(ServiceOps.class);
50     }
51
52 }