2 * Copyright (c) 2014 Cisco Systems, Inc. and others. 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
8 package org.opendaylight.ovsdb.southbound.ovsdb.transact;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import java.util.Collection;
12 import java.util.List;
13 import java.util.concurrent.ExecutionException;
15 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
16 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
17 import org.opendaylight.ovsdb.lib.operations.OperationResult;
18 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
19 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
20 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
21 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
22 import org.opendaylight.yangtools.yang.binding.DataObject;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class TransactInvokerImpl implements TransactInvoker {
28 private static final Logger LOG = LoggerFactory.getLogger(TransactInvokerImpl.class);
29 private OvsdbConnectionInstance connectionInstance;
30 private DatabaseSchema dbSchema;
32 public TransactInvokerImpl(OvsdbConnectionInstance connectionInstance, DatabaseSchema dbSchema) {
33 this.connectionInstance = connectionInstance;
34 this.dbSchema = dbSchema;
38 public void invoke(TransactCommand command, BridgeOperationalState state,
39 AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events) {
40 TransactionBuilder tb = new TransactionBuilder(connectionInstance, dbSchema);
41 command.execute(tb, state, events);
46 public void invoke(TransactCommand command, BridgeOperationalState state,
47 Collection<DataTreeModification<Node>> modifications) {
48 TransactionBuilder tb = new TransactionBuilder(connectionInstance, dbSchema);
49 command.execute(tb, state, modifications);
53 private void invoke(TransactCommand command, TransactionBuilder tb) {
54 ListenableFuture<List<OperationResult>> result = tb.execute();
55 LOG.debug("invoke: command: {}, tb: {}", command, tb);
56 if (tb.getOperations().size() > 0) {
58 List<OperationResult> got = result.get();
59 LOG.debug("OVSDB transaction result: {}", got);
60 } catch (InterruptedException | ExecutionException e) {
61 LOG.warn("Transact execution exception: ", e);
63 LOG.trace("invoke exit command: {}, tb: {}", command, tb);