2 * Copyright (c) 2015 China Telecom Beijing Research Institute 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
9 package org.opendaylight.ovsdb.hwvtepsouthbound.transact;
11 import static org.opendaylight.ovsdb.lib.operations.Operations.op;
13 import java.util.Collection;
14 import java.util.List;
16 import java.util.Map.Entry;
17 import java.util.Objects;
19 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
20 import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundUtil;
21 import org.opendaylight.ovsdb.lib.notation.UUID;
22 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
23 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
24 import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.LogicalSwitches;
27 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
28 import org.opendaylight.yangtools.yang.binding.Identifiable;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import com.google.common.base.Optional;
35 public class LogicalSwitchRemoveCommand extends AbstractTransactCommand<LogicalSwitches, HwvtepGlobalAugmentation> {
36 private static final Logger LOG = LoggerFactory.getLogger(LogicalSwitchRemoveCommand.class);
38 public LogicalSwitchRemoveCommand(HwvtepOperationalState state,
39 Collection<DataTreeModification<Node>> changes) {
40 super(state, changes);
44 public void execute(TransactionBuilder transaction) {
45 Map<InstanceIdentifier<Node>, List<LogicalSwitches>> removeds =
46 extractRemoved(getChanges(),LogicalSwitches.class);
47 if (removeds != null) {
48 for (Entry<InstanceIdentifier<Node>, List<LogicalSwitches>> created: removeds.entrySet()) {
49 if (!HwvtepSouthboundUtil.isEmpty(created.getValue())) {
50 for (LogicalSwitches lswitch : created.getValue()) {
51 InstanceIdentifier<LogicalSwitches> lsKey = created.getKey().augmentation(
52 HwvtepGlobalAugmentation.class).child(LogicalSwitches.class, lswitch.getKey());
53 updateCurrentTxDeleteData(LogicalSwitches.class, lsKey, lswitch);
55 getOperationalState().getDeviceInfo().scheduleTransaction(new TransactCommand() {
57 public void execute(TransactionBuilder transactionBuilder) {
58 LOG.debug("Running delete logical switch in seperate tx {}", created.getKey());
59 removeLogicalSwitch(transactionBuilder, created.getKey(), created.getValue());
63 public void onConfigUpdate(TransactionBuilder transaction, InstanceIdentifier nodeIid,
64 Identifiable data, InstanceIdentifier key, Object... extraData) {
68 public void doDeviceTransaction(TransactionBuilder transaction, InstanceIdentifier nodeIid,
69 Identifiable data, InstanceIdentifier key, Object... extraData) {
77 private void removeLogicalSwitch(TransactionBuilder transaction,
78 InstanceIdentifier<Node> instanceIdentifier, List<LogicalSwitches> lswitchList) {
79 for (LogicalSwitches lswitch: lswitchList) {
80 LOG.debug("Removing logcial switch named: {}", lswitch.getHwvtepNodeName().getValue());
81 Optional<LogicalSwitches> operationalSwitchOptional =
82 getOperationalState().getLogicalSwitches(instanceIdentifier, lswitch.getKey());
83 LogicalSwitch logicalSwitch = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), LogicalSwitch.class, null);
85 if (operationalSwitchOptional.isPresent() &&
86 operationalSwitchOptional.get().getLogicalSwitchUuid() != null) {
87 UUID logicalSwitchUuid = new UUID(operationalSwitchOptional.get().getLogicalSwitchUuid().getValue());
88 transaction.add(op.delete(logicalSwitch.getSchema())
89 .where(logicalSwitch.getUuidColumn().getSchema().opEqual(logicalSwitchUuid)).build());
90 transaction.add(op.comment("Logical Switch: Deleting " + lswitch.getHwvtepNodeName().getValue()));
92 LOG.warn("Unable to delete logical switch {} because it was not found in the operational store",
93 lswitch.getHwvtepNodeName().getValue());
99 protected List<LogicalSwitches> getData(HwvtepGlobalAugmentation augmentation) {
100 return augmentation.getLogicalSwitches();
104 protected boolean areEqual(LogicalSwitches a , LogicalSwitches b) {
105 return a.getKey().equals(b.getKey()) && Objects.equals(a.getTunnelKey(), b.getTunnelKey());
109 protected boolean isRemoveCommand() {