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;
25 public class LispStateCommandExecutor {
26 private static final Logger LOG = LoggerFactory.getLogger(LispStateCommandExecutor.class);
28 public static <T extends DataObject> boolean executePutCommand(InstanceIdentifier<Node> nodeIid,
29 AbstractLispCommand<T> lispStateCommand) {
30 lispStateCommand.setOperation(General.Operations.PUT);
31 return executeCommand(nodeIid, lispStateCommand);
34 public static <T extends DataObject> boolean executePutCommand(String hostName,
35 AbstractLispCommand<T> lispStateCommand) {
36 lispStateCommand.setOperation(General.Operations.PUT);
37 return executeCommand(LispUtil.HOSTNAME_TO_IID.apply(hostName), lispStateCommand);
40 public static <T extends DataObject> boolean executeMergeCommand(String hostName,
41 AbstractLispCommand<T> lispStateCommand) {
42 lispStateCommand.setOperation(General.Operations.MERGE);
43 return executeCommand(LispUtil.HOSTNAME_TO_IID.apply(hostName), lispStateCommand);
46 public static <T extends DataObject> boolean executeDeleteCommand(InstanceIdentifier<Node> nodeIid,
47 AbstractLispCommand<T> lispStateCommand) {
48 lispStateCommand.setOperation(General.Operations.DELETE);
49 return executeCommand(nodeIid, lispStateCommand);
52 public static <T extends DataObject> boolean executeDeleteCommand(String hostName,
53 AbstractLispCommand<T> lispStateCommand) {
54 lispStateCommand.setOperation(General.Operations.DELETE);
55 return executeCommand(LispUtil.HOSTNAME_TO_IID.apply(hostName), lispStateCommand);
58 public static <T extends DataObject> boolean executeCommand(InstanceIdentifier<Node> nodeIid,
59 AbstractLispCommand<T> lispStateCommand) {
60 final boolean transactionState;
61 switch (lispStateCommand.getOperation()) {
64 transactionState = GbpNetconfTransaction.netconfSyncedWrite(nodeIid, lispStateCommand.getIid(),
65 lispStateCommand.getData(), GbpNetconfTransaction.RETRY_COUNT);
69 transactionState = GbpNetconfTransaction.netconfSyncedDelete(nodeIid, lispStateCommand.getIid(),
70 GbpNetconfTransaction.RETRY_COUNT);
74 throw new IllegalStateException("No supported operation specified.");
76 if (transactionState) {
77 LOG.trace("Successfully executed command: {}", lispStateCommand);
79 LOG.debug("Failed to execute command: {}", lispStateCommand);
82 return transactionState;