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 java.util.ArrayList;
11 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.rev100924.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 import com.google.common.base.Preconditions;
33 public class OvsdbControllerRemovedCommand extends AbstractTransactionCommand {
37 private Map<UUID, Bridge> oldBridgeRows;
38 private Map<UUID, Controller> removedControllerRows;
39 private Map<UUID, Bridge> updatedBridgeRows;
41 public OvsdbControllerRemovedCommand(OvsdbConnectionInstance key,
42 TableUpdates updates, DatabaseSchema dbSchema) {
43 super(key, updates, dbSchema);
44 updatedBridgeRows = TyperUtils.extractRowsUpdated(Bridge.class, getUpdates(), getDbSchema());
45 oldBridgeRows = TyperUtils.extractRowsOld(Bridge.class, getUpdates(), getDbSchema());
46 removedControllerRows = TyperUtils.extractRowsRemoved(Controller.class,
47 getUpdates(), getDbSchema());
51 public void execute(ReadWriteTransaction transaction) {
52 for (Bridge bridge : updatedBridgeRows.values()) {
53 InstanceIdentifier<Node> bridgeIid =
54 SouthboundMapper.createInstanceIdentifier(getOvsdbConnectionInstance(), bridge);
55 deleteControllers(transaction, controllerEntriesToRemove(bridgeIid,bridge));
59 private void deleteControllers(ReadWriteTransaction transaction,
60 List<InstanceIdentifier<ControllerEntry>> controllerEntryIids) {
61 for (InstanceIdentifier<ControllerEntry> controllerEntryIid: controllerEntryIids) {
62 transaction.delete(LogicalDatastoreType.OPERATIONAL, controllerEntryIid);
66 private List<InstanceIdentifier<ControllerEntry>> controllerEntriesToRemove(
67 InstanceIdentifier<Node> bridgeIid, Bridge bridge) {
68 Preconditions.checkNotNull(bridgeIid);
69 Preconditions.checkNotNull(bridge);
70 List<InstanceIdentifier<ControllerEntry>> result =
72 Bridge oldBridgeNode = oldBridgeRows.get(bridge.getUuid());
74 if (oldBridgeNode != null && oldBridgeNode.getControllerColumn() != null) {
75 for (UUID controllerUuid: oldBridgeNode.getControllerColumn().getData()) {
76 if (bridge.getControllerColumn() == null
77 || !bridge.getControllerColumn().getData().contains(controllerUuid)) {
78 Controller controller = removedControllerRows.get(controllerUuid);
79 if (controller != null && controller.getTargetColumn() != null) {
80 InstanceIdentifier<ControllerEntry> iid = bridgeIid
81 .augmentation(OvsdbBridgeAugmentation.class)
82 .child(ControllerEntry.class,
83 new ControllerEntryKey(new Uri(controller.getTargetColumn().getData())));