2 * Copyright (c) 2015 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.transactions.md;
10 import com.google.common.base.Preconditions;
11 import java.util.ArrayList;
12 import java.util.List;
14 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.ovsdb.lib.message.TableUpdates;
17 import org.opendaylight.ovsdb.lib.notation.UUID;
18 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
19 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
20 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
21 import org.opendaylight.ovsdb.schema.openvswitch.Controller;
22 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
23 import org.opendaylight.ovsdb.southbound.SouthboundMapper;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntryKey;
28 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 public class OvsdbControllerRemovedCommand extends AbstractTransactionCommand {
35 private Map<UUID, Bridge> oldBridgeRows;
36 private Map<UUID, Controller> removedControllerRows;
37 private Map<UUID, Bridge> updatedBridgeRows;
39 public OvsdbControllerRemovedCommand(OvsdbConnectionInstance key,
40 TableUpdates updates, DatabaseSchema dbSchema) {
41 super(key, updates, dbSchema);
42 updatedBridgeRows = TyperUtils.extractRowsUpdated(Bridge.class, getUpdates(), getDbSchema());
43 oldBridgeRows = TyperUtils.extractRowsOld(Bridge.class, getUpdates(), getDbSchema());
44 removedControllerRows = TyperUtils.extractRowsRemoved(Controller.class,
45 getUpdates(), getDbSchema());
49 public void execute(ReadWriteTransaction transaction) {
50 for (Bridge bridge : updatedBridgeRows.values()) {
51 InstanceIdentifier<Node> bridgeIid =
52 SouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(), bridge);
53 deleteControllers(transaction, controllerEntriesToRemove(bridgeIid,bridge));
57 private void deleteControllers(ReadWriteTransaction transaction,
58 List<InstanceIdentifier<ControllerEntry>> controllerEntryIids) {
59 for (InstanceIdentifier<ControllerEntry> controllerEntryIid: controllerEntryIids) {
60 transaction.delete(LogicalDatastoreType.OPERATIONAL, controllerEntryIid);
64 private List<InstanceIdentifier<ControllerEntry>> controllerEntriesToRemove(
65 InstanceIdentifier<Node> bridgeIid, Bridge bridge) {
66 Preconditions.checkNotNull(bridgeIid);
67 Preconditions.checkNotNull(bridge);
68 List<InstanceIdentifier<ControllerEntry>> result =
70 Bridge oldBridgeNode = oldBridgeRows.get(bridge.getUuid());
72 if (oldBridgeNode != null && oldBridgeNode.getControllerColumn() != null) {
73 for (UUID controllerUuid: oldBridgeNode.getControllerColumn().getData()) {
74 if (bridge.getControllerColumn() == null
75 || !bridge.getControllerColumn().getData().contains(controllerUuid)) {
76 Controller controller = removedControllerRows.get(controllerUuid);
77 if (controller != null && controller.getTargetColumn() != null) {
78 InstanceIdentifier<ControllerEntry> iid = bridgeIid
79 .augmentation(OvsdbBridgeAugmentation.class)
80 .child(ControllerEntry.class,
81 new ControllerEntryKey(new Uri(controller.getTargetColumn().getData())));