/* * Copyright (c) 2017 Cisco Systems. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp; import org.opendaylight.groupbasedpolicy.renderer.vpp.commands.lisp.AbstractLispCommand; import org.opendaylight.groupbasedpolicy.renderer.vpp.util.GbpNetconfTransaction; import org.opendaylight.groupbasedpolicy.renderer.vpp.util.General; import org.opendaylight.groupbasedpolicy.renderer.vpp.util.LispUtil; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class LispStateCommandExecutor { private static final Logger LOG = LoggerFactory.getLogger(LispStateCommandExecutor.class); public static boolean executePutCommand(InstanceIdentifier nodeIid, AbstractLispCommand lispStateCommand) { lispStateCommand.setOperation(General.Operations.PUT); return executeCommand(nodeIid, lispStateCommand); } static boolean executePutCommand(String hostName, AbstractLispCommand lispStateCommand) { lispStateCommand.setOperation(General.Operations.PUT); return executeCommand(LispUtil.hostnameToIid(hostName), lispStateCommand); } static boolean executeMergeCommand(String hostName, AbstractLispCommand lispStateCommand) { lispStateCommand.setOperation(General.Operations.MERGE); return executeCommand(LispUtil.hostnameToIid(hostName), lispStateCommand); } public static boolean executeDeleteCommand(InstanceIdentifier nodeIid, AbstractLispCommand lispStateCommand) { lispStateCommand.setOperation(General.Operations.DELETE); return executeCommand(nodeIid, lispStateCommand); } static boolean executeDeleteCommand(String hostName, AbstractLispCommand lispStateCommand) { lispStateCommand.setOperation(General.Operations.DELETE); return executeCommand(LispUtil.hostnameToIid(hostName), lispStateCommand); } private static boolean executeCommand(InstanceIdentifier nodeIid, AbstractLispCommand lispStateCommand) { final boolean transactionState; switch (lispStateCommand.getOperation()) { case MERGE: case PUT: { transactionState = GbpNetconfTransaction.netconfSyncedWrite(nodeIid, lispStateCommand.getIid(), lispStateCommand.getData(), GbpNetconfTransaction.RETRY_COUNT); break; } case DELETE: { transactionState = GbpNetconfTransaction.netconfSyncedDelete(nodeIid, lispStateCommand.getIid(), GbpNetconfTransaction.RETRY_COUNT); } break; default: throw new IllegalStateException("No supported operation specified."); } if (transactionState) { LOG.trace("Successfully executed command: {}", lispStateCommand); } else { LOG.debug("Failed to execute command: {}", lispStateCommand); } return transactionState; } }