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
9 package org.opendaylight.unimgr.command;
11 import java.util.List;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.unimgr.api.AbstractCommand;
17 import org.opendaylight.unimgr.utils.EvcUtils;
18 import org.opendaylight.unimgr.utils.MdsalUtils;
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.Link;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import com.google.common.base.Optional;
30 public class EvcRemoveCommand extends AbstractCommand<Link> {
32 private static final Logger LOG = LoggerFactory.getLogger(EvcRemoveCommand.class);
34 public EvcRemoveCommand(final DataBroker dataBroker, final DataTreeModification<Link> removedEvcLink) {
35 super(dataBroker, removedEvcLink);
39 public void execute() {
40 final Link evcLink = dataObject.getRootNode().getDataBefore();
41 final EvcAugmentation evcAugmentation = evcLink.getAugmentation(EvcAugmentation.class);
42 final InstanceIdentifier<?> removedEvcIid = dataObject.getRootPath().getRootIdentifier();
43 if (evcAugmentation != null) {
44 final List<UniSource> unisSource = evcAugmentation.getUniSource();
45 final List<UniDest> unisDest = evcAugmentation.getUniDest();
46 if (unisSource != null && !unisSource.isEmpty()) {
47 for (final UniSource source: unisSource) {
49 final Optional<Node> optionalSourceUniNode =
50 MdsalUtils.readNode(dataBroker,
51 LogicalDatastoreType.OPERATIONAL,
53 EvcUtils.deleteEvcData(dataBroker, optionalSourceUniNode);
57 if (unisDest != null && !unisDest.isEmpty()) {
58 for (final UniDest dest : unisDest) {
60 final Optional<Node> optionalDestUniNode =
61 MdsalUtils.readNode(dataBroker,
62 LogicalDatastoreType.OPERATIONAL,
64 EvcUtils.deleteEvcData(dataBroker, optionalDestUniNode);
70 LOG.info("EvcAugmentation is null");
72 MdsalUtils.deleteNode(dataBroker, removedEvcIid, LogicalDatastoreType.OPERATIONAL);