2 * Copyright (c) 2016 CableLabs 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.unimgr.command;
10 import java.util.List;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.unimgr.utils.EvcUtils;
17 import org.opendaylight.unimgr.utils.MdsalUtils;
18 import org.opendaylight.unimgr.utils.OvsdbUtils;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.EvcAugmentation;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniDest;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.unimgr.rev151012.evc.UniSource;
22 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 import com.google.common.base.Optional;
28 public class EvcDeleteCommand extends AbstractDeleteCommand {
30 public EvcDeleteCommand(DataBroker dataBroker,
31 AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> changes) {
32 super.changes = changes;
33 super.dataBroker = dataBroker;
37 public void execute() {
38 Set<InstanceIdentifier<EvcAugmentation>> removedEvcs = OvsdbUtils.extractRemoved(changes,
39 EvcAugmentation.class);
40 if (!removedEvcs.isEmpty()) {
41 for (InstanceIdentifier<EvcAugmentation> removedEvcIid: removedEvcs) {
42 EvcAugmentation evcAugmentation = MdsalUtils.read(dataBroker,
43 LogicalDatastoreType.OPERATIONAL,
45 if (evcAugmentation != null) {
46 List<UniSource> unisSource = evcAugmentation.getUniSource();
47 List<UniDest> unisDest = evcAugmentation.getUniDest();
48 if (unisSource != null && !unisSource.isEmpty()) {
49 for (UniSource source: unisSource) {
51 Optional<Node> optionalSourceUniNode =
52 MdsalUtils.readNode(dataBroker,
53 LogicalDatastoreType.OPERATIONAL,
55 EvcUtils.deleteEvcData(dataBroker, optionalSourceUniNode);
59 if (unisDest != null && !unisDest.isEmpty()) {
60 for (UniDest dest : unisDest) {
62 Optional<Node> optionalDestUniNode =
63 MdsalUtils.readNode(dataBroker,
64 LogicalDatastoreType.OPERATIONAL,
66 EvcUtils.deleteEvcData(dataBroker, optionalDestUniNode);
71 MdsalUtils.deleteNode(dataBroker, removedEvcIid, LogicalDatastoreType.OPERATIONAL);