return result;
}
+ /**
+ * This method extracts all row updates of Class<T> klazz from a TableUpdates
+ * that correspond to old version of rows of type klazz that have been updated
+ * Example:
+ * <code>
+ * Map<UUID,Bridge> oldBridges = extractRowsOld(Bridge.class,updates,dbSchema)
+ * </code>
+ *
+ * @param klazz Class for row type to be extracted
+ * @param updates TableUpdates from which to extract rowUpdates
+ * @param dbSchema Dbschema for the TableUpdates
+ * @return Map<UUID,T> for the type of things being sought
+ */
+ public static <T> Map<UUID,T> extractRowsOld(Class<T> klazz,TableUpdates updates,DatabaseSchema dbSchema) {
+ Preconditions.checkNotNull(klazz);
+ Preconditions.checkNotNull(updates);
+ Preconditions.checkNotNull(dbSchema);
+ Map<UUID,T> result = new HashMap<UUID,T>();
+ Map<UUID,TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema>> rowUpdates =
+ extractRowUpdates(klazz,updates,dbSchema);
+ for (TableUpdate<GenericTableSchema>.RowUpdate<GenericTableSchema> rowUpdate : rowUpdates.values()) {
+ if (rowUpdate != null) {
+ if (rowUpdate.getOld() != null) {
+ Row<GenericTableSchema> row = rowUpdate.getOld();
+ result.put(rowUpdate.getUuid(),TyperUtils.getTypedRowWrapper(dbSchema,klazz,row));
+ }
+ }
+ }
+ return result;
+ }
+
/**
* This method extracts all row updates of Class<T> klazz from a TableUpdates
* that correspond to removal of rows of type klazz.
import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
-import org.opendaylight.ovsdb.schema.openvswitch.Controller;
import org.opendaylight.ovsdb.southbound.OvsdbClientKey;
import org.opendaylight.ovsdb.southbound.SouthboundConstants;
import org.opendaylight.ovsdb.southbound.SouthboundMapper;
public class OvsdbBridgeUpdateCommand extends AbstractTransactionCommand {
private static final Logger LOG = LoggerFactory.getLogger(OvsdbBridgeUpdateCommand.class);
- private Map<UUID,Controller> updatedControllerRows;
private Map<UUID,Bridge> updatedBridgeRows;
public OvsdbBridgeUpdateCommand(OvsdbClientKey key, TableUpdates updates,
DatabaseSchema dbSchema) {
super(key,updates,dbSchema);
updatedBridgeRows = TyperUtils.extractRowsUpdated(Bridge.class, getUpdates(), getDbSchema());
- updatedControllerRows = TyperUtils.extractRowsUpdated(Controller.class,
- getUpdates(), getDbSchema());
}
@Override
setProtocol(ovsdbBridgeAugmentationBuilder, bridge);
setExternalIds(ovsdbBridgeAugmentationBuilder, bridge);
setOtherConfig(ovsdbBridgeAugmentationBuilder, bridge);
- setController(ovsdbBridgeAugmentationBuilder, bridge);
setFailMode(ovsdbBridgeAugmentationBuilder, bridge);
setManagedBy(ovsdbBridgeAugmentationBuilder);
bridgeNodeBuilder.addAugmentation(OvsdbBridgeAugmentation.class, ovsdbBridgeAugmentationBuilder.build());
}
}
- private void setController(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder,Bridge bridge) {
- if (!SouthboundMapper.createControllerEntries(bridge, updatedControllerRows).isEmpty()) {
- ovsdbBridgeAugmentationBuilder.setControllerEntry(
- SouthboundMapper.createControllerEntries(bridge, updatedControllerRows));
- }
- }
-
private void setOtherConfig(OvsdbBridgeAugmentationBuilder ovsdbBridgeAugmentationBuilder,
Bridge bridge) {
Map<String, String> otherConfigs = bridge
--- /dev/null
+/*
+ * Copyright (c) 2015 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.ovsdb.southbound.transactions.md;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
+import org.opendaylight.ovsdb.schema.openvswitch.Controller;
+import org.opendaylight.ovsdb.southbound.OvsdbClientKey;
+import org.opendaylight.ovsdb.southbound.SouthboundMapper;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Uri;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryKey;
+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.InstanceIdentifier;
+
+import com.google.common.base.Preconditions;
+
+public class OvsdbControllerRemovedCommand extends AbstractTransactionCommand {
+
+
+
+ private Map<UUID, Bridge> oldBridgeRows;
+ private Map<UUID, Controller> removedControllerRows;
+ private Map<UUID, Bridge> updatedBridgeRows;
+
+ public OvsdbControllerRemovedCommand(OvsdbClientKey key,
+ TableUpdates updates, DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ updatedBridgeRows = TyperUtils.extractRowsUpdated(Bridge.class, getUpdates(), getDbSchema());
+ oldBridgeRows = TyperUtils.extractRowsOld(Bridge.class, getUpdates(), getDbSchema());
+ removedControllerRows = TyperUtils.extractRowsRemoved(Controller.class,
+ getUpdates(), getDbSchema());
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ for (Bridge bridge : updatedBridgeRows.values()) {
+ InstanceIdentifier<Node> bridgeIid = SouthboundMapper.createInstanceIdentifier(getKey(), bridge);
+ deleteControllers(transaction, controllerEntriesToRemove(bridgeIid,bridge));
+ }
+ }
+
+ private void deleteControllers(ReadWriteTransaction transaction,
+ List<InstanceIdentifier<ControllerEntry>> controllerEntryIids) {
+ for (InstanceIdentifier<ControllerEntry> controllerEntryIid: controllerEntryIids) {
+ transaction.delete(LogicalDatastoreType.OPERATIONAL, controllerEntryIid);
+ }
+ }
+
+ private List<InstanceIdentifier<ControllerEntry>> controllerEntriesToRemove(
+ InstanceIdentifier<Node> bridgeIid, Bridge bridge) {
+ Preconditions.checkNotNull(bridgeIid);
+ Preconditions.checkNotNull(bridge);
+ List<InstanceIdentifier<ControllerEntry>> result =
+ new ArrayList<InstanceIdentifier<ControllerEntry>>();
+ Bridge oldBridgeNode = oldBridgeRows.get(bridge.getUuid());
+
+ if (oldBridgeNode != null && oldBridgeNode.getControllerColumn() != null) {
+ for (UUID controllerUuid: oldBridgeNode.getControllerColumn().getData()) {
+ if (bridge.getControllerColumn() == null
+ || !bridge.getControllerColumn().getData().contains(controllerUuid)) {
+ Controller controller = removedControllerRows.get(controllerUuid);
+ if (controller != null && controller.getTargetColumn() != null) {
+ InstanceIdentifier<ControllerEntry> iid = bridgeIid
+ .augmentation(OvsdbBridgeAugmentation.class)
+ .child(ControllerEntry.class,
+ new ControllerEntryKey(new Uri(controller.getTargetColumn().getData())));
+ result.add(iid);
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.ovsdb.southbound.transactions.md;
+
+import java.util.Map;
+
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.ovsdb.lib.message.TableUpdates;
+import org.opendaylight.ovsdb.lib.notation.UUID;
+import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
+import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
+import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
+import org.opendaylight.ovsdb.schema.openvswitch.Controller;
+import org.opendaylight.ovsdb.southbound.OvsdbClientKey;
+import org.opendaylight.ovsdb.southbound.SouthboundMapper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class OvsdbControllerUpdateCommand extends AbstractTransactionCommand {
+
+
+
+ private Map<UUID, Controller> updatedControllerRows;
+ private Map<UUID, Bridge> updatedBridgeRows;
+
+ public OvsdbControllerUpdateCommand(OvsdbClientKey key,
+ TableUpdates updates, DatabaseSchema dbSchema) {
+ super(key, updates, dbSchema);
+ updatedBridgeRows = TyperUtils.extractRowsUpdated(Bridge.class, getUpdates(), getDbSchema());
+ updatedControllerRows = TyperUtils.extractRowsUpdated(Controller.class,
+ getUpdates(), getDbSchema());
+ }
+
+ @Override
+ public void execute(ReadWriteTransaction transaction) {
+ for (Bridge bridge: updatedBridgeRows.values()) {
+ setController(transaction, bridge);
+ }
+
+ }
+
+ private void setController(ReadWriteTransaction transaction, Bridge bridge) {
+ for (ControllerEntry controllerEntry: SouthboundMapper.createControllerEntries(bridge, updatedControllerRows)) {
+ InstanceIdentifier<ControllerEntry> iid = SouthboundMapper.createInstanceIdentifier(getKey(), bridge)
+ .augmentation(OvsdbBridgeAugmentation.class)
+ .child(ControllerEntry.class,controllerEntry.getKey());
+ transaction.put(LogicalDatastoreType.OPERATIONAL, iid, controllerEntry);
+ }
+ }
+
+}
public OvsdbOperationalCommandAggregator(OvsdbClientKey key,TableUpdates updates, DatabaseSchema dbSchema) {
commands.add(new OvsdbBridgeUpdateCommand(key, updates, dbSchema));
commands.add(new OvsdbBridgeRemovedCommand(key, updates, dbSchema));
+ commands.add(new OvsdbControllerUpdateCommand(key, updates, dbSchema));
+ commands.add(new OvsdbControllerRemovedCommand(key, updates, dbSchema));
commands.add(new OvsdbPortUpdateCommand(key, updates, dbSchema));
commands.add(new OvsdbPortRemoveCommand(key, updates, dbSchema));
commands.add(new OpenVSwitchUpdateCommand(key, updates, dbSchema));