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.groupbasedpolicy.renderer.vpp.util.VppIidFactory;
16 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
17 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 import com.google.common.base.Function;
26 * Created by Shakib Ahmed on 4/18/17.
28 public class LispStateCommandExecutor {
29 private static final Logger LOG = LoggerFactory.getLogger(LispStateCommandExecutor.class);
31 public static <T extends DataObject> boolean executePutCommand(InstanceIdentifier<Node> nodeIid,
32 AbstractLispCommand<T> lispStateCommand) {
33 lispStateCommand.setOptions(General.Operations.PUT);
34 return executeCommand(nodeIid, lispStateCommand);
37 public static <T extends DataObject> boolean executePutCommand(String hostName,
38 AbstractLispCommand<T> lispStateCommand) {
39 lispStateCommand.setOptions(General.Operations.PUT);
40 return executeCommand(LispUtil.HOSTNAME_TO_IID.apply(hostName), lispStateCommand);
43 public static <T extends DataObject> boolean executeDeleteCommand(InstanceIdentifier<Node> nodeIid,
44 AbstractLispCommand<T> lispStateCommand) {
45 lispStateCommand.setOptions(General.Operations.DELETE);
46 return executeCommand(nodeIid, lispStateCommand);
49 public static <T extends DataObject> boolean executeDeleteCommand(String hostName,
50 AbstractLispCommand<T> lispStateCommand) {
51 lispStateCommand.setOptions(General.Operations.DELETE);
52 return executeCommand(LispUtil.HOSTNAME_TO_IID.apply(hostName), lispStateCommand);
55 public static <T extends DataObject> boolean executeCommand(InstanceIdentifier<Node> nodeIid,
56 AbstractLispCommand<T> lispStateCommand) {
57 final boolean transactionState = GbpNetconfTransaction.netconfSyncedWrite(nodeIid, lispStateCommand.getIid(),
58 lispStateCommand.getData(), GbpNetconfTransaction.RETRY_COUNT);
59 if (transactionState) {
60 LOG.trace("Successfully executed command: ", lispStateCommand);
62 LOG.debug("Failed to execute command: ", lispStateCommand);
65 return transactionState;