X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=southbound%2Fsouthbound-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fovsdb%2Fsouthbound%2FOvsdbConnectionInstance.java;h=ce8181c87202c3885bc0209671e30ef4f6a19e26;hb=55ce82cbd9fdcb0edf9e629bd2d626b193c6ab26;hp=33184082ca1860ea717c42682a2eaea425fd3d4c;hpb=fc1ac1a87136e0f273aeb783dfb63e2911853a21;p=ovsdb.git diff --git a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstance.java b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstance.java index 33184082c..ce8181c87 100644 --- a/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstance.java +++ b/southbound/southbound-impl/src/main/java/org/opendaylight/ovsdb/southbound/OvsdbConnectionInstance.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2015, 2016 Cisco Systems, Inc. and others. 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, @@ -9,6 +9,7 @@ package org.opendaylight.ovsdb.southbound; import static org.opendaylight.ovsdb.lib.operations.Operations.op; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -18,8 +19,10 @@ import java.util.concurrent.ExecutionException; import javax.annotation.Nonnull; +import org.opendaylight.controller.md.sal.binding.api.DataTreeModification; import org.opendaylight.controller.md.sal.common.api.clustering.Entity; import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipCandidateRegistration; +import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent; import org.opendaylight.ovsdb.lib.EchoServiceCallbackFilters; import org.opendaylight.ovsdb.lib.LockAquisitionCallback; import org.opendaylight.ovsdb.lib.LockStolenCallback; @@ -43,11 +46,13 @@ import org.opendaylight.ovsdb.lib.schema.TableSchema; import org.opendaylight.ovsdb.lib.schema.typed.TypedBaseTable; import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils; import org.opendaylight.ovsdb.schema.openvswitch.OpenVSwitch; +import org.opendaylight.ovsdb.southbound.ovsdb.transact.BridgeOperationalState; import org.opendaylight.ovsdb.southbound.ovsdb.transact.TransactCommand; import org.opendaylight.ovsdb.southbound.ovsdb.transact.TransactInvoker; import org.opendaylight.ovsdb.southbound.ovsdb.transact.TransactInvokerImpl; import org.opendaylight.ovsdb.southbound.ovsdb.transact.TransactUtils; import org.opendaylight.ovsdb.southbound.transactions.md.TransactionInvoker; +import org.opendaylight.ovsdb.utils.yang.YangUtils; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbNodeAugmentation; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.ConnectionInfo; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.node.attributes.OpenvswitchExternalIds; @@ -55,11 +60,11 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.re import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey; +import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Lists; import com.google.common.util.concurrent.ListenableFuture; @@ -85,9 +90,31 @@ public class OvsdbConnectionInstance implements OvsdbClient { this.instanceIdentifier = iid; } - public void transact(TransactCommand command) { - for (TransactInvoker transactInvoker: transactInvokers.values()) { - transactInvoker.invoke(command); + /** + * Apply the given command to the given events, based on the given bridge state. + * + * @param command The command to run. + * @param state The current bridge state. + * @param events The events to process. + */ + public void transact(TransactCommand command, BridgeOperationalState state, + AsyncDataChangeEvent, DataObject> events) { + for (TransactInvoker transactInvoker : transactInvokers.values()) { + transactInvoker.invoke(command, state, events); + } + } + + /** + * Apply the given command to the given modifications, based on the given bridge state. + * + * @param command The command to run. + * @param state The current bridge state. + * @param modifications The modifications to process. + */ + public void transact(TransactCommand command, BridgeOperationalState state, + Collection> modifications) { + for (TransactInvoker transactInvoker : transactInvokers.values()) { + transactInvoker.invoke(command, state, modifications); } } @@ -117,12 +144,9 @@ public class OvsdbConnectionInstance implements OvsdbClient { if (transactInvokers == null) { try { transactInvokers = new HashMap<>(); - List databases = getDatabases().get(); - for (String database : databases) { - DatabaseSchema dbSchema = getSchema(database).get(); - if (dbSchema != null) { - transactInvokers.put(dbSchema, new TransactInvokerImpl(this,dbSchema)); - } + DatabaseSchema dbSchema = getSchema(SouthboundConstants.OPEN_V_SWITCH).get(); + if(dbSchema != null) { + transactInvokers.put(dbSchema, new TransactInvokerImpl(this,dbSchema)); } } catch (InterruptedException | ExecutionException e) { LOG.warn("Exception attempting to createTransactionInvokers {}", connectionInfo, e); @@ -160,20 +184,15 @@ public class OvsdbConnectionInstance implements OvsdbClient { // OpenVSwitchPart OpenVSwitch ovs = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), OpenVSwitch.class); - Map externalIdsMap = new HashMap<>(); List externalIds = this.initialCreateData.getOpenvswitchExternalIds(); - if (externalIds != null) { - for (OpenvswitchExternalIds externalId : externalIds) { - externalIdsMap.put(externalId.getExternalIdKey(), externalId.getExternalIdValue()); - } - } - stampInstanceIdentifier(transaction,this.instanceIdentifier.firstIdentifierOf(Node.class)); try { - ovs.setExternalIds(ImmutableMap.copyOf(externalIdsMap)); + ovs.setExternalIds( + YangUtils.convertYangKeyValueListToMap(externalIds, OpenvswitchExternalIds::getExternalIdKey, + OpenvswitchExternalIds::getExternalIdValue)); Mutate mutate = op.mutate(ovs) .addMutation(ovs.getExternalIdsColumn().getSchema(), Mutator.INSERT, @@ -187,12 +206,10 @@ public class OvsdbConnectionInstance implements OvsdbClient { List otherConfigs = this.initialCreateData.getOpenvswitchOtherConfigs(); if (otherConfigs != null) { - Map otherConfigsMap = new HashMap<>(); - for (OpenvswitchOtherConfigs otherConfig : otherConfigs) { - otherConfigsMap.put(otherConfig.getOtherConfigKey(), otherConfig.getOtherConfigValue()); - } try { - ovs.setOtherConfig(ImmutableMap.copyOf(otherConfigsMap)); + ovs.setOtherConfig(YangUtils.convertYangKeyValueListToMap(otherConfigs, + OpenvswitchOtherConfigs::getOtherConfigKey, + OpenvswitchOtherConfigs::getOtherConfigValue)); transaction.add(op.mutate(ovs).addMutation(ovs.getOtherConfigColumn().getSchema(), Mutator.INSERT, ovs.getOtherConfigColumn().getData())); @@ -377,4 +394,9 @@ public class OvsdbConnectionInstance implements OvsdbClient { public void setOvsdbNodeAugmentation(OvsdbNodeAugmentation ovsdbNodeCreateData) { this.initialCreateData = ovsdbNodeCreateData; } + + @Override + public void echo() { + client.echo(); + } }