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 static org.opendaylight.ovsdb.lib.operations.Operations.op;
15 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
16 import org.opendaylight.ovsdb.lib.notation.Mutator;
17 import org.opendaylight.ovsdb.lib.notation.UUID;
18 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
19 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
20 import org.opendaylight.ovsdb.schema.openvswitch.Bridge;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.OvsdbBridgeAugmentation;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.rev150105.ovsdb.bridge.attributes.ControllerEntry;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import com.google.common.base.Optional;
27 import com.google.common.collect.Sets;
29 public class ControllerRemovedCommand implements TransactCommand {
32 public void execute(TransactionBuilder transaction, BridgeOperationalState state,
33 AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events) {
34 execute(transaction, state, TransactUtils.extractRemoved(events, ControllerEntry.class),
35 TransactUtils.extractCreatedOrUpdatedOrRemoved(events, OvsdbBridgeAugmentation.class));
38 private void execute(TransactionBuilder transaction, BridgeOperationalState state,
39 Set<InstanceIdentifier<ControllerEntry>> removedControllers,
40 Map<InstanceIdentifier<OvsdbBridgeAugmentation>, OvsdbBridgeAugmentation>
42 for (InstanceIdentifier<ControllerEntry> controllerIid : removedControllers) {
43 InstanceIdentifier<OvsdbBridgeAugmentation> bridgeIid =
44 controllerIid.firstIdentifierOf(OvsdbBridgeAugmentation.class);
45 OvsdbBridgeAugmentation ovsdbBridge = modifiedBridges.get(bridgeIid);
46 Optional<ControllerEntry> controllerEntryOptional = state.getControllerEntry(controllerIid);
47 if (ovsdbBridge != null && controllerEntryOptional.isPresent()) {
48 ControllerEntry controllerEntry = controllerEntryOptional.get();
49 Bridge bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), Bridge.class);
50 bridge.setController(Sets.newHashSet(new UUID(controllerEntry.getControllerUuid().getValue())));
51 transaction.add(op.mutate(bridge).addMutation(bridge.getControllerColumn().getSchema(),
52 Mutator.DELETE, bridge.getControllerColumn().getData()));