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;
15 import java.util.Map.Entry;
18 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
19 import org.opendaylight.ovsdb.lib.notation.UUID;
20 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
21 import org.opendaylight.ovsdb.lib.schema.typed.TyperUtils;
22 import org.opendaylight.ovsdb.schema.hardwarevtep.Global;
23 import org.opendaylight.ovsdb.schema.hardwarevtep.LogicalSwitch;
24 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 import com.google.common.base.Optional;
31 public class LogicalSwitchRemoveCommand extends AbstractTransactCommand {
32 private static final Logger LOG = LoggerFactory.getLogger(LogicalSwitchRemoveCommand.class);
34 public LogicalSwitchRemoveCommand(HwvtepOperationalState state,
35 Collection<DataTreeModification<Node>> changes) {
36 super(state, changes);
40 public void execute(TransactionBuilder transaction) {
42 /*Set<InstanceIdentifier<HwvtepLogicalSwitchAugmentation>> removeds =
43 TransactUtils.extractRemoved(getChanges(),HwvtepLogicalSwitchAugmentation.class);
44 Map<InstanceIdentifier<HwvtepLogicalSwitchAugmentation>, HwvtepLogicalSwitchAugmentation> originals
45 = TransactUtils.extractOriginal(getChanges(),HwvtepLogicalSwitchAugmentation.class);
46 for (InstanceIdentifier<HwvtepLogicalSwitchAugmentation> removed: removeds) {
47 LOG.info("Received request to delete ovsdb node {}",removed);
48 HwvtepLogicalSwitchAugmentation original = originals.get(removed);
49 LogicalSwitch bridge = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(), LogicalSwitch.class, null);
50 Optional<HwvtepLogicalSwitchAugmentation> lsAugmentationOptional = getOperationalState()
51 .getLogicalSwitchAugmentation(removed);
52 if (lsAugmentationOptional.isPresent() && lsAugmentationOptional.get().getHwvtepLogicalSwitchExternalId() != null) {
53 UUID lsUuid = new UUID(lsAugmentationOptional.get().getHwvtepLogicalSwitchExternalId().getValue());
54 Global ovs = TyperUtils.getTypedRowWrapper(transaction.getDatabaseSchema(),
56 transaction.add(op.delete(bridge.getSchema())
57 .where(bridge.getUuidColumn().getSchema().opEqual(lsUuid)).build());
58 transaction.add(op.comment("Logical Switch: Deleting " + original.getHwvtepNodeName()));
60 LOG.warn("Unable to delete logical switch {} because it was not found in the operational store, "
61 + "and thus we cannot retrieve its UUID", removed);