2 * Copyright (c) 2017 Cisco Systems. 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.groupbasedpolicy.renderer.vpp.lisp;
11 import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.lisp.AbstractLispCommand;
12 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction;
13 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General;
14 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.LispUtil;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 public class LispStateCommandExecutor {
22 private static final Logger LOG = LoggerFactory.getLogger(LispStateCommandExecutor.class);
24 public static <T extends DataObject> boolean executePutCommand(InstanceIdentifier<Node> nodeIid,
25 AbstractLispCommand<T> lispStateCommand) {
26 lispStateCommand.setOperation(General.Operations.PUT);
27 return executeCommand(nodeIid, lispStateCommand);
30 static <T extends DataObject> boolean executePutCommand(String hostName, AbstractLispCommand<T> lispStateCommand) {
31 lispStateCommand.setOperation(General.Operations.PUT);
32 return executeCommand(LispUtil.hostnameToIid(hostName), lispStateCommand);
35 static <T extends DataObject> boolean executeMergeCommand(String hostName, AbstractLispCommand<T> lispStateCommand) {
36 lispStateCommand.setOperation(General.Operations.MERGE);
37 return executeCommand(LispUtil.hostnameToIid(hostName), lispStateCommand);
40 public static <T extends DataObject> boolean executeDeleteCommand(InstanceIdentifier<Node> nodeIid,
41 AbstractLispCommand<T> lispStateCommand) {
42 lispStateCommand.setOperation(General.Operations.DELETE);
43 return executeCommand(nodeIid, lispStateCommand);
46 static <T extends DataObject> boolean executeDeleteCommand(String hostName, AbstractLispCommand<T> lispStateCommand) {
47 lispStateCommand.setOperation(General.Operations.DELETE);
48 return executeCommand(LispUtil.hostnameToIid(hostName), lispStateCommand);
51 private static <T extends DataObject> boolean executeCommand(InstanceIdentifier<Node> nodeIid,
52 AbstractLispCommand<T> lispStateCommand) {
53 final boolean transactionState;
54 switch (lispStateCommand.getOperation()) {
57 transactionState = GbpNetconfTransaction.netconfSyncedWrite(nodeIid, lispStateCommand.getIid(),
58 lispStateCommand.getData(), GbpNetconfTransaction.RETRY_COUNT);
62 transactionState = GbpNetconfTransaction.netconfSyncedDelete(nodeIid, lispStateCommand.getIid(),
63 GbpNetconfTransaction.RETRY_COUNT);
67 throw new IllegalStateException("No supported operation specified.");
69 if (transactionState) {
70 LOG.trace("Successfully executed command: {}", lispStateCommand);
72 LOG.debug("Failed to execute command: {}", lispStateCommand);
75 return transactionState;